|
1 /* |
|
2 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. |
|
3 * |
|
4 * Redistribution and use in source and binary forms, with or without |
|
5 * modification, are permitted provided that the following conditions |
|
6 * are met: |
|
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. |
|
12 * |
|
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. |
|
24 */ |
|
25 |
|
26 #ifndef Scrollbar_h |
|
27 #define Scrollbar_h |
|
28 |
|
29 #include "ScrollTypes.h" |
|
30 #include "Timer.h" |
|
31 #include "Widget.h" |
|
32 #include <wtf/MathExtras.h> |
|
33 #include <wtf/PassRefPtr.h> |
|
34 |
|
35 namespace WebCore { |
|
36 |
|
37 class GraphicsContext; |
|
38 class IntRect; |
|
39 class ScrollbarClient; |
|
40 class ScrollbarTheme; |
|
41 class PlatformMouseEvent; |
|
42 |
|
43 class Scrollbar : public Widget { |
|
44 public: |
|
45 virtual ~Scrollbar(); |
|
46 |
|
47 // 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. |
|
48 static PassRefPtr<Scrollbar> createNativeScrollbar(ScrollbarClient* client, ScrollbarOrientation orientation, ScrollbarControlSize size); |
|
49 |
|
50 static int pixelsPerLineStep() { return 40; } |
|
51 static float minFractionToStepWhenPaging() { return 0.875f; } |
|
52 static int maxOverlapBetweenPages(); |
|
53 |
|
54 void setClient(ScrollbarClient* client) { m_client = client; } |
|
55 ScrollbarClient* client() const { return m_client; } |
|
56 |
|
57 virtual bool isCustomScrollbar() const { return false; } |
|
58 ScrollbarOrientation orientation() const { return m_orientation; } |
|
59 |
|
60 int value() const { return lroundf(m_currentPos); } |
|
61 float currentPos() const { return m_currentPos; } |
|
62 int pressedPos() const { return m_pressedPos; } |
|
63 int visibleSize() const { return m_visibleSize; } |
|
64 int totalSize() const { return m_totalSize; } |
|
65 int maximum() const { return m_totalSize - m_visibleSize; } |
|
66 ScrollbarControlSize controlSize() const { return m_controlSize; } |
|
67 |
|
68 int lineStep() const { return m_lineStep; } |
|
69 int pageStep() const { return m_pageStep; } |
|
70 float pixelStep() const { return m_pixelStep; } |
|
71 |
|
72 ScrollbarPart pressedPart() const { return m_pressedPart; } |
|
73 ScrollbarPart hoveredPart() const { return m_hoveredPart; } |
|
74 virtual void setHoveredPart(ScrollbarPart); |
|
75 virtual void setPressedPart(ScrollbarPart); |
|
76 |
|
77 void setSteps(int lineStep, int pageStep, int pixelsPerStep = 1); |
|
78 bool setValue(int); |
|
79 void setProportion(int visibleSize, int totalSize); |
|
80 void setPressedPos(int p) { m_pressedPos = p; } |
|
81 |
|
82 bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1.0f); |
|
83 |
|
84 virtual void paint(GraphicsContext*, const IntRect& damageRect); |
|
85 |
|
86 bool enabled() const { return m_enabled; } |
|
87 virtual void setEnabled(bool e); |
|
88 |
|
89 bool isWindowActive() const; |
|
90 |
|
91 // These methods are used for platform scrollbars to give :hover feedback. They will not get called |
|
92 // when the mouse went down in a scrollbar, since it is assumed the scrollbar will start |
|
93 // grabbing all events in that case anyway. |
|
94 bool mouseMoved(const PlatformMouseEvent&); |
|
95 bool mouseExited(); |
|
96 |
|
97 // Used by some platform scrollbars to know when they've been released from capture. |
|
98 bool mouseUp(); |
|
99 |
|
100 bool mouseDown(const PlatformMouseEvent&); |
|
101 |
|
102 #if PLATFORM(QT) |
|
103 // For platforms that wish to handle context menu events. |
|
104 // FIXME: This is misplaced. Normal hit testing should be used to populate a correct |
|
105 // context menu. There's no reason why the scrollbar should have to do it. |
|
106 bool contextMenu(const PlatformMouseEvent& event); |
|
107 #endif |
|
108 |
|
109 ScrollbarTheme* theme() const { return m_theme; } |
|
110 |
|
111 virtual void setParent(ScrollView*); |
|
112 virtual void setFrameRect(const IntRect&); |
|
113 |
|
114 virtual void invalidateRect(const IntRect&); |
|
115 |
|
116 bool suppressInvalidation() const { return m_suppressInvalidation; } |
|
117 void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; } |
|
118 |
|
119 virtual void styleChanged() { } |
|
120 |
|
121 virtual IntRect convertToContainingView(const IntRect&) const; |
|
122 virtual IntRect convertFromContainingView(const IntRect&) const; |
|
123 |
|
124 virtual IntPoint convertToContainingView(const IntPoint&) const; |
|
125 virtual IntPoint convertFromContainingView(const IntPoint&) const; |
|
126 |
|
127 private: |
|
128 virtual bool isScrollbar() const { return true; } |
|
129 |
|
130 protected: |
|
131 Scrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0); |
|
132 |
|
133 void updateThumb(); |
|
134 virtual void updateThumbPosition(); |
|
135 virtual void updateThumbProportion(); |
|
136 |
|
137 void autoscrollTimerFired(Timer<Scrollbar>*); |
|
138 void startTimerIfNeeded(double delay); |
|
139 void stopTimerIfNeeded(); |
|
140 void autoscrollPressedPart(double delay); |
|
141 ScrollDirection pressedPartScrollDirection(); |
|
142 ScrollGranularity pressedPartScrollGranularity(); |
|
143 |
|
144 void moveThumb(int pos); |
|
145 bool setCurrentPos(float pos); |
|
146 |
|
147 ScrollbarClient* m_client; |
|
148 ScrollbarOrientation m_orientation; |
|
149 ScrollbarControlSize m_controlSize; |
|
150 ScrollbarTheme* m_theme; |
|
151 |
|
152 int m_visibleSize; |
|
153 int m_totalSize; |
|
154 float m_currentPos; |
|
155 float m_dragOrigin; |
|
156 int m_lineStep; |
|
157 int m_pageStep; |
|
158 float m_pixelStep; |
|
159 |
|
160 ScrollbarPart m_hoveredPart; |
|
161 ScrollbarPart m_pressedPart; |
|
162 int m_pressedPos; |
|
163 |
|
164 bool m_enabled; |
|
165 |
|
166 Timer<Scrollbar> m_scrollTimer; |
|
167 bool m_overlapsResizer; |
|
168 |
|
169 bool m_suppressInvalidation; |
|
170 }; |
|
171 |
|
172 } |
|
173 |
|
174 #endif |