Skip to content
Permalink
Browse files
[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:

Canonical link: https://commits.webkit.org/172396@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196632 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
carlosgcampos committed Feb 16, 2016
1 parent 161c8fb commit 0bd053218b1c67f7bf017c98adbbafcdea303da2
Showing 14 changed files with 139 additions and 34 deletions.
@@ -1,3 +1,44 @@
2016-02-16 Carlos Garcia Campos <cgarcia@igalia.com>

[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:

2016-02-16 Carlos Garcia Campos <cgarcia@igalia.com>

Mouse cursor doesn't change when entering scrollbars
@@ -180,6 +180,13 @@ enum ScrollBehaviorForFixedElements {
StickToViewportBounds
};

enum class ScrollbarButtonPressAction {
None,
CenterOnThumb,
StartDrag,
Scroll
};

}

#endif
@@ -391,31 +391,34 @@ bool Scrollbar::mouseUp(const PlatformMouseEvent& mouseEvent)

bool Scrollbar::mouseDown(const PlatformMouseEvent& evt)
{
// Early exit for right click
if (evt.button() == RightButton)
return true; // FIXME: Handled as context menu by Qt right now. Should just avoid even calling this method on a right click though.
ScrollbarPart pressedPart = theme().hitTest(*this, evt.position());
auto action = theme().handleMousePressEvent(*this, evt, pressedPart);
if (action == ScrollbarButtonPressAction::None)
return true;

m_scrollableArea.mouseIsDownInScrollbar(this, true);
setPressedPart(theme().hitTest(*this, evt.position()));
int pressedPos = (orientation() == HorizontalScrollbar ? convertFromContainingWindow(evt.position()).x() : convertFromContainingWindow(evt.position()).y());

if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && theme().shouldCenterOnThumb(*this, evt)) {
setPressedPart(pressedPart);

int pressedPosition = (orientation() == HorizontalScrollbar ? convertFromContainingWindow(evt.position()).x() : convertFromContainingWindow(evt.position()).y());
if (action == ScrollbarButtonPressAction::CenterOnThumb) {
setHoveredPart(ThumbPart);
setPressedPart(ThumbPart);
m_dragOrigin = m_currentPos;
int thumbLen = theme().thumbLength(*this);
int desiredPos = pressedPos;
// Set the pressed position to the middle of the thumb so that when we do the move, the delta
// will be from the current pixel position of the thumb to the new desired position for the thumb.
m_pressedPos = theme().trackPosition(*this) + theme().thumbPosition(*this) + thumbLen / 2;
moveThumb(desiredPos);
m_pressedPos = theme().trackPosition(*this) + theme().thumbPosition(*this) + theme().thumbLength(*this) / 2;
moveThumb(pressedPosition);
return true;
} else if (m_pressedPart == ThumbPart)
}

m_pressedPos = pressedPosition;

if (action == ScrollbarButtonPressAction::StartDrag)
m_dragOrigin = m_currentPos;

m_pressedPos = pressedPos;

autoscrollPressedPart(theme().initialAutoscrollTimerDelay());
if (action == ScrollbarButtonPressAction::Scroll)
autoscrollPressedPart(theme().initialAutoscrollTimerDelay());

return true;
}

@@ -26,6 +26,7 @@
#include "config.h"
#include "ScrollbarTheme.h"

#include "PlatformMouseEvent.h"
#include "ScrollbarThemeMock.h"
#include "Settings.h"
#include <wtf/NeverDestroyed.h>
@@ -41,4 +42,13 @@ ScrollbarTheme& ScrollbarTheme::theme()
return nativeTheme();
}

