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 "ScrollTypes.h"
32 #include <wtf/MathExtras.h>
33 #include <wtf/PassRefPtr.h>
37 class GraphicsContext;
39 class PlatformMouseEvent;
43 class Scrollbar : public Widget {
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);
50 // Called by the ScrollableArea when the scroll offset changes.
51 void offsetDidChange();
53 static int pixelsPerLineStep() { return 40; }
54 static float minFractionToStepWhenPaging() { return 0.875f; }
55 static int maxOverlapBetweenPages();
57 void disconnectFromScrollableArea() { m_scrollableArea = 0; }
58 ScrollableArea* scrollableArea() const { return m_scrollableArea; }
60 virtual bool isCustomScrollbar() const { return false; }
61 ScrollbarOrientation orientation() const { return m_orientation; }
63 int value() const { return lroundf(m_currentPos); }
64 float currentPos() const { return m_currentPos; }
65 int pressedPos() const { return m_pressedPos; }
66 int visibleSize() const { return m_visibleSize; }
67 int totalSize() const { return m_totalSize; }
68 int maximum() const { return m_totalSize - m_visibleSize; }
69 ScrollbarControlSize controlSize() const { return m_controlSize; }
71 int lineStep() const { return m_lineStep; }
72 int pageStep() const { return m_pageStep; }
73 float pixelStep() const { return m_pixelStep; }
75 ScrollbarPart pressedPart() const { return m_pressedPart; }
76 ScrollbarPart hoveredPart() const { return m_hoveredPart; }
77 virtual void setHoveredPart(ScrollbarPart);
78 virtual void setPressedPart(ScrollbarPart);
80 void setSteps(int lineStep, int pageStep, int pixelsPerStep = 1);
81 void setProportion(int visibleSize, int totalSize);
82 void setPressedPos(int p) { m_pressedPos = p; }
84 virtual void paint(GraphicsContext*, const IntRect& damageRect);
86 bool enabled() const { return m_enabled; }
87 virtual void setEnabled(bool e);
89 virtual bool isOverlayScrollbar() const;
91 bool isWindowActive() const;
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&);
99 // Used by some platform scrollbars to know when they've been released from capture.
102 bool mouseDown(const PlatformMouseEvent&);
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);
111 ScrollbarTheme* theme() const { return m_theme; }
113 virtual void setParent(ScrollView*);
114 virtual void setFrameRect(const IntRect&);
116 virtual void invalidateRect(const IntRect&);
118 bool suppressInvalidation() const { return m_suppressInvalidation; }
119 void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; }
121 virtual void styleChanged() { }
123 virtual IntRect convertToContainingView(const IntRect&) const;
124 virtual IntRect convertFromContainingView(const IntRect&) const;
126 virtual IntPoint convertToContainingView(const IntPoint&) const;
127 virtual IntPoint convertFromContainingView(const IntPoint&) const;
130 Scrollbar(ScrollableArea*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0);
133 virtual void updateThumbPosition();
134 virtual void updateThumbProportion();
136 void autoscrollTimerFired(Timer<Scrollbar>*);
137 void startTimerIfNeeded(double delay);
138 void stopTimerIfNeeded();
139 void autoscrollPressedPart(double delay);
140 ScrollDirection pressedPartScrollDirection();
141 ScrollGranularity pressedPartScrollGranularity();
143 void moveThumb(int pos, bool draggingDocument = false);
145 ScrollableArea* m_scrollableArea;
146 ScrollbarOrientation m_orientation;
147 ScrollbarControlSize m_controlSize;
148 ScrollbarTheme* m_theme;
158 ScrollbarPart m_hoveredPart;
159 ScrollbarPart m_pressedPart;
161 bool m_draggingDocument;
162 int m_documentDragPos;
166 Timer<Scrollbar> m_scrollTimer;
167 bool m_overlapsResizer;
169 bool m_suppressInvalidation;
172 virtual bool isScrollbar() const { return true; }
173 virtual AXObjectCache* axObjectCache() const;
176 } // namespace WebCore
178 #endif // Scrollbar_h