Index: cc/layers/scrollbar_layer_unittest.cc |
diff --git a/cc/layers/scrollbar_layer_unittest.cc b/cc/layers/scrollbar_layer_unittest.cc |
index 3de091f82d86a54bde2985ff84c6f5cc91a77589..4fab6251135f9cef8507c439441ed6cdc6065508 100644 |
--- a/cc/layers/scrollbar_layer_unittest.cc |
+++ b/cc/layers/scrollbar_layer_unittest.cc |
@@ -45,9 +45,9 @@ |
const bool kIsLeftSideVerticalScrollbar = false; |
child2 = SolidColorScrollbarLayer::Create( |
scrollbar->Orientation(), thumb_thickness, |
- kIsLeftSideVerticalScrollbar, child1.get()); |
+ kIsLeftSideVerticalScrollbar, child1->id()); |
} else { |
- child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1.get()); |
+ child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1->id()); |
} |
layer_tree_root->AddChild(child1); |
layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); |
@@ -66,8 +66,7 @@ |
static_cast<PaintedScrollbarLayerImpl*>( |
layer_impl_tree_root->children()[1]); |
- EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL); |
- EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2); |
+ EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2); |
} |
TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { |
@@ -81,8 +80,7 @@ |
layer_impl_tree_root->children()[0]); |
LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; |
- EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL); |
- EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1); |
+ EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1); |
} |
TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { |
@@ -123,24 +121,19 @@ |
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
- scoped_refptr<Layer> scroll_layer = Layer::Create(); |
scoped_refptr<Layer> content_layer = Layer::Create(); |
scoped_refptr<Layer> scrollbar_layer = |
- PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root.get()); |
- |
- // Choose bounds to give max_scroll_offset = (30, 50). |
- layer_tree_root->SetBounds(gfx::Size(70, 150)); |
- scroll_layer->SetScrollClipLayer(layer_tree_root.get()); |
- scroll_layer->SetScrollOffset(gfx::Vector2d(10, 20)); |
- scroll_layer->SetBounds(gfx::Size(100, 200)); |
+ PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); |
+ |
+ layer_tree_root->SetScrollable(true); |
+ layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); |
+ layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50)); |
+ layer_tree_root->SetBounds(gfx::Size(100, 200)); |
content_layer->SetBounds(gfx::Size(100, 200)); |
host->SetRootLayer(layer_tree_root); |
- layer_tree_root->AddChild(scroll_layer); |
- scroll_layer->AddChild(content_layer); |
+ layer_tree_root->AddChild(content_layer); |
layer_tree_root->AddChild(scrollbar_layer); |
- scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer); |
- scrollbar_layer->ToScrollbarLayer()->SetClipLayer(layer_tree_root); |
layer_tree_root->SavePaintProperties(); |
content_layer->SavePaintProperties(); |
@@ -154,11 +147,10 @@ |
EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); |
EXPECT_EQ(30, cc_scrollbar_layer->maximum()); |
- layer_tree_root->SetBounds(gfx::Size(700, 1500)); |
+ layer_tree_root->SetScrollOffset(gfx::Vector2d(100, 200)); |
+ layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(300, 500)); |
+ layer_tree_root->SetBounds(gfx::Size(1000, 2000)); |
layer_tree_root->SavePaintProperties(); |
- scroll_layer->SetBounds(gfx::Size(1000, 2000)); |
- scroll_layer->SetScrollOffset(gfx::Vector2d(100, 200)); |
- scroll_layer->SavePaintProperties(); |
content_layer->SetBounds(gfx::Size(1000, 2000)); |
content_layer->SavePaintProperties(); |
@@ -171,73 +163,65 @@ |
EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos()); |
EXPECT_EQ(300, cc_scrollbar_layer->maximum()); |
- LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; |
- scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34)); |
+ layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34)); |
EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); |
EXPECT_EQ(300, cc_scrollbar_layer->maximum()); |
} |
-#define UPDATE_AND_EXTRACT_LAYER_POINTERS() \ |
- do { \ |
- scrollbar_layer->UpdateThumbAndTrackGeometry(); \ |
- root_clip_layer_impl = host->CommitAndCreateLayerImplTree(); \ |
- root_layer_impl = root_clip_layer_impl->children()[0]; \ |
- scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ |
- root_layer_impl->children()[1]); \ |
- scrollbar_layer_impl->ScrollbarParametersDidChange(); \ |
- } while (false) |
- |
TEST(ScrollbarLayerTest, ThumbRect) { |
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
- scoped_refptr<Layer> root_clip_layer = Layer::Create(); |
scoped_refptr<Layer> root_layer = Layer::Create(); |
scoped_refptr<Layer> content_layer = Layer::Create(); |
scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
- FakePaintedScrollbarLayer::Create(false, true, root_layer.get()); |
- |
- root_layer->SetScrollClipLayer(root_clip_layer.get()); |
- // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). |
- root_clip_layer->SetBounds(gfx::Size(20, 50)); |
+ FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); |
+ |
+ root_layer->SetScrollable(true); |
+ root_layer->SetMaxScrollOffset(gfx::Vector2d(80, 0)); |
root_layer->SetBounds(gfx::Size(100, 50)); |
content_layer->SetBounds(gfx::Size(100, 50)); |
- host->SetRootLayer(root_clip_layer); |
- root_clip_layer->AddChild(root_layer); |
+ host->SetRootLayer(root_layer); |
root_layer->AddChild(content_layer); |
root_layer->AddChild(scrollbar_layer); |
root_layer->SetScrollOffset(gfx::Vector2d(0, 0)); |
scrollbar_layer->SetBounds(gfx::Size(70, 10)); |
- scrollbar_layer->SetScrollLayer(root_layer.get()); |
- scrollbar_layer->SetClipLayer(root_clip_layer.get()); |
scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); |
scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); |
scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); |
scrollbar_layer->fake_scrollbar()->set_thumb_length(4); |
scrollbar_layer->UpdateThumbAndTrackGeometry(); |
- LayerImpl* root_clip_layer_impl = NULL; |
LayerImpl* root_layer_impl = NULL; |
PaintedScrollbarLayerImpl* scrollbar_layer_impl = NULL; |
// Thumb is at the edge of the scrollbar (should be inset to |
// the start of the track within the scrollbar layer's |
// position). |
- UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
+ scrollbar_layer->UpdateThumbAndTrackGeometry(); |
+ root_layer_impl = host->CommitAndCreateLayerImplTree(); |
+ scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( |
+ root_layer_impl->children()[1]); |
EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), |
scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
// Under-scroll (thumb position should clamp and be unchanged). |
root_layer->SetScrollOffset(gfx::Vector2d(-5, 0)); |
- UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
+ scrollbar_layer->UpdateThumbAndTrackGeometry(); |
+ root_layer_impl = host->CommitAndCreateLayerImplTree(); |
+ scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( |
+ root_layer_impl->children()[1]); |
EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), |
scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
// Over-scroll (thumb position should clamp on the far side). |
root_layer->SetScrollOffset(gfx::Vector2d(85, 0)); |
- UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
+ scrollbar_layer->UpdateThumbAndTrackGeometry(); |
+ root_layer_impl = host->CommitAndCreateLayerImplTree(); |
+ scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( |
+ root_layer_impl->children()[1]); |
EXPECT_EQ(gfx::Rect(56, 0, 4, 10).ToString(), |
scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
@@ -245,7 +229,10 @@ |
scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4); |
scrollbar_layer->fake_scrollbar()->set_thumb_length(6); |
- UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
+ scrollbar_layer->UpdateThumbAndTrackGeometry(); |
+ root_layer_impl = host->CommitAndCreateLayerImplTree(); |
+ scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( |
+ root_layer_impl->children()[1]); |
EXPECT_EQ(gfx::Rect(54, 0, 6, 4).ToString(), |
scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
@@ -254,7 +241,10 @@ |
scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(30, 10)); |
scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); |
- UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
+ scrollbar_layer->UpdateThumbAndTrackGeometry(); |
+ root_layer_impl = host->CommitAndCreateLayerImplTree(); |
+ scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( |
+ root_layer_impl->children()[1]); |
EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), |
scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
@@ -263,7 +253,10 @@ |
// position). |
scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6)); |
- UPDATE_AND_EXTRACT_LAYER_POINTERS(); |
+ scrollbar_layer->UpdateThumbAndTrackGeometry(); |
+ root_layer_impl = host->CommitAndCreateLayerImplTree(); |
+ scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( |
+ root_layer_impl->children()[1]); |
EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), |
scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); |
} |
@@ -339,39 +332,21 @@ |
FakeLayerTreeHost::Create(layer_tree_settings); |
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
- |
- { |
- scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
- scoped_refptr<Layer> scroll_layer = Layer::Create(); |
- scroll_layer->SetScrollClipLayer(layer_tree_root); |
- scoped_refptr<Layer> child1 = Layer::Create(); |
- scoped_refptr<Layer> child2; |
- const bool kIsLeftSideVerticalScrollbar = false; |
- child2 = SolidColorScrollbarLayer::Create( |
- scrollbar->Orientation(), kThumbThickness, |
- kIsLeftSideVerticalScrollbar, child1.get()); |
- child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer); |
- child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root); |
- scroll_layer->AddChild(child1); |
- scroll_layer->InsertChild(child2, 1); |
- layer_tree_root->AddChild(scroll_layer); |
- host->SetRootLayer(layer_tree_root); |
- } |
- LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); |
- LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; |
- |
+ LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
+ host.get(), scrollbar.Pass(), false, true, kThumbThickness); |
ScrollbarLayerImplBase* scrollbar_layer_impl = |
static_cast<PaintedScrollbarLayerImpl*>( |
- scroll_layer_impl->children()[1]); |
- |
- // Choose layer bounds to give max_scroll_offset = (8, 8). |
- layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); |
- scroll_layer_impl->SetBounds(gfx::Size(10, 10)); |
- scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f)); |
+ layer_impl_tree_root->children()[1]); |
scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
scrollbar_layer_impl->SetCurrentPos(4.f); |
scrollbar_layer_impl->SetMaximum(8); |
+ |
+ layer_impl_tree_root->SetScrollable(true); |
+ layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); |
+ layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); |
+ layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); |
+ layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); |
{ |
MockQuadCuller quad_culler; |
@@ -393,14 +368,13 @@ |
const int kThumbThickness = 3; |
const bool kIsLeftSideVerticalScrollbar = false; |
- const bool kIsOverlayScrollbar = false; |
horizontal_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( |
host_impl_->active_tree(), 1, HORIZONTAL, kThumbThickness, |
- kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
+ kIsLeftSideVerticalScrollbar); |
vertical_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( |
host_impl_->active_tree(), 2, VERTICAL, kThumbThickness, |
- kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar); |
+ kIsLeftSideVerticalScrollbar); |
} |
protected: |
@@ -482,16 +456,15 @@ |
void SetScrollbarBounds(gfx::Size bounds) { bounds_ = bounds; } |
virtual void BeginTest() OVERRIDE { |
- scroll_layer_ = Layer::Create(); |
- layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
- |
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
- scrollbar_layer_ = |
- PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_.get()); |
- scrollbar_layer_->SetScrollLayer(scroll_layer_); |
+ scrollbar_layer_ = PaintedScrollbarLayer::Create(scrollbar.Pass(), 1); |
scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); |
scrollbar_layer_->SetBounds(bounds_); |
layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); |
+ |
+ scroll_layer_ = Layer::Create(); |
+ scrollbar_layer_->SetScrollLayerId(scroll_layer_->id()); |
+ layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
PostSetNeedsCommitToMainThread(); |
} |
@@ -611,10 +584,10 @@ |
SolidColorScrollbarLayer::Create(scrollbar->Orientation(), |
kThumbThickness, |
kIsLeftSideVerticalScrollbar, |
- layer_tree_root.get()); |
+ layer_tree_root->id()); |
} else { |
scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(), |
- layer_tree_root.get()); |
+ layer_tree_root->id()); |
} |
layer_tree_root->AddChild(content_layer); |
layer_tree_root->AddChild(scrollbar_layer); |
@@ -624,6 +597,7 @@ |
scrollbar_layer->SetIsDrawable(true); |
scrollbar_layer->SetBounds(gfx::Size(100, 100)); |
layer_tree_root->SetScrollOffset(gfx::Vector2d(10, 20)); |
+ layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(30, 50)); |
layer_tree_root->SetBounds(gfx::Size(100, 200)); |
content_layer->SetBounds(gfx::Size(100, 200)); |
scrollbar_layer->draw_properties().content_bounds = gfx::Size(100, 200); |
@@ -690,7 +664,7 @@ |
scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
scoped_refptr<Layer> content_layer = Layer::Create(); |
scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
- FakePaintedScrollbarLayer::Create(false, true, layer_tree_root.get()); |
+ FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); |
layer_tree_root->AddChild(content_layer); |
layer_tree_root->AddChild(scrollbar_layer); |