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 GraphicsLayer* ScrollableArea::layerForContainer() const | 115 GraphicsLayer* ScrollableArea::layerForContainer() const |
107 { | 116 { |
108 return layerForScrolling() ? layerForScrolling()->parent() : 0; | 117 return layerForScrolling() ? layerForScrolling()->parent() : 0; |
109 } | 118 } |
110 | 119 |
111 bool ScrollableArea::scroll(ScrollDirection direction, ScrollGranularity granula
rity, float delta) | 120 bool ScrollableArea::scroll(ScrollDirection direction, ScrollGranularity granula
rity, float delta) |
112 { | 121 { |
113 ScrollbarOrientation orientation; | 122 ScrollbarOrientation orientation; |
114 | 123 |
115 if (direction == ScrollUp || direction == ScrollDown) | 124 if (direction == ScrollUp || direction == ScrollDown) |
116 orientation = VerticalScrollbar; | 125 orientation = VerticalScrollbar; |
117 else | 126 else |
118 orientation = HorizontalScrollbar; | 127 orientation = HorizontalScrollbar; |
119 | 128 |
120 if (!userInputScrollable(orientation)) | 129 if (!userInputScrollable(orientation)) |
121 return false; | 130 return false; |
122 | 131 |
| 132 cancelProgrammaticScrollAnimation(); |
| 133 |
123 float step = 0; | 134 float step = 0; |
124 switch (granularity) { | 135 switch (granularity) { |
125 case ScrollByLine: | 136 case ScrollByLine: |
126 step = lineStep(orientation); | 137 step = lineStep(orientation); |
127 break; | 138 break; |
128 case ScrollByPage: | 139 case ScrollByPage: |
129 step = pageStep(orientation); | 140 step = pageStep(orientation); |
130 break; | 141 break; |
131 case ScrollByDocument: | 142 case ScrollByDocument: |
132 step = documentStep(orientation); | 143 step = documentStep(orientation); |
133 break; | 144 break; |
134 case ScrollByPixel: | 145 case ScrollByPixel: |
135 case ScrollByPrecisePixel: | 146 case ScrollByPrecisePixel: |
136 step = pixelStep(orientation); | 147 step = pixelStep(orientation); |
137 break; | 148 break; |
138 } | 149 } |
139 | 150 |
140 if (direction == ScrollUp || direction == ScrollLeft) | 151 if (direction == ScrollUp || direction == ScrollLeft) |
141 delta = -delta; | 152 delta = -delta; |
142 | 153 |
143 return scrollAnimator()->scroll(orientation, granularity, step, delta); | 154 return scrollAnimator()->scroll(orientation, granularity, step, delta); |
144 } | 155 } |
145 | 156 |
146 void ScrollableArea::scrollToOffsetWithoutAnimation(const FloatPoint& offset) | 157 void ScrollableArea::scrollToOffsetWithoutAnimation(const FloatPoint& offset) |
147 { | 158 { |
| 159 cancelProgrammaticScrollAnimation(); |
148 scrollAnimator()->scrollToOffsetWithoutAnimation(offset); | 160 scrollAnimator()->scrollToOffsetWithoutAnimation(offset); |
149 } | 161 } |
150 | 162 |
151 void ScrollableArea::scrollToOffsetWithoutAnimation(ScrollbarOrientation orienta
tion, float offset) | 163 void ScrollableArea::scrollToOffsetWithoutAnimation(ScrollbarOrientation orienta
tion, float offset) |
152 { | 164 { |
153 if (orientation == HorizontalScrollbar) | 165 if (orientation == HorizontalScrollbar) |
154 scrollToOffsetWithoutAnimation(FloatPoint(offset, scrollAnimator()->curr
entPosition().y())); | 166 scrollToOffsetWithoutAnimation(FloatPoint(offset, scrollAnimator()->curr
entPosition().y())); |
155 else | 167 else |
156 scrollToOffsetWithoutAnimation(FloatPoint(scrollAnimator()->currentPosit
ion().x(), offset)); | 168 scrollToOffsetWithoutAnimation(FloatPoint(scrollAnimator()->currentPosit
ion().x(), offset)); |
157 } | 169 } |
158 | 170 |
| 171 void ScrollableArea::programmaticallyScrollSmoothlyToOffset(const FloatPoint& of
fset) |
| 172 { |
| 173 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) |
| 174 scrollAnimator->cancelAnimations(); |
| 175 cancelProgrammaticScrollAnimation(); |
| 176 programmaticScrollAnimator()->animateToOffset(offset); |
| 177 } |
| 178 |
159 void ScrollableArea::notifyScrollPositionChanged(const IntPoint& position) | 179 void ScrollableArea::notifyScrollPositionChanged(const IntPoint& position) |
160 { | 180 { |
161 scrollPositionChanged(position); | 181 scrollPositionChanged(position); |
162 scrollAnimator()->setCurrentPosition(position); | 182 scrollAnimator()->setCurrentPosition(position); |
163 } | 183 } |
164 | 184 |
165 void ScrollableArea::scrollPositionChanged(const IntPoint& position) | 185 void ScrollableArea::scrollPositionChanged(const IntPoint& position) |
166 { | 186 { |
167 TRACE_EVENT0("blink", "ScrollableArea::scrollPositionChanged"); | 187 TRACE_EVENT0("blink", "ScrollableArea::scrollPositionChanged"); |
168 | 188 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 | 230 |
211 return true; | 231 return true; |
212 } | 232 } |
213 | 233 |
214 bool ScrollableArea::handleWheelEvent(const PlatformWheelEvent& wheelEvent) | 234 bool ScrollableArea::handleWheelEvent(const PlatformWheelEvent& wheelEvent) |
215 { | 235 { |
216 // ctrl+wheel events are used to trigger zooming, not scrolling. | 236 // ctrl+wheel events are used to trigger zooming, not scrolling. |
217 if (wheelEvent.modifiers() & PlatformEvent::CtrlKey) | 237 if (wheelEvent.modifiers() & PlatformEvent::CtrlKey) |
218 return false; | 238 return false; |
219 | 239 |
| 240 cancelProgrammaticScrollAnimation(); |
220 return scrollAnimator()->handleWheelEvent(wheelEvent); | 241 return scrollAnimator()->handleWheelEvent(wheelEvent); |
221 } | 242 } |
222 | 243 |
223 // NOTE: Only called from Internals for testing. | 244 // NOTE: Only called from Internals for testing. |
224 void ScrollableArea::setScrollOffsetFromInternals(const IntPoint& offset) | 245 void ScrollableArea::setScrollOffsetFromInternals(const IntPoint& offset) |
225 { | 246 { |
226 setScrollOffsetFromAnimation(offset); | 247 setScrollOffsetFromAnimation(offset); |
227 } | 248 } |
228 | 249 |
229 void ScrollableArea::setScrollOffsetFromAnimation(const IntPoint& offset) | 250 void ScrollableArea::setScrollOffsetFromAnimation(const IntPoint& offset) |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 bool ScrollableArea::hasLayerForVerticalScrollbar() const | 406 bool ScrollableArea::hasLayerForVerticalScrollbar() const |
386 { | 407 { |
387 return layerForVerticalScrollbar(); | 408 return layerForVerticalScrollbar(); |
388 } | 409 } |
389 | 410 |
390 bool ScrollableArea::hasLayerForScrollCorner() const | 411 bool ScrollableArea::hasLayerForScrollCorner() const |
391 { | 412 { |
392 return layerForScrollCorner(); | 413 return layerForScrollCorner(); |
393 } | 414 } |
394 | 415 |
395 void ScrollableArea::serviceScrollAnimations() | 416 void ScrollableArea::serviceScrollAnimations(double monotonicTime) |
396 { | 417 { |
397 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) | 418 if (ScrollAnimator* scrollAnimator = existingScrollAnimator()) |
398 scrollAnimator->serviceScrollAnimations(); | 419 scrollAnimator->serviceScrollAnimations(); |
| 420 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram
maticScrollAnimator()) |
| 421 programmaticScrollAnimator->tickAnimation(monotonicTime); |
| 422 } |
| 423 |
| 424 void ScrollableArea::notifyAnimationStarted(double monotonicTime) |
| 425 { |
| 426 programmaticScrollAnimator()->notifyAnimationStarted(monotonicTime); |
| 427 } |
| 428 |
| 429 void ScrollableArea::notifyAnimationFinished(double monotonicTime) |
| 430 { |
| 431 programmaticScrollAnimator()->notifyAnimationFinished(monotonicTime); |
| 432 } |
| 433 |
| 434 void ScrollableArea::layerForScrollingDidChange() |
| 435 { |
| 436 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram
maticScrollAnimator()) |
| 437 programmaticScrollAnimator->canUseCompositedScrollAnimationsDidChange(); |
| 438 } |
| 439 |
| 440 void ScrollableArea::requiresMainThreadScrollingDidChange() |
| 441 { |
| 442 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram
maticScrollAnimator()) |
| 443 programmaticScrollAnimator->canUseCompositedScrollAnimationsDidChange(); |
| 444 } |
| 445 |
| 446 bool ScrollableArea::canUseCompositedScrollAnimations() const |
| 447 { |
| 448 return layerForScrolling() && !layerForScrolling()->platformLayer()->shouldS
crollOnMainThread(); |
| 449 } |
| 450 |
| 451 void ScrollableArea::cancelProgrammaticScrollAnimation() |
| 452 { |
| 453 if (ProgrammaticScrollAnimator* programmaticScrollAnimator = existingProgram
maticScrollAnimator()) |
| 454 programmaticScrollAnimator->cancelAnimation(); |
399 } | 455 } |
400 | 456 |
401 IntRect ScrollableArea::visibleContentRect(IncludeScrollbarsInRect scrollbarIncl
usion) const | 457 IntRect ScrollableArea::visibleContentRect(IncludeScrollbarsInRect scrollbarIncl
usion) const |
402 { | 458 { |
403 int verticalScrollbarWidth = 0; | 459 int verticalScrollbarWidth = 0; |
404 int horizontalScrollbarHeight = 0; | 460 int horizontalScrollbarHeight = 0; |
405 | 461 |
406 if (scrollbarInclusion == IncludeScrollbars) { | 462 if (scrollbarInclusion == IncludeScrollbars) { |
407 if (Scrollbar* verticalBar = verticalScrollbar()) | 463 if (Scrollbar* verticalBar = verticalScrollbar()) |
408 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? vertic
alBar->width() : 0; | 464 verticalScrollbarWidth = !verticalBar->isOverlayScrollbar() ? vertic
alBar->width() : 0; |
(...skipping 30 matching lines...) Expand all Loading... |
439 { | 495 { |
440 return scrollSize(orientation); | 496 return scrollSize(orientation); |
441 } | 497 } |
442 | 498 |
443 float ScrollableArea::pixelStep(ScrollbarOrientation) const | 499 float ScrollableArea::pixelStep(ScrollbarOrientation) const |
444 { | 500 { |
445 return 1; | 501 return 1; |
446 } | 502 } |
447 | 503 |
448 } // namespace WebCore | 504 } // namespace WebCore |
OLD | NEW |