Title: [171862] trunk/Source/WebCore
Revision
171862
Author
[email protected]
Date
2014-07-31 10:16:08 -0700 (Thu, 31 Jul 2014)

Log Message

Refactor EventHandler to call ScrollAnimator::handleWheelEvent for overflow scrolling
https://bugs.webkit.org/show_bug.cgi?id=135195

Patch by Wenson Hsieh <[email protected]> on 2014-07-31
Reviewed by Beth Dakin.

ScrollableArea::handleWheelEvent is not currently being used to handle wheel events for overflow scrolling; it instead directly invokes ScrollableArea::scroll.
In order to expose wheel phases on Mac, the PlatformWheelEvent itself should propagate down to ScrollableArea, not just the scroll granularity, direction and
multiplier required by ScrollableArea::scroll. With this patch, PlatformWheelEvent will be "shipped" along with the WheelEvent.

No new tests, since behavior should not have changed.

* page/EventHandler.cpp:
(WebCore::didScrollInScrollableAreaForSingleAxis): Calls ScrollableArea::scroll directly using WheelEvent's data. Used to handle programmatic WheelEvents, e.g. from _javascript_.
(WebCore::handleWheelEventInAppropriateEnclosingBoxForSingleAxis): Finds the correct ScrollableArea and attempts to scroll it using the information contained in the WheelEvent via ScrollableArea::handleWheelEvent
(WebCore::EventHandler::defaultWheelEventHandler): Updated to use handleWheelEventInAppropriateEnclosingBoxForSingleAxis instead of scrollNode.
(WebCore::scrollNode): Deleted.
* rendering/RenderListBox.h: Made RenderListBox::scroll public so it can be invoked from EventHandler::handleWheelEventInAppropriateEnclosingBoxForSingleAxis.
* rendering/RenderNamedFlowThread.cpp: Refactored to let EventHandler update nextScrollBlock in the case of isRenderNamedFlowThread().
(WebCore::RenderNamedFlowThread::fragmentFromRenderBoxAsRenderBlock):
* rendering/RenderNamedFlowThread.h:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (171861 => 171862)


--- trunk/Source/WebCore/ChangeLog	2014-07-31 17:15:10 UTC (rev 171861)
+++ trunk/Source/WebCore/ChangeLog	2014-07-31 17:16:08 UTC (rev 171862)
@@ -1,3 +1,26 @@
+2014-07-31  Wenson Hsieh  <[email protected]>
+
+        Refactor EventHandler to call ScrollAnimator::handleWheelEvent for overflow scrolling
+        https://bugs.webkit.org/show_bug.cgi?id=135195
+
+        Reviewed by Beth Dakin.
+
+        ScrollableArea::handleWheelEvent is not currently being used to handle wheel events for overflow scrolling; it instead directly invokes ScrollableArea::scroll.
+        In order to expose wheel phases on Mac, the PlatformWheelEvent itself should propagate down to ScrollableArea, not just the scroll granularity, direction and
+        multiplier required by ScrollableArea::scroll. With this patch, PlatformWheelEvent will be "shipped" along with the WheelEvent.
+
+        No new tests, since behavior should not have changed.
+
+        * page/EventHandler.cpp:
+        (WebCore::didScrollInScrollableAreaForSingleAxis): Calls ScrollableArea::scroll directly using WheelEvent's data. Used to handle programmatic WheelEvents, e.g. from _javascript_.
+        (WebCore::handleWheelEventInAppropriateEnclosingBoxForSingleAxis): Finds the correct ScrollableArea and attempts to scroll it using the information contained in the WheelEvent via ScrollableArea::handleWheelEvent
+        (WebCore::EventHandler::defaultWheelEventHandler): Updated to use handleWheelEventInAppropriateEnclosingBoxForSingleAxis instead of scrollNode.
+        (WebCore::scrollNode): Deleted.
+        * rendering/RenderListBox.h: Made RenderListBox::scroll public so it can be invoked from EventHandler::handleWheelEventInAppropriateEnclosingBoxForSingleAxis.
+        * rendering/RenderNamedFlowThread.cpp: Refactored to let EventHandler update nextScrollBlock in the case of isRenderNamedFlowThread().
+        (WebCore::RenderNamedFlowThread::fragmentFromRenderBoxAsRenderBlock): 
+        * rendering/RenderNamedFlowThread.h:
+
 2014-07-31  Dan Bernstein  <[email protected]>
 
         WebCore part of: Server trust authentication challenges aren’t sent to the navigation delegate

Modified: trunk/Source/WebCore/page/EventHandler.cpp (171861 => 171862)


--- trunk/Source/WebCore/page/EventHandler.cpp	2014-07-31 17:15:10 UTC (rev 171861)
+++ trunk/Source/WebCore/page/EventHandler.cpp	2014-07-31 17:16:08 UTC (rev 171862)
@@ -73,6 +73,7 @@
 #include "RenderFrameSet.h"
 #include "RenderLayer.h"
 #include "RenderListBox.h"
