• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "platform/Timer.h"
30 #include "platform/Widget.h"
31 #include "platform/scroll/ScrollTypes.h"
32 #include "platform/scroll/ScrollbarThemeClient.h"
33 #include "wtf/MathExtras.h"
34 #include "wtf/PassRefPtr.h"
35 
36 namespace WebCore {
37 
38 class GraphicsContext;
39 class IntRect;
40 class PlatformGestureEvent;
41 class PlatformMouseEvent;
42 class ScrollableArea;
43 class ScrollbarTheme;
44 class ScrollView;
45 
46 class PLATFORM_EXPORT Scrollbar : public Widget,
47                   public ScrollbarThemeClient {
48 
49 public:
50     static PassRefPtr<Scrollbar> create(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize);
51 
52     virtual ~Scrollbar();
53 
54     // ScrollbarThemeClient implementation.
x()55     virtual int x() const { return Widget::x(); }
y()56     virtual int y() const { return Widget::y(); }
width()57     virtual int width() const { return Widget::width(); }
height()58     virtual int height() const { return Widget::height(); }
size()59     virtual IntSize size() const { return Widget::size(); }
location()60     virtual IntPoint location() const { return Widget::location(); }
61 
parent()62     virtual Widget* parent() const { return Widget::parent(); }
root()63     virtual Widget* root() const { return Widget::root(); }
64 
65     void removeFromParent();
66     ScrollView* parentScrollView() const;
67     ScrollView* rootScrollView() const;
68 
69     virtual void setFrameRect(const IntRect&);
frameRect()70     virtual IntRect frameRect() const { return Widget::frameRect(); }
71 
invalidate()72     virtual void invalidate() { Widget::invalidate(); }
73     virtual void invalidateRect(const IntRect&);
74 
75     virtual ScrollbarOverlayStyle scrollbarOverlayStyle() const;
76     virtual void getTickmarks(Vector<IntRect>&) const;
77     virtual bool isScrollableAreaActive() const;
78     virtual bool isScrollViewScrollbar() const;
79 
convertFromContainingWindow(const IntPoint & windowPoint)80     virtual IntPoint convertFromContainingWindow(const IntPoint& windowPoint) { return Widget::convertFromContainingWindow(windowPoint); }
81 
isCustomScrollbar()82     virtual bool isCustomScrollbar() const { return false; }
orientation()83     virtual ScrollbarOrientation orientation() const { return m_orientation; }
84     virtual bool isLeftSideVerticalScrollbar() const;
85 
value()86     virtual int value() const { return lroundf(m_currentPos); }
currentPos()87     virtual float currentPos() const { return m_currentPos; }
visibleSize()88     virtual int visibleSize() const { return m_visibleSize; }
totalSize()89     virtual int totalSize() const { return m_totalSize; }
maximum()90     virtual int maximum() const { return m_totalSize - m_visibleSize; }
controlSize()91     virtual ScrollbarControlSize controlSize() const { return m_controlSize; }
92 
pressedPart()93     virtual ScrollbarPart pressedPart() const { return m_pressedPart; }
hoveredPart()94     virtual ScrollbarPart hoveredPart() const { return m_hoveredPart; }
95 
styleChanged()96     virtual void styleChanged() { }
97 
enabled()98     virtual bool enabled() const { return m_enabled; }
99     virtual void setEnabled(bool);
100 
101     // Called by the ScrollableArea when the scroll offset changes.
102     void offsetDidChange();
103 
disconnectFromScrollableArea()104     void disconnectFromScrollableArea() { m_scrollableArea = 0; }
scrollableArea()105     ScrollableArea* scrollableArea() const { return m_scrollableArea; }
106 
pressedPos()107     int pressedPos() const { return m_pressedPos; }
108 
109     virtual void setHoveredPart(ScrollbarPart);
110     virtual void setPressedPart(ScrollbarPart);
111 
112     void setProportion(int visibleSize, int totalSize);
setPressedPos(int p)113     void setPressedPos(int p) { m_pressedPos = p; }
114 
115     virtual void paint(GraphicsContext*, const IntRect& damageRect);
116 
117     virtual bool isOverlayScrollbar() const;
118     bool shouldParticipateInHitTesting();
119 
120     bool isWindowActive() const;
121 
122     bool gestureEvent(const PlatformGestureEvent&);
123 
124     // These methods are used for platform scrollbars to give :hover feedback.  They will not get called
125     // when the mouse went down in a scrollbar, since it is assumed the scrollbar will start
126     // grabbing all events in that case anyway.
127     void mouseMoved(const PlatformMouseEvent&);
128     void mouseEntered();
129     void mouseExited();
130 
131     // Used by some platform scrollbars to know when they've been released from capture.
132     void mouseUp(const PlatformMouseEvent&);
133     void mouseDown(const PlatformMouseEvent&);
134 
theme()135     ScrollbarTheme* theme() const { return m_theme; }
136 
137     virtual void setParent(Widget*) OVERRIDE;
138 
suppressInvalidation()139     bool suppressInvalidation() const { return m_suppressInvalidation; }
setSuppressInvalidation(bool s)140     void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; }
141 
142     virtual IntRect convertToContainingView(const IntRect&) const;
143     virtual IntRect convertFromContainingView(const IntRect&) const;
144 
145     virtual IntPoint convertToContainingView(const IntPoint&) const;
146     virtual IntPoint convertFromContainingView(const IntPoint&) const;
147 
148     void moveThumb(int pos, bool draggingDocument = false);
149 
isAlphaLocked()150     virtual bool isAlphaLocked() const { return m_isAlphaLocked; }
setIsAlphaLocked(bool flag)151     virtual void setIsAlphaLocked(bool flag) { m_isAlphaLocked = flag; }
152 
153 protected:
154     Scrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0);
155 
156     void updateThumb();
157     virtual void updateThumbPosition();
158     virtual void updateThumbProportion();
159 
160     void autoscrollTimerFired(Timer<Scrollbar>*);
161     void startTimerIfNeeded(double delay);
162     void stopTimerIfNeeded();
163     void autoscrollPressedPart(double delay);
164     ScrollDirection pressedPartScrollDirection();
165     ScrollGranularity pressedPartScrollGranularity();
166 
167     ScrollableArea* m_scrollableArea;
168     ScrollbarOrientation m_orientation;
169     ScrollbarControlSize m_controlSize;
170     ScrollbarTheme* m_theme;
171 
172     int m_visibleSize;
173     int m_totalSize;
174     float m_currentPos;
175     float m_dragOrigin;
176 
177     ScrollbarPart m_hoveredPart;
178     ScrollbarPart m_pressedPart;
179     int m_pressedPos;
180     float m_scrollPos;
181     bool m_draggingDocument;
182     int m_documentDragPos;
183 
184     bool m_enabled;
185 
186     Timer<Scrollbar> m_scrollTimer;
187     bool m_overlapsResizer;
188 
189     bool m_suppressInvalidation;
190 
191     bool m_isAlphaLocked;
192 
193 private:
isScrollbar()194     virtual bool isScrollbar() const { return true; }
195 
196     float scrollableAreaCurrentPos() const;
197 };
198 
toScrollbar(Widget * widget)199 inline Scrollbar* toScrollbar(Widget* widget)
200 {
201     ASSERT_WITH_SECURITY_IMPLICATION(!widget || widget->isScrollbar());
202     return static_cast<Scrollbar*>(widget);
203 }
204 
toScrollbar(const Widget * widget)205 inline const Scrollbar* toScrollbar(const Widget* widget)
206 {
207     ASSERT_WITH_SECURITY_IMPLICATION(!widget || widget->isScrollbar());
208     return static_cast<const Scrollbar*>(widget);
209 }
210 
211 // This will catch anyone doing an unnecessary cast.
212 void toScrollbar(const Scrollbar*);
213 
214 } // namespace WebCore
215 
216 #endif // Scrollbar_h
217