Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (288946 => 288947)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2022-02-02 08:40:41 UTC (rev 288946)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2022-02-02 09:12:57 UTC (rev 288947)
@@ -1,3 +1,14 @@
+2022-02-02 Martin Robinson <[email protected]>
+
+ scroll-margin-top doesn't work on inline elements
+ https://bugs.webkit.org/show_bug.cgi?id=235933
+ <rdar://87983307>
+
+ Reviewed by Simon Fraser.
+
+ * web-platform-tests/css/css-scroll-snap/scroll-target-margin-006-expected.txt: Added.
+ * web-platform-tests/css/css-scroll-snap/scroll-target-margin-006.html: Added.
+
2022-02-01 Antti Koivisto <[email protected]>
[CSS Container Queries] Ensure query containers have valid layout before resolving the subtree
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/scroll-target-margin-006-expected.txt (0 => 288947)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/scroll-target-margin-006-expected.txt (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/scroll-target-margin-006-expected.txt 2022-02-02 09:12:57 UTC (rev 288947)
@@ -0,0 +1,4 @@
+XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX TARGETTARGETTARGETTARGET XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+
+PASS scroll-margin is taken into account when scrolling an inline element into view
+
Added: trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/scroll-target-margin-006.html (0 => 288947)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/scroll-target-margin-006.html (rev 0)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/css-scroll-snap/scroll-target-margin-006.html 2022-02-02 09:12:57 UTC (rev 288947)
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html>
+<title>scrollIntoView() and scroll-margin applied to an inline element</title>
+<link rel='author' title='Martin Robinson' href=''>
+<link rel='help' href=''>
+<script src=""
+<script src=""
+
+<style type='text/css'>
+ .container {
+ border: solid black 1px;
+ height: 40px;
+ width: 40px;
+ overflow: auto;
+ }
+</style>
+
+<div class="container">
+ <div style="height: 1000px; width: 2000px;"></div>
+ <div style="width: 2000px;">
+ <span>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</span>
+ <span id="target">TARGETTARGETTARGETTARGET</span>
+ <span>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</span>
+ </div>
+ <div style="height: 1000px; width: 2000px;"></div>
+</div>
+
+<script>
+
+test(() => {
+ target.scrollIntoView();
+ const scroller = target.parentElement.parentElement;
+ let expectedScrollPosition = [scroller.scrollLeft - 20, scroller.scrollTop - 20];
+ scroller.scrollTo(0, 0);
+
+ target.style.scrollMarginTop = "20px";
+ target.style.scrollMarginLeft = "20px";
+ target.scrollIntoView();
+ assert_equals(scroller.scrollLeft, expectedScrollPosition[0]);
+ assert_equals(scroller.scrollTop, expectedScrollPosition[1]);
+
+ target.style.scrollMarginTop = "0px";
+ target.style.scrollMarginLeft = "0px";
+
+ scroller.scrollTo(2000, 2000);
+ target.scrollIntoView({"block": "end", "inline": "end"});
+ expectedScrollPosition = [scroller.scrollLeft + 20, scroller.scrollTop + 20];
+ scroller.scrollTo(2000, 2000);
+
+ target.style.scrollMarginBottom = "20px";
+ target.style.scrollMarginRight = "20px";
+ target.scrollIntoView({"block": "end", "inline": "end"});
+ assert_equals(scroller.scrollLeft, expectedScrollPosition[0]);
+ assert_equals(scroller.scrollTop, expectedScrollPosition[1]);
+
+}, "scroll-margin is taken into account when scrolling an inline element into view");
+</script>
Modified: trunk/Source/WebCore/ChangeLog (288946 => 288947)
--- trunk/Source/WebCore/ChangeLog 2022-02-02 08:40:41 UTC (rev 288946)
+++ trunk/Source/WebCore/ChangeLog 2022-02-02 09:12:57 UTC (rev 288947)
@@ -1,3 +1,26 @@
+2022-02-02 Martin Robinson <[email protected]>
+
+ scroll-margin-top doesn't work on inline elements
+ https://bugs.webkit.org/show_bug.cgi?id=235933
+ <rdar://87983307>
+
+ Reviewed by Simon Fraser.
+
+ Test: imported/w3c/web-platform-tests/css/css-scroll-snap/scroll-target-margin-005.html
+
+ Move the implementation of absoluteAnchorRectWithScrollMargin which actually processes
+ the CSS scroll-margin property to RenderElement. This allows it to be used for inline
+ as well as block elements. The specification says it should apply to both. The box
+ sizes passed in here do not matter too much, because the Length should never be a
+ percentage.
+
+ * rendering/RenderBox.cpp:
+ (WebCore::RenderBox::absoluteAnchorRectWithScrollMargin const): Deleted.
+ * rendering/RenderBox.h:
+ * rendering/RenderElement.cpp:
+ (WebCore::RenderElement::absoluteAnchorRectWithScrollMargin const):
+ * rendering/RenderElement.h:
+
2022-02-01 Alan Bujtas <[email protected]>
[LFC][IFC] Using Fontcascade::spaceWidth to subtract the trailing space width may result in incorrect layout
Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (288946 => 288947)
--- trunk/Source/WebCore/rendering/RenderBox.cpp 2022-02-02 08:40:41 UTC (rev 288946)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp 2022-02-02 09:12:57 UTC (rev 288947)
@@ -5472,28 +5472,6 @@
return containerBlock->offsetFromLogicalTopOfFirstPage() + logicalTop();
}
-LayoutRect RenderBox::absoluteAnchorRectWithScrollMargin(bool* insideFixed) const
-{
- LayoutRect anchorRect = absoluteAnchorRect(insideFixed);
- const LengthBox& scrollMargin = style().scrollMargin();
- if (scrollMargin.isZero())
- return anchorRect;
-
- // The scroll snap specification says that the scroll-margin should be applied in the
- // coordinate system of the scroll container and applied to the rectangular bounding
- // box of the transformed border box of the target element.
- // See https://www.w3.org/TR/css-scroll-snap-1/#scroll-margin.
- const LayoutSize boxSize = size();
- const LayoutBoxExtent margin(
- valueForLength(scrollMargin.top(), boxSize.height()),
- valueForLength(scrollMargin.right(), boxSize.width()),
- valueForLength(scrollMargin.bottom(), boxSize.height()),
- valueForLength(scrollMargin.left(), boxSize.width()));
- anchorRect.expand(margin);
-
- return anchorRect;
-}
-
LayoutBoxExtent RenderBox::scrollPaddingForViewportRect(const LayoutRect& viewportRect)
{
// We are using minimumValueForLength here, because scroll-padding values might be "auto". WebKit currently
Modified: trunk/Source/WebCore/rendering/RenderBox.h (288946 => 288947)
--- trunk/Source/WebCore/rendering/RenderBox.h 2022-02-02 08:40:41 UTC (rev 288946)
+++ trunk/Source/WebCore/rendering/RenderBox.h 2022-02-02 09:12:57 UTC (rev 288947)
@@ -669,8 +669,6 @@
virtual void adjustBorderBoxRectForPainting(LayoutRect&) { };
- LayoutRect absoluteAnchorRectWithScrollMargin(bool* insideFixed = nullptr) const override;
-
bool shouldComputeLogicalHeightFromAspectRatio() const;
protected:
Modified: trunk/Source/WebCore/rendering/RenderElement.cpp (288946 => 288947)
--- trunk/Source/WebCore/rendering/RenderElement.cpp 2022-02-02 08:40:41 UTC (rev 288946)
+++ trunk/Source/WebCore/rendering/RenderElement.cpp 2022-02-02 09:12:57 UTC (rev 288947)
@@ -1734,7 +1734,22 @@
LayoutRect RenderElement::absoluteAnchorRectWithScrollMargin(bool* insideFixed) const
{
- return absoluteAnchorRect(insideFixed);
+ LayoutRect anchorRect = absoluteAnchorRect(insideFixed);
+ const LengthBox& scrollMargin = style().scrollMargin();
+ if (scrollMargin.isZero())
+ return anchorRect;
+
+ // The scroll snap specification says that the scroll-margin should be applied in the
+ // coordinate system of the scroll container and applied to the rectangular bounding
+ // box of the transformed border box of the target element.
+ // See https://www.w3.org/TR/css-scroll-snap-1/#scroll-margin.
+ const LayoutBoxExtent margin(
+ valueForLength(scrollMargin.top(), anchorRect.height()),
+ valueForLength(scrollMargin.right(), anchorRect.width()),
+ valueForLength(scrollMargin.bottom(), anchorRect.height()),
+ valueForLength(scrollMargin.left(), anchorRect.width()));
+ anchorRect.expand(margin);
+ return anchorRect;
}
void RenderElement::drawLineForBoxSide(GraphicsContext& graphicsContext, const FloatRect& rect, BoxSide side, Color color, BorderStyle borderStyle, float adjacentWidth1, float adjacentWidth2, bool antialias) const
Modified: trunk/Source/WebCore/rendering/RenderElement.h (288946 => 288947)
--- trunk/Source/WebCore/rendering/RenderElement.h 2022-02-02 08:40:41 UTC (rev 288946)
+++ trunk/Source/WebCore/rendering/RenderElement.h 2022-02-02 09:12:57 UTC (rev 288947)
@@ -190,7 +190,7 @@
// absoluteAnchorRectWithScrollMargin() is similar to absoluteAnchorRect, but it also takes into account any
// CSS scroll-margin that is set in the style of this RenderElement.
- virtual LayoutRect absoluteAnchorRectWithScrollMargin(bool* insideFixed = nullptr) const;
+ LayoutRect absoluteAnchorRectWithScrollMargin(bool* insideFixed = nullptr) const;
bool hasFilter() const { return style().hasFilter(); }
bool hasBackdropFilter() const