+#include "RenderNamedFlowThread.h"
 #include "RenderTextControlSingleLine.h"
 #include "RenderView.h"
 #include "RenderWidget.h"
@@ -283,16 +284,50 @@
     }
 }
 
-static inline bool scrollNode(float delta, ScrollGranularity granularity, ScrollDirection positiveDirection, ScrollDirection negativeDirection, Node* node, Element** stopElement, const IntPoint& wheelEventAbsolutePoint)
+static inline bool didScrollInScrollableAreaForSingleAxis(ScrollableArea* scrollableArea, WheelEvent* wheelEvent, ScrollEventAxis axis)
 {
-    if (!delta)
+    float delta = axis == ScrollEventAxis::Vertical ? wheelEvent->deltaY() : wheelEvent->deltaX();
+    ScrollDirection negativeDirection = axis == ScrollEventAxis::Vertical ? ScrollUp : ScrollLeft;
+    ScrollDirection positiveDirection = axis == ScrollEventAxis::Vertical ? ScrollDown : ScrollRight;
+    return scrollableArea->scroll(delta < 0 ? negativeDirection : positiveDirection, wheelGranularityToScrollGranularity(wheelEvent->deltaMode()), delta > 0 ? delta : -delta);
+}
+
+static inline bool handleWheelEventInAppropriateEnclosingBoxForSingleAxis(Node* startNode, WheelEvent* wheelEvent, Element** stopElement, ScrollEventAxis axis)
+{
+    if (!startNode->renderer() || (axis == ScrollEventAxis::Vertical && !wheelEvent->deltaY()) || (axis == ScrollEventAxis::Horizontal && !wheelEvent->deltaX()))
         return false;
-    if (!node->renderer())
-        return false;
-    RenderBox& enclosingBox = node->renderer()->enclosingBox();
-    float absDelta = delta > 0 ? delta : -delta;
 
-    return enclosingBox.scroll(delta < 0 ? negativeDirection : positiveDirection, granularity, absDelta, stopElement, &enclosingBox, wheelEventAbsolutePoint);
+    RenderBox& initialEnclosingBox = startNode->renderer()->enclosingBox();
+    if (initialEnclosingBox.isListBox())
+        return didScrollInScrollableAreaForSingleAxis(static_cast<RenderListBox*>(&initialEnclosingBox), wheelEvent, axis);
+
+    RenderBox* currentEnclosingBox = &initialEnclosingBox;
+    while (currentEnclosingBox) {
+        if (RenderLayer* boxLayer = currentEnclosingBox->layer()) {
+            const PlatformWheelEvent* platformEvent = wheelEvent->wheelEvent();
+            bool scrollingWasHandled;
+            if (platformEvent != nullptr)
+                scrollingWasHandled = boxLayer->handleWheelEvent(axis == ScrollEventAxis::Vertical ? platformEvent->copyIgnoringHorizontalDelta() : platformEvent->copyIgnoringVerticalDelta());
+            else
+                scrollingWasHandled = didScrollInScrollableAreaForSingleAxis(boxLayer, wheelEvent, axis);
+
+            if (scrollingWasHandled) {
+                if (stopElement)
+                    *stopElement = currentEnclosingBox->element();
+                return true;
+            }
+        }
+
+        if (stopElement && *stopElement && *stopElement == currentEnclosingBox->element())
+            return true;
+
+        currentEnclosingBox = currentEnclosingBox->containingBlock();
+        if (currentEnclosingBox && currentEnclosingBox->isRenderNamedFlowThread())
+            currentEnclosingBox = RenderNamedFlowThread::fragmentFromRenderBoxAsRenderBlock(currentEnclosingBox, roundedIntPoint(wheelEvent->absoluteLocation()), initialEnclosingBox);
+        if (!currentEnclosingBox || currentEnclosingBox->isRenderView())
+            return false;
+    }
+    return false;
 }
 
 #if (ENABLE(TOUCH_EVENTS) && !PLATFORM(IOS))
@@ -2631,7 +2666,6 @@
         return;
     
     Element* stopElement = m_previousWheelScrolledElement.get();
-    ScrollGranularity granularity = wheelGranularityToScrollGranularity(wheelEvent->deltaMode());
     DominantScrollGestureDirection dominantDirection = DominantScrollGestureDirection::None;
 
     // Workaround for scrolling issues <rdar://problem/14758615>.
@@ -2642,10 +2676,10 @@
     
     // Break up into two scrolls if we need to.  Diagonal movement on 
     // a MacBook pro is an example of a 2-dimensional mouse wheel event (where both deltaX and deltaY can be set).
