• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "ScrollTypes.h"
30 #include "Timer.h"
31 #include "Widget.h"
32 #include <wtf/MathExtras.h>
33 #include <wtf/PassRefPtr.h>
34 
35 namespace WebCore {
36 
37 class GraphicsContext;
38 class IntRect;
39 class PlatformMouseEvent;
40 class ScrollableArea;
41 class ScrollbarTheme;
42 
43 class Scrollbar : public Widget {
44 public:
45     // 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.
46     static PassRefPtr<Scrollbar> createNativeScrollbar(ScrollableArea*, ScrollbarOrientation orientation, ScrollbarControlSize size);
47 
48     virtual ~Scrollbar();
49 
50     // Called by the ScrollableArea when the scroll offset changes.
51     void offsetDidChange();
52 
pixelsPerLineStep()53     static int pixelsPerLineStep() { return 40; }
minFractionToStepWhenPaging()54     static float minFractionToStepWhenPaging() { return 0.875f; }
55     static int maxOverlapBetweenPages();
56 
disconnectFromScrollableArea()57     void disconnectFromScrollableArea() { m_scrollableArea = 0; }
scrollableArea()58     ScrollableArea* scrollableArea() const { return m_scrollableArea; }
59 
isCustomScrollbar()60     virtual bool isCustomScrollbar() const { return false; }
orientation()61     ScrollbarOrientation orientation() const { return m_orientation; }
62 
value()63     int value() const { return lroundf(m_currentPos); }
currentPos()64     float currentPos() const { return m_currentPos; }
pressedPos()65     int pressedPos() const { return m_pressedPos; }
visibleSize()66     int visibleSize() const { return m_visibleSize; }
totalSize()67     int totalSize() const { return m_totalSize; }
maximum()68     int maximum() const { return m_totalSize - m_visibleSize; }
controlSize()69     ScrollbarControlSize controlSize() const { return m_controlSize; }
70 
lineStep()71     int lineStep() const { return m_lineStep; }
pageStep()72     int pageStep() const { return m_pageStep; }
pixelStep()73     float pixelStep() const { return m_pixelStep; }
74 
pressedPart()75     ScrollbarPart pressedPart() const { return m_pressedPart; }
hoveredPart()76     ScrollbarPart hoveredPart() const { return m_hoveredPart; }
77     virtual void setHoveredPart(ScrollbarPart);
78     virtual void setPressedPart(ScrollbarPart);
79 
80     void setSteps(int lineStep, int pageStep, int pixelsPerStep = 1);
81     void setProportion(int visibleSize, int totalSize);
setPressedPos(int p)82     void setPressedPos(int p) { m_pressedPos = p; }
83 
84     virtual void paint(GraphicsContext*, const IntRect& damageRect);
85 
enabled()86     bool enabled() const { return m_enabled; }
87     virtual void setEnabled(bool e);
88 
89     virtual bool isOverlayScrollbar() const;
90 
91     bool isWindowActive() const;
92 
93     // These methods are used for platform scrollbars to give :hover feedback.  They will not get called
94     // when the mouse went down in a scrollbar, since it is assumed the scrollbar will start
95     // grabbing all events in that case anyway.
96     bool mouseMoved(const PlatformMouseEvent&);
97     bool mouseExited();
98 
99     // Used by some platform scrollbars to know when they've been released from capture.
100     bool mouseUp();
101 
102     bool mouseDown(const PlatformMouseEvent&);
103 
104 #if PLATFORM(QT)
105     // For platforms that wish to handle context menu events.
106     // FIXME: This is misplaced.  Normal hit testing should be used to populate a correct
107     // context menu.  There's no reason why the scrollbar should have to do it.
108     bool contextMenu(const PlatformMouseEvent& event);
109 #endif
110 
theme()111     ScrollbarTheme* theme() const { return m_theme; }
112 
113     virtual void setParent(ScrollView*);
114     virtual void setFrameRect(const IntRect&);
115 
116     virtual void invalidateRect(const IntRect&);
117 
suppressInvalidation()118     bool suppressInvalidation() const { return m_suppressInvalidation; }
setSuppressInvalidation(bool s)119     void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; }
120 
styleChanged()121     virtual void styleChanged() { }
122 
123     virtual IntRect convertToContainingView(const IntRect&) const;
124     virtual IntRect convertFromContainingView(const IntRect&) const;
125 
126     virtual IntPoint convertToContainingView(const IntPoint&) const;
127     virtual IntPoint convertFromContainingView(const IntPoint&) const;
128 
129 protected:
130     Scrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0);
131 
132     void updateThumb();
133     virtual void updateThumbPosition();
134     virtual void updateThumbProportion();
135 
136     void autoscrollTimerFired(Timer<Scrollbar>*);
137     void startTimerIfNeeded(double delay);
138     void stopTimerIfNeeded();
139     void autoscrollPressedPart(double delay);
140     ScrollDirection pressedPartScrollDirection();
141     ScrollGranularity pressedPartScrollGranularity();
142 
143     void moveThumb(int pos);
144 
145     ScrollableArea* m_scrollableArea;
146     ScrollbarOrientation m_orientation;
147     ScrollbarControlSize m_controlSize;
148     ScrollbarTheme* m_theme;
149 
150     int m_visibleSize;
151     int m_totalSize;
152     float m_currentPos;
153     float m_dragOrigin;
154     int m_lineStep;
155     int m_pageStep;
156     float m_pixelStep;
157 
158     ScrollbarPart m_hoveredPart;
159     ScrollbarPart m_pressedPart;
160     int m_pressedPos;
161 
162     bool m_enabled;
163 
164     Timer<Scrollbar> m_scrollTimer;
165     bool m_overlapsResizer;
166 
167     bool m_suppressInvalidation;
168 
169 private:
isScrollbar()170     virtual bool isScrollbar() const { return true; }
171     virtual AXObjectCache* axObjectCache() const;
172 };
173 
174 } // namespace WebCore
175 
176 #endif // Scrollbar_h
177