Title: [247255] trunk
Revision
247255
Author
[email protected]
Date
2019-07-09 03:03:19 -0700 (Tue, 09 Jul 2019)

Log Message

Support writing-mode and direction for scrollIntoViewOptions.
https://bugs.webkit.org/show_bug.cgi?id=161611

Patch by Cathie Chen <[email protected]> on 2019-07-09
Reviewed by Frédéric Wang and Simon Fraser.

LayoutTests/imported/w3c:

* web-platform-tests/css/cssom-view/scrollIntoView-horizontal-tb-writing-mode-and-rtl-direction-expected.txt:
* web-platform-tests/css/cssom-view/scrollIntoView-vertical-lr-writing-mode-and-rtl-direction-expected.txt:
* web-platform-tests/css/cssom-view/scrollIntoView-vertical-lr-writing-mode-expected.txt:
* web-platform-tests/css/cssom-view/scrollIntoView-vertical-rl-writing-mode-expected.txt:

Source/WebCore:

To determine which physical side to align we need to transform ScrollIntoViewOptions to scrollAlignment.
We'll translate the inline and block direction separately. The writing-mode will affect the block scrollAlignment.
While both writing-mode and CSS direction will affect the inline scrollAlignment. The argument for scrollRectToVisible
should be physical, so if !isHorizontalWritingMode(), we need to switch alignX and alignY.

For direction: rtl and writing-mode: horizontal-tb box, WebKit puts the scrollbar on the left side. The visible rect
starts from the right side of the scroll bar, so localExposeRect should also start from the right side of
scroll bar.

* dom/Element.cpp:
(WebCore::toScrollAlignmentForInlineDirection):
(WebCore::toScrollAlignmentForBlockDirection):
(WebCore::Element::scrollIntoView):
(WebCore::toScrollAlignment): Deleted.
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::scrollRectToVisible):

LayoutTests:

* platform/ios-simulator-wk2/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-horizontal-tb-writing-mode-and-rtl-direction-expected.txt: Removed.

Modified Paths

Removed Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (247254 => 247255)


