b2g/components/Screenshot.jsm
author Ehsan Akhgari <ehsan@mozilla.com>
Sat, 21 Mar 2015 12:28:04 -0400
changeset 263771 ac4464790ec4896a5188fa50cfc69ae0ffeddc08
parent 262054 1d8b0c948fd35c8ee9e024d7d562ca35027da6b1
child 295257 380817d573cdfbfc4a4b4a4647cf1a53bb52c3b9
permissions -rw-r--r--
Bug 1145631 - Part 1: Replace MOZ_OVERRIDE and MOZ_FINAL with override and final in the tree; r=froydnj This patch was automatically generated using the following script: function convert() { echo "Converting $1 to $2..." find . \ ! -wholename "*/.git*" \ ! -wholename "obj-ff-dbg*" \ -type f \ \( -iname "*.cpp" \ -o -iname "*.h" \ -o -iname "*.c" \ -o -iname "*.cc" \ -o -iname "*.idl" \ -o -iname "*.ipdl" \ -o -iname "*.ipdlh" \ -o -iname "*.mm" \) | \ xargs -n 1 sed -i -e "s/\b$1\b/$2/g" } convert MOZ_OVERRIDE override convert MOZ_FINAL final

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

'use strict';

const { classes: Cc, interfaces: Ci, utils: Cu } = Components;

Cu.import('resource://gre/modules/XPCOMUtils.jsm');

XPCOMUtils.defineLazyModuleGetter(this, "SystemAppProxy", "resource://gre/modules/SystemAppProxy.jsm");

this.EXPORTED_SYMBOLS = ['Screenshot'];

let Screenshot = {
  get: function screenshot_get() {
    let systemAppFrame = SystemAppProxy.getFrame();
    let window = systemAppFrame.ownerDocument.defaultView;
    let document = window.document;

    var canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
    var docRect = document.body.getBoundingClientRect();
    var width = docRect.width;
    var height = docRect.height;

    // Convert width and height from CSS pixels (potentially fractional)
    // to device pixels (integer).
    var scale = window.devicePixelRatio;
    canvas.setAttribute('width', Math.round(width * scale));
    canvas.setAttribute('height', Math.round(height * scale));

    var context = canvas.getContext('2d');
    var flags =
      context.DRAWWINDOW_DRAW_CARET |
      context.DRAWWINDOW_DRAW_VIEW |
      context.DRAWWINDOW_USE_WIDGET_LAYERS;
    context.scale(scale, scale);
    context.drawWindow(window, 0, 0, width, height, 'rgb(255,255,255)', flags);

    return canvas.mozGetAsFile('screenshot', 'image/png');
  }
};
this.Screenshot = Screenshot;