Commit 30ed544a authored by hyatt@apple.com's avatar hyatt@apple.com

More scrollbar refactoring.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@36369 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent bbdd8fb4
2008-09-12 Dave Hyatt <hyatt@apple.com>
Move the member variables of PlatformScrollbar up into Scrollbar. Move autoscroll timer handling
up into scrollbar. Make sure a bunch of cross-platform code now just uses "Scrollbar" instead of
"PlatformScrollbar."
Reviewed by Sam Weinig
* WebCore.vcproj/WebCore.vcproj:
* editing/EditorCommand.cpp:
* page/EventHandler.cpp:
(WebCore::EventHandler::selectCursor):
(WebCore::EventHandler::handleMousePressEvent):
(WebCore::EventHandler::handleMouseMoveEvent):
* page/EventHandler.h:
* page/MouseEventWithHitTestResults.cpp:
(WebCore::MouseEventWithHitTestResults::scrollbar):
* page/MouseEventWithHitTestResults.h:
* page/gtk/EventHandlerGtk.cpp:
(WebCore::EventHandler::passMousePressEventToScrollbar):
* page/mac/EventHandlerMac.mm:
(WebCore::EventHandler::passMousePressEventToScrollbar):
* page/qt/EventHandlerQt.cpp:
(WebCore::EventHandler::passMousePressEventToScrollbar):
* page/win/EventHandlerWin.cpp:
(WebCore::EventHandler::passMousePressEventToScrollbar):
* page/wx/EventHandlerWx.cpp:
(WebCore::EventHandler::passMousePressEventToScrollbar):
* platform/PopupMenu.h:
* platform/ScrollBar.cpp:
(WebCore::Scrollbar::Scrollbar):
(WebCore::Scrollbar::autoscrollTimerFired):
(WebCore::Scrollbar::autoscrollPressedPart):
(WebCore::Scrollbar::startTimerIfNeeded):
(WebCore::Scrollbar::stopTimerIfNeeded):
(WebCore::Scrollbar::pressedPartScrollDirection):
(WebCore::Scrollbar::pressedPartScrollGranularity):
* platform/ScrollBar.h:
(WebCore::Scrollbar::handleMousePressEvent):
(WebCore::Scrollbar::invalidatePart):
(WebCore::Scrollbar::thumbUnderMouse):
* platform/ScrollView.h:
* platform/ScrollbarClient.h: Added.
(WebCore::ScrollbarClient::~ScrollbarClient):
* platform/gtk/ScrollViewGtk.cpp:
(WebCore::ScrollView::scrollbarUnderMouse):
* platform/qt/PlatformScrollBar.h:
* platform/qt/PlatformScrollBarQt.cpp:
(WebCore::PlatformScrollbar::PlatformScrollbar):
(WebCore::scrollbarPart):
(WebCore::PlatformScrollbar::handleMouseMoveEvent):
(WebCore::PlatformScrollbar::handleMouseOutEvent):
(WebCore::PlatformScrollbar::handleMousePressEvent):
(WebCore::PlatformScrollbar::handleMouseReleaseEvent):
* platform/qt/ScrollViewQt.cpp:
(WebCore::ScrollView::scrollbarUnderMouse):
(WebCore::ScrollView::wheelEvent):
* platform/win/PlatformScrollBar.h:
* platform/win/PlatformScrollBarSafari.cpp:
(WebCore::PlatformScrollbar::PlatformScrollbar):
* platform/win/PlatformScrollBarWin.cpp:
(WebCore::PlatformScrollbar::PlatformScrollbar):
* platform/win/ScrollViewWin.cpp:
(WebCore::ScrollView::scrollbarUnderMouse):
* rendering/HitTestResult.cpp:
(WebCore::HitTestResult::setScrollbar):
* rendering/HitTestResult.h:
(WebCore::HitTestResult::scrollbar):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::hitTestOverflowControls):
* rendering/RenderLayer.h:
* rendering/RenderListBox.h:
2008-09-12 Steve Falkenburg <sfalken@apple.com>
Fix Mac build.
......
<?xml version="1.0" encoding="Windows-1252"?>
<?xml version="1.0" encoding="windows-1251"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
......@@ -3323,6 +3323,10 @@
RelativePath="..\platform\ScrollBar.h"
>
</File>
<File
RelativePath="..\platform\ScrollbarClient.h"
>
</File>
<File
RelativePath="..\platform\ScrollTypes.h"
>
......@@ -3581,48 +3585,6 @@
<File
RelativePath="..\platform\win\PlatformScrollBarWin.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_Internal|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Debug_Cairo|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release_Cairo|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
<FileConfiguration
Name="Release_PGO|Win32"
>
<Tool
Name="VCCLCompilerTool"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\platform\win\PopupMenuWin.cpp"
......
......@@ -42,6 +42,7 @@
#include "InsertListCommand.h"
#include "Page.h"
#include "ReplaceSelectionCommand.h"
#include "ScrollBar.h"
#include "Settings.h"
#include "Sound.h"
#include "TypingCommand.h"
......
......@@ -54,11 +54,11 @@
#include "MouseEventWithHitTestResults.h"
#include "Page.h"
#include "PlatformKeyboardEvent.h"
#include "PlatformScrollBar.h"
#include "PlatformWheelEvent.h"
#include "RenderFrameSet.h"
#include "RenderWidget.h"
#include "RenderView.h"
#include "ScrollBar.h"
#include "SelectionController.h"
#include "Settings.h"
#include "TextEvent.h"
......@@ -817,7 +817,7 @@ static bool nodeIsNotBeingEdited(Node* node, Frame* frame)
return frame->selection()->rootEditableElement() != node->rootEditableElement();
}
Cursor EventHandler::selectCursor(const MouseEventWithHitTestResults& event, PlatformScrollbar* scrollbar)
Cursor EventHandler::selectCursor(const MouseEventWithHitTestResults& event, Scrollbar* scrollbar)
{
// During selection, use an I-beam no matter what we're over.
// If you're capturing mouse events for a particular node, don't treat this as a selection.
......@@ -1064,7 +1064,7 @@ bool EventHandler::handleMousePressEvent(const PlatformMouseEvent& mouseEvent)
if (mev.targetNode()->isShadowNode() && mev.targetNode()->shadowParentNode()->hasTagName(inputTag))
mev = prepareMouseEvent(HitTestRequest(true, true), mouseEvent);
PlatformScrollbar* scrollbar = m_frame->view()->scrollbarUnderMouse(mouseEvent);
Scrollbar* scrollbar = m_frame->view()->scrollbarUnderMouse(mouseEvent);
if (!scrollbar)
scrollbar = mev.scrollbar();
if (scrollbar && passMousePressEventToScrollbar(mev, scrollbar))
......@@ -1166,7 +1166,7 @@ bool EventHandler::handleMouseMoveEvent(const PlatformMouseEvent& mouseEvent, Hi
if (hoveredNode)
*hoveredNode = mev.hitTestResult();
PlatformScrollbar* scrollbar = 0;
Scrollbar* scrollbar = 0;
if (m_resizeLayer && m_resizeLayer->inResizeMode())
m_resizeLayer->resize(mouseEvent, m_offsetFromResizeCorner);
......
......@@ -60,11 +60,11 @@ class KeyboardEvent;
class MouseEventWithHitTestResults;
class Node;
class PlatformKeyboardEvent;
class PlatformScrollbar;
class PlatformWheelEvent;
class RenderLayer;
class RenderObject;
class RenderWidget;
class Scrollbar;
class String;
class TextEvent;
class VisiblePosition;
......@@ -214,7 +214,7 @@ private:
void handleKeyboardSelectionMovement(KeyboardEvent*);
Cursor selectCursor(const MouseEventWithHitTestResults&, PlatformScrollbar*);
Cursor selectCursor(const MouseEventWithHitTestResults&, Scrollbar*);
void setPanScrollCursor();
void hoverTimerFired(Timer<EventHandler>*);
......@@ -256,7 +256,7 @@ private:
bool passSubframeEventToSubframe(MouseEventWithHitTestResults&, Frame* subframe, HitTestResult* hoveredNode = 0);
bool passMousePressEventToScrollbar(MouseEventWithHitTestResults&, PlatformScrollbar*);
bool passMousePressEventToScrollbar(MouseEventWithHitTestResults&, Scrollbar*);
bool passWidgetMouseDownEventToWidget(const MouseEventWithHitTestResults&);
bool passWidgetMouseDownEventToWidget(RenderWidget*);
......@@ -316,7 +316,7 @@ private:
RefPtr<Node> m_nodeUnderMouse;
RefPtr<Node> m_lastNodeUnderMouse;
RefPtr<Frame> m_lastMouseMoveEventSubframe;
RefPtr<PlatformScrollbar> m_lastScrollbarUnderMouse;
RefPtr<Scrollbar> m_lastScrollbarUnderMouse;
int m_clickCount;
RefPtr<Node> m_clickNode;
......
......@@ -61,7 +61,7 @@ const IntPoint MouseEventWithHitTestResults::localPoint() const
return m_hitTestResult.localPoint();
}
PlatformScrollbar* MouseEventWithHitTestResults::scrollbar() const
Scrollbar* MouseEventWithHitTestResults::scrollbar() const
{
return m_hitTestResult.scrollbar();
}
......
......@@ -26,7 +26,7 @@
namespace WebCore {
class PlatformScrollbar;
class Scrollbar;
// FIXME: Why doesn't this class just cache a HitTestResult instead of copying all of HitTestResult's fields over?
class MouseEventWithHitTestResults {
......@@ -37,7 +37,7 @@ public:
const HitTestResult& hitTestResult() const { return m_hitTestResult; }
Node* targetNode() const;
const IntPoint localPoint() const;
PlatformScrollbar* scrollbar() const;
Scrollbar* scrollbar() const;
bool isOverLink() const;
private:
......
......@@ -37,9 +37,9 @@
#include "NotImplemented.h"
#include "Page.h"
#include "PlatformKeyboardEvent.h"
#include "PlatformScrollBar.h"
#include "PlatformWheelEvent.h"
#include "RenderWidget.h"
#include "ScrollBar.h"
namespace WebCore {
......@@ -123,7 +123,7 @@ bool EventHandler::passMouseReleaseEventToSubframe(MouseEventWithHitTestResults&
return true;
}
bool EventHandler::passMousePressEventToScrollbar(MouseEventWithHitTestResults&, PlatformScrollbar* scrollbar)
bool EventHandler::passMousePressEventToScrollbar(MouseEventWithHitTestResults&, Scrollbar* scrollbar)
{
notImplemented();
return false;
......
......@@ -38,9 +38,9 @@
#include "MouseEventWithHitTestResults.h"
#include "Page.h"
#include "PlatformKeyboardEvent.h"
#include "PlatformScrollBar.h"
#include "PlatformWheelEvent.h"
#include "RenderWidget.h"
#include "ScrollBar.h"
#include "Settings.h"
namespace WebCore {
......@@ -645,7 +645,7 @@ bool EventHandler::passMouseReleaseEventToSubframe(MouseEventWithHitTestResults&
return passSubframeEventToSubframe(mev, subframe);
}
bool EventHandler::passMousePressEventToScrollbar(MouseEventWithHitTestResults&, PlatformScrollbar* scrollbar)
bool EventHandler::passMousePressEventToScrollbar(MouseEventWithHitTestResults&, Scrollbar* scrollbar)
{
return passMouseDownEventToWidget(scrollbar);
}
......
......@@ -45,9 +45,9 @@
#include "MouseEventWithHitTestResults.h"
#include "Page.h"
#include "PlatformKeyboardEvent.h"
#include "PlatformScrollBar.h"
#include "PlatformWheelEvent.h"
#include "RenderWidget.h"
#include "ScrollBar.h"
#include "NotImplemented.h"
QT_BEGIN_NAMESPACE
......@@ -134,7 +134,7 @@ bool EventHandler::passMouseReleaseEventToSubframe(MouseEventWithHitTestResults&
return true;
}
bool EventHandler::passMousePressEventToScrollbar(MouseEventWithHitTestResults& mev, PlatformScrollbar* scrollbar)
bool EventHandler::passMousePressEventToScrollbar(MouseEventWithHitTestResults& mev, Scrollbar* scrollbar)
{
if (!scrollbar || !scrollbar->isEnabled())
return false;
......
......@@ -37,8 +37,8 @@
#include "MouseEventWithHitTestResults.h"
#include "Page.h"
#include "PlatformKeyboardEvent.h"
#include "PlatformScrollbar.h"
#include "PlatformWheelEvent.h"
#include "Scrollbar.h"
#include "SelectionController.h"
#include "WCDataObject.h"
#include "NotImplemented.h"
......@@ -77,7 +77,7 @@ bool EventHandler::passWheelEventToWidget(PlatformWheelEvent& wheelEvent, Widget
return static_cast<FrameView*>(widget)->frame()->eventHandler()->handleWheelEvent(wheelEvent);
}
bool EventHandler::passMousePressEventToScrollbar(MouseEventWithHitTestResults& mev, PlatformScrollbar* scrollbar)
bool EventHandler::passMousePressEventToScrollbar(MouseEventWithHitTestResults& mev, Scrollbar* scrollbar)
{
if (!scrollbar || !scrollbar->isEnabled())
return false;
......
......@@ -34,8 +34,8 @@
#include "MouseEventWithHitTestResults.h"
#include "Page.h"
#include "PlatformKeyboardEvent.h"
#include "PlatformScrollBar.h"
#include "RenderWidget.h"
#include "ScrollBar.h"
namespace WebCore {
......@@ -58,7 +58,7 @@ bool EventHandler::passMouseReleaseEventToSubframe(MouseEventWithHitTestResults&
return passSubframeEventToSubframe(mev, subframe);
}
bool EventHandler::passMousePressEventToScrollbar(MouseEventWithHitTestResults& mouseEvent, PlatformScrollbar* scrollbar)
bool EventHandler::passMousePressEventToScrollbar(MouseEventWithHitTestResults& mouseEvent, Scrollbar* scrollbar)
{
return passMouseDownEventToWidget(scrollbar);
}
......
......@@ -35,6 +35,7 @@ class NSPopUpButtonCell;
#endif
#elif PLATFORM(WIN)
#include "ScrollBar.h"
#include "ScrollbarClient.h"
#include <wtf/RefPtr.h>
typedef struct HWND__* HWND;
typedef struct HDC__* HDC;
......
......@@ -26,11 +26,17 @@
#include "config.h"
#include "ScrollBar.h"
#include "ScrollbarClient.h"
#include <algorithm>
using std::max;
using std::min;
// FIXME: These constants should come from the ScrollbarTheme.
const double cInitialTimerDelay = 0.25;
const double cNormalTimerDelay = 0.05;
namespace WebCore {
Scrollbar::Scrollbar(ScrollbarClient* client, ScrollbarOrientation orientation, ScrollbarControlSize controlSize)
......@@ -43,6 +49,11 @@ Scrollbar::Scrollbar(ScrollbarClient* client, ScrollbarOrientation orientation,
, m_lineStep(0)
, m_pageStep(0)
, m_pixelStep(1)
, m_hoveredPart(NoPart)
, m_pressedPart(NoPart)
, m_pressedPos(0)
, m_scrollTimer(this, &Scrollbar::autoscrollTimerFired)
, m_overlapsResizer(false)
{
}
......@@ -114,4 +125,80 @@ bool Scrollbar::scroll(ScrollDirection direction, ScrollGranularity granularity,
return true;
}
void Scrollbar::autoscrollTimerFired(Timer<Scrollbar>*)
{
autoscrollPressedPart(cNormalTimerDelay); // FIXME: Get timer delay from ScrollbarTheme.
}
void Scrollbar::autoscrollPressedPart(double delay)
{
// Don't do anything for the thumb or if nothing was pressed.
if (m_pressedPart == ThumbPart || m_pressedPart == NoPart)
return;
// Handle the track.
if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && thumbUnderMouse()) {
invalidatePart(m_pressedPart);
m_hoveredPart = ThumbPart;
return;
}
// Handle the arrows and track.
if (scroll(pressedPartScrollDirection(), pressedPartScrollGranularity()))
startTimerIfNeeded(delay);
}
void Scrollbar::startTimerIfNeeded(double delay)
{
// Don't do anything for the thumb.
if (m_pressedPart == ThumbPart)
return;
// Handle the track. We halt track scrolling once the thumb is level
// with us.
if ((m_pressedPart == BackTrackPart || m_pressedPart == ForwardTrackPart) && thumbUnderMouse()) {
invalidatePart(m_pressedPart);
m_hoveredPart = ThumbPart;
return;
}
// We can't scroll if we've hit the beginning or end.
ScrollDirection dir = pressedPartScrollDirection();
if (dir == ScrollUp || dir == ScrollLeft) {
if (m_currentPos == 0)
return;
} else {
if (m_currentPos == m_totalSize - m_visibleSize)
return;
}
m_scrollTimer.startOneShot(delay);
}
void Scrollbar::stopTimerIfNeeded()
{
if (m_scrollTimer.isActive())
m_scrollTimer.stop();
}
ScrollDirection Scrollbar::pressedPartScrollDirection()
{
if (m_orientation == HorizontalScrollbar) {
if (m_pressedPart == BackButtonPart || m_pressedPart == BackTrackPart)
return ScrollLeft;
return ScrollRight;
} else {
if (m_pressedPart == BackButtonPart || m_pressedPart == BackTrackPart)
return ScrollUp;
return ScrollDown;
}
}
ScrollGranularity Scrollbar::pressedPartScrollGranularity()
{
if (m_pressedPart == BackButtonPart || m_pressedPart == ForwardButtonPart)
return ScrollByLine;
return ScrollByPage;
}
}
......@@ -28,6 +28,7 @@
#include <wtf/RefCounted.h>
#include "ScrollTypes.h"
#include "Timer.h"
#include "Widget.h"
#include <wtf/MathExtras.h>
......@@ -35,26 +36,13 @@ namespace WebCore {
class GraphicsContext;
class IntRect;
class Scrollbar;
class ScrollbarClient;
class PlatformMouseEvent;
// These match the numbers we use over in WebKit (WebFrameView.m).
#define LINE_STEP 40
#define PAGE_KEEP 40
class ScrollbarClient {
public:
virtual ~ScrollbarClient() {}
virtual void valueChanged(Scrollbar*) = 0;
// Used to obtain a window clip rect.
virtual IntRect windowClipRect() const = 0;
// FIXME: It would be nice to set this state on the scroll bar instead of
// having to ask for it from the client at paint time.
virtual bool isActive() const = 0;
};
class Scrollbar : public Widget, public RefCounted<Scrollbar> {
protected:
Scrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize);
......@@ -90,11 +78,24 @@ public:
// Used by some platform scrollbars to know when they've been released from capture.
virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&) { return false; }
virtual bool handleMousePressEvent(const PlatformMouseEvent&) { return false; }
protected:
virtual void updateThumbPosition() = 0;
virtual void updateThumbProportion() = 0;
// FIXME: This two methods will not need to be virtual eventually.
virtual void invalidatePart(ScrollbarPart part) {}
virtual bool thumbUnderMouse() { return false; }
void autoscrollTimerFired(Timer<Scrollbar>*);
void startTimerIfNeeded(double delay);
void stopTimerIfNeeded();
void autoscrollPressedPart(double delay);
ScrollDirection pressedPartScrollDirection();
ScrollGranularity pressedPartScrollGranularity();
ScrollbarClient* client() const { return m_client; }
ScrollbarClient* m_client;
......@@ -106,6 +107,12 @@ protected:
int m_lineStep;
int m_pageStep;
float m_pixelStep;
ScrollbarPart m_hoveredPart;
ScrollbarPart m_pressedPart;
int m_pressedPos;
Timer<Scrollbar> m_scrollTimer;
bool m_overlapsResizer;
};
}
......
......@@ -50,8 +50,8 @@ class wxScrollWinEvent;
namespace WebCore {
class FloatRect;
class PlatformScrollbar;
class PlatformWheelEvent;
class Scrollbar;
class ScrollView : public Widget {
public:
......@@ -108,7 +108,7 @@ namespace WebCore {
virtual bool shouldUpdateWhileOffscreen() const = 0;
// For platforms that need to hit test scrollbars from within the engine's event handlers (like Win32).
PlatformScrollbar* scrollbarUnderMouse(const PlatformMouseEvent& mouseEvent);
Scrollbar* scrollbarUnderMouse(const PlatformMouseEvent& mouseEvent);
// This method exists for scrollviews that need to handle wheel events manually.
// On Mac the underlying NSScrollView just does the scrolling, but on other platforms
......
/*
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef ScrollbarClient_h
#define ScrollbarClient_h
#include "IntRect.h"
namespace WebCore {
class Scrollbar;
class ScrollbarClient {
public:
virtual ~ScrollbarClient() {}
virtual void valueChanged(Scrollbar*) = 0;
// Used to obtain a window clip rect.
virtual IntRect windowClipRect() const = 0;
virtual bool isActive() const = 0;
};
}
#endif
......@@ -681,7 +681,7 @@ IntPoint ScrollView::contentsToWindow(const IntPoint& contentsPoint) const
return convertToContainingWindow(viewPoint);
}
PlatformScrollbar* ScrollView::scrollbarUnderMouse(const PlatformMouseEvent& mouseEvent)
Scrollbar* ScrollView::scrollbarUnderMouse(const PlatformMouseEvent& mouseEvent)
{
IntPoint viewPoint = convertFromContainingWindow(mouseEvent.pos());
if (m_data->hBar && m_data->hBar->frameGeometry().contains(viewPoint))
......
......@@ -91,10 +91,6 @@ private:
int pixelPosToRangeValue(int pos) const;
int m_pressedPos;
QStyle::SubControl m_pressedPart;
QStyle::SubControl m_hoveredPart;
Timer<PlatformScrollbar> m_scrollTimer;
QStyleOptionSlider m_opt;
};
......
......@@ -56,10 +56,6 @@ const double cNormalTimerDelay = 0.05;
PlatformScrollbar::PlatformScrollbar(ScrollbarClient* client, ScrollbarOrientation orientation, ScrollbarControlSize size)
: Scrollbar(client, orientation, size)
, m_pressedPos(0)
, m_pressedPart(QStyle::SC_None)
, m_hoveredPart(QStyle::SC_None)
, m_scrollTimer(this, &PlatformScrollbar::autoscrollTimerFired)
{
QStyle *s = QApplication::style();
......@@ -231,6 +227,26 @@ int PlatformScrollbar::pixelPosToRangeValue(int pos) const
thumbMax - thumbMin, m_opt.upsideDown);
}
ScrollbarPart scrollbarPart(const QStyle::SubControl& sc)
{
switch (sc) {
case QStyle::SC_None:
return NoPart;
case QStyle::SC_ScrollBarSubLine:
return BackButtonPart;
case QStyle::SC_ScrollBarSubPage:
return BackTrackPart;
case QStyle::SC_ScrollBarSlider:
return ThumbPart;
case QStyle::SC_ScrollBarAddPage:
return ForwardTrackPart;
case QStyle::SC_ScrollBarAddLine:
return ForwardButtonPart;
default:
return NoPart;
}
}
bool PlatformScrollbar::handleMouseMoveEvent(const PlatformMouseEvent& evt)
{
const QPoint pos = convertFromContainingWindow(evt.pos());
......@@ -242,7 +258,7 @@ bool PlatformScrollbar::handleMouseMoveEvent(const PlatformMouseEvent& evt)
QStyle::SubControl sc = QApplication::style()->hitTestComplexControl(QStyle::CC_ScrollBar, &m_opt, pos, 0);
m_opt.rect.moveTo(topLeft);
if (m_pressedPart == QStyle::SC_ScrollBarSlider) {
if (m_pressedPart == ThumbPart) {
// Drag the thumb.
int thumbPos = thumbPosition();
int thumbLen = thumbLength();
......@@ -269,12 +285,13 @@ bool PlatformScrollbar::handleMouseMoveEvent(const PlatformMouseEvent& evt)
return true;
}