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

Side by Side Diff: cc/layer_tree_impl.cc

Issue 12025031: Find root scroll layer at tree activation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/layer_tree_impl.h" 5 #include "cc/layer_tree_impl.h"
6 6
7 #include "base/debug/trace_event.h" 7 #include "base/debug/trace_event.h"
8 #include "cc/layer_tree_host_common.h" 8 #include "cc/layer_tree_host_common.h"
9 #include "cc/layer_tree_host_impl.h" 9 #include "cc/layer_tree_host_impl.h"
10 #include "ui/gfx/vector2d_conversions.h" 10 #include "ui/gfx/vector2d_conversions.h"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 scrolling_layer_id_from_previous_tree_); 62 scrolling_layer_id_from_previous_tree_);
63 } 63 }
64 64
65 scrolling_layer_id_from_previous_tree_ = 0; 65 scrolling_layer_id_from_previous_tree_ = 0;
66 } 66 }
67 67
68 scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() { 68 scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() {
69 // Clear all data structures that have direct references to the layer tree. 69 // Clear all data structures that have direct references to the layer tree.
70 scrolling_layer_id_from_previous_tree_ = 70 scrolling_layer_id_from_previous_tree_ =
71 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0; 71 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
72 root_scroll_layer_ = NULL;
72 currently_scrolling_layer_ = NULL; 73 currently_scrolling_layer_ = NULL;
73 74
74 render_surface_layer_list_.clear(); 75 render_surface_layer_list_.clear();
75 SetNeedsUpdateDrawProperties(); 76 SetNeedsUpdateDrawProperties();
76 return root_layer_.Pass(); 77 return root_layer_.Pass();
77 } 78 }
78 79
80 LayerImpl* LayerTreeImpl::RootScrollLayer() {
81 DCHECK(IsActiveTree());
82 return root_scroll_layer_;
83 }
84
85 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() {
86 DCHECK(IsActiveTree());
87 return currently_scrolling_layer_;
88 }
89
79 void LayerTreeImpl::ClearCurrentlyScrollingLayer() { 90 void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
80 currently_scrolling_layer_ = NULL; 91 currently_scrolling_layer_ = NULL;
81 scrolling_layer_id_from_previous_tree_ = 0; 92 scrolling_layer_id_from_previous_tree_ = 0;
82 } 93 }
83 94
84 void LayerTreeImpl::UpdateMaxScrollOffset() { 95 void LayerTreeImpl::UpdateMaxScrollOffset() {
85 if (!root_scroll_layer() || !root_scroll_layer()->children().size()) 96 if (!root_scroll_layer_ || !root_scroll_layer_->children().size())
86 return; 97 return;
87 98
88 gfx::SizeF view_bounds = device_viewport_size(); 99 gfx::SizeF view_bounds = device_viewport_size();
89 if (LayerImpl* clip_layer = root_scroll_layer()->parent()) { 100 if (LayerImpl* clip_layer = root_scroll_layer_->parent()) {
90 // Compensate for non-overlay scrollbars. 101 // Compensate for non-overlay scrollbars.
91 if (clip_layer->masksToBounds()) 102 if (clip_layer->masksToBounds())
92 view_bounds = gfx::ScaleSize(clip_layer->bounds(), device_scale_factor()); 103 view_bounds = gfx::ScaleSize(clip_layer->bounds(), device_scale_factor());
93 } 104 }
94 105
95 gfx::Size content_bounds = ContentSize(); 106 gfx::Size content_bounds = ContentSize();
96 if (settings().pageScalePinchZoomEnabled) { 107 if (settings().pageScalePinchZoomEnabled) {
97 // Pinch with pageScale scrolls entirely in layout space. ContentSize 108 // Pinch with pageScale scrolls entirely in layout space. ContentSize
98 // returns the bounds including the page scale factor, so calculate the 109 // returns the bounds including the page scale factor, so calculate the
99 // pre page-scale layout size here. 110 // pre page-scale layout size here.
100 float page_scale_factor = pinch_zoom_viewport().page_scale_factor(); 111 float page_scale_factor = pinch_zoom_viewport().page_scale_factor();
101 content_bounds.set_width(content_bounds.width() / page_scale_factor); 112 content_bounds.set_width(content_bounds.width() / page_scale_factor);
102 content_bounds.set_height(content_bounds.height() / page_scale_factor); 113 content_bounds.set_height(content_bounds.height() / page_scale_factor);
103 } else { 114 } else {
104 view_bounds.Scale(1 / pinch_zoom_viewport().page_scale_delta()); 115 view_bounds.Scale(1 / pinch_zoom_viewport().page_scale_delta());
105 } 116 }
106 117
107 gfx::Vector2dF max_scroll = gfx::Rect(content_bounds).bottom_right() - 118 gfx::Vector2dF max_scroll = gfx::Rect(content_bounds).bottom_right() -
108 gfx::RectF(view_bounds).bottom_right(); 119 gfx::RectF(view_bounds).bottom_right();
109 max_scroll.Scale(1 / device_scale_factor()); 120 max_scroll.Scale(1 / device_scale_factor());
110 121
111 // The viewport may be larger than the contents in some cases, such as 122 // The viewport may be larger than the contents in some cases, such as
112 // having a vertical scrollbar but no horizontal overflow. 123 // having a vertical scrollbar but no horizontal overflow.
113 max_scroll.ClampToMin(gfx::Vector2dF()); 124 max_scroll.ClampToMin(gfx::Vector2dF());
114 125
115 root_scroll_layer()->setMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll)); 126 root_scroll_layer_->setMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll));
116 } 127 }
117 128
118 void LayerTreeImpl::UpdateDrawProperties() { 129 void LayerTreeImpl::UpdateDrawProperties() {
119 render_surface_layer_list_.clear(); 130 render_surface_layer_list_.clear();
120 if (!RootLayer()) 131 if (!RootLayer())
121 return; 132 return;
122 133
123 if (root_scroll_layer()) { 134 if (root_scroll_layer_) {
124 root_scroll_layer()->setImplTransform( 135 root_scroll_layer_->setImplTransform(
125 layer_tree_host_impl_->implTransform()); 136 layer_tree_host_impl_->implTransform());
126 } 137 }
127 138
128 { 139 {
129 TRACE_EVENT0("cc", "LayerTreeImpl::UpdateDrawProperties"); 140 TRACE_EVENT0("cc", "LayerTreeImpl::UpdateDrawProperties");
130 LayerTreeHostCommon::calculateDrawProperties( 141 LayerTreeHostCommon::calculateDrawProperties(
131 RootLayer(), 142 RootLayer(),
132 device_viewport_size(), 143 device_viewport_size(),
133 device_scale_factor(), 144 device_scale_factor(),
134 pinch_zoom_viewport().page_scale_factor(), 145 pinch_zoom_viewport().page_scale_factor(),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 return true; 180 return true;
170 } 181 }
171 182
172 const LayerTreeImpl::LayerList& LayerTreeImpl::RenderSurfaceLayerList() const { 183 const LayerTreeImpl::LayerList& LayerTreeImpl::RenderSurfaceLayerList() const {
173 // If this assert triggers, then the list is dirty. 184 // If this assert triggers, then the list is dirty.
174 DCHECK(!layer_tree_host_impl_->needsUpdateDrawProperties()); 185 DCHECK(!layer_tree_host_impl_->needsUpdateDrawProperties());
175 return render_surface_layer_list_; 186 return render_surface_layer_list_;
176 } 187 }
177 188
178 gfx::Size LayerTreeImpl::ContentSize() const { 189 gfx::Size LayerTreeImpl::ContentSize() const {
179 // TODO(aelias): Hardcoding the first child here is weird. Think of 190 if (!root_scroll_layer_)
180 // a cleaner way to get the contentBounds on the Impl side.
181 if (!root_scroll_layer() || root_scroll_layer()->children().empty())
182 return gfx::Size(); 191 return gfx::Size();
183 return root_scroll_layer()->children()[0]->contentBounds(); 192 return root_scroll_layer_->bounds();
184 } 193 }
185 194
186 LayerImpl* LayerTreeImpl::LayerById(int id) { 195 LayerImpl* LayerTreeImpl::LayerById(int id) {
187 LayerIdMap::iterator iter = layer_id_map_.find(id); 196 LayerIdMap::iterator iter = layer_id_map_.find(id);
188 return iter != layer_id_map_.end() ? iter->second : NULL; 197 return iter != layer_id_map_.end() ? iter->second : NULL;
189 } 198 }
190 199
191 void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { 200 void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
192 DCHECK(!LayerById(layer->id())); 201 DCHECK(!LayerById(layer->id()));
193 layer_id_map_[layer->id()] = layer; 202 layer_id_map_[layer->id()] = layer;
(...skipping 12 matching lines...) Expand all
206 215
207 static void DidBecomeActiveRecursive(LayerImpl* layer) { 216 static void DidBecomeActiveRecursive(LayerImpl* layer) {
208 layer->didBecomeActive(); 217 layer->didBecomeActive();
209 for (size_t i = 0; i < layer->children().size(); ++i) 218 for (size_t i = 0; i < layer->children().size(); ++i)
210 DidBecomeActiveRecursive(layer->children()[i]); 219 DidBecomeActiveRecursive(layer->children()[i]);
211 } 220 }
212 221
213 void LayerTreeImpl::DidBecomeActive() { 222 void LayerTreeImpl::DidBecomeActive() {
214 if (RootLayer()) 223 if (RootLayer())
215 DidBecomeActiveRecursive(RootLayer()); 224 DidBecomeActiveRecursive(RootLayer());
225 FindRootScrollLayer();
226 UpdateMaxScrollOffset();
216 } 227 }
217 228
218 const LayerTreeSettings& LayerTreeImpl::settings() const { 229 const LayerTreeSettings& LayerTreeImpl::settings() const {
219 return layer_tree_host_impl_->settings(); 230 return layer_tree_host_impl_->settings();
220 } 231 }
221 232
222 OutputSurface* LayerTreeImpl::output_surface() const { 233 OutputSurface* LayerTreeImpl::output_surface() const {
223 return layer_tree_host_impl_->outputSurface(); 234 return layer_tree_host_impl_->outputSurface();
224 } 235 }
225 236
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 310
300 AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { 311 AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
301 return layer_tree_host_impl_->animationRegistrar(); 312 return layer_tree_host_impl_->animationRegistrar();
302 } 313 }
303 314
304 const PinchZoomViewport& LayerTreeImpl::pinch_zoom_viewport() const { 315 const PinchZoomViewport& LayerTreeImpl::pinch_zoom_viewport() const {
305 return layer_tree_host_impl_->pinchZoomViewport(); 316 return layer_tree_host_impl_->pinchZoomViewport();
306 } 317 }
307 318
308 } // namespace cc 319 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698