[Webkit-unassigned] [Bug 160548] New: getBoundingClientRect returns incorrect position when pinch-zoomed

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Aug 4 06:47:09 PDT 2016


https://bugs.webkit.org/show_bug.cgi?id=160548

            Bug ID: 160548
           Summary: getBoundingClientRect returns incorrect position when
                    pinch-zoomed
    Classification: Unclassified
           Product: WebKit
           Version: WebKit Local Build
          Hardware: Macintosh
                OS: OS X 10.11
            Status: NEW
          Severity: Normal
          Priority: P2
         Component: New Bugs
          Assignee: webkit-unassigned at lists.webkit.org
          Reporter: bokan at chromium.org

Created attachment 285316
  --> https://bugs.webkit.org/attachment.cgi?id=285316&action=review
Demo of the bug

getBoundingClientRect reports incorrect 'top' and 'left' values when the page is pinch-zoomed. I've narrowed down the problem to Document::adjustFloatRectForScrollAndAbsoluteZoomAndFrameScale, which subtracts the Frame's scroll position (which is already in CSS pixels, i.e. is divided by the frameScaleFactor) from the rect and then scales the rect by 1/frameScaleFactor. This means the frame's scroll position, as applied to the rect, is scaled by frameScaleFactor twice. It also seems to me that the bounding box returned in Element::getBoundingClientRect has the position in CSS pixels by the size in DIPs. That is, printf'ing the FloatRect returned by quads[0].boundingBox() shows that pinch-zooming in causes the size to increase but not the position.

If I want to get the correct getBoundingClientRect as a page author today, I have to perform this calculation:

var rect = element.getBoundingClientRect();
var pageScaleFactor = window.outerWidth / window.innerWidth;
var correctedTop = rect.top*pageScaleFactor + window.scrollY*pageScaleFactor - window.scrollY;

I've attached a demo page showing the bug. It *should* keep the red box fixed to the top of the viewport but you can see that scrolling causes the box to move down faster than the page. You can uncomment the "corrected" calculation to see how it should look. I've also hosted this at http://bokan.ca/getBoundingClientRectBug.html for convenience.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-unassigned/attachments/20160804/919440b4/attachment.html>


More information about the webkit-unassigned mailing list