Update To 11.40.268.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/heap/Handle.h"
32 #include "platform/scroll/ScrollTypes.h"
33 #include "platform/scroll/ScrollbarThemeClient.h"
34 #include "wtf/MathExtras.h"
35 #include "wtf/PassRefPtr.h"
36
37 namespace blink {
38
39 class GraphicsContext;
40 class IntRect;
41 class PlatformGestureEvent;
42 class PlatformMouseEvent;
43 class ScrollAnimator;
44 class ScrollableArea;
45 class ScrollbarTheme;
46
47 class PLATFORM_EXPORT Scrollbar : public Widget, public ScrollbarThemeClient {
48
49 public:
50     static PassRefPtrWillBeRawPtr<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     virtual void setFrameRect(const IntRect& frameRect) override { Widget::setFrameRect(frameRect); }
66     virtual IntRect frameRect() const override { return Widget::frameRect(); }
67
68     virtual void invalidate() override { Widget::invalidate(); }
69     virtual void invalidateRect(const IntRect&) override;
70
71     virtual ScrollbarOverlayStyle scrollbarOverlayStyle() const override;
72     virtual void getTickmarks(Vector<IntRect>&) const override;
73     virtual bool isScrollableAreaActive() const override;
74
75     virtual IntPoint convertFromContainingWindow(const IntPoint& windowPoint) override { return Widget::convertFromContainingWindow(windowPoint); }
76
77     virtual bool isCustomScrollbar() const override { return false; }
78     virtual ScrollbarOrientation orientation() const override { return m_orientation; }
79     virtual bool isLeftSideVerticalScrollbar() const override;
80
81     virtual int value() const override { return lroundf(m_currentPos); }
82     virtual float currentPos() const override { return m_currentPos; }
83     virtual int visibleSize() const override { return m_visibleSize; }
84     virtual int totalSize() const override { return m_totalSize; }
85     virtual int maximum() const override { return m_totalSize - m_visibleSize; }
86     virtual ScrollbarControlSize controlSize() const override { return m_controlSize; }
87
88     virtual ScrollbarPart pressedPart() const override { return m_pressedPart; }
89     virtual ScrollbarPart hoveredPart() const override { return m_hoveredPart; }
90
91     virtual void styleChanged() override { }
92
93     virtual bool enabled() const override { return m_enabled; }
94     virtual void setEnabled(bool) override;
95
96     // Called by the ScrollableArea when the scroll offset changes.
97     void offsetDidChange();
98
99     void disconnectFromScrollableArea();
100     ScrollableArea* scrollableArea() const { return m_scrollableArea; }
101
102     int pressedPos() const { return m_pressedPos; }
103
104     virtual void setHoveredPart(ScrollbarPart);
105     virtual void setPressedPart(ScrollbarPart);
106
107     void setProportion(int visibleSize, int totalSize);
108     void setPressedPos(int p) { m_pressedPos = p; }
109
110     virtual void paint(GraphicsContext*, const IntRect& damageRect) override;
111
112     virtual bool isOverlayScrollbar() const override;
113     bool shouldParticipateInHitTesting();
114
115     bool isWindowActive() const;
116
117     bool gestureEvent(const PlatformGestureEvent&);
118
119     // These methods are used for platform scrollbars to give :hover feedback.  They will not get called
120     // when the mouse went down in a scrollbar, since it is assumed the scrollbar will start
121     // grabbing all events in that case anyway.
122     void mouseMoved(const PlatformMouseEvent&);
123     void mouseEntered();
124     void mouseExited();
125
126     // Used by some platform scrollbars to know when they've been released from capture.
127     void mouseUp(const PlatformMouseEvent&);
128     void mouseDown(const PlatformMouseEvent&);
129
130     ScrollbarTheme* theme() const { return m_theme; }
131
132     bool suppressInvalidation() const { return m_suppressInvalidation; }
133     void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; }
134
135     virtual IntRect convertToContainingView(const IntRect&) const override;
136     virtual IntRect convertFromContainingView(const IntRect&) const override;
137
138     virtual IntPoint convertToContainingView(const IntPoint&) const override;
139     virtual IntPoint convertFromContainingView(const IntPoint&) const override;
140
141     void moveThumb(int pos, bool draggingDocument = false);
142
143     virtual bool isAlphaLocked() const override { return m_isAlphaLocked; }
144     virtual void setIsAlphaLocked(bool flag) override { m_isAlphaLocked = flag; }
145
146     bool overlapsResizer() const { return m_overlapsResizer; }
147     void setOverlapsResizer(bool overlapsResizer) { m_overlapsResizer = overlapsResizer; }
148
149 protected:
150     Scrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0);
151
152     void updateThumb();
153     virtual void updateThumbPosition();
154     virtual void updateThumbProportion();
155
156     void autoscrollTimerFired(Timer<Scrollbar>*);
157     void startTimerIfNeeded(double delay);
158     void stopTimerIfNeeded();
159     void autoscrollPressedPart(double delay);
160     ScrollDirection pressedPartScrollDirection();
161     ScrollGranularity pressedPartScrollGranularity();
162
163     ScrollableArea* m_scrollableArea;
164     ScrollbarOrientation m_orientation;
165     ScrollbarControlSize m_controlSize;
166     ScrollbarTheme* m_theme;
167
168 #if ENABLE(OILPAN)
169     // To simplify Oilpan finalization, keep a copy of the ScrollableArea's
170     // scroll animator. Scrollbar is responsible for notifying the animator
171     // when it is destructed.
172     RefPtr<ScrollAnimator> m_animator;
173 #endif
174
175     int m_visibleSize;
176     int m_totalSize;
177     float m_currentPos;
178     float m_dragOrigin;
179
180     ScrollbarPart m_hoveredPart;
181     ScrollbarPart m_pressedPart;
182     int m_pressedPos;
183     float m_scrollPos;
184     bool m_draggingDocument;
185     int m_documentDragPos;
186
187     bool m_enabled;
188
189     Timer<Scrollbar> m_scrollTimer;
190     bool m_overlapsResizer;
191
192     bool m_suppressInvalidation;
193
194     bool m_isAlphaLocked;
195
196 private:
197     virtual bool isScrollbar() const override { return true; }
198
199     float scrollableAreaCurrentPos() const;
200 };
201
202 DEFINE_TYPE_CASTS(Scrollbar, Widget, widget, widget->isScrollbar(), widget.isScrollbar());
203
204 } // namespace blink
205
206 #endif // Scrollbar_h