Skip to content

Commit 01aaa3e

Browse files
Ahmad-S792Ahmad Saleem
authored andcommitted
scrollIntoView() on an inline element sharing a tall line scrolls to the line box top instead of the element's bounding rect
https://bugs.webkit.org/show_bug.cgi?id=316063 rdar://178491868 Reviewed by Alan Baradlay. This patch aligns WebKit with Blink / Chromium. RenderElement::getLeadingCorner() computed the leading corner of an inline element's anchor rect by taking the x from the text's linesBoundingBox() but the y from the line box's contentLogicalTop(). When the inline shares a line with a much taller sibling (e.g. a 100vh image), the line box is inflated and its top sits far above the baseline-aligned text, so the leading corner pointed at the top of the line box rather than at the text itself. This made scrollIntoView() scroll to the wrong position, since getTrailingCorner() already uses the text's linesBoundingBox(). Take both x and y from the text's linesBoundingBox(), mirroring getTrailingCorner(), so the anchor rect is the element's own bounding rect. For normal lines linesBoundingBox().y() equals contentLogicalTop(), so only the tall-line case changes behavior. * LayoutTests/TestExpectations: Remove [ Failure ] expectations * Source/WebCore/rendering/RenderElement.cpp: (WebCore::RenderElement::getLeadingCorner const): > Platform Specific Updates: * LayoutTests/platform/glib/fast/scrolling/scroll-to-anchor-zoomed-header-expected.txt: Removed. (Now matches pass expectation) * LayoutTests/platform/ios/fast/dynamic/anchor-lock-expected.txt: Rebaselined * LayoutTests/platform/glib/fast/dynamic/anchor-lock-expected.txt: Ditto Canonical link: https://commits.webkit.org/317933@main
1 parent 63d08db commit 01aaa3e

5 files changed

Lines changed: 7 additions & 17 deletions

File tree

‎LayoutTests/TestExpectations‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5904,8 +5904,6 @@ http/wpt/crypto/aes-ctr-crash.any.html [ DumpJSConsoleLogInStdErr ]
59045904
webkit.org/b/228176 fast/text/variable-system-font.html [ Pass ImageOnlyFailure ]
59055905
webkit.org/b/228176 fast/text/variable-system-font-2.html [ Pass ImageOnlyFailure ]
59065906

5907-
webkit.org/b/230237 imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-inline-image.html [ Failure ]
5908-
59095907
webkit.org/b/230004 imported/w3c/web-platform-tests/css/css-pseudo/active-selection-012.html [ ImageOnlyFailure ]
59105908
webkit.org/b/230004 imported/w3c/web-platform-tests/css/css-pseudo/active-selection-014.html [ ImageOnlyFailure ]
59115909
webkit.org/b/230004 imported/w3c/web-platform-tests/css/css-pseudo/active-selection-018.html [ ImageOnlyFailure ]

‎LayoutTests/platform/glib/fast/dynamic/anchor-lock-expected.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ layer at (0,0) size 785x2122
3636
RenderBlock (anonymous) at (0,2088) size 769x19
3737
RenderText {#text} at (0,0) size 59x18
3838
text run at (0,0) width 59: "#anchor1"
39-
scrolled to 0,983
39+
scrolled to 0,982

‎LayoutTests/platform/glib/fast/scrolling/scroll-to-anchor-zoomed-header-expected.txt‎

Lines changed: 0 additions & 11 deletions
This file was deleted.

‎LayoutTests/platform/ios/fast/dynamic/anchor-lock-expected.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ layer at (0,0) size 800x2131
3636
RenderBlock (anonymous) at (0,2095) size 784x21
3737
RenderText {#text} at (0,0) size 60x20
3838
text run at (0,0) width 60: "#anchor1"
39-
scrolled to 0,988
39+
scrolled to 0,987

‎Source/WebCore/rendering/RenderElement.cpp‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,8 +2123,11 @@ bool RenderElement::getLeadingCorner(FloatPoint& point, bool& insideFixed) const
21232123
} else if (is<RenderText>(*o) || o->isBlockLevelReplacedOrAtomicInline()) {
21242124
point = FloatPoint();
21252125
if (CheckedPtr textRenderer = dynamicDowncast<RenderText>(*o)) {
2126-
if (auto run = InlineIterator::lineLeftmostTextBoxFor(*textRenderer))
2127-
point.move(textRenderer->linesBoundingBox().x(), run->lineBox()->contentLogicalTop());
2126+
// Use the text's own bounding box rather than the line box top, so that an inline
2127+
// element sharing a tall line (e.g. with a large image) scrolls to its actual
2128+
// position. This mirrors getTrailingCorner()'s use of linesBoundingBox().
2129+
if (InlineIterator::lineLeftmostTextBoxFor(*textRenderer))
2130+
point.moveBy(textRenderer->linesBoundingBox().location());
21282131
} else if (auto* box = dynamicDowncast<RenderBox>(*o))
21292132
point.moveBy(box->location());
21302133
point = o->container()->localToAbsolute(point, MapCoordinatesMode::UseTransforms, &insideFixed);

0 commit comments

Comments
 (0)