mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 779618 - [Page Thumbnails] make tabbrowser use the thumbnail service; r=jaws
This commit is contained in:
parent
1de8a7810d
commit
45dccf7b5d
@ -25,11 +25,6 @@ let gBrowserThumbnails = {
|
||||
*/
|
||||
_timeouts: null,
|
||||
|
||||
/**
|
||||
* Cache for the PageThumbs module.
|
||||
*/
|
||||
_pageThumbs: null,
|
||||
|
||||
/**
|
||||
* List of tab events we want to listen for.
|
||||
*/
|
||||
@ -52,9 +47,6 @@ let gBrowserThumbnails = {
|
||||
}, this);
|
||||
|
||||
this._timeouts = new WeakMap();
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "_pageThumbs",
|
||||
"resource:///modules/PageThumbs.jsm", "PageThumbs");
|
||||
},
|
||||
|
||||
uninit: function Thumbnails_uninit() {
|
||||
@ -100,7 +92,7 @@ let gBrowserThumbnails = {
|
||||
|
||||
_capture: function Thumbnails_capture(aBrowser) {
|
||||
if (this._shouldCapture(aBrowser))
|
||||
this._pageThumbs.captureAndStore(aBrowser);
|
||||
PageThumbs.captureAndStore(aBrowser);
|
||||
},
|
||||
|
||||
_delayedCapture: function Thumbnails_delayedCapture(aBrowser) {
|
||||
|
@ -140,6 +140,9 @@ XPCOMUtils.defineLazyGetter(this, "Social", function() {
|
||||
return tmp.Social;
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "PageThumbs",
|
||||
"resource:///modules/PageThumbs.jsm");
|
||||
|
||||
#ifdef MOZ_SAFE_BROWSING
|
||||
XPCOMUtils.defineLazyGetter(this, "SafeBrowsing", function() {
|
||||
let tmp = {};
|
||||
|
@ -3407,7 +3407,20 @@
|
||||
// Set the cursor to an arrow during tab drags.
|
||||
dt.mozCursor = "default";
|
||||
|
||||
let canvas = tabPreviews.capture(tab, false);
|
||||
// Create a canvas to which we capture the current tab.
|
||||
let canvas = document.createElementNS("http://www.w3.org/1999/xhtml", "canvas");
|
||||
canvas.mozOpaque = true;
|
||||
|
||||
// We want drag images to be about 1/6th of the available screen width.
|
||||
const widthFactor = 0.1739; // 1:5.75 inverse
|
||||
canvas.width = Math.ceil(screen.availWidth * widthFactor);
|
||||
|
||||
// Maintain a 16:9 aspect ratio for drag images.
|
||||
const aspectRatio = 0.5625; // 16:9 inverse
|
||||
canvas.height = Math.round(canvas.width * aspectRatio);
|
||||
|
||||
let browser = tab.linkedBrowser;
|
||||
PageThumbs.captureToCanvas(browser.contentWindow, canvas);
|
||||
dt.setDragImage(canvas, 0, 0);
|
||||
|
||||
// _dragOffsetX/Y give the coordinates that the mouse should be
|
||||
|
@ -116,11 +116,26 @@ let PageThumbs = {
|
||||
return;
|
||||
}
|
||||
|
||||
let telemetryCaptureTime = new Date();
|
||||
let [sw, sh, scale] = this._determineCropSize(aWindow);
|
||||
|
||||
let canvas = this._createCanvas();
|
||||
let ctx = canvas.getContext("2d");
|
||||
this.captureToCanvas(aWindow, canvas);
|
||||
|
||||
// Fetch the canvas data on the next event loop tick so that we allow
|
||||
// some event processing in between drawing to the canvas and encoding
|
||||
// its data. We want to block the UI as short as possible. See bug 744100.
|
||||
Services.tm.currentThread.dispatch(function () {
|
||||
canvas.mozFetchAsStream(aCallback, this.contentType);
|
||||
}.bind(this), Ci.nsIThread.DISPATCH_NORMAL);
|
||||
},
|
||||
|
||||
/**
|
||||
* Captures a thumbnail from a given window and draws it to the given canvas.
|
||||
* @param aWindow The DOM window to capture a thumbnail from.
|
||||
* @param aCanvas The canvas to draw to.
|
||||
*/
|
||||
captureToCanvas: function PageThumbs_captureToCanvas(aWindow, aCanvas) {
|
||||
let telemetryCaptureTime = new Date();
|
||||
let [sw, sh, scale] = this._determineCropSize(aWindow, aCanvas);
|
||||
let ctx = aCanvas.getContext("2d");
|
||||
|
||||
// Scale the canvas accordingly.
|
||||
ctx.scale(scale, scale);
|
||||
@ -137,12 +152,7 @@ let PageThumbs = {
|
||||
telemetry.getHistogramById("FX_THUMBNAILS_CAPTURE_TIME_MS")
|
||||
.add(new Date() - telemetryCaptureTime);
|
||||
|
||||
// Fetch the canvas data on the next event loop tick so that we allow
|
||||
// some event processing in between drawing to the canvas and encoding
|
||||
// its data. We want to block the UI as short as possible. See bug 744100.
|
||||
Services.tm.currentThread.dispatch(function () {
|
||||
canvas.mozFetchAsStream(aCallback, this.contentType);
|
||||
}.bind(this), Ci.nsIThread.DISPATCH_NORMAL);
|
||||
return aCanvas;
|
||||
},
|
||||
|
||||
/**
|
||||
@ -193,13 +203,14 @@ let PageThumbs = {
|
||||
/**
|
||||
* Determines the crop size for a given content window.
|
||||
* @param aWindow The content window.
|
||||
* @param aCanvas The target canvas.
|
||||
* @return An array containing width, height and scale.
|
||||
*/
|
||||
_determineCropSize: function PageThumbs_determineCropSize(aWindow) {
|
||||
_determineCropSize: function PageThumbs_determineCropSize(aWindow, aCanvas) {
|
||||
let sw = aWindow.innerWidth;
|
||||
let sh = aWindow.innerHeight;
|
||||
|
||||
let [thumbnailWidth, thumbnailHeight] = this._getThumbnailSize();
|
||||
let {width: thumbnailWidth, height: thumbnailHeight} = aCanvas;
|
||||
let scale = Math.max(thumbnailWidth / sw, thumbnailHeight / sh);
|
||||
let scaledWidth = sw * scale;
|
||||
let scaledHeight = sh * scale;
|
||||
|
@ -11,8 +11,6 @@ registerCleanupFunction(function () {
|
||||
gBrowser.removeTab(gBrowser.tabs[1]);
|
||||
});
|
||||
|
||||
let cachedXULDocument;
|
||||
|
||||
/**
|
||||
* Provide the default test function to start our test runner.
|
||||
*/
|
||||
|
Loading…
Reference in New Issue
Block a user