Title: [258787] trunk
Revision
258787
Author
aj...@chromium.org
Date
2020-03-20 13:58:54 -0700 (Fri, 20 Mar 2020)

Log Message

Intersection Observer intersections are wrong with zooming
https://bugs.webkit.org/show_bug.cgi?id=209264

Reviewed by Simon Fraser.

Source/WebCore:

An IntersectionObserver's rootMargin is expressed in CSS pixels,
but we weren't accounting for page zoom. Fix this by multiplying
the root margin by the zoom factor.

Test: intersection-observer/root-margin-with-zoom.html

* dom/Document.cpp:
(WebCore::expandRootBoundsWithRootMargin):
(WebCore::computeIntersectionState):

LayoutTests:

* intersection-observer/root-margin-with-zoom.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (258786 => 258787)


--- trunk/LayoutTests/ChangeLog	2020-03-20 20:44:56 UTC (rev 258786)
+++ trunk/LayoutTests/ChangeLog	2020-03-20 20:58:54 UTC (rev 258787)
@@ -1,3 +1,12 @@
+2020-03-20  Ali Juma  <aj...@chromium.org>
+
+        Intersection Observer intersections are wrong with zooming
+        https://bugs.webkit.org/show_bug.cgi?id=209264
+
+        Reviewed by Simon Fraser.
+
+        * intersection-observer/root-margin-with-zoom.html: Added.
+
 2020-03-20  Jason Lawrence  <lawrenc...@apple.com>
 
         REGRESSION: (r258747) [ Mac wk1 Release ] media/video-background-tab-playback.html is failing.

Added: trunk/LayoutTests/intersection-observer/root-margin-with-zoom.html (0 => 258787)


--- trunk/LayoutTests/intersection-observer/root-margin-with-zoom.html	                        (rev 0)
+++ trunk/LayoutTests/intersection-observer/root-margin-with-zoom.html	2020-03-20 20:58:54 UTC (rev 258787)
@@ -0,0 +1,34 @@
+<!DOCTYPE html>
+<link rel="help" href=""
+<script src=""
+<script src=""
+<style>
+#target {
+    position: absolute;
+    height: 40px;
+    width: 100px;
+    top: -40px;
+    background-color: green;
+}
+</style>
+
+
+<div id="target"></div>
+
+<script>
+    // The target is positioned 40 px above the viewport so should fully intersect
+    // when the viewport is expanded by a root margin of 40 px, no matter what
+    // page zoom factor is used, since page zoom should equally affect both the
+    // positioning of the target and the size of the root margin.
+    window.internals.setPageZoomFactor(2);
+    async_test((t) =>  {
+        let options = {
+            rootMargin: '40px 0px 0px 0px',
+            threshold: [1]
+        }
+        let observer = new IntersectionObserver(t.step_func_done((entries) => {
+            assert_true(entries[0].isIntersecting, "isIntersecting"); 
+        }), options);
+        observer.observe(document.getElementById("target"));
+    }, "IntersectionObserver's root margin accounts for zooming");
+</script>

Modified: trunk/Source/WebCore/ChangeLog (258786 => 258787)


--- trunk/Source/WebCore/ChangeLog	2020-03-20 20:44:56 UTC (rev 258786)
+++ trunk/Source/WebCore/ChangeLog	2020-03-20 20:58:54 UTC (rev 258787)
@@ -1,3 +1,20 @@
+2020-03-20  Ali Juma  <aj...@chromium.org>
+
+        Intersection Observer intersections are wrong with zooming
+        https://bugs.webkit.org/show_bug.cgi?id=209264
+
+        Reviewed by Simon Fraser.
+
+        An IntersectionObserver's rootMargin is expressed in CSS pixels,
+        but we weren't accounting for page zoom. Fix this by multiplying
+        the root margin by the zoom factor.
+
+        Test: intersection-observer/root-margin-with-zoom.html
+
+        * dom/Document.cpp:
+        (WebCore::expandRootBoundsWithRootMargin):
+        (WebCore::computeIntersectionState):
+
 2020-03-20  Don Olmstead  <don.olmst...@sony.com>
 
         [GPUP] Add PlatformLayerContainer to hold pointer to PlatformLayer

Modified: trunk/Source/WebCore/dom/Document.cpp (258786 => 258787)


--- trunk/Source/WebCore/dom/Document.cpp	2020-03-20 20:44:56 UTC (rev 258786)
+++ trunk/Source/WebCore/dom/Document.cpp	2020-03-20 20:58:54 UTC (rev 258787)
@@ -7488,13 +7488,13 @@
     m_intersectionObservers.removeFirst(&observer);
 }
 
-static void expandRootBoundsWithRootMargin(FloatRect& localRootBounds, const LengthBox& rootMargin)
+static void expandRootBoundsWithRootMargin(FloatRect& localRootBounds, const LengthBox& rootMargin, float zoomFactor)
 {
     FloatBoxExtent rootMarginFloatBox(
-        floatValueForLength(rootMargin.top(), localRootBounds.height()),
-        floatValueForLength(rootMargin.right(), localRootBounds.width()),
-        floatValueForLength(rootMargin.bottom(), localRootBounds.height()),
-        floatValueForLength(rootMargin.left(), localRootBounds.width())
+        floatValueForLength(rootMargin.top(), localRootBounds.height()) * zoomFactor,
+        floatValueForLength(rootMargin.right(), localRootBounds.width()) * zoomFactor,
+        floatValueForLength(rootMargin.bottom(), localRootBounds.height()) * zoomFactor,
+        floatValueForLength(rootMargin.left(), localRootBounds.width()) * zoomFactor
     );
 
     localRootBounds.expand(rootMarginFloatBox);
@@ -7560,7 +7560,7 @@
     }
 
     if (applyRootMargin)
-        expandRootBoundsWithRootMargin(localRootBounds, observer.rootMarginBox());
+        expandRootBoundsWithRootMargin(localRootBounds, observer.rootMarginBox(), rootRenderer->style().effectiveZoom());
 
     LayoutRect localTargetBounds;
     if (is<RenderBox>(*targetRenderer))
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to