Find root scroll layer at tree activation
This finds the root scroll layer when a LayerTreeImpl is activated since we can
only interact with the active tree. Doing this allows adding more checks for
proper use and cuts down on the number of functions that have to be called in a
specific order.
I've also tightened up the TopControlsManagerClient interface, since previously
the interface defined "virtual LayerTreeImpl* activeTree()" but LayerTreeHostImpl
also defined a non-virtual "const LayerTreeImpl* activeTree() const" so depending
on the constness of a pointer callers would get one or the other. Turns out the
top controls system doesn't need the active tree, it just needs the root scroll
layer. It actually doesn't even need the full layer, it just needs to know if
there is a layer and if so what the y offset is.
BUG=169143
Review URL: https://chromiumcodereview.appspot.com/12025031
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177847 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/cc/layer_tree_impl.cc b/cc/layer_tree_impl.cc
index 99ba2030..bfdcf50 100644
--- a/cc/layer_tree_impl.cc
+++ b/cc/layer_tree_impl.cc
@@ -70,6 +70,7 @@
// Clear all data structures that have direct references to the layer tree.
scrolling_layer_id_from_previous_tree_ =
currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
+ root_scroll_layer_ = NULL;
currently_scrolling_layer_ = NULL;
render_surface_layer_list_.clear();
@@ -77,17 +78,27 @@
return root_layer_.Pass();
}
+LayerImpl* LayerTreeImpl::RootScrollLayer() {
+ DCHECK(IsActiveTree());
+ return root_scroll_layer_;
+}
+
+LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() {
+ DCHECK(IsActiveTree());
+ return currently_scrolling_layer_;
+}
+
void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
currently_scrolling_layer_ = NULL;
scrolling_layer_id_from_previous_tree_ = 0;
}
void LayerTreeImpl::UpdateMaxScrollOffset() {
- if (!root_scroll_layer() || !root_scroll_layer()->children().size())
+ if (!root_scroll_layer_ || !root_scroll_layer_->children().size())
return;
gfx::SizeF view_bounds = device_viewport_size();
- if (LayerImpl* clip_layer = root_scroll_layer()->parent()) {
+ if (LayerImpl* clip_layer = root_scroll_layer_->parent()) {
// Compensate for non-overlay scrollbars.
if (clip_layer->masksToBounds())
view_bounds = gfx::ScaleSize(clip_layer->bounds(), device_scale_factor());
@@ -113,7 +124,7 @@
// having a vertical scrollbar but no horizontal overflow.
max_scroll.ClampToMin(gfx::Vector2dF());
- root_scroll_layer()->setMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll));
+ root_scroll_layer_->setMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll));
}
void LayerTreeImpl::UpdateDrawProperties() {
@@ -121,8 +132,8 @@
if (!RootLayer())
return;
- if (root_scroll_layer()) {
- root_scroll_layer()->setImplTransform(
+ if (root_scroll_layer_) {
+ root_scroll_layer_->setImplTransform(
layer_tree_host_impl_->implTransform());
}
@@ -177,11 +188,9 @@
}
gfx::Size LayerTreeImpl::ContentSize() const {
- // TODO(aelias): Hardcoding the first child here is weird. Think of
- // a cleaner way to get the contentBounds on the Impl side.
- if (!root_scroll_layer() || root_scroll_layer()->children().empty())
+ if (!root_scroll_layer_)
return gfx::Size();
- return root_scroll_layer()->children()[0]->contentBounds();
+ return root_scroll_layer_->bounds();
}
LayerImpl* LayerTreeImpl::LayerById(int id) {
@@ -214,6 +223,8 @@
void LayerTreeImpl::DidBecomeActive() {
if (RootLayer())
DidBecomeActiveRecursive(RootLayer());
+ FindRootScrollLayer();
+ UpdateMaxScrollOffset();
}
bool LayerTreeImpl::ContentsTexturesPurged() const {