Skip to content
This repository has been archived by the owner on Sep 21, 2022. It is now read-only.

Commit

Permalink
isOutsideOfImage: take into account scrolling position
Browse files Browse the repository at this point in the history
  • Loading branch information
scf2k committed Apr 24, 2015
1 parent ed7a683 commit 239c1b6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/browser/client-scripts/gemini.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ function prepareScreenshotUnsafe(selectors, opts) {

var viewportHeight = window.innerHeight || document.documentElement.clientHeight,
documentHeight = document.documentElement.scrollHeight,
documentWidth = document.documentElement.scrollWidth,
coverage;

if (opts.coverage) {
Expand All @@ -50,6 +51,7 @@ function prepareScreenshotUnsafe(selectors, opts) {
ignoreAreas: findIgnoreAreas(opts.ignoreSelectors),
viewportHeight: Math.round(viewportHeight),
documentHeight: Math.round(documentHeight),
documentWidth: Math.round(documentWidth),
coverage: coverage,
canHaveCaret: isEditable(document.activeElement)
};
Expand Down
13 changes: 10 additions & 3 deletions lib/capture-session.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = inherit({
));
}

if (isOutsideOfImage(captureArea, imageSize)) {
if (isOutsideOfImage(prepareData, imageSize)) {
throw new StateError(
'Can not capture specified region of the page\n' +
'The size of a region is larger then image, captured by browser\n' +
Expand All @@ -105,8 +105,15 @@ module.exports = inherit({

});

function isOutsideOfImage(area, imageSize) {
return area.top < 0 || area.left < 0 || area.left + area.width > imageSize.width;
function isOutsideOfImage(data, imageSize) {
var area = data.captureArea,
rightBorder = area.left + area.width;

if (imageSize.width < data.documentWidth) {
rightBorder -= data.viewportOffset.left;
}

return area.top < 0 || area.left < 0 || area.left + area.width - rightBorder > imageSize.width;
}

function getToImageCoordsFunction(image, prepareData) {
Expand Down

0 comments on commit 239c1b6

Please sign in to comment.