-    if (dominantDirection != DominantScrollGestureDirection::Vertical && scrollNode(wheelEvent->deltaX(), granularity, ScrollRight, ScrollLeft, startNode, &stopElement, roundedIntPoint(wheelEvent->absoluteLocation())))
+    if (dominantDirection != DominantScrollGestureDirection::Vertical && handleWheelEventInAppropriateEnclosingBoxForSingleAxis(startNode, wheelEvent, &stopElement, ScrollEventAxis::Horizontal))
         wheelEvent->setDefaultHandled();
     
-    if (dominantDirection != DominantScrollGestureDirection::Horizontal && scrollNode(wheelEvent->deltaY(), granularity, ScrollDown, ScrollUp, startNode, &stopElement, roundedIntPoint(wheelEvent->absoluteLocation())))
+    if (dominantDirection != DominantScrollGestureDirection::Horizontal && handleWheelEventInAppropriateEnclosingBoxForSingleAxis(startNode, wheelEvent, &stopElement, ScrollEventAxis::Vertical))
         wheelEvent->setDefaultHandled();
     
     if (!m_latchedWheelEventElement)

Modified: trunk/Source/WebCore/platform/ScrollTypes.h (171861 => 171862)


--- trunk/Source/WebCore/platform/ScrollTypes.h	2014-07-31 17:15:10 UTC (rev 171861)
+++ trunk/Source/WebCore/platform/ScrollTypes.h	2014-07-31 17:16:08 UTC (rev 171862)
@@ -123,6 +123,8 @@
 
     enum ScrollbarControlSize { RegularScrollbar, SmallScrollbar };
 
+    enum class ScrollEventAxis { Horizontal, Vertical };
+
     typedef unsigned ScrollbarControlState;
 
     enum ScrollbarControlStateMask {

Modified: trunk/Source/WebCore/rendering/RenderListBox.h (171861 => 171862)


--- trunk/Source/WebCore/rendering/RenderListBox.h	2014-07-31 17:15:10 UTC (rev 171861)
+++ trunk/Source/WebCore/rendering/RenderListBox.h	2014-07-31 17:16:08 UTC (rev 171862)
@@ -59,6 +59,8 @@
 
     int size() const;
 
+    virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = nullptr, RenderBox* startBox = nullptr, const IntPoint& wheelEventAbsolutePoint = IntPoint()) override;
+
     virtual bool scrolledToTop() const override;
     virtual bool scrolledToBottom() const override;
     virtual bool scrolledToLeft() const override;
@@ -78,7 +80,6 @@
 
     virtual bool isPointInOverflowControl(HitTestResult&, const LayoutPoint& locationInContainer, const LayoutPoint& accumulatedOffset) override;
 
-    virtual bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = nullptr, RenderBox* startBox = nullptr, const IntPoint& wheelEventAbsolutePoint = IntPoint()) override;
     virtual bool logicalScroll(ScrollLogicalDirection, ScrollGranularity, float multiplier = 1, Element** stopElement = 0) override;
 
     virtual void computeIntrinsicLogicalWidths(LayoutUnit& minLogicalWidth, LayoutUnit& maxLogicalWidth) const override;

Modified: trunk/Source/WebCore/rendering/RenderNamedFlowThread.cpp (171861 => 171862)


--- trunk/Source/WebCore/rendering/RenderNamedFlowThread.cpp	2014-07-31 17:15:10 UTC (rev 171861)
+++ trunk/Source/WebCore/rendering/RenderNamedFlowThread.cpp	2014-07-31 17:16:08 UTC (rev 171862)
@@ -375,6 +375,11 @@
     return visualOverflowRect;
 }
 
+RenderBlock* RenderNamedFlowThread::fragmentFromRenderBoxAsRenderBlock(RenderBox* renderBox, const IntPoint& absolutePoint, const RenderBox& flowedBox)
+{
+    return toRenderNamedFlowThread(renderBox)->fragmentFromAbsolutePointAndBox(absolutePoint, flowedBox);
+}
+
 RenderNamedFlowFragment* RenderNamedFlowThread::fragmentFromAbsolutePointAndBox(const IntPoint& absolutePoint, const RenderBox& flowedBox)
 {
     RenderRegion* startRegion = nullptr;

Modified: trunk/Source/WebCore/rendering/RenderNamedFlowThread.h (171861 => 171862)


--- trunk/Source/WebCore/rendering/RenderNamedFlowThread.h	2014-07-31 17:15:10 UTC (rev 171861)
+++ trunk/Source/WebCore/rendering/RenderNamedFlowThread.h	2014-07-31 17:16:08 UTC (rev 171862)
@@ -62,6 +62,8 @@
     bool hasChild(RenderElement& child) const { return m_flowThreadChildList.contains(&child); }
 #endif
 
+    static RenderBlock* fragmentFromRenderBoxAsRenderBlock(RenderBox*, const IntPoint& absolutePoint, const RenderBox& flowedBox);
+
     void pushDependencies(RenderNamedFlowThreadList&);
 
     virtual void addRegionToThread(RenderRegion*) override;
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to