| 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 2630 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2641 } | 2641 } |
| 2642 | 2642 |
| 2643 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( | 2643 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( |
| 2644 ScrollState* scroll_state, | 2644 ScrollState* scroll_state, |
| 2645 InputHandler::ScrollInputType type) { | 2645 InputHandler::ScrollInputType type) { |
| 2646 ScrollStatus scroll_status; | 2646 ScrollStatus scroll_status; |
| 2647 scroll_status.main_thread_scrolling_reasons = | 2647 scroll_status.main_thread_scrolling_reasons = |
| 2648 MainThreadScrollingReason::kNotScrollingOnMain; | 2648 MainThreadScrollingReason::kNotScrollingOnMain; |
| 2649 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); | 2649 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); |
| 2650 | 2650 |
| 2651 ClearCurrentlyScrollingLayer(); | 2651 LayerImpl* scrolling_layer_impl = nullptr; |
| 2652 bool scroll_on_main_thread = false; |
| 2652 | 2653 |
| 2653 gfx::Point viewport_point(scroll_state->position_x(), | 2654 if (scroll_state->is_in_inertial_phase()) |
| 2654 scroll_state->position_y()); | 2655 scrolling_layer_impl = CurrentlyScrollingLayer(); |
| 2655 | 2656 |
| 2656 gfx::PointF device_viewport_point = gfx::ScalePoint( | 2657 if (!scrolling_layer_impl) { |
| 2657 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); | 2658 ClearCurrentlyScrollingLayer(); |
| 2658 LayerImpl* layer_impl = | |
| 2659 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); | |
| 2660 | 2659 |
| 2661 if (layer_impl) { | 2660 gfx::Point viewport_point(scroll_state->position_x(), |
| 2662 LayerImpl* scroll_layer_impl = | 2661 scroll_state->position_y()); |
| 2663 active_tree_->FindFirstScrollingLayerOrScrollbarLayerThatIsHitByPoint( | 2662 |
| 2664 device_viewport_point); | 2663 gfx::PointF device_viewport_point = gfx::ScalePoint( |
| 2665 if (scroll_layer_impl && | 2664 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); |
| 2666 !HasScrollAncestor(layer_impl, scroll_layer_impl)) { | 2665 LayerImpl* layer_impl = |
| 2667 scroll_status.thread = SCROLL_UNKNOWN; | 2666 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); |
| 2668 scroll_status.main_thread_scrolling_reasons = | 2667 |
| 2669 MainThreadScrollingReason::kFailedHitTest; | 2668 if (layer_impl) { |
| 2670 return scroll_status; | 2669 LayerImpl* scroll_layer_impl = |
| 2670 active_tree_->FindFirstScrollingLayerOrScrollbarLayerThatIsHitByPoint( |
| 2671 device_viewport_point); |
| 2672 if (scroll_layer_impl && |
| 2673 !HasScrollAncestor(layer_impl, scroll_layer_impl)) { |
| 2674 scroll_status.thread = SCROLL_UNKNOWN; |
| 2675 scroll_status.main_thread_scrolling_reasons = |
| 2676 MainThreadScrollingReason::kFailedHitTest; |
| 2677 return scroll_status; |
| 2678 } |
| 2671 } | 2679 } |
| 2680 |
| 2681 scrolling_layer_impl = FindScrollLayerForDeviceViewportPoint( |
| 2682 device_viewport_point, type, layer_impl, &scroll_on_main_thread, |
| 2683 &scroll_status.main_thread_scrolling_reasons); |
| 2672 } | 2684 } |
| 2673 | |
| 2674 bool scroll_on_main_thread = false; | |
| 2675 LayerImpl* scrolling_layer_impl = FindScrollLayerForDeviceViewportPoint( | |
| 2676 device_viewport_point, type, layer_impl, &scroll_on_main_thread, | |
| 2677 &scroll_status.main_thread_scrolling_reasons); | |
| 2678 | |
| 2679 if (scrolling_layer_impl) | 2685 if (scrolling_layer_impl) |
| 2680 scroll_affects_scroll_handler_ = | 2686 scroll_affects_scroll_handler_ = |
| 2681 scrolling_layer_impl->layer_tree_impl()->have_scroll_event_handlers(); | 2687 scrolling_layer_impl->layer_tree_impl()->have_scroll_event_handlers(); |
| 2682 | 2688 |
| 2683 if (scroll_on_main_thread) { | 2689 if (scroll_on_main_thread) { |
| 2684 RecordCompositorSlowScrollMetric(type, MAIN_THREAD); | 2690 RecordCompositorSlowScrollMetric(type, MAIN_THREAD); |
| 2685 | 2691 |
| 2686 scroll_status.thread = SCROLL_ON_MAIN_THREAD; | 2692 scroll_status.thread = SCROLL_ON_MAIN_THREAD; |
| 2687 return scroll_status; | 2693 return scroll_status; |
| 2688 } | 2694 } |
| (...skipping 28 matching lines...) Expand all Loading... |
| 2717 // ScrollAnimated is used for animated wheel scrolls. We find the first layer | 2723 // ScrollAnimated is used for animated wheel scrolls. We find the first layer |
| 2718 // that can scroll and set up an animation of its scroll offset. Note that | 2724 // that can scroll and set up an animation of its scroll offset. Note that |
| 2719 // this does not currently go through the scroll customization machinery | 2725 // this does not currently go through the scroll customization machinery |
| 2720 // that ScrollBy uses for non-animated wheel scrolls. | 2726 // that ScrollBy uses for non-animated wheel scrolls. |
| 2721 scroll_status = ScrollBegin(&scroll_state, WHEEL); | 2727 scroll_status = ScrollBegin(&scroll_state, WHEEL); |
| 2722 scroll_node = scroll_tree.CurrentlyScrollingNode(); | 2728 scroll_node = scroll_tree.CurrentlyScrollingNode(); |
| 2723 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { | 2729 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { |
| 2724 ScrollStateData scroll_state_end_data; | 2730 ScrollStateData scroll_state_end_data; |
| 2725 scroll_state_end_data.is_ending = true; | 2731 scroll_state_end_data.is_ending = true; |
| 2726 ScrollState scroll_state_end(scroll_state_end_data); | 2732 ScrollState scroll_state_end(scroll_state_end_data); |
| 2727 // TODO(Sahel): Once the touchpad scroll latching for Non-mac devices is | |
| 2728 // implemented, the current scrolling layer should not get cleared after | |
| 2729 // each animation (crbug.com/526463). | |
| 2730 ScrollEnd(&scroll_state_end); | 2733 ScrollEnd(&scroll_state_end); |
| 2731 ClearCurrentlyScrollingLayer(); | |
| 2732 } | 2734 } |
| 2733 return scroll_status; | 2735 return scroll_status; |
| 2734 } | 2736 } |
| 2735 | 2737 |
| 2736 gfx::Vector2dF LayerTreeHostImpl::ComputeScrollDelta( | 2738 gfx::Vector2dF LayerTreeHostImpl::ComputeScrollDelta( |
| 2737 ScrollNode* scroll_node, | 2739 ScrollNode* scroll_node, |
| 2738 const gfx::Vector2dF& delta) { | 2740 const gfx::Vector2dF& delta) { |
| 2739 ScrollTree& scroll_tree = active_tree()->property_trees()->scroll_tree; | 2741 ScrollTree& scroll_tree = active_tree()->property_trees()->scroll_tree; |
| 2740 float scale_factor = active_tree()->current_page_scale_factor(); | 2742 float scale_factor = active_tree()->current_page_scale_factor(); |
| 2741 | 2743 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2808 scroll_status.thread = SCROLL_IGNORED; | 2810 scroll_status.thread = SCROLL_IGNORED; |
| 2809 scroll_status.main_thread_scrolling_reasons = | 2811 scroll_status.main_thread_scrolling_reasons = |
| 2810 MainThreadScrollingReason::kNotScrollable; | 2812 MainThreadScrollingReason::kNotScrollable; |
| 2811 } | 2813 } |
| 2812 return scroll_status; | 2814 return scroll_status; |
| 2813 } | 2815 } |
| 2814 | 2816 |
| 2815 ScrollStateData scroll_state_data; | 2817 ScrollStateData scroll_state_data; |
| 2816 scroll_state_data.position_x = viewport_point.x(); | 2818 scroll_state_data.position_x = viewport_point.x(); |
| 2817 scroll_state_data.position_y = viewport_point.y(); | 2819 scroll_state_data.position_y = viewport_point.y(); |
| 2818 scroll_state_data.is_in_inertial_phase = true; | |
| 2819 ScrollState scroll_state(scroll_state_data); | 2820 ScrollState scroll_state(scroll_state_data); |
| 2820 | 2821 |
| 2821 // ScrollAnimated is used for animated wheel scrolls. We find the first layer | 2822 // ScrollAnimated is used for animated wheel scrolls. We find the first layer |
| 2822 // that can scroll and set up an animation of its scroll offset. Note that | 2823 // that can scroll and set up an animation of its scroll offset. Note that |
| 2823 // this does not currently go through the scroll customization machinery | 2824 // this does not currently go through the scroll customization machinery |
| 2824 // that ScrollBy uses for non-animated wheel scrolls. | 2825 // that ScrollBy uses for non-animated wheel scrolls. |
| 2825 scroll_status = ScrollBegin(&scroll_state, WHEEL); | 2826 scroll_status = ScrollBegin(&scroll_state, WHEEL); |
| 2826 scroll_node = scroll_tree.CurrentlyScrollingNode(); | 2827 scroll_node = scroll_tree.CurrentlyScrollingNode(); |
| 2827 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { | 2828 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { |
| 2828 gfx::Vector2dF pending_delta = scroll_delta; | 2829 gfx::Vector2dF pending_delta = scroll_delta; |
| (...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3166 scroll_affects_scroll_handler_ = false; | 3167 scroll_affects_scroll_handler_ = false; |
| 3167 accumulated_root_overscroll_ = gfx::Vector2dF(); | 3168 accumulated_root_overscroll_ = gfx::Vector2dF(); |
| 3168 } | 3169 } |
| 3169 | 3170 |
| 3170 void LayerTreeHostImpl::ScrollEnd(ScrollState* scroll_state) { | 3171 void LayerTreeHostImpl::ScrollEnd(ScrollState* scroll_state) { |
| 3171 DCHECK(scroll_state); | 3172 DCHECK(scroll_state); |
| 3172 DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0); | 3173 DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0); |
| 3173 | 3174 |
| 3174 DistributeScrollDelta(scroll_state); | 3175 DistributeScrollDelta(scroll_state); |
| 3175 browser_controls_offset_manager_->ScrollEnd(); | 3176 browser_controls_offset_manager_->ScrollEnd(); |
| 3176 ClearCurrentlyScrollingLayer(); | 3177 |
| 3178 if (!scroll_state->data()->may_precede_fling) { |
| 3179 // Only clear the currently scrolling layer if we know the scroll is done. |
| 3180 ClearCurrentlyScrollingLayer(); |
| 3181 } |
| 3177 } | 3182 } |
| 3178 | 3183 |
| 3179 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { | 3184 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { |
| 3180 InputHandler::ScrollStatus scroll_status; | 3185 InputHandler::ScrollStatus scroll_status; |
| 3181 scroll_status.main_thread_scrolling_reasons = | 3186 scroll_status.main_thread_scrolling_reasons = |
| 3182 MainThreadScrollingReason::kNotScrollingOnMain; | 3187 MainThreadScrollingReason::kNotScrollingOnMain; |
| 3183 if (!CurrentlyScrollingLayer()) { | 3188 if (!CurrentlyScrollingLayer()) { |
| 3184 scroll_status.thread = SCROLL_IGNORED; | 3189 scroll_status.thread = SCROLL_IGNORED; |
| 3185 scroll_status.main_thread_scrolling_reasons = | 3190 scroll_status.main_thread_scrolling_reasons = |
| 3186 MainThreadScrollingReason::kNoScrollingLayer; | 3191 MainThreadScrollingReason::kNoScrollingLayer; |
| (...skipping 897 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4084 if (is_visible) { | 4089 if (is_visible) { |
| 4085 worker_context_visibility_ = | 4090 worker_context_visibility_ = |
| 4086 worker_context->CacheController()->ClientBecameVisible(); | 4091 worker_context->CacheController()->ClientBecameVisible(); |
| 4087 } else { | 4092 } else { |
| 4088 worker_context->CacheController()->ClientBecameNotVisible( | 4093 worker_context->CacheController()->ClientBecameNotVisible( |
| 4089 std::move(worker_context_visibility_)); | 4094 std::move(worker_context_visibility_)); |
| 4090 } | 4095 } |
| 4091 } | 4096 } |
| 4092 | 4097 |
| 4093 } // namespace cc | 4098 } // namespace cc |
| OLD | NEW |