| 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 2707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2718 } | 2718 } |
| 2719 | 2719 |
| 2720 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( | 2720 InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin( |
| 2721 ScrollState* scroll_state, | 2721 ScrollState* scroll_state, |
| 2722 InputHandler::ScrollInputType type) { | 2722 InputHandler::ScrollInputType type) { |
| 2723 ScrollStatus scroll_status; | 2723 ScrollStatus scroll_status; |
| 2724 scroll_status.main_thread_scrolling_reasons = | 2724 scroll_status.main_thread_scrolling_reasons = |
| 2725 MainThreadScrollingReason::kNotScrollingOnMain; | 2725 MainThreadScrollingReason::kNotScrollingOnMain; |
| 2726 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); | 2726 TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin"); |
| 2727 | 2727 |
| 2728 // On Mac a scroll begin with |inertial_phase| = true happens to handle a |
| 2729 // fling. |
| 2730 if (scroll_state->is_in_inertial_phase()) |
| 2731 return FlingScrollBegin(); |
| 2732 |
| 2728 ClearCurrentlyScrollingLayer(); | 2733 ClearCurrentlyScrollingLayer(); |
| 2729 | 2734 |
| 2730 gfx::Point viewport_point(scroll_state->position_x(), | 2735 gfx::Point viewport_point(scroll_state->position_x(), |
| 2731 scroll_state->position_y()); | 2736 scroll_state->position_y()); |
| 2732 | 2737 |
| 2733 gfx::PointF device_viewport_point = gfx::ScalePoint( | 2738 gfx::PointF device_viewport_point = gfx::ScalePoint( |
| 2734 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); | 2739 gfx::PointF(viewport_point), active_tree_->device_scale_factor()); |
| 2735 LayerImpl* layer_impl = | 2740 LayerImpl* layer_impl = |
| 2736 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); | 2741 active_tree_->FindLayerThatIsHitByPoint(device_viewport_point); |
| 2737 | 2742 |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2880 scroll_status.thread = SCROLL_IGNORED; | 2885 scroll_status.thread = SCROLL_IGNORED; |
| 2881 scroll_status.main_thread_scrolling_reasons = | 2886 scroll_status.main_thread_scrolling_reasons = |
| 2882 MainThreadScrollingReason::kNotScrollable; | 2887 MainThreadScrollingReason::kNotScrollable; |
| 2883 } | 2888 } |
| 2884 return scroll_status; | 2889 return scroll_status; |
| 2885 } | 2890 } |
| 2886 | 2891 |
| 2887 ScrollStateData scroll_state_data; | 2892 ScrollStateData scroll_state_data; |
| 2888 scroll_state_data.position_x = viewport_point.x(); | 2893 scroll_state_data.position_x = viewport_point.x(); |
| 2889 scroll_state_data.position_y = viewport_point.y(); | 2894 scroll_state_data.position_y = viewport_point.y(); |
| 2890 scroll_state_data.is_in_inertial_phase = true; | 2895 scroll_state_data.is_in_inertial_phase = false; |
| 2891 ScrollState scroll_state(scroll_state_data); | 2896 ScrollState scroll_state(scroll_state_data); |
| 2892 | 2897 |
| 2893 // ScrollAnimated is used for animated wheel scrolls. We find the first layer | 2898 // ScrollAnimated is used for animated wheel scrolls. We find the first layer |
| 2894 // that can scroll and set up an animation of its scroll offset. Note that | 2899 // that can scroll and set up an animation of its scroll offset. Note that |
| 2895 // this does not currently go through the scroll customization machinery | 2900 // this does not currently go through the scroll customization machinery |
| 2896 // that ScrollBy uses for non-animated wheel scrolls. | 2901 // that ScrollBy uses for non-animated wheel scrolls. |
| 2897 scroll_status = ScrollBegin(&scroll_state, WHEEL); | 2902 scroll_status = ScrollBegin(&scroll_state, WHEEL); |
| 2898 scroll_node = scroll_tree.CurrentlyScrollingNode(); | 2903 scroll_node = scroll_tree.CurrentlyScrollingNode(); |
| 2899 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { | 2904 if (scroll_status.thread == SCROLL_ON_IMPL_THREAD) { |
| 2900 gfx::Vector2dF pending_delta = scroll_delta; | 2905 gfx::Vector2dF pending_delta = scroll_delta; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2918 gfx::Vector2dF scroll_delta = | 2923 gfx::Vector2dF scroll_delta = |
| 2919 ComputeScrollDelta(scroll_node, pending_delta); | 2924 ComputeScrollDelta(scroll_node, pending_delta); |
| 2920 if (ScrollAnimationCreate(scroll_node, scroll_delta)) | 2925 if (ScrollAnimationCreate(scroll_node, scroll_delta)) |
| 2921 return scroll_status; | 2926 return scroll_status; |
| 2922 | 2927 |
| 2923 pending_delta -= scroll_delta; | 2928 pending_delta -= scroll_delta; |
| 2924 } | 2929 } |
| 2925 } | 2930 } |
| 2926 } | 2931 } |
| 2927 scroll_state.set_is_ending(true); | 2932 scroll_state.set_is_ending(true); |
| 2933 // TODO(Sahel): Once the touchpad scroll latching for Non-mac devices is |
| 2934 // impelemented, the current scrolling layer should not get cleared after |
| 2935 // each animation (crbug.com/526463). |
| 2928 ScrollEnd(&scroll_state); | 2936 ScrollEnd(&scroll_state); |
| 2937 ClearCurrentlyScrollingLayer(); |
| 2938 |
| 2929 return scroll_status; | 2939 return scroll_status; |
| 2930 } | 2940 } |
| 2931 | 2941 |
| 2932 gfx::Vector2dF LayerTreeHostImpl::ScrollNodeWithViewportSpaceDelta( | 2942 gfx::Vector2dF LayerTreeHostImpl::ScrollNodeWithViewportSpaceDelta( |
| 2933 ScrollNode* scroll_node, | 2943 ScrollNode* scroll_node, |
| 2934 const gfx::PointF& viewport_point, | 2944 const gfx::PointF& viewport_point, |
| 2935 const gfx::Vector2dF& viewport_delta, | 2945 const gfx::Vector2dF& viewport_delta, |
| 2936 ScrollTree* scroll_tree) { | 2946 ScrollTree* scroll_tree) { |
| 2937 // Layers with non-invertible screen space transforms should not have passed | 2947 // Layers with non-invertible screen space transforms should not have passed |
| 2938 // the scroll hit test in the first place. | 2948 // the scroll hit test in the first place. |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3272 scroll_affects_scroll_handler_ = false; | 3282 scroll_affects_scroll_handler_ = false; |
| 3273 accumulated_root_overscroll_ = gfx::Vector2dF(); | 3283 accumulated_root_overscroll_ = gfx::Vector2dF(); |
| 3274 } | 3284 } |
| 3275 | 3285 |
| 3276 void LayerTreeHostImpl::ScrollEnd(ScrollState* scroll_state) { | 3286 void LayerTreeHostImpl::ScrollEnd(ScrollState* scroll_state) { |
| 3277 DCHECK(scroll_state); | 3287 DCHECK(scroll_state); |
| 3278 DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0); | 3288 DCHECK(scroll_state->delta_x() == 0 && scroll_state->delta_y() == 0); |
| 3279 | 3289 |
| 3280 DistributeScrollDelta(scroll_state); | 3290 DistributeScrollDelta(scroll_state); |
| 3281 top_controls_manager_->ScrollEnd(); | 3291 top_controls_manager_->ScrollEnd(); |
| 3282 ClearCurrentlyScrollingLayer(); | 3292 |
| 3293 if (scroll_state->is_in_inertial_phase()) { |
| 3294 // Only clear the currently scrolling layer if we know the scroll is done. |
| 3295 // A non-inertial scroll end could be followed by an inertial scroll. |
| 3296 ClearCurrentlyScrollingLayer(); |
| 3297 } |
| 3283 } | 3298 } |
| 3284 | 3299 |
| 3285 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { | 3300 InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() { |
| 3286 InputHandler::ScrollStatus scroll_status; | 3301 InputHandler::ScrollStatus scroll_status; |
| 3287 scroll_status.main_thread_scrolling_reasons = | 3302 scroll_status.main_thread_scrolling_reasons = |
| 3288 MainThreadScrollingReason::kNotScrollingOnMain; | 3303 MainThreadScrollingReason::kNotScrollingOnMain; |
| 3289 if (!CurrentlyScrollingLayer()) { | 3304 if (!CurrentlyScrollingLayer()) { |
| 3290 scroll_status.thread = SCROLL_IGNORED; | 3305 scroll_status.thread = SCROLL_IGNORED; |
| 3291 scroll_status.main_thread_scrolling_reasons = | 3306 scroll_status.main_thread_scrolling_reasons = |
| 3292 MainThreadScrollingReason::kNoScrollingLayer; | 3307 MainThreadScrollingReason::kNoScrollingLayer; |
| (...skipping 793 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4086 layer->OnFilterIsCurrentlyAnimatingChanged(is_animating); | 4101 layer->OnFilterIsCurrentlyAnimatingChanged(is_animating); |
| 4087 break; | 4102 break; |
| 4088 } | 4103 } |
| 4089 } | 4104 } |
| 4090 } | 4105 } |
| 4091 | 4106 |
| 4092 void LayerTreeHostImpl::ScrollOffsetAnimationFinished() { | 4107 void LayerTreeHostImpl::ScrollOffsetAnimationFinished() { |
| 4093 // TODO(majidvp): We should pass in the original starting scroll position here | 4108 // TODO(majidvp): We should pass in the original starting scroll position here |
| 4094 ScrollStateData scroll_state_data; | 4109 ScrollStateData scroll_state_data; |
| 4095 ScrollState scroll_state(scroll_state_data); | 4110 ScrollState scroll_state(scroll_state_data); |
| 4111 // TODO(Sahel): Once the touchpad scroll latching for Non-mac devices is |
| 4112 // impelemented, the current scrolling layer should not get cleared after |
| 4113 // each animation (crbug.com/526463). |
| 4096 ScrollEnd(&scroll_state); | 4114 ScrollEnd(&scroll_state); |
| 4115 ClearCurrentlyScrollingLayer(); |
| 4097 } | 4116 } |
| 4098 | 4117 |
| 4099 gfx::ScrollOffset LayerTreeHostImpl::GetScrollOffsetForAnimation( | 4118 gfx::ScrollOffset LayerTreeHostImpl::GetScrollOffsetForAnimation( |
| 4100 ElementId element_id) const { | 4119 ElementId element_id) const { |
| 4101 if (active_tree()) { | 4120 if (active_tree()) { |
| 4102 LayerImpl* layer = active_tree()->LayerByElementId(element_id); | 4121 LayerImpl* layer = active_tree()->LayerByElementId(element_id); |
| 4103 if (layer) | 4122 if (layer) |
| 4104 return layer->ScrollOffsetForAnimation(); | 4123 return layer->ScrollOffsetForAnimation(); |
| 4105 } | 4124 } |
| 4106 | 4125 |
| 4107 return gfx::ScrollOffset(); | 4126 return gfx::ScrollOffset(); |
| 4108 } | 4127 } |
| 4109 | 4128 |
| 4110 bool LayerTreeHostImpl::SupportsImplScrolling() const { | 4129 bool LayerTreeHostImpl::SupportsImplScrolling() const { |
| 4111 // Supported in threaded mode. | 4130 // Supported in threaded mode. |
| 4112 return task_runner_provider_->HasImplThread(); | 4131 return task_runner_provider_->HasImplThread(); |
| 4113 } | 4132 } |
| 4114 | 4133 |
| 4115 bool LayerTreeHostImpl::CommitToActiveTree() const { | 4134 bool LayerTreeHostImpl::CommitToActiveTree() const { |
| 4116 // In single threaded mode we skip the pending tree and commit directly to the | 4135 // In single threaded mode we skip the pending tree and commit directly to the |
| 4117 // active tree. | 4136 // active tree. |
| 4118 return !task_runner_provider_->HasImplThread(); | 4137 return !task_runner_provider_->HasImplThread(); |
| 4119 } | 4138 } |
| 4120 | 4139 |
| 4121 } // namespace cc | 4140 } // namespace cc |
| OLD | NEW |