| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2004, 2005, 2006, 2007 Apple 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 PlatformScrollbar_h | |
| 27 #define PlatformScrollbar_h | |
| 28 | |
| 29 #include <windows.h> | |
| 30 | |
| 31 #include "Widget.h" | |
| 32 #include "ScrollBar.h" | |
| 33 #include "Timer.h" | |
| 34 | |
| 35 namespace gfx { | |
| 36 class PlatformCanvasWin; | |
| 37 } | |
| 38 | |
| 39 namespace WebCore { | |
| 40 | |
| 41 // IMPORTANT NOTES ABOUT SCROLLBARS | |
| 42 // | |
| 43 // WebKit uses scrollbars in two ways. The first way is as a scroll control | |
| 44 // for a ScrollView. This scrollbar sits inside the ScrollView's rect and | |
| 45 // modifies its scrollOffset. Because it is inside the ScrollView's rect, it | |
| 46 // is a child of the ScrollView, but because it is not really part of the | |
| 47 // scrollView's content, it doesn't move as the scrollOffset changes. | |
| 48 // | |
| 49 // The second use is as a scroll control for things other than a ScrollView, | |
| 50 // e.g. a <select>. A <select> is not a ScrollView, so the scrollbar is not a | |
| 51 // child of it -- instead, it is a child of the ScrollView representing the | |
| 52 // frame in which the <select> (and the scrollbar) are located. In this case, | |
| 53 // the scrollbar IS part of the ScrollView's content, and it moves when the | |
| 54 // scrollOffset changes. | |
| 55 // | |
| 56 // ScrollViewWin distinguishes these two cases in its convertChildToSelf and | |
| 57 // convertSelfToChild methods, which are used when converting coordinates | |
| 58 // between the ScrollBar's coordinate system and that of the native window. | |
| 59 | |
| 60 class PlatformScrollbar : public Widget, public Scrollbar { | |
| 61 public: | |
| 62 static PassRefPtr<PlatformScrollbar> create(ScrollbarClient* client, Scrollb
arOrientation orientation, ScrollbarControlSize size) | |
| 63 { | |
| 64 return adoptRef(new PlatformScrollbar(client, orientation, size)); | |
| 65 } | |
| 66 virtual ~PlatformScrollbar(); | |
| 67 | |
| 68 virtual bool isWidget() const { return true; } | |
| 69 | |
| 70 virtual int width() const; | |
| 71 virtual int height() const; | |
| 72 virtual void setRect(const IntRect&); | |
| 73 virtual void setEnabled(bool); | |
| 74 virtual bool isEnabled() const { return m_enabled; } | |
| 75 virtual void paint(GraphicsContext*, const IntRect& damageRect); | |
| 76 | |
| 77 virtual void setFrameGeometry(const IntRect& rect); | |
| 78 | |
| 79 // All mouse handler functions below receive mouse events in window | |
| 80 // coordinates. | |
| 81 | |
| 82 // NOTE: These may be called after we've been removed from the widget/ | |
| 83 // window hierarchy, for example because the EventHandler keeps a reference | |
| 84 // around and tries to feed us MouseOut events. In this case, doing | |
| 85 // something would be not only pointless but dangerous, as without a | |
| 86 // parent() we will end up failing an ASSERT(). So bail early if we get to | |
| 87 // any of these with no parent(). | |
| 88 virtual bool handleMouseMoveEvent(const PlatformMouseEvent&); | |
| 89 virtual bool handleMouseOutEvent(const PlatformMouseEvent&); | |
| 90 virtual bool handleMousePressEvent(const PlatformMouseEvent&); | |
| 91 virtual bool handleMouseReleaseEvent(const PlatformMouseEvent&); | |
| 92 | |
| 93 virtual IntRect windowClipRect() const; | |
| 94 | |
| 95 static void themeChanged(); | |
| 96 static int horizontalScrollbarHeight(ScrollbarControlSize size = RegularScro
llbar); | |
| 97 static int verticalScrollbarWidth(ScrollbarControlSize size = RegularScrollb
ar); | |
| 98 | |
| 99 // Scrolls the page when auto-repeat scrolling. | |
| 100 void autoscrollTimerFired(Timer<PlatformScrollbar>*); | |
| 101 | |
| 102 // This function receives events in window coordinates. | |
| 103 void handleMouseMoveEventWhenCapturing(const PlatformMouseEvent& e); | |
| 104 | |
| 105 protected: | |
| 106 virtual void updateThumbPosition(); | |
| 107 virtual void updateThumbProportion(); | |
| 108 | |
| 109 private: | |
| 110 PlatformScrollbar(ScrollbarClient*, ScrollbarOrientation, ScrollbarControlSi
ze); | |
| 111 | |
| 112 // Scroll bar segment identifiers | |
| 113 enum Segment { | |
| 114 Arrow1 = 0, | |
| 115 Track, // Only used when scrollbar does not contain a thumb | |
| 116 BeforeThumb, // -| | |
| 117 Thumb, // -+ Only used when scrollbar contains a thumb | |
| 118 AfterThumb, // -| | |
| 119 Arrow2, | |
| 120 None, | |
| 121 NumSegments = None | |
| 122 }; | |
| 123 | |
| 124 // Turns on/off whether we have mouse capture. This is only for tracking, | |
| 125 // as the EventHandler is what controls the actual capture. | |
| 126 void setCapturingMouse(bool capturing); | |
| 127 | |
| 128 // Returns the girth of the scrollbar arrow button for layout, given the | |
| 129 // system metrics code for the desired direction's button and a limiting | |
| 130 // height (for vertical scroll bars) or width (for horizontal scrollbars). | |
| 131 // Also computes the background span (available remaining space). | |
| 132 int scrollButtonGirth(int systemMetricsCode, int limit, | |
| 133 int* backgroundSpan); | |
| 134 | |
| 135 // Returns the girth of the scrollbar thumb for layout, given the system | |
| 136 // metrics code for the desired direction's thumb and the background span | |
| 137 // (space remaining after the buttons are drawn). | |
| 138 int scrollThumbGirth(int systemMetricsCode, int backgroundSpan); | |
| 139 | |
| 140 // Computes the layout of the scroll bar given its current configuration. | |
| 141 void layout(); | |
| 142 | |
| 143 // Sets the current mouse position to the coordinates in |event|. | |
| 144 void updateMousePosition(int x, int y); | |
| 145 | |
| 146 // Helper routine for updateMousePosition(), used to bypass layout(). | |
| 147 void updateMousePositionInternal(); | |
| 148 | |
| 149 // Returns the correct state for the theme engine to draw a segment. | |
| 150 int getThemeState(Segment target) const; | |
| 151 int getThemeArrowState(Segment target) const; | |
| 152 int getClassicThemeState(Segment target) const; | |
| 153 | |
| 154 // Draws the tick-marks on the scrollbar. The tick-marks are visual | |
| 155 // indicators showing the results from a find-in-page operation. | |
| 156 void DrawTickmarks(GraphicsContext* context) const; | |
| 157 | |
| 158 IntPoint m_lastNativePos; // The last (native) mouse coordinate received. | |
| 159 struct { | |
| 160 int thumbPos; // Relevant (window) mouse coordinate, and... | |
| 161 int scrollVal; // ...current scrollvalue, when... | |
| 162 } m_dragOrigin; // ...user begins dragging the thumb. | |
| 163 RECT m_segmentRects[NumSegments]; | |
| 164 // The native coordinates of the scrollbar | |
| 165 // segments. | |
| 166 Segment m_mouseOver; // The scrollbar segment the mouse is over. | |
| 167 Segment m_captureStart; // The segment on which we started capture. | |
| 168 Timer<PlatformScrollbar> m_autorepeatTimer; | |
| 169 // Timer to start and continue auto-repeat | |
| 170 // scrolling when the button is held down. | |
| 171 bool m_enabled; // True when the scrollbar is enabled. | |
| 172 bool m_needsLayout; // True when cached geometry may have changed | |
| 173 | |
| 174 // Multipliers against scrollbar thickness that determine how far away from | |
| 175 // the scrollbar track the cursor can go before the thumb "snaps back" | |
| 176 static const int kOffSideMultiplier; | |
| 177 static const int kOffEndMultiplier; | |
| 178 | |
| 179 // Auto-repeat delays, in seconds | |
| 180 static const double kAutorepeatInitialDelay; | |
| 181 static const double kAutorepeatRepeatInterval; | |
| 182 }; | |
| 183 | |
| 184 } | |
| 185 | |
| 186 #endif // PlatformScrollbar_h | |
| 187 | |
| OLD | NEW |