hyatt | 642b72a | 2003-04-25 21:14:28 +0000 | [diff] [blame] | 1 | /* |
darin | e9700da | 2006-03-06 23:09:48 +0000 | [diff] [blame] | 2 | * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. |
hyatt | 642b72a | 2003-04-25 21:14:28 +0000 | [diff] [blame] | 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 | |
alp@webkit.org | 226f72a | 2008-09-17 04:22:02 +0000 | [diff] [blame] | 26 | #ifndef Scrollbar_h |
| 27 | #define Scrollbar_h |
hyatt | 642b72a | 2003-04-25 21:14:28 +0000 | [diff] [blame] | 28 | |
jamesr@google.com | d5496ef | 2012-03-01 23:36:21 +0000 | [diff] [blame] | 29 | #include "ScrollbarThemeClient.h" |
darin | 60e537f5 | 2006-11-15 01:29:46 +0000 | [diff] [blame] | 30 | #include "ScrollTypes.h" |
hyatt@apple.com | 30ed544 | 2008-09-13 18:39:58 +0000 | [diff] [blame] | 31 | #include "Timer.h" |
hyatt@apple.com | 818ffe9 | 2008-09-12 18:37:23 +0000 | [diff] [blame] | 32 | #include "Widget.h" |
andersca | c3c0159 | 2007-03-27 16:40:11 +0000 | [diff] [blame] | 33 | #include <wtf/MathExtras.h> |
hyatt@apple.com | 4e3b860 | 2008-09-17 03:17:11 +0000 | [diff] [blame] | 34 | #include <wtf/PassRefPtr.h> |
hyatt | d6df585 | 2006-09-28 06:46:35 +0000 | [diff] [blame] | 35 | |
darin | f4b05b2 | 2006-07-10 05:20:17 +0000 | [diff] [blame] | 36 | namespace WebCore { |
| 37 | |
hyatt | 8285c6b | 2006-08-01 01:50:45 +0000 | [diff] [blame] | 38 | class GraphicsContext; |
| 39 | class IntRect; |
hyatt | d6df585 | 2006-09-28 06:46:35 +0000 | [diff] [blame] | 40 | class PlatformMouseEvent; |
weinig@apple.com | d7d77c3 | 2011-01-21 20:15:04 +0000 | [diff] [blame] | 41 | class ScrollableArea; |
| 42 | class ScrollbarTheme; |
hyatt | 8285c6b | 2006-08-01 01:50:45 +0000 | [diff] [blame] | 43 | |
commit-queue@webkit.org | 42fa320 | 2012-11-16 18:17:30 +0000 | [diff] [blame] | 44 | #if ENABLE(GESTURE_EVENTS) |
| 45 | class PlatformGestureEvent; |
| 46 | #endif |
| 47 | |
jamesr@google.com | d5496ef | 2012-03-01 23:36:21 +0000 | [diff] [blame] | 48 | class Scrollbar : public Widget, |
| 49 | public ScrollbarThemeClient { |
| 50 | |
hyatt | 8285c6b | 2006-08-01 01:50:45 +0000 | [diff] [blame] | 51 | public: |
weinig@apple.com | d7d77c3 | 2011-01-21 20:15:04 +0000 | [diff] [blame] | 52 | // Must be implemented by platforms that can't simply use the Scrollbar base class. Right now the only platform that is not using the base class is GTK. |
| 53 | static PassRefPtr<Scrollbar> createNativeScrollbar(ScrollableArea*, ScrollbarOrientation orientation, ScrollbarControlSize size); |
commit-queue@webkit.org | 1bf3b4b | 2010-09-08 19:31:47 +0000 | [diff] [blame] | 54 | |
hyatt@apple.com | d62f5bf | 2008-09-14 00:32:19 +0000 | [diff] [blame] | 55 | virtual ~Scrollbar(); |
hyatt | 8285c6b | 2006-08-01 01:50:45 +0000 | [diff] [blame] | 56 | |
jamesr@google.com | d5496ef | 2012-03-01 23:36:21 +0000 | [diff] [blame] | 57 | // ScrollbarThemeClient implementation. |
| 58 | virtual int x() const { return Widget::x(); } |
| 59 | virtual int y() const { return Widget::y(); } |
| 60 | virtual int width() const { return Widget::width(); } |
| 61 | virtual int height() const { return Widget::height(); } |
| 62 | virtual IntSize size() const { return Widget::size(); } |
| 63 | virtual IntPoint location() const { return Widget::location(); } |
| 64 | |
| 65 | virtual ScrollView* parent() const { return Widget::parent(); } |
| 66 | virtual ScrollView* root() const { return Widget::root(); } |
| 67 | |
| 68 | virtual void setFrameRect(const IntRect&); |
| 69 | virtual IntRect frameRect() const { return Widget::frameRect(); } |
| 70 | |
| 71 | virtual void invalidate() { Widget::invalidate(); } |
| 72 | virtual void invalidateRect(const IntRect&); |
| 73 | |
| 74 | virtual ScrollbarOverlayStyle scrollbarOverlayStyle() const; |
| 75 | virtual void getTickmarks(Vector<IntRect>&) const; |
| 76 | virtual bool isScrollableAreaActive() const; |
| 77 | virtual bool isScrollViewScrollbar() const; |
| 78 | |
| 79 | virtual IntPoint convertFromContainingWindow(const IntPoint& windowPoint) { return Widget::convertFromContainingWindow(windowPoint); } |
| 80 | |
| 81 | virtual bool isCustomScrollbar() const { return false; } |
| 82 | virtual ScrollbarOrientation orientation() const { return m_orientation; } |
| 83 | |
| 84 | virtual int value() const { return lroundf(m_currentPos); } |
| 85 | virtual float currentPos() const { return m_currentPos; } |
| 86 | virtual int visibleSize() const { return m_visibleSize; } |
| 87 | virtual int totalSize() const { return m_totalSize; } |
| 88 | virtual int maximum() const { return m_totalSize - m_visibleSize; } |
| 89 | virtual ScrollbarControlSize controlSize() const { return m_controlSize; } |
| 90 | |
| 91 | virtual int lineStep() const { return m_lineStep; } |
| 92 | virtual int pageStep() const { return m_pageStep; } |
| 93 | |
| 94 | virtual ScrollbarPart pressedPart() const { return m_pressedPart; } |
| 95 | virtual ScrollbarPart hoveredPart() const { return m_hoveredPart; } |
| 96 | |
| 97 | virtual void styleChanged() { } |
| 98 | |
| 99 | virtual bool enabled() const { return m_enabled; } |
| 100 | virtual void setEnabled(bool); |
| 101 | |
weinig@apple.com | d7d77c3 | 2011-01-21 20:15:04 +0000 | [diff] [blame] | 102 | // Called by the ScrollableArea when the scroll offset changes. |
weinig@apple.com | 2a13aa8 | 2011-01-20 23:14:47 +0000 | [diff] [blame] | 103 | void offsetDidChange(); |
| 104 | |
mitz@apple.com | ed85003 | 2010-02-04 17:35:58 +0000 | [diff] [blame] | 105 | static int pixelsPerLineStep() { return 40; } |
| 106 | static float minFractionToStepWhenPaging() { return 0.875f; } |
| 107 | static int maxOverlapBetweenPages(); |
| 108 | |
weinig@apple.com | d7d77c3 | 2011-01-21 20:15:04 +0000 | [diff] [blame] | 109 | void disconnectFromScrollableArea() { m_scrollableArea = 0; } |
| 110 | ScrollableArea* scrollableArea() const { return m_scrollableArea; } |
mitz@apple.com | e55c4d3 | 2007-11-08 01:54:14 +0000 | [diff] [blame] | 111 | |
hyatt@apple.com | 1cd4bcc | 2008-09-16 06:53:34 +0000 | [diff] [blame] | 112 | int pressedPos() const { return m_pressedPos; } |
hyatt | 642b72a | 2003-04-25 21:14:28 +0000 | [diff] [blame] | 113 | |
hyatt@apple.com | 3ab4830 | 2008-09-14 23:55:16 +0000 | [diff] [blame] | 114 | float pixelStep() const { return m_pixelStep; } |
weinig@apple.com | 2a13aa8 | 2011-01-20 23:14:47 +0000 | [diff] [blame] | 115 | |
hyatt@apple.com | f9e710b | 2008-10-10 19:32:52 +0000 | [diff] [blame] | 116 | virtual void setHoveredPart(ScrollbarPart); |
| 117 | virtual void setPressedPart(ScrollbarPart); |
hyatt@apple.com | 3ab4830 | 2008-09-14 23:55:16 +0000 | [diff] [blame] | 118 | |
hyatt@apple.com | 1cd4bcc | 2008-09-16 06:53:34 +0000 | [diff] [blame] | 119 | void setSteps(int lineStep, int pageStep, int pixelsPerStep = 1); |
hyatt | 83b685e | 2006-09-24 07:23:03 +0000 | [diff] [blame] | 120 | void setProportion(int visibleSize, int totalSize); |
hyatt@apple.com | 1cd4bcc | 2008-09-16 06:53:34 +0000 | [diff] [blame] | 121 | void setPressedPos(int p) { m_pressedPos = p; } |
hyatt | 8285c6b | 2006-08-01 01:50:45 +0000 | [diff] [blame] | 122 | |
jamesr@google.com | d5496ef | 2012-03-01 23:36:21 +0000 | [diff] [blame] | 123 | virtual void paint(GraphicsContext*, const IntRect& damageRect); |
hyatt@apple.com | b4f28b3 | 2008-09-18 00:39:36 +0000 | [diff] [blame] | 124 | |
bdakin@apple.com | 1592fa2 | 2011-02-22 22:28:52 +0000 | [diff] [blame] | 125 | virtual bool isOverlayScrollbar() const; |
bdakin@apple.com | d1b8ae2 | 2012-01-13 23:58:22 +0000 | [diff] [blame] | 126 | bool shouldParticipateInHitTesting(); |
bdakin@apple.com | 1592fa2 | 2011-02-22 22:28:52 +0000 | [diff] [blame] | 127 | |
hyatt@apple.com | e380326 | 2008-10-10 07:04:38 +0000 | [diff] [blame] | 128 | bool isWindowActive() const; |
| 129 | |
commit-queue@webkit.org | 42fa320 | 2012-11-16 18:17:30 +0000 | [diff] [blame] | 130 | #if ENABLE(GESTURE_EVENTS) |
| 131 | bool gestureEvent(const PlatformGestureEvent&); |
| 132 | #endif |
| 133 | |
hyatt | d6df585 | 2006-09-28 06:46:35 +0000 | [diff] [blame] | 134 | // These methods are used for platform scrollbars to give :hover feedback. They will not get called |
| 135 | // when the mouse went down in a scrollbar, since it is assumed the scrollbar will start |
| 136 | // grabbing all events in that case anyway. |
hyatt@apple.com | 938a55f | 2008-10-03 20:10:32 +0000 | [diff] [blame] | 137 | bool mouseMoved(const PlatformMouseEvent&); |
bdakin@apple.com | 6875d82 | 2011-11-16 19:53:12 +0000 | [diff] [blame] | 138 | void mouseEntered(); |
hyatt@apple.com | 938a55f | 2008-10-03 20:10:32 +0000 | [diff] [blame] | 139 | bool mouseExited(); |
jamesr@google.com | d5496ef | 2012-03-01 23:36:21 +0000 | [diff] [blame] | 140 | |
hyatt | f2c253a | 2007-04-06 21:37:48 +0000 | [diff] [blame] | 141 | // Used by some platform scrollbars to know when they've been released from capture. |
bdakin@apple.com | 39ef8b8 | 2011-11-07 23:45:23 +0000 | [diff] [blame] | 142 | bool mouseUp(const PlatformMouseEvent&); |
hyatt@apple.com | 30ed544 | 2008-09-13 18:39:58 +0000 | [diff] [blame] | 143 | |
hyatt@apple.com | 938a55f | 2008-10-03 20:10:32 +0000 | [diff] [blame] | 144 | bool mouseDown(const PlatformMouseEvent&); |
hyatt@apple.com | 30ed544 | 2008-09-13 18:39:58 +0000 | [diff] [blame] | 145 | |
hyatt@apple.com | 3ab4830 | 2008-09-14 23:55:16 +0000 | [diff] [blame] | 146 | ScrollbarTheme* theme() const { return m_theme; } |
| 147 | |
hyatt@apple.com | 7597c17 | 2008-09-17 02:15:08 +0000 | [diff] [blame] | 148 | virtual void setParent(ScrollView*); |
hyatt@apple.com | 7597c17 | 2008-09-17 02:15:08 +0000 | [diff] [blame] | 149 | |
hyatt@apple.com | d23089a | 2008-09-18 20:24:16 +0000 | [diff] [blame] | 150 | bool suppressInvalidation() const { return m_suppressInvalidation; } |
| 151 | void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; } |
| 152 | |
hyatt@apple.com | b327f5d | 2009-07-02 17:31:42 +0000 | [diff] [blame] | 153 | virtual IntRect convertToContainingView(const IntRect&) const; |
| 154 | virtual IntRect convertFromContainingView(const IntRect&) const; |
jamesr@google.com | d5496ef | 2012-03-01 23:36:21 +0000 | [diff] [blame] | 155 | |
hyatt@apple.com | b327f5d | 2009-07-02 17:31:42 +0000 | [diff] [blame] | 156 | virtual IntPoint convertToContainingView(const IntPoint&) const; |
| 157 | virtual IntPoint convertFromContainingView(const IntPoint&) const; |
| 158 | |
hausmann@webkit.org | acf913d | 2012-02-22 15:10:21 +0000 | [diff] [blame] | 159 | void moveThumb(int pos, bool draggingDocument = false); |
| 160 | |
commit-queue@webkit.org | d6c30c6 | 2012-09-19 03:39:04 +0000 | [diff] [blame] | 161 | virtual bool isAlphaLocked() const { return m_isAlphaLocked; } |
| 162 | virtual void setIsAlphaLocked(bool flag) { m_isAlphaLocked = flag; } |
| 163 | |
hyatt | 8285c6b | 2006-08-01 01:50:45 +0000 | [diff] [blame] | 164 | protected: |
weinig@apple.com | d7d77c3 | 2011-01-21 20:15:04 +0000 | [diff] [blame] | 165 | Scrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0); |
mitz@apple.com | ed85003 | 2010-02-04 17:35:58 +0000 | [diff] [blame] | 166 | |
estade@chromium.org | 28e13cc | 2010-06-25 22:09:41 +0000 | [diff] [blame] | 167 | void updateThumb(); |
hyatt@apple.com | 63739ce | 2008-09-15 23:44:10 +0000 | [diff] [blame] | 168 | virtual void updateThumbPosition(); |
| 169 | virtual void updateThumbProportion(); |
hyatt@apple.com | b327f5d | 2009-07-02 17:31:42 +0000 | [diff] [blame] | 170 | |
hyatt@apple.com | 30ed544 | 2008-09-13 18:39:58 +0000 | [diff] [blame] | 171 | void autoscrollTimerFired(Timer<Scrollbar>*); |
| 172 | void startTimerIfNeeded(double delay); |
| 173 | void stopTimerIfNeeded(); |
| 174 | void autoscrollPressedPart(double delay); |
| 175 | ScrollDirection pressedPartScrollDirection(); |
| 176 | ScrollGranularity pressedPartScrollGranularity(); |
cfleizach@apple.com | fd65313 | 2013-03-24 07:37:37 +0000 | [diff] [blame] | 177 | |
weinig@apple.com | d7d77c3 | 2011-01-21 20:15:04 +0000 | [diff] [blame] | 178 | ScrollableArea* m_scrollableArea; |
ggaren | cd2cd53 | 2006-10-05 19:59:28 +0000 | [diff] [blame] | 179 | ScrollbarOrientation m_orientation; |
| 180 | ScrollbarControlSize m_controlSize; |
hyatt@apple.com | 0c378c7 | 2008-09-13 22:59:05 +0000 | [diff] [blame] | 181 | ScrollbarTheme* m_theme; |
jamesr@google.com | e53ce64 | 2011-04-14 06:51:50 +0000 | [diff] [blame] | 182 | |
hyatt | 642b72a | 2003-04-25 21:14:28 +0000 | [diff] [blame] | 183 | int m_visibleSize; |
| 184 | int m_totalSize; |
antti | 8a4614c | 2007-03-27 08:03:58 +0000 | [diff] [blame] | 185 | float m_currentPos; |
pkasting@chromium.org | acc0f85 | 2009-04-21 18:34:35 +0000 | [diff] [blame] | 186 | float m_dragOrigin; |
hyatt | 642b72a | 2003-04-25 21:14:28 +0000 | [diff] [blame] | 187 | int m_lineStep; |
| 188 | int m_pageStep; |
antti | 8a4614c | 2007-03-27 08:03:58 +0000 | [diff] [blame] | 189 | float m_pixelStep; |
hyatt@apple.com | 30ed544 | 2008-09-13 18:39:58 +0000 | [diff] [blame] | 190 | |
| 191 | ScrollbarPart m_hoveredPart; |
| 192 | ScrollbarPart m_pressedPart; |
| 193 | int m_pressedPos; |
commit-queue@webkit.org | 42fa320 | 2012-11-16 18:17:30 +0000 | [diff] [blame] | 194 | float m_scrollPos; |
mitz@apple.com | 2b007aa | 2011-04-25 07:26:53 +0000 | [diff] [blame] | 195 | bool m_draggingDocument; |
| 196 | int m_documentDragPos; |
| 197 | |
hyatt@apple.com | b4f28b3 | 2008-09-18 00:39:36 +0000 | [diff] [blame] | 198 | bool m_enabled; |
| 199 | |
hyatt@apple.com | 30ed544 | 2008-09-13 18:39:58 +0000 | [diff] [blame] | 200 | Timer<Scrollbar> m_scrollTimer; |
| 201 | bool m_overlapsResizer; |
jamesr@google.com | d5496ef | 2012-03-01 23:36:21 +0000 | [diff] [blame] | 202 | |
hyatt@apple.com | d23089a | 2008-09-18 20:24:16 +0000 | [diff] [blame] | 203 | bool m_suppressInvalidation; |
pkasting@chromium.org | 591fbbf | 2010-08-26 19:57:43 +0000 | [diff] [blame] | 204 | |
commit-queue@webkit.org | d6c30c6 | 2012-09-19 03:39:04 +0000 | [diff] [blame] | 205 | bool m_isAlphaLocked; |
| 206 | |
pkasting@chromium.org | 591fbbf | 2010-08-26 19:57:43 +0000 | [diff] [blame] | 207 | private: |
| 208 | virtual bool isScrollbar() const { return true; } |
hyatt | 642b72a | 2003-04-25 21:14:28 +0000 | [diff] [blame] | 209 | }; |
| 210 | |
weinig@apple.com | 2a13aa8 | 2011-01-20 23:14:47 +0000 | [diff] [blame] | 211 | } // namespace WebCore |
darin | f4b05b2 | 2006-07-10 05:20:17 +0000 | [diff] [blame] | 212 | |
weinig@apple.com | 2a13aa8 | 2011-01-20 23:14:47 +0000 | [diff] [blame] | 213 | #endif // Scrollbar_h |