--- trunk/LayoutTests/ChangeLog	2019-07-09 05:32:26 UTC (rev 247254)
+++ trunk/LayoutTests/ChangeLog	2019-07-09 10:03:19 UTC (rev 247255)
@@ -1,3 +1,12 @@
+2019-07-09  Cathie Chen  <[email protected]>
+
+        Support writing-mode and direction for scrollIntoViewOptions.
+        https://bugs.webkit.org/show_bug.cgi?id=161611
+
+        Reviewed by Frédéric Wang and Simon Fraser.
+
+        * platform/ios-simulator-wk2/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-horizontal-tb-writing-mode-and-rtl-direction-expected.txt: Removed.
+
 2019-07-08  Saam Barati  <[email protected]>
 
         [WHLSL Import 23 new JS reference spec tests

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (247254 => 247255)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2019-07-09 05:32:26 UTC (rev 247254)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2019-07-09 10:03:19 UTC (rev 247255)
@@ -1,3 +1,15 @@
+2019-07-09  Cathie Chen  <[email protected]>
+
+        Support writing-mode and direction for scrollIntoViewOptions.
+        https://bugs.webkit.org/show_bug.cgi?id=161611
+
+        Reviewed by Frédéric Wang and Simon Fraser.
+
+        * web-platform-tests/css/cssom-view/scrollIntoView-horizontal-tb-writing-mode-and-rtl-direction-expected.txt:
+        * web-platform-tests/css/cssom-view/scrollIntoView-vertical-lr-writing-mode-and-rtl-direction-expected.txt:
+        * web-platform-tests/css/cssom-view/scrollIntoView-vertical-lr-writing-mode-expected.txt:
+        * web-platform-tests/css/cssom-view/scrollIntoView-vertical-rl-writing-mode-expected.txt:
+
 2019-07-06  Cathie Chen  <[email protected]>
 
         Import css/cssom-view testcases from WPT.

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-horizontal-tb-writing-mode-and-rtl-direction-expected.txt (247254 => 247255)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-horizontal-tb-writing-mode-and-rtl-direction-expected.txt	2019-07-09 05:32:26 UTC (rev 247254)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-horizontal-tb-writing-mode-and-rtl-direction-expected.txt	2019-07-09 10:03:19 UTC (rev 247255)
@@ -1,11 +1,11 @@
 
-FAIL scrollIntoView({"block":"start","inline":"start"}) assert_approx_equals: scrollX expected -200 +/- 0.5 but got -100
-FAIL scrollIntoView({"block":"start","inline":"center"}) assert_approx_equals: scrollX expected -157.5 +/- 0.5 but got -143
-FAIL scrollIntoView({"block":"start","inline":"end"}) assert_approx_equals: scrollX expected -115 +/- 0.5 but got -185
-FAIL scrollIntoView({"block":"center","inline":"start"}) assert_approx_equals: scrollX expected -200 +/- 0.5 but got -100
-FAIL scrollIntoView({"block":"center","inline":"center"}) assert_approx_equals: scrollX expected -157.5 +/- 0.5 but got -143
-FAIL scrollIntoView({"block":"center","inline":"end"}) assert_approx_equals: scrollX expected -115 +/- 0.5 but got -185
-FAIL scrollIntoView({"block":"end","inline":"start"}) assert_approx_equals: scrollX expected -200 +/- 0.5 but got -100
-FAIL scrollIntoView({"block":"end","inline":"center"}) assert_approx_equals: scrollX expected -157.5 +/- 0.5 but got -143
-FAIL scrollIntoView({"block":"end","inline":"end"}) assert_approx_equals: scrollX expected -115 +/- 0.5 but got -185
+PASS scrollIntoView({"block":"start","inline":"start"}) 
+PASS scrollIntoView({"block":"start","inline":"center"}) 
+PASS scrollIntoView({"block":"start","inline":"end"}) 
+PASS scrollIntoView({"block":"center","inline":"start"}) 
+PASS scrollIntoView({"block":"center","inline":"center"}) 
+PASS scrollIntoView({"block":"center","inline":"end"}) 
+PASS scrollIntoView({"block":"end","inline":"start"}) 
+PASS scrollIntoView({"block":"end","inline":"center"}) 
+PASS scrollIntoView({"block":"end","inline":"end"}) 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-vertical-lr-writing-mode-and-rtl-direction-expected.txt (247254 => 247255)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-vertical-lr-writing-mode-and-rtl-direction-expected.txt	2019-07-09 05:32:26 UTC (rev 247254)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-vertical-lr-writing-mode-and-rtl-direction-expected.txt	2019-07-09 10:03:19 UTC (rev 247255)
@@ -1,11 +1,11 @@
 
-FAIL scrollIntoView({"block":"start","inline":"start"}) assert_approx_equals: scrollY expected -200 +/- 0.5 but got -115
-FAIL scrollIntoView({"block":"start","inline":"center"}) assert_approx_equals: scrollX expected 200 +/- 0.5 but got 158
-FAIL scrollIntoView({"block":"start","inline":"end"}) assert_approx_equals: scrollX expected 200 +/- 0.5 but got 115
-FAIL scrollIntoView({"block":"center","inline":"start"}) assert_approx_equals: scrollX expected 157.5 +/- 0.5 but got 200
+PASS scrollIntoView({"block":"start","inline":"start"}) 
+PASS scrollIntoView({"block":"start","inline":"center"}) 
+PASS scrollIntoView({"block":"start","inline":"end"}) 
+PASS scrollIntoView({"block":"center","inline":"start"}) 
 PASS scrollIntoView({"block":"center","inline":"center"}) 
-FAIL scrollIntoView({"block":"center","inline":"end"}) assert_approx_equals: scrollX expected 157.5 +/- 0.5 but got 115
-FAIL scrollIntoView({"block":"end","inline":"start"}) assert_approx_equals: scrollX expected 115 +/- 0.5 but got 200
-FAIL scrollIntoView({"block":"end","inline":"center"}) assert_approx_equals: scrollX expected 115 +/- 0.5 but got 158
-FAIL scrollIntoView({"block":"end","inline":"end"}) assert_approx_equals: scrollY expected -115 +/- 0.5 but got -200
+PASS scrollIntoView({"block":"center","inline":"end"}) 
+PASS scrollIntoView({"block":"end","inline":"start"}) 
+PASS scrollIntoView({"block":"end","inline":"center"}) 
+PASS scrollIntoView({"block":"end","inline":"end"}) 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-vertical-lr-writing-mode-expected.txt (247254 => 247255)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-vertical-lr-writing-mode-expected.txt	2019-07-09 05:32:26 UTC (rev 247254)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-vertical-lr-writing-mode-expected.txt	2019-07-09 10:03:19 UTC (rev 247255)
@@ -1,11 +1,11 @@
 
 PASS scrollIntoView({"block":"start","inline":"start"}) 
-FAIL scrollIntoView({"block":"start","inline":"center"}) assert_approx_equals: scrollX expected 200 +/- 0.5 but got 158
-FAIL scrollIntoView({"block":"start","inline":"end"}) assert_approx_equals: scrollX expected 200 +/- 0.5 but got 115
-FAIL scrollIntoView({"block":"center","inline":"start"}) assert_approx_equals: scrollX expected 157.5 +/- 0.5 but got 200
+PASS scrollIntoView({"block":"start","inline":"center"}) 
+PASS scrollIntoView({"block":"start","inline":"end"}) 
+PASS scrollIntoView({"block":"center","inline":"start"}) 
 PASS scrollIntoView({"block":"center","inline":"center"}) 
-FAIL scrollIntoView({"block":"center","inline":"end"}) assert_approx_equals: scrollX expected 157.5 +/- 0.5 but got 115
-FAIL scrollIntoView({"block":"end","inline":"start"}) assert_approx_equals: scrollX expected 115 +/- 0.5 but got 200
-FAIL scrollIntoView({"block":"end","inline":"center"}) assert_approx_equals: scrollX expected 115 +/- 0.5 but got 158
+PASS scrollIntoView({"block":"center","inline":"end"}) 
+PASS scrollIntoView({"block":"end","inline":"start"}) 
+PASS scrollIntoView({"block":"end","inline":"center"}) 
 PASS scrollIntoView({"block":"end","inline":"end"}) 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-vertical-rl-writing-mode-expected.txt (247254 => 247255)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-vertical-rl-writing-mode-expected.txt	2019-07-09 05:32:26 UTC (rev 247254)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-vertical-rl-writing-mode-expected.txt	2019-07-09 10:03:19 UTC (rev 247255)
@@ -1,11 +1,11 @@
 
-FAIL scrollIntoView({"block":"start","inline":"start"}) assert_approx_equals: scrollX expected -185 +/- 0.5 but got -100
-FAIL scrollIntoView({"block":"start","inline":"center"}) assert_approx_equals: scrollX expected -185 +/- 0.5 but got -143
-FAIL scrollIntoView({"block":"start","inline":"end"}) assert_approx_equals: scrollY expected 115 +/- 0.5 but got 200
-FAIL scrollIntoView({"block":"center","inline":"start"}) assert_approx_equals: scrollX expected -142.5 +/- 0.5 but got -100
+PASS scrollIntoView({"block":"start","inline":"start"}) 
+PASS scrollIntoView({"block":"start","inline":"center"}) 
+PASS scrollIntoView({"block":"start","inline":"end"}) 
+PASS scrollIntoView({"block":"center","inline":"start"}) 
 PASS scrollIntoView({"block":"center","inline":"center"}) 
-FAIL scrollIntoView({"block":"center","inline":"end"}) assert_approx_equals: scrollX expected -142.5 +/- 0.5 but got -185
-FAIL scrollIntoView({"block":"end","inline":"start"}) assert_approx_equals: scrollY expected 200 +/- 0.5 but got 115
-FAIL scrollIntoView({"block":"end","inline":"center"}) assert_approx_equals: scrollX expected -100 +/- 0.5 but got -143
-FAIL scrollIntoView({"block":"end","inline":"end"}) assert_approx_equals: scrollX expected -100 +/- 0.5 but got -185
+PASS scrollIntoView({"block":"center","inline":"end"}) 
+PASS scrollIntoView({"block":"end","inline":"start"}) 
+PASS scrollIntoView({"block":"end","inline":"center"}) 
+PASS scrollIntoView({"block":"end","inline":"end"}) 
 

Deleted: trunk/LayoutTests/platform/ios-simulator-wk2/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-horizontal-tb-writing-mode-and-rtl-direction-expected.txt (247254 => 247255)


--- trunk/LayoutTests/platform/ios-simulator-wk2/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-horizontal-tb-writing-mode-and-rtl-direction-expected.txt	2019-07-09 05:32:26 UTC (rev 247254)
+++ trunk/LayoutTests/platform/ios-simulator-wk2/imported/w3c/web-platform-tests/css/cssom-view/scrollIntoView-horizontal-tb-writing-mode-and-rtl-direction-expected.txt	2019-07-09 10:03:19 UTC (rev 247255)
@@ -1,11 +0,0 @@
-
-FAIL scrollIntoView({"block":"start","inline":"start"}) assert_approx_equals: scrollX expected -200 +/- 0.5 but got -115
-PASS scrollIntoView({"block":"start","inline":"center"}) 
-FAIL scrollIntoView({"block":"start","inline":"end"}) assert_approx_equals: scrollX expected -115 +/- 0.5 but got -200
-FAIL scrollIntoView({"block":"center","inline":"start"}) assert_approx_equals: scrollX expected -200 +/- 0.5 but got -115
-PASS scrollIntoView({"block":"center","inline":"center"}) 
-FAIL scrollIntoView({"block":"center","inline":"end"}) assert_approx_equals: scrollX expected -115 +/- 0.5 but got -200
-FAIL scrollIntoView({"block":"end","inline":"start"}) assert_approx_equals: scrollX expected -200 +/- 0.5 but got -115
-PASS scrollIntoView({"block":"end","inline":"center"}) 
-FAIL scrollIntoView({"block":"end","inline":"end"}) assert_approx_equals: scrollX expected -115 +/- 0.5 but got -200
-

Modified: trunk/Source/WebCore/ChangeLog (247254 => 247255)


--- trunk/Source/WebCore/ChangeLog	2019-07-09 05:32:26 UTC (rev 247254)
+++ trunk/Source/WebCore/ChangeLog	2019-07-09 10:03:19 UTC (rev 247255)
@@ -1,3 +1,27 @@
+2019-07-09  Cathie Chen  <[email protected]>
+
+        Support writing-mode and direction for scrollIntoViewOptions.
+        https://bugs.webkit.org/show_bug.cgi?id=161611
+
+        Reviewed by Frédéric Wang and Simon Fraser.
+
+        To determine which physical side to align we need to transform ScrollIntoViewOptions to scrollAlignment.
+        We'll translate the inline and block direction separately. The writing-mode will affect the block scrollAlignment.
+        While both writing-mode and CSS direction will affect the inline scrollAlignment. The argument for scrollRectToVisible
+        should be physical, so if !isHorizontalWritingMode(), we need to switch alignX and alignY.
+
+        For direction: rtl and writing-mode: horizontal-tb box, WebKit puts the scrollbar on the left side. The visible rect
+        starts from the right side of the scroll bar, so localExposeRect should also start from the right side of
+        scroll bar.
+
+        * dom/Element.cpp:
+        (WebCore::toScrollAlignmentForInlineDirection):
+        (WebCore::toScrollAlignmentForBlockDirection):
+        (WebCore::Element::scrollIntoView):
+        (WebCore::toScrollAlignment): Deleted.
+        * rendering/RenderLayer.cpp:
+        (WebCore::RenderLayer::scrollRectToVisible):
+
 2019-07-08  Saam Barati  <[email protected]>
 
         [WHLSL Import 23 new JS reference spec tests

Modified: trunk/Source/WebCore/dom/Element.cpp (247254 => 247255)


--- trunk/Source/WebCore/dom/Element.cpp	2019-07-09 05:32:26 UTC (rev 247254)
+++ trunk/Source/WebCore/dom/Element.cpp	2019-07-09 10:03:19 UTC (rev 247255)
@@ -701,16 +701,41 @@
         renderer()->theme().stateChanged(*renderer(), ControlStates::HoverState);
 }
 
-// FIXME(webkit.org/b/161611): Take into account orientation/direction.
-inline ScrollAlignment toScrollAlignment(Optional<ScrollLogicalPosition> position, bool isVertical)
+inline ScrollAlignment toScrollAlignmentForInlineDirection(Optional<ScrollLogicalPosition> position, WritingMode writingMode, bool isLTR)
 {
-    switch (position.valueOr(isVertical ? ScrollLogicalPosition::Start : ScrollLogicalPosition::Nearest)) {
-    case ScrollLogicalPosition::Start:
-        return isVertical ? ScrollAlignment::alignTopAlways : ScrollAlignment::alignLeftAlways;
+    switch (position.valueOr(ScrollLogicalPosition::Nearest)) {
+    case ScrollLogicalPosition::Start: {
+        switch (writingMode) {
+        case TopToBottomWritingMode:
+        case BottomToTopWritingMode: {
+            return isLTR ? ScrollAlignment::alignLeftAlways : ScrollAlignment::alignRightAlways;
+        }
+        case LeftToRightWritingMode:
+        case RightToLeftWritingMode: {
+            return isLTR ? ScrollAlignment::alignTopAlways : ScrollAlignment::alignBottomAlways;
+        }
+        default:
+            ASSERT_NOT_REACHED();
+            return ScrollAlignment::alignLeftAlways;
+        }
+    }
     case ScrollLogicalPosition::Center:
         return ScrollAlignment::alignCenterAlways;
-    case ScrollLogicalPosition::End:
-        return isVertical ? ScrollAlignment::alignBottomAlways : ScrollAlignment::alignRightAlways;
+    case ScrollLogicalPosition::End: {
+        switch (writingMode) {
+        case TopToBottomWritingMode:
+        case BottomToTopWritingMode: {
+            return isLTR ? ScrollAlignment::alignRightAlways : ScrollAlignment::alignLeftAlways;
+        }
+        case LeftToRightWritingMode:
+        case RightToLeftWritingMode: {
+            return isLTR ? ScrollAlignment::alignBottomAlways : ScrollAlignment::alignTopAlways;
+        }
+        default:
+            ASSERT_NOT_REACHED();
+            return ScrollAlignment::alignRightAlways;
+        }
+    }
     case ScrollLogicalPosition::Nearest:
         return ScrollAlignment::alignToEdgeIfNeeded;
     default:
@@ -719,6 +744,49 @@
     }
 }
 
+inline ScrollAlignment toScrollAlignmentForBlockDirection(Optional<ScrollLogicalPosition> position, WritingMode writingMode)
+{
+    switch (position.valueOr(ScrollLogicalPosition::Start)) {
+    case ScrollLogicalPosition::Start: {
+        switch (writingMode) {
+        case TopToBottomWritingMode:
+            return ScrollAlignment::alignTopAlways;
+        case BottomToTopWritingMode:
+            return ScrollAlignment::alignBottomAlways;
+        case LeftToRightWritingMode:
+            return ScrollAlignment::alignLeftAlways;
+        case RightToLeftWritingMode:
+            return ScrollAlignment::alignRightAlways;
+        default:
+            ASSERT_NOT_REACHED();
+            return ScrollAlignment::alignTopAlways;
+        }
+    }
+    case ScrollLogicalPosition::Center:
+        return ScrollAlignment::alignCenterAlways;
+    case ScrollLogicalPosition::End: {
+        switch (writingMode) {
+        case TopToBottomWritingMode:
+            return ScrollAlignment::alignBottomAlways;
+        case BottomToTopWritingMode:
+            return ScrollAlignment::alignTopAlways;
+        case LeftToRightWritingMode:
+            return ScrollAlignment::alignRightAlways;
+        case RightToLeftWritingMode:
+            return ScrollAlignment::alignLeftAlways;
+        default:
+            ASSERT_NOT_REACHED();
+            return ScrollAlignment::alignBottomAlways;
+        }
+    }
+    case ScrollLogicalPosition::Nearest:
+        return ScrollAlignment::alignToEdgeIfNeeded;
+    default:
+        ASSERT_NOT_REACHED();
+        return ScrollAlignment::alignToEdgeIfNeeded;
+    }
+}
+
 void Element::scrollIntoView(Optional<Variant<bool, ScrollIntoViewOptions>>&& arg)
 {
     document().updateLayoutIgnorePendingStylesheets();
@@ -739,9 +807,18 @@
             options.blockPosition = ScrollLogicalPosition::End;
     }
 
-    ScrollAlignment alignX = toScrollAlignment(options.inlinePosition, false);
-    ScrollAlignment alignY = toScrollAlignment(options.blockPosition, true);
-    renderer()->scrollRectToVisible(absoluteBounds, insideFixed, { SelectionRevealMode::Reveal, alignX, alignY, ShouldAllowCrossOriginScrolling::No });
+    auto writingMode = renderer()->style().writingMode();
+    ScrollAlignment alignX = toScrollAlignmentForInlineDirection(options.inlinePosition, writingMode, renderer()->style().isLeftToRightDirection());
+    ScrollAlignment alignY = toScrollAlignmentForBlockDirection(options.blockPosition, writingMode);
+
+    bool isHorizontal = renderer()->style().isHorizontalWritingMode();
+    ScrollRectToVisibleOptions visibleOptions {
+        SelectionRevealMode::Reveal,
+        isHorizontal ? alignX : alignY,
+        isHorizontal ? alignY : alignX,
+        ShouldAllowCrossOriginScrolling::No
+    };
+    renderer()->scrollRectToVisible(absoluteBounds, insideFixed, visibleOptions);
 }
 
 void Element::scrollIntoView(bool alignToTop) 

Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (247254 => 247255)


--- trunk/Source/WebCore/rendering/RenderLayer.cpp	2019-07-09 05:32:26 UTC (rev 247254)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp	2019-07-09 10:03:19 UTC (rev 247255)
@@ -2623,6 +2623,11 @@
         RenderBox* box = renderBox();
         ASSERT(box);
         LayoutRect localExposeRect(box->absoluteToLocalQuad(FloatQuad(FloatRect(absoluteRect))).boundingBox());
+        if (shouldPlaceBlockDirectionScrollbarOnLeft()) {
+            // For direction: rtl; writing-mode: horizontal-tb box, the scroll bar is on the left side. The visible rect
+            // starts from the right side of scroll bar. So the x of localExposeRect should start from the same position too.
+            localExposeRect.moveBy(LayoutPoint(-verticalScrollbarWidth(), 0));
+        }
         LayoutRect layerBounds(0_lu, 0_lu, box->clientWidth(), box->clientHeight());
         LayoutRect revealRect = getRectToExpose(layerBounds, localExposeRect, insideFixed, options.alignX, options.alignY);
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to