| 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 SKY_ENGINE_PLATFORM_SCROLL_SCROLLABLEAREA_H_ | |
| 27 #define SKY_ENGINE_PLATFORM_SCROLL_SCROLLABLEAREA_H_ | |
| 28 | |
| 29 #include "sky/engine/platform/PlatformExport.h" | |
| 30 #include "sky/engine/platform/scroll/ScrollAnimator.h" | |
| 31 #include "sky/engine/platform/scroll/Scrollbar.h" | |
| 32 #include "sky/engine/wtf/Noncopyable.h" | |
| 33 #include "sky/engine/wtf/Vector.h" | |
| 34 | |
| 35 namespace blink { | |
| 36 | |
| 37 class FloatPoint; | |
| 38 class HostWindow; | |
| 39 class ScrollAnimator; | |
| 40 | |
| 41 enum ScrollBehavior { | |
| 42 ScrollBehaviorAuto, | |
| 43 ScrollBehaviorInstant, | |
| 44 ScrollBehaviorSmooth, | |
| 45 }; | |
| 46 | |
| 47 enum IncludeScrollbarsInRect { | |
| 48 ExcludeScrollbars, | |
| 49 IncludeScrollbars, | |
| 50 }; | |
| 51 | |
| 52 class PLATFORM_EXPORT ScrollableArea { | |
| 53 WTF_MAKE_NONCOPYABLE(ScrollableArea); | |
| 54 public: | |
| 55 static int pixelsPerLineStep(); | |
| 56 static float minFractionToStepWhenPaging(); | |
| 57 static int maxOverlapBetweenPages(); | |
| 58 | |
| 59 // The window that hosts the ScrollView. The ScrollView will communicate scr
olls and repaints to the | |
| 60 // host window in the window's coordinate space. | |
| 61 virtual HostWindow* hostWindow() const = 0; | |
| 62 | |
| 63 bool scroll(ScrollDirection, ScrollGranularity, float delta = 1); | |
| 64 void scrollToOffsetWithoutAnimation(const FloatPoint&); | |
| 65 void scrollToOffsetWithoutAnimation(ScrollbarOrientation, float offset); | |
| 66 | |
| 67 static bool scrollBehaviorFromString(const String&, ScrollBehavior&); | |
| 68 | |
| 69 // Functions for controlling if you can scroll past the end of the document. | |
| 70 bool constrainsScrollingToContentEdge() const { return m_constrainsScrolling
ToContentEdge; } | |
| 71 void setConstrainsScrollingToContentEdge(bool constrainsScrollingToContentEd
ge) { m_constrainsScrollingToContentEdge = constrainsScrollingToContentEdge; } | |
| 72 | |
| 73 void setVerticalScrollElasticity(ScrollElasticity scrollElasticity) { m_vert
icalScrollElasticity = scrollElasticity; } | |
| 74 ScrollElasticity verticalScrollElasticity() const { return static_cast<Scrol
lElasticity>(m_verticalScrollElasticity); } | |
| 75 | |
| 76 void setHorizontalScrollElasticity(ScrollElasticity scrollElasticity) { m_ho
rizontalScrollElasticity = scrollElasticity; } | |
| 77 ScrollElasticity horizontalScrollElasticity() const { return static_cast<Scr
ollElasticity>(m_horizontalScrollElasticity); } | |
| 78 | |
| 79 void contentAreaDidShow() const; | |
| 80 void contentAreaDidHide() const; | |
| 81 | |
| 82 void finishCurrentScrollAnimations() const; | |
| 83 | |
| 84 void didAddScrollbar(Scrollbar*, ScrollbarOrientation); | |
| 85 void willRemoveScrollbar(Scrollbar*, ScrollbarOrientation); | |
| 86 | |
| 87 void contentsResized(); | |
| 88 | |
| 89 bool hasOverlayScrollbars() const; | |
| 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_animators ? m_anim
ators->scrollAnimator.get() : 0; } | |
| 96 | |
| 97 const IntPoint& scrollOrigin() const { return m_scrollOrigin; } | |
| 98 bool scrollOriginChanged() const { return m_scrollOriginChanged; } | |
| 99 | |
| 100 // FIXME(bokan): Meaningless name, rename to isActiveFocus | |
| 101 virtual bool isActive() const = 0; | |
| 102 virtual int scrollSize(ScrollbarOrientation) const = 0; | |
| 103 | |
| 104 // Convert points and rects between the scrollbar and its containing view. | |
| 105 // The client needs to implement these in order to be aware of layout effect
s | |
| 106 // like CSS transforms. | |
| 107 virtual IntRect convertFromScrollbarToContainingView(const Scrollbar*, const
IntRect&) const = 0; | |
| 108 virtual IntRect convertFromContainingViewToScrollbar(const Scrollbar*, const
IntRect&) const = 0; | |
| 109 virtual IntPoint convertFromScrollbarToContainingView(const Scrollbar*, cons
t IntPoint&) const = 0; | |
| 110 virtual IntPoint convertFromContainingViewToScrollbar(const Scrollbar*, cons
t IntPoint&) const = 0; | |
| 111 | |
| 112 virtual Scrollbar* horizontalScrollbar() const = 0; | |
| 113 virtual Scrollbar* verticalScrollbar() const = 0; | |
| 114 | |
| 115 // scrollPosition is relative to the scrollOrigin. i.e. If the page is RTL | |
| 116 // then scrollPosition will be negative. | |
| 117 virtual IntPoint scrollPosition() const = 0; | |
| 118 virtual IntPoint minimumScrollPosition() const = 0; | |
| 119 virtual IntPoint maximumScrollPosition() const = 0; | |
| 120 | |
| 121 virtual IntSize contentsSize() const = 0; | |
| 122 | |
| 123 bool shouldSuspendScrollAnimations() const { return true; } | |
| 124 | |
| 125 IntPoint clampScrollPosition(const IntPoint&) const; | |
| 126 | |
| 127 // Returns true if the GraphicsLayer tree needs to be rebuilt. | |
| 128 virtual bool updateAfterCompositingChange() = 0; | |
| 129 | |
| 130 virtual bool userInputScrollable(ScrollbarOrientation) const = 0; | |
| 131 virtual bool shouldPlaceVerticalScrollbarOnLeft() const = 0; | |
| 132 | |
| 133 int scrollPosition(ScrollbarOrientation orientation) { return orientation ==
HorizontalScrollbar ? scrollPosition().x() : scrollPosition().y(); } | |
| 134 int minimumScrollPosition(ScrollbarOrientation orientation) { return orienta
tion == HorizontalScrollbar ? minimumScrollPosition().x() : minimumScrollPositio
n().y(); } | |
| 135 int maximumScrollPosition(ScrollbarOrientation orientation) { return orienta
tion == HorizontalScrollbar ? maximumScrollPosition().x() : maximumScrollPositio
n().y(); } | |
| 136 int clampScrollPosition(ScrollbarOrientation orientation, int pos) { return
std::max(std::min(pos, maximumScrollPosition(orientation)), minimumScrollPositi
on(orientation)); } | |
| 137 | |
| 138 protected: | |
| 139 ScrollableArea(); | |
| 140 virtual ~ScrollableArea(); | |
| 141 | |
| 142 void setScrollOrigin(const IntPoint&); | |
| 143 void resetScrollOriginChanged() { m_scrollOriginChanged = false; } | |
| 144 | |
| 145 private: | |
| 146 void scrollPositionChanged(const IntPoint&); | |
| 147 | |
| 148 // NOTE: Only called from the ScrollAnimator. | |
| 149 friend class ScrollAnimator; | |
| 150 void setScrollOffsetFromAnimation(const IntPoint&); | |
| 151 | |
| 152 // This function should be overriden by subclasses to perform the actual | |
| 153 // scroll of the content. | |
| 154 virtual void setScrollOffset(const IntPoint&) = 0; | |
| 155 | |
| 156 int lineStep(ScrollbarOrientation) const; | |
| 157 int documentStep(ScrollbarOrientation) const; | |
| 158 virtual int pageStep(ScrollbarOrientation) const = 0; | |
| 159 float pixelStep(ScrollbarOrientation) const; | |
| 160 | |
| 161 struct ScrollableAreaAnimators { | |
| 162 OwnPtr<ScrollAnimator> scrollAnimator; | |
| 163 }; | |
| 164 | |
| 165 mutable OwnPtr<ScrollableAreaAnimators> m_animators; | |
| 166 unsigned m_constrainsScrollingToContentEdge : 1; | |
| 167 | |
| 168 unsigned m_verticalScrollElasticity : 2; // ScrollElasticity | |
| 169 unsigned m_horizontalScrollElasticity : 2; // ScrollElasticity | |
| 170 | |
| 171 unsigned m_scrollOriginChanged : 1; | |
| 172 | |
| 173 // There are 8 possible combinations of writing mode and direction. Scroll o
rigin will be non-zero in the x or y axis | |
| 174 // if there is any reversed direction or writing-mode. The combinations are: | |
| 175 // writing-mode / direction scrollOrigin.x() set scrollOrigin.y() set | |
| 176 // horizontal-tb / ltr NO NO | |
| 177 // horizontal-tb / rtl YES NO | |
| 178 // horizontal-bt / ltr NO YES | |
| 179 // horizontal-bt / rtl YES YES | |
| 180 // vertical-lr / ltr NO NO | |
| 181 // vertical-lr / rtl NO YES | |
| 182 // vertical-rl / ltr YES NO | |
| 183 // vertical-rl / rtl YES YES | |
| 184 IntPoint m_scrollOrigin; | |
| 185 }; | |
| 186 | |
| 187 } // namespace blink | |
| 188 | |
| 189 #endif // SKY_ENGINE_PLATFORM_SCROLL_SCROLLABLEAREA_H_ | |
| OLD | NEW |