Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1137)

Unified Diff: cc/trees/layer_tree_host_impl.cc

Issue 2423143002: Scrollbar fade animation broken on Android regression resolved. (Closed)
Patch Set: review comments addressed. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/trees/layer_tree_host_impl.cc
diff --git a/cc/trees/layer_tree_host_impl.cc b/cc/trees/layer_tree_host_impl.cc
index 5b90fd12c5a679f7c2823aa1327898fe84ed435e..a17755bb29fa53ef2b4df84b18d0e6590a8d464f 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -240,7 +240,11 @@ LayerTreeHostImpl::LayerTreeHostImpl(
requires_high_res_to_draw_(false),
is_likely_to_require_a_draw_(false),
has_valid_compositor_frame_sink_(false),
- mutator_(nullptr) {
+ mutator_(nullptr),
+ cached_scroll_state_for_fling_(Layer::INVALID_ID,
+ did_lock_scrolling_layer_,
+ scroll_affects_scroll_handler_,
+ accumulated_root_overscroll_) {
DCHECK(animation_host_);
animation_host_->SetMutatorHostClient(this);
@@ -2642,49 +2646,55 @@ InputHandler::ScrollStatus LayerTreeHostImpl::ScrollBegin(
scroll_status.main_thread_scrolling_reasons =
MainThreadScrollingReason::kNotScrollingOnMain;
TRACE_EVENT0("cc", "LayerTreeHostImpl::ScrollBegin");
-
+ LayerImpl* scrolling_layer_impl = nullptr;
// On Mac a scroll begin with |inertial_phase| = true happens to handle a
- // fling.
- if (scroll_state->is_in_inertial_phase())
- return FlingScrollBegin();
+ // fling. Also, touchpad fling starts are handled by calling ScrollBegin
+ // instead of FlingScrollBegin.
+ if (scroll_state->is_in_inertial_phase()) {
+ RestoreScrollStateForFling();
+ scrolling_layer_impl = active_tree_->CurrentlyScrollingLayer();
+ }
- ClearCurrentlyScrollingLayer();
+ if (!scrolling_layer_impl) {
+ ClearCurrentlyScrollingLayer();
- gfx::Point viewport_point(scroll_state->position_x(),
- scroll_state->position_y());
+ gfx::Point viewport_point(scroll_state->position_x(),
+ scroll_state->position_y());
- gfx::PointF device_viewport_point = gfx::ScalePoint(
- gfx::PointF(viewport_point), active_tree_->device_scale_factor());
- LayerImpl* layer_impl =
- active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
-
- if (layer_impl) {
- LayerImpl* scroll_layer_impl =
- active_tree_->FindFirstScrollingLayerOrScrollbarLayerThatIsHitByPoint(
- device_viewport_point);
- if (scroll_layer_impl &&
- !HasScrollAncestor(layer_impl, scroll_layer_impl)) {
- scroll_status.thread = SCROLL_UNKNOWN;
- scroll_status.main_thread_scrolling_reasons =
- MainThreadScrollingReason::kFailedHitTest;
- return scroll_status;
+ gfx::PointF device_viewport_point = gfx::ScalePoint(
+ gfx::PointF(viewport_point), active_tree_->device_scale_factor());
+ LayerImpl* layer_impl =
+ active_tree_->FindLayerThatIsHitByPoint(device_viewport_point);
+
+ if (layer_impl) {
+ LayerImpl* scroll_layer_impl =
+ active_tree_->FindFirstScrollingLayerOrScrollbarLayerThatIsHitByPoint(
+ device_viewport_point);
+ if (scroll_layer_impl &&
+ !HasScrollAncestor(layer_impl, scroll_layer_impl)) {
+ scroll_status.thread = SCROLL_UNKNOWN;
+ scroll_status.main_thread_scrolling_reasons =
+ MainThreadScrollingReason::kFailedHitTest;
+ return scroll_status;
+ }
}
- }
- bool scroll_on_main_thread = false;
- LayerImpl* scrolling_layer_impl = FindScrollLayerForDeviceViewportPoint(
- device_viewport_point, type, layer_impl, &scroll_on_main_thread,
- &scroll_status.main_thread_scrolling_reasons);
+ bool scroll_on_main_thread = false;
+ scrolling_layer_impl = FindScrollLayerForDeviceViewportPoint(
+ device_viewport_point, type, layer_impl, &scroll_on_main_thread,
+ &scroll_status.main_thread_scrolling_reasons);
- if (scrolling_layer_impl)
- scroll_affects_scroll_handler_ =
- scrolling_layer_impl->layer_tree_impl()->have_scroll_event_handlers();
+ if (scrolling_layer_impl) {
+ scroll_affects_scroll_handler_ =
+ scrolling_layer_impl->layer_tree_impl()->have_scroll_event_handlers();
+ }
- if (scroll_on_main_thread) {
- RecordCompositorSlowScrollMetric(type, MAIN_THREAD);
+ if (scroll_on_main_thread) {
+ RecordCompositorSlowScrollMetric(type, MAIN_THREAD);
- scroll_status.thread = SCROLL_ON_MAIN_THREAD;
- return scroll_status;
+ scroll_status.thread = SCROLL_ON_MAIN_THREAD;
+ return scroll_status;
+ }
}
return ScrollBeginImpl(scroll_state, scrolling_layer_impl, type);
@@ -2724,11 +2734,7 @@ InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimatedBegin(
ScrollStateData scroll_state_end_data;
scroll_state_end_data.is_ending = true;
ScrollState scroll_state_end(scroll_state_end_data);
- // TODO(Sahel): Once the touchpad scroll latching for Non-mac devices is
- // implemented, the current scrolling layer should not get cleared after
- // each animation (crbug.com/526463).
ScrollEnd(&scroll_state_end);
- ClearCurrentlyScrollingLayer();
}
return scroll_status;
}
@@ -2852,11 +2858,7 @@ InputHandler::ScrollStatus LayerTreeHostImpl::ScrollAnimated(
}
}
scroll_state.set_is_ending(true);
- // TODO(Sahel): Once the touchpad scroll latching for Non-mac devices is
- // implemented, the current scrolling layer should not get cleared after
- // each animation (crbug.com/526463).
ScrollEnd(&scroll_state);
- ClearCurrentlyScrollingLayer();
return scroll_status;
}
@@ -3164,6 +3166,11 @@ void LayerTreeHostImpl::SetSynchronousInputHandlerRootScrollOffset(
}
void LayerTreeHostImpl::ClearCurrentlyScrollingLayer() {
+ // Cached scrolling variables state is restored in a ScrollBegin with
+ // inertial phase (fling) to latch it to its corresponding scroll. When
+ // reseting a variable here, update ScrollStateForFling class as well
+ // to maintain the proper caching.
+ CacheScrollStateForFling();
active_tree_->ClearCurrentlyScrollingLayer();
did_lock_scrolling_layer_ = false;
scroll_affects_scroll_handler_ = false;
@@ -3177,11 +3184,7 @@ void LayerTreeHostImpl::ScrollEnd(ScrollState* scroll_state) {
DistributeScrollDelta(scroll_state);
top_controls_manager_->ScrollEnd();
- if (scroll_state->is_in_inertial_phase()) {
- // Only clear the currently scrolling layer if we know the scroll is done.
- // A non-inertial scroll end could be followed by an inertial scroll.
- ClearCurrentlyScrollingLayer();
- }
+ ClearCurrentlyScrollingLayer();
}
InputHandler::ScrollStatus LayerTreeHostImpl::FlingScrollBegin() {
@@ -4018,11 +4021,7 @@ void LayerTreeHostImpl::ScrollOffsetAnimationFinished() {
// TODO(majidvp): We should pass in the original starting scroll position here
ScrollStateData scroll_state_data;
ScrollState scroll_state(scroll_state_data);
- // TODO(Sahel): Once the touchpad scroll latching for Non-mac devices is
- // implemented, the current scrolling layer should not get cleared after
- // each animation (crbug.com/526463).
ScrollEnd(&scroll_state);
- ClearCurrentlyScrollingLayer();
}
gfx::ScrollOffset LayerTreeHostImpl::GetScrollOffsetForAnimation(
@@ -4090,4 +4089,23 @@ void LayerTreeHostImpl::SetWorkerContextVisibility(bool is_visible) {
}
}
+void LayerTreeHostImpl::CacheScrollStateForFling() {
+ int scrolling_layer_id = active_tree_->CurrentlyScrollingLayer()
+ ? active_tree_->CurrentlyScrollingLayer()->id()
+ : Layer::INVALID_ID;
+ cached_scroll_state_for_fling_ = ScrollStateForFling(
+ scrolling_layer_id, did_lock_scrolling_layer_,
+ scroll_affects_scroll_handler_, accumulated_root_overscroll_);
+}
+void LayerTreeHostImpl::RestoreScrollStateForFling() {
+ active_tree_->SetCurrentlyScrollingLayer(active_tree_->LayerById(
+ cached_scroll_state_for_fling_.scrolling_layer_id()));
+ did_lock_scrolling_layer_ =
+ cached_scroll_state_for_fling_.did_lock_scrolling_layer();
+ scroll_affects_scroll_handler_ =
+ cached_scroll_state_for_fling_.scroll_affects_scroll_handler();
+ accumulated_root_overscroll_ =
+ cached_scroll_state_for_fling_.accumulated_root_overscroll();
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698