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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 } | 47 } |
48 | 48 |
49 ScrollAnimator::~ScrollAnimator() | 49 ScrollAnimator::~ScrollAnimator() |
50 { | 50 { |
51 } | 51 } |
52 | 52 |
53 ScrollResultOneDimensional ScrollAnimator::scroll(ScrollbarOrientation orientati
on, ScrollGranularity, float step, float delta) | 53 ScrollResultOneDimensional ScrollAnimator::scroll(ScrollbarOrientation orientati
on, ScrollGranularity, float step, float delta) |
54 { | 54 { |
55 float& currentPos = (orientation == HorizontalScrollbar) ? m_currentPosX : m
_currentPosY; | 55 float& currentPos = (orientation == HorizontalScrollbar) ? m_currentPosX : m
_currentPosY; |
56 float newPos = clampScrollPosition(orientation, currentPos + step * delta); | 56 float newPos = clampScrollPosition(orientation, currentPos + step * delta); |
| 57 |
57 if (currentPos == newPos) | 58 if (currentPos == newPos) |
58 return ScrollResultOneDimensional(false); | 59 return ScrollResultOneDimensional(false, delta); |
59 | 60 |
60 float usedDelta = (newPos - currentPos) / step; | 61 float usedDelta = (newPos - currentPos) / step; |
61 currentPos = newPos; | 62 currentPos = newPos; |
62 | 63 |
63 notifyPositionChanged(); | 64 notifyPositionChanged(); |
64 | 65 |
65 return ScrollResultOneDimensional(true, delta - usedDelta); | 66 return ScrollResultOneDimensional(true, delta - usedDelta); |
66 } | 67 } |
67 | 68 |
68 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) | 69 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) |
69 { | 70 { |
70 m_currentPosX = offset.x(); | 71 m_currentPosX = offset.x(); |
71 m_currentPosY = offset.y(); | 72 m_currentPosY = offset.y(); |
72 notifyPositionChanged(); | 73 notifyPositionChanged(); |
73 } | 74 } |
74 | 75 |
75 ScrollResult ScrollAnimator::handleWheelEvent(const PlatformWheelEvent& e) | 76 ScrollResult ScrollAnimator::handleWheelEvent(const PlatformWheelEvent& e) |
76 { | 77 { |
77 bool canScrollX = m_scrollableArea->userInputScrollable(HorizontalScrollbar) | 78 bool canScrollX = m_scrollableArea->userInputScrollable(HorizontalScrollbar) |
78 && e.railsMode() != PlatformEvent::RailsModeVertical; | 79 && e.railsMode() != PlatformEvent::RailsModeVertical; |
79 bool canScrollY = m_scrollableArea->userInputScrollable(VerticalScrollbar) | 80 bool canScrollY = m_scrollableArea->userInputScrollable(VerticalScrollbar) |
80 && e.railsMode() != PlatformEvent::RailsModeHorizontal; | 81 && e.railsMode() != PlatformEvent::RailsModeHorizontal; |
81 | 82 |
82 // Accept the event if we are scrollable in that direction and can still | 83 // Accept the event if we are scrollable in that direction and can still |
83 // scroll any further. | 84 // scroll any further. |
84 float deltaX = canScrollX ? e.deltaX() : 0; | 85 float deltaX = canScrollX ? e.deltaX() : 0; |
85 float deltaY = canScrollY ? e.deltaY() : 0; | 86 float deltaY = canScrollY ? e.deltaY() : 0; |
86 | 87 |
87 ScrollResult result(false); | 88 ScrollResult result; |
88 | 89 |
89 #if !OS(MACOSX) | 90 #if !OS(MACOSX) |
90 ScrollGranularity granularity = e.hasPreciseScrollingDeltas() ? ScrollByPrec
isePixel : ScrollByPixel; | 91 ScrollGranularity granularity = e.hasPreciseScrollingDeltas() ? ScrollByPrec
isePixel : ScrollByPixel; |
91 #else | 92 #else |
92 ScrollGranularity granularity = ScrollByPixel; | 93 ScrollGranularity granularity = ScrollByPixel; |
93 #endif | 94 #endif |
94 | 95 |
95 IntSize maxForwardScrollDelta = m_scrollableArea->maximumScrollPosition() -
m_scrollableArea->scrollPosition(); | 96 IntSize maxForwardScrollDelta = m_scrollableArea->maximumScrollPosition() -
m_scrollableArea->scrollPosition(); |
96 IntSize maxBackwardScrollDelta = m_scrollableArea->scrollPosition() - m_scro
llableArea->minimumScrollPosition(); | 97 IntSize maxBackwardScrollDelta = m_scrollableArea->scrollPosition() - m_scro
llableArea->minimumScrollPosition(); |
97 if ((deltaX < 0 && maxForwardScrollDelta.width() > 0) | 98 if ((deltaX < 0 && maxForwardScrollDelta.width() > 0) |
98 || (deltaX > 0 && maxBackwardScrollDelta.width() > 0) | 99 || (deltaX > 0 && maxBackwardScrollDelta.width() > 0)) |
99 || (deltaY < 0 && maxForwardScrollDelta.height() > 0) | 100 result.didScrollX = true; |
100 || (deltaY > 0 && maxBackwardScrollDelta.height() > 0)) { | 101 if ((deltaY < 0 && maxForwardScrollDelta.height() > 0) |
101 result.didScroll = true; | 102 || (deltaY > 0 && maxBackwardScrollDelta.height() > 0)) |
102 | 103 result.didScrollY = true; |
| 104 if (result.didScroll()) { |
103 if (deltaY) { | 105 if (deltaY) { |
104 if (e.granularity() == ScrollByPageWheelEvent) { | 106 if (e.granularity() == ScrollByPageWheelEvent) { |
105 bool negative = deltaY < 0; | 107 bool negative = deltaY < 0; |
106 deltaY = m_scrollableArea->pageStep(VerticalScrollbar); | 108 deltaY = m_scrollableArea->pageStep(VerticalScrollbar); |
107 if (negative) | 109 if (negative) |
108 deltaY = -deltaY; | 110 deltaY = -deltaY; |
109 } | 111 } |
110 | 112 |
111 ScrollResultOneDimensional resultY = scroll( | 113 ScrollResultOneDimensional resultY = scroll( |
112 VerticalScrollbar, granularity, m_scrollableArea->pixelStep(Vert
icalScrollbar), -deltaY); | 114 VerticalScrollbar, granularity, m_scrollableArea->pixelStep(Vert
icalScrollbar), -deltaY); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 } | 164 } |
163 | 165 |
164 float ScrollAnimator::clampScrollPosition(ScrollbarOrientation orientation, floa
t pos) | 166 float ScrollAnimator::clampScrollPosition(ScrollbarOrientation orientation, floa
t pos) |
165 { | 167 { |
166 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation); | 168 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation); |
167 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation); | 169 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation); |
168 return std::max(std::min(pos, maxScrollPos), minScrollPos); | 170 return std::max(std::min(pos, maxScrollPos), minScrollPos); |
169 } | 171 } |
170 | 172 |
171 } // namespace blink | 173 } // namespace blink |
OLD | NEW |