ScrollbarButtonPressAction ScrollbarTheme::handleMousePressEvent(Scrollbar&, const PlatformMouseEvent& event, ScrollbarPart pressedPart)
{
if (event.button() == RightButton)
return ScrollbarButtonPressAction::None;
if (pressedPart == ThumbPart)
return ScrollbarButtonPressAction::StartDrag;
return ScrollbarButtonPressAction::Scroll;
}

}
@@ -95,7 +95,7 @@ class ScrollbarTheme {
virtual void setUpContentShadowLayer(GraphicsLayer*) { }
#endif

virtual bool shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent&) { return false; }
virtual ScrollbarButtonPressAction handleMousePressEvent(Scrollbar&, const PlatformMouseEvent&, ScrollbarPart);
virtual bool shouldSnapBackToDragOrigin(Scrollbar&, const PlatformMouseEvent&) { return false; }
virtual bool shouldDragDocumentInsteadOfThumb(Scrollbar&, const PlatformMouseEvent&) { return false; }
virtual int thumbPosition(Scrollbar&) { return 0; } // The position of the thumb relative to the track.
@@ -493,9 +493,25 @@ bool ScrollbarThemeGtk::paint(Scrollbar& scrollbar, GraphicsContext& graphicsCon
return true;
}

bool ScrollbarThemeGtk::shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent& event)
ScrollbarButtonPressAction ScrollbarThemeGtk::handleMousePressEvent(Scrollbar&, const PlatformMouseEvent& event, ScrollbarPart pressedPart)
{
return (event.shiftKey() && event.button() == LeftButton) || (event.button() == MiddleButton);
switch (pressedPart) {
case BackTrackPart:
case ForwardTrackPart:
if (event.button() == LeftButton)
return ScrollbarButtonPressAction::CenterOnThumb;
if (event.button() == RightButton)
return ScrollbarButtonPressAction::Scroll;
break;
case ThumbPart:
if (event.button() != RightButton)
return ScrollbarButtonPressAction::StartDrag;
break;
default:
break;
}

return ScrollbarButtonPressAction::None;
}

int ScrollbarThemeGtk::scrollbarThickness(ScrollbarControlSize)
@@ -53,7 +53,7 @@ class ScrollbarThemeGtk final : public ScrollbarThemeComposite {
virtual void paintTrackBackground(GraphicsContext&, Scrollbar&, const IntRect&) override;
virtual void paintThumb(GraphicsContext&, Scrollbar&, const IntRect&) override;
virtual void paintButton(GraphicsContext&, Scrollbar&, const IntRect&, ScrollbarPart) override;
virtual bool shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent&) override;
virtual ScrollbarButtonPressAction handleMousePressEvent(Scrollbar&, const PlatformMouseEvent&, ScrollbarPart) override;
virtual int scrollbarThickness(ScrollbarControlSize) override;
virtual int minimumThumbLength(Scrollbar&) override;

@@ -58,9 +58,7 @@ class ScrollbarThemeIOS : public ScrollbarThemeComposite {
virtual IntRect trackRect(Scrollbar&, bool painting = false) override;

virtual int minimumThumbLength(Scrollbar&) override;

virtual bool shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent&) override;


public:
void preferencesChanged();
};
@@ -111,11 +111,6 @@
return 0;
}

bool ScrollbarThemeIOS::shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent&)
{
return false;
}

