[GTK] Shift + mouse scroll should scroll horizontally
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Feb 2018 16:04:09 +0000 (16:04 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 1 Feb 2018 16:04:09 +0000 (16:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=181629

Reviewed by Michael Catanzaro.

Source/WebCore:

We currently turn vertical scroll into horizontal when scrolling over the horizontal scrollbar. When Shift key is
pressed, we still want to scroll in the scrollbar direction when scrolling over a scrollbar, so we need to swap
directions in both scrollbars depending on whther the Shift key is pressed or not.

* page/EventHandler.cpp:
(WebCore::EventHandler::shouldSwapScrollDirection const): Renamed.
(WebCore::EventHandler::handleWheelEvent): Use the new name.
(WebCore::EventHandler::shouldTurnVerticalTicksIntoHorizontal const): Deleted.
* page/EventHandler.h:
* platform/PlatformWheelEvent.h:
(WebCore::PlatformWheelEvent::copySwappingDirection const): Swap the direction of the event.
(WebCore::PlatformWheelEvent::copyTurningVerticalTicksIntoHorizontalTicks const): Deleted.
* platform/glib/EventHandlerGLib.cpp:
(WebCore::EventHandler::shouldSwapScrollDirection const): Take into account whether the Shift key is present.
(WebCore::EventHandler::shouldTurnVerticalTicksIntoHorizontal const): Deleted.

Source/WebKit:

Swap scroll direction when Shift is pressed for consistency with GtkScrolledWindow.

* UIProcess/API/gtk/WebKitWebViewBase.cpp:
(webkitWebViewBaseScrollEvent):

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

Source/WebCore/ChangeLog
Source/WebCore/page/EventHandler.cpp
Source/WebCore/page/EventHandler.h
Source/WebCore/platform/PlatformWheelEvent.h
Source/WebCore/platform/glib/EventHandlerGLib.cpp
Source/WebKit/ChangeLog
Source/WebKit/UIProcess/API/gtk/WebKitWebViewBase.cpp

index 942a5c3..e5a3257 100644 (file)
@@ -1,5 +1,28 @@
 2018-02-01  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK] Shift + mouse scroll should scroll horizontally
+        https://bugs.webkit.org/show_bug.cgi?id=181629
+
+        Reviewed by Michael Catanzaro.
+
+        We currently turn vertical scroll into horizontal when scrolling over the horizontal scrollbar. When Shift key is
+        pressed, we still want to scroll in the scrollbar direction when scrolling over a scrollbar, so we need to swap
+        directions in both scrollbars depending on whther the Shift key is pressed or not.
+
+        * page/EventHandler.cpp:
+        (WebCore::EventHandler::shouldSwapScrollDirection const): Renamed.
+        (WebCore::EventHandler::handleWheelEvent): Use the new name.
+        (WebCore::EventHandler::shouldTurnVerticalTicksIntoHorizontal const): Deleted.
+        * page/EventHandler.h:
+        * platform/PlatformWheelEvent.h:
+        (WebCore::PlatformWheelEvent::copySwappingDirection const): Swap the direction of the event.
+        (WebCore::PlatformWheelEvent::copyTurningVerticalTicksIntoHorizontalTicks const): Deleted.
+        * platform/glib/EventHandlerGLib.cpp:
+        (WebCore::EventHandler::shouldSwapScrollDirection const): Take into account whether the Shift key is present.
+        (WebCore::EventHandler::shouldTurnVerticalTicksIntoHorizontal const): Deleted.
+
+2018-02-01  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         [GTK] Problem with Washington Post images
         https://bugs.webkit.org/show_bug.cgi?id=181421
 
index 5c22a3e..e5fc2d2 100644 (file)
@@ -2639,7 +2639,7 @@ bool EventHandler::isInsideScrollbar(const IntPoint& windowPoint) const
 
 #if !PLATFORM(GTK) && !PLATFORM(WPE)
 
-bool EventHandler::shouldTurnVerticalTicksIntoHorizontal(const HitTestResult&, const PlatformWheelEvent&) const
+bool EventHandler::shouldSwapScrollDirection(const HitTestResult&, const PlatformWheelEvent&) const
 {
     return false;
 }
@@ -2783,10 +2783,7 @@ bool EventHandler::handleWheelEvent(const PlatformWheelEvent& event)
 
     // FIXME: It should not be necessary to do this mutation here.
     // Instead, the handlers should know convert vertical scrolls appropriately.
-    PlatformWheelEvent adjustedEvent = event;
-    if (shouldTurnVerticalTicksIntoHorizontal(result, event))
-        adjustedEvent = event.copyTurningVerticalTicksIntoHorizontalTicks();
-
+    PlatformWheelEvent adjustedEvent = shouldSwapScrollDirection(result, event) ? event.copySwappingDirection() : event;
     platformRecordWheelEvent(adjustedEvent);
 
     if (element) {
index e3b42f8..777e809 100644 (file)
@@ -384,7 +384,7 @@ private:
 
     bool logicalScrollOverflow(ScrollLogicalDirection, ScrollGranularity, Node* startingNode = nullptr);
     
-    bool shouldTurnVerticalTicksIntoHorizontal(const HitTestResult&, const PlatformWheelEvent&) const;
+    bool shouldSwapScrollDirection(const HitTestResult&, const PlatformWheelEvent&) const;
     
     bool mouseDownMayStartSelect() const { return m_mouseDownMayStartSelect; }
 
index 2958821..c2d6976 100644 (file)
@@ -81,13 +81,11 @@ public:
     {
     }
 
-    PlatformWheelEvent copyTurningVerticalTicksIntoHorizontalTicks() const
+    PlatformWheelEvent copySwappingDirection() const
     {
         PlatformWheelEvent copy = *this;
-        copy.m_deltaX = copy.m_deltaY;
-        copy.m_deltaY = 0;
-        copy.m_wheelTicksX = copy.m_wheelTicksY;
-        copy.m_wheelTicksY = 0;
+        std::swap(copy.m_deltaX, copy.m_deltaY);
+        std::swap(copy.m_wheelTicksX, copy.m_wheelTicksY);
         return copy;
     }
 
index 763658e..020f349 100644 (file)
@@ -128,14 +128,19 @@ OptionSet<PlatformEvent::Modifier> EventHandler::accessKeyModifiers()
 // horizontal scrollbar while scrolling with the wheel; we need to
 // add the deltas and ticks here so that this behavior is consistent
 // for styled scrollbars.
-bool EventHandler::shouldTurnVerticalTicksIntoHorizontal(const HitTestResult& result, const PlatformWheelEvent& event) const
+bool EventHandler::shouldSwapScrollDirection(const HitTestResult& result, const PlatformWheelEvent& event) const
 {
 #if PLATFORM(GTK)
     FrameView* view = m_frame.view();
     Scrollbar* scrollbar = view ? view->scrollbarAtPoint(event.position()) : nullptr;
     if (!scrollbar)
         scrollbar = result.scrollbar();
-    return scrollbar && scrollbar->orientation() == HorizontalScrollbar;
+    if (!scrollbar)
+        return false;
+
+    // The directions are already swapped when shift key is pressed, but when scrolling
+    // over scrollbars we always want to follow the scrollbar direction.
+    return scrollbar->orientation() == HorizontalScrollbar ? !event.shiftKey() : event.shiftKey();
 #else
     UNUSED_PARAM(result);
     UNUSED_PARAM(event);
index 1f732f7..f31d7b4 100644 (file)
@@ -1,5 +1,17 @@
 2018-02-01  Carlos Garcia Campos  <cgarcia@igalia.com>
 
+        [GTK] Shift + mouse scroll should scroll horizontally
+        https://bugs.webkit.org/show_bug.cgi?id=181629
+
+        Reviewed by Michael Catanzaro.
+
+        Swap scroll direction when Shift is pressed for consistency with GtkScrolledWindow.
+
+        * UIProcess/API/gtk/WebKitWebViewBase.cpp:
+        (webkitWebViewBaseScrollEvent):
+
+2018-02-01  Carlos Garcia Campos  <cgarcia@igalia.com>
+
         REGRESSION(r227893): fast/events/touch/touch-stale-node-crash.html and other tests crash
         https://bugs.webkit.org/show_bug.cgi?id=182350
 
index 7668d1e..f339a40 100644 (file)
@@ -830,6 +830,27 @@ static gboolean webkitWebViewBaseScrollEvent(GtkWidget* widget, GdkEventScroll*
     if (priv->authenticationDialog)
         return GDK_EVENT_PROPAGATE;
 
+    // Shift+Wheel scrolls in the perpendicular direction.
+    if (event->state & GDK_SHIFT_MASK) {
+        switch (event->direction) {
+        case GDK_SCROLL_UP:
+            event->direction = GDK_SCROLL_LEFT;
+            break;
+        case GDK_SCROLL_LEFT:
+            event->direction = GDK_SCROLL_UP;
+            break;
+        case GDK_SCROLL_DOWN:
+            event->direction = GDK_SCROLL_RIGHT;
+            break;
+        case GDK_SCROLL_RIGHT:
+            event->direction = GDK_SCROLL_DOWN;
+            break;
+        case GDK_SCROLL_SMOOTH:
+            std::swap(event->delta_x, event->delta_y);
+            break;
+        }
+    }
+
     webkitWebViewBaseHandleWheelEvent(webViewBase, reinterpret_cast<GdkEvent*>(event));
 
     return GDK_EVENT_STOP;