OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google 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 are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 13 matching lines...) Expand all Loading... |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "platform/scroll/ScrollAnimatorBase.h" | 31 #include "platform/scroll/ScrollAnimatorBase.h" |
32 | 32 |
33 #include "platform/RuntimeEnabledFeatures.h" | 33 #include "platform/RuntimeEnabledFeatures.h" |
34 #include "platform/geometry/FloatPoint.h" | |
35 #include "platform/scroll/ScrollableArea.h" | 34 #include "platform/scroll/ScrollableArea.h" |
36 #include "wtf/MathExtras.h" | 35 #include "wtf/MathExtras.h" |
37 | 36 |
38 namespace blink { | 37 namespace blink { |
39 | 38 |
40 ScrollAnimatorBase::ScrollAnimatorBase(ScrollableArea* scrollableArea) | 39 ScrollAnimatorBase::ScrollAnimatorBase(ScrollableArea* scrollableArea) |
41 : m_scrollableArea(scrollableArea) {} | 40 : m_scrollableArea(scrollableArea) {} |
42 | 41 |
43 ScrollAnimatorBase::~ScrollAnimatorBase() {} | 42 ScrollAnimatorBase::~ScrollAnimatorBase() {} |
44 | 43 |
45 FloatSize ScrollAnimatorBase::computeDeltaToConsume( | 44 ScrollOffset ScrollAnimatorBase::computeDeltaToConsume( |
46 const FloatSize& delta) const { | 45 const ScrollOffset& delta) const { |
47 FloatPoint newPos = | 46 ScrollOffset newPos = |
48 toFloatPoint(m_scrollableArea->clampScrollPosition(m_currentPos + delta)); | 47 m_scrollableArea->clampScrollOffset(m_currentOffset + delta); |
49 return newPos - m_currentPos; | 48 return newPos - m_currentOffset; |
50 } | 49 } |
51 | 50 |
52 ScrollResult ScrollAnimatorBase::userScroll(ScrollGranularity, | 51 ScrollResult ScrollAnimatorBase::userScroll(ScrollGranularity, |
53 const FloatSize& delta) { | 52 const ScrollOffset& delta) { |
54 FloatSize consumedDelta = computeDeltaToConsume(delta); | 53 ScrollOffset consumedDelta = computeDeltaToConsume(delta); |
55 FloatPoint newPos = m_currentPos + consumedDelta; | 54 ScrollOffset newPos = m_currentOffset + consumedDelta; |
56 if (m_currentPos == newPos) | 55 if (m_currentOffset == newPos) |
57 return ScrollResult(false, false, delta.width(), delta.height()); | 56 return ScrollResult(false, false, delta.width(), delta.height()); |
58 | 57 |
59 m_currentPos = newPos; | 58 m_currentOffset = newPos; |
60 | 59 |
61 notifyPositionChanged(); | 60 notifyOffsetChanged(); |
62 | 61 |
63 return ScrollResult(consumedDelta.width(), consumedDelta.height(), | 62 return ScrollResult(consumedDelta.width(), consumedDelta.height(), |
64 delta.width() - consumedDelta.width(), | 63 delta.width() - consumedDelta.width(), |
65 delta.height() - consumedDelta.height()); | 64 delta.height() - consumedDelta.height()); |
66 } | 65 } |
67 | 66 |
68 void ScrollAnimatorBase::scrollToOffsetWithoutAnimation( | 67 void ScrollAnimatorBase::scrollToOffsetWithoutAnimation( |
69 const FloatPoint& offset) { | 68 const ScrollOffset& offset) { |
70 m_currentPos = offset; | 69 m_currentOffset = offset; |
71 notifyPositionChanged(); | 70 notifyOffsetChanged(); |
72 } | 71 } |
73 | 72 |
74 void ScrollAnimatorBase::setCurrentPosition(const FloatPoint& position) { | 73 void ScrollAnimatorBase::setCurrentOffset(const ScrollOffset& offset) { |
75 m_currentPos = position; | 74 m_currentOffset = offset; |
76 } | 75 } |
77 | 76 |
78 FloatPoint ScrollAnimatorBase::currentPosition() const { | 77 ScrollOffset ScrollAnimatorBase::currentOffset() const { |
79 return m_currentPos; | 78 return m_currentOffset; |
80 } | 79 } |
81 | 80 |
82 void ScrollAnimatorBase::notifyPositionChanged() { | 81 void ScrollAnimatorBase::notifyOffsetChanged() { |
83 scrollPositionChanged(m_currentPos, UserScroll); | 82 scrollOffsetChanged(m_currentOffset, UserScroll); |
84 } | 83 } |
85 | 84 |
86 DEFINE_TRACE(ScrollAnimatorBase) { | 85 DEFINE_TRACE(ScrollAnimatorBase) { |
87 visitor->trace(m_scrollableArea); | 86 visitor->trace(m_scrollableArea); |
88 ScrollAnimatorCompositorCoordinator::trace(visitor); | 87 ScrollAnimatorCompositorCoordinator::trace(visitor); |
89 } | 88 } |
90 | 89 |
91 } // namespace blink | 90 } // namespace blink |
OLD | NEW |