]>
Commit | Line | Data |
---|---|---|
a90939db JF |
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 <wtf/RefCounted.h> | |
30 | #include "ScrollTypes.h" | |
31 | #include "Timer.h" | |
32 | #include "Widget.h" | |
33 | #include <wtf/MathExtras.h> | |
34 | #include <wtf/PassRefPtr.h> | |
35 | ||
36 | namespace WebCore { | |
37 | ||
38 | class GraphicsContext; | |
39 | class IntRect; | |
40 | class ScrollbarClient; | |
41 | class ScrollbarTheme; | |
42 | class PlatformMouseEvent; | |
43 | ||
44 | // These match the numbers we use over in WebKit (WebFrameView.m). | |
45 | const int cScrollbarPixelsPerLineStep = 40; | |
46 | const float cMouseWheelPixelsPerLineStep = 40.0f / 3.0f; | |
47 | const int cAmountToKeepWhenPaging = 40; | |
48 | ||
49 | class Scrollbar : public Widget, public RefCounted<Scrollbar> { | |
50 | protected: | |
51 | Scrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0); | |
52 | ||
53 | public: | |
54 | virtual ~Scrollbar(); | |
55 | ||
56 | // 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. | |
57 | static PassRefPtr<Scrollbar> createNativeScrollbar(ScrollbarClient* client, ScrollbarOrientation orientation, ScrollbarControlSize size); | |
58 | ||
59 | void setClient(ScrollbarClient* client) { m_client = client; } | |
60 | ScrollbarClient* client() const { return m_client; } | |
61 | ||
62 | ScrollbarOrientation orientation() const { return m_orientation; } | |
63 | ||
64 | int value() const { return lroundf(m_currentPos); } | |
65 | float currentPos() const { return m_currentPos; } | |
66 | int pressedPos() const { return m_pressedPos; } | |
67 | int visibleSize() const { return m_visibleSize; } | |
68 | int totalSize() const { return m_totalSize; } | |
69 | int maximum() const { return m_totalSize - m_visibleSize; } | |
70 | ScrollbarControlSize controlSize() const { return m_controlSize; } | |
71 | ||
72 | int lineStep() const { return m_lineStep; } | |
73 | int pageStep() const { return m_pageStep; } | |
74 | float pixelStep() const { return m_pixelStep; } | |
75 | ||
76 | ScrollbarPart pressedPart() const { return m_pressedPart; } | |
77 | ScrollbarPart hoveredPart() const { return m_hoveredPart; } | |
78 | virtual void setHoveredPart(ScrollbarPart); | |
79 | virtual void setPressedPart(ScrollbarPart); | |
80 | ||
81 | void setSteps(int lineStep, int pageStep, int pixelsPerStep = 1); | |
82 | bool setValue(int); | |
83 | void setProportion(int visibleSize, int totalSize); | |
84 | void setPressedPos(int p) { m_pressedPos = p; } | |
85 | ||
86 | bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1.0f); | |
87 | ||
88 | virtual void paint(GraphicsContext*, const IntRect& damageRect); | |
89 | ||
90 | bool enabled() const { return m_enabled; } | |
91 | virtual void setEnabled(bool e); | |
92 | ||
93 | bool isWindowActive() const; | |
94 | ||
95 | // These methods are used for platform scrollbars to give :hover feedback. They will not get called | |
96 | // when the mouse went down in a scrollbar, since it is assumed the scrollbar will start | |
97 | // grabbing all events in that case anyway. | |
98 | bool mouseExited(); | |
99 | ||
100 | // Used by some platform scrollbars to know when they've been released from capture. | |
101 | bool mouseUp(); | |
102 | ||
103 | bool mouseDown(const PlatformMouseEvent&); | |
104 | ||
105 | #if PLATFORM(QT) | |
106 | // For platforms that wish to handle context menu events. | |
107 | // FIXME: This is misplaced. Normal hit testing should be used to populate a correct | |
108 | // context menu. There's no reason why the scrollbar should have to do it. | |
109 | bool contextMenu(const PlatformMouseEvent& event); | |
110 | #endif | |
111 | ||
112 | // Takes an event and accounts for any transforms that might occur on the scrollbar. Returns | |
113 | // a new event that has had all of the transforms applied. | |
114 | PlatformMouseEvent transformEvent(const PlatformMouseEvent&); | |
115 | ||
116 | ScrollbarTheme* theme() const { return m_theme; } | |
117 | ||
118 | virtual void setParent(ScrollView*); | |
119 | virtual void setFrameRect(const IntRect&); | |
120 | ||
121 | virtual void invalidateRect(const IntRect&); | |
122 | ||
123 | bool suppressInvalidation() const { return m_suppressInvalidation; } | |
124 | void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; } | |
125 | ||
126 | virtual void styleChanged() { } | |
127 | ||
128 | protected: | |
129 | virtual void updateThumbPosition(); | |
130 | virtual void updateThumbProportion(); | |
131 | ||
132 | void autoscrollTimerFired(Timer<Scrollbar>*); | |
133 | void startTimerIfNeeded(double delay); | |
134 | void stopTimerIfNeeded(); | |
135 | void autoscrollPressedPart(double delay); | |
136 | ScrollDirection pressedPartScrollDirection(); | |
137 | ScrollGranularity pressedPartScrollGranularity(); | |
138 | ||
139 | void moveThumb(int pos); | |
140 | ||
141 | ScrollbarClient* m_client; | |
142 | ScrollbarOrientation m_orientation; | |
143 | ScrollbarControlSize m_controlSize; | |
144 | ScrollbarTheme* m_theme; | |
145 | ||
146 | int m_visibleSize; | |
147 | int m_totalSize; | |
148 | float m_currentPos; | |
149 | int m_lineStep; | |
150 | int m_pageStep; | |
151 | float m_pixelStep; | |
152 | ||
153 | ScrollbarPart m_hoveredPart; | |
154 | ScrollbarPart m_pressedPart; | |
155 | int m_pressedPos; | |
156 | ||
157 | bool m_enabled; | |
158 | ||
159 | Timer<Scrollbar> m_scrollTimer; | |
160 | bool m_overlapsResizer; | |
161 | ||
162 | bool m_suppressInvalidation; | |
163 | }; | |
164 | ||
165 | } | |
166 | ||
167 | #endif |