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 ScrollbarClient; 40 class ScrollbarTheme; 41 class PlatformMouseEvent; 42 43 class Scrollbar : public Widget { 44 public: 45 virtual ~Scrollbar(); 46 47 // 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. 48 static PassRefPtr<Scrollbar> createNativeScrollbar(ScrollbarClient* client, ScrollbarOrientation orientation, ScrollbarControlSize size); 49 pixelsPerLineStep()50 static int pixelsPerLineStep() { return 40; } minFractionToStepWhenPaging()51 static float minFractionToStepWhenPaging() { return 0.875f; } 52 static int maxOverlapBetweenPages(); 53 setClient(ScrollbarClient * client)54 void setClient(ScrollbarClient* client) { m_client = client; } client()55 ScrollbarClient* client() const { return m_client; } 56 isCustomScrollbar()57 virtual bool isCustomScrollbar() const { return false; } orientation()58 ScrollbarOrientation orientation() const { return m_orientation; } 59 value()60 int value() const { return lroundf(m_currentPos); } currentPos()61 float currentPos() const { return m_currentPos; } pressedPos()62 int pressedPos() const { return m_pressedPos; } visibleSize()63 int visibleSize() const { return m_visibleSize; } totalSize()64 int totalSize() const { return m_totalSize; } maximum()65 int maximum() const { return m_totalSize - m_visibleSize; } controlSize()66 ScrollbarControlSize controlSize() const { return m_controlSize; } 67 lineStep()68 int lineStep() const { return m_lineStep; } pageStep()69 int pageStep() const { return m_pageStep; } pixelStep()70 float pixelStep() const { return m_pixelStep; } 71 pressedPart()72 ScrollbarPart pressedPart() const { return m_pressedPart; } hoveredPart()73 ScrollbarPart hoveredPart() const { return m_hoveredPart; } 74 virtual void setHoveredPart(ScrollbarPart); 75 virtual void setPressedPart(ScrollbarPart); 76 77 void setSteps(int lineStep, int pageStep, int pixelsPerStep = 1); 78 bool setValue(int); 79 void setProportion(int visibleSize, int totalSize); setPressedPos(int p)80 void setPressedPos(int p) { m_pressedPos = p; } 81 82 bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1.0f); 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 bool isWindowActive() const; 90 91 // These methods are used for platform scrollbars to give :hover feedback. They will not get called 92 // when the mouse went down in a scrollbar, since it is assumed the scrollbar will start 93 // grabbing all events in that case anyway. 94 bool mouseMoved(const PlatformMouseEvent&); 95 bool mouseExited(); 96 97 // Used by some platform scrollbars to know when they've been released from capture. 98 bool mouseUp(); 99 100 bool mouseDown(const PlatformMouseEvent&); 101 102 #if PLATFORM(QT) 103 // For platforms that wish to handle context menu events. 104 // FIXME: This is misplaced. Normal hit testing should be used to populate a correct 105 // context menu. There's no reason why the scrollbar should have to do it. 106 bool contextMenu(const PlatformMouseEvent& event); 107 #endif 108 theme()109 ScrollbarTheme* theme() const { return m_theme; } 110 111 virtual void setParent(ScrollView*); 112 virtual void setFrameRect(const IntRect&); 113 114 virtual void invalidateRect(const IntRect&); 115 suppressInvalidation()116 bool suppressInvalidation() const { return m_suppressInvalidation; } setSuppressInvalidation(bool s)117 void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; } 118 styleChanged()119 virtual void styleChanged() { } 120 121 virtual IntRect convertToContainingView(const IntRect&) const; 122 virtual IntRect convertFromContainingView(const IntRect&) const; 123 124 virtual IntPoint convertToContainingView(const IntPoint&) const; 125 virtual IntPoint convertFromContainingView(const IntPoint&) const; 126 127 private: isScrollbar()128 virtual bool isScrollbar() const { return true; } 129 130 protected: 131 Scrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0); 132 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 bool setCurrentPos(float pos); 145 146 ScrollbarClient* m_client; 147 ScrollbarOrientation m_orientation; 148 ScrollbarControlSize m_controlSize; 149 ScrollbarTheme* m_theme; 150 151 int m_visibleSize; 152 int m_totalSize; 153 float m_currentPos; 154 float m_dragOrigin; 155 int m_lineStep; 156 int m_pageStep; 157 float m_pixelStep; 158 159 ScrollbarPart m_hoveredPart; 160 ScrollbarPart m_pressedPart; 161 int m_pressedPos; 162 163 bool m_enabled; 164 165 Timer<Scrollbar> m_scrollTimer; 166 bool m_overlapsResizer; 167 168 bool m_suppressInvalidation; 169 }; 170 171 } 172 173 #endif 174