Skip to content

Commit

Permalink
Bug 1404078 - notify user when full page is cut off r=kmag
Browse files Browse the repository at this point in the history
Adds a new captureType, fullPageTruncated

Fixes upstream bug: mozilla-services/screenshots#2129
Export of commit: mozilla-services/screenshots@e31c321

MozReview-Commit-ID: HB3e5Q24afT
  • Loading branch information
ianb committed Sep 28, 2017
1 parent 24456dd commit 7021ee6
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
}
}
},
"imageCroppedWarning": {
"message": "This image has been cropped to $PIXELS$px.",
"placeholders": {
"pixels": {
"content": "$1"
}
}
},
"requestErrorTitle": {
"message": "Out of order."
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ window.buildSettings = {
logLevel: "" || "warn",
captureText: ("" === "true"),
uploadBinary: ("" === "true"),
pngToJpegCutoff: parseInt("" || 2500000, 10)
pngToJpegCutoff: parseInt("" || 2500000, 10),
maxImageHeight: parseInt("" || 5000, 10),
maxImageWidth: parseInt("" || 5000, 10)
};
null;

Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,18 @@ window.inlineSelectionCss = `
padding-top: 20px;
width: 400px; }
#imageCroppedWarning {
position: absolute;
background: rgba(0, 0, 0, 0.8);
bottom: 0;
color: #fff;
font-family: -apple-system, BlinkMacSystemFont, "segoe ui", "helvetica neue", helvetica, ubuntu, roboto, noto, arial, sans-serif;
font-size: 12px;
padding: 10px;
text-align: center;
width: 100%;
z-index: 2; }
.myshots-all-buttons-container {
display: flex;
flex-direction: row-reverse;
Expand Down
9 changes: 8 additions & 1 deletion browser/extensions/screenshots/webextension/build/shot.js
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,14 @@ class _Clip {
}
assert(checkObject(image, ["url"], ["dimensions", "text", "location", "captureType", "type"]), "Bad attrs for Clip Image:", Object.keys(image));
assert(isValidClipImageUrl(image.url), "Bad Clip image URL:", image.url);
assert(image.captureType == "madeSelection" || image.captureType == "selection" || image.captureType == "visible" || image.captureType == "auto" || image.captureType == "fullPage" || !image.captureType, "Bad image.captureType:", image.captureType);
assert(
image.captureType == "madeSelection" ||
image.captureType == "selection" ||
image.captureType == "visible" ||
image.captureType == "auto" ||
image.captureType == "fullPage" ||
image.captureType == "fullPageTruncated" ||
!image.captureType, "Bad image.captureType:", image.captureType);
assert(typeof image.text == "string" || !image.text, "Bad Clip image text:", image.text);
if (image.dimensions) {
assert(typeof image.dimensions.x == "number" && typeof image.dimensions.y == "number", "Bad Clip image dimensions:", image.dimensions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,16 @@ this.shooter = (function() { // eslint-disable-line no-unused-vars
let width = selectedPos.right - selectedPos.left;
let canvas = document.createElementNS('http://www.w3.org/1999/xhtml', 'canvas');
let ctx = canvas.getContext('2d');
if (captureType == 'fullPage') {
let expand = window.devicePixelRatio !== 1;
if (captureType == 'fullPage' || captureType == 'fullPageTruncated') {
expand = false;
canvas.width = width;
canvas.height = height;
} else {
canvas.width = width * window.devicePixelRatio;
canvas.height = height * window.devicePixelRatio;
}
if (window.devicePixelRatio !== 1 && captureType != 'fullPage') {
if (expand) {
ctx.scale(window.devicePixelRatio, window.devicePixelRatio);
}
ui.iframe.hide();
Expand Down
10 changes: 8 additions & 2 deletions browser/extensions/screenshots/webextension/selector/ui.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals log, util, catcher, inlineSelectionCss, callBackground, assertIsTrusted, assertIsBlankDocument */
/* globals log, util, catcher, inlineSelectionCss, callBackground, assertIsTrusted, assertIsBlankDocument, buildSettings */

"use strict";

Expand Down Expand Up @@ -707,10 +707,16 @@ this.ui = (function() { // eslint-disable-line no-unused-vars
};

exports.Preview = {
display(dataUrl) {
display(dataUrl, showCropWarning) {
let img = makeEl("IMG");
img.src = dataUrl;
iframe.document().querySelector(".preview-image").appendChild(img);
if (showCropWarning) {
let imageCroppedEl = makeEl("DIV");
imageCroppedEl.id = "imageCroppedWarning";
imageCroppedEl.textContent = browser.i18n.getMessage("imageCroppedWarning", buildSettings.maxImageHeight);
iframe.document().querySelector(".preview-overlay").appendChild(imageCroppedEl);
}
}
};

Expand Down
16 changes: 11 additions & 5 deletions browser/extensions/screenshots/webextension/selector/uicontrol.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* globals log, catcher, util, ui, slides */
/* globals shooter, callBackground, selectorLoader, assertIsTrusted */
/* globals shooter, callBackground, selectorLoader, assertIsTrusted, buildSettings */

"use strict";

Expand Down Expand Up @@ -45,8 +45,8 @@ this.uicontrol = (function() {

const { watchFunction, watchPromise } = catcher;

const MAX_PAGE_HEIGHT = 5000;
const MAX_PAGE_WIDTH = 5000;
const MAX_PAGE_HEIGHT = buildSettings.maxImageHeight;
const MAX_PAGE_WIDTH = buildSettings.maxImageWidth;
// An autoselection smaller than these will be ignored entirely:
const MIN_DETECT_ABSOLUTE_HEIGHT = 10;
const MIN_DETECT_ABSOLUTE_WIDTH = 30;
Expand Down Expand Up @@ -160,22 +160,28 @@ this.uicontrol = (function() {
},
onClickFullPage: () => {
sendEvent("capture-full-page", "selection-button");
captureType = "fullPage";
let width = Math.max(
document.body.clientWidth,
document.documentElement.clientWidth,
document.body.scrollWidth,
document.documentElement.scrollWidth);
if (width > MAX_PAGE_WIDTH) {
captureType = "fullPageTruncated";
}
width = Math.min(width, MAX_PAGE_WIDTH);
let height = Math.max(
document.body.clientHeight,
document.documentElement.clientHeight,
document.body.scrollHeight,
document.documentElement.scrollHeight);
if (height > MAX_PAGE_HEIGHT) {
captureType = "fullPageTruncated";
}
height = Math.min(height, MAX_PAGE_HEIGHT);
selectedPos = new Selection(
0, 0,
width, height);
captureType = 'fullPage';
setState("previewing");
},
onSavePreview: () => {
Expand Down Expand Up @@ -368,7 +374,7 @@ this.uicontrol = (function() {
start() {
dataUrl = shooter.screenshotPage(selectedPos, captureType);
ui.iframe.usePreview();
ui.Preview.display(dataUrl);
ui.Preview.display(dataUrl, captureType == "fullPageTruncated");
}
};

Expand Down

0 comments on commit 7021ee6

Please sign in to comment.