Title: [205505] trunk
Revision
205505
Author
[email protected]
Date
2016-09-06 14:18:06 -0700 (Tue, 06 Sep 2016)

Log Message

Align element.scroll() / scrollTo() / scrollBy() with the CSSOM specification
https://bugs.webkit.org/show_bug.cgi?id=161610

Reviewed by Darin Adler, Chris Dumez.

Source/WebCore:

Implement Element.scroll(), scrollBy() and scrollTo() with x,y and ScrollToOptions
on Element, according to <https://drafts.csswg.org/cssom-view/#element-scrolling-members>

WebKit's behavior of treating scrolls on the body element in both quirks and strict mode
is preserved.

Tests: fast/dom/Element/scrolling-funtions-on-body-quirks.html
       fast/dom/Element/scrolling-funtions-on-body.html
       fast/dom/Element/scrolling-funtions-on-element.html

* dom/Element.cpp:
(WebCore::Element::scrollBy):
(WebCore::normalizeNonFiniteValue):
(WebCore::Element::scrollTo):
* dom/Element.h:
* dom/Element.idl:
* html/HTMLBodyElement.cpp:
(WebCore::HTMLBodyElement::scrollTo):
* html/HTMLBodyElement.h:

LayoutTests:

* fast/dom/Element/scrolling-funtions-on-body-expected.txt: Added.
* fast/dom/Element/scrolling-funtions-on-body-quirks-expected.txt: Added.
* fast/dom/Element/scrolling-funtions-on-body-quirks.html: Added.
* fast/dom/Element/scrolling-funtions-on-body.html: Added.
* fast/dom/Element/scrolling-funtions-on-element-expected.txt: Added.
* fast/dom/Element/scrolling-funtions-on-element.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (205504 => 205505)


--- trunk/LayoutTests/ChangeLog	2016-09-06 21:13:25 UTC (rev 205504)
+++ trunk/LayoutTests/ChangeLog	2016-09-06 21:18:06 UTC (rev 205505)
@@ -1,3 +1,17 @@
+2016-09-06  Simon Fraser  <[email protected]>
+
+        Align element.scroll() / scrollTo() / scrollBy() with the CSSOM specification
+        https://bugs.webkit.org/show_bug.cgi?id=161610
+
+        Reviewed by Darin Adler, Chris Dumez.
+
+        * fast/dom/Element/scrolling-funtions-on-body-expected.txt: Added.
+        * fast/dom/Element/scrolling-funtions-on-body-quirks-expected.txt: Added.
+        * fast/dom/Element/scrolling-funtions-on-body-quirks.html: Added.
+        * fast/dom/Element/scrolling-funtions-on-body.html: Added.
+        * fast/dom/Element/scrolling-funtions-on-element-expected.txt: Added.
+        * fast/dom/Element/scrolling-funtions-on-element.html: Added.
+
 2016-09-06  Ryan Haddad  <[email protected]>
 
         Skip some asserting Fetch API tests.

Added: trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-expected.txt (0 => 205505)


--- trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-expected.txt	2016-09-06 21:18:06 UTC (rev 205505)
@@ -0,0 +1,21 @@
+Tests scrollTo/By(x,y) and scrollTo/By(scrollOptions) on the body. WebKit always uses quirks mode for body scrolling behavior, so this scrolls the window.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS scroller.scrollLeft is 20
+PASS scroller.scrollTop is 500
+PASS window.scrollX is 20
+PASS window.scrollY is 500
+PASS scroller.scrollLeft is 70
+PASS scroller.scrollTop is 560
+PASS window.scrollX is 70
+PASS window.scrollY is 560
+PASS scroller.scrollLeft is 100
+PASS scroller.scrollTop is 400
+PASS window.scrollX is 100
+PASS window.scrollY is 400
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-quirks-expected.txt (0 => 205505)


--- trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-quirks-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-quirks-expected.txt	2016-09-06 21:18:06 UTC (rev 205505)
@@ -0,0 +1,21 @@
+Tests scrollTo/By(x,y) and scrollTo/By(scrollOptions) on the body in quirks mode.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS scroller.scrollLeft is 20
+PASS scroller.scrollTop is 500
+PASS window.scrollX is 20
+PASS window.scrollY is 500
+PASS scroller.scrollLeft is 70
+PASS scroller.scrollTop is 560
+PASS window.scrollX is 70
+PASS window.scrollY is 560
+PASS scroller.scrollLeft is 100
+PASS scroller.scrollTop is 400
+PASS window.scrollX is 100
+PASS window.scrollY is 400
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-quirks.html (0 => 205505)


--- trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-quirks.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body-quirks.html	2016-09-06 21:18:06 UTC (rev 205505)
@@ -0,0 +1,48 @@
+<html>
+    <head>
+        <style>
+            div {
+                width: 9999px;
+                height: 9999px;
+            }
+        </style>
+        <script src=""
+        <script>
+            var scroller;
+            function runTest() {
+                description('Tests scrollTo/By(x,y) and scrollTo/By(scrollOptions) on the body in quirks mode.');
+                
+                scroller = document.body;
+                setTimeout(function() {
+                    scroller.scrollTo(20, 500);
+                    shouldBe("scroller.scrollLeft", "20");
+                    shouldBe("scroller.scrollTop", "500");
+                    shouldBe("window.scrollX", "20");
+                    shouldBe("window.scrollY", "500");
+
+                    scroller.scrollBy(50, 60);
+                    shouldBe("scroller.scrollLeft", "70");
+                    shouldBe("scroller.scrollTop", "560");
+                    shouldBe("window.scrollX", "70");
+                    shouldBe("window.scrollY", "560");
+
+                    scroller.scrollTo({ 'left' : 100, 'top' : 400 });
+                    shouldBe("scroller.scrollLeft", "100");
+                    shouldBe("scroller.scrollTop", "400");
+                    shouldBe("window.scrollX", "100");
+                    shouldBe("window.scrollY", "400");
+
+                    scroller.scrollTo(0, 0);
+
+                    finishJSTest();
+                }, 0);
+            }
+            var jsTestIsAsync = true;
+        </script>
+    </head>
+    <body _onload_="runTest()">
+        <div>
+        </div>
+        <script src=""
+    </body>
+</html>

Added: trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body.html (0 => 205505)


--- trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-body.html	2016-09-06 21:18:06 UTC (rev 205505)
@@ -0,0 +1,49 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <style>
+            div {
+                width: 9999px;
+                height: 9999px;
+            }
+        </style>
+        <script src=""
+        <script>
+            var scroller;
+            function runTest() {
+                description('Tests scrollTo/By(x,y) and scrollTo/By(scrollOptions) on the body. WebKit always uses quirks mode for body scrolling behavior, so this scrolls the window.');
+                
+                scroller = document.body;
+                setTimeout(function() {
+                    scroller.scrollTo(20, 500);
+                    shouldBe("scroller.scrollLeft", "20");
+                    shouldBe("scroller.scrollTop", "500");
+                    shouldBe("window.scrollX", "20");
+                    shouldBe("window.scrollY", "500");
+
+                    scroller.scrollBy(50, 60);
+                    shouldBe("scroller.scrollLeft", "70");
+                    shouldBe("scroller.scrollTop", "560");
+                    shouldBe("window.scrollX", "70");
+                    shouldBe("window.scrollY", "560");
+
+                    scroller.scrollTo({ 'left' : 100, 'top' : 400 });
+                    shouldBe("scroller.scrollLeft", "100");
+                    shouldBe("scroller.scrollTop", "400");
+                    shouldBe("window.scrollX", "100");
+                    shouldBe("window.scrollY", "400");
+
+                    scroller.scrollTo(0, 0);
+
+                    finishJSTest();
+                }, 0);
+            }
+            var jsTestIsAsync = true;
+        </script>
+    </head>
+    <body _onload_="runTest()">
+        <div>
+        </div>
+        <script src=""
+    </body>
+</html>

