Changeset 196632 in webkit


Ignore:
Timestamp:
Feb 16, 2016 1:50:26 AM (8 years ago)
Author:
Carlos Garcia Campos
Message:

[GTK] clicking on the scrollbar trough steps rather than jumps to the clicked position
https://bugs.webkit.org/show_bug.cgi?id=115363

Reviewed by Michael Catanzaro.

Allow ScrollbarTheme to decide the behavior of a button press event,
instead of only deciding whether to center on thumb or not. This
way we can match the current GTK+ behavior in WebKit, without
affecting other ports.

  • platform/ScrollTypes.h: Add ScrollbarButtonPressAction enum.
  • platform/Scrollbar.cpp:

(WebCore::Scrollbar::mouseDown): Ask ScrollbarTheme to handle the
event for the pressed part and do the requested action.

  • platform/ScrollbarTheme.cpp:

(WebCore::ScrollbarTheme::handleMousePressEvent): Add default
implementation. It's equivalent to the previous default implementation.

  • platform/ScrollbarTheme.h:
  • platform/gtk/ScrollbarThemeGtk.cpp:

(WebCore::ScrollbarThemeGtk::handleMousePressEvent): Match current
GTK+ behavior: left click centers on thumb and right click
scrolls. Dragging the thumb works for left and middle buttons.

  • platform/gtk/ScrollbarThemeGtk.h:
  • platform/ios/ScrollbarThemeIOS.h: Remove shouldCenterOnThumb,

and don't override handleMousePressEvent since iOS wants the
default behavior.

  • platform/ios/ScrollbarThemeIOS.mm:
  • platform/mac/ScrollbarThemeMac.h: Override handleMousePressEvent

and remove shouldCenterOnThumb.

  • platform/mac/ScrollbarThemeMac.mm:

(WebCore::shouldCenterOnThumb): Same implementation just made it
static to be used as helper.
(WebCore::ScrollbarThemeMac::handleMousePressEvent): Return the
desired action keeping the same behavior.

  • platform/win/ScrollbarThemeWin.cpp:

(WebCore::ScrollbarThemeWin::handleMousePressEvent): Ditto.

  • platform/win/ScrollbarThemeWin.h:
  • rendering/RenderScrollbarTheme.h:
