Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(902)

Unified Diff: cc/layers/scrollbar_layer_unittest.cc

Issue 23983047: Pinch/Zoom Infrastructure & Plumbing CL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add fix for empty scroll-layer bounds. Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: cc/layers/scrollbar_layer_unittest.cc
diff --git a/cc/layers/scrollbar_layer_unittest.cc b/cc/layers/scrollbar_layer_unittest.cc
index 53a9fa87b68228ef4d9735123b2f99e8bad5a04c..b93a0a88a85601342219836ced5fb2c28be08b6a 100644
--- a/cc/layers/scrollbar_layer_unittest.cc
+++ b/cc/layers/scrollbar_layer_unittest.cc
@@ -45,9 +45,9 @@ LayerImpl* LayerImplForScrollAreaAndScrollbar(
const bool kIsLeftSideVerticalScrollbar = false;
child2 = SolidColorScrollbarLayer::Create(
scrollbar->Orientation(), thumb_thickness,
- kIsLeftSideVerticalScrollbar, child1->id());
+ kIsLeftSideVerticalScrollbar, child1.get());
} else {
- child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1->id());
+ child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1.get());
}
layer_tree_root->AddChild(child1);
layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1);
@@ -66,7 +66,8 @@ TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) {
static_cast<PaintedScrollbarLayerImpl*>(
layer_impl_tree_root->children()[1]);
- EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2);
+ EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL);
+ EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2);
}
TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) {
@@ -80,7 +81,8 @@ TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) {
layer_impl_tree_root->children()[0]);
LayerImpl* cc_child2 = layer_impl_tree_root->children()[1];
- EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1);
+ EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL);
+ EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1);
}
TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
@@ -121,19 +123,24 @@ TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) {
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->id());
+ PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root.get());
- 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));
+ // 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));
content_layer->SetBounds(gfx::Size(100, 200));
host->SetRootLayer(layer_tree_root);
- layer_tree_root->AddChild(content_layer);
+ layer_tree_root->AddChild(scroll_layer);
+ scroll_layer->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();
@@ -147,10 +154,11 @@ TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) {
EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos());
EXPECT_EQ(30, cc_scrollbar_layer->maximum());
- 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->SetBounds(gfx::Size(700, 1500));
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();
@@ -163,65 +171,71 @@ TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) {
EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos());
EXPECT_EQ(300, cc_scrollbar_layer->maximum());
- layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34));
+ LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0];
+ scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34));
EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos());
EXPECT_EQ(300, cc_scrollbar_layer->maximum());
}
+#define UPDATE_AND_EXTRACK_LAYER_POINTERS \
aelias_OOO_until_Jul13 2014/01/16 03:44:04 typo: should be EXTRACT
wjmaclean 2014/01/16 15:07:32 Done.
+ 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(); \
+
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->id());
+ FakePaintedScrollbarLayer::Create(false, true, root_layer.get());
- root_layer->SetScrollable(true);
- root_layer->SetMaxScrollOffset(gfx::Vector2d(80, 0));
+ 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));
root_layer->SetBounds(gfx::Size(100, 50));
content_layer->SetBounds(gfx::Size(100, 50));
- host->SetRootLayer(root_layer);
+ host->SetRootLayer(root_clip_layer);
+ root_clip_layer->AddChild(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).
- scrollbar_layer->UpdateThumbAndTrackGeometry();
- root_layer_impl = host->CommitAndCreateLayerImplTree();
- scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
- root_layer_impl->children()[1]);
+ UPDATE_AND_EXTRACK_LAYER_POINTERS
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));
- scrollbar_layer->UpdateThumbAndTrackGeometry();
- root_layer_impl = host->CommitAndCreateLayerImplTree();
- scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
- root_layer_impl->children()[1]);
+ UPDATE_AND_EXTRACK_LAYER_POINTERS
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));
- scrollbar_layer->UpdateThumbAndTrackGeometry();
- root_layer_impl = host->CommitAndCreateLayerImplTree();
- scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
- root_layer_impl->children()[1]);
+ UPDATE_AND_EXTRACK_LAYER_POINTERS
EXPECT_EQ(gfx::Rect(56, 0, 4, 10).ToString(),
scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
@@ -229,10 +243,7 @@ TEST(ScrollbarLayerTest, ThumbRect) {
scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4);
scrollbar_layer->fake_scrollbar()->set_thumb_length(6);
- scrollbar_layer->UpdateThumbAndTrackGeometry();
- root_layer_impl = host->CommitAndCreateLayerImplTree();
- scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
- root_layer_impl->children()[1]);
+ UPDATE_AND_EXTRACK_LAYER_POINTERS
EXPECT_EQ(gfx::Rect(54, 0, 6, 4).ToString(),
scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
@@ -241,10 +252,7 @@ TEST(ScrollbarLayerTest, ThumbRect) {
scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(30, 10));
scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
- scrollbar_layer->UpdateThumbAndTrackGeometry();
- root_layer_impl = host->CommitAndCreateLayerImplTree();
- scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
- root_layer_impl->children()[1]);
+ UPDATE_AND_EXTRACK_LAYER_POINTERS
EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(),
scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
@@ -253,10 +261,7 @@ TEST(ScrollbarLayerTest, ThumbRect) {
// position).
scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6));
- scrollbar_layer->UpdateThumbAndTrackGeometry();
- root_layer_impl = host->CommitAndCreateLayerImplTree();
- scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
- root_layer_impl->children()[1]);
+ UPDATE_AND_EXTRACK_LAYER_POINTERS
EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(),
scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
}
@@ -332,22 +337,40 @@ TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) {
FakeLayerTreeHost::Create(layer_tree_settings);
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
- LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
- host.get(), scrollbar.Pass(), false, true, kThumbThickness);
+
+ {
+ 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];
+
ScrollbarLayerImplBase* scrollbar_layer_impl =
static_cast<PaintedScrollbarLayerImpl*>(
- layer_impl_tree_root->children()[1]);
+ 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));
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;
AppendQuadsData data;
@@ -368,13 +391,14 @@ class ScrollbarLayerSolidColorThumbTest : public testing::Test {
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);
+ kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar);
vertical_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create(
host_impl_->active_tree(), 2, VERTICAL, kThumbThickness,
- kIsLeftSideVerticalScrollbar);
+ kIsLeftSideVerticalScrollbar, kIsOverlayScrollbar);
}
protected:
@@ -456,16 +480,17 @@ class ScrollbarLayerTestMaxTextureSize : public LayerTreeTest {
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(), 1);
+ scrollbar_layer_ =
+ PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_.get());
+ scrollbar_layer_->SetScrollLayer(scroll_layer_);
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();
}
@@ -584,10 +609,10 @@ class ScrollbarLayerTestResourceCreation : public testing::Test {
SolidColorScrollbarLayer::Create(scrollbar->Orientation(),
kThumbThickness,
kIsLeftSideVerticalScrollbar,
- layer_tree_root->id());
+ layer_tree_root.get());
} else {
scrollbar_layer = PaintedScrollbarLayer::Create(scrollbar.Pass(),
- layer_tree_root->id());
+ layer_tree_root.get());
}
layer_tree_root->AddChild(content_layer);
layer_tree_root->AddChild(scrollbar_layer);
@@ -598,7 +623,6 @@ class ScrollbarLayerTestResourceCreation : public testing::Test {
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);
@@ -665,7 +689,7 @@ class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
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->id());
+ FakePaintedScrollbarLayer::Create(false, true, layer_tree_root.get());
layer_tree_root->AddChild(content_layer);
layer_tree_root->AddChild(scrollbar_layer);

Powered by Google App Engine
This is Rietveld 408576698