Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / platform / scroll / Scrollbar.h
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 blink {
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.
55     virtual int x() const OVERRIDE { return Widget::x(); }
56     virtual int y() const OVERRIDE { return Widget::y(); }
57     virtual int width() const OVERRIDE { return Widget::width(); }
58     virtual int height() const OVERRIDE { return Widget::height(); }
59     virtual IntSize size() const OVERRIDE { return Widget::size(); }
60     virtual IntPoint location() const OVERRIDE { return Widget::location(); }
61
62     virtual Widget* parent() const OVERRIDE { return Widget::parent(); }
63     virtual Widget* root() const OVERRIDE { return Widget::root(); }
64
65     void removeFromParent();
66     ScrollView* parentScrollView() const;
67
68     virtual void setFrameRect(const IntRect&) OVERRIDE;
69     virtual IntRect frameRect() const OVERRIDE { return Widget::frameRect(); }
70
71     virtual void invalidate() OVERRIDE { Widget::invalidate(); }
72     virtual void invalidateRect(const IntRect&) OVERRIDE;
73
74     virtual ScrollbarOverlayStyle scrollbarOverlayStyle() const OVERRIDE;
75     virtual void getTickmarks(Vector<IntRect>&) const OVERRIDE;
76     virtual bool isScrollableAreaActive() const OVERRIDE;
77     virtual bool isScrollViewScrollbar() const OVERRIDE;
78
79     virtual IntPoint convertFromContainingWindow(const IntPoint& windowPoint) OVERRIDE { return Widget::convertFromContainingWindow(windowPoint); }
80
81     virtual bool isCustomScrollbar() const OVERRIDE { return false; }
82     virtual ScrollbarOrientation orientation() const OVERRIDE { return m_orientation; }
83     virtual bool isLeftSideVerticalScrollbar() const OVERRIDE;
84
85     virtual int value() const OVERRIDE { return lroundf(m_currentPos); }
86     virtual float currentPos() const OVERRIDE { return m_currentPos; }
87     virtual int visibleSize() const OVERRIDE { return m_visibleSize; }
88     virtual int totalSize() const OVERRIDE { return m_totalSize; }
89     virtual int maximum() const OVERRIDE { return m_totalSize - m_visibleSize; }
90     virtual ScrollbarControlSize controlSize() const OVERRIDE { return m_controlSize; }
91
92     virtual ScrollbarPart pressedPart() const OVERRIDE { return m_pressedPart; }
93     virtual ScrollbarPart hoveredPart() const OVERRIDE { return m_hoveredPart; }
94
95     virtual void styleChanged() OVERRIDE { }
96
97     virtual bool enabled() const OVERRIDE { return m_enabled; }
98     virtual void setEnabled(bool) OVERRIDE;
99
100     // Called by the ScrollableArea when the scroll offset changes.
101     void offsetDidChange();
102
103     void disconnectFromScrollableArea() { m_scrollableArea = 0; }
104     ScrollableArea* scrollableArea() const { return m_scrollableArea; }
105
106     int pressedPos() const { return m_pressedPos; }
107
108     virtual void setHoveredPart(ScrollbarPart);
109     virtual void setPressedPart(ScrollbarPart);
110
111     void setProportion(int visibleSize, int totalSize);
112     void setPressedPos(int p) { m_pressedPos = p; }
113
114     virtual void paint(GraphicsContext*, const IntRect& damageRect) OVERRIDE;
115
116     virtual bool isOverlayScrollbar() const OVERRIDE;
117     bool shouldParticipateInHitTesting();
118
119     bool isWindowActive() const;
120
121     bool gestureEvent(const PlatformGestureEvent&);
122
123     // These methods are used for platform scrollbars to give :hover feedback.  They will not get called
124     // when the mouse went down in a scrollbar, since it is assumed the scrollbar will start
125     // grabbing all events in that case anyway.
126     void mouseMoved(const PlatformMouseEvent&);
127     void mouseEntered();
128     void mouseExited();
129
130     // Used by some platform scrollbars to know when they've been released from capture.
131     void mouseUp(const PlatformMouseEvent&);
132     void mouseDown(const PlatformMouseEvent&);
133
134     ScrollbarTheme* theme() const { return m_theme; }
135
136     virtual void setParent(Widget*) OVERRIDE;
137
138     bool suppressInvalidation() const { return m_suppressInvalidation; }
139     void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; }
140
141     virtual IntRect convertToContainingView(const IntRect&) const OVERRIDE;
142     virtual IntRect convertFromContainingView(const IntRect&) const OVERRIDE;
143
144     virtual IntPoint convertToContainingView(const IntPoint&) const OVERRIDE;
145     virtual IntPoint convertFromContainingView(const IntPoint&) const OVERRIDE;
146
147     void moveThumb(int pos, bool draggingDocument = false);
148
149     virtual bool isAlphaLocked() const OVERRIDE { return m_isAlphaLocked; }
150     virtual void setIsAlphaLocked(bool flag) OVERRIDE { m_isAlphaLocked = flag; }
151
152 protected:
153     Scrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0);
154
155     void updateThumb();
156     virtual void updateThumbPosition();
157     virtual void updateThumbProportion();
158
159     void autoscrollTimerFired(Timer<Scrollbar>*);
160     void startTimerIfNeeded(double delay);
161     void stopTimerIfNeeded();
162     void autoscrollPressedPart(double delay);
163     ScrollDirection pressedPartScrollDirection();
164     ScrollGranularity pressedPartScrollGranularity();
165
166     ScrollableArea* m_scrollableArea;
167     ScrollbarOrientation m_orientation;
168     ScrollbarControlSize m_controlSize;
169     ScrollbarTheme* m_theme;
170
171     int m_visibleSize;
172     int m_totalSize;
173     float m_currentPos;
174     float m_dragOrigin;
175
176     ScrollbarPart m_hoveredPart;
177     ScrollbarPart m_pressedPart;
178     int m_pressedPos;
179     float m_scrollPos;
180     bool m_draggingDocument;
181     int m_documentDragPos;
182
183     bool m_enabled;
184
185     Timer<Scrollbar> m_scrollTimer;
186     bool m_overlapsResizer;
187
188     bool m_suppressInvalidation;
189
190     bool m_isAlphaLocked;
191
192 private:
193     virtual bool isScrollbar() const OVERRIDE { return true; }
194
195     float scrollableAreaCurrentPos() const;
196 };
197
198 DEFINE_TYPE_CASTS(Scrollbar, Widget, widget, widget->isScrollbar(), widget.isScrollbar());
199
200 } // namespace blink
201
202 #endif // Scrollbar_h