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 // These match the numbers we use over in WebKit (WebFrameView.m). 44 const int cScrollbarPixelsPerLineStep = 40; 45 const int cAmountToKeepWhenPaging = 40; 46 47 class Scrollbar : public Widget { 48 protected: 49 Scrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSize, ScrollbarTheme* = 0); 50 51 public: 52 virtual ~Scrollbar(); 53 54 // 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. 55 static PassRefPtr<Scrollbar> createNativeScrollbar(ScrollbarClient* client, ScrollbarOrientation orientation, ScrollbarControlSize size); 56 setClient(ScrollbarClient * client)57 void setClient(ScrollbarClient* client) { m_client = client; } client()58 ScrollbarClient* client() const { return m_client; } 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 bool setValue(int); 82 void setProportion(int visibleSize, int totalSize); setPressedPos(int p)83 void setPressedPos(int p) { m_pressedPos = p; } 84 85 bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1.0f); 86 87 virtual void paint(GraphicsContext*, const IntRect& damageRect); 88 enabled()89 bool enabled() const { return m_enabled; } 90 virtual void setEnabled(bool e); 91 92 bool isWindowActive() const; 93 94 // These methods are used for platform scrollbars to give :hover feedback. They will not get called 95 // when the mouse went down in a scrollbar, since it is assumed the scrollbar will start 96 // grabbing all events in that case anyway. 97 bool mouseMoved(const PlatformMouseEvent&); 98 bool mouseExited(); 99 100 // Used by some platform scrollbars to know when they've been released from capture. 101 bool mouseUp(); 102 103 bool mouseDown(const PlatformMouseEvent&); 104 105 #if PLATFORM(QT) 106 // For platforms that wish to handle context menu events. 107 // FIXME: This is misplaced. Normal hit testing should be used to populate a correct 108 // context menu. There's no reason why the scrollbar should have to do it. 109 bool contextMenu(const PlatformMouseEvent& event); 110 #endif 111 theme()112 ScrollbarTheme* theme() const { return m_theme; } 113 114 virtual void setParent(ScrollView*); 115 virtual void setFrameRect(const IntRect&); 116 117 virtual void invalidateRect(const IntRect&); 118 suppressInvalidation()119 bool suppressInvalidation() const { return m_suppressInvalidation; } setSuppressInvalidation(bool s)120 void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; } 121 styleChanged()122 virtual void styleChanged() { } 123 124 virtual IntRect convertToContainingView(const IntRect&) const; 125 virtual IntRect convertFromContainingView(const IntRect&) const; 126 127 virtual IntPoint convertToContainingView(const IntPoint&) const; 128 virtual IntPoint convertFromContainingView(const IntPoint&) const; 129 130 private: isScrollbar()131 virtual bool isScrollbar() const { return true; } 132 133 protected: 134 virtual void updateThumbPosition(); 135 virtual void updateThumbProportion(); 136 137 void autoscrollTimerFired(Timer<Scrollbar>*); 138 void startTimerIfNeeded(double delay); 139 void stopTimerIfNeeded(); 140 void autoscrollPressedPart(double delay); 141 ScrollDirection pressedPartScrollDirection(); 142 ScrollGranularity pressedPartScrollGranularity(); 143 144 void moveThumb(int pos); 145 bool setCurrentPos(float pos); 146 147 ScrollbarClient* m_client; 148 ScrollbarOrientation m_orientation; 149 ScrollbarControlSize m_controlSize; 150 ScrollbarTheme* m_theme; 151 152 int m_visibleSize; 153 int m_totalSize; 154 float m_currentPos; 155 float m_dragOrigin; 156 int m_lineStep; 157 int m_pageStep; 158 float m_pixelStep; 159 160 ScrollbarPart m_hoveredPart; 161 ScrollbarPart m_pressedPart; 162 int m_pressedPos; 163 164 bool m_enabled; 165 166 Timer<Scrollbar> m_scrollTimer; 167 bool m_overlapsResizer; 168 169 bool m_suppressInvalidation; 170 }; 171 172 } 173 174 #endif 175