Source/WebCore/ChangeLog

 12022-04-29 Rob Buis <rbuis@igalia.com>
 2
 3 REGRESSION(r290770): element.scrollIntoViewIfNeeded() scrolls to top even when element is already in viewport
 4 https://bugs.webkit.org/show_bug.cgi?id=238985
 5
 6 Reviewed by Simon Fraser.
 7
 8 This mostly reverts to the code as it was before r290770, but adds code to
 9 treat non-intersections as hidden, including zero width/height rects.
 10
 11 Test: imported/w3c/web-platform-tests/css/cssom-view/scrollintoview-zero-height-item.html
 12
 13 * rendering/RenderLayer.cpp:
 14 (WebCore::RenderLayer::getRectToExpose const):
 15
1162022-04-29 Tim Nguyen <ntim@apple.com>
217
318 Add background-clip: text to CSSProperties.json

Source/WebCore/rendering/RenderLayer.cpp

@@LayoutRect RenderLayer::getRectToExpose(const LayoutRect& visibleRect, const Lay
26512651 }
26522652 }
26532653
2654  // Determine the appropriate X behavior.
26552654 ScrollAlignment::Behavior scrollX = alignX.getHiddenBehavior();
2656  LayoutRect exposeRectX(exposeRect.x(), visibleRect.y(), exposeRect.width(), visibleRect.height());
2657  LayoutRect intersectRect = intersection(visibleRect, exposeRectX);
2658  if (!intersectRect.isEmpty()) {
2659  LayoutUnit intersectWidth = intersectRect.width();
 2655 bool intersectsInX = exposeRect.maxX() >= visibleRect.x() && exposeRect.x() <= visibleRect.maxX();
 2656
 2657 // Determine the appropriate X behavior.
 2658 if (intersectsInX) {
 2659 LayoutUnit intersectWidth = std::max(LayoutUnit(), std::min(visibleRect.maxX(), exposeRect.maxX()) - std::max(visibleRect.x(), exposeRect.x()));
26602660 if (intersectWidth == exposeRect.width() || (alignX.legacyHorizontalVisibilityThresholdEnabled() && intersectWidth >= MIN_INTERSECT_FOR_REVEAL)) {
26612661 // If the rectangle is fully visible, use the specified visible behavior.
26622662 // If the rectangle is partially visible, but over a certain threshold,

@@LayoutRect RenderLayer::getRectToExpose(const LayoutRect& visibleRect, const Lay
26882688 else
26892689 x = exposeRect.x();
26902690
2691  // Determine the appropriate Y behavior.
26922691 ScrollAlignment::Behavior scrollY = alignY.getHiddenBehavior();
2693  LayoutRect exposeRectY(visibleRect.x(), exposeRect.y(), visibleRect.width(), exposeRect.height());
2694  intersectRect = intersection(visibleRect, exposeRectY);
2695  if (!intersectRect.isEmpty()) {
2696  LayoutUnit intersectHeight = intersectRect.height();
 2692 bool intersectsInY = exposeRect.maxY() >= visibleRect.y() && exposeRect.y() <= visibleRect.maxY();
 2693
 2694 // Determine the appropriate Y behavior.
 2695 if (intersectsInY) {
 2696 LayoutUnit intersectHeight = std::max(LayoutUnit(), std::min(visibleRect.maxY(), exposeRect.maxY()) - std::max(visibleRect.y(), exposeRect.y()));
26972697 if (intersectHeight == exposeRect.height()) {
26982698 // If the rectangle is fully visible, use the specified visible behavior.
26992699 scrollY = alignY.getVisibleBehavior();

LayoutTests/imported/w3c/ChangeLog

 12022-04-29 Rob Buis <rbuis@igalia.com>
 2
 3 REGRESSION(r290770): element.scrollIntoViewIfNeeded() scrolls to top even when element is already in viewport
 4 https://bugs.webkit.org/show_bug.cgi?id=238985
 5
 6 Reviewed by Simon Fraser.
 7
 8 * web-platform-tests/css/cssom-view/scrollintoview-zero-height-item-expected.txt: Added.
 9 * web-platform-tests/css/cssom-view/scrollintoview-zero-height-item.html: Added.
 10
1112022-04-29 Youenn Fablet <youenn@apple.com>
212
313 Make sure to fail importScripts as per https://w3c.github.io/ServiceWorker/#importscripts step 4

LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollintoview-zero-height-item-expected.txt

 1
 2PASS scrollIntoView on zero height item
 3

LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollintoview-zero-height-item.html

 1<!DOCTYPE html>
 2<title>CSSOM View - scrollIntoView does not scroll to zero height item</title>
 3<meta charset="UTF-8">
 4<link rel="help" href="https://drafts.csswg.org/cssom-view/#dom-element-scrollintoview">
 5<script src="/resources/testharness.js"></script>
 6<script src="/resources/testharnessreport.js"></script>
 7<body>
 8<div style="border: 1px solid black; height: 300px; width: 200px; overflow-y: auto;visibility: hidden" id="box">
 9 <div>text</div>
 10 <div>text</div>
 11 <div>text</div>
 12 <div>text</div>
 13 <div id="text">--- Clicking here should NOT scroll to top ---</div>
 14 <div>text</div>
 15 <div>text</div>
 16 <div>text</div>
 17 <div>text</div>
 18 <div>text</div>
 19 <div>text</div>
 20 <div>text</div>
 21 <div>text</div>
 22 <div>text</div>
 23 <div>text</div>
 24 <div>text</div>
 25 <div>text</div>
 26 <div>text</div>
 27 <div>text</div>
 28 <div>text</div>
 29 <div>text</div>
 30 <div>text</div>
 31 <div>text</div>
 32 <div>text</div>
 33 <div>text</div>
 34</div>
 35<script>
 36test(() => {
 37box.scrollTop = 40;
 38
 39let div = document.createElement("div");
 40div.textContent = "div";
 41text.parentNode.insertBefore(div, text);
 42
 43let span = document.createElement("span");
 44span.tabIndex = 0;
 45div.append(span);
 46
 47span.scrollIntoViewIfNeeded();
 48
 49assert_equals(box.scrollTop, 40, 'box.scrollTop');
 50}, `scrollIntoView on zero height item`);
 51
 52</script>
 53</body>