Changeset 235459 in webkit


Ignore:
Timestamp:
Aug 29, 2018 5:36:15 AM (6 years ago)
Author:
ajuma@chromium.org
Message:

[IntersectionObserver] Implement intersection logic for the same-document implicit root case
https://bugs.webkit.org/show_bug.cgi?id=189055

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

Rebaseline tests.

  • web-platform-tests/intersection-observer/display-none-expected.txt:
  • web-platform-tests/intersection-observer/inline-client-rect-expected.txt:
  • web-platform-tests/intersection-observer/multiple-targets-expected.txt:
  • web-platform-tests/intersection-observer/multiple-thresholds-expected.txt:
  • web-platform-tests/intersection-observer/observer-without-js-reference-expected.txt:
  • web-platform-tests/intersection-observer/root-margin-expected.txt:
  • web-platform-tests/intersection-observer/same-document-no-root-expected.txt:
  • web-platform-tests/intersection-observer/same-document-zero-size-target-expected.txt:
  • web-platform-tests/intersection-observer/shadow-content-expected.txt:
  • web-platform-tests/intersection-observer/text-target-expected.txt:
  • web-platform-tests/intersection-observer/zero-area-element-hidden-expected.txt:

Source/WebCore:

Extend the intersection logic to handle computing the intersection of the target and the
viewport, for the case where the target is in the main frame.

Tested by existing tests in imported/w3c/web-platform-tests/intersection-observer.

  • dom/Document.cpp:

(WebCore::computeIntersectionRects):
(WebCore::Document::updateIntersectionObservations):

