| 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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 return true; | 67 return true; |
| 68 } | 68 } |
| 69 | 69 |
| 70 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) | 70 void ScrollAnimator::scrollToOffsetWithoutAnimation(const FloatPoint& offset) |
| 71 { | 71 { |
| 72 m_currentPosX = offset.x(); | 72 m_currentPosX = offset.x(); |
| 73 m_currentPosY = offset.y(); | 73 m_currentPosY = offset.y(); |
| 74 notifyPositionChanged(); | 74 notifyPositionChanged(); |
| 75 } | 75 } |
| 76 | 76 |
| 77 bool ScrollAnimator::handleWheelEvent(const PlatformWheelEvent& e) | |
| 78 { | |
| 79 bool canScrollX = m_scrollableArea->userInputScrollable(HorizontalScrollbar)
; | |
| 80 bool canScrollY = m_scrollableArea->userInputScrollable(VerticalScrollbar); | |
| 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 bool handled = false; | |
| 88 | |
| 89 ScrollGranularity granularity = e.hasPreciseScrollingDeltas() ? ScrollByPrec
isePixel : ScrollByPixel; | |
| 90 | |
| 91 IntSize maxForwardScrollDelta = m_scrollableArea->maximumScrollPosition() -
m_scrollableArea->scrollPosition(); | |
| 92 IntSize maxBackwardScrollDelta = m_scrollableArea->scrollPosition() - m_scro
llableArea->minimumScrollPosition(); | |
| 93 if ((deltaX < 0 && maxForwardScrollDelta.width() > 0) | |
| 94 || (deltaX > 0 && maxBackwardScrollDelta.width() > 0) | |
| 95 || (deltaY < 0 && maxForwardScrollDelta.height() > 0) | |
| 96 || (deltaY > 0 && maxBackwardScrollDelta.height() > 0)) { | |
| 97 handled = true; | |
| 98 | |
| 99 if (deltaY) { | |
| 100 if (e.granularity() == ScrollByPageWheelEvent) { | |
| 101 bool negative = deltaY < 0; | |
| 102 deltaY = m_scrollableArea->pageStep(VerticalScrollbar); | |
| 103 if (negative) | |
| 104 deltaY = -deltaY; | |
| 105 } | |
| 106 | |
| 107 scroll(VerticalScrollbar, granularity, m_scrollableArea->pixelStep(V
erticalScrollbar), -deltaY); | |
| 108 } | |
| 109 | |
| 110 if (deltaX) { | |
| 111 if (e.granularity() == ScrollByPageWheelEvent) { | |
| 112 bool negative = deltaX < 0; | |
| 113 deltaX = m_scrollableArea->pageStep(HorizontalScrollbar); | |
| 114 if (negative) | |
| 115 deltaX = -deltaX; | |
| 116 } | |
| 117 | |
| 118 scroll(HorizontalScrollbar, granularity, m_scrollableArea->pixelStep
(HorizontalScrollbar), -deltaX); | |
| 119 } | |
| 120 } | |
| 121 return handled; | |
| 122 } | |
| 123 | |
| 124 void ScrollAnimator::setCurrentPosition(const FloatPoint& position) | 77 void ScrollAnimator::setCurrentPosition(const FloatPoint& position) |
| 125 { | 78 { |
| 126 m_currentPosX = position.x(); | 79 m_currentPosX = position.x(); |
| 127 m_currentPosY = position.y(); | 80 m_currentPosY = position.y(); |
| 128 } | 81 } |
| 129 | 82 |
| 130 FloatPoint ScrollAnimator::currentPosition() const | 83 FloatPoint ScrollAnimator::currentPosition() const |
| 131 { | 84 { |
| 132 return FloatPoint(m_currentPosX, m_currentPosY); | 85 return FloatPoint(m_currentPosX, m_currentPosY); |
| 133 } | 86 } |
| 134 | 87 |
| 135 void ScrollAnimator::notifyPositionChanged() | 88 void ScrollAnimator::notifyPositionChanged() |
| 136 { | 89 { |
| 137 m_scrollableArea->setScrollOffsetFromAnimation(IntPoint(m_currentPosX, m_cur
rentPosY)); | 90 m_scrollableArea->setScrollOffsetFromAnimation(IntPoint(m_currentPosX, m_cur
rentPosY)); |
| 138 } | 91 } |
| 139 | 92 |
| 140 float ScrollAnimator::clampScrollPosition(ScrollbarOrientation orientation, floa
t pos) | 93 float ScrollAnimator::clampScrollPosition(ScrollbarOrientation orientation, floa
t pos) |
| 141 { | 94 { |
| 142 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation); | 95 float maxScrollPos = m_scrollableArea->maximumScrollPosition(orientation); |
| 143 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation); | 96 float minScrollPos = m_scrollableArea->minimumScrollPosition(orientation); |
| 144 return std::max(std::min(pos, maxScrollPos), minScrollPos); | 97 return std::max(std::min(pos, maxScrollPos), minScrollPos); |
| 145 } | 98 } |
| 146 | 99 |
| 147 } // namespace blink | 100 } // namespace blink |
| OLD | NEW |