bool ScrollbarThemeIOS::paint(Scrollbar&, GraphicsContext&, const IntRect& /*damageRect*/)
{
return true;
@@ -84,7 +84,7 @@ class ScrollbarThemeMac : public ScrollbarThemeComposite {

virtual int minimumThumbLength(Scrollbar&) override;

virtual bool shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent&) override;
virtual ScrollbarButtonPressAction handleMousePressEvent(Scrollbar&, const PlatformMouseEvent&, ScrollbarPart) override;
virtual bool shouldDragDocumentInsteadOfThumb(Scrollbar&, const PlatformMouseEvent&) override;
int scrollbarPartToHIPressedState(ScrollbarPart);

@@ -424,7 +424,7 @@ static IntRect buttonRepaintRect(const IntRect& buttonRect, ScrollbarOrientation
END_BLOCK_OBJC_EXCEPTIONS;
}

bool ScrollbarThemeMac::shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent& evt)
static bool shouldCenterOnThumb(const PlatformMouseEvent& evt)
{
if (evt.button() != LeftButton)
return false;
@@ -433,6 +433,26 @@ static IntRect buttonRepaintRect(const IntRect& buttonRect, ScrollbarOrientation
return evt.altKey();
}

ScrollbarButtonPressAction ScrollbarThemeMac::handleMousePressEvent(Scrollbar&, const PlatformMouseEvent& event, ScrollbarPart pressedPart)
{
if (event.button() == RightButton)
return ScrollbarButtonPressAction::None;

switch (pressedPart) {
case BackTrackPart:
case ForwardTrackPart:
if (shouldCenterOnThumb(event))
return ScrollbarButtonPressAction::CenterOnThumb;
break;
case ThumbPart:
return ScrollbarButtonPressAction::StartDrag;
default:
break;
}

return ScrollbarButtonPressAction::Scroll;
}

bool ScrollbarThemeMac::shouldDragDocumentInsteadOfThumb(Scrollbar&, const PlatformMouseEvent& event)
{
return event.altKey();
@@ -193,9 +193,24 @@ IntRect ScrollbarThemeWin::trackRect(Scrollbar& scrollbar, bool)
return IntRect(scrollbar.x(), scrollbar.y() + thickness, thickness, scrollbar.height() - 2 * thickness);
}

bool ScrollbarThemeWin::shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent& evt)
ScrollbarButtonPressAction ScrollbarThemeWin::handleMousePressEvent(Scrollbar&, const PlatformMouseEvent& event, ScrollbarPart pressedPart)
{
return evt.shiftKey() && evt.button() == LeftButton;
if (event.button() == RightButton)
return ScrollbarButtonPressAction::None;

switch (pressedPart) {
case BackTrackPart:
case ForwardTrackPart:
if (event.shiftKey() && event.button() == LeftButton)
return ScrollbarButtonPressAction::CenterOnThumb;
break;
case ThumbPart:
return ScrollbarButtonPressAction::StartDrag;
default:
break;
}

return ScrollbarButtonPressAction::Scroll;
}

bool ScrollbarThemeWin::shouldSnapBackToDragOrigin(Scrollbar& scrollbar, const PlatformMouseEvent& evt)
@@ -49,7 +49,7 @@ class ScrollbarThemeWin : public ScrollbarThemeComposite {
bool hasButtons(Scrollbar&) override { return true; }
bool hasThumb(Scrollbar&) override;

bool shouldCenterOnThumb(Scrollbar&, const PlatformMouseEvent&) override;
virtual ScrollbarButtonPressAction handleMousePressEvent(Scrollbar&, const PlatformMouseEvent&, ScrollbarPart) override;
bool shouldSnapBackToDragOrigin(Scrollbar&, const PlatformMouseEvent&) override;

void paintTrackBackground(GraphicsContext&, Scrollbar&, const IntRect&) override;
@@ -46,8 +46,8 @@ class RenderScrollbarTheme final : public ScrollbarThemeComposite {

virtual void paintScrollCorner(ScrollView*, GraphicsContext&, const IntRect& cornerRect) override;

virtual bool shouldCenterOnThumb(Scrollbar& scrollbar, const PlatformMouseEvent& event) override { return ScrollbarTheme::theme().shouldCenterOnThumb(scrollbar, event); }
virtual ScrollbarButtonPressAction handleMousePressEvent(Scrollbar& scrollbar, const PlatformMouseEvent& event, ScrollbarPart pressedPart) override { return ScrollbarTheme::theme().handleMousePressEvent(scrollbar, event, pressedPart); }

virtual double initialAutoscrollTimerDelay() override { return ScrollbarTheme::theme().initialAutoscrollTimerDelay(); }
virtual double autoscrollTimerDelay() override { return ScrollbarTheme::theme().autoscrollTimerDelay(); }

0 comments on commit 0bd0532

Please sign in to comment.