Added: trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-element-expected.txt (0 => 205505)


--- trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-element-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-element-expected.txt	2016-09-06 21:18:06 UTC (rev 205505)
@@ -0,0 +1,41 @@
+Tests scrollTo/By(x,y) and scrollTo/By(scrollOptions) on Element
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS scroller.scrollLeft is 20
+PASS scroller.scrollTop is 500
+PASS scroller.scrollLeft is 70
+PASS scroller.scrollTop is 560
+PASS scroller.scrollLeft is 100
+PASS scroller.scrollTop is 400
+PASS scroller.scrollLeft is 120
+PASS scroller.scrollTop is 430
+PASS scroller.scrollLeft is 120
+PASS scroller.scrollTop is 700
+PASS scroller.scrollLeft is 300
+PASS scroller.scrollTop is 700
+PASS scroller.scrollLeft is 500
+PASS scroller.scrollTop is 700
+PASS scroller.scrollLeft is 500
+PASS scroller.scrollTop is 950
+PASS scroller.scrollLeft is 20
+PASS scroller.scrollTop is 25
+PASS scroller.scrollLeft is 30
+PASS scroller.scrollTop is 35
+PASS scroller.scrollLeft is 0
+PASS scroller.scrollTop is 0
+PASS scroller.scrollLeft is 10
+PASS scroller.scrollTop is 10
+PASS scroller.scrollLeft is 0
+PASS scroller.scrollTop is 0
+PASS scroller.scrollLeft is 0
+PASS scroller.scrollTop is 0
+PASS scroller.scrollLeft is 0
+PASS scroller.scrollTop is 0
+PASS scroller.scrollLeft is 100
+PASS scroller.scrollTop is 400
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-element.html (0 => 205505)


--- trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-element.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/Element/scrolling-funtions-on-element.html	2016-09-06 21:18:06 UTC (rev 205505)
@@ -0,0 +1,106 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <style>
+            #scroller {
+                height: 500px;
+                width:500px;
+                outline: 1px solid black;
+                overflow: auto;
+            }
+            .content {
+                width: 9999px;
+                height: 9999px;
+            }
+        </style>
+        <script src=""
+        <script>
+            function runTest() {
+                description('Tests scrollTo/By(x,y) and scrollTo/By(scrollOptions) on Element');
+                
+                var scroller = document.getElementById('scroller');
+                setTimeout(function() {
+                    scroller.scrollTo(20, 500);
+                    shouldBe("scroller.scrollLeft", "20");
+                    shouldBe("scroller.scrollTop", "500");
+
+                    scroller.scrollBy(50, 60);
+                    shouldBe("scroller.scrollLeft", "70");
+                    shouldBe("scroller.scrollTop", "560");
+
+                    scroller.scrollTo({ 'left' : 100, 'top' : 400 });
+                    shouldBe("scroller.scrollLeft", "100");
+                    shouldBe("scroller.scrollTop", "400");
+
+                    scroller.scrollBy({ 'left' : 20, 'top' : 30 });
+                    shouldBe("scroller.scrollLeft", "120");
+                    shouldBe("scroller.scrollTop", "430");
+
+                    scroller.scrollTo({ 'top' : 700 });
+                    shouldBe("scroller.scrollLeft", "120");
+                    shouldBe("scroller.scrollTop", "700");
+
+                    scroller.scrollTo({ 'left' : 300 });
+                    shouldBe("scroller.scrollLeft", "300");
+                    shouldBe("scroller.scrollTop", "700");
+
+                    scroller.scrollBy({ 'left' : 200 });
+                    shouldBe("scroller.scrollLeft", "500");
+                    shouldBe("scroller.scrollTop", "700");
+
+                    scroller.scrollBy({ 'top' : 250 });
+                    shouldBe("scroller.scrollLeft", "500");
+                    shouldBe("scroller.scrollTop", "950");
+
+                    scroller.scrollTo(20.5, 25.5);
+                    shouldBe("scroller.scrollLeft", "20");
+                    shouldBe("scroller.scrollTop", "25");
+
+                    scroller.scrollTo(30.99, 35.99);
+                    shouldBe("scroller.scrollLeft", "30");
+                    shouldBe("scroller.scrollTop", "35");
+
+                    scroller.scrollTo(NaN, NaN);
+                    shouldBe("scroller.scrollLeft", "0");
+                    shouldBe("scroller.scrollTop", "0");
+
+                    scroller.scrollTo(10, 10);
+                    scroller.scrollBy(Infinity, Infinity);
+                    shouldBe("scroller.scrollLeft", "10");
+                    shouldBe("scroller.scrollTop", "10");
+
+                    scroller.scrollTo(-100, -100);
+                    shouldBe("scroller.scrollLeft", "0");
+                    shouldBe("scroller.scrollTop", "0");
+
+                    scroller.style.display = 'none';
+                    scroller.scrollTo(100, 100);
+                    shouldBe("scroller.scrollLeft", "0");
+                    shouldBe("scroller.scrollTop", "0");
+
+                    scroller.style.display = 'block';
+                    shouldBe("scroller.scrollLeft", "0");
+                    shouldBe("scroller.scrollTop", "0");
+
+                    if (window.internals)
+                        internals.setPageZoomFactor(1.5);
+
+                    scroller.scrollTo({ 'left' : 100, 'top' : 400 });
+                    shouldBe("scroller.scrollLeft", "100");
+                    shouldBe("scroller.scrollTop", "400");
+
+                    scroller.style.display = 'none';
+
+                    finishJSTest();
+                }, 0);
+            }
+            var jsTestIsAsync = true;
+        </script>
+    </head>
+    <body _onload_="runTest()">
+        <div id="scroller">
+            <div class="content">Scrolling content</div>
+        </div>
+        <script src=""
+    </body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (205504 => 205505)


