OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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 "cc/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
399 base::TimeTicks monotonic_time = CurrentBeginFrameArgs().frame_time; | 399 base::TimeTicks monotonic_time = CurrentBeginFrameArgs().frame_time; |
400 | 400 |
401 // mithro(TODO): Enable these checks. | 401 // mithro(TODO): Enable these checks. |
402 // DCHECK(!current_begin_frame_tracker_.HasFinished()); | 402 // DCHECK(!current_begin_frame_tracker_.HasFinished()); |
403 // DCHECK(monotonic_time == current_begin_frame_tracker_.Current().frame_time) | 403 // DCHECK(monotonic_time == current_begin_frame_tracker_.Current().frame_time) |
404 // << "Called animate with unknown frame time!?"; | 404 // << "Called animate with unknown frame time!?"; |
405 | 405 |
406 if (input_handler_client_) { | 406 if (input_handler_client_) { |
407 // This animates fling scrolls. But on Android WebView root flings are | 407 // This animates fling scrolls. But on Android WebView root flings are |
408 // controlled by the application, so the compositor does not animate them. | 408 // controlled by the application, so the compositor does not animate them. |
409 bool ignore_fling = | 409 bool ignore_fling = settings_.ignore_root_layer_flings && |
410 settings_.ignore_root_layer_flings && IsCurrentlyScrollingRoot(); | 410 IsCurrentlyScrollingInnerViewport(); |
411 if (!ignore_fling) | 411 if (!ignore_fling) |
412 input_handler_client_->Animate(monotonic_time); | 412 input_handler_client_->Animate(monotonic_time); |
413 } | 413 } |
414 | 414 |
415 AnimatePageScale(monotonic_time); | 415 AnimatePageScale(monotonic_time); |
416 AnimateLayers(monotonic_time); | 416 AnimateLayers(monotonic_time); |
417 AnimateScrollbars(monotonic_time); | 417 AnimateScrollbars(monotonic_time); |
418 AnimateTopControls(monotonic_time); | 418 AnimateTopControls(monotonic_time); |
419 | 419 |
420 // Animating stuff can change the root scroll offset, so inform the | 420 // Animating stuff can change the root scroll offset, so inform the |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 page_scale, | 468 page_scale, |
469 duration.InSecondsF()); | 469 duration.InSecondsF()); |
470 } | 470 } |
471 | 471 |
472 SetNeedsAnimate(); | 472 SetNeedsAnimate(); |
473 client_->SetNeedsCommitOnImplThread(); | 473 client_->SetNeedsCommitOnImplThread(); |
474 client_->RenewTreePriority(); | 474 client_->RenewTreePriority(); |
475 } | 475 } |
476 | 476 |
477 void LayerTreeHostImpl::SetNeedsAnimateInput() { | 477 void LayerTreeHostImpl::SetNeedsAnimateInput() { |
478 DCHECK_IMPLIES(IsCurrentlyScrollingRoot(), | 478 DCHECK_IMPLIES(IsCurrentlyScrollingInnerViewport(), |
479 !settings_.ignore_root_layer_flings); | 479 !settings_.ignore_root_layer_flings); |
480 SetNeedsAnimate(); | 480 SetNeedsAnimate(); |
481 } | 481 } |
482 | 482 |
483 bool LayerTreeHostImpl::IsCurrentlyScrollingRoot() const { | 483 bool LayerTreeHostImpl::IsCurrentlyScrollingInnerViewport() const { |
484 LayerImpl* scrolling_layer = CurrentlyScrollingLayer(); | 484 LayerImpl* scrolling_layer = CurrentlyScrollingLayer(); |
485 if (!scrolling_layer) | 485 if (!scrolling_layer) |
486 return false; | 486 return false; |
487 return scrolling_layer == InnerViewportScrollLayer(); | 487 return scrolling_layer == InnerViewportScrollLayer(); |
488 } | 488 } |
489 | 489 |
490 bool LayerTreeHostImpl::IsCurrentlyScrollingLayerAt( | 490 bool LayerTreeHostImpl::IsCurrentlyScrollingLayerAt( |
491 const gfx::Point& viewport_point, | 491 const gfx::Point& viewport_point, |
492 InputHandler::ScrollInputType type) const { | 492 InputHandler::ScrollInputType type) const { |
493 LayerImpl* scrolling_layer_impl = CurrentlyScrollingLayer(); | 493 LayerImpl* scrolling_layer_impl = CurrentlyScrollingLayer(); |
(...skipping 1365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 LayerImpl* LayerTreeHostImpl::CurrentlyScrollingLayer() const { | 1859 LayerImpl* LayerTreeHostImpl::CurrentlyScrollingLayer() const { |
1860 return active_tree_->CurrentlyScrollingLayer(); | 1860 return active_tree_->CurrentlyScrollingLayer(); |
1861 } | 1861 } |
1862 | 1862 |
1863 bool LayerTreeHostImpl::IsActivelyScrolling() const { | 1863 bool LayerTreeHostImpl::IsActivelyScrolling() const { |
1864 if (!CurrentlyScrollingLayer()) | 1864 if (!CurrentlyScrollingLayer()) |
1865 return false; | 1865 return false; |
1866 // On Android WebView root flings are controlled by the application, | 1866 // On Android WebView root flings are controlled by the application, |
1867 // so the compositor does not animate them and can't tell if they | 1867 // so the compositor does not animate them and can't tell if they |
1868 // are actually animating. So assume there are none. | 1868 // are actually animating. So assume there are none. |
1869 if (settings_.ignore_root_layer_flings && IsCurrentlyScrollingRoot()) | 1869 if (settings_.ignore_root_layer_flings && IsCurrentlyScrollingInnerViewport()) |
1870 return false; | 1870 return false; |
1871 return did_lock_scrolling_layer_; | 1871 return did_lock_scrolling_layer_; |
1872 } | 1872 } |
1873 | 1873 |
1874 // Content layers can be either directly scrollable or contained in an outer | 1874 // Content layers can be either directly scrollable or contained in an outer |
1875 // scrolling layer which applies the scroll transform. Given a content layer, | 1875 // scrolling layer which applies the scroll transform. Given a content layer, |
1876 // this function returns the associated scroll layer if any. | 1876 // this function returns the associated scroll layer if any. |
1877 static LayerImpl* FindScrollLayerForContentLayer(LayerImpl* layer_impl) { | 1877 static LayerImpl* FindScrollLayerForContentLayer(LayerImpl* layer_impl) { |
1878 if (!layer_impl) | 1878 if (!layer_impl) |
1879 return NULL; | 1879 return NULL; |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2389 // notifications while preventing scroll updates from being unintentionally | 2389 // notifications while preventing scroll updates from being unintentionally |
2390 // forwarded to the main thread. The inner viewport layer represents the | 2390 // forwarded to the main thread. The inner viewport layer represents the |
2391 // viewport during scrolling. | 2391 // viewport during scrolling. |
2392 if (!potentially_scrolling_layer_impl) | 2392 if (!potentially_scrolling_layer_impl) |
2393 potentially_scrolling_layer_impl = InnerViewportScrollLayer(); | 2393 potentially_scrolling_layer_impl = InnerViewportScrollLayer(); |
2394 | 2394 |
2395 // The inner viewport layer represents the viewport. | 2395 // The inner viewport layer represents the viewport. |
2396 if (potentially_scrolling_layer_impl == OuterViewportScrollLayer()) | 2396 if (potentially_scrolling_layer_impl == OuterViewportScrollLayer()) |
2397 potentially_scrolling_layer_impl = InnerViewportScrollLayer(); | 2397 potentially_scrolling_layer_impl = InnerViewportScrollLayer(); |
2398 | 2398 |
| 2399 // Animated wheel scrolls need to scroll the outer viewport layer, and do not |
| 2400 // go through Viewport::ScrollBy which would normally handle the distribution. |
| 2401 // NOTE: This will need refactoring if we want smooth scrolling on Android. |
| 2402 if (type == ANIMATED_WHEEL && |
| 2403 potentially_scrolling_layer_impl == InnerViewportScrollLayer()) { |
| 2404 potentially_scrolling_layer_impl = OuterViewportScrollLayer(); |
| 2405 } |
| 2406 |
2399 return potentially_scrolling_layer_impl; | 2407 return potentially_scrolling_layer_impl; |
2400 } | 2408 } |
2401 | 2409 |
2402 // Similar to LayerImpl::HasAncestor, but walks up the scroll parents. | 2410 // Similar to LayerImpl::HasAncestor, but walks up the scroll parents. |
2403 static bool HasScrollAncestor(LayerImpl* child, LayerImpl* scroll_ancestor) { | 2411 static bool HasScrollAncestor(LayerImpl* child, LayerImpl* scroll_ancestor) { |
2404 DCHECK(scroll_ancestor); | 2412 DCHECK(scroll_ancestor); |
2405 for (LayerImpl* ancestor = child; ancestor; | 2413 for (LayerImpl* ancestor = child; ancestor; |
2406 ancestor = NextLayerInScrollOrder(ancestor)) { | 2414 ancestor = NextLayerInScrollOrder(ancestor)) { |
2407 if (ancestor->scrollable()) | 2415 if (ancestor->scrollable()) |
2408 return ancestor == scroll_ancestor; | 2416 return ancestor == scroll_ancestor; |
2409 } | 2417 } |
2410 return false; | 2418 return false; |
2411 } | 2419 } |
2412 | 2420 |
2413 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBeginImpl( | 2421 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBeginImpl( |
2414 LayerImpl* scrolling_layer_impl, | 2422 LayerImpl* scrolling_layer_impl, |
2415 InputHandler::ScrollInputType type) { | 2423 InputHandler::ScrollInputType type) { |
2416 if (!scrolling_layer_impl) | 2424 if (!scrolling_layer_impl) |
2417 return SCROLL_IGNORED; | 2425 return SCROLL_IGNORED; |
2418 | 2426 |
2419 top_controls_manager_->ScrollBegin(); | 2427 top_controls_manager_->ScrollBegin(); |
2420 | 2428 |
2421 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl); | 2429 active_tree_->SetCurrentlyScrollingLayer(scrolling_layer_impl); |
2422 wheel_scrolling_ = (type == WHEEL); | 2430 wheel_scrolling_ = (type == WHEEL || type == ANIMATED_WHEEL); |
2423 client_->RenewTreePriority(); | 2431 client_->RenewTreePriority(); |
2424 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); | 2432 UMA_HISTOGRAM_BOOLEAN("TryScroll.SlowScroll", false); |
2425 return SCROLL_STARTED; | 2433 return SCROLL_STARTED; |
2426 } | 2434 } |
2427 | 2435 |
2428 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin( | 2436 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin( |
2429 InputHandler::ScrollInputType type) { | 2437 InputHandler::ScrollInputType type) { |
2430 TRACE_EVENT0("cc", "LayerTreeHostImpl::RootScrollBegin"); | 2438 TRACE_EVENT0("cc", "LayerTreeHostImpl::RootScrollBegin"); |
2431 | 2439 |
2432 DCHECK(!CurrentlyScrollingLayer()); | 2440 DCHECK(!CurrentlyScrollingLayer()); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2470 } | 2478 } |
2471 | 2479 |
2472 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated( | 2480 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated( |
2473 const gfx::Point& viewport_point, | 2481 const gfx::Point& viewport_point, |
2474 const gfx::Vector2dF& scroll_delta) { | 2482 const gfx::Vector2dF& scroll_delta) { |
2475 if (LayerImpl* layer_impl = CurrentlyScrollingLayer()) { | 2483 if (LayerImpl* layer_impl = CurrentlyScrollingLayer()) { |
2476 return ScrollAnimationUpdateTarget(layer_impl, scroll_delta) | 2484 return ScrollAnimationUpdateTarget(layer_impl, scroll_delta) |
2477 ? SCROLL_STARTED | 2485 ? SCROLL_STARTED |
2478 : SCROLL_IGNORED; | 2486 : SCROLL_IGNORED; |
2479 } | 2487 } |
2480 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling | 2488 // ScrollAnimated is used for animated wheel scrolls. We find the first layer |
2481 // behavior as ScrollBy to determine which layer to animate, but we do not | 2489 // that can scroll and set up an animation of its scroll offset. Note that |
2482 // do the Android-specific things in ScrollBy like showing top controls. | 2490 // this does not currently go through the scroll customization and viewport |
2483 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, WHEEL); | 2491 // machinery that ScrollBy uses for non-animated wheel scrolls. |
| 2492 InputHandler::ScrollStatus scroll_status = |
| 2493 ScrollBegin(viewport_point, ANIMATED_WHEEL); |
2484 if (scroll_status == SCROLL_STARTED) { | 2494 if (scroll_status == SCROLL_STARTED) { |
2485 gfx::Vector2dF pending_delta = scroll_delta; | 2495 gfx::Vector2dF pending_delta = scroll_delta; |
2486 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; | 2496 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; |
2487 layer_impl = NextLayerInScrollOrder(layer_impl)) { | 2497 layer_impl = NextLayerInScrollOrder(layer_impl)) { |
2488 // The inner viewport layer represents the viewport. | 2498 if (!layer_impl->scrollable()) |
2489 if (!layer_impl->scrollable() || layer_impl == OuterViewportScrollLayer()) | |
2490 continue; | 2499 continue; |
2491 | 2500 |
2492 gfx::ScrollOffset current_offset = layer_impl->CurrentScrollOffset(); | 2501 gfx::ScrollOffset current_offset = layer_impl->CurrentScrollOffset(); |
2493 gfx::ScrollOffset target_offset = | 2502 gfx::ScrollOffset target_offset = |
2494 ScrollOffsetWithDelta(current_offset, pending_delta); | 2503 ScrollOffsetWithDelta(current_offset, pending_delta); |
2495 target_offset.SetToMax(gfx::ScrollOffset()); | 2504 target_offset.SetToMax(gfx::ScrollOffset()); |
2496 target_offset.SetToMin(layer_impl->MaxScrollOffset()); | 2505 target_offset.SetToMin(layer_impl->MaxScrollOffset()); |
2497 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset); | 2506 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset); |
2498 | 2507 |
2499 const float kEpsilon = 0.1f; | 2508 const float kEpsilon = 0.1f; |
(...skipping 1108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3608 if (active_tree()) { | 3617 if (active_tree()) { |
3609 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); | 3618 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); |
3610 if (layer) | 3619 if (layer) |
3611 return layer->ScrollOffsetForAnimation(); | 3620 return layer->ScrollOffsetForAnimation(); |
3612 } | 3621 } |
3613 | 3622 |
3614 return gfx::ScrollOffset(); | 3623 return gfx::ScrollOffset(); |
3615 } | 3624 } |
3616 | 3625 |
3617 } // namespace cc | 3626 } // namespace cc |
OLD | NEW |