diff options
author | wangxianzhu@chromium.org <wangxianzhu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-27 03:58:57 +0000 |
---|---|---|
committer | wangxianzhu@chromium.org <wangxianzhu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-06-27 03:58:57 +0000 |
commit | 9942a7337b595557fb8fdbb76bca0e3b978100f7 (patch) | |
tree | 630da1614d423bf4e21b493790a9fa9eaa49183a /cc | |
parent | 8465b58fd70487e78b51e0e53f0b606f4d318ac5 (diff) | |
download | chromium_src-9942a7337b595557fb8fdbb76bca0e3b978100f7.zip chromium_src-9942a7337b595557fb8fdbb76bca0e3b978100f7.tar.gz chromium_src-9942a7337b595557fb8fdbb76bca0e3b978100f7.tar.bz2 |
Update scrollbar parameters when it is associated to layer
Otherwise the scrollbar will be in invalid state (max=0, pos=0)
until the next time scrollbar parameters change.
BUG=388152
TEST=LayerImplScrollTest.SetNewScrollbarParameters
Review URL: https://codereview.chromium.org/358693007
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@280233 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r-- | cc/animation/scrollbar_animation_controller_linear_fade_unittest.cc | 4 | ||||
-rw-r--r-- | cc/animation/scrollbar_animation_controller_thinning_unittest.cc | 4 | ||||
-rw-r--r-- | cc/layers/layer_impl_unittest.cc | 28 | ||||
-rw-r--r-- | cc/layers/painted_scrollbar_layer.cc | 4 | ||||
-rw-r--r-- | cc/layers/scrollbar_layer_impl_base.cc | 26 | ||||
-rw-r--r-- | cc/layers/scrollbar_layer_impl_base.h | 6 | ||||
-rw-r--r-- | cc/layers/solid_color_scrollbar_layer.cc | 4 | ||||
-rw-r--r-- | cc/trees/layer_tree_host_impl_unittest.cc | 6 |
8 files changed, 51 insertions, 31 deletions
diff --git a/cc/animation/scrollbar_animation_controller_linear_fade_unittest.cc b/cc/animation/scrollbar_animation_controller_linear_fade_unittest.cc index c503335..e5801d6 100644 --- a/cc/animation/scrollbar_animation_controller_linear_fade_unittest.cc +++ b/cc/animation/scrollbar_animation_controller_linear_fade_unittest.cc @@ -50,8 +50,8 @@ class ScrollbarAnimationControllerLinearFadeTest LayerImpl* scroll_layer_ptr = scroll_layer.get(); clip_layer_->AddChild(scroll_layer.Pass()); - scrollbar_layer_->SetClipLayerById(clip_layer_->id()); - scrollbar_layer_->SetScrollLayerById(scroll_layer_ptr->id()); + scrollbar_layer_->SetScrollLayerAndClipLayerByIds(scroll_layer_ptr->id(), + clip_layer_->id()); clip_layer_->SetBounds(gfx::Size(100, 100)); scroll_layer_ptr->SetBounds(gfx::Size(50, 50)); diff --git a/cc/animation/scrollbar_animation_controller_thinning_unittest.cc b/cc/animation/scrollbar_animation_controller_thinning_unittest.cc index c0ab515..6dad5b0 100644 --- a/cc/animation/scrollbar_animation_controller_thinning_unittest.cc +++ b/cc/animation/scrollbar_animation_controller_thinning_unittest.cc @@ -49,8 +49,8 @@ class ScrollbarAnimationControllerThinningTest kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); - scrollbar_layer_->SetClipLayerById(clip_layer_->id()); - scrollbar_layer_->SetScrollLayerById(scroll_layer_ptr->id()); + scrollbar_layer_->SetScrollLayerAndClipLayerByIds(scroll_layer_ptr->id(), + clip_layer_->id()); clip_layer_->SetBounds(gfx::Size(100, 100)); scroll_layer_ptr->SetBounds(gfx::Size(50, 50)); diff --git a/cc/layers/layer_impl_unittest.cc b/cc/layers/layer_impl_unittest.cc index 281a3f1..39469c1 100644 --- a/cc/layers/layer_impl_unittest.cc +++ b/cc/layers/layer_impl_unittest.cc @@ -4,6 +4,7 @@ #include "cc/layers/layer_impl.h" +#include "cc/layers/painted_scrollbar_layer_impl.h" #include "cc/output/filter_operation.h" #include "cc/output/filter_operations.h" #include "cc/test/fake_impl_proxy.h" @@ -433,6 +434,8 @@ class LayerImplScrollTest : public testing::Test { return host_impl_.active_tree()->root_layer()->children()[0]; } + LayerTreeImpl* tree() { return host_impl_.active_tree(); } + private: FakeImplProxy proxy_; TestSharedBitmapManager shared_bitmap_manager_; @@ -659,5 +662,30 @@ TEST_F(LayerImplScrollTest, DISABLED_ScrollUserUnscrollableLayer) { EXPECT_VECTOR_EQ(gfx::Vector2dF(30.5f, 5), layer()->TotalScrollOffset()); } +TEST_F(LayerImplScrollTest, SetNewScrollbarParameters) { + gfx::Vector2d scroll_offset(10, 5); + layer()->SetScrollOffset(scroll_offset); + + scoped_ptr<PaintedScrollbarLayerImpl> vertical_scrollbar( + PaintedScrollbarLayerImpl::Create(tree(), 100, VERTICAL)); + vertical_scrollbar->SetScrollLayerAndClipLayerByIds( + layer()->id(), tree()->root_layer()->id()); + + int expected_vertical_maximum = + layer()->bounds().height() - tree()->root_layer()->bounds().height(); + EXPECT_EQ(expected_vertical_maximum, vertical_scrollbar->maximum()); + EXPECT_EQ(scroll_offset.y(), vertical_scrollbar->current_pos()); + + scoped_ptr<PaintedScrollbarLayerImpl> horizontal_scrollbar( + PaintedScrollbarLayerImpl::Create(tree(), 101, HORIZONTAL)); + horizontal_scrollbar->SetScrollLayerAndClipLayerByIds( + layer()->id(), tree()->root_layer()->id()); + + int expected_horizontal_maximum = + layer()->bounds().width() - tree()->root_layer()->bounds().width(); + EXPECT_EQ(expected_horizontal_maximum, horizontal_scrollbar->maximum()); + EXPECT_EQ(scroll_offset.x(), horizontal_scrollbar->current_pos()); +} + } // namespace } // namespace cc diff --git a/cc/layers/painted_scrollbar_layer.cc b/cc/layers/painted_scrollbar_layer.cc index 9c5ab88..3764689 100644 --- a/cc/layers/painted_scrollbar_layer.cc +++ b/cc/layers/painted_scrollbar_layer.cc @@ -152,8 +152,8 @@ void PaintedScrollbarLayer::PushScrollClipPropertiesTo(LayerImpl* layer) { PaintedScrollbarLayerImpl* scrollbar_layer = static_cast<PaintedScrollbarLayerImpl*>(layer); - scrollbar_layer->SetScrollLayerById(scroll_layer_id_); - scrollbar_layer->SetClipLayerById(clip_layer_id_); + scrollbar_layer->SetScrollLayerAndClipLayerByIds(scroll_layer_id_, + clip_layer_id_); } void PaintedScrollbarLayer::SetLayerTreeHost(LayerTreeHost* host) { diff --git a/cc/layers/scrollbar_layer_impl_base.cc b/cc/layers/scrollbar_layer_impl_base.cc index 9db0254..956f617 100644 --- a/cc/layers/scrollbar_layer_impl_base.cc +++ b/cc/layers/scrollbar_layer_impl_base.cc @@ -41,8 +41,8 @@ void ScrollbarLayerImplBase::PushPropertiesTo(LayerImpl* layer) { void ScrollbarLayerImplBase::PushScrollClipPropertiesTo(LayerImpl* layer) { DCHECK(layer->ToScrollbarLayer()); - layer->ToScrollbarLayer()->SetScrollLayerById(ScrollLayerId()); - layer->ToScrollbarLayer()->SetClipLayerById(ClipLayerId()); + layer->ToScrollbarLayer()->SetScrollLayerAndClipLayerByIds(ScrollLayerId(), + ClipLayerId()); } ScrollbarLayerImplBase* ScrollbarLayerImplBase::ToScrollbarLayer() { @@ -77,28 +77,22 @@ void RegisterScrollbarWithLayers(ScrollbarLayerImplBase* scrollbar, } } // namespace -void ScrollbarLayerImplBase::SetScrollLayerById(int id) { - LayerImpl* scroll_layer = layer_tree_impl()->LayerById(id); - if (scroll_layer_ == scroll_layer) +void ScrollbarLayerImplBase::SetScrollLayerAndClipLayerByIds( + int scroll_layer_id, + int clip_layer_id) { + LayerImpl* scroll_layer = layer_tree_impl()->LayerById(scroll_layer_id); + LayerImpl* clip_layer = layer_tree_impl()->LayerById(clip_layer_id); + if (scroll_layer_ == scroll_layer && clip_layer_ == clip_layer) return; RegisterScrollbarWithLayers( this, clip_layer_, scroll_layer_, &LayerImpl::RemoveScrollbar); scroll_layer_ = scroll_layer; - RegisterScrollbarWithLayers( - this, clip_layer_, scroll_layer_, &LayerImpl::AddScrollbar); -} - -void ScrollbarLayerImplBase::SetClipLayerById(int id) { - LayerImpl* clip_layer = layer_tree_impl()->LayerById(id); - if (clip_layer_ == clip_layer) - return; - - RegisterScrollbarWithLayers( - this, clip_layer_, scroll_layer_, &LayerImpl::RemoveScrollbar); clip_layer_ = clip_layer; RegisterScrollbarWithLayers( this, clip_layer_, scroll_layer_, &LayerImpl::AddScrollbar); + + ScrollbarParametersDidChange(); } gfx::Rect ScrollbarLayerImplBase::ScrollbarLayerRectToContentRect( diff --git a/cc/layers/scrollbar_layer_impl_base.h b/cc/layers/scrollbar_layer_impl_base.h index e7a2fc7..435943d 100644 --- a/cc/layers/scrollbar_layer_impl_base.h +++ b/cc/layers/scrollbar_layer_impl_base.h @@ -19,13 +19,13 @@ class CC_EXPORT ScrollbarLayerImplBase : public LayerImpl { int ScrollLayerId() const { return scroll_layer_ ? scroll_layer_->id() : Layer::INVALID_ID; } - void ClearScrollLayer() { scroll_layer_ = NULL; } - void SetScrollLayerById(int id); int ClipLayerId() const { return clip_layer_ ? clip_layer_->id() : Layer::INVALID_ID; } + + void SetScrollLayerAndClipLayerByIds(int scroll_layer_id, int clip_layer_id); + void ClearScrollLayer() { scroll_layer_ = NULL; } void ClearClipLayer() { clip_layer_ = NULL; } - void SetClipLayerById(int id); float current_pos() const { return current_pos_; } void SetCurrentPos(float current_pos); diff --git a/cc/layers/solid_color_scrollbar_layer.cc b/cc/layers/solid_color_scrollbar_layer.cc index 8749398..7ea7265 100644 --- a/cc/layers/solid_color_scrollbar_layer.cc +++ b/cc/layers/solid_color_scrollbar_layer.cc @@ -65,8 +65,8 @@ void SolidColorScrollbarLayer::PushScrollClipPropertiesTo(LayerImpl* layer) { SolidColorScrollbarLayerImpl* scrollbar_layer = static_cast<SolidColorScrollbarLayerImpl*>(layer); - scrollbar_layer->SetScrollLayerById(scroll_layer_id_); - scrollbar_layer->SetClipLayerById(clip_layer_id_); + scrollbar_layer->SetScrollLayerAndClipLayerByIds(scroll_layer_id_, + clip_layer_id_); } void SolidColorScrollbarLayer::SetNeedsDisplayRect(const gfx::RectF&) { diff --git a/cc/trees/layer_tree_host_impl_unittest.cc b/cc/trees/layer_tree_host_impl_unittest.cc index bfe5938..ed38144 100644 --- a/cc/trees/layer_tree_host_impl_unittest.cc +++ b/cc/trees/layer_tree_host_impl_unittest.cc @@ -1360,11 +1360,10 @@ class LayerTreeHostImplOverridePhysicalTime : public LayerTreeHostImpl { SolidColorScrollbarLayerImpl::Create( \ host_impl_->active_tree(), 4, VERTICAL, 10, 0, false, true); \ EXPECT_FLOAT_EQ(0.f, scrollbar->opacity()); \ - scrollbar->SetScrollLayerById(2); \ - scrollbar->SetClipLayerById(1); \ \ scroll->AddChild(contents.Pass()); \ root->AddChild(scroll.Pass()); \ + scrollbar->SetScrollLayerAndClipLayerByIds(2, 1); \ root->AddChild(scrollbar.PassAs<LayerImpl>()); \ \ host_impl_->active_tree()->SetRootLayer(root.Pass()); \ @@ -1523,11 +1522,10 @@ void LayerTreeHostImplTest::SetupMouseMoveAtWithDeviceScale( scrollbar->SetBounds(gfx::Size(15, viewport_size.height())); scrollbar->SetContentBounds(gfx::Size(15, viewport_size.height())); scrollbar->SetPosition(gfx::Point(285, 0)); - scrollbar->SetClipLayerById(1); - scrollbar->SetScrollLayerById(2); scroll->AddChild(contents.Pass()); root->AddChild(scroll.Pass()); + scrollbar->SetScrollLayerAndClipLayerByIds(2, 1); root->AddChild(scrollbar.PassAs<LayerImpl>()); host_impl_->active_tree()->SetRootLayer(root.Pass()); |