Chromium Code Reviews| 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 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 489 client_->RenewTreePriority(); | 489 client_->RenewTreePriority(); |
| 490 } | 490 } |
| 491 | 491 |
| 492 void LayerTreeHostImpl::SetNeedsAnimateInput() { | 492 void LayerTreeHostImpl::SetNeedsAnimateInput() { |
| 493 DCHECK_IMPLIES(IsCurrentlyScrollingRoot(), | 493 DCHECK_IMPLIES(IsCurrentlyScrollingRoot(), |
| 494 !settings_.ignore_root_layer_flings); | 494 !settings_.ignore_root_layer_flings); |
| 495 SetNeedsAnimate(); | 495 SetNeedsAnimate(); |
| 496 } | 496 } |
| 497 | 497 |
| 498 bool LayerTreeHostImpl::IsCurrentlyScrollingRoot() const { | 498 bool LayerTreeHostImpl::IsCurrentlyScrollingRoot() const { |
| 499 LayerImpl* scrolling_layer = CurrentlyScrollingLayer(); | 499 return CurrentlyScrollingLayer() == InnerViewportScrollLayer(); |
|
bokan
2015/09/25 17:37:10
Could you keep the NULL check? If this ever gets c
tdresser
2015/09/25 17:41:43
Done.
| |
| 500 if (!scrolling_layer) | |
| 501 return false; | |
| 502 return scrolling_layer == InnerViewportScrollLayer() || | |
| 503 scrolling_layer == OuterViewportScrollLayer(); | |
| 504 } | 500 } |
| 505 | 501 |
| 506 bool LayerTreeHostImpl::IsCurrentlyScrollingLayerAt( | 502 bool LayerTreeHostImpl::IsCurrentlyScrollingLayerAt( |
| 507 const gfx::Point& viewport_point, | 503 const gfx::Point& viewport_point, |
| 508 InputHandler::ScrollInputType type) const { | 504 InputHandler::ScrollInputType type) const { |
| 509 LayerImpl* scrolling_layer_impl = CurrentlyScrollingLayer(); | 505 LayerImpl* scrolling_layer_impl = CurrentlyScrollingLayer(); |
| 510 if (!scrolling_layer_impl) | 506 if (!scrolling_layer_impl) |
| 511 return false; | 507 return false; |
| 512 | 508 |
| 513 gfx::PointF device_viewport_point = | 509 gfx::PointF device_viewport_point = |
| (...skipping 1852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2366 *optional_has_ancestor_scroll_handler = true; | 2362 *optional_has_ancestor_scroll_handler = true; |
| 2367 | 2363 |
| 2368 if (status == SCROLL_STARTED && !potentially_scrolling_layer_impl) | 2364 if (status == SCROLL_STARTED && !potentially_scrolling_layer_impl) |
| 2369 potentially_scrolling_layer_impl = scroll_layer_impl; | 2365 potentially_scrolling_layer_impl = scroll_layer_impl; |
| 2370 } | 2366 } |
| 2371 | 2367 |
| 2372 // Falling back to the root scroll layer ensures generation of root overscroll | 2368 // Falling back to the root scroll layer ensures generation of root overscroll |
| 2373 // notifications while preventing scroll updates from being unintentionally | 2369 // notifications while preventing scroll updates from being unintentionally |
| 2374 // forwarded to the main thread. | 2370 // forwarded to the main thread. |
| 2375 if (!potentially_scrolling_layer_impl) | 2371 if (!potentially_scrolling_layer_impl) |
| 2376 potentially_scrolling_layer_impl = OuterViewportScrollLayer() | 2372 potentially_scrolling_layer_impl = InnerViewportScrollLayer(); |
| 2377 ? OuterViewportScrollLayer() | 2373 |
| 2378 : InnerViewportScrollLayer(); | 2374 // The inner viewport layer represents the viewport. |
| 2375 if (potentially_scrolling_layer_impl == OuterViewportScrollLayer()) | |
| 2376 potentially_scrolling_layer_impl = InnerViewportScrollLayer(); | |
| 2379 | 2377 |
| 2380 return potentially_scrolling_layer_impl; | 2378 return potentially_scrolling_layer_impl; |
| 2381 } | 2379 } |
| 2382 | 2380 |
| 2383 // Similar to LayerImpl::HasAncestor, but walks up the scroll parents. | 2381 // Similar to LayerImpl::HasAncestor, but walks up the scroll parents. |
| 2384 static bool HasScrollAncestor(LayerImpl* child, LayerImpl* scroll_ancestor) { | 2382 static bool HasScrollAncestor(LayerImpl* child, LayerImpl* scroll_ancestor) { |
| 2385 DCHECK(scroll_ancestor); | 2383 DCHECK(scroll_ancestor); |
| 2386 for (LayerImpl* ancestor = child; ancestor; | 2384 for (LayerImpl* ancestor = child; ancestor; |
| 2387 ancestor = NextLayerInScrollOrder(ancestor)) { | 2385 ancestor = NextLayerInScrollOrder(ancestor)) { |
| 2388 if (ancestor->scrollable()) | 2386 if (ancestor->scrollable()) |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2459 ? SCROLL_STARTED | 2457 ? SCROLL_STARTED |
| 2460 : SCROLL_IGNORED; | 2458 : SCROLL_IGNORED; |
| 2461 } | 2459 } |
| 2462 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling | 2460 // ScrollAnimated is only used for wheel scrolls. We use the same bubbling |
| 2463 // behavior as ScrollBy to determine which layer to animate, but we do not | 2461 // behavior as ScrollBy to determine which layer to animate, but we do not |
| 2464 // do the Android-specific things in ScrollBy like showing top controls. | 2462 // do the Android-specific things in ScrollBy like showing top controls. |
| 2465 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, WHEEL); | 2463 InputHandler::ScrollStatus scroll_status = ScrollBegin(viewport_point, WHEEL); |
| 2466 if (scroll_status == SCROLL_STARTED) { | 2464 if (scroll_status == SCROLL_STARTED) { |
| 2467 gfx::Vector2dF pending_delta = scroll_delta; | 2465 gfx::Vector2dF pending_delta = scroll_delta; |
| 2468 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; | 2466 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; |
| 2469 layer_impl = layer_impl->parent()) { | 2467 layer_impl = NextLayerInScrollOrder(layer_impl)) { |
| 2470 if (!layer_impl->scrollable()) | 2468 // The inner viewport layer represents the viewport. |
| 2469 if (!layer_impl->scrollable() || layer_impl == OuterViewportScrollLayer()) | |
| 2471 continue; | 2470 continue; |
| 2472 | 2471 |
| 2473 gfx::ScrollOffset current_offset = layer_impl->CurrentScrollOffset(); | 2472 gfx::ScrollOffset current_offset = layer_impl->CurrentScrollOffset(); |
| 2474 gfx::ScrollOffset target_offset = | 2473 gfx::ScrollOffset target_offset = |
| 2475 ScrollOffsetWithDelta(current_offset, pending_delta); | 2474 ScrollOffsetWithDelta(current_offset, pending_delta); |
| 2476 target_offset.SetToMax(gfx::ScrollOffset()); | 2475 target_offset.SetToMax(gfx::ScrollOffset()); |
| 2477 target_offset.SetToMin(layer_impl->MaxScrollOffset()); | 2476 target_offset.SetToMin(layer_impl->MaxScrollOffset()); |
| 2478 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset); | 2477 gfx::Vector2dF actual_delta = target_offset.DeltaFrom(current_offset); |
| 2479 | 2478 |
| 2480 const float kEpsilon = 0.1f; | 2479 const float kEpsilon = 0.1f; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2736 return scroll_result; | 2735 return scroll_result; |
| 2737 } | 2736 } |
| 2738 | 2737 |
| 2739 // This implements scrolling by page as described here: | 2738 // This implements scrolling by page as described here: |
| 2740 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).asp x#_win32_The_Mouse_Wheel | 2739 // http://msdn.microsoft.com/en-us/library/windows/desktop/ms645601(v=vs.85).asp x#_win32_The_Mouse_Wheel |
| 2741 // for events with WHEEL_PAGESCROLL set. | 2740 // for events with WHEEL_PAGESCROLL set. |
| 2742 bool LayerTreeHostImpl::ScrollVerticallyByPage(const gfx::Point& viewport_point, | 2741 bool LayerTreeHostImpl::ScrollVerticallyByPage(const gfx::Point& viewport_point, |
| 2743 ScrollDirection direction) { | 2742 ScrollDirection direction) { |
| 2744 DCHECK(wheel_scrolling_); | 2743 DCHECK(wheel_scrolling_); |
| 2745 | 2744 |
| 2746 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); | 2745 for (LayerImpl* layer_impl = CurrentlyScrollingLayer(); layer_impl; |
| 2747 layer_impl; | 2746 layer_impl = NextLayerInScrollOrder(layer_impl)) { |
| 2748 layer_impl = layer_impl->parent()) { | 2747 // The inner viewport layer represents the viewport. |
| 2749 if (!layer_impl->scrollable()) | 2748 if (!layer_impl->scrollable() || layer_impl == OuterViewportScrollLayer()) |
| 2750 continue; | 2749 continue; |
| 2751 | 2750 |
| 2752 if (!layer_impl->HasScrollbar(VERTICAL)) | 2751 if (!layer_impl->HasScrollbar(VERTICAL)) |
| 2753 continue; | 2752 continue; |
| 2754 | 2753 |
| 2755 float height = layer_impl->clip_height(); | 2754 float height = layer_impl->clip_height(); |
| 2756 | 2755 |
| 2757 // These magical values match WebKit and are designed to scroll nearly the | 2756 // These magical values match WebKit and are designed to scroll nearly the |
| 2758 // entire visible content height but leave a bit of overlap. | 2757 // entire visible content height but leave a bit of overlap. |
| 2759 float page = std::max(height * 0.875f, 1.f); | 2758 float page = std::max(height * 0.875f, 1.f); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2803 void LayerTreeHostImpl::ScrollEnd() { | 2802 void LayerTreeHostImpl::ScrollEnd() { |
| 2804 top_controls_manager_->ScrollEnd(); | 2803 top_controls_manager_->ScrollEnd(); |
| 2805 ClearCurrentlyScrollingLayer(); | 2804 ClearCurrentlyScrollingLayer(); |
| 2806 } | 2805 } |
| 2807 | 2806 |
| 2808 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { | 2807 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { |
| 2809 if (!CurrentlyScrollingLayer()) | 2808 if (!CurrentlyScrollingLayer()) |
| 2810 return SCROLL_IGNORED; | 2809 return SCROLL_IGNORED; |
| 2811 | 2810 |
| 2812 bool currently_scrolling_viewport = | 2811 bool currently_scrolling_viewport = |
| 2813 CurrentlyScrollingLayer() == OuterViewportScrollLayer() || | |
| 2814 CurrentlyScrollingLayer() == InnerViewportScrollLayer(); | 2812 CurrentlyScrollingLayer() == InnerViewportScrollLayer(); |
| 2815 if (!wheel_scrolling_ && !currently_scrolling_viewport) { | 2813 if (!wheel_scrolling_ && !currently_scrolling_viewport) { |
| 2816 // Allow the fling to lock to the first layer that moves after the initial | 2814 // Allow the fling to lock to the first layer that moves after the initial |
| 2817 // fling |ScrollBy()| event, unless we're already scrolling the viewport. | 2815 // fling |ScrollBy()| event, unless we're already scrolling the viewport. |
| 2818 did_lock_scrolling_layer_ = false; | 2816 did_lock_scrolling_layer_ = false; |
| 2819 should_bubble_scrolls_ = false; | 2817 should_bubble_scrolls_ = false; |
| 2820 } | 2818 } |
| 2821 | 2819 |
| 2822 return SCROLL_STARTED; | 2820 return SCROLL_STARTED; |
| 2823 } | 2821 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2901 return true; | 2899 return true; |
| 2902 } | 2900 } |
| 2903 | 2901 |
| 2904 return false; | 2902 return false; |
| 2905 } | 2903 } |
| 2906 | 2904 |
| 2907 void LayerTreeHostImpl::PinchGestureBegin() { | 2905 void LayerTreeHostImpl::PinchGestureBegin() { |
| 2908 pinch_gesture_active_ = true; | 2906 pinch_gesture_active_ = true; |
| 2909 client_->RenewTreePriority(); | 2907 client_->RenewTreePriority(); |
| 2910 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer(); | 2908 pinch_gesture_end_should_clear_scrolling_layer_ = !CurrentlyScrollingLayer(); |
| 2911 if (active_tree_->OuterViewportScrollLayer()) { | 2909 active_tree_->SetCurrentlyScrollingLayer( |
| 2912 active_tree_->SetCurrentlyScrollingLayer( | 2910 active_tree_->InnerViewportScrollLayer()); |
| 2913 active_tree_->OuterViewportScrollLayer()); | |
| 2914 } else { | |
| 2915 active_tree_->SetCurrentlyScrollingLayer( | |
| 2916 active_tree_->InnerViewportScrollLayer()); | |
| 2917 } | |
| 2918 top_controls_manager_->PinchBegin(); | 2911 top_controls_manager_->PinchBegin(); |
| 2919 } | 2912 } |
| 2920 | 2913 |
| 2921 void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta, | 2914 void LayerTreeHostImpl::PinchGestureUpdate(float magnify_delta, |
| 2922 const gfx::Point& anchor) { | 2915 const gfx::Point& anchor) { |
| 2923 TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate"); | 2916 TRACE_EVENT0("cc", "LayerTreeHostImpl::PinchGestureUpdate"); |
| 2924 if (!InnerViewportScrollLayer()) | 2917 if (!InnerViewportScrollLayer()) |
| 2925 return; | 2918 return; |
| 2926 viewport()->PinchUpdate(magnify_delta, anchor); | 2919 viewport()->PinchUpdate(magnify_delta, anchor); |
| 2927 client_->SetNeedsCommitOnImplThread(); | 2920 client_->SetNeedsCommitOnImplThread(); |
| (...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3614 if (active_tree()) { | 3607 if (active_tree()) { |
| 3615 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); | 3608 LayerAnimationValueProvider* layer = active_tree()->LayerById(layer_id); |
| 3616 if (layer) | 3609 if (layer) |
| 3617 return layer->ScrollOffsetForAnimation(); | 3610 return layer->ScrollOffsetForAnimation(); |
| 3618 } | 3611 } |
| 3619 | 3612 |
| 3620 return gfx::ScrollOffset(); | 3613 return gfx::ScrollOffset(); |
| 3621 } | 3614 } |
| 3622 | 3615 |
| 3623 } // namespace cc | 3616 } // namespace cc |
| OLD | NEW |