Bug 1443648 - Restore high DPI scaling for most downloaded or copied shots; r=_6a68
authorJared Hirsch <ohai@6a68.net>
Tue, 06 Mar 2018 14:24:03 -0800
changeset 461998 c9541861b02d4d03f7db0d1fd58e4279379fabe5
parent 461997 ec0e046ffe652b6d647e2623fd17b15fb48e73b6
child 461999 e1ae4f79fd6c2acf2c92233edb62fbfbf97ca30e
push id1683
push usersfraser@mozilla.com
push dateThu, 26 Apr 2018 16:43:40 +0000
treeherdermozilla-release@5af6cb21869d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewers_6a68
bugs1443648
milestone60.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1443648 - Restore high DPI scaling for most downloaded or copied shots; r=_6a68 * Don't overwrite correctly-scaled canvas dimensions when generating a shot async * Pass the shot type to downloadShot and copyShot, so that non-fullpage shots will be correctly scaled. Note that fullpage shots are always low DPI. MozReview-Commit-ID: 5SAnoJrJ88S
browser/extensions/screenshots/webextension/selector/shooter.js
browser/extensions/screenshots/webextension/selector/uicontrol.js
--- a/browser/extensions/screenshots/webextension/selector/shooter.js
+++ b/browser/extensions/screenshots/webextension/selector/shooter.js
@@ -79,19 +79,17 @@ this.shooter = (function() { // eslint-d
   };
 
   function screenshotPageAsync(selectedPos, captureType) {
     if (!supportsDrawWindow) {
       return Promise.resolve(null);
     }
     const canvas = captureToCanvas(selectedPos, captureType);
     ui.iframe.showLoader();
-    const width = selectedPos.right - selectedPos.left;
-    const height = selectedPos.bottom - selectedPos.top;
-    const imageData = canvas.getContext("2d").getImageData(0, 0, width, height);
+    const imageData = canvas.getContext("2d").getImageData(0, 0, canvas.width, canvas.height);
     return callBackground("canvasToDataURL", imageData);
   }
 
   let isSaving = null;
 
   exports.takeShot = function(captureType, selectedPos, url) {
     // isSaving indicates we're aleady in the middle of saving
     // we use a timeout so in the case of a failure the button will
@@ -175,18 +173,18 @@ this.shooter = (function() { // eslint-d
       }
     }).then(() => {
       if (deactivateAfterFinish) {
         uicontrol.deactivate();
       }
     }));
   };
 
-  exports.downloadShot = function(selectedPos, previewDataUrl) {
-    const shotPromise = previewDataUrl ? Promise.resolve(previewDataUrl) : screenshotPageAsync(selectedPos, "fullPage");
+  exports.downloadShot = function(selectedPos, previewDataUrl, type) {
+    const shotPromise = previewDataUrl ? Promise.resolve(previewDataUrl) : screenshotPageAsync(selectedPos, type);
     catcher.watchPromise(shotPromise.then(dataUrl => {
       let promise = Promise.resolve(dataUrl);
       if (!dataUrl) {
         promise = callBackground(
           "screenshotPage",
           selectedPos.asJson(),
           {
             scrollX: window.scrollX,
@@ -209,34 +207,34 @@ this.shooter = (function() { // eslint-d
         });
         ui.triggerDownload(dataUrl, shotObject.filename);
         uicontrol.deactivate();
       }));
     }))
   };
 
   let copyInProgress = null;
-  exports.copyShot = function(selectedPos, previewDataUrl) {
+  exports.copyShot = function(selectedPos, previewDataUrl, type) {
     // This is pretty slow. We'll ignore additional user triggered copy events
     // while it is in progress.
     if (copyInProgress) {
       return;
     }
     // A max of five seconds in case some error occurs.
     copyInProgress = setTimeout(() => {
       copyInProgress = null;
     }, 5000);
 
     const unsetCopyInProgress = () => {
       if (copyInProgress) {
         clearTimeout(copyInProgress);
         copyInProgress = null;
       }
     }
-    const shotPromise = previewDataUrl ? Promise.resolve(previewDataUrl) : screenshotPageAsync(selectedPos, "fullPage");
+    const shotPromise = previewDataUrl ? Promise.resolve(previewDataUrl) : screenshotPageAsync(selectedPos, type);
     catcher.watchPromise(shotPromise.then(dataUrl => {
       const blob = blobConverters.dataUrlToBlob(dataUrl);
       catcher.watchPromise(callBackground("copyShotToClipboard", blob).then(() => {
         uicontrol.deactivate();
         unsetCopyInProgress();
       }, unsetCopyInProgress));
     }));
   };
--- a/browser/extensions/screenshots/webextension/selector/uicontrol.js
+++ b/browser/extensions/screenshots/webextension/selector/uicontrol.js
@@ -94,24 +94,24 @@ this.uicontrol = (function() {
       cd2: round10(posEnd.x - posStart.x)
     };
   }
 
   function downloadShot() {
     const previewDataUrl = (captureType === "fullPageTruncated") ? null : dataUrl;
     // Downloaded shots don't have dimension limits
     removeDimensionLimitsOnFullPageShot();
-    shooter.downloadShot(selectedPos, previewDataUrl);
+    shooter.downloadShot(selectedPos, previewDataUrl, captureType);
   }
 
   function copyShot() {
     const previewDataUrl = (captureType === "fullPageTruncated") ? null : dataUrl;
     // Copied shots don't have dimension limits
     removeDimensionLimitsOnFullPageShot();
-    shooter.copyShot(selectedPos, previewDataUrl);
+    shooter.copyShot(selectedPos, previewDataUrl, captureType);
   }
 
   /** *********************************************
    * State and stateHandlers infrastructure
    */
 
   // This enumerates all the anchors on the selection, and what part of the
   // selection they move: