iframe and scrollbar with "overflow:auto" should support autoscroll with mousedrag
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Sep 2013 21:50:16 +0000 (21:50 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 23 Sep 2013 21:50:16 +0000 (21:50 +0000)
https://bugs.webkit.org/show_bug.cgi?id=40981

Patch by Antonio Gomes <a1.gomes@sisa.samsung.com> on 2013-09-23
Reviewed by Darin Adler.

Source/WebCore:

RenderBox::calculateAutoscrollDirection does not properly translate
inner frames' coordinates in order to determine its auto-scrollability.
By coincidence, if the inner frame box it placed near to page's 0, 0 position
(upper left corner), it might work.

Patch fixes it by changing ::calculateAutoscrollDirection algorithm to operate
with window coordinates, taking inner frames offset and scroll position into account.
The behavior of auto-scrollable non-frame overflow boxes, including divs, still works
as it is used to.

Test: fast/events/drag-and-drop-autoscroll-inner-frame.html

* rendering/RenderBox.cpp:
(WebCore::RenderBox::calculateAutoscrollDirection):

LayoutTests:

Test ensures that dragging an element close to the boundary of
scrollable Frames, scroll its content in that direction.

* fast/events/drag-and-drop-autoscroll-inner-frame-expected.txt: Added.
* fast/events/drag-and-drop-autoscroll-inner-frame.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/events/drag-and-drop-autoscroll-inner-frame-expected.txt [new file with mode: 0644]
LayoutTests/fast/events/drag-and-drop-autoscroll-inner-frame.html [new file with mode: 0644]
LayoutTests/fast/events/resources/iframe-drag-and-drop-autoscroll.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderBox.cpp

index 60ab1d5780f8d6e91f6d213f9e9775b93e4daae1..182d3a53c62d18a7e38c54463c9747256321a0c7 100644 (file)
@@ -1,3 +1,16 @@
+2013-09-23  Antonio Gomes  <a1.gomes@sisa.samsung.com>
+
+        iframe and scrollbar with "overflow:auto" should support autoscroll with mousedrag
+        https://bugs.webkit.org/show_bug.cgi?id=40981
+
+        Reviewed by Darin Adler.
+
+        Test ensures that dragging an element close to the boundary of
+        scrollable Frames, scroll its content in that direction.
+
+        * fast/events/drag-and-drop-autoscroll-inner-frame-expected.txt: Added.
+        * fast/events/drag-and-drop-autoscroll-inner-frame.html: Added.
+
 2013-09-23  Alexey Proskuryakov  <ap@apple.com>
 
         video-object-fit tests are flaky
diff --git a/LayoutTests/fast/events/drag-and-drop-autoscroll-inner-frame-expected.txt b/LayoutTests/fast/events/drag-and-drop-autoscroll-inner-frame-expected.txt
new file mode 100644 (file)
index 0000000..1399292
--- /dev/null
@@ -0,0 +1,12 @@
+For manual testing, drag and drop "Drop Me" downwards and then upwards. 
+Check autoscroll within an inner frame by drag-and-drop
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+PASS Autoscroll should have scrolled the iframe downwards, and did.
+PASS iframe.contentDocument.body.scrollTop < middleTermScrollOffset is true
+
diff --git a/LayoutTests/fast/events/drag-and-drop-autoscroll-inner-frame.html b/LayoutTests/fast/events/drag-and-drop-autoscroll-inner-frame.html
new file mode 100644 (file)
index 0000000..b3611af
--- /dev/null
@@ -0,0 +1,113 @@
+<!DOCTYPE html>
+<head>
+<style type="text/css">
+#scrollable {
+    height: 200px;
+    overflow: auto;
+    border: solid 3px #cc0000;
+    font-size: 80px;
+}
+</style>
+<script>
+
+var x, y, middleTermScrollOffset;
+var iframe, iframeDocument, draggable;
+
+function setUpTest()
+{
+    if (!window.eventSender) {
+        log('Please run within DumpRenderTree');
+        return;
+    }
+
+    window.internals.settings.setAutoscrollForDragAndDropEnabled(true);
+    testRunner.waitUntilDone();
+    testIt();
+}
+
+function testIt()
+{
+    eventSender.dragMode = false;
+
+    iframe = document.getElementById('scrollable');
+    iframeDocument = iframe.contentDocument;
+    draggable = iframeDocument.getElementById('draggable');
+
+    iframeDocument.addEventListener("scroll", recordScroll);
+
+    // Grab draggable.
+    x = iframe.offsetLeft + draggable.offsetLeft + 7;
+    y = iframe.offsetTop + draggable.offsetTop + 7;
+
+    eventSender.mouseMoveTo(x, y);
+    eventSender.mouseDown();
+
+    // Move mouse to the bottom autoscroll border belt.
+    y = iframe.offsetTop + iframe.offsetHeight - 10;
+    eventSender.mouseMoveTo(x, y);
+}
+
+function recordScroll(e)
+{
+    iframeDocument.removeEventListener("scroll", recordScroll);
+    autoscrollTestPart1();
+}
+
+function recordScroll2(e)
+{
+    iframeDocument.removeEventListener("scroll", recordScroll2);
+    autoscrollTestPart2();
+}
+
+function autoscrollTestPart1()
+{
+    if (iframe.contentDocument.body.scrollTop == 0) {
+        testFailed("Autoscroll should have scrolled the iframe downwards, but did not");
+        finishTest();
+        return;
+    }
+
+    testPassed("Autoscroll should have scrolled the iframe downwards, and did.");
+    eventSender.mouseUp();
+    iframeDocument.addEventListener("scroll", recordScroll2);
+
+    middleTermScrollOffset = iframe.contentDocument.body.scrollTop;
+
+    // Grab draggable.
+    x = iframe.offsetLeft + draggable.offsetLeft + 7;
+    y = iframe.offsetTop + draggable.offsetTop + 7 - iframe.contentDocument.body.scrollTop ;
+
+    // Move mouse to the upper autoscroll border belt.
+    eventSender.mouseMoveTo(x, y);
+    eventSender.mouseDown();
+
+    y = iframe.offsetTop + 10;
+    eventSender.mouseMoveTo(x, y);
+}
+
+function autoscrollTestPart2()
+{
+    shouldBeTrue("iframe.contentDocument.body.scrollTop < middleTermScrollOffset")
+    finishTest();
+}
+
+function finishTest()
+{
+    eventSender.mouseUp();
+    testRunner.notifyDone();
+}
+
+</script>
+</head>
+<body>
+For manual testing, drag and drop "Drop Me" downwards and then upwards.
+<iframe id="scrollable" src="resources/iframe-drag-and-drop-autoscroll.html"></iframe><br>
+</div>
+<div id="console"></div>
+<script src="../../resources/js-test-pre.js"></script>
+<script>
+description('Check autoscroll within an inner frame by drag-and-drop');
+</script>
+<script src="../../resources/js-test-post.js"></script>
+</body>
+</html>
diff --git a/LayoutTests/fast/events/resources/iframe-drag-and-drop-autoscroll.html b/LayoutTests/fast/events/resources/iframe-drag-and-drop-autoscroll.html
new file mode 100644 (file)
index 0000000..c14126b
--- /dev/null
@@ -0,0 +1,8 @@
+<body onload='parent.setUpTest()'>
+<br>
+<p id='draggable' draggable='true' style='cursor: hand;'>
+    <b>Drag me!</b>
+</p>
+Try to drag and drop the text above in the input element at the bottom of this iframe. It should scroll. Then, try the way back.
+<br><br>more<br>more<br>more<br>more<br>more<br>more<br>more<br>more<br>more<br>more<br>more<br>more<br><input>
+</body>
index d5da6ecce627a4cbd57447c81cc03e9ccf32e156..8dcc452b9c7c087b06244b7d07776b3c61562cbb 100644 (file)
@@ -1,3 +1,25 @@
+2013-09-23  Antonio Gomes  <a1.gomes@sisa.samsung.com>
+
+        iframe and scrollbar with "overflow:auto" should support autoscroll with mousedrag
+        https://bugs.webkit.org/show_bug.cgi?id=40981
+
+        Reviewed by Darin Adler.
+
+        RenderBox::calculateAutoscrollDirection does not properly translate
+        inner frames' coordinates in order to determine its auto-scrollability.
+        By coincidence, if the inner frame box it placed near to page's 0, 0 position
+        (upper left corner), it might work.
+
+        Patch fixes it by changing ::calculateAutoscrollDirection algorithm to operate
+        with window coordinates, taking inner frames offset and scroll position into account.
+        The behavior of auto-scrollable non-frame overflow boxes, including divs, still works
+        as it is used to.
+
+        Test: fast/events/drag-and-drop-autoscroll-inner-frame.html
+
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::calculateAutoscrollDirection):
+
 2013-09-23  Brady Eidson  <beidson@apple.com>
 
         Move LevelDB specific IDB files into their own subdirectory.
index 98a2e057913e625d7159d935aefa24a670ffe427..df0d8d704f5bee385e322780f3a408b68c02571d 100644 (file)
@@ -842,20 +842,23 @@ bool RenderBox::canAutoscroll() const
 // scrolling.
 IntSize RenderBox::calculateAutoscrollDirection(const IntPoint& windowPoint) const
 {
-    IntSize offset;
-    IntPoint point = view().frameView().windowToContents(windowPoint);
     IntRect box(absoluteBoundingBoxRect());
+    box.move(view().frameView().scrollOffset());
+    IntRect windowBox = view().frameView().contentsToWindow(box);
 
-    if (point.x() < box.x() + autoscrollBeltSize)
-        point.move(-autoscrollBeltSize, 0);
-    else if (point.x() > box.maxX() - autoscrollBeltSize)
-        point.move(autoscrollBeltSize, 0);
+    IntPoint windowAutoscrollPoint = windowPoint;
 
-    if (point.y() < box.y() + autoscrollBeltSize)
-        point.move(0, -autoscrollBeltSize);
-    else if (point.y() > box.maxY() - autoscrollBeltSize)
-        point.move(0, autoscrollBeltSize);
-    return view().frameView().contentsToWindow(point) - windowPoint;
+    if (windowAutoscrollPoint.x() < windowBox.x() + autoscrollBeltSize)
+        windowAutoscrollPoint.move(-autoscrollBeltSize, 0);
+    else if (windowAutoscrollPoint.x() > windowBox.maxX() - autoscrollBeltSize)
+        windowAutoscrollPoint.move(autoscrollBeltSize, 0);
+
+    if (windowAutoscrollPoint.y() < windowBox.y() + autoscrollBeltSize)
+        windowAutoscrollPoint.move(0, -autoscrollBeltSize);
+    else if (windowAutoscrollPoint.y() > windowBox.maxY() - autoscrollBeltSize)
+        windowAutoscrollPoint.move(0, autoscrollBeltSize);
+
+    return windowAutoscrollPoint - windowPoint;
 }
 
 RenderBox* RenderBox::findAutoscrollable(RenderObject* renderer)