| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2008, 2011 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 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 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 ScrollableArea_h | |
| 27 #define ScrollableArea_h | |
| 28 | |
| 29 #include "core/platform/Scrollbar.h" | |
| 30 #include "wtf/Vector.h" | |
| 31 | |
| 32 namespace WebCore { | |
| 33 | |
| 34 class FloatPoint; | |
| 35 class GraphicsContext; | |
| 36 class GraphicsLayer; | |
| 37 class PlatformGestureEvent; | |
| 38 class PlatformWheelEvent; | |
| 39 class ScrollAnimator; | |
| 40 | |
| 41 class ScrollableArea { | |
| 42 public: | |
| 43 static int pixelsPerLineStep(); | |
| 44 static float minFractionToStepWhenPaging(); | |
| 45 static int maxOverlapBetweenPages(); | |
| 46 | |
| 47 bool scroll(ScrollDirection, ScrollGranularity, float multiplier = 1); | |
| 48 void scrollToOffsetWithoutAnimation(const FloatPoint&); | |
| 49 void scrollToOffsetWithoutAnimation(ScrollbarOrientation, float offset); | |
| 50 | |
| 51 // Should be called when the scroll position changes externally, for example
if the scroll layer position | |
| 52 // is updated on the scrolling thread and we need to notify the main thread. | |
| 53 void notifyScrollPositionChanged(const IntPoint&); | |
| 54 | |
| 55 bool handleWheelEvent(const PlatformWheelEvent&); | |
| 56 | |
| 57 // Functions for controlling if you can scroll past the end of the document. | |
| 58 bool constrainsScrollingToContentEdge() const { return m_constrainsScrolling
ToContentEdge; } | |
| 59 void setConstrainsScrollingToContentEdge(bool constrainsScrollingToContentEd
ge) { m_constrainsScrollingToContentEdge = constrainsScrollingToContentEdge; } | |
| 60 | |
| 61 void setVerticalScrollElasticity(ScrollElasticity scrollElasticity) { m_vert
icalScrollElasticity = scrollElasticity; } | |
| 62 ScrollElasticity verticalScrollElasticity() const { return static_cast<Scrol
lElasticity>(m_verticalScrollElasticity); } | |
| 63 | |
| 64 void setHorizontalScrollElasticity(ScrollElasticity scrollElasticity) { m_ho
rizontalScrollElasticity = scrollElasticity; } | |
| 65 ScrollElasticity horizontalScrollElasticity() const { return static_cast<Scr
ollElasticity>(m_horizontalScrollElasticity); } | |
| 66 | |
| 67 bool inLiveResize() const { return m_inLiveResize; } | |
| 68 void willStartLiveResize(); | |
| 69 void willEndLiveResize(); | |
| 70 | |
| 71 void contentAreaWillPaint() const; | |
| 72 void mouseEnteredContentArea() const; | |
| 73 void mouseExitedContentArea() const; | |
| 74 void mouseMovedInContentArea() const; | |
| 75 void mouseEnteredScrollbar(Scrollbar*) const; | |
| 76 void mouseExitedScrollbar(Scrollbar*) const; | |
| 77 void contentAreaDidShow() const; | |
| 78 void contentAreaDidHide() const; | |
| 79 | |
| 80 void finishCurrentScrollAnimations() const; | |
| 81 | |
| 82 virtual void didAddScrollbar(Scrollbar*, ScrollbarOrientation); | |
| 83 virtual void willRemoveScrollbar(Scrollbar*, ScrollbarOrientation); | |
| 84 | |
| 85 virtual void contentsResized(); | |
| 86 | |
| 87 bool hasOverlayScrollbars() const; | |
| 88 void setScrollbarOverlayStyle(ScrollbarOverlayStyle); | |
| 89 ScrollbarOverlayStyle scrollbarOverlayStyle() const { return static_cast<Scr
ollbarOverlayStyle>(m_scrollbarOverlayStyle); } | |
| 90 | |
| 91 // This getter will create a ScrollAnimator if it doesn't already exist. | |
| 92 ScrollAnimator* scrollAnimator() const; | |
| 93 | |
| 94 // This getter will return null if the ScrollAnimator hasn't been created ye
t. | |
| 95 ScrollAnimator* existingScrollAnimator() const { return m_scrollAnimator.get
(); } | |
| 96 | |
| 97 const IntPoint& scrollOrigin() const { return m_scrollOrigin; } | |
| 98 bool scrollOriginChanged() const { return m_scrollOriginChanged; } | |
| 99 | |
| 100 virtual bool isActive() const = 0; | |
| 101 virtual int scrollSize(ScrollbarOrientation) const = 0; | |
| 102 virtual void invalidateScrollbar(Scrollbar*, const IntRect&); | |
| 103 virtual bool isScrollCornerVisible() const = 0; | |
| 104 virtual IntRect scrollCornerRect() const = 0; | |
| 105 virtual void invalidateScrollCorner(const IntRect&); | |
| 106 virtual void getTickmarks(Vector<IntRect>&) const { } | |
| 107 | |
| 108 // Convert points and rects between the scrollbar and its containing view. | |
| 109 // The client needs to implement these in order to be aware of layout effect
s | |
| 110 // like CSS transforms. | |
| 111 virtual IntRect convertFromScrollbarToContainingView(const Scrollbar* scroll
bar, const IntRect& scrollbarRect) const | |
| 112 { | |
| 113 return scrollbar->Widget::convertToContainingView(scrollbarRect); | |
| 114 } | |
| 115 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar* scroll
bar, const IntRect& parentRect) const | |
| 116 { | |
| 117 return scrollbar->Widget::convertFromContainingView(parentRect); | |
| 118 } | |
| 119 virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar* scrol
lbar, const IntPoint& scrollbarPoint) const | |
| 120 { | |
| 121 return scrollbar->Widget::convertToContainingView(scrollbarPoint); | |
| 122 } | |
| 123 virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar* scrol
lbar, const IntPoint& parentPoint) const | |
| 124 { | |
| 125 return scrollbar->Widget::convertFromContainingView(parentPoint); | |
| 126 } | |
| 127 | |
| 128 virtual Scrollbar* horizontalScrollbar() const { return 0; } | |
| 129 virtual Scrollbar* verticalScrollbar() const { return 0; } | |
| 130 | |
| 131 // scrollPosition is relative to the scrollOrigin. i.e. If the page is RTL | |
| 132 // then scrollPosition will be negative. | |
| 133 virtual IntPoint scrollPosition() const = 0; | |
| 134 virtual IntPoint minimumScrollPosition() const = 0; | |
| 135 virtual IntPoint maximumScrollPosition() const = 0; | |
| 136 | |
| 137 enum IncludeScrollbarsInRect { ExcludeScrollbars, IncludeScrollbars }; | |
| 138 virtual IntRect visibleContentRect(IncludeScrollbarsInRect = ExcludeScrollba
rs) const; | |
| 139 virtual int visibleHeight() const = 0; | |
| 140 virtual int visibleWidth() const = 0; | |
| 141 virtual IntSize contentsSize() const = 0; | |
| 142 virtual IntSize overhangAmount() const { return IntSize(); } | |
| 143 virtual IntPoint lastKnownMousePosition() const { return IntPoint(); } | |
| 144 | |
| 145 virtual bool shouldSuspendScrollAnimations() const { return true; } | |
| 146 virtual void scrollbarStyleChanged(int /*newStyle*/, bool /*forceUpdate*/) {
} | |
| 147 | |
| 148 virtual bool scrollbarsCanBeActive() const = 0; | |
| 149 | |
| 150 // Note that this only returns scrollable areas that can actually be scrolle
d. | |
| 151 virtual ScrollableArea* enclosingScrollableArea() const = 0; | |
| 152 | |
| 153 // Returns the bounding box of this scrollable area, in the coordinate syste
m of the enclosing scroll view. | |
| 154 virtual IntRect scrollableAreaBoundingBox() const = 0; | |
| 155 | |
| 156 virtual bool shouldRubberBandInDirection(ScrollDirection) const { return tru
e; } | |
| 157 virtual bool isRubberBandInProgress() const { return false; } | |
| 158 | |
| 159 virtual bool scrollAnimatorEnabled() const { return false; } | |
| 160 | |
| 161 // NOTE: Only called from Internals for testing. | |
| 162 void setScrollOffsetFromInternals(const IntPoint&); | |
| 163 | |
| 164 IntPoint clampScrollPosition(const IntPoint&) const; | |
| 165 | |
| 166 // Let subclasses provide a way of asking for and servicing scroll | |
| 167 // animations. | |
| 168 virtual bool scheduleAnimation() { return false; } | |
| 169 void serviceScrollAnimations(); | |
| 170 | |
| 171 virtual bool usesCompositedScrolling() const { return false; } | |
| 172 virtual void updateNeedsCompositedScrolling() { } | |
| 173 virtual void updateHasVisibleNonLayerContent() { } | |
| 174 | |
| 175 virtual bool userInputScrollable(ScrollbarOrientation) const = 0; | |
| 176 virtual bool shouldPlaceVerticalScrollbarOnLeft() const = 0; | |
| 177 | |
| 178 // Convenience functions | |
| 179 int scrollPosition(ScrollbarOrientation orientation) { return orientation ==
HorizontalScrollbar ? scrollPosition().x() : scrollPosition().y(); } | |
| 180 int minimumScrollPosition(ScrollbarOrientation orientation) { return orienta
tion == HorizontalScrollbar ? minimumScrollPosition().x() : minimumScrollPositio
n().y(); } | |
| 181 int maximumScrollPosition(ScrollbarOrientation orientation) { return orienta
tion == HorizontalScrollbar ? maximumScrollPosition().x() : maximumScrollPositio
n().y(); } | |
| 182 int clampScrollPosition(ScrollbarOrientation orientation, int pos) { return
std::max(std::min(pos, maximumScrollPosition(orientation)), minimumScrollPositi
on(orientation)); } | |
| 183 | |
| 184 protected: | |
| 185 ScrollableArea(); | |
| 186 virtual ~ScrollableArea(); | |
| 187 | |
| 188 void setScrollOrigin(const IntPoint&); | |
| 189 void resetScrollOriginChanged() { m_scrollOriginChanged = false; } | |
| 190 | |
| 191 virtual void invalidateScrollbarRect(Scrollbar*, const IntRect&) = 0; | |
| 192 virtual void invalidateScrollCornerRect(const IntRect&) = 0; | |
| 193 | |
| 194 friend class ScrollingCoordinator; | |
| 195 virtual GraphicsLayer* layerForScrolling() const { return 0; } | |
| 196 virtual GraphicsLayer* layerForHorizontalScrollbar() const { return 0; } | |
| 197 virtual GraphicsLayer* layerForVerticalScrollbar() const { return 0; } | |
| 198 virtual GraphicsLayer* layerForScrollCorner() const { return 0; } | |
| 199 bool hasLayerForHorizontalScrollbar() const; | |
| 200 bool hasLayerForVerticalScrollbar() const; | |
| 201 bool hasLayerForScrollCorner() const; | |
| 202 | |
| 203 private: | |
| 204 void scrollPositionChanged(const IntPoint&); | |
| 205 | |
| 206 // NOTE: Only called from the ScrollAnimator. | |
| 207 friend class ScrollAnimator; | |
| 208 void setScrollOffsetFromAnimation(const IntPoint&); | |
| 209 | |
| 210 // This function should be overriden by subclasses to perform the actual | |
| 211 // scroll of the content. | |
| 212 virtual void setScrollOffset(const IntPoint&) = 0; | |
| 213 | |
| 214 virtual int lineStep(ScrollbarOrientation) const; | |
| 215 virtual int pageStep(ScrollbarOrientation) const = 0; | |
| 216 virtual int documentStep(ScrollbarOrientation) const; | |
| 217 virtual float pixelStep(ScrollbarOrientation) const; | |
| 218 | |
| 219 mutable OwnPtr<ScrollAnimator> m_scrollAnimator; | |
| 220 unsigned m_constrainsScrollingToContentEdge : 1; | |
| 221 | |
| 222 unsigned m_inLiveResize : 1; | |
| 223 | |
| 224 unsigned m_verticalScrollElasticity : 2; // ScrollElasticity | |
| 225 unsigned m_horizontalScrollElasticity : 2; // ScrollElasticity | |
| 226 | |
| 227 unsigned m_scrollbarOverlayStyle : 2; // ScrollbarOverlayStyle | |
| 228 | |
| 229 unsigned m_scrollOriginChanged : 1; | |
| 230 | |
| 231 // There are 8 possible combinations of writing mode and direction. Scroll o
rigin will be non-zero in the x or y axis | |
| 232 // if there is any reversed direction or writing-mode. The combinations are: | |
| 233 // writing-mode / direction scrollOrigin.x() set scrollOrigin.y() set | |
| 234 // horizontal-tb / ltr NO NO | |
| 235 // horizontal-tb / rtl YES NO | |
| 236 // horizontal-bt / ltr NO YES | |
| 237 // horizontal-bt / rtl YES YES | |
| 238 // vertical-lr / ltr NO NO | |
| 239 // vertical-lr / rtl NO YES | |
| 240 // vertical-rl / ltr YES NO | |
| 241 // vertical-rl / rtl YES YES | |
| 242 IntPoint m_scrollOrigin; | |
| 243 }; | |
| 244 | |
| 245 } // namespace WebCore | |
| 246 | |
| 247 #endif // ScrollableArea_h | |
| OLD | NEW |