Chromium Code Reviews| Index: cc/layers/layer.cc |
| diff --git a/cc/layers/layer.cc b/cc/layers/layer.cc |
| index 7110dc70812c7987694b81fb8549345cc0c88d2d..5b76198133777e342cf4748361b1348decfa7313 100644 |
| --- a/cc/layers/layer.cc |
| +++ b/cc/layers/layer.cc |
| @@ -16,6 +16,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" |
| @@ -39,7 +40,7 @@ Layer::Layer() |
| ignore_set_needs_commit_(false), |
| parent_(NULL), |
| layer_tree_host_(NULL), |
| - scrollable_(false), |
| + scroll_clip_layer_(NULL), |
| should_scroll_on_main_thread_(false), |
| have_wheel_event_handlers_(false), |
| user_scrollable_horizontal_(true), |
| @@ -679,9 +680,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( |
|
aelias_OOO_until_Jul13
2014/01/16 03:44:04
Instead of doing this, I think we should make Blin
wjmaclean
2014/01/16 15:07:32
Hmm, but the design doc specifies (and I have alwa
enne (OOO)
2014/01/16 19:35:53
I disagree. I don't think Javascript is ever goin
aelias_OOO_until_Jul13
2014/01/16 19:49:26
For the purpose of this comment I am including Web
|
| + scroll_offset, this); |
| + } |
| + |
| if (scroll_offset_ == scroll_offset) |
| return; |
| scroll_offset_ = scroll_offset; |
| + |
| SetNeedsCommit(); |
| } |
| @@ -700,19 +708,43 @@ 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(); |
| +// TODO(wjmaclean) We should template this and put it into LayerTreeHostCommon |
|
aelias_OOO_until_Jul13
2014/01/16 03:44:04
I don't believe main-thread Layers need to know ab
wjmaclean
2014/01/16 15:07:32
Main thread layers need to know in order to deal w
|
| +// 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 (!scroll_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 != scroll_clip_layer_); |
| + DCHECK(current_layer == scroll_clip_layer_); |
| + |
| + gfx::Vector2dF max_offset( |
| + scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(), |
| + scaled_scroll_bounds.height() - scroll_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::SetScrollClipLayer(Layer* clip_layer) { |
| DCHECK(IsPropertyChangeAllowed()); |
| - if (scrollable_ == scrollable) |
| + if (scroll_clip_layer_ == clip_layer) |
| return; |
| - scrollable_ = scrollable; |
| + scroll_clip_layer_ = clip_layer; |
| SetNeedsCommit(); |
| } |
| @@ -915,10 +947,10 @@ void Layer::PushPropertiesTo(LayerImpl* layer) { |
| layer->SetTransform(transform_); |
| DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
| - layer->SetScrollable(scrollable_); |
| + layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_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_) |