--- trunk/Source/WebCore/ChangeLog	2016-09-06 21:13:25 UTC (rev 205504)
+++ trunk/Source/WebCore/ChangeLog	2016-09-06 21:18:06 UTC (rev 205505)
@@ -1,3 +1,30 @@
+2016-09-06  Simon Fraser  <[email protected]>
+
+        Align element.scroll() / scrollTo() / scrollBy() with the CSSOM specification
+        https://bugs.webkit.org/show_bug.cgi?id=161610
+
+        Reviewed by Darin Adler, Chris Dumez.
+
+        Implement Element.scroll(), scrollBy() and scrollTo() with x,y and ScrollToOptions
+        on Element, according to <https://drafts.csswg.org/cssom-view/#element-scrolling-members>
+
+        WebKit's behavior of treating scrolls on the body element in both quirks and strict mode
+        is preserved.
+
+        Tests: fast/dom/Element/scrolling-funtions-on-body-quirks.html
+               fast/dom/Element/scrolling-funtions-on-body.html
+               fast/dom/Element/scrolling-funtions-on-element.html
+
+        * dom/Element.cpp:
+        (WebCore::Element::scrollBy):
+        (WebCore::normalizeNonFiniteValue):
+        (WebCore::Element::scrollTo):
+        * dom/Element.h:
+        * dom/Element.idl:
+        * html/HTMLBodyElement.cpp:
+        (WebCore::HTMLBodyElement::scrollTo):
+        * html/HTMLBodyElement.h:
+
 2016-09-06  Saam Barati  <[email protected]>
 
         Make JSMap and JSSet faster

Modified: trunk/Source/WebCore/dom/Element.cpp (205504 => 205505)


--- trunk/Source/WebCore/dom/Element.cpp	2016-09-06 21:13:25 UTC (rev 205504)
+++ trunk/Source/WebCore/dom/Element.cpp	2016-09-06 21:18:06 UTC (rev 205505)
@@ -684,7 +684,50 @@
     else
         renderer()->scrollRectToVisible(SelectionRevealMode::Reveal, bounds, ScrollAlignment::alignToEdgeIfNotVisible, ScrollAlignment::alignToEdgeIfNotVisible);
 }
