| 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 16 matching lines...) Expand all Loading... |
| 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 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/graphics/GraphicsLayer.h" | 35 #include "platform/graphics/GraphicsLayer.h" |
| 36 #include "platform/geometry/FloatPoint.h" | 36 #include "platform/geometry/FloatPoint.h" |
| 37 #include "platform/scroll/ProgrammaticScrollAnimator.h" |
| 37 #include "platform/scroll/ScrollbarTheme.h" | 38 #include "platform/scroll/ScrollbarTheme.h" |
| 38 #include "wtf/PassOwnPtr.h" | 39 #include "wtf/PassOwnPtr.h" |
| 39 | 40 |
| 40 #include "platform/TraceEvent.h" | 41 #include "platform/TraceEvent.h" |
| 41 | 42 |
| 42 static const int kPixelsPerLineStep = 40; | 43 static const int kPixelsPerLineStep = 40; |
| 43 static const float kMinFractionToStepWhenPaging = 0.875f; | 44 static const float kMinFractionToStepWhenPaging = 0.875f; |
| 44 | 45 |
| 45 namespace WebCore { | 46 namespace WebCore { |
| 46 | 47 |
| 47 struct SameSizeAsScrollableArea { | 48 struct SameSizeAsScrollableArea { |
| 48 virtual ~SameSizeAsScrollableArea(); | 49 virtual ~SameSizeAsScrollableArea(); |
| 49 unsigned damageBits : 2; | 50 unsigned damageBits : 2; |
| 50 IntRect scrollbarDamage[2]; | 51 IntRect scrollbarDamage[2]; |
| 51 void* pointer; | 52 void* pointer[2]; |
| 52 unsigned bitfields : 16; | 53 unsigned bitfields : 16; |
| 53 IntPoint origin; | 54 IntPoint origin; |
| 54 }; | 55 }; |
| 55 | 56 |
| 56 COMPILE_ASSERT(sizeof(ScrollableArea) == sizeof(SameSizeAsScrollableArea), Scrol
lableArea_should_stay_small); | 57 COMPILE_ASSERT(sizeof(ScrollableArea) == sizeof(SameSizeAsScrollableArea), Scrol
lableArea_should_stay_small); |
| 57 | 58 |
| 58 int ScrollableArea::pixelsPerLineStep() | 59 int ScrollableArea::pixelsPerLineStep() |
| 59 { | 60 { |
| 60 return kPixelsPerLineStep; | 61 return kPixelsPerLineStep; |
| 61 } | 62 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 88 } | 89 } |
| 89 | 90 |
| 90 ScrollAnimator* ScrollableArea::scrollAnimator() const | 91 ScrollAnimator* ScrollableArea::scrollAnimator() const |
| 91 { | 92 { |
| 92 if (!m_scrollAnimator) | 93 if (!m_scrollAnimator) |
| 93 m_scrollAnimator = ScrollAnimator::create(const_cast<ScrollableArea*>(th
is)); | 94 m_scrollAnimator = ScrollAnimator::create(const_cast<ScrollableArea*>(th
is)); |
| 94 | 95 |
| 95 return m_scrollAnimator.get(); | 96 return m_scrollAnimator.get(); |
| 96 } | 97 } |
| 97 | 98 |
| 99 ProgrammaticScrollAnimator* ScrollableArea::programmaticScrollAnimator() const |
| 100 { |
| 101 if (!m_programmaticScrollAnimator) |
| 102 m_programmaticScrollAnimator = ProgrammaticScrollAnimator::create(const_
cast<ScrollableArea*>(this)); |
| 103 |
| 104 return m_programmaticScrollAnimator.get(); |
| 105 } |
| 106 |
| 98 void ScrollableArea::setScrollOrigin(const IntPoint& origin) | 107 void ScrollableArea::setScrollOrigin(const IntPoint& origin) |
| 99 { | 108 { |
| 100 if (m_scrollOrigin != origin) { | 109 if (m_scrollOrigin != origin) { |
| 101 m_scrollOrigin = origin; | 110 m_scrollOrigin = origin; |
| 102 m_scrollOriginChanged = true; | 111 m_scrollOriginChanged = true; |
| 103 } | 112 } |
| 104 } | 113 } |
| 105 | 114 |
| 106 bool ScrollableArea::scroll(ScrollDirection direction, ScrollGranularity granula
rity, float delta) | 115 bool ScrollableArea::scroll(ScrollDirection direction, ScrollGranularity granula
rity, float delta) |
| 107 { | 116 { |
| 108 ScrollbarOrientation orientation; | 117 ScrollbarOrientation orientation; |
| 109 | 118 |
| 110 if (direction == ScrollUp || direction == ScrollDown) | 119 if (direction == ScrollUp || direction == ScrollDown) |
| 111 orientation = VerticalScrollbar; | 120 orientation = VerticalScrollbar; |
| 112 else | 121 else |
| 113 orientation = HorizontalScrollbar; | 122 orientation = HorizontalScrollbar; |
| 114 | 123 |
| 115 if (!userInputScrollable(orientation)) | 124 if (!userInputScrollable(orientation)) |
| 116 return false; | 125 return false; |
| 117 | 126 |
| 127 cancelProgrammaticScrollAnimation(); |
| 128 |
| 118 float step = 0; | 129 float step = 0; |
| 119 switch (granularity) { | 130 switch (granularity) { |
| 120 case ScrollByLine: | 131 case ScrollByLine: |
| 121 step = lineStep(orientation); | 132 step = lineStep(orientation); |
| 122 break; | 133 break; |
| 123 case ScrollByPage: | 134 case ScrollByPage: |
| 124 step = pageStep(orientation); | 135 step = pageStep(orientation); |
| 125 break; | 136 break; |
| 126 case ScrollByDocument: | 137 case ScrollByDocument: |
| 127 step = documentStep(orientation); | 138 step = documentStep(orientation); |
| 128 break; | 139 break; |
| 129 case ScrollByPixel: | 140 case ScrollByPixel: |
| 130 case ScrollByPrecisePixel: | 141 case ScrollByPrecisePixel: |
| 131 step = pixelStep(orientation); | 142 step = pixelStep(orientation); |
| 132 break; | 143 break; |
| 133 } | 144 } |
| 134 | 145 |
| 135 if (direction == ScrollUp || direction == ScrollLeft) | 146 if (direction == ScrollUp || direction == ScrollLeft) |
| 136 delta = -delta; | 147 delta = -delta; |
| 137 | 148 |
| 138 return scrollAnimator()->scroll(orientation, granularity, step, delta); | 149 return scrollAnimator()->scroll(orientation, granularity, step, delta); |
| 139 } | 150 } |
| 140 | 151 |
| 141 void ScrollableArea::scrollToOffsetWithoutAnimation(const FloatPoint& offset) | 152 void ScrollableArea::scrollToOffsetWithoutAnimation(const FloatPoint& offset) |
| 142 { | 153 { |
| 154 cancelProgrammaticScrollAnimation(); |
| 143 scrollAnimator()->scrollToOffsetWithoutAnimation(offset); | 155 scrollAnimator()->scrollToOffsetWithoutAnimation(offset); |
| 144 } | 156 } |
| 145 | 157 |
| 146 void ScrollableArea::scrollToOffsetWithoutAnimation(ScrollbarOrientation orienta
tion, float offset) | 158 void ScrollableArea::scrollToOffsetWithoutAnimation(ScrollbarOrientation orienta
tion, float offset) |
| 147 { | 159 { |
| 148 if (orientation == HorizontalScrollbar) | 160 if (orientation == HorizontalScrollbar) |
| 149 scrollToOffsetWithoutAnimation(FloatPoint(offset, scrollAnimator()->curr
entPosition().y())); | 161 scrollToOffsetWithoutAnimation(FloatPoint(offset, scrollAnimator()->curr
entPosition().y())); |
| 150 else | 162 else |
| 151 scrollToOffsetWithoutAnimation(FloatPoint(scrollAnimator()->currentPosit
ion().x(), offset)); | 163 scrollToOffsetWithoutAnimation(FloatPoint(scrollAnimator()->currentPosit
ion().x(), offset)); |
| 152 } | 164 } |
| 153 | 165 |
| 166 void ScrollableArea::programmaticallyScrollSmoothlyToOffset(const FloatPoint& of
fset) |
| 167 { |
| 168 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) |
| 169 scrollAnimator->cancelAnimations(); |
| 170 cancelProgrammaticScrollAnimation(); |
| 171 programmaticScrollAnimator()->animateToOffset(offset); |
| 172 } |
| 173 |
| 154 void ScrollableArea::notifyScrollPositionChanged(const IntPoint& position) | 174 void ScrollableArea::notifyScrollPositionChanged(const IntPoint& position) |
| 155 { | 175 { |
| 156 scrollPositionChanged(position); | 176 scrollPositionChanged(position); |
| 157 scrollAnimator()->setCurrentPosition(position); | 177 scrollAnimator()->setCurrentPosition(position); |
| 158 } | 178 } |
| 159 | 179 |
| 160 void ScrollableArea::scrollPositionChanged(const IntPoint& position) | 180 void ScrollableArea::scrollPositionChanged(const IntPoint& position) |
| 161 { | 181 { |
| 162 TRACE_EVENT0("webkit", "ScrollableArea::scrollPositionChanged"); | 182 TRACE_EVENT0("webkit", "ScrollableArea::scrollPositionChanged"); |
| 163 | 183 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 else if (behaviorString == "smooth") | 221 else if (behaviorString == "smooth") |
| 202 behavior = ScrollBehaviorSmooth; | 222 behavior = ScrollBehaviorSmooth; |
| 203 else | 223 else |
| 204 return false; | 224 return false; |
| 205 | 225 |
| 206 return true; | 226 return true; |
| 207 } | 227 } |
| 208 | 228 |
| 209 bool ScrollableArea::handleWheelEvent(const PlatformWheelEvent& wheelEvent) | 229 bool ScrollableArea::handleWheelEvent(const PlatformWheelEvent& wheelEvent) |
| 210 { | 230 { |
| 231 cancelProgrammaticScrollAnimation(); |
| 211 return scrollAnimator()->handleWheelEvent(wheelEvent); | 232 return scrollAnimator()->handleWheelEvent(wheelEvent); |
| 212 } | 233 } |
| 213 | 234 |
| 214 // NOTE: Only called from Internals for testing. | 235 // NOTE: Only called from Internals for testing. |
| 215 void ScrollableArea::setScrollOffsetFromInternals(const IntPoint& offset) | 236 void ScrollableArea::setScrollOffsetFromInternals(const IntPoint& offset) |
| 216 { | 237 { |
| 217 setScrollOffsetFromAnimation(offset); | 238 setScrollOffsetFromAnimation(offset); |
| 218 } | 239 } |
| 219 | 240 |
| 220 void ScrollableArea::setScrollOffsetFromAnimation(const IntPoint& offset) | 241 void ScrollableArea::setScrollOffsetFromAnimation(const IntPoint& offset) |
| 221 { | 242 { |
| 222 scrollPositionChanged(offset); | 243 scrollPositionChanged(offset); |
| 223 } | 244 } |
| 224 | 245 |
| 246 void ScrollableArea::setScrollOffsetFromProgrammaticAnimation(const IntPoint& of
fset) |
| 247 { |
| 248 scrollPositionChanged(offset); |
| 249 scrollAnimator()->setCurrentPosition(offset); |
| 250 } |
| 251 |
| 225 void ScrollableArea::willStartLiveResize() | 252 void ScrollableArea::willStartLiveResize() |
| 226 { | 253 { |
| 227 if (m_inLiveResize) | 254 if (m_inLiveResize) |
| 228 return; | 255 return; |
| 229 m_inLiveResize = true; | 256 m_inLiveResize = true; |
| 230 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) | 257 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) |
| 231 scrollAnimator->willStartLiveResize(); | 258 scrollAnimator->willStartLiveResize(); |
| 232 } | 259 } |
| 233 | 260 |
| 234 void ScrollableArea::willEndLiveResize() | 261 void ScrollableArea::willEndLiveResize() |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 bool ScrollableArea::hasLayerForVerticalScrollbar() const | 400 bool ScrollableArea::hasLayerForVerticalScrollbar() const |
| 374 { | 401 { |
| 375 return layerForVerticalScrollbar(); | 402 return layerForVerticalScrollbar(); |
| 376 } | 403 } |
| 377 | 404 |
| 378 bool ScrollableArea::hasLayerForScrollCorner() const | 405 bool ScrollableArea::hasLayerForScrollCorner() const |
| 379 { | 406 { |
| 380 return layerForScrollCorner(); | 407 return layerForScrollCorner(); |
| 381 } | 408 } |
| 382 | 409 |
| 383 void ScrollableArea::serviceScrollAnimations() | 410 void ScrollableArea::serviceScrollAnimations(double monotonicTime) |
| 384 { | 411 { |
| 385 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) | 412 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) |
| 386 scrollAnimator->serviceScrollAnimations(); | 413 scrollAnimator->serviceScrollAnimations(); |
| 414 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram
maticScrollAnimator()) |
| 415 programmaticScrollAnimator->tickAnimation(monotonicTime); |
| 416 } |
| 417 |
| 418 void ScrollableArea::notifyAnimationStarted(double monotonicTime) |
| 419 { |
| 420 programmaticScrollAnimator()->notifyAnimationStarted(monotonicTime); |
| 421 } |
| 422 |
| 423 void ScrollableArea::notifyAnimationFinished(double monotonicTime) |
| 424 { |
| 425 programmaticScrollAnimator()->notifyAnimationFinished(monotonicTime); |
| 426 } |
| 427 |
| 428 void ScrollableArea::layerForScrollingDidChange() |
| 429 { |
| 430 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram
maticScrollAnimator()) |
| 431 programmaticScrollAnimator->canUseCompositedScrollAnimationsDidChange(); |
| 432 } |
| 433 |
| 434 void ScrollableArea::requiresMainThreadScrollingDidChange() |
| 435 { |
| 436 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram
maticScrollAnimator()) |
| 437 programmaticScrollAnimator->canUseCompositedScrollAnimationsDidChange(); |
| 438 } |
| 439 |
| 440 bool ScrollableArea::canUseCompositedScrollAnimations() const |
| 441 { |
| 442 return compositedScrollAnimationsEnabled() && layerForScrolling() && !layerF
orScrolling()->platformLayer()->shouldScrollOnMainThread(); |
| 443 } |
| 444 |
| 445 void ScrollableArea::cancelProgrammaticScrollAnimation() |
| 446 { |
| 447 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram
maticScrollAnimator()) |
| 448 programmaticScrollAnimator->cancelAnimation(); |
| 387 } | 449 } |
| 388 | 450 |
| 389 IntRect ScrollableArea::visibleContentRect(IncludeScrollbarsInRect scrollbarIncl
usion) const | 451 IntRect ScrollableArea::visibleContentRect(IncludeScrollbarsInRect scrollbarIncl
usion) const |
| 390 { | 452 { |
| 391 int verticalScrollbarWidth = 0; | 453 int verticalScrollbarWidth = 0; |
| 392 int horizontalScrollbarHeight = 0; | 454 int horizontalScrollbarHeight = 0; |
| 393 | 455 |
| 394 if (scrollbarInclusion == IncludeScrollbars) { | 456 if (scrollbarInclusion == IncludeScrollbars) { |
| 395 if (Scrollbar* verticalBar = verticalScrollbar()) | 457 if (Scrollbar* verticalBar = verticalScrollbar()) |
| 396 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? vertic
alBar->width() : 0; | 458 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? vertic
alBar->width() : 0; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 418 { | 480 { |
| 419 return scrollSize(orientation); | 481 return scrollSize(orientation); |
| 420 } | 482 } |
| 421 | 483 |
| 422 float ScrollableArea::pixelStep(ScrollbarOrientation) const | 484 float ScrollableArea::pixelStep(ScrollbarOrientation) const |
| 423 { | 485 { |
| 424 return 1; | 486 return 1; |
| 425 } | 487 } |
| 426 | 488 |
| 427 } // namespace WebCore | 489 } // namespace WebCore |
| OLD | NEW |