| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 return ScrollResultOneDimensional(true, delta - usedDelta); | 65 return ScrollResultOneDimensional(true, delta - usedDelta); |
| 66 } | 66 } |
| 67 | 67 |
| 68 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) | 68 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) |
| 69 { | 69 { |
| 70 m_currentPosX = offset.x(); | 70 m_currentPosX = offset.x(); |
| 71 m_currentPosY = offset.y(); | 71 m_currentPosY = offset.y(); |
| 72 notifyPositionChanged(); | 72 notifyPositionChanged(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 ScrollResult ScrollAnimator::handleWheelEvent(const PlatformWheelEvent& e) | |
| 76 { | |
| 77 bool canScrollX = m_scrollableArea->userInputScrollable(HorizontalScrollbar) | |
| 78 && e.railsMode() != PlatformEvent::RailsModeVertical; | |
| 79 bool canScrollY = m_scrollableArea->userInputScrollable(VerticalScrollbar) | |
| 80 && e.railsMode() != PlatformEvent::RailsModeHorizontal; | |
| 81 | |
| 82 // Accept the event if we are scrollable in that direction and can still | |
| 83 // scroll any further. | |
| 84 float deltaX = canScrollX ? e.deltaX() : 0; | |
| 85 float deltaY = canScrollY ? e.deltaY() : 0; | |
| 86 | |
| 87 ScrollResult result; | |
| 88 | |
| 89 #if !OS(MACOSX) | |
| 90 ScrollGranularity granularity = e.hasPreciseScrollingDeltas() ? ScrollByPrec
isePixel : ScrollByPixel; | |
| 91 #else | |
| 92 ScrollGranularity granularity = ScrollByPixel; | |
| 93 #endif | |
| 94 | |
| 95 if (deltaY) { | |
| 96 if (e.granularity() == ScrollByPageWheelEvent) { | |
| 97 bool negative = deltaY < 0; | |
| 98 deltaY = m_scrollableArea->pageStep(VerticalScrollbar); | |
| 99 if (negative) | |
| 100 deltaY = -deltaY; | |
| 101 } | |
| 102 | |
| 103 ScrollResultOneDimensional resultY = userScroll( | |
| 104 VerticalScrollbar, granularity, m_scrollableArea->pixelStep(Vertical
Scrollbar), -deltaY); | |
| 105 result.didScrollY = resultY.didScroll; | |
| 106 if (e.granularity() != ScrollByPageWheelEvent) { | |
| 107 if (resultY.didScroll) | |
| 108 result.unusedScrollDeltaY = -resultY.unusedScrollDelta; | |
| 109 else | |
| 110 result.unusedScrollDeltaY = deltaY; | |
| 111 } | |
| 112 } | |
| 113 | |
| 114 if (deltaX) { | |
| 115 if (e.granularity() == ScrollByPageWheelEvent) { | |
| 116 bool negative = deltaX < 0; | |
| 117 deltaX = m_scrollableArea->pageStep(HorizontalScrollbar); | |
| 118 if (negative) | |
| 119 deltaX = -deltaX; | |
| 120 } | |
| 121 | |
| 122 ScrollResultOneDimensional resultX = userScroll( | |
| 123 HorizontalScrollbar, granularity, m_scrollableArea->pixelStep(Horizo
ntalScrollbar), -deltaX); | |
| 124 result.didScrollX = resultX.didScroll; | |
| 125 if (e.granularity() != ScrollByPageWheelEvent) { | |
| 126 if (resultX.didScroll) | |
| 127 result.unusedScrollDeltaX = -resultX.unusedScrollDelta; | |
| 128 else | |
| 129 result.unusedScrollDeltaX = deltaX; | |
| 130 } | |
| 131 } | |
| 132 return result; | |
| 133 } | |
| 134 | |
| 135 void ScrollAnimator::setCurrentPosition(const FloatPoint& position) | 75 void ScrollAnimator::setCurrentPosition(const FloatPoint& position) |
| 136 { | 76 { |
| 137 m_currentPosX = position.x(); | 77 m_currentPosX = position.x(); |
| 138 m_currentPosY = position.y(); | 78 m_currentPosY = position.y(); |
| 139 } | 79 } |
| 140 | 80 |
| 141 FloatPoint ScrollAnimator::currentPosition() const | 81 FloatPoint ScrollAnimator::currentPosition() const |
| 142 { | 82 { |
| 143 return FloatPoint(m_currentPosX, m_currentPosY); | 83 return FloatPoint(m_currentPosX, m_currentPosY); |
| 144 } | 84 } |
| 145 | 85 |
| 146 void ScrollAnimator::notifyPositionChanged() | 86 void ScrollAnimator::notifyPositionChanged() |
| 147 { | 87 { |
| 148 m_scrollableArea->scrollPositionChanged(DoublePoint(m_currentPosX, m_current
PosY), UserScroll); | 88 m_scrollableArea->scrollPositionChanged(DoublePoint(m_currentPosX, m_current
PosY), UserScroll); |
| 149 } | 89 } |
| 150 | 90 |
| 151 float ScrollAnimator::clampScrollPosition(ScrollbarOrientation orientation, floa
t pos) | 91 float ScrollAnimator::clampScrollPosition(ScrollbarOrientation orientation, floa
t pos) |
| 152 { | 92 { |
| 153 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation); | 93 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation); |
| 154 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation); | 94 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation); |
| 155 return std::max(std::min(pos, maxScrollPos), minScrollPos); | 95 return std::max(std::min(pos, maxScrollPos), minScrollPos); |
| 156 } | 96 } |
| 157 | 97 |
| 158 } // namespace blink | 98 } // namespace blink |
| OLD | NEW |