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 2752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2763 | 2763 |
2764 active_tree_->SetCurrentlyScrollingNode(scrolling_node); | 2764 active_tree_->SetCurrentlyScrollingNode(scrolling_node); |
2765 // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation | 2765 // TODO(majidvp): get rid of wheel_scrolling_ and set is_direct_manipulation |
2766 // in input_handler_proxy instead. | 2766 // in input_handler_proxy instead. |
2767 wheel_scrolling_ = IsWheelBasedScroll(type); | 2767 wheel_scrolling_ = IsWheelBasedScroll(type); |
2768 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); | 2768 scroll_state->set_is_direct_manipulation(!wheel_scrolling_); |
2769 // Invoke |DistributeScrollDelta| even with zero delta and velocity to ensure | 2769 // Invoke |DistributeScrollDelta| even with zero delta and velocity to ensure |
2770 // scroll customization callbacks are invoked. | 2770 // scroll customization callbacks are invoked. |
2771 DistributeScrollDelta(scroll_state); | 2771 DistributeScrollDelta(scroll_state); |
2772 | 2772 |
2773 // If the CurrentlyScrollingNode doesn't exist after distributing scroll | |
2774 // delta, no scroller can scroll in the given delta hint direction(s). | |
2775 if (!active_tree_->CurrentlyScrollingNode()) { | |
2776 scroll_status.thread = InputHandler::SCROLL_IGNORED; | |
2777 scroll_status.main_thread_scrolling_reasons = | |
2778 MainThreadScrollingReason::kNotScrollingOnMain; | |
2779 return scroll_status; | |
2780 } | |
2781 | |
2773 client_->RenewTreePriority(); | 2782 client_->RenewTreePriority(); |
2774 RecordCompositorSlowScrollMetric(type, CC_THREAD); | 2783 RecordCompositorSlowScrollMetric(type, CC_THREAD); |
2775 | 2784 |
2776 UpdateScrollSourceInfo(wheel_scrolling_); | 2785 UpdateScrollSourceInfo(wheel_scrolling_); |
2777 | 2786 |
2778 return scroll_status; | 2787 return scroll_status; |
2779 } | 2788 } |
2780 | 2789 |
2781 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin( | 2790 InputHandler::ScrollStatus LayerTreeHostImpl::RootScrollBegin( |
2782 ScrollState* scroll_state, | 2791 ScrollState* scroll_state, |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2889 } | 2898 } |
2890 | 2899 |
2891 // If |first_scrolling_layer_or_drawn_scrollbar| is not scrollable, it must | 2900 // If |first_scrolling_layer_or_drawn_scrollbar| is not scrollable, it must |
2892 // be a drawn scrollbar. These hit tests require falling back to main-thread | 2901 // be a drawn scrollbar. These hit tests require falling back to main-thread |
2893 // scrolling. | 2902 // scrolling. |
2894 DCHECK(first_scrolling_layer_or_drawn_scrollbar->IsDrawnScrollbar()); | 2903 DCHECK(first_scrolling_layer_or_drawn_scrollbar->IsDrawnScrollbar()); |
2895 return false; | 2904 return false; |
2896 } | 2905 } |
2897 | 2906 |
2898 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin( | 2907 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin( |
2899 const gfx::Point& viewport_point) { | 2908 ScrollState* scroll_state) { |
2900 InputHandler::ScrollStatus scroll_status; | 2909 InputHandler::ScrollStatus scroll_status; |
2901 scroll_status.main_thread_scrolling_reasons = | 2910 scroll_status.main_thread_scrolling_reasons = |
2902 MainThreadScrollingReason::kNotScrollingOnMain; | 2911 MainThreadScrollingReason::kNotScrollingOnMain; |
2903 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; | 2912 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; |
2904 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); | 2913 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); |
2905 if (scroll_node) { | 2914 if (scroll_node) { |
2906 gfx::Vector2dF delta; | 2915 gfx::Vector2dF delta; |
2907 | 2916 |
2908 if (ScrollAnimationUpdateTarget(scroll_node, delta, base::TimeDelta())) { | 2917 if (ScrollAnimationUpdateTarget(scroll_node, delta, base::TimeDelta())) { |
2909 scroll_status.thread = SCROLL_ON_IMPL_THREAD; | 2918 scroll_status.thread = SCROLL_ON_IMPL_THREAD; |
2910 } else { | 2919 } else { |
2911 scroll_status.thread = SCROLL_IGNORED; | 2920 scroll_status.thread = SCROLL_IGNORED; |
2912 scroll_status.main_thread_scrolling_reasons = | 2921 scroll_status.main_thread_scrolling_reasons = |
2913 MainThreadScrollingReason::kNotScrollable; | 2922 MainThreadScrollingReason::kNotScrollable; |
2914 } | 2923 } |
2915 return scroll_status; | 2924 return scroll_status; |
2916 } | 2925 } |
2917 ScrollStateData scroll_state_data; | |
2918 scroll_state_data.position_x = viewport_point.x(); | |
2919 scroll_state_data.position_y = viewport_point.y(); | |
2920 ScrollState scroll_state(scroll_state_data); | |
2921 | 2926 |
2922 // ScrollAnimated is used for animated wheel scrolls. We find the first layer | 2927 // ScrollAnimated is used for animated wheel scrolls. We find the first layer |
2923 // that can scroll and set up an animation of its scroll offset. Note that | 2928 // that can scroll and set up an animation of its scroll offset. Note that |
2924 // this does not currently go through the scroll customization machinery | 2929 // this does not currently go through the scroll customization machinery |
2925 // that ScrollBy uses for non-animated wheel scrolls. | 2930 // that ScrollBy uses for non-animated wheel scrolls. |
2926 scroll_status = ScrollBegin(&scroll_state, WHEEL); | 2931 scroll_status = ScrollBegin(scroll_state, WHEEL); |
2927 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { | 2932 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { |
2928 scroll_animating_latched_node_id_ = ScrollTree::kInvalidNodeId; | 2933 scroll_animating_latched_node_id_ = ScrollTree::kInvalidNodeId; |
2929 ScrollStateData scroll_state_end_data; | 2934 ScrollStateData scroll_state_end_data; |
2930 scroll_state_end_data.is_ending = true; | 2935 scroll_state_end_data.is_ending = true; |
2931 ScrollState scroll_state_end(scroll_state_end_data); | 2936 ScrollState scroll_state_end(scroll_state_end_data); |
2932 ScrollEnd(&scroll_state_end); | 2937 ScrollEnd(&scroll_state_end); |
2933 } | 2938 } |
2934 return scroll_status; | 2939 return scroll_status; |
2935 } | 2940 } |
2936 | 2941 |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3281 } | 3286 } |
3282 | 3287 |
3283 void LayerTreeHostImpl::DistributeScrollDelta(ScrollState* scroll_state) { | 3288 void LayerTreeHostImpl::DistributeScrollDelta(ScrollState* scroll_state) { |
3284 // TODO(majidvp): in Blink we compute scroll chain only at scroll begin which | 3289 // TODO(majidvp): in Blink we compute scroll chain only at scroll begin which |
3285 // is not the case here. We eventually want to have the same behaviour on both | 3290 // is not the case here. We eventually want to have the same behaviour on both |
3286 // sides but it may become a non issue if we get rid of scroll chaining (see | 3291 // sides but it may become a non issue if we get rid of scroll chaining (see |
3287 // crbug.com/526462) | 3292 // crbug.com/526462) |
3288 std::list<ScrollNode*> current_scroll_chain; | 3293 std::list<ScrollNode*> current_scroll_chain; |
3289 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; | 3294 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; |
3290 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); | 3295 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); |
3291 ScrollNode* viewport_scroll_node = OuterViewportScrollNode(); | 3296 ScrollNode* viewport_scroll_node = OuterViewportScrollNode(); |
bokan
2017/05/30 15:07:06
While you're here, please change this from OuterVi
sahel
2017/05/31 17:50:00
Done.
| |
3292 if (scroll_node) { | 3297 if (scroll_node) { |
3293 // TODO(bokan): The loop checks for a null parent but don't we still want to | 3298 // TODO(bokan): The loop checks for a null parent but don't we still want to |
3294 // distribute to the root scroll node? | 3299 // distribute to the root scroll node? |
3295 for (; scroll_tree.parent(scroll_node); | 3300 for (; scroll_tree.parent(scroll_node); |
3296 scroll_node = scroll_tree.parent(scroll_node)) { | 3301 scroll_node = scroll_tree.parent(scroll_node)) { |
3297 if (scroll_node == viewport_scroll_node) { | 3302 if (scroll_node == viewport_scroll_node) { |
3298 // Don't chain scrolls past the outer viewport scroll layer. Once we | 3303 // Don't chain scrolls past the outer viewport scroll layer. Once we |
3299 // reach that, we should scroll the viewport which is represented by the | 3304 // reach that, we should scroll the viewport which is represented by the |
3300 // main viewport scroll layer. | 3305 // main viewport scroll layer. |
3301 DCHECK(viewport_scroll_node); | 3306 DCHECK(viewport_scroll_node); |
3302 current_scroll_chain.push_front(viewport_scroll_node); | 3307 if (CanConsumeDelta(viewport_scroll_node, *scroll_state)) |
3308 current_scroll_chain.push_front(viewport_scroll_node); | |
3303 break; | 3309 break; |
3304 } | 3310 } |
3305 | 3311 |
3306 if (!scroll_node->scrollable) | 3312 if (!scroll_node->scrollable) |
3307 continue; | 3313 continue; |
3308 | 3314 |
3309 current_scroll_chain.push_front(scroll_node); | 3315 if (CanConsumeDelta(scroll_node, *scroll_state)) |
3316 current_scroll_chain.push_front(scroll_node); | |
3310 } | 3317 } |
3311 } | 3318 } |
3319 active_tree_->SetCurrentlyScrollingNode( | |
3320 current_scroll_chain.empty() ? nullptr : current_scroll_chain.back()); | |
3312 scroll_state->set_scroll_chain_and_layer_tree(current_scroll_chain, | 3321 scroll_state->set_scroll_chain_and_layer_tree(current_scroll_chain, |
3313 active_tree()); | 3322 active_tree()); |
3314 scroll_state->DistributeToScrollChainDescendant(); | 3323 scroll_state->DistributeToScrollChainDescendant(); |
3315 } | 3324 } |
3316 | 3325 |
3326 bool LayerTreeHostImpl::CanConsumeDelta(ScrollNode* scroll_node, | |
3327 const ScrollState& scroll_state) { | |
3328 gfx::Vector2dF delta_to_scroll; | |
3329 if (scroll_state.is_beginning()) { | |
3330 if (scroll_state.ignore_delta_hints()) | |
3331 return true; | |
3332 | |
3333 delta_to_scroll = gfx::Vector2dF(scroll_state.delta_x_hint(), | |
3334 scroll_state.delta_y_hint()); | |
3335 } else { | |
3336 delta_to_scroll = | |
3337 gfx::Vector2dF(scroll_state.delta_x(), scroll_state.delta_y()); | |
3338 } | |
3339 | |
3340 if (delta_to_scroll == gfx::Vector2dF()) | |
3341 return true; | |
3342 | |
3343 return ComputeScrollDelta(scroll_node, delta_to_scroll) != gfx::Vector2dF(); | |
3344 } | |
3345 | |
3317 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( | 3346 InputHandlerScrollResult LayerTreeHostImpl::ScrollBy( |
3318 ScrollState* scroll_state) { | 3347 ScrollState* scroll_state) { |
3319 DCHECK(scroll_state); | 3348 DCHECK(scroll_state); |
3320 | 3349 |
3321 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); | 3350 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBy"); |
3322 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; | 3351 ScrollTree& scroll_tree = active_tree_->property_trees()->scroll_tree; |
3323 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); | 3352 ScrollNode* scroll_node = scroll_tree.CurrentlyScrollingNode(); |
3324 | 3353 |
3325 if (!scroll_node) | 3354 if (!scroll_node) |
3326 return InputHandlerScrollResult(); | 3355 return InputHandlerScrollResult(); |
(...skipping 1020 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4347 | 4376 |
4348 void LayerTreeHostImpl::ShowScrollbarsForImplScroll(ElementId element_id) { | 4377 void LayerTreeHostImpl::ShowScrollbarsForImplScroll(ElementId element_id) { |
4349 if (!element_id) | 4378 if (!element_id) |
4350 return; | 4379 return; |
4351 if (ScrollbarAnimationController* animation_controller = | 4380 if (ScrollbarAnimationController* animation_controller = |
4352 ScrollbarAnimationControllerForElementId(element_id)) | 4381 ScrollbarAnimationControllerForElementId(element_id)) |
4353 animation_controller->DidScrollUpdate(); | 4382 animation_controller->DidScrollUpdate(); |
4354 } | 4383 } |
4355 | 4384 |
4356 } // namespace cc | 4385 } // namespace cc |
OLD | NEW |