Harden RenderBox::canBeScrolledAndHasScrollableArea logic https://bugs.webkit.org...
authortonikitoo@webkit.org <tonikitoo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Aug 2013 12:53:04 +0000 (12:53 +0000)
committertonikitoo@webkit.org <tonikitoo@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 21 Aug 2013 12:53:04 +0000 (12:53 +0000)
Reviewed by Simon Fraser.
Patch by Antonio Gomes <a1.gomes@sisa.samsung.com>

Source/WebCore:

Previously if a say div has a overflown content on 'y' but is
styled as "overflow-x: auto; overflow-y: hidden", RenderBox::canBeProgramaticallyScrolled
would still return true. It interfers, among other things, with the way
autoscroll works.

Patch fixes it by adding two helper methods to RenderBox class in order to verify a box'
scrollability in a given axis (x or y); They are used when checking if a given box is in
fact programatically scrollable.

Test: fast/events/autoscroll-overflow-hidden-longhands.html

WebKit autoscroll behavior now matches Firefox and Opera12 (pre-blink)
in that sense.

* rendering/RenderBox.cpp:
(WebCore::RenderBox::canBeProgramaticallyScrolled):
* rendering/RenderBox.h:
(WebCore::RenderBox::hasScrollableOverflowX):
(WebCore::RenderBox::hasScrollableOverflowY):

LayoutTests:

Patch adds a test to ensure autoscrolling only happens on a given
axis if it is scrollable in that direction, according to its style.

* fast/events/autoscroll-overflow-hidden-longhands-expected.txt: Added.
* fast/events/autoscroll-overflow-hidden-longhands.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@154383 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/events/autoscroll-overflow-hidden-longhands-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/autoscroll-overflow-hidden-longhands.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderBox.cpp
Source/WebCore/rendering/RenderBox.h

index 2766150..9d7c78f 100644 (file)
@@ -1,3 +1,16 @@
+2013-08-20  Antonio Gomes  <a1.gomes@sisa.samsung.com>
+
+        Harden RenderBox::canBeScrolledAndHasScrollableArea logic
+        https://bugs.webkit.org/show_bug.cgi?id=104373
+
+        Reviewed by Simon Fraser.
+
+        Patch adds a test to ensure autoscrolling only happens on a given
+        axis if it is scrollable in that direction, according to its style.
+
+        * fast/events/autoscroll-overflow-hidden-longhands-expected.txt: Added.
+        * fast/events/autoscroll-overflow-hidden-longhands.html: Added.
+
 2013-08-19  Antonio Gomes  <a1.gomes@sisa.samsung.com>
 
         Text dragging can scroll overflow:hidden boxes
diff --git a/LayoutTests/fast/events/autoscroll-overflow-hidden-longhands-expected.txt b/LayoutTests/fast/events/autoscroll-overflow-hidden-longhands-expected.txt
new file mode 100644 (file)
index 0000000..ca46565
--- /dev/null
@@ -0,0 +1,2 @@
+Try to autoscroll this text.
+PASSED : the autoscroll did not happen!
diff --git a/LayoutTests/fast/events/autoscroll-overflow-hidden-longhands.html b/LayoutTests/fast/events/autoscroll-overflow-hidden-longhands.html
new file mode 100644 (file)
index 0000000..51791d7
--- /dev/null
@@ -0,0 +1,56 @@
+<html>
+    <head>
+        <script>
+       function log(msg)
+       {
+           document.getElementById('console').appendChild(document.createTextNode(msg + '\n'));
+       }
+
+       function test()
+       {
+           if (window.testRunner) {
+               testRunner.waitUntilDone();
+               testRunner.dumpAsText();
+               setTimeout(autoscrollTestPart1, 0);
+           }
+       }
+
+       function autoscrollTestPart1()
+       {
+           var textInDiv = document.getElementById('textInDiv');
+           if (window.eventSender) {
+               var x = textInDiv.offsetLeft + 17;
+               var y = textInDiv.offsetTop + 7;
+               eventSender.dragMode = false;
+               eventSender.mouseMoveTo(x, y);
+               eventSender.mouseDown();
+               eventSender.mouseMoveTo(x, y + 20);
+               eventSender.mouseMoveTo(x, y + 220);
+           }
+           setTimeout(autoscrollTestPart2, 100);
+       }
+
+       function autoscrollTestPart2()
+       {
+           if (window.eventSender)
+               eventSender.mouseUp();
+           var sd = document.getElementById('nonScrollableDiv');
+           if (sd.scrollTop == 0)
+               log("PASSED : the autoscroll did not happen!");
+           else
+               log("FAILED : the autoscroll has happened :-(");
+           
+           if (window.testRunner)
+               testRunner.notifyDone();
+       }       
+        </script>
+    </head>
+<body onload="test()">
+   <div id="nonScrollableDiv" style="height: 100px; overflow-x: auto; overflow-y: hidden; width: 100px">
+       <div id="tailDiv" style=" height: 1000px; background-color: yellow">
+           <span id='textInDiv'> Try to autoscroll this text.<br>
+       </div>
+   </div>
+   <div id="console"></div>
+</body>
+</html>
index d0fbe57..7877869 100644 (file)
@@ -1,3 +1,30 @@
+2013-08-20  Antonio Gomes  <a1.gomes@sisa.samsung.com>
+
+        Harden RenderBox::canBeScrolledAndHasScrollableArea logic
+        https://bugs.webkit.org/show_bug.cgi?id=104373
+
+        Reviewed by Simon Fraser.
+
+        Previously if a say div has a overflown content on 'y' but is
+        styled as "overflow-x: auto; overflow-y: hidden", RenderBox::canBeProgramaticallyScrolled
+        would still return true. It interfers, among other things, with the way
+        autoscroll works.
+
+        Patch fixes it by adding two helper methods to RenderBox class in order to verify a box'
+        scrollability in a given axis (x or y); They are used when checking if a given box is in
+        fact programatically scrollable.
+
+        Test: fast/events/autoscroll-overflow-hidden-longhands.html
+
+        WebKit autoscroll behavior now matches Firefox and Opera12 (pre-blink)
+        in that sense.
+
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::canBeProgramaticallyScrolled):
+        * rendering/RenderBox.h:
+        (WebCore::RenderBox::hasScrollableOverflowX):
+        (WebCore::RenderBox::hasScrollableOverflowY):
+
 2013-08-19  Antonio Gomes  <a1.gomes@sisa.samsung.com>
 
         Text dragging can scroll overflow:hidden boxes
index 54fe88d..5d18bdc 100644 (file)
@@ -790,7 +790,18 @@ bool RenderBox::canBeScrolledAndHasScrollableArea() const
     
 bool RenderBox::canBeProgramaticallyScrolled() const
 {
-    return (hasOverflowClip() && (scrollsOverflow() || (node() && node()->rendererIsEditable()))) || (node() && node()->isDocumentNode());
+    Node* node = this->node();
+    if (node && node->isDocumentNode())
+        return true;
+
+    if (!hasOverflowClip())
+        return false;
+
+    bool hasScrollableOverflow = hasScrollableOverflowX() || hasScrollableOverflowY();
+    if (scrollsOverflow() && hasScrollableOverflow)
+        return true;
+
+    return node && node->rendererIsEditable();
 }
 
 bool RenderBox::usesCompositedScrolling() const
index f71b70a..68cf05a 100644 (file)
@@ -463,6 +463,9 @@ public:
     bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
     bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); }
     bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); }
+    bool hasScrollableOverflowX() const { return scrollsOverflowX() && scrollWidth() != clientWidth(); }
+    bool hasScrollableOverflowY() const { return scrollsOverflowY() && scrollHeight() != clientHeight(); }
+
     bool usesCompositedScrolling() const;
     
     bool hasUnsplittableScrollingOverflow() const;