2 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
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"
38 class GraphicsContext;
40 class PlatformGestureEvent;
41 class PlatformMouseEvent;
46 class PLATFORM_EXPORT Scrollbar : public Widget,
47 public ScrollbarThemeClient {
50 static PassRefPtr<Scrollbar> create(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize);
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(); }
62 virtual Widget* parent() const OVERRIDE { return Widget::parent(); }
63 virtual Widget* root() const OVERRIDE { return Widget::root(); }
65 void removeFromParent();
66 ScrollView* parentScrollView() const;
68 virtual void setFrameRect(const IntRect&) OVERRIDE;
69 virtual IntRect frameRect() const OVERRIDE { return Widget::frameRect(); }
71 virtual void invalidate() OVERRIDE { Widget::invalidate(); }
72 virtual void invalidateRect(const IntRect&) OVERRIDE;
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;
79 virtual IntPoint convertFromContainingWindow(const IntPoint& windowPoint) OVERRIDE { return Widget::convertFromContainingWindow(windowPoint); }
81 virtual bool isCustomScrollbar() const OVERRIDE { return false; }
82 virtual ScrollbarOrientation orientation() const OVERRIDE { return m_orientation; }
83 virtual bool isLeftSideVerticalScrollbar() const OVERRIDE;
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; }
92 virtual ScrollbarPart pressedPart() const OVERRIDE { return m_pressedPart; }
93 virtual ScrollbarPart hoveredPart() const OVERRIDE { return m_hoveredPart; }
95 virtual void styleChanged() OVERRIDE { }
97 virtual bool enabled() const OVERRIDE { return m_enabled; }
98 virtual void setEnabled(bool) OVERRIDE;
100 // Called by the ScrollableArea when the scroll offset changes.
101 void offsetDidChange();
103 void disconnectFromScrollableArea() { m_scrollableArea = 0; }
104 ScrollableArea* scrollableArea() const { return m_scrollableArea; }
106 int pressedPos() const { return m_pressedPos; }
108 virtual void setHoveredPart(ScrollbarPart);
109 virtual void setPressedPart(ScrollbarPart);
111 void setProportion(int visibleSize, int totalSize);
112 void setPressedPos(int p) { m_pressedPos = p; }
114 virtual void paint(GraphicsContext*, const IntRect& damageRect) OVERRIDE;
116 virtual bool isOverlayScrollbar() const OVERRIDE;
117 bool shouldParticipateInHitTesting();
119 bool isWindowActive() const;
121 bool gestureEvent(const PlatformGestureEvent&);
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&);
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&);
134 ScrollbarTheme* theme() const { return m_theme; }
136 virtual void setParent(Widget*) OVERRIDE;
138 bool suppressInvalidation() const { return m_suppressInvalidation; }
139 void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; }
141 virtual IntRect convertToContainingView(const IntRect&) const OVERRIDE;
142 virtual IntRect convertFromContainingView(const IntRect&) const OVERRIDE;
144 virtual IntPoint convertToContainingView(const IntPoint&) const OVERRIDE;
145 virtual IntPoint convertFromContainingView(const IntPoint&) const OVERRIDE;
147 void moveThumb(int pos, bool draggingDocument = false);
149 virtual bool isAlphaLocked() const OVERRIDE { return m_isAlphaLocked; }
150 virtual void setIsAlphaLocked(bool flag) OVERRIDE { m_isAlphaLocked = flag; }
153 Scrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0);
156 virtual void updateThumbPosition();
157 virtual void updateThumbProportion();
159 void autoscrollTimerFired(Timer<Scrollbar>*);
160 void startTimerIfNeeded(double delay);
161 void stopTimerIfNeeded();
162 void autoscrollPressedPart(double delay);
163 ScrollDirection pressedPartScrollDirection();
164 ScrollGranularity pressedPartScrollGranularity();
166 ScrollableArea* m_scrollableArea;
167 ScrollbarOrientation m_orientation;
168 ScrollbarControlSize m_controlSize;
169 ScrollbarTheme* m_theme;
176 ScrollbarPart m_hoveredPart;
177 ScrollbarPart m_pressedPart;
180 bool m_draggingDocument;
181 int m_documentDragPos;
185 Timer<Scrollbar> m_scrollTimer;
186 bool m_overlapsResizer;
188 bool m_suppressInvalidation;
190 bool m_isAlphaLocked;
193 virtual bool isScrollbar() const OVERRIDE { return true; }
195 float scrollableAreaCurrentPos() const;
198 DEFINE_TYPE_CASTS(Scrollbar, Widget, widget, widget->isScrollbar(), widget.isScrollbar());
202 #endif // Scrollbar_h