| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. | 2 * Copyright (C) 2004, 2006 Apple Computer, Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "wtf/PassRefPtr.h" | 34 #include "wtf/PassRefPtr.h" |
| 35 | 35 |
| 36 namespace blink { | 36 namespace blink { |
| 37 | 37 |
| 38 class GraphicsContext; | 38 class GraphicsContext; |
| 39 class IntRect; | 39 class IntRect; |
| 40 class PlatformGestureEvent; | 40 class PlatformGestureEvent; |
| 41 class PlatformMouseEvent; | 41 class PlatformMouseEvent; |
| 42 class ScrollableArea; | 42 class ScrollableArea; |
| 43 | 43 |
| 44 class PLATFORM_EXPORT Scrollbar : public Widget { | 44 class PLATFORM_EXPORT Scrollbar final : public Widget { |
| 45 | |
| 46 public: | 45 public: |
| 47 static PassRefPtr<Scrollbar> create(ScrollableArea*, ScrollbarOrientation); | 46 static PassRefPtr<Scrollbar> create(ScrollableArea*, ScrollbarOrientation); |
| 48 | 47 |
| 49 virtual ~Scrollbar(); | 48 virtual ~Scrollbar(); |
| 50 | 49 |
| 51 int x() const { return Widget::x(); } | |
| 52 int y() const { return Widget::y(); } | |
| 53 int width() const { return Widget::width(); } | |
| 54 int height() const { return Widget::height(); } | |
| 55 IntSize size() const { return Widget::size(); } | |
| 56 IntPoint location() const { return Widget::location(); } | |
| 57 | |
| 58 Widget* parent() const { return Widget::parent(); } | |
| 59 Widget* root() const { return Widget::root(); } | |
| 60 | |
| 61 void setFrameRect(const IntRect& r) { Widget::setFrameRect(r); } | |
| 62 IntRect frameRect() const { return Widget::frameRect(); } | |
| 63 | |
| 64 void invalidate() { Widget::invalidate(); } | |
| 65 void invalidateRect(const IntRect&); | 50 void invalidateRect(const IntRect&); |
| 66 | 51 |
| 67 ScrollbarOverlayStyle scrollbarOverlayStyle() const; | 52 ScrollbarOverlayStyle scrollbarOverlayStyle() const; |
| 68 void getTickmarks(Vector<IntRect>&) const; | 53 void getTickmarks(Vector<IntRect>&) const; |
| 69 bool isScrollableAreaActive() const; | 54 bool isScrollableAreaActive() const; |
| 70 bool isScrollViewScrollbar() const; | |
| 71 | 55 |
| 72 IntPoint convertFromContainingWindow(const IntPoint& windowPoint) { return W
idget::convertFromContainingWindow(windowPoint); } | |
| 73 | |
| 74 bool isCustomScrollbar() const { return false; } | |
| 75 ScrollbarOrientation orientation() const { return m_orientation; } | 56 ScrollbarOrientation orientation() const { return m_orientation; } |
| 76 bool isLeftSideVerticalScrollbar() const; | 57 bool isLeftSideVerticalScrollbar() const; |
| 77 | 58 |
| 78 int value() const { return lroundf(m_currentPos); } | 59 int value() const { return lroundf(m_currentPos); } |
| 79 float currentPos() const { return m_currentPos; } | 60 float currentPos() const { return m_currentPos; } |
| 80 int visibleSize() const { return m_visibleSize; } | 61 int visibleSize() const { return m_visibleSize; } |
| 81 int totalSize() const { return m_totalSize; } | 62 int totalSize() const { return m_totalSize; } |
| 82 int maximum() const { return m_totalSize - m_visibleSize; } | 63 int maximum() const { return m_totalSize - m_visibleSize; } |
| 83 | 64 |
| 84 ScrollbarPart pressedPart() const { return m_pressedPart; } | 65 ScrollbarPart pressedPart() const { return m_pressedPart; } |
| 85 ScrollbarPart hoveredPart() const { return m_hoveredPart; } | 66 ScrollbarPart hoveredPart() const { return m_hoveredPart; } |
| 86 | 67 |
| 87 void styleChanged() { } | |
| 88 | |
| 89 bool enabled() const { return m_enabled; } | 68 bool enabled() const { return m_enabled; } |
| 90 void setEnabled(bool); | 69 void setEnabled(bool); |
| 91 | 70 |
| 92 // Called by the ScrollableArea when the scroll offset changes. | 71 // Called by the ScrollableArea when the scroll offset changes. |
| 93 void offsetDidChange(); | 72 void offsetDidChange(); |
| 94 | 73 |
| 95 void disconnectFromScrollableArea() { m_scrollableArea = 0; } | 74 void disconnectFromScrollableArea() { m_scrollableArea = 0; } |
| 96 ScrollableArea* scrollableArea() const { return m_scrollableArea; } | 75 ScrollableArea* scrollableArea() const { return m_scrollableArea; } |
| 97 | 76 |
| 98 int pressedPos() const { return m_pressedPos; } | 77 int pressedPos() const { return m_pressedPos; } |
| 99 | 78 |
| 100 virtual void setHoveredPart(ScrollbarPart); | 79 void setHoveredPart(ScrollbarPart); |
| 101 virtual void setPressedPart(ScrollbarPart); | 80 void setPressedPart(ScrollbarPart); |
| 102 | 81 |
| 103 void setProportion(int visibleSize, int totalSize); | 82 void setProportion(int visibleSize, int totalSize); |
| 104 void setPressedPos(int p) { m_pressedPos = p; } | 83 void setPressedPos(int p) { m_pressedPos = p; } |
| 105 | 84 |
| 106 virtual void paint(GraphicsContext*, const IntRect& damageRect) override; | 85 virtual void paint(GraphicsContext*, const IntRect& damageRect) override; |
| 107 | 86 |
| 108 bool isOverlayScrollbar() const; | 87 bool isOverlayScrollbar() const; |
| 109 bool shouldParticipateInHitTesting(); | 88 bool shouldParticipateInHitTesting(); |
| 110 | 89 |
| 111 bool isWindowActive() const; | |
| 112 | |
| 113 bool gestureEvent(const PlatformGestureEvent&); | 90 bool gestureEvent(const PlatformGestureEvent&); |
| 114 | 91 |
| 115 // These methods are used for platform scrollbars to give :hover feedback.
They will not get called | 92 // These methods are used for platform scrollbars to give :hover feedback.
They will not get called |
| 116 // when the mouse went down in a scrollbar, since it is assumed the scrollba
r will start | 93 // when the mouse went down in a scrollbar, since it is assumed the scrollba
r will start |
| 117 // grabbing all events in that case anyway. | 94 // grabbing all events in that case anyway. |
| 118 void mouseMoved(const PlatformMouseEvent&); | 95 void mouseMoved(const PlatformMouseEvent&); |
| 119 void mouseEntered(); | 96 void mouseEntered(); |
| 120 void mouseExited(); | 97 void mouseExited(); |
| 121 | 98 |
| 122 // Used by some platform scrollbars to know when they've been released from
capture. | 99 // Used by some platform scrollbars to know when they've been released from
capture. |
| 123 void mouseUp(const PlatformMouseEvent&); | 100 void mouseUp(const PlatformMouseEvent&); |
| 124 void mouseDown(const PlatformMouseEvent&); | 101 void mouseDown(const PlatformMouseEvent&); |
| 125 | 102 |
| 126 // FIXME(sky): Remove this. | |
| 127 Scrollbar* theme() { return this; } | |
| 128 | |
| 129 bool suppressInvalidation() const { return m_suppressInvalidation; } | |
| 130 void setSuppressInvalidation(bool s) { m_suppressInvalidation = s; } | |
| 131 | |
| 132 virtual IntRect convertToContainingView(const IntRect&) const override; | 103 virtual IntRect convertToContainingView(const IntRect&) const override; |
| 133 virtual IntRect convertFromContainingView(const IntRect&) const override; | 104 virtual IntRect convertFromContainingView(const IntRect&) const override; |
| 134 | 105 |
| 135 virtual IntPoint convertToContainingView(const IntPoint&) const override; | 106 virtual IntPoint convertToContainingView(const IntPoint&) const override; |
| 136 virtual IntPoint convertFromContainingView(const IntPoint&) const override; | 107 virtual IntPoint convertFromContainingView(const IntPoint&) const override; |
| 137 | 108 |
| 138 void moveThumb(int pos); | 109 void moveThumb(int pos); |
| 139 | 110 |
| 140 bool isAlphaLocked() const { return m_isAlphaLocked; } | |
| 141 void setIsAlphaLocked(bool flag) { m_isAlphaLocked = flag; } | |
| 142 | |
| 143 static int scrollbarThickness(); | 111 static int scrollbarThickness(); |
| 144 | 112 |
| 145 void invalidateParts() | 113 void invalidateParts() |
| 146 { | 114 { |
| 147 invalidatePart(BackTrackPart); | 115 invalidatePart(BackTrackPart); |
| 148 invalidatePart(ThumbPart); | 116 invalidatePart(ThumbPart); |
| 149 invalidatePart(ForwardTrackPart); | 117 invalidatePart(ForwardTrackPart); |
| 150 } | 118 } |
| 151 | 119 |
| 152 void invalidatePart(ScrollbarPart); | 120 void invalidatePart(ScrollbarPart); |
| 153 | 121 |
| 154 static void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect); | 122 static void paintScrollCorner(GraphicsContext*, const IntRect& cornerRect); |
| 155 | 123 |
| 156 static void paintOverhangBackground(GraphicsContext*, const IntRect&, const
IntRect&, const IntRect&); | |
| 157 | |
| 158 bool shouldCenterOnThumb(const PlatformMouseEvent&); | 124 bool shouldCenterOnThumb(const PlatformMouseEvent&); |
| 159 bool shouldSnapBackToDragOrigin(const PlatformMouseEvent&); | 125 bool shouldSnapBackToDragOrigin(const PlatformMouseEvent&); |
| 160 | 126 |
| 161 // The position of the thumb relative to the track. | 127 // The position of the thumb relative to the track. |
| 162 int thumbPosition(); | 128 int thumbPosition(); |
| 163 // The length of the thumb along the axis of the scrollbar. | 129 // The length of the thumb along the axis of the scrollbar. |
| 164 int thumbLength(); | 130 int thumbLength(); |
| 165 // The position of the track relative to the scrollbar. | 131 // The position of the track relative to the scrollbar. |
| 166 int trackPosition(); | 132 int trackPosition(); |
| 167 // The length of the track along the axis of the scrollbar. | 133 // The length of the track along the axis of the scrollbar. |
| 168 int trackLength(); | 134 int trackLength(); |
| 169 | 135 |
| 170 IntRect trackRect(); | 136 IntRect trackRect(); |
| 171 IntRect thumbRect(); | 137 IntRect thumbRect(); |
| 172 int thumbThickness(); | 138 int thumbThickness(); |
| 173 | 139 |
| 174 int minimumThumbLength(); | 140 int minimumThumbLength(); |
| 175 | 141 |
| 176 void splitTrack(const IntRect& track, IntRect& startTrack, IntRect& thumb, I
ntRect& endTrack); | 142 void splitTrack(const IntRect& track, IntRect& startTrack, IntRect& thumb, I
ntRect& endTrack); |
| 177 | 143 |
| 178 void paintThumb(GraphicsContext*, const IntRect&); | 144 void paintThumb(GraphicsContext*, const IntRect&); |
| 179 | 145 |
| 180 double initialAutoscrollTimerDelay() { return 0.25; } | 146 double initialAutoscrollTimerDelay() { return 0.25; } |
| 181 double autoscrollTimerDelay() { return 0.05; } | 147 double autoscrollTimerDelay() { return 0.05; } |
| 182 | 148 |
| 183 protected: | 149 protected: |
| 184 Scrollbar(ScrollableArea*, ScrollbarOrientation); | 150 Scrollbar(ScrollableArea*, ScrollbarOrientation); |
| 185 | 151 |
| 186 void updateThumb(); | 152 void updateThumb(); |
| 187 virtual void updateThumbPosition(); | |
| 188 virtual void updateThumbProportion(); | |
| 189 | 153 |
| 190 void autoscrollTimerFired(Timer<Scrollbar>*); | 154 void autoscrollTimerFired(Timer<Scrollbar>*); |
| 191 void startTimerIfNeeded(double delay); | 155 void startTimerIfNeeded(double delay); |
| 192 void stopTimerIfNeeded(); | 156 void stopTimerIfNeeded(); |
| 193 void autoscrollPressedPart(double delay); | 157 void autoscrollPressedPart(double delay); |
| 194 ScrollDirection pressedPartScrollDirection(); | 158 ScrollDirection pressedPartScrollDirection(); |
| 195 ScrollGranularity pressedPartScrollGranularity(); | 159 ScrollGranularity pressedPartScrollGranularity(); |
| 196 | 160 |
| 197 ScrollableArea* m_scrollableArea; | 161 ScrollableArea* m_scrollableArea; |
| 198 ScrollbarOrientation m_orientation; | 162 ScrollbarOrientation m_orientation; |
| 199 | 163 |
| 200 int m_visibleSize; | 164 int m_visibleSize; |
| 201 int m_totalSize; | 165 int m_totalSize; |
| 202 float m_currentPos; | 166 float m_currentPos; |
| 203 float m_dragOrigin; | 167 float m_dragOrigin; |
| 204 | 168 |
| 205 ScrollbarPart m_hoveredPart; | 169 ScrollbarPart m_hoveredPart; |
| 206 ScrollbarPart m_pressedPart; | 170 ScrollbarPart m_pressedPart; |
| 207 int m_pressedPos; | 171 int m_pressedPos; |
| 208 float m_scrollPos; | 172 float m_scrollPos; |
| 209 int m_documentDragPos; | 173 int m_documentDragPos; |
| 210 | 174 |
| 211 bool m_enabled; | 175 bool m_enabled; |
| 212 | 176 |
| 213 Timer<Scrollbar> m_scrollTimer; | 177 Timer<Scrollbar> m_scrollTimer; |
| 214 bool m_overlapsResizer; | 178 bool m_overlapsResizer; |
| 215 | 179 |
| 216 bool m_suppressInvalidation; | |
| 217 | |
| 218 bool m_isAlphaLocked; | |
| 219 | |
| 220 private: | 180 private: |
| 221 virtual bool isScrollbar() const override { return true; } | 181 virtual bool isScrollbar() const override { return true; } |
| 222 | 182 |
| 223 float scrollableAreaCurrentPos() const; | 183 float scrollableAreaCurrentPos() const; |
| 224 }; | 184 }; |
| 225 | 185 |
| 226 DEFINE_TYPE_CASTS(Scrollbar, Widget, widget, widget->isScrollbar(), widget.isScr
ollbar()); | 186 DEFINE_TYPE_CASTS(Scrollbar, Widget, widget, widget->isScrollbar(), widget.isScr
ollbar()); |
| 227 | 187 |
| 228 } // namespace blink | 188 } // namespace blink |
| 229 | 189 |
| 230 #endif // Scrollbar_h | 190 #endif // Scrollbar_h |
| OLD | NEW |