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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 2775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2786 | 2786 |
2787 active_tree_->SetCurrentlyScrollingNode(scrolling_node); | 2787 active_tree_->SetCurrentlyScrollingNode(scrolling_node); |
2788 // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation | 2788 // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation |
2789 // in input_handler_proxy instead. | 2789 // in input_handler_proxy instead. |
2790 wheel_scrolling_ = IsWheelBasedScroll(type); | 2790 wheel_scrolling_ = IsWheelBasedScroll(type); |
2791 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); | 2791 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); |
2792 // Invoke |DistributeScrollDelta| even with zero delta and velocity to ensure | 2792 // Invoke |DistributeScrollDelta| even with zero delta and velocity to ensure |
2793 // scroll customization callbacks are invoked. | 2793 // scroll customization callbacks are invoked. |
2794 DistributeScrollDelta(scroll_state); | 2794 DistributeScrollDelta(scroll_state); |
2795 | 2795 |
2796 // If the CurrentlyScrollingNode doesn't exist after distributing scroll | |
2797 // delta, no scroller can scroll in the given delta hint direction(s). | |
2798 if (!active_tree_->CurrentlyScrollingNode()) { | |
2799 scroll_status.thread = InputHandler::SCROLL_IGNORED; | |
2800 scroll_status.main_thread_scrolling_reasons = | |
2801 MainThreadScrollingReason::kNotScrollingOnMain; | |
2802 return scroll_status; | |
2803 } | |
2804 | |
2796 client_->RenewTreePriority(); | 2805 client_->RenewTreePriority(); |
2797 RecordCompositorSlowScrollMetric(type, CC_THREAD); | 2806 RecordCompositorSlowScrollMetric(type, CC_THREAD); |
2798 | 2807 |
2799 UpdateScrollSourceInfo(wheel_scrolling_); | 2808 UpdateScrollSourceInfo(wheel_scrolling_); |
2800 | 2809 |
2801 return scroll_status; | 2810 return scroll_status; |
2802 } | 2811 } |
2803 | 2812 |
2804 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin( | 2813 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin( |
2805 ScrollState* scroll_state, | 2814 ScrollState* scroll_state, |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2913 } | 2922 } |
2914 | 2923 |
2915 // If |first_scrolling_layer_or_drawn_scrollbar| is not scrollable, it must | 2924 // If |first_scrolling_layer_or_drawn_scrollbar| is not scrollable, it must |
2916 // be a drawn scrollbar. These hit tests require falling back to main-thread | 2925 // be a drawn scrollbar. These hit tests require falling back to main-thread |
2917 // scrolling. | 2926 // scrolling. |
2918 DCHECK(first_scrolling_layer_or_drawn_scrollbar->IsDrawnScrollbar()); | 2927 DCHECK(first_scrolling_layer_or_drawn_scrollbar->IsDrawnScrollbar()); |
2919 return false; | 2928 return false; |
2920 } | 2929 } |
2921 | 2930 |
2922 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin( | 2931 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin( |
2923 const gfx::Point& viewport_point) { | 2932 ScrollState* scroll_state) { |
2924 InputHandler::ScrollStatus scroll_status; | 2933 InputHandler::ScrollStatus scroll_status; |
2925 scroll_status.main_thread_scrolling_reasons = | 2934 scroll_status.main_thread_scrolling_reasons = |
2926 MainThreadScrollingReason::kNotScrollingOnMain; | 2935 MainThreadScrollingReason::kNotScrollingOnMain; |
2927 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; | 2936 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; |
2928 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); | 2937 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); |
2929 if (scroll_node) { | 2938 if (scroll_node) { |
2930 gfx::Vector2dF delta; | 2939 gfx::Vector2dF delta; |
2931 | 2940 |
2932 if (ScrollAnimationUpdateTarget(scroll_node, delta, base::TimeDelta())) { | 2941 if (ScrollAnimationUpdateTarget(scroll_node, delta, base::TimeDelta())) { |
2933 scroll_status.thread = SCROLL_ON_IMPL_THREAD; | 2942 scroll_status.thread = SCROLL_ON_IMPL_THREAD; |
2934 } else { | 2943 } else { |
2935 scroll_status.thread = SCROLL_IGNORED; | 2944 scroll_status.thread = SCROLL_IGNORED; |
2936 scroll_status.main_thread_scrolling_reasons = | 2945 scroll_status.main_thread_scrolling_reasons = |
2937 MainThreadScrollingReason::kNotScrollable; | 2946 MainThreadScrollingReason::kNotScrollable; |
2938 } | 2947 } |
2939 return scroll_status; | 2948 return scroll_status; |
2940 } | 2949 } |
2941 ScrollStateData scroll_state_data; | |
2942 scroll_state_data.position_x = viewport_point.x(); | |
2943 scroll_state_data.position_y = viewport_point.y(); | |
2944 ScrollState scroll_state(scroll_state_data); | |
2945 | 2950 |
2946 // ScrollAnimated is used for animated wheel scrolls. We find the first layer | 2951 // ScrollAnimated is used for animated wheel scrolls. We find the first layer |
2947 // that can scroll and set up an animation of its scroll offset. Note that | 2952 // that can scroll and set up an animation of its scroll offset. Note that |
2948 // this does not currently go through the scroll customization machinery | 2953 // this does not currently go through the scroll customization machinery |
2949 // that ScrollBy uses for non-animated wheel scrolls. | 2954 // that ScrollBy uses for non-animated wheel scrolls. |
2950 scroll_status = ScrollBegin(&scroll_state, WHEEL); | 2955 scroll_status = ScrollBegin(scroll_state, WHEEL); |
2951 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { | 2956 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { |
2952 scroll_animating_latched_node_id_ = ScrollTree::kInvalidNodeId; | 2957 scroll_animating_latched_node_id_ = ScrollTree::kInvalidNodeId; |
2953 ScrollStateData scroll_state_end_data; | 2958 ScrollStateData scroll_state_end_data; |
2954 scroll_state_end_data.is_ending = true; | 2959 scroll_state_end_data.is_ending = true; |
2955 ScrollState scroll_state_end(scroll_state_end_data); | 2960 ScrollState scroll_state_end(scroll_state_end_data); |
2956 ScrollEnd(&scroll_state_end); | 2961 ScrollEnd(&scroll_state_end); |
2957 } | 2962 } |
2958 return scroll_status; | 2963 return scroll_status; |
2959 } | 2964 } |
2960 | 2965 |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3305 } | 3310 } |
3306 | 3311 |
3307 void LayerTreeHostImpl::DistributeScrollDelta(ScrollState* scroll_state) { | 3312 void LayerTreeHostImpl::DistributeScrollDelta(ScrollState* scroll_state) { |
3308 // TODO(majidvp): in Blink we compute scroll chain only at scroll begin which | 3313 // TODO(majidvp): in Blink we compute scroll chain only at scroll begin which |
3309 // is not the case here. We eventually want to have the same behaviour on both | 3314 // is not the case here. We eventually want to have the same behaviour on both |
3310 // sides but it may become a non issue if we get rid of scroll chaining (see | 3315 // sides but it may become a non issue if we get rid of scroll chaining (see |
3311 // crbug.com/526462) | 3316 // crbug.com/526462) |
3312 std::list<ScrollNode*> current_scroll_chain; | 3317 std::list<ScrollNode*> current_scroll_chain; |
3313 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; | 3318 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; |
3314 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); | 3319 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); |
3315 ScrollNode* viewport_scroll_node = OuterViewportScrollNode(); | 3320 ScrollNode* viewport_scroll_node = |
3321 viewport()->MainScrollLayer() | |
3322 ? scroll_tree.Node(viewport()->MainScrollLayer()->scroll_tree_index()) | |
3323 : nullptr; | |
3316 if (scroll_node) { | 3324 if (scroll_node) { |
3317 // TODO(bokan): The loop checks for a null parent but don't we still want to | 3325 // TODO(bokan): The loop checks for a null parent but don't we still want to |
3318 // distribute to the root scroll node? | 3326 // distribute to the root scroll node? |
3319 for (; scroll_tree.parent(scroll_node); | 3327 for (; scroll_tree.parent(scroll_node); |
3320 scroll_node = scroll_tree.parent(scroll_node)) { | 3328 scroll_node = scroll_tree.parent(scroll_node)) { |
3321 if (scroll_node == viewport_scroll_node) { | 3329 if (scroll_node == viewport_scroll_node) { |
3322 // Don't chain scrolls past the outer viewport scroll layer. Once we | 3330 // Don't chain scrolls past the outer viewport scroll layer. Once we |
3323 // reach that, we should scroll the viewport which is represented by the | 3331 // reach that, we should scroll the viewport which is represented by the |
3324 // main viewport scroll layer. | 3332 // main viewport scroll layer. |
3325 DCHECK(viewport_scroll_node); | 3333 DCHECK(viewport_scroll_node); |
3326 current_scroll_chain.push_front(viewport_scroll_node); | 3334 current_scroll_chain.push_front(viewport_scroll_node); |
3327 break; | 3335 break; |
3328 } | 3336 } |
3329 | 3337 |
3330 if (!scroll_node->scrollable) | 3338 if (!scroll_node->scrollable) |
3331 continue; | 3339 continue; |
3332 | 3340 |
3333 current_scroll_chain.push_front(scroll_node); | 3341 if (CanConsumeDelta(scroll_node, *scroll_state)) |
3342 current_scroll_chain.push_front(scroll_node); | |
3334 } | 3343 } |
3335 } | 3344 } |
3345 active_tree_->SetCurrentlyScrollingNode( | |
3346 current_scroll_chain.empty() ? nullptr : current_scroll_chain.back()); | |
3336 scroll_state->set_scroll_chain_and_layer_tree(current_scroll_chain, | 3347 scroll_state->set_scroll_chain_and_layer_tree(current_scroll_chain, |
3337 active_tree()); | 3348 active_tree()); |
3338 scroll_state->DistributeToScrollChainDescendant(); | 3349 scroll_state->DistributeToScrollChainDescendant(); |
3339 } | 3350 } |
3340 | 3351 |
3352 bool LayerTreeHostImpl::CanConsumeDelta(ScrollNode* scroll_node, | |
3353 const ScrollState& scroll_state) { | |
3354 gfx::Vector2dF delta_to_scroll; | |
3355 if (scroll_state.is_beginning()) { | |
3356 if (scroll_state.ignore_delta_hints()) | |
3357 return true; | |
3358 | |
3359 delta_to_scroll = gfx::Vector2dF(scroll_state.delta_x_hint(), | |
3360 scroll_state.delta_y_hint()); | |
3361 } else { | |
3362 delta_to_scroll = | |
3363 gfx::Vector2dF(scroll_state.delta_x(), scroll_state.delta_y()); | |
3364 } | |
3365 | |
3366 if (delta_to_scroll == gfx::Vector2dF()) | |
3367 return true; | |
3368 | |
3369 if (ComputeScrollDelta(scroll_node, delta_to_scroll) != gfx::Vector2dF()) | |
3370 return true; | |
3371 | |
3372 if (scroll_node->scrolls_inner_viewport) { | |
bokan
2017/06/19 21:43:17
I don't think you need this special case, at least
sahel
2017/06/22 16:34:17
I don't think ComputeScrollDelta checks for viewpo
bokan
2017/06/22 21:44:37
Sorry, I meant that we should add it to ComputeScr
sahel
2017/06/23 18:22:03
I deleted this special case, as we discussed alway
bokan
2017/06/23 18:56:44
Acknowledged.
| |
3373 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; | |
3374 ScrollNode* viewport_scroll_node = | |
3375 viewport()->MainScrollLayer() | |
3376 ? scroll_tree.Node( | |
3377 viewport()->MainScrollLayer()->scroll_tree_index()) | |
3378 : nullptr; | |
3379 if (viewport_scroll_node) | |
3380 return ComputeScrollDelta(viewport_scroll_node, delta_to_scroll) != | |
3381 gfx::Vector2dF(); | |
3382 } | |
3383 | |
3384 return false; | |
3385 } | |
3386 | |
3341 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( | 3387 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( |
3342 ScrollState* scroll_state) { | 3388 ScrollState* scroll_state) { |
3343 DCHECK(scroll_state); | 3389 DCHECK(scroll_state); |
3344 | 3390 |
3345 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); | 3391 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); |
3346 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; | 3392 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; |
3347 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); | 3393 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); |
3348 | 3394 |
3349 if (!scroll_node) | 3395 if (!scroll_node) |
3350 return InputHandlerScrollResult(); | 3396 return InputHandlerScrollResult(); |
(...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4312 | 4358 |
4313 void LayerTreeHostImpl::ShowScrollbarsForImplScroll(ElementId element_id) { | 4359 void LayerTreeHostImpl::ShowScrollbarsForImplScroll(ElementId element_id) { |
4314 if (!element_id) | 4360 if (!element_id) |
4315 return; | 4361 return; |
4316 if (ScrollbarAnimationController* animation_controller = | 4362 if (ScrollbarAnimationController* animation_controller = |
4317 ScrollbarAnimationControllerForElementId(element_id)) | 4363 ScrollbarAnimationControllerForElementId(element_id)) |
4318 animation_controller->DidScrollUpdate(); | 4364 animation_controller->DidScrollUpdate(); |
4319 } | 4365 } |
4320 | 4366 |
4321 } // namespace cc | 4367 } // namespace cc |
OLD | NEW |