blob: 00c7618b04cb726b70f82a22b03e744ba98ac177 [file] [log] [blame]
hyatt642b72a2003-04-25 21:14:28 +00001/*
darine9700da2006-03-06 23:09:48 +00002 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved.
hyatt642b72a2003-04-25 21:14:28 +00003 *
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.org226f72a2008-09-17 04:22:02 +000026#ifndef Scrollbar_h
27#define Scrollbar_h
hyatt642b72a2003-04-25 21:14:28 +000028
jamesr@google.comd5496ef2012-03-01 23:36:21 +000029#include "ScrollbarThemeClient.h"
darin60e537f52006-11-15 01:29:46 +000030#include "ScrollTypes.h"
hyatt@apple.com30ed5442008-09-13 18:39:58 +000031#include "Timer.h"
hyatt@apple.com818ffe92008-09-12 18:37:23 +000032#include "Widget.h"
anderscac3c01592007-03-27 16:40:11 +000033#include <wtf/MathExtras.h>
hyatt@apple.com4e3b8602008-09-17 03:17:11 +000034#include <wtf/PassRefPtr.h>
hyattd6df5852006-09-28 06:46:35 +000035
darinf4b05b22006-07-10 05:20:17 +000036namespace WebCore {
37
hyatt8285c6b2006-08-01 01:50:45 +000038class GraphicsContext;
39class IntRect;
hyattd6df5852006-09-28 06:46:35 +000040class PlatformMouseEvent;
weinig@apple.comd7d77c32011-01-21 20:15:04 +000041class ScrollableArea;
42class ScrollbarTheme;
hyatt8285c6b2006-08-01 01:50:45 +000043
commit-queue@webkit.org42fa3202012-11-16 18:17:30 +000044#if ENABLE(GESTURE_EVENTS)
45class PlatformGestureEvent;
46#endif
47
jamesr@google.comd5496ef2012-03-01 23:36:21 +000048class Scrollbar : public Widget,
49 public ScrollbarThemeClient {
50
hyatt8285c6b2006-08-01 01:50:45 +000051public:
weinig@apple.comd7d77c32011-01-21 20:15:04 +000052 // 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.org1bf3b4b2010-09-08 19:31:47 +000054
hyatt@apple.comd62f5bf2008-09-14 00:32:19 +000055 virtual ~Scrollbar();
hyatt8285c6b2006-08-01 01:50:45 +000056
jamesr@google.comd5496ef2012-03-01 23:36:21 +000057 // 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.comd7d77c32011-01-21 20:15:04 +0000102 // Called by the ScrollableArea when the scroll offset changes.
weinig@apple.com2a13aa82011-01-20 23:14:47 +0000103 void offsetDidChange();
104
mitz@apple.comed850032010-02-04 17:35:58 +0000105 static int pixelsPerLineStep() { return 40; }
106 static float minFractionToStepWhenPaging() { return 0.875f; }
107 static int maxOverlapBetweenPages();
108
weinig@apple.comd7d77c32011-01-21 20:15:04 +0000109 void disconnectFromScrollableArea() { m_scrollableArea = 0; }
110 ScrollableArea* scrollableArea() const { return m_scrollableArea; }
mitz@apple.come55c4d32007-11-08 01:54:14 +0000111
hyatt@apple.com1cd4bcc2008-09-16 06:53:34 +0000112 int pressedPos() const { return m_pressedPos; }
hyatt642b72a2003-04-25 21:14:28 +0000113
hyatt@apple.com3ab48302008-09-14 23:55:16 +0000114 float pixelStep() const { return m_pixelStep; }
weinig@apple.com2a13aa82011-01-20 23:14:47 +0000115
hyatt@apple.comf9e710b2008-10-10 19:32:52 +0000116 virtual void setHoveredPart(ScrollbarPart);
117 virtual void setPressedPart(ScrollbarPart);
hyatt@apple.com3ab48302008-09-14 23:55:16 +0000118
hyatt@apple.com1cd4bcc2008-09-16 06:53:34 +0000119 void setSteps(int lineStep, int pageStep, int pixelsPerStep = 1);
hyatt83b685e2006-09-24 07:23:03 +0000120 void setProportion(int visibleSize, int totalSize);
hyatt@apple.com1cd4bcc2008-09-16 06:53:34 +0000121 void setPressedPos(int p) { m_pressedPos = p; }
hyatt8285c6b2006-08-01 01:50:45 +0000122
jamesr@google.comd5496ef2012-03-01 23:36:21 +0000123 virtual void paint(GraphicsContext*, const IntRect& damageRect);
hyatt@apple.comb4f28b32008-09-18 00:39:36 +0000124
bdakin@apple.com1592fa22011-02-22 22:28:52 +0000125 virtual bool isOverlayScrollbar() const;
bdakin@apple.comd1b8ae22012-01-13 23:58:22 +0000126 bool shouldParticipateInHitTesting();
bdakin@apple.com1592fa22011-02-22 22:28:52 +0000127
hyatt@apple.come3803262008-10-10 07:04:38 +0000128 bool isWindowActive() const;
129
commit-queue@webkit.org42fa3202012-11-16 18:17:30 +0000130#if ENABLE(GESTURE_EVENTS)
131 bool gestureEvent(const PlatformGestureEvent&);
132#endif
133
hyattd6df5852006-09-28 06:46:35 +0000134 // 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.com938a55f2008-10-03 20:10:32 +0000137 bool mouseMoved(const PlatformMouseEvent&);
bdakin@apple.com6875d822011-11-16 19:53:12 +0000138 void mouseEntered();
hyatt@apple.com938a55f2008-10-03 20:10:32 +0000139 bool mouseExited();
jamesr@google.comd5496ef2012-03-01 23:36:21 +0000140
hyattf2c253a2007-04-06 21:37:48 +0000141 // Used by some platform scrollbars to know when they've been released from capture.
bdakin@apple.com39ef8b82011-11-07 23:45:23 +0000142 bool mouseUp(const PlatformMouseEvent&);
hyatt@apple.com30ed5442008-09-13 18:39:58 +0000143
hyatt@apple.com938a55f2008-10-03 20:10:32 +0000144 bool mouseDown(const PlatformMouseEvent&);
hyatt@apple.com30ed5442008-09-13 18:39:58 +0000145
hyatt@apple.com3ab48302008-09-14 23:55:16 +0000146 ScrollbarTheme* theme() const { return m_theme; }
147
hyatt@apple.com7597c172008-09-17 02:15:08 +0000148 virtual void setParent(ScrollView*);
hyatt@apple.com7597c172008-09-17 02:15:08 +0000149
hyatt@apple.comd23089a2008-09-18 20:24:16 +0000150 bool suppressInvalidation() const { return m_suppressInvalidation; }
151 void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; }
152
hyatt@apple.comb327f5d2009-07-02 17:31:42 +0000153 virtual IntRect convertToContainingView(const IntRect&) const;
154 virtual IntRect convertFromContainingView(const IntRect&) const;
jamesr@google.comd5496ef2012-03-01 23:36:21 +0000155
hyatt@apple.comb327f5d2009-07-02 17:31:42 +0000156 virtual IntPoint convertToContainingView(const IntPoint&) const;
157 virtual IntPoint convertFromContainingView(const IntPoint&) const;
158
hausmann@webkit.orgacf913d2012-02-22 15:10:21 +0000159 void moveThumb(int pos, bool draggingDocument = false);
160
commit-queue@webkit.orgd6c30c62012-09-19 03:39:04 +0000161 virtual bool isAlphaLocked() const { return m_isAlphaLocked; }
162 virtual void setIsAlphaLocked(bool flag) { m_isAlphaLocked = flag; }
163
hyatt8285c6b2006-08-01 01:50:45 +0000164protected:
weinig@apple.comd7d77c32011-01-21 20:15:04 +0000165 Scrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0);
mitz@apple.comed850032010-02-04 17:35:58 +0000166
estade@chromium.org28e13cc2010-06-25 22:09:41 +0000167 void updateThumb();
hyatt@apple.com63739ce2008-09-15 23:44:10 +0000168 virtual void updateThumbPosition();
169 virtual void updateThumbProportion();
hyatt@apple.comb327f5d2009-07-02 17:31:42 +0000170
hyatt@apple.com30ed5442008-09-13 18:39:58 +0000171 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.comfd653132013-03-24 07:37:37 +0000177
weinig@apple.comd7d77c32011-01-21 20:15:04 +0000178 ScrollableArea* m_scrollableArea;
ggarencd2cd532006-10-05 19:59:28 +0000179 ScrollbarOrientation m_orientation;
180 ScrollbarControlSize m_controlSize;
hyatt@apple.com0c378c72008-09-13 22:59:05 +0000181 ScrollbarTheme* m_theme;
jamesr@google.come53ce642011-04-14 06:51:50 +0000182
hyatt642b72a2003-04-25 21:14:28 +0000183 int m_visibleSize;
184 int m_totalSize;
antti8a4614c2007-03-27 08:03:58 +0000185 float m_currentPos;
pkasting@chromium.orgacc0f852009-04-21 18:34:35 +0000186 float m_dragOrigin;
hyatt642b72a2003-04-25 21:14:28 +0000187 int m_lineStep;
188 int m_pageStep;
antti8a4614c2007-03-27 08:03:58 +0000189 float m_pixelStep;
hyatt@apple.com30ed5442008-09-13 18:39:58 +0000190
191 ScrollbarPart m_hoveredPart;
192 ScrollbarPart m_pressedPart;
193 int m_pressedPos;
commit-queue@webkit.org42fa3202012-11-16 18:17:30 +0000194 float m_scrollPos;
mitz@apple.com2b007aa2011-04-25 07:26:53 +0000195 bool m_draggingDocument;
196 int m_documentDragPos;
197
hyatt@apple.comb4f28b32008-09-18 00:39:36 +0000198 bool m_enabled;
199
hyatt@apple.com30ed5442008-09-13 18:39:58 +0000200 Timer<Scrollbar> m_scrollTimer;
201 bool m_overlapsResizer;
jamesr@google.comd5496ef2012-03-01 23:36:21 +0000202
hyatt@apple.comd23089a2008-09-18 20:24:16 +0000203 bool m_suppressInvalidation;
pkasting@chromium.org591fbbf2010-08-26 19:57:43 +0000204
commit-queue@webkit.orgd6c30c62012-09-19 03:39:04 +0000205 bool m_isAlphaLocked;
206
pkasting@chromium.org591fbbf2010-08-26 19:57:43 +0000207private:
208 virtual bool isScrollbar() const { return true; }
hyatt642b72a2003-04-25 21:14:28 +0000209};
210
weinig@apple.com2a13aa82011-01-20 23:14:47 +0000211} // namespace WebCore
darinf4b05b22006-07-10 05:20:17 +0000212
weinig@apple.com2a13aa82011-01-20 23:14:47 +0000213#endif // Scrollbar_h