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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 , m_currentPosY(0) | 46 , m_currentPosY(0) |
47 { | 47 { |
48 } | 48 } |
49 | 49 |
50 ScrollAnimator::~ScrollAnimator() | 50 ScrollAnimator::~ScrollAnimator() |
51 { | 51 { |
52 } | 52 } |
53 | 53 |
54 bool ScrollAnimator::scroll(ScrollbarOrientation orientation, ScrollGranularity,
float step, float delta) | 54 bool ScrollAnimator::scroll(ScrollbarOrientation orientation, ScrollGranularity,
float step, float delta) |
55 { | 55 { |
56 float* currentPos = (orientation == HorizontalScrollbar) ? &m_currentPosX :
&m_currentPosY; | 56 float& currentPos = (orientation == HorizontalScrollbar) ? m_currentPosX : m
_currentPosY; |
57 float newPos = clampScrollPosition(orientation, *currentPos + step * delta); | 57 float newPos = clampScrollPosition(orientation, currentPos + step * delta); |
58 float scrolledDelta = *currentPos - newPos; | 58 if (currentPos == newPos) |
59 if (*currentPos == newPos) | |
60 return false; | 59 return false; |
61 *currentPos = newPos; | 60 currentPos = newPos; |
62 | 61 |
63 notifyPositionChanged( | 62 notifyPositionChanged(); |
64 orientation == HorizontalScrollbar ? FloatSize(scrolledDelta, 0) : Float
Size(0, scrolledDelta)); | |
65 | 63 |
66 return true; | 64 return true; |
67 } | 65 } |
68 | 66 |
69 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) | 67 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) |
70 { | 68 { |
71 FloatSize delta = FloatSize(offset.x() - m_currentPosX, offset.y() - m_curre
ntPosY); | |
72 m_currentPosX = offset.x(); | 69 m_currentPosX = offset.x(); |
73 m_currentPosY = offset.y(); | 70 m_currentPosY = offset.y(); |
74 notifyPositionChanged(delta); | 71 notifyPositionChanged(); |
75 } | 72 } |
76 | 73 |
77 bool ScrollAnimator::handleWheelEvent(const PlatformWheelEvent& e) | 74 bool ScrollAnimator::handleWheelEvent(const PlatformWheelEvent& e) |
78 { | 75 { |
79 bool canScrollX = m_scrollableArea->userInputScrollable(HorizontalScrollbar)
; | 76 bool canScrollX = m_scrollableArea->userInputScrollable(HorizontalScrollbar)
; |
80 bool canScrollY = m_scrollableArea->userInputScrollable(VerticalScrollbar); | 77 bool canScrollY = m_scrollableArea->userInputScrollable(VerticalScrollbar); |
81 | 78 |
82 // Accept the event if we are scrollable in that direction and can still | 79 // Accept the event if we are scrollable in that direction and can still |
83 // scroll any further. | 80 // scroll any further. |
84 float deltaX = canScrollX ? e.deltaX() : 0; | 81 float deltaX = canScrollX ? e.deltaX() : 0; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 { | 126 { |
130 m_currentPosX = position.x(); | 127 m_currentPosX = position.x(); |
131 m_currentPosY = position.y(); | 128 m_currentPosY = position.y(); |
132 } | 129 } |
133 | 130 |
134 FloatPoint ScrollAnimator::currentPosition() const | 131 FloatPoint ScrollAnimator::currentPosition() const |
135 { | 132 { |
136 return FloatPoint(m_currentPosX, m_currentPosY); | 133 return FloatPoint(m_currentPosX, m_currentPosY); |
137 } | 134 } |
138 | 135 |
139 void ScrollAnimator::notifyPositionChanged(const FloatSize&) | 136 void ScrollAnimator::notifyPositionChanged() |
140 { | 137 { |
141 m_scrollableArea->setScrollOffsetFromAnimation(IntPoint(m_currentPosX, m_cur
rentPosY)); | 138 m_scrollableArea->setScrollOffsetFromAnimation(IntPoint(m_currentPosX, m_cur
rentPosY)); |
142 } | 139 } |
143 | 140 |
144 float ScrollAnimator::clampScrollPosition(ScrollbarOrientation orientation, floa
t pos) | 141 float ScrollAnimator::clampScrollPosition(ScrollbarOrientation orientation, floa
t pos) |
145 { | 142 { |
146 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation); | 143 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation); |
147 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation); | 144 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation); |
148 return std::max(std::min(pos, maxScrollPos), minScrollPos); | 145 return std::max(std::min(pos, maxScrollPos), minScrollPos); |
149 } | 146 } |
150 | 147 |
151 } // namespace WebCore | 148 } // namespace WebCore |
OLD | NEW |