-    
+
+void Element::scrollBy(const ScrollToOptions& options)
+{
+    return scrollBy(options.left.valueOr(0), options.top.valueOr(0));
+}
+
+static inline double normalizeNonFiniteValue(double f)
+{
+    return std::isfinite(f) ? f : 0;
+}
+
+void Element::scrollBy(double x, double y)
+{
+    scrollTo(scrollLeft() + normalizeNonFiniteValue(x), scrollTop() + normalizeNonFiniteValue(y));
+}
+
+void Element::scrollTo(const ScrollToOptions& options)
+{
+    // If the element is the root element and document is in quirks mode, terminate these steps.
+    // Note that WebKit always uses quirks mode document scrolling behavior. See Document::scrollingElement().
+    if (this == document().documentElement())
+        return;
+
+    document().updateLayoutIgnorePendingStylesheets();
+
+    // If the element does not have any associated CSS layout box, the element has no associated scrolling box,
+    // or the element has no overflow, terminate these steps.
+    RenderBox* renderer = renderBox();
+    if (!renderer || !renderer->hasOverflowClip())
+        return;
+
+    // Normalize non-finite values for left and top dictionary members of options, if present.
+    double x = options.left ? normalizeNonFiniteValue(options.left.value()) : adjustForAbsoluteZoom(renderer->scrollLeft(), *renderer);
+    double y = options.top ? normalizeNonFiniteValue(options.top.value()) : adjustForAbsoluteZoom(renderer->scrollTop(), *renderer);
+
+    renderer->setScrollLeft(clampToInteger(x * renderer->style().effectiveZoom()));
+    renderer->setScrollTop(clampToInteger(y * renderer->style().effectiveZoom()));
+}
+
+void Element::scrollTo(double x, double y)
+{
+    scrollTo({ x, y });
+}
+
 void Element::scrollByUnits(int units, ScrollGranularity granularity)
 {
     document().updateLayoutIgnorePendingStylesheets();
@@ -826,7 +869,7 @@
 {
     document().updateLayoutIgnorePendingStylesheets();
 
-    if (RenderBox* renderer = renderBox()) {
+    if (auto* renderer = renderBox()) {
         LayoutUnit clientLeft = subpixelMetricsEnabled(renderer->document()) ? renderer->clientLeft() : LayoutUnit(roundToInt(renderer->clientLeft()));
         return convertToNonSubpixelValueIfNeeded(adjustLayoutUnitForAbsoluteZoom(clientLeft, *renderer).toDouble(), renderer->document());
     }
@@ -837,7 +880,7 @@
 {
     document().updateLayoutIgnorePendingStylesheets();
 
-    if (RenderBox* renderer = renderBox()) {
+    if (auto* renderer = renderBox()) {
         LayoutUnit clientTop = subpixelMetricsEnabled(renderer->document()) ? renderer->clientTop() : LayoutUnit(roundToInt(renderer->clientTop()));
         return convertToNonSubpixelValueIfNeeded(adjustLayoutUnitForAbsoluteZoom(clientTop, *renderer).toDouble(), renderer->document());
     }
@@ -850,6 +893,7 @@
 
     if (!document().hasLivingRenderTree())
         return 0;
+
     RenderView& renderView = *document().renderView();
 
     // When in strict mode, clientWidth for the document element should return the width of the containing frame.
@@ -870,6 +914,7 @@
     document().updateLayoutIfDimensionsOutOfDate(*this, HeightDimensionsCheck);
     if (!document().hasLivingRenderTree())
         return 0;
+
     RenderView& renderView = *document().renderView();
 
     // When in strict mode, clientHeight for the document element should return the height of the containing frame.
@@ -889,8 +934,8 @@
 {
     document().updateLayoutIgnorePendingStylesheets();
 
-    if (RenderBox* rend = renderBox())
-        return adjustForAbsoluteZoom(rend->scrollLeft(), *rend);
+    if (auto* renderer = renderBox())
+        return adjustForAbsoluteZoom(renderer->scrollLeft(), *renderer);
     return 0;
 }
 
@@ -898,8 +943,8 @@
 {
     document().updateLayoutIgnorePendingStylesheets();
 
-    if (RenderBox* rend = renderBox())
-        return adjustForAbsoluteZoom(rend->scrollTop(), *rend);
+    if (RenderBox* renderer = renderBox())
+        return adjustForAbsoluteZoom(renderer->scrollTop(), *renderer);
     return 0;
 }
 
@@ -907,7 +952,7 @@
 {
     document().updateLayoutIgnorePendingStylesheets();
 
-    if (RenderBox* renderer = renderBox()) {
+    if (auto* renderer = renderBox()) {
         renderer->setScrollLeft(static_cast<int>(newLeft * renderer->style().effectiveZoom()));
         if (auto* scrollableArea = renderer->layer())
             scrollableArea->setScrolledProgrammatically(true);
@@ -918,7 +963,7 @@
 {
     document().updateLayoutIgnorePendingStylesheets();
 
-    if (RenderBox* renderer = renderBox()) {
+    if (auto* renderer = renderBox()) {
         renderer->setScrollTop(static_cast<int>(newTop * renderer->style().effectiveZoom()));
         if (auto* scrollableArea = renderer->layer())
             scrollableArea->setScrolledProgrammatically(true);
@@ -928,8 +973,8 @@
 int Element::scrollWidth()
 {
     document().updateLayoutIfDimensionsOutOfDate(*this, WidthDimensionsCheck);
-    if (RenderBox* rend = renderBox())
-        return adjustForAbsoluteZoom(rend->scrollWidth(), *rend);
+    if (auto* renderer = renderBox())
+        return adjustForAbsoluteZoom(renderer->scrollWidth(), *renderer);
     return 0;
 }
 
@@ -936,8 +981,8 @@
 int Element::scrollHeight()
 {
     document().updateLayoutIfDimensionsOutOfDate(*this, HeightDimensionsCheck);
-    if (RenderBox* rend = renderBox())
-        return adjustForAbsoluteZoom(rend->scrollHeight(), *rend);
+    if (auto* renderer = renderBox())
+        return adjustForAbsoluteZoom(renderer->scrollHeight(), *renderer);
     return 0;
 }
 

Modified: trunk/Source/WebCore/dom/Element.h (205504 => 205505)


--- trunk/Source/WebCore/dom/Element.h	2016-09-06 21:13:25 UTC (rev 205504)
+++ trunk/Source/WebCore/dom/Element.h	2016-09-06 21:18:06 UTC (rev 205505)
@@ -136,6 +136,16 @@
     WEBCORE_EXPORT void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
     WEBCORE_EXPORT void scrollIntoViewIfNotVisible(bool centerIfNotVisible = true);
 
+    struct ScrollToOptions {
+        Optional<double> left;
+        Optional<double> top;
+    };
+
+    void scrollBy(const ScrollToOptions&);
+    void scrollBy(double x, double y);
+    virtual void scrollTo(const ScrollToOptions&);
+    void scrollTo(double x, double y);
+
     WEBCORE_EXPORT void scrollByLines(int lines);
     WEBCORE_EXPORT void scrollByPages(int pages);
 
@@ -157,6 +167,7 @@
     WEBCORE_EXPORT double clientTop();
     WEBCORE_EXPORT double clientWidth();
     WEBCORE_EXPORT double clientHeight();
+
     virtual int scrollLeft();
     virtual int scrollTop();
     virtual void setScrollLeft(int);

Modified: trunk/Source/WebCore/dom/Element.idl (205504 => 205505)


--- trunk/Source/WebCore/dom/Element.idl	2016-09-06 21:13:25 UTC (rev 205504)
+++ trunk/Source/WebCore/dom/Element.idl	2016-09-06 21:18:06 UTC (rev 205505)
@@ -71,8 +71,8 @@
     readonly attribute double clientWidth;
     readonly attribute double clientHeight;
 
-    attribute long scrollLeft;
-    attribute long scrollTop;
+    attribute long scrollLeft; // FIXME: should be unrestricted double
+    attribute long scrollTop; // FIXME: should be unrestricted double
     readonly attribute long scrollWidth;
     readonly attribute long scrollHeight;
 
@@ -80,12 +80,22 @@
 
     void scrollIntoView(optional boolean alignWithTop = true);
 
-    sequence<DOMString> getAttributeNames();
+    void scrollIntoViewIfNeeded(optional boolean centerIfNeeded = true);
 
-    void scrollIntoViewIfNeeded(optional boolean centerIfNeeded = true);
+    [ImplementedAs=scrollTo] void scroll(optional ScrollToOptions options);
+    [ImplementedAs=scrollTo] void scroll(unrestricted double x, unrestricted double y);
+
+    void scrollTo(optional ScrollToOptions options);
+    void scrollTo(unrestricted double x, unrestricted double y);
+
+    void scrollBy(optional ScrollToOptions option);
+    void scrollBy(unrestricted double x, unrestricted double y);
+
     void scrollByLines(optional long lines = 0);
     void scrollByPages(optional long pages = 0);
 
+    sequence<DOMString> getAttributeNames();
+
     HTMLCollection getElementsByClassName(DOMString name);
     [TreatNullAs=EmptyString, SetterRaisesException] attribute DOMString innerHTML;
     [TreatNullAs=EmptyString, SetterRaisesException] attribute DOMString outerHTML;
@@ -178,6 +188,12 @@
     required ShadowRootMode mode;
 };
 
+// FIXME: Support ScrollBehavior.
+dictionary ScrollToOptions {
+    unrestricted double left;
+    unrestricted double top;
+};
+
 Element implements Animatable;
 Element implements ChildNode;
 Element implements NonDocumentTypeChildNode;

Modified: trunk/Source/WebCore/html/HTMLBodyElement.cpp (205504 => 205505)


--- trunk/Source/WebCore/html/HTMLBodyElement.cpp	2016-09-06 21:13:25 UTC (rev 205504)
+++ trunk/Source/WebCore/html/HTMLBodyElement.cpp	2016-09-06 21:18:06 UTC (rev 205505)
@@ -27,6 +27,7 @@
 #include "CSSImageValue.h"
 #include "CSSParser.h"
 #include "CSSValueKeywords.h"
+#include "DOMWindow.h"
 #include "EventNames.h"
 #include "Frame.h"
 #include "FrameView.h"
@@ -294,6 +295,23 @@
     return HTMLElement::setScrollTop(scrollTop);
 }
 
+void HTMLBodyElement::scrollTo(const ScrollToOptions& options)
+{
+    if (isFirstBodyElementOfDocument()) {
+        // If the element is the HTML body element, document is in quirks mode, and the element is not potentially scrollable,
+        // invoke scroll() on window with options as the only argument, and terminate these steps.
+        // Note that WebKit always uses quirks mode document scrolling behavior. See Document::scrollingElement().
+        // FIXME: Scrolling an independently scrollable body is broken: webkit.org/b/161612.
+        auto* window = document().domWindow();
+        if (!window)
+            return;
+
+        window->scrollTo({ options.left, options.top });
+        return;
+    }
+    return HTMLElement::scrollTo(options);
+}
+
 int HTMLBodyElement::scrollHeight()
 {
     if (isFirstBodyElementOfDocument()) {

Modified: trunk/Source/WebCore/html/HTMLBodyElement.h (205504 => 205505)


--- trunk/Source/WebCore/html/HTMLBodyElement.h	2016-09-06 21:13:25 UTC (rev 205504)
+++ trunk/Source/WebCore/html/HTMLBodyElement.h	2016-09-06 21:18:06 UTC (rev 205505)
@@ -56,6 +56,8 @@
     
     int scrollTop() final;
     void setScrollTop(int) final;
+
+    void scrollTo(const ScrollToOptions&) final;
     
     int scrollHeight() final;
     int scrollWidth() final;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to