Location:
trunk/Source/WebCore
Files:
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r196631 r196632  
     12016-02-16  Carlos Garcia Campos  <cgarcia@igalia.com>
     2
     3        [GTK] clicking on the scrollbar trough steps rather than jumps to the clicked position
     4        https://bugs.webkit.org/show_bug.cgi?id=115363
     5
     6        Reviewed by Michael Catanzaro.
     7
     8        Allow ScrollbarTheme to decide the behavior of a button press event,
     9        instead of only deciding whether to center on thumb or not. This
     10        way we can match the current GTK+ behavior in WebKit, without
     11        affecting other ports.
     12
     13        * platform/ScrollTypes.h: Add ScrollbarButtonPressAction enum.
     14        * platform/Scrollbar.cpp:
     15        (WebCore::Scrollbar::mouseDown): Ask ScrollbarTheme to handle the
     16        event for the pressed part and do the requested action.
     17        * platform/ScrollbarTheme.cpp:
     18        (WebCore::ScrollbarTheme::handleMousePressEvent): Add default
     19        implementation. It's equivalent to the previous default implementation.
     20        * platform/ScrollbarTheme.h:
     21        * platform/gtk/ScrollbarThemeGtk.cpp:
     22        (WebCore::ScrollbarThemeGtk::handleMousePressEvent): Match current
     23        GTK+ behavior: left click centers on thumb and right click
     24        scrolls. Dragging the thumb works for left and middle buttons.
     25        * platform/gtk/ScrollbarThemeGtk.h:
     26        * platform/ios/ScrollbarThemeIOS.h: Remove shouldCenterOnThumb,
     27        and don't override handleMousePressEvent since iOS wants the
     28        default behavior.
     29        * platform/ios/ScrollbarThemeIOS.mm:
     30        * platform/mac/ScrollbarThemeMac.h: Override handleMousePressEvent
     31        and remove shouldCenterOnThumb.
     32        * platform/mac/ScrollbarThemeMac.mm:
     33        (WebCore::shouldCenterOnThumb): Same implementation just made it
     34        static to be used as helper.
     35        (WebCore::ScrollbarThemeMac::handleMousePressEvent): Return the
     36        desired action keeping the same behavior.
     37        * platform/win/ScrollbarThemeWin.cpp:
     38        (WebCore::ScrollbarThemeWin::handleMousePressEvent): Ditto.
     39        * platform/win/ScrollbarThemeWin.h:
     40        * rendering/RenderScrollbarTheme.h:
     41
    1422016-02-16  Carlos Garcia Campos  <cgarcia@igalia.com>
    243
  • trunk/Source/WebCore/platform/ScrollTypes.h

    r196248 r196632  
    181181};
    182182
     183enum class ScrollbarButtonPressAction {
     184    None,
     185    CenterOnThumb,
     186    StartDrag,
     187    Scroll
     188};
     189
    183190}
    184191
  • trunk/Source/WebCore/platform/Scrollbar.cpp

    r194515 r196632  
    392392bool Scrollbar::mouseDown(const PlatformMouseEvent& evt)
    393393{
    394     // Early exit for right click
    395     if (evt.button() == RightButton)
    396         return true; // FIXME: Handled as context menu by Qt right now.  Should just avoid even calling this method on a right click though.
     394    ScrollbarPart pressedPart = theme().hitTest(*this, evt.position());
     395    auto action = theme().handleMousePressEvent(*this, evt, pressedPart);
     396    if (action == ScrollbarButtonPressAction::None)
     397        return true;
    397398
    398399    m_scrollableArea.mouseIsDownInScrollbar(this, true);
    399     setPressedPart(theme().hitTest(*this, evt.position()));
    400     int pressedPos = (orientation() == HorizontalScrollbar ? convertFromContainingWindow(evt.position()).x() : convertFromContainingWindow(evt.position()).y());
    401    
    402     if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && theme().shouldCenterOnThumb(*this, evt)) {
     400    setPressedPart(pressedPart);
     401
     402    int pressedPosition = (orientation() == HorizontalScrollbar ? convertFromContainingWindow(evt.position()).x() : convertFromContainingWindow(evt.position()).y());
     403    if (action == ScrollbarButtonPressAction::CenterOnThumb) {
    403404        setHoveredPart(ThumbPart);
    404405        setPressedPart(ThumbPart);
    405406        m_dragOrigin = m_currentPos;
    406         int thumbLen = theme().thumbLength(*this);
    407         int desiredPos = pressedPos;
    408407        // Set the pressed position to the middle of the thumb so that when we do the move, the delta
    409408        // will be from the current pixel position of the thumb to the new desired position for the thumb.
    410         m_pressedPos = theme().trackPosition(*this) + theme().thumbPosition(*this) + thumbLen / 2;
    411         moveThumb(desiredPos);
     409        m_pressedPos = theme().trackPosition(*this) + theme().thumbPosition(*this) + theme().thumbLength(*this) / 2;
     410        moveThumb(pressedPosition);
    412411        return true;
    413     } else if (m_pressedPart == ThumbPart)
     412    }
     413
     414    m_pressedPos = pressedPosition;
     415
     416    if (action == ScrollbarButtonPressAction::StartDrag)
    414417        m_dragOrigin = m_currentPos;
    415    
    416     m_pressedPos = pressedPos;
    417 
    418     autoscrollPressedPart(theme().initialAutoscrollTimerDelay());
     418
     419    if (action == ScrollbarButtonPressAction::Scroll)
     420        autoscrollPressedPart(theme().initialAutoscrollTimerDelay());
     421
    419422    return true;
    420423}
  • trunk/Source/WebCore/platform/ScrollbarTheme.cpp

    r194819 r196632  
    2727#include "ScrollbarTheme.h"
    2828
     29#include "PlatformMouseEvent.h"
    2930#include "ScrollbarThemeMock.h"
    3031#include "Settings.h"
     
    4243}
    4344
     45ScrollbarButtonPressAction ScrollbarTheme::handleMousePressEvent(Scrollbar&, const PlatformMouseEvent& event, ScrollbarPart pressedPart)
     46{
     47    if (event.button() == RightButton)
     48        return ScrollbarButtonPressAction::None;
     49    if (pressedPart == ThumbPart)
     50        return ScrollbarButtonPressAction::StartDrag;
     51    return ScrollbarButtonPressAction::Scroll;
    4452}
     53
     54}
  • trunk/Source/WebCore/platform/ScrollbarTheme.h

    r192140 r196632  
    9696#endif
    9797
    98     virtual bool shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent&) { return false; }
     98    virtual ScrollbarButtonPressAction handleMousePressEvent(Scrollbar&, const PlatformMouseEvent&, ScrollbarPart);
    9999    virtual bool shouldSnapBackToDragOrigin(Scrollbar&, const PlatformMouseEvent&) { return false; }
    100100    virtual bool shouldDragDocumentInsteadOfThumb(Scrollbar&, const PlatformMouseEvent&) { return false; }
  • trunk/Source/WebCore/platform/gtk/ScrollbarThemeGtk.cpp

    r196172 r196632  
    494494}
    495495
    496 bool ScrollbarThemeGtk::shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent& event)
    497 {
    498     return (event.shiftKey() && event.button() == LeftButton) || (event.button() == MiddleButton);
     496ScrollbarButtonPressAction ScrollbarThemeGtk::handleMousePressEvent(Scrollbar&, const PlatformMouseEvent& event, ScrollbarPart pressedPart)
     497{
     498    switch (pressedPart) {
     499    case BackTrackPart:
     500    case ForwardTrackPart:
     501        if (event.button() == LeftButton)
     502            return ScrollbarButtonPressAction::CenterOnThumb;
     503        if (event.button() == RightButton)
     504            return ScrollbarButtonPressAction::Scroll;
     505        break;
     506    case ThumbPart:
     507        if (event.button() != RightButton)
     508            return ScrollbarButtonPressAction::StartDrag;
     509        break;
     510    default:
     511        break;
     512    }
     513
     514    return ScrollbarButtonPressAction::None;
    499515}
    500516
  • trunk/Source/WebCore/platform/gtk/ScrollbarThemeGtk.h

    r195810 r196632  
    5454    virtual void paintThumb(GraphicsContext&, Scrollbar&, const IntRect&) override;
    5555    virtual void paintButton(GraphicsContext&, Scrollbar&, const IntRect&, ScrollbarPart) override;
    56     virtual bool shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent&) override;
     56    virtual ScrollbarButtonPressAction handleMousePressEvent(Scrollbar&, const PlatformMouseEvent&, ScrollbarPart) override;
    5757    virtual int scrollbarThickness(ScrollbarControlSize) override;
    5858    virtual int minimumThumbLength(Scrollbar&) override;
  • trunk/Source/WebCore/platform/ios/ScrollbarThemeIOS.h

    r185964 r196632  
    5959
    6060    virtual int minimumThumbLength(Scrollbar&) override;
    61    
    62     virtual bool shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent&) override;
    63    
     61
    6462public:
    6563    void preferencesChanged();
  • trunk/Source/WebCore/platform/ios/ScrollbarThemeIOS.mm

    r189270 r196632  
    112112}
    113113
    114 bool ScrollbarThemeIOS::shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent&)
    115 {
    116     return false;
    117 }
    118 
    119114bool ScrollbarThemeIOS::paint(Scrollbar&, GraphicsContext&, const IntRect& /*damageRect*/)
    120115{
  • trunk/Source/WebCore/platform/mac/ScrollbarThemeMac.h

    r185964 r196632  
    8585    virtual int minimumThumbLength(Scrollbar&) override;
    8686   
    87     virtual bool shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent&) override;
     87    virtual ScrollbarButtonPressAction handleMousePressEvent(Scrollbar&, const PlatformMouseEvent&, ScrollbarPart) override;
    8888    virtual bool shouldDragDocumentInsteadOfThumb(Scrollbar&, const PlatformMouseEvent&) override;
    8989    int scrollbarPartToHIPressedState(ScrollbarPart);
  • trunk/Source/WebCore/platform/mac/ScrollbarThemeMac.mm

    r196247 r196632  
    425425}
    426426
    427 bool ScrollbarThemeMac::shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent& evt)
     427static bool shouldCenterOnThumb(const PlatformMouseEvent& evt)
    428428{
    429429    if (evt.button() != LeftButton)
     
    432432        return !evt.altKey();
    433433    return evt.altKey();
     434}
     435
     436ScrollbarButtonPressAction ScrollbarThemeMac::handleMousePressEvent(Scrollbar&, const PlatformMouseEvent& event, ScrollbarPart pressedPart)
     437{
     438    if (event.button() == RightButton)
     439        return ScrollbarButtonPressAction::None;
     440
     441    switch (pressedPart) {
     442    case BackTrackPart:
     443    case ForwardTrackPart:
     444        if (shouldCenterOnThumb(event))
     445            return ScrollbarButtonPressAction::CenterOnThumb;
     446        break;
     447    case ThumbPart:
     448        return ScrollbarButtonPressAction::StartDrag;
     449    default:
     450        break;
     451    }
     452
     453    return ScrollbarButtonPressAction::Scroll;
    434454}
    435455
  • trunk/Source/WebCore/platform/win/ScrollbarThemeWin.cpp

    r189270 r196632  
    194194}
    195195
    196 bool ScrollbarThemeWin::shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent& evt)
    197 {
    198     return evt.shiftKey() && evt.button() == LeftButton;
     196ScrollbarButtonPressAction ScrollbarThemeWin::handleMousePressEvent(Scrollbar&, const PlatformMouseEvent& event, ScrollbarPart pressedPart)
     197{
     198    if (event.button() == RightButton)
     199        return ScrollbarButtonPressAction::None;
     200
     201    switch (pressedPart) {
     202    case BackTrackPart:
     203    case ForwardTrackPart:
     204        if (event.shiftKey() && event.button() == LeftButton)
     205            return ScrollbarButtonPressAction::CenterOnThumb;
     206        break;
     207    case ThumbPart:
     208        return ScrollbarButtonPressAction::StartDrag;
     209    default:
     210        break;
     211    }
     212
     213    return ScrollbarButtonPressAction::Scroll;
    199214}
    200215
  • trunk/Source/WebCore/platform/win/ScrollbarThemeWin.h

    r185964 r196632  
    5050    bool hasThumb(Scrollbar&) override;
    5151
    52     bool shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent&) override;
     52    virtual ScrollbarButtonPressAction handleMousePressEvent(Scrollbar&, const PlatformMouseEvent&, ScrollbarPart) override;
    5353    bool shouldSnapBackToDragOrigin(Scrollbar&, const PlatformMouseEvent&) override;
    5454
  • trunk/Source/WebCore/rendering/RenderScrollbarTheme.h

    r189270 r196632  
    4747    virtual void paintScrollCorner(ScrollView*, GraphicsContext&, const IntRect& cornerRect) override;
    4848
    49     virtual bool shouldCenterOnThumb(Scrollbar& scrollbar, const PlatformMouseEvent& event) override { return ScrollbarTheme::theme().shouldCenterOnThumb(scrollbar, event); }
    50    
     49    virtual ScrollbarButtonPressAction handleMousePressEvent(Scrollbar& scrollbar, const PlatformMouseEvent& event, ScrollbarPart pressedPart) override { return ScrollbarTheme::theme().handleMousePressEvent(scrollbar, event, pressedPart); }
     50
    5151    virtual double initialAutoscrollTimerDelay() override { return ScrollbarTheme::theme().initialAutoscrollTimerDelay(); }
    5252    virtual double autoscrollTimerDelay() override { return ScrollbarTheme::theme().autoscrollTimerDelay(); }
Note: See TracChangeset for help on using the changeset viewer.