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/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"
39 class GraphicsContext;
41 class PlatformGestureEvent;
42 class PlatformMouseEvent;
47 class PLATFORM_EXPORT Scrollbar : public Widget, public ScrollbarThemeClient {
50 static PassRefPtrWillBeRawPtr<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 virtual void setFrameRect(const IntRect& frameRect) override { Widget::setFrameRect(frameRect); }
66 virtual IntRect frameRect() const override { return Widget::frameRect(); }
68 virtual void invalidate() override { Widget::invalidate(); }
69 virtual void invalidateRect(const IntRect&) override;
71 virtual ScrollbarOverlayStyle scrollbarOverlayStyle() const override;
72 virtual void getTickmarks(Vector<IntRect>&) const override;
73 virtual bool isScrollableAreaActive() const override;
75 virtual IntPoint convertFromContainingWindow(const IntPoint& windowPoint) override { return Widget::convertFromContainingWindow(windowPoint); }
77 virtual bool isCustomScrollbar() const override { return false; }
78 virtual ScrollbarOrientation orientation() const override { return m_orientation; }
79 virtual bool isLeftSideVerticalScrollbar() const override;
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; }
88 virtual ScrollbarPart pressedPart() const override { return m_pressedPart; }
89 virtual ScrollbarPart hoveredPart() const override { return m_hoveredPart; }
91 virtual void styleChanged() override { }
93 virtual bool enabled() const override { return m_enabled; }
94 virtual void setEnabled(bool) override;
96 // Called by the ScrollableArea when the scroll offset changes.
97 void offsetDidChange();
99 void disconnectFromScrollableArea();
100 ScrollableArea* scrollableArea() const { return m_scrollableArea; }
102 int pressedPos() const { return m_pressedPos; }
104 virtual void setHoveredPart(ScrollbarPart);
105 virtual void setPressedPart(ScrollbarPart);
107 void setProportion(int visibleSize, int totalSize);
108 void setPressedPos(int p) { m_pressedPos = p; }
110 virtual void paint(GraphicsContext*, const IntRect& damageRect) override;
112 virtual bool isOverlayScrollbar() const override;
113 bool shouldParticipateInHitTesting();
115 bool isWindowActive() const;
117 bool gestureEvent(const PlatformGestureEvent&);
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&);
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&);
130 ScrollbarTheme* theme() const { return m_theme; }
132 bool suppressInvalidation() const { return m_suppressInvalidation; }
133 void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; }
135 virtual IntRect convertToContainingView(const IntRect&) const override;
136 virtual IntRect convertFromContainingView(const IntRect&) const override;
138 virtual IntPoint convertToContainingView(const IntPoint&) const override;
139 virtual IntPoint convertFromContainingView(const IntPoint&) const override;
141 void moveThumb(int pos, bool draggingDocument = false);
143 virtual bool isAlphaLocked() const override { return m_isAlphaLocked; }
144 virtual void setIsAlphaLocked(bool flag) override { m_isAlphaLocked = flag; }
146 bool overlapsResizer() const { return m_overlapsResizer; }
147 void setOverlapsResizer(bool overlapsResizer) { m_overlapsResizer = overlapsResizer; }
150 Scrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0);
153 virtual void updateThumbPosition();
154 virtual void updateThumbProportion();
156 void autoscrollTimerFired(Timer<Scrollbar>*);
157 void startTimerIfNeeded(double delay);
158 void stopTimerIfNeeded();
159 void autoscrollPressedPart(double delay);
160 ScrollDirection pressedPartScrollDirection();
161 ScrollGranularity pressedPartScrollGranularity();
163 ScrollableArea* m_scrollableArea;
164 ScrollbarOrientation m_orientation;
165 ScrollbarControlSize m_controlSize;
166 ScrollbarTheme* m_theme;
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;
180 ScrollbarPart m_hoveredPart;
181 ScrollbarPart m_pressedPart;
184 bool m_draggingDocument;
185 int m_documentDragPos;
189 Timer<Scrollbar> m_scrollTimer;
190 bool m_overlapsResizer;
192 bool m_suppressInvalidation;
194 bool m_isAlphaLocked;
197 virtual bool isScrollbar() const override { return true; }
199 float scrollableAreaCurrentPos() const;
202 DEFINE_TYPE_CASTS(Scrollbar, Widget, widget, widget->isScrollbar(), widget.isScrollbar());
206 #endif // Scrollbar_h