| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010, Google Inc. All rights reserved. | 2 * Copyright (c) 2010, Google Inc. All rights reserved. |
| 3 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. | 3 * Copyright (C) 2008, 2011 Apple Inc. All Rights Reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
| 7 * met: | 7 * met: |
| 8 * | 8 * |
| 9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 */ | 30 */ |
| 31 | 31 |
| 32 #include "config.h" | 32 #include "config.h" |
| 33 #include "platform/scroll/ScrollableArea.h" | 33 #include "platform/scroll/ScrollableArea.h" |
| 34 | 34 |
| 35 #include "platform/HostWindow.h" | 35 #include "platform/HostWindow.h" |
| 36 #include "platform/Logging.h" | 36 #include "platform/Logging.h" |
| 37 #include "platform/graphics/GraphicsLayer.h" | 37 #include "platform/graphics/GraphicsLayer.h" |
| 38 #include "platform/geometry/FloatPoint.h" | 38 #include "platform/geometry/FloatPoint.h" |
| 39 #include "platform/scroll/ProgrammaticScrollAnimator.h" | |
| 40 #include "platform/scroll/Scrollbar.h" | 39 #include "platform/scroll/Scrollbar.h" |
| 41 #include "wtf/PassOwnPtr.h" | 40 #include "wtf/PassOwnPtr.h" |
| 42 | 41 |
| 43 #include "platform/TraceEvent.h" | 42 #include "platform/TraceEvent.h" |
| 44 | 43 |
| 45 static const int kPixelsPerLineStep = 40; | 44 static const int kPixelsPerLineStep = 40; |
| 46 static const float kMinFractionToStepWhenPaging = 0.875f; | 45 static const float kMinFractionToStepWhenPaging = 0.875f; |
| 47 | 46 |
| 48 namespace blink { | 47 namespace blink { |
| 49 | 48 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 { | 90 { |
| 92 if (!m_animators) | 91 if (!m_animators) |
| 93 m_animators = adoptPtr(new ScrollableAreaAnimators); | 92 m_animators = adoptPtr(new ScrollableAreaAnimators); |
| 94 | 93 |
| 95 if (!m_animators->scrollAnimator) | 94 if (!m_animators->scrollAnimator) |
| 96 m_animators->scrollAnimator = ScrollAnimator::create(const_cast<Scrollab
leArea*>(this)); | 95 m_animators->scrollAnimator = ScrollAnimator::create(const_cast<Scrollab
leArea*>(this)); |
| 97 | 96 |
| 98 return m_animators->scrollAnimator.get(); | 97 return m_animators->scrollAnimator.get(); |
| 99 } | 98 } |
| 100 | 99 |
| 101 ProgrammaticScrollAnimator* ScrollableArea::programmaticScrollAnimator() const | |
| 102 { | |
| 103 if (!m_animators) | |
| 104 m_animators = adoptPtr(new ScrollableAreaAnimators); | |
| 105 | |
| 106 if (!m_animators->programmaticScrollAnimator) | |
| 107 m_animators->programmaticScrollAnimator = ProgrammaticScrollAnimator::cr
eate(const_cast<ScrollableArea*>(this)); | |
| 108 | |
| 109 return m_animators->programmaticScrollAnimator.get(); | |
| 110 } | |
| 111 | |
| 112 void ScrollableArea::setScrollOrigin(const IntPoint& origin) | 100 void ScrollableArea::setScrollOrigin(const IntPoint& origin) |
| 113 { | 101 { |
| 114 if (m_scrollOrigin != origin) { | 102 if (m_scrollOrigin != origin) { |
| 115 m_scrollOrigin = origin; | 103 m_scrollOrigin = origin; |
| 116 m_scrollOriginChanged = true; | 104 m_scrollOriginChanged = true; |
| 117 } | 105 } |
| 118 } | 106 } |
| 119 | 107 |
| 120 bool ScrollableArea::scroll(ScrollDirection direction, ScrollGranularity granula
rity, float delta) | 108 bool ScrollableArea::scroll(ScrollDirection direction, ScrollGranularity granula
rity, float delta) |
| 121 { | 109 { |
| 122 ScrollbarOrientation orientation; | 110 ScrollbarOrientation orientation; |
| 123 | 111 |
| 124 if (direction == ScrollUp || direction == ScrollDown) | 112 if (direction == ScrollUp || direction == ScrollDown) |
| 125 orientation = VerticalScrollbar; | 113 orientation = VerticalScrollbar; |
| 126 else | 114 else |
| 127 orientation = HorizontalScrollbar; | 115 orientation = HorizontalScrollbar; |
| 128 | 116 |
| 129 if (!userInputScrollable(orientation)) | 117 if (!userInputScrollable(orientation)) |
| 130 return false; | 118 return false; |
| 131 | 119 |
| 132 cancelProgrammaticScrollAnimation(); | |
| 133 | |
| 134 float step = 0; | 120 float step = 0; |
| 135 switch (granularity) { | 121 switch (granularity) { |
| 136 case ScrollByLine: | 122 case ScrollByLine: |
| 137 step = lineStep(orientation); | 123 step = lineStep(orientation); |
| 138 break; | 124 break; |
| 139 case ScrollByPage: | 125 case ScrollByPage: |
| 140 step = pageStep(orientation); | 126 step = pageStep(orientation); |
| 141 break; | 127 break; |
| 142 case ScrollByDocument: | 128 case ScrollByDocument: |
| 143 step = documentStep(orientation); | 129 step = documentStep(orientation); |
| 144 break; | 130 break; |
| 145 case ScrollByPixel: | 131 case ScrollByPixel: |
| 146 case ScrollByPrecisePixel: | 132 case ScrollByPrecisePixel: |
| 147 step = pixelStep(orientation); | 133 step = pixelStep(orientation); |
| 148 break; | 134 break; |
| 149 } | 135 } |
| 150 | 136 |
| 151 if (direction == ScrollUp || direction == ScrollLeft) | 137 if (direction == ScrollUp || direction == ScrollLeft) |
| 152 delta = -delta; | 138 delta = -delta; |
| 153 | 139 |
| 154 return scrollAnimator()->scroll(orientation, granularity, step, delta); | 140 return scrollAnimator()->scroll(orientation, granularity, step, delta); |
| 155 } | 141 } |
| 156 | 142 |
| 157 void ScrollableArea::scrollToOffsetWithoutAnimation(const FloatPoint& offset) | 143 void ScrollableArea::scrollToOffsetWithoutAnimation(const FloatPoint& offset) |
| 158 { | 144 { |
| 159 cancelProgrammaticScrollAnimation(); | |
| 160 scrollAnimator()->scrollToOffsetWithoutAnimation(offset); | 145 scrollAnimator()->scrollToOffsetWithoutAnimation(offset); |
| 161 } | 146 } |
| 162 | 147 |
| 163 void ScrollableArea::scrollToOffsetWithoutAnimation(ScrollbarOrientation orienta
tion, float offset) | 148 void ScrollableArea::scrollToOffsetWithoutAnimation(ScrollbarOrientation orienta
tion, float offset) |
| 164 { | 149 { |
| 165 if (orientation == HorizontalScrollbar) | 150 if (orientation == HorizontalScrollbar) |
| 166 scrollToOffsetWithoutAnimation(FloatPoint(offset, scrollAnimator()->curr
entPosition().y())); | 151 scrollToOffsetWithoutAnimation(FloatPoint(offset, scrollAnimator()->curr
entPosition().y())); |
| 167 else | 152 else |
| 168 scrollToOffsetWithoutAnimation(FloatPoint(scrollAnimator()->currentPosit
ion().x(), offset)); | 153 scrollToOffsetWithoutAnimation(FloatPoint(scrollAnimator()->currentPosit
ion().x(), offset)); |
| 169 } | 154 } |
| 170 | 155 |
| 171 void ScrollableArea::programmaticallyScrollSmoothlyToOffset(const FloatPoint& of
fset) | |
| 172 { | |
| 173 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) | |
| 174 scrollAnimator->cancelAnimations(); | |
| 175 programmaticScrollAnimator()->animateToOffset(offset); | |
| 176 } | |
| 177 | |
| 178 void ScrollableArea::notifyScrollPositionChanged(const IntPoint& position) | 156 void ScrollableArea::notifyScrollPositionChanged(const IntPoint& position) |
| 179 { | 157 { |
| 180 scrollPositionChanged(position); | 158 scrollPositionChanged(position); |
| 181 scrollAnimator()->setCurrentPosition(position); | 159 scrollAnimator()->setCurrentPosition(position); |
| 182 } | 160 } |
| 183 | 161 |
| 184 void ScrollableArea::scrollPositionChanged(const IntPoint& position) | 162 void ScrollableArea::scrollPositionChanged(const IntPoint& position) |
| 185 { | 163 { |
| 186 TRACE_EVENT0("blink", "ScrollableArea::scrollPositionChanged"); | 164 TRACE_EVENT0("blink", "ScrollableArea::scrollPositionChanged"); |
| 187 | 165 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 | 207 |
| 230 return true; | 208 return true; |
| 231 } | 209 } |
| 232 | 210 |
| 233 bool ScrollableArea::handleWheelEvent(const PlatformWheelEvent& wheelEvent) | 211 bool ScrollableArea::handleWheelEvent(const PlatformWheelEvent& wheelEvent) |
| 234 { | 212 { |
| 235 // ctrl+wheel events are used to trigger zooming, not scrolling. | 213 // ctrl+wheel events are used to trigger zooming, not scrolling. |
| 236 if (wheelEvent.modifiers() & PlatformEvent::CtrlKey) | 214 if (wheelEvent.modifiers() & PlatformEvent::CtrlKey) |
| 237 return false; | 215 return false; |
| 238 | 216 |
| 239 cancelProgrammaticScrollAnimation(); | |
| 240 return scrollAnimator()->handleWheelEvent(wheelEvent); | 217 return scrollAnimator()->handleWheelEvent(wheelEvent); |
| 241 } | 218 } |
| 242 | 219 |
| 243 // NOTE: Only called from Internals for testing. | 220 // NOTE: Only called from Internals for testing. |
| 244 void ScrollableArea::setScrollOffsetFromInternals(const IntPoint& offset) | 221 void ScrollableArea::setScrollOffsetFromInternals(const IntPoint& offset) |
| 245 { | 222 { |
| 246 setScrollOffsetFromAnimation(offset); | 223 setScrollOffsetFromAnimation(offset); |
| 247 } | 224 } |
| 248 | 225 |
| 249 void ScrollableArea::setScrollOffsetFromAnimation(const IntPoint& offset) | 226 void ScrollableArea::setScrollOffsetFromAnimation(const IntPoint& offset) |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 window->scheduleAnimation(); | 352 window->scheduleAnimation(); |
| 376 return true; | 353 return true; |
| 377 } | 354 } |
| 378 return false; | 355 return false; |
| 379 } | 356 } |
| 380 | 357 |
| 381 void ScrollableArea::serviceScrollAnimations(double monotonicTime) | 358 void ScrollableArea::serviceScrollAnimations(double monotonicTime) |
| 382 { | 359 { |
| 383 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) | 360 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) |
| 384 scrollAnimator->serviceScrollAnimations(); | 361 scrollAnimator->serviceScrollAnimations(); |
| 385 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram
maticScrollAnimator()) | |
| 386 programmaticScrollAnimator->tickAnimation(monotonicTime); | |
| 387 } | |
| 388 | |
| 389 void ScrollableArea::cancelProgrammaticScrollAnimation() | |
| 390 { | |
| 391 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram
maticScrollAnimator()) | |
| 392 programmaticScrollAnimator->cancelAnimation(); | |
| 393 } | 362 } |
| 394 | 363 |
| 395 IntPoint ScrollableArea::clampScrollPosition(const IntPoint& scrollPosition) con
st | 364 IntPoint ScrollableArea::clampScrollPosition(const IntPoint& scrollPosition) con
st |
| 396 { | 365 { |
| 397 return scrollPosition.shrunkTo(maximumScrollPosition()).expandedTo(minimumSc
rollPosition()); | 366 return scrollPosition.shrunkTo(maximumScrollPosition()).expandedTo(minimumSc
rollPosition()); |
| 398 } | 367 } |
| 399 | 368 |
| 400 int ScrollableArea::lineStep(ScrollbarOrientation) const | 369 int ScrollableArea::lineStep(ScrollbarOrientation) const |
| 401 { | 370 { |
| 402 return pixelsPerLineStep(); | 371 return pixelsPerLineStep(); |
| 403 } | 372 } |
| 404 | 373 |
| 405 int ScrollableArea::documentStep(ScrollbarOrientation orientation) const | 374 int ScrollableArea::documentStep(ScrollbarOrientation orientation) const |
| 406 { | 375 { |
| 407 return scrollSize(orientation); | 376 return scrollSize(orientation); |
| 408 } | 377 } |
| 409 | 378 |
| 410 float ScrollableArea::pixelStep(ScrollbarOrientation) const | 379 float ScrollableArea::pixelStep(ScrollbarOrientation) const |
| 411 { | 380 { |
| 412 return 1; | 381 return 1; |
| 413 } | 382 } |
| 414 | 383 |
| 415 } // namespace blink | 384 } // namespace blink |
| OLD | NEW |