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_impl.h" | 5 #include "cc/trees/layer_tree_impl.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "cc/animation/keyframed_animation_curve.h" | 8 #include "cc/animation/keyframed_animation_curve.h" |
9 #include "cc/animation/scrollbar_animation_controller.h" | 9 #include "cc/animation/scrollbar_animation_controller.h" |
10 #include "cc/debug/traced_value.h" | 10 #include "cc/debug/traced_value.h" |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
136 } | 136 } |
137 | 137 |
138 LayerImpl* LayerTreeImpl::RootScrollLayer() const { | 138 LayerImpl* LayerTreeImpl::RootScrollLayer() const { |
139 return root_scroll_layer_; | 139 return root_scroll_layer_; |
140 } | 140 } |
141 | 141 |
142 LayerImpl* LayerTreeImpl::RootContainerLayer() const { | 142 LayerImpl* LayerTreeImpl::RootContainerLayer() const { |
143 return root_scroll_layer_ ? root_scroll_layer_->parent() : NULL; | 143 return root_scroll_layer_ ? root_scroll_layer_->parent() : NULL; |
144 } | 144 } |
145 | 145 |
146 LayerImpl* LayerTreeImpl::ViewportLayer() const { | |
147 // Return the first ancestor of the root container layer which has | |
148 // nonzero bounds. | |
149 LayerImpl* root_container = RootContainerLayer(); | |
150 if (!root_container) | |
151 return NULL; | |
152 | |
153 LayerImpl* ancestor = root_container->parent(); | |
154 while (ancestor) { | |
155 if (!ancestor->bounds().IsEmpty()) | |
156 return ancestor; | |
157 ancestor = ancestor->parent(); | |
158 } | |
159 return NULL; | |
160 } | |
161 | |
146 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const { | 162 LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const { |
147 DCHECK(IsActiveTree()); | 163 DCHECK(IsActiveTree()); |
148 return currently_scrolling_layer_; | 164 return currently_scrolling_layer_; |
149 } | 165 } |
150 | 166 |
167 int LayerTreeImpl::NonOverlayScrollbarThickness( | |
168 ScrollbarOrientation orientation) const { | |
169 LayerImpl* viewport = ViewportLayer(); | |
170 LayerImpl* root_container = RootContainerLayer(); | |
171 if (!viewport || !root_container) | |
172 return 0; | |
173 | |
174 DCHECK_GE(viewport->bounds().width(), root_container->bounds().width()); | |
175 DCHECK_GE(viewport->bounds().height(), root_container->bounds().height()); | |
176 | |
177 if (orientation == VERTICAL) | |
178 return viewport->bounds().width() - root_container->bounds().width(); | |
179 else | |
180 return viewport->bounds().height() - root_container->bounds().height(); | |
181 } | |
182 | |
151 void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) { | 183 void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) { |
152 if (currently_scrolling_layer_ == layer) | 184 if (currently_scrolling_layer_ == layer) |
153 return; | 185 return; |
154 | 186 |
155 if (currently_scrolling_layer_ && | 187 if (currently_scrolling_layer_ && |
156 currently_scrolling_layer_->scrollbar_animation_controller()) | 188 currently_scrolling_layer_->scrollbar_animation_controller()) |
157 currently_scrolling_layer_->scrollbar_animation_controller()-> | 189 currently_scrolling_layer_->scrollbar_animation_controller()-> |
158 DidScrollGestureEnd(CurrentPhysicalTimeTicks()); | 190 DidScrollGestureEnd(CurrentPhysicalTimeTicks()); |
159 currently_scrolling_layer_ = layer; | 191 currently_scrolling_layer_ = layer; |
160 if (layer && layer->scrollbar_animation_controller()) | 192 if (layer && layer->scrollbar_animation_controller()) |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 void LayerTreeImpl::UpdateMaxScrollOffset() { | 242 void LayerTreeImpl::UpdateMaxScrollOffset() { |
211 LayerImpl* root_scroll = RootScrollLayer(); | 243 LayerImpl* root_scroll = RootScrollLayer(); |
212 if (!root_scroll || !root_scroll->children().size()) | 244 if (!root_scroll || !root_scroll->children().size()) |
213 return; | 245 return; |
214 | 246 |
215 gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() - | 247 gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() - |
216 gfx::RectF(ScrollableViewportSize()).bottom_right(); | 248 gfx::RectF(ScrollableViewportSize()).bottom_right(); |
217 | 249 |
218 // The scrollable viewport size is based on device viewport instead of Blink's | 250 // The scrollable viewport size is based on device viewport instead of Blink's |
219 // container layer, so we need to adjust for non-overlay scrollbars. | 251 // container layer, so we need to adjust for non-overlay scrollbars. |
220 ScrollbarLayerImpl* horiz = root_scroll->horizontal_scrollbar_layer(); | 252 max_scroll.set_x(max_scroll.x() + NonOverlayScrollbarThickness(VERTICAL)); |
enne (OOO)
2013/07/30 02:32:17
This code seems like it'd be cleaner if it set Ren
aelias_OOO_until_Jul13
2013/07/30 02:52:00
OK, I'll try that. It will be useful for root ove
enne (OOO)
2013/07/30 03:44:47
Oh, I see what you're getting at. What would make
aelias_OOO_until_Jul13
2013/07/30 04:06:13
That actually is not correct. In your page scale
| |
221 ScrollbarLayerImpl* vertical = root_scroll->vertical_scrollbar_layer(); | 253 max_scroll.set_y(max_scroll.y() + NonOverlayScrollbarThickness(HORIZONTAL)); |
222 if (horiz && !horiz->is_overlay_scrollbar()) | |
223 max_scroll.set_y(max_scroll.y() + horiz->thumb_thickness()); | |
224 if (vertical && !vertical->is_overlay_scrollbar()) | |
225 max_scroll.set_x(max_scroll.x() + vertical->thumb_thickness()); | |
226 | 254 |
227 // The viewport may be larger than the contents in some cases, such as | 255 // The viewport may be larger than the contents in some cases, such as |
228 // having a vertical scrollbar but no horizontal overflow. | 256 // having a vertical scrollbar but no horizontal overflow. |
229 max_scroll.SetToMax(gfx::Vector2dF()); | 257 max_scroll.SetToMax(gfx::Vector2dF()); |
230 | 258 |
231 root_scroll_layer_->SetMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll)); | 259 root_scroll_layer_->SetMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll)); |
232 } | 260 } |
233 | 261 |
234 void LayerTreeImpl::UpdateSolidColorScrollbars() { | 262 void LayerTreeImpl::UpdateSolidColorScrollbars() { |
235 DCHECK(settings().solid_color_scrollbars); | 263 DCHECK(settings().solid_color_scrollbars); |
(...skipping 15 matching lines...) Expand all Loading... | |
251 scrollable_viewport.width() / ScrollableSize().width()); | 279 scrollable_viewport.width() / ScrollableSize().width()); |
252 } | 280 } |
253 if (ScrollbarLayerImpl* vertical = root_scroll->vertical_scrollbar_layer()) { | 281 if (ScrollbarLayerImpl* vertical = root_scroll->vertical_scrollbar_layer()) { |
254 vertical->set_vertical_adjust(vertical_adjust); | 282 vertical->set_vertical_adjust(vertical_adjust); |
255 vertical->set_visible_to_total_length_ratio( | 283 vertical->set_visible_to_total_length_ratio( |
256 scrollable_viewport.height() / ScrollableSize().height()); | 284 scrollable_viewport.height() / ScrollableSize().height()); |
257 } | 285 } |
258 } | 286 } |
259 | 287 |
260 void LayerTreeImpl::UpdateDrawProperties() { | 288 void LayerTreeImpl::UpdateDrawProperties() { |
261 if (IsActiveTree() && RootScrollLayer() && RootContainerLayer()) | 289 if (IsActiveTree()) |
262 UpdateRootScrollLayerSizeDelta(); | 290 UpdateRootScrollLayerSizeDelta(); |
263 | 291 |
264 if (settings().solid_color_scrollbars && | 292 if (settings().solid_color_scrollbars && |
265 IsActiveTree() && | 293 IsActiveTree() && |
266 RootScrollLayer()) { | 294 RootScrollLayer()) { |
267 UpdateSolidColorScrollbars(); | 295 UpdateSolidColorScrollbars(); |
268 } | 296 } |
269 | 297 |
270 needs_update_draw_properties_ = false; | 298 needs_update_draw_properties_ = false; |
271 render_surface_layer_list_.clear(); | 299 render_surface_layer_list_.clear(); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
519 void LayerTreeImpl::SetRootLayerScrollOffsetDelegate( | 547 void LayerTreeImpl::SetRootLayerScrollOffsetDelegate( |
520 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) { | 548 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) { |
521 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate; | 549 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate; |
522 if (root_scroll_layer_) { | 550 if (root_scroll_layer_) { |
523 root_scroll_layer_->SetScrollOffsetDelegate( | 551 root_scroll_layer_->SetScrollOffsetDelegate( |
524 root_layer_scroll_offset_delegate_); | 552 root_layer_scroll_offset_delegate_); |
525 } | 553 } |
526 } | 554 } |
527 | 555 |
528 void LayerTreeImpl::UpdateRootScrollLayerSizeDelta() { | 556 void LayerTreeImpl::UpdateRootScrollLayerSizeDelta() { |
529 LayerImpl* root_scroll = RootScrollLayer(); | 557 LayerImpl* viewport_layer = ViewportLayer(); |
530 LayerImpl* root_container = RootContainerLayer(); | 558 if (!viewport_layer) |
531 DCHECK(root_scroll); | 559 return; |
532 DCHECK(root_container); | 560 |
533 DCHECK(IsActiveTree()); | 561 DCHECK(IsActiveTree()); |
562 DCHECK(root_scroll_layer_); | |
534 | 563 |
535 gfx::Vector2dF scrollable_viewport_size = | 564 // This corrects fixed-position elements for 1) dynamic viewport size changes |
536 gfx::RectF(ScrollableViewportSize()).bottom_right() - gfx::PointF(); | 565 // caused by things like URL-bar hiding, and 2) impl-side page scale delta. |
566 gfx::SizeF true_viewport_size = | |
567 gfx::ScaleSize(layer_tree_host_impl_->VisibleViewportSize(), | |
568 1 / total_page_scale_factor()); | |
569 gfx::SizeF blink_perceived_viewport_size = | |
570 gfx::ScaleSize(viewport_layer->bounds(), 1 / page_scale_factor()); | |
enne (OOO)
2013/07/30 02:32:17
Just to make sure I'm reading this correctly, View
aelias_OOO_until_Jul13
2013/07/30 02:52:00
It doesn't matter because it's a delta. This is c
enne (OOO)
2013/07/30 03:44:47
I worked through an example, and I'll buy that exp
| |
571 gfx::Vector2dF delta( | |
572 true_viewport_size.width() - blink_perceived_viewport_size.width(), | |
573 true_viewport_size.height() - blink_perceived_viewport_size.height()); | |
537 | 574 |
538 gfx::Vector2dF original_viewport_size = | 575 root_scroll_layer_->SetFixedContainerSizeDelta(delta); |
539 gfx::RectF(root_container->bounds()).bottom_right() - | |
540 gfx::PointF(); | |
541 original_viewport_size.Scale(1 / page_scale_factor()); | |
542 | |
543 root_scroll->SetFixedContainerSizeDelta( | |
544 scrollable_viewport_size - original_viewport_size); | |
545 } | 576 } |
546 | 577 |
547 void LayerTreeImpl::SetLatencyInfo(const ui::LatencyInfo& latency_info) { | 578 void LayerTreeImpl::SetLatencyInfo(const ui::LatencyInfo& latency_info) { |
548 latency_info_.MergeWith(latency_info); | 579 latency_info_.MergeWith(latency_info); |
549 } | 580 } |
550 | 581 |
551 const ui::LatencyInfo& LayerTreeImpl::GetLatencyInfo() { | 582 const ui::LatencyInfo& LayerTreeImpl::GetLatencyInfo() { |
552 return latency_info_; | 583 return latency_info_; |
553 } | 584 } |
554 | 585 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
589 const std::vector<LayerImpl*> LayerTreeImpl::LayersWithCopyOutputRequest() | 620 const std::vector<LayerImpl*> LayerTreeImpl::LayersWithCopyOutputRequest() |
590 const { | 621 const { |
591 // Only the active tree needs to know about layers with copy requests, as | 622 // Only the active tree needs to know about layers with copy requests, as |
592 // they are aborted if not serviced during draw. | 623 // they are aborted if not serviced during draw. |
593 DCHECK(IsActiveTree()); | 624 DCHECK(IsActiveTree()); |
594 | 625 |
595 return layers_with_copy_output_request_; | 626 return layers_with_copy_output_request_; |
596 } | 627 } |
597 | 628 |
598 } // namespace cc | 629 } // namespace cc |
OLD | NEW |