Chromium Code Reviews| Index: cc/layers/layer.cc |
| diff --git a/cc/layers/layer.cc b/cc/layers/layer.cc |
| index 8d07366441b10ff6e5d3359c64851d1cc9a64b47..76c8dadc0fe107c66f7952cea4b4b2e3aed91f7b 100644 |
| --- a/cc/layers/layer.cc |
| +++ b/cc/layers/layer.cc |
| @@ -15,6 +15,7 @@ |
| #include "cc/animation/layer_animation_controller.h" |
| #include "cc/layers/layer_client.h" |
| #include "cc/layers/layer_impl.h" |
| +#include "cc/layers/scrollbar_layer_interface.h" |
| #include "cc/output/copy_output_request.h" |
| #include "cc/output/copy_output_result.h" |
| #include "cc/trees/layer_tree_host.h" |
| @@ -38,7 +39,7 @@ Layer::Layer() |
| ignore_set_needs_commit_(false), |
| parent_(NULL), |
| layer_tree_host_(NULL), |
| - scrollable_(false), |
| + clip_layer_(NULL), |
| should_scroll_on_main_thread_(false), |
| have_wheel_event_handlers_(false), |
| user_scrollable_horizontal_(true), |
| @@ -611,9 +612,16 @@ void Layer::RemoveClipChild(Layer* child) { |
| void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { |
| DCHECK(IsPropertyChangeAllowed()); |
| + |
| + if (layer_tree_host()) { |
| + scroll_offset = layer_tree_host()->DistributeScrollOffsetToViewports( |
| + scroll_offset, this); |
| + } |
| + |
| if (scroll_offset_ == scroll_offset) |
| return; |
| scroll_offset_ = scroll_offset; |
| + |
| SetNeedsCommit(); |
| } |
| @@ -632,19 +640,56 @@ void Layer::SetScrollOffsetFromImplSide(gfx::Vector2d scroll_offset) { |
| // "this" may have been destroyed during the process. |
| } |
| -void Layer::SetMaxScrollOffset(gfx::Vector2d max_scroll_offset) { |
| - DCHECK(IsPropertyChangeAllowed()); |
| - if (max_scroll_offset_ == max_scroll_offset) |
| - return; |
| - max_scroll_offset_ = max_scroll_offset; |
| - SetNeedsCommit(); |
| +gfx::Vector2d Layer::TotalViewportScrollOffset() const { |
|
enne (OOO)
2013/11/14 22:59:01
This seems like a LayerTreeHost function and not a
wjmaclean
2013/12/24 21:03:49
Done.
|
| + if (!layer_tree_host() || |
| + (this != layer_tree_host()->inner_viewport_scroll_layer() && |
| + this != layer_tree_host()->outer_viewport_scroll_layer())) |
| + return scroll_offset(); |
| + |
| + gfx::Vector2d offset = |
| + layer_tree_host()->inner_viewport_scroll_layer()->scroll_offset(); |
| + if (layer_tree_host()->outer_viewport_scroll_layer()) |
| + offset += layer_tree_host()->outer_viewport_scroll_layer()->scroll_offset(); |
| + return offset; |
| +} |
| + |
| +// TODO(wjmaclean) We should template this and put it into LayerTreeHostCommon |
| +// so that both Layer and LayerImpl are using the same code. In order |
| +// to template it we should avoid calling layer_tree_host() by giving |
| +// Layer/LayerImpl local accessors for page_scale_layer() and |
| +// page_scale_factor(). |
| +gfx::Vector2d Layer::MaxScrollOffset() const { |
| + if (!clip_layer_) |
| + return gfx::Vector2d(); |
| + |
| + gfx::Size scaled_scroll_bounds(bounds()); |
| + Layer const* current_layer = this; |
| + Layer const* page_scale_layer = layer_tree_host()->page_scale_layer(); |
| + float scale_factor = 1.f; |
| + do { |
| + if (current_layer == page_scale_layer) { |
| + scale_factor = layer_tree_host()->page_scale_factor(); |
| + scaled_scroll_bounds.SetSize( |
| + scale_factor * scaled_scroll_bounds.width(), |
| + scale_factor * scaled_scroll_bounds.height()); |
| + } |
| + current_layer = current_layer->parent(); |
| + } while (current_layer && current_layer != clip_layer_); |
| + DCHECK(current_layer == clip_layer_); |
| + |
| + gfx::Vector2dF max_offset( |
| + scaled_scroll_bounds.width() - clip_layer_->bounds().width(), |
| + scaled_scroll_bounds.height() - clip_layer_->bounds().height()); |
| + // We need the final scroll offset to be in CSS coords. |
| + max_offset.Scale(1 / scale_factor); |
| + return gfx::Vector2d(max_offset.x(), max_offset.y()); |
| } |
| -void Layer::SetScrollable(bool scrollable) { |
| +void Layer::SetScrollable(Layer* clip_layer) { |
| DCHECK(IsPropertyChangeAllowed()); |
| - if (scrollable_ == scrollable) |
| + if (clip_layer_ == clip_layer) |
| return; |
| - scrollable_ = scrollable; |
| + clip_layer_ = clip_layer; |
| SetNeedsCommit(); |
| } |
| @@ -844,10 +889,9 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { |
| layer->SetTransform(transform_); |
| DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
| - layer->SetScrollable(scrollable_); |
| + layer->SetScrollable(clip_layer_ ? clip_layer_->id() : Layer::INVALID_ID); |
| layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
| - layer->SetMaxScrollOffset(max_scroll_offset_); |
| LayerImpl* scroll_parent = NULL; |
| if (scroll_parent_) |