2
* Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
#include "ScrollbarThemeClient.h"
30
#include "ScrollTypes.h"
33
#include <wtf/MathExtras.h>
34
#include <wtf/PassRefPtr.h>
38
class GraphicsContext;
40
class PlatformMouseEvent;
44
#if ENABLE(GESTURE_EVENTS)
45
class PlatformGestureEvent;
48
class Scrollbar : public Widget,
49
public ScrollbarThemeClient {
52
// Must be implemented by platforms that can't simply use the Scrollbar base class. Right now the only platform that is not using the base class is GTK.
53
static PassRefPtr<Scrollbar> createNativeScrollbar(ScrollableArea*, ScrollbarOrientation orientation, ScrollbarControlSize size);
57
// ScrollbarThemeClient implementation.
58
virtual int x() const { return Widget::x(); }
59
virtual int y() const { return Widget::y(); }
60
virtual int width() const { return Widget::width(); }
61
virtual int height() const { return Widget::height(); }
62
virtual IntSize size() const { return Widget::size(); }
63
virtual IntPoint location() const { return Widget::location(); }
65
virtual ScrollView* parent() const { return Widget::parent(); }
66
virtual ScrollView* root() const { return Widget::root(); }
68
virtual void setFrameRect(const IntRect&);
69
virtual IntRect frameRect() const { return Widget::frameRect(); }
71
virtual void invalidate() { Widget::invalidate(); }
72
virtual void invalidateRect(const IntRect&);
74
virtual ScrollbarOverlayStyle scrollbarOverlayStyle() const;
75
virtual void getTickmarks(Vector<IntRect>&) const;
76
virtual bool isScrollableAreaActive() const;
77
virtual bool isScrollViewScrollbar() const;
79
virtual IntPoint convertFromContainingWindow(const IntPoint& windowPoint) { return Widget::convertFromContainingWindow(windowPoint); }
81
virtual bool isCustomScrollbar() const { return false; }
82
virtual ScrollbarOrientation orientation() const { return m_orientation; }
84
virtual int value() const { return lroundf(m_currentPos); }
85
virtual float currentPos() const { return m_currentPos; }
86
virtual int visibleSize() const { return m_visibleSize; }
87
virtual int totalSize() const { return m_totalSize; }
88
virtual int maximum() const { return m_totalSize - m_visibleSize; }
89
virtual ScrollbarControlSize controlSize() const { return m_controlSize; }
91
virtual int lineStep() const { return m_lineStep; }
92
virtual int pageStep() const { return m_pageStep; }
94
virtual ScrollbarPart pressedPart() const { return m_pressedPart; }
95
virtual ScrollbarPart hoveredPart() const { return m_hoveredPart; }
97
virtual void styleChanged() { }
99
virtual bool enabled() const { return m_enabled; }
100
virtual void setEnabled(bool);
102
// Called by the ScrollableArea when the scroll offset changes.
103
void offsetDidChange();
105
static int pixelsPerLineStep() { return 40; }
106
static float minFractionToStepWhenPaging() { return 0.875f; }
107
static int maxOverlapBetweenPages();
109
void disconnectFromScrollableArea() { m_scrollableArea = 0; }
110
ScrollableArea* scrollableArea() const { return m_scrollableArea; }
112
int pressedPos() const { return m_pressedPos; }
114
float pixelStep() const { return m_pixelStep; }
116
virtual void setHoveredPart(ScrollbarPart);
117
virtual void setPressedPart(ScrollbarPart);
119
void setSteps(int lineStep, int pageStep, int pixelsPerStep = 1);
120
void setProportion(int visibleSize, int totalSize);
121
void setPressedPos(int p) { m_pressedPos = p; }
123
virtual void paint(GraphicsContext*, const IntRect& damageRect);
125
virtual bool isOverlayScrollbar() const;
126
bool shouldParticipateInHitTesting();
128
bool isWindowActive() const;
130
#if ENABLE(GESTURE_EVENTS)
131
bool gestureEvent(const PlatformGestureEvent&);
134
// These methods are used for platform scrollbars to give :hover feedback. They will not get called
135
// when the mouse went down in a scrollbar, since it is assumed the scrollbar will start
136
// grabbing all events in that case anyway.
137
bool mouseMoved(const PlatformMouseEvent&);
141
// Used by some platform scrollbars to know when they've been released from capture.
142
bool mouseUp(const PlatformMouseEvent&);
144
bool mouseDown(const PlatformMouseEvent&);
146
ScrollbarTheme* theme() const { return m_theme; }
148
virtual void setParent(ScrollView*);
150
bool suppressInvalidation() const { return m_suppressInvalidation; }
151
void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; }
153
virtual IntRect convertToContainingView(const IntRect&) const;
154
virtual IntRect convertFromContainingView(const IntRect&) const;
156
virtual IntPoint convertToContainingView(const IntPoint&) const;
157
virtual IntPoint convertFromContainingView(const IntPoint&) const;
159
void moveThumb(int pos, bool draggingDocument = false);
161
virtual bool isAlphaLocked() const { return m_isAlphaLocked; }
162
virtual void setIsAlphaLocked(bool flag) { m_isAlphaLocked = flag; }
165
Scrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0);
168
virtual void updateThumbPosition();
169
virtual void updateThumbProportion();
171
void autoscrollTimerFired(Timer<Scrollbar>*);
172
void startTimerIfNeeded(double delay);
173
void stopTimerIfNeeded();
174
void autoscrollPressedPart(double delay);
175
ScrollDirection pressedPartScrollDirection();
176
ScrollGranularity pressedPartScrollGranularity();
178
ScrollableArea* m_scrollableArea;
179
ScrollbarOrientation m_orientation;
180
ScrollbarControlSize m_controlSize;
181
ScrollbarTheme* m_theme;
191
ScrollbarPart m_hoveredPart;
192
ScrollbarPart m_pressedPart;
195
bool m_draggingDocument;
196
int m_documentDragPos;
200
Timer<Scrollbar> m_scrollTimer;
201
bool m_overlapsResizer;
203
bool m_suppressInvalidation;
205
bool m_isAlphaLocked;
208
virtual bool isScrollbar() const { return true; }
209
virtual AXObjectCache* axObjectCache() const;
212
} // namespace WebCore
214
#endif // Scrollbar_h