Location:
trunk
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r235458 r235459  
     12018-08-29  Ali Juma  <ajuma@chromium.org>
     2
     3        [IntersectionObserver]  Implement intersection logic for the same-document implicit root case
     4        https://bugs.webkit.org/show_bug.cgi?id=189055
     5
     6        Reviewed by Simon Fraser.
     7
     8        Rebaseline tests.
     9
     10        * web-platform-tests/intersection-observer/display-none-expected.txt:
     11        * web-platform-tests/intersection-observer/inline-client-rect-expected.txt:
     12        * web-platform-tests/intersection-observer/multiple-targets-expected.txt:
     13        * web-platform-tests/intersection-observer/multiple-thresholds-expected.txt:
     14        * web-platform-tests/intersection-observer/observer-without-js-reference-expected.txt:
     15        * web-platform-tests/intersection-observer/root-margin-expected.txt:
     16        * web-platform-tests/intersection-observer/same-document-no-root-expected.txt:
     17        * web-platform-tests/intersection-observer/same-document-zero-size-target-expected.txt:
     18        * web-platform-tests/intersection-observer/shadow-content-expected.txt:
     19        * web-platform-tests/intersection-observer/text-target-expected.txt:
     20        * web-platform-tests/intersection-observer/zero-area-element-hidden-expected.txt:
     21
    1222018-08-28  Ryosuke Niwa  <rniwa@webkit.org>
    223
  • trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/display-none-expected.txt

    r235014 r235459  
    11
    22PASS IntersectionObserver should send a not-intersecting notification for a target that gets display:none.
    3 FAIL Intersecting notification after first rAF. assert_equals: entries[0].boundingClientRect.left expected 8 but got 0
    4 FAIL Not-intersecting notification after setting display:none on target. assert_equals: entries.length expected 2 but got 1
    5 FAIL Intersecting notification after removing display:none on target. assert_equals: entries.length expected 3 but got 1
     3PASS Intersecting notification after first rAF.
     4PASS Not-intersecting notification after setting display:none on target.
     5PASS Intersecting notification after removing display:none on target.
    66
  • trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/inline-client-rect-expected.txt

    r235014 r235459  
    22
    33PASS Inline target
    4 FAIL First rAF assert_equals: entries[0].boundingClientRect.left expected 320 but got 0
    5 FAIL scroller.scrollLeft = 90 assert_equals: entries.length expected 2 but got 1
     4PASS First rAF
     5PASS scroller.scrollLeft = 90
    66
  • trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/multiple-targets-expected.txt

    r235014 r235459  
    22PASS One observer with multiple targets.
    33PASS First rAF.
    4 FAIL document.scrollingElement.scrollTop = 150 assert_equals: Four notifications. expected 4 but got 3
    5 FAIL document.scrollingElement.scrollTop = 10000 assert_equals: Six notifications. expected 6 but got 3
    6 FAIL document.scrollingElement.scrollTop = 0 assert_equals: Nine notifications. expected 9 but got 3
     4PASS document.scrollingElement.scrollTop = 150
     5PASS document.scrollingElement.scrollTop = 10000
     6PASS document.scrollingElement.scrollTop = 0
    77
  • trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/multiple-thresholds-expected.txt

    r235014 r235459  
    11
    22PASS Observer with multiple thresholds.
    3 FAIL First rAF. assert_equals: entries[0].boundingClientRect.left expected 8 but got 0
    4 FAIL document.scrollingElement.scrollTop = 120 assert_equals: entries.length expected 2 but got 1
    5 FAIL document.scrollingElement.scrollTop = 160 assert_equals: entries.length expected 3 but got 1
    6 FAIL document.scrollingElement.scrollTop = 200 assert_equals: entries.length expected 4 but got 1
    7 FAIL document.scrollingElement.scrollTop = 240 assert_equals: entries.length expected 5 but got 1
    8 FAIL document.scrollingElement.scrollTop = window.innerHeight + 140 assert_equals: entries.length expected 6 but got 1
    9 FAIL document.scrollingElement.scrollTop = window.innerHeight + 160 assert_equals: entries.length expected 7 but got 1
    10 FAIL document.scrollingElement.scrollTop = window.innerHeight + 200 assert_equals: entries.length expected 8 but got 1
     3PASS First rAF.
     4PASS document.scrollingElement.scrollTop = 120
     5PASS document.scrollingElement.scrollTop = 160
     6PASS document.scrollingElement.scrollTop = 200
     7PASS document.scrollingElement.scrollTop = 240
     8PASS document.scrollingElement.scrollTop = window.innerHeight + 140
     9PASS document.scrollingElement.scrollTop = window.innerHeight + 160
     10PASS document.scrollingElement.scrollTop = window.innerHeight + 200
     11PASS document.scrollingElement.scrollTop = window.innerHeight + 220
    1112
  • trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/observer-without-js-reference-expected.txt

    r235014 r235459  
    22PASS IntersectionObserver that is unreachable in js should still generate notifications.
    33PASS First rAF
    4 FAIL document.scrollingElement.scrollTop = 300 assert_equals: Two notifications. expected 2 but got 1
     4PASS document.scrollingElement.scrollTop = 300
    55
  • trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/root-margin-expected.txt

    r235014 r235459  
    22
    33PASS Root margin tests
    4 FAIL First rAF. assert_equals: entries[0].boundingClientRect.left expected 972 but got 0
     4FAIL First rAF. assert_equals: entries[0].rootBounds.left expected -30 but got 0
    55FAIL document.scrollingElement.scrollLeft = 100 assert_equals: entries.length expected 2 but got 1
    66FAIL document.scrollingElement.scrollTop = document.documentElement.clientHeight + 200 assert_equals: entries.length expected 2 but got 1
  • trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/same-document-no-root-expected.txt

    r235014 r235459  
    11
    22PASS IntersectionObserver in a single document using the implicit root.
    3 FAIL First rAF. assert_equals: entries[0].boundingClientRect.left expected 8 but got 0
    4 FAIL document.scrollingElement.scrollTop = 300 assert_equals: entries.length expected 2 but got 1
    5 FAIL document.scrollingElement.scrollTop = 100 assert_equals: entries.length expected 3 but got 1
     3PASS First rAF.
     4PASS document.scrollingElement.scrollTop = 300
     5PASS document.scrollingElement.scrollTop = 100
    66
  • trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/same-document-zero-size-target-expected.txt

    r235014 r235459  
    11
    22PASS Observing a zero-area target.
    3 FAIL First rAF assert_equals: entries[0].boundingClientRect.left expected 8 but got 0
     3PASS First rAF
    44FAIL document.scrollingElement.scrollTop = 300 assert_equals: entries.length expected 2 but got 1
    55FAIL document.scrollingElement.scrollTop = 100 assert_equals: entries.length expected 3 but got 1
  • trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/shadow-content-expected.txt

    r235014 r235459  
    11
    22PASS Observing a target inside shadow DOM.
    3 FAIL First rAF after creating shadow DOM. assert_equals: entries[0].boundingClientRect.left expected 8 but got 0
     3PASS First rAF after creating shadow DOM.
    44
  • trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/text-target-expected.txt

    r235014 r235459  
    22
    33PASS IntersectionObserver observing a br element.
    4 FAIL First rAF. assert_equals: entries[0].boundingClientRect.left expected 8 but got 0
     4PASS First rAF.
    55FAIL document.scrollingElement.scrollTop = 300 assert_equals: entries.length expected 2 but got 1
    66FAIL document.scrollingElement.scrollTop = 100 assert_equals: entries.length expected 3 but got 1
  • trunk/LayoutTests/imported/w3c/web-platform-tests/intersection-observer/zero-area-element-hidden-expected.txt

    r235014 r235459  
    11
    22PASS A zero-area hidden target should not be intersecting.
    3 FAIL First rAF. assert_equals: entries[0].boundingClientRect.left expected 8 but got 0
     3PASS First rAF.
    44
  • trunk/Source/WebCore/ChangeLog

    r235458 r235459  
     12018-08-29  Ali Juma  <ajuma@chromium.org>
     2
     3        [IntersectionObserver]  Implement intersection logic for the same-document implicit root case
     4        https://bugs.webkit.org/show_bug.cgi?id=189055
     5
     6        Reviewed by Simon Fraser.
     7
     8        Extend the intersection logic to handle computing the intersection of the target and the
     9        viewport, for the case where the target is in the main frame.
     10
     11        Tested by existing tests in imported/w3c/web-platform-tests/intersection-observer.
     12
     13        * dom/Document.cpp:
     14        (WebCore::computeIntersectionRects):
     15        (WebCore::Document::updateIntersectionObservations):
     16
    1172018-08-28  Ryosuke Niwa  <rniwa@webkit.org>
    218
  • trunk/Source/WebCore/dom/Document.cpp

    r235424 r235459  
    74457445}
    74467446
    7447 static void computeIntersectionRects(IntersectionObserver& observer, Element& target, FloatRect& absTargetRect, FloatRect& absIntersectionRect, FloatRect& absRootBounds)
    7448 {
    7449     // FIXME: Implement intersection computation for the case of an implicit root.
    7450     if (!observer.root())
    7451         return;
    7452 
    7453     if (observer.root()->document() != target.document())
    7454         return;
    7455 
    7456     if (!observer.root()->renderer() || !is<RenderBlock>(observer.root()->renderer()))
    7457         return;
    7458 
    7459     RenderBlock* rootRenderer = downcast<RenderBlock>(observer.root()->renderer());
     7447static void computeIntersectionRects(FrameView& frameView, IntersectionObserver& observer, Element& target, FloatRect& absTargetRect, FloatRect& absIntersectionRect, FloatRect& absRootBounds)
     7448{
     7449    // FIXME: Implement intersection computation for the cross-document case.
     7450    if (observer.trackingDocument() != &target.document())
     7451        return;
    74607452
    74617453    auto* targetRenderer = target.renderer();
     
    74637455        return;
    74647456
    7465     if (!rootRenderer->isContainingBlockAncestorFor(*targetRenderer))
    7466         return;
    7467 
    74687457    // FIXME: Expand localRootBounds using the observer's rootMargin.
    74697458    FloatRect localRootBounds;
    7470     if (rootRenderer->hasOverflowClip())
    7471         localRootBounds = rootRenderer->contentBoxRect();
    7472     else
    7473         localRootBounds = { FloatPoint(), rootRenderer->size() };
     7459    RenderBlock* rootRenderer;
     7460    if (observer.root()) {
     7461        if (!observer.root()->renderer() || !is<RenderBlock>(observer.root()->renderer()))
     7462            return;
     7463
     7464        rootRenderer = downcast<RenderBlock>(observer.root()->renderer());
     7465        if (!rootRenderer->isContainingBlockAncestorFor(*targetRenderer))
     7466            return;
     7467
     7468        if (rootRenderer->hasOverflowClip())
     7469            localRootBounds = rootRenderer->contentBoxRect();
     7470        else
     7471            localRootBounds = { FloatPoint(), rootRenderer->size() };
     7472    } else {
     7473        ASSERT(frameView.frame().isMainFrame());
     7474        rootRenderer = frameView.renderView();
     7475        localRootBounds = frameView.layoutViewportRect();
     7476    }
    74747477
    74757478    LayoutRect localTargetBounds;
     
    75207523            FloatRect absIntersectionRect;
    75217524            FloatRect absRootBounds;
    7522             computeIntersectionRects(*observer, *target, absTargetRect, absIntersectionRect, absRootBounds);
     7525            computeIntersectionRects(*frameView, *observer, *target, absTargetRect, absIntersectionRect, absRootBounds);
    75237526
    75247527            // FIXME: Handle zero-area intersections (e.g., intersections involving zero-area targets).
     
    75347537            if (!registration.previousThresholdIndex || thresholdIndex != registration.previousThresholdIndex) {
    75357538                FloatRect targetBoundingClientRect = frameView->absoluteToClientRect(absTargetRect);
    7536                 FloatRect clientIntersectionRect = frameView->absoluteToClientRect(absIntersectionRect);
     7539                FloatRect clientIntersectionRect = isIntersecting ? frameView->absoluteToClientRect(absIntersectionRect) : FloatRect();
    75377540
    75387541                // FIXME: Once cross-document observation is implemented, only report root bounds if the target document and
Note: See TracChangeset for help on using the changeset viewer.