OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "config.h" | 5 #include "config.h" |
6 #include "core/frame/RootFrameViewport.h" | 6 #include "core/frame/RootFrameViewport.h" |
7 | 7 |
8 #include "core/frame/FrameView.h" | 8 #include "core/frame/FrameView.h" |
9 #include "core/layout/ScrollAlignment.h" | 9 #include "core/layout/ScrollAlignment.h" |
10 #include "platform/geometry/DoubleRect.h" | 10 #include "platform/geometry/DoubleRect.h" |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
232 | 232 |
233 GraphicsLayer* RootFrameViewport::layerForVerticalScrollbar() const | 233 GraphicsLayer* RootFrameViewport::layerForVerticalScrollbar() const |
234 { | 234 { |
235 return layoutViewport().layerForVerticalScrollbar(); | 235 return layoutViewport().layerForVerticalScrollbar(); |
236 } | 236 } |
237 | 237 |
238 ScrollResultOneDimensional RootFrameViewport::userScroll(ScrollDirectionPhysical
direction, ScrollGranularity granularity, float delta) | 238 ScrollResultOneDimensional RootFrameViewport::userScroll(ScrollDirectionPhysical
direction, ScrollGranularity granularity, float delta) |
239 { | 239 { |
240 updateScrollAnimator(); | 240 updateScrollAnimator(); |
241 | 241 |
242 ScrollbarOrientation orientation; | 242 ScrollbarOrientation orientation = scrollbarOrientationFromDirection(directi
on); |
243 | 243 |
244 if (direction == ScrollUp || direction == ScrollDown) | 244 if (layoutViewport().userInputScrollable(orientation) && visualViewport().us
erInputScrollable(orientation)) { |
245 orientation = VerticalScrollbar; | 245 // Distribute the scroll between the visual and layout viewport. |
246 else | 246 float step = scrollStep(granularity, orientation); |
247 orientation = HorizontalScrollbar; | |
248 | 247 |
249 if (layoutViewport().userInputScrollable(orientation) && visualViewport().us
erInputScrollable(orientation)) | 248 if (direction == ScrollUp || direction == ScrollLeft) |
250 return ScrollableArea::userScroll(direction, granularity, delta); | 249 delta = -delta; |
| 250 |
| 251 // This is the total amount we need to scroll. Instead of passing step |
| 252 // to the scroll animator and letting it compute the total delta, we |
| 253 // give it the delta it should scroll. This way we can apply the |
| 254 // unused delta from the visual viewport to the layout viewport. |
| 255 // TODO(ymalik): ScrollAnimator should return unused delta in pixles |
| 256 // rather than in terms of steps. |
| 257 delta *= step; |
| 258 |
| 259 cancelProgrammaticScrollAnimation(); |
| 260 |
| 261 float visualUsedDelta = visualViewport().scrollAnimator().computeDeltaTo
Consume(orientation, delta); |
| 262 ScrollResultOneDimensional visualResult = visualViewport().scrollAnimato
r().userScroll( |
| 263 orientation, granularity, 1 /* step */, visualUsedDelta); |
| 264 |
| 265 // Scroll the layout viewport if all of the scroll was not applied to th
e |
| 266 // visual viewport. |
| 267 if (visualUsedDelta == delta) |
| 268 return visualResult; |
| 269 |
| 270 ScrollResultOneDimensional layoutResult = layoutViewport().scrollAnimato
r().userScroll( |
| 271 orientation, granularity, 1 /* step */, delta - visualUsedDelta); |
| 272 |
| 273 return ScrollResultOneDimensional(visualResult.didScroll || layoutResult
.didScroll, |
| 274 layoutResult.unusedScrollDelta / step); |
| 275 } |
251 | 276 |
252 if (visualViewport().userInputScrollable(orientation)) | 277 if (visualViewport().userInputScrollable(orientation)) |
253 return visualViewport().userScroll(direction, granularity, delta); | 278 return visualViewport().userScroll(direction, granularity, delta); |
254 | 279 |
255 if (layoutViewport().userInputScrollable(orientation)) | 280 if (layoutViewport().userInputScrollable(orientation)) |
256 return layoutViewport().userScroll(direction, granularity, delta); | 281 return layoutViewport().userScroll(direction, granularity, delta); |
257 | 282 |
258 return ScrollResultOneDimensional(false, delta); | 283 return ScrollResultOneDimensional(false, delta); |
259 } | 284 } |
260 | 285 |
(...skipping 14 matching lines...) Expand all Loading... |
275 visualViewport().serviceScrollAnimations(monotonicTime); | 300 visualViewport().serviceScrollAnimations(monotonicTime); |
276 } | 301 } |
277 | 302 |
278 void RootFrameViewport::updateCompositorScrollAnimations() | 303 void RootFrameViewport::updateCompositorScrollAnimations() |
279 { | 304 { |
280 ScrollableArea::updateCompositorScrollAnimations(); | 305 ScrollableArea::updateCompositorScrollAnimations(); |
281 layoutViewport().updateCompositorScrollAnimations(); | 306 layoutViewport().updateCompositorScrollAnimations(); |
282 visualViewport().updateCompositorScrollAnimations(); | 307 visualViewport().updateCompositorScrollAnimations(); |
283 } | 308 } |
284 | 309 |
| 310 void RootFrameViewport::cancelProgrammaticScrollAnimation() |
| 311 { |
| 312 ScrollableArea::cancelProgrammaticScrollAnimation(); |
| 313 layoutViewport().cancelProgrammaticScrollAnimation(); |
| 314 visualViewport().cancelProgrammaticScrollAnimation(); |
| 315 } |
| 316 |
285 DEFINE_TRACE(RootFrameViewport) | 317 DEFINE_TRACE(RootFrameViewport) |
286 { | 318 { |
287 visitor->trace(m_visualViewport); | 319 visitor->trace(m_visualViewport); |
288 visitor->trace(m_layoutViewport); | 320 visitor->trace(m_layoutViewport); |
289 ScrollableArea::trace(visitor); | 321 ScrollableArea::trace(visitor); |
290 } | 322 } |
291 | 323 |
292 } // namespace blink | 324 } // namespace blink |
OLD | NEW |