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

Unified Diff: cc/trees/layer_tree_host_impl.cc

Issue 2423143002: Scrollbar fade animation broken on Android regression resolved. (Closed)
Patch Set: scrolling_layer_id cached. 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 9a6842fd7ca9c44f83171964d264e19cc052c027..d4b04172fc5b380964d8992b1b842cdc44f1ba00 100644
--- a/cc/trees/layer_tree_host_impl.cc
+++ b/cc/trees/layer_tree_host_impl.cc
@@ -241,7 +241,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);
@@ -2643,49 +2647,52 @@ 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.
+ // fling. Also, touchpad fling starts are handled by calling ScrollBegin
+ // instead of FlingScrollBegin.
if (scroll_state->is_in_inertial_phase())
- return FlingScrollBegin();
+ scrolling_layer_impl = RestoreScrollStateForFling();
- 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)
tdresser 2016/10/26 15:38:18 Use {}
sahel 2016/10/26 18:47:45 Done.
+ 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);
@@ -2725,11 +2732,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;
}
@@ -2853,11 +2856,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;
}
@@ -3165,6 +3164,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;
@@ -3178,11 +3182,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() {
@@ -4035,11 +4035,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(
@@ -4107,4 +4103,24 @@ 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_);
+}
+LayerImpl* LayerTreeHostImpl::RestoreScrollStateForFling() {
tdresser 2016/10/26 15:38:18 It seems a bit weird to me that this returns the c
bokan 2016/10/26 16:01:53 +1
sahel 2016/10/26 18:47:45 Done.
+ active_tree_->SetCurrentlyScrollingLayer(active_tree_->LayerById(
+ cached_scroll_state_for_fling_.scrollingLayerId()));
+ did_lock_scrolling_layer_ =
+ cached_scroll_state_for_fling_.didLockScrollingLayer();
+ scroll_affects_scroll_handler_ =
+ cached_scroll_state_for_fling_.scrollAffectsScrollHandler();
+ accumulated_root_overscroll_ =
+ cached_scroll_state_for_fling_.accumulatedRootOverscroll();
+ return active_tree_->CurrentlyScrollingLayer();
+}
+
} // namespace cc

Powered by Google App Engine
This is Rietveld 408576698