Index: cc/layers/scrollbar_layer_unittest.cc |
diff --git a/cc/layers/scrollbar_layer_unittest.cc b/cc/layers/scrollbar_layer_unittest.cc |
index 0c160c400d9b1fdc72de719fe598db04d5c51ef0..216b8f2364b850e4082bd89a60467f072a0bf575 100644 |
--- a/cc/layers/scrollbar_layer_unittest.cc |
+++ b/cc/layers/scrollbar_layer_unittest.cc |
@@ -6,7 +6,10 @@ |
#include "cc/animation/scrollbar_animation_controller.h" |
#include "cc/layers/append_quads_data.h" |
+#include "cc/layers/scrollbar_layer_base.h" |
#include "cc/layers/scrollbar_layer_impl.h" |
+#include "cc/layers/solid_color_scrollbar_layer.h" |
+#include "cc/layers/solid_color_scrollbar_layer_impl.h" |
#include "cc/quads/solid_color_draw_quad.h" |
#include "cc/resources/prioritized_resource_manager.h" |
#include "cc/resources/priority_calculator.h" |
@@ -32,12 +35,19 @@ namespace { |
LayerImpl* LayerImplForScrollAreaAndScrollbar( |
FakeLayerTreeHost* host, |
scoped_ptr<Scrollbar> scrollbar, |
- bool reverse_order) { |
+ bool reverse_order, |
+ bool use_solid_color_scrollbar, |
+ int thumb_thickness) { |
scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
scoped_refptr<Layer> child1 = Layer::Create(); |
- scoped_refptr<Layer> child2 = |
- ScrollbarLayer::Create(scrollbar.Pass(), |
- child1->id()); |
+ scoped_refptr<Layer> child2; |
+ if (use_solid_color_scrollbar) { |
+ SkColor color = SkColorSetARGB(128, 128, 128, 128); |
+ child2 = SolidColorScrollbarLayer::Create( |
+ scrollbar->Orientation(), thumb_thickness, color, child1->id()); |
+ } else { |
+ child2 = ScrollbarLayer::Create(scrollbar.Pass(), child1->id()); |
+ } |
layer_tree_root->AddChild(child1); |
layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); |
host->SetRootLayer(layer_tree_root); |
@@ -47,8 +57,8 @@ LayerImpl* LayerImplForScrollAreaAndScrollbar( |
TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { |
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
- LayerImpl* layer_impl_tree_root = |
- LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); |
+ LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
+ host.get(), scrollbar.Pass(), false, false, 0); |
LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; |
ScrollbarLayerImpl* cc_child2 = static_cast<ScrollbarLayerImpl*>( |
@@ -60,8 +70,8 @@ TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { |
TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { |
scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
- LayerImpl* layer_impl_tree_root = |
- LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), true); |
+ LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
+ host.get(), scrollbar.Pass(), true, false, 0); |
ScrollbarLayerImpl* cc_child1 = static_cast<ScrollbarLayerImpl*>( |
layer_impl_tree_root->children()[0]); |
@@ -75,8 +85,8 @@ TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { |
// Create and attach a non-overlay scrollbar. |
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
- LayerImpl* layer_impl_tree_root = |
- LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); |
+ LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
+ host.get(), scrollbar.Pass(), false, false, 0); |
ScrollbarLayerImpl* scrollbar_layer_impl = |
static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); |
@@ -90,8 +100,8 @@ TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { |
// Create and attach an overlay scrollbar. |
scrollbar.reset(new FakeScrollbar(false, false, true)); |
- layer_impl_tree_root = |
- LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); |
+ layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
+ host.get(), scrollbar.Pass(), false, false, 0); |
scrollbar_layer_impl = |
static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); |
@@ -130,8 +140,8 @@ TEST(ScrollbarLayerTest, ScrollOffsetSynchronization) { |
ScrollbarLayerImpl* cc_scrollbar_layer = |
static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); |
- EXPECT_EQ(10.f, cc_scrollbar_layer->CurrentPos()); |
- EXPECT_EQ(30, cc_scrollbar_layer->Maximum()); |
+ 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)); |
@@ -146,31 +156,31 @@ TEST(ScrollbarLayerTest, ScrollOffsetSynchronization) { |
EXPECT_EQ(scrollbar_controller, |
layer_impl_tree_root->scrollbar_animation_controller()); |
- EXPECT_EQ(100.f, cc_scrollbar_layer->CurrentPos()); |
- EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); |
+ 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)); |
- EXPECT_EQ(112.f, cc_scrollbar_layer->CurrentPos()); |
- EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); |
+ EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); |
+ EXPECT_EQ(300, cc_scrollbar_layer->maximum()); |
} |
TEST(ScrollbarLayerTest, SolidColorDrawQuads) { |
+ const int thumb_thickness = 3; |
+ const int track_length = 100; |
+ |
LayerTreeSettings layer_tree_settings; |
- layer_tree_settings.solid_color_scrollbars = true; |
- layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; |
scoped_ptr<FakeLayerTreeHost> host = |
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); |
- ScrollbarLayerImpl* scrollbar_layer_impl = |
+ LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
+ host.get(), scrollbar.Pass(), false, true, thumb_thickness); |
+ ScrollbarLayerImplBase* scrollbar_layer_impl = |
static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); |
- scrollbar_layer_impl->set_thumb_thickness(3); |
- scrollbar_layer_impl->SetCurrentPos(10.f); |
- scrollbar_layer_impl->SetMaximum(100); |
- scrollbar_layer_impl->set_track_length(100); |
+ scrollbar_layer_impl->SetBounds(gfx::Size(track_length, thumb_thickness)); |
+ scrollbar_layer_impl->set_current_pos(10.f); |
+ scrollbar_layer_impl->set_maximum(100); |
scrollbar_layer_impl->set_visible_to_total_length_ratio(0.4f); |
// Thickness should be overridden to 3. |
@@ -217,22 +227,22 @@ TEST(ScrollbarLayerTest, SolidColorDrawQuads) { |
} |
TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
+ const int thumb_thickness = 3; |
enne (OOO)
2013/08/14 21:01:09
style nit: constants in chromium are kThumbThickne
wjmaclean
2013/08/15 20:09:40
Done.
|
+ const int track_length = 10; |
+ |
LayerTreeSettings layer_tree_settings; |
- layer_tree_settings.solid_color_scrollbars = true; |
- layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; |
scoped_ptr<FakeLayerTreeHost> host = |
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); |
- ScrollbarLayerImpl* scrollbar_layer_impl = |
+ LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
+ host.get(), scrollbar.Pass(), false, true, thumb_thickness); |
+ ScrollbarLayerImplBase* scrollbar_layer_impl = |
static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); |
- scrollbar_layer_impl->set_thumb_thickness(3); |
- scrollbar_layer_impl->set_track_length(10); |
- scrollbar_layer_impl->SetCurrentPos(4.f); |
- scrollbar_layer_impl->SetMaximum(8); |
+ scrollbar_layer_impl->SetBounds(gfx::Size(track_length, thumb_thickness)); |
+ scrollbar_layer_impl->set_current_pos(4.f); |
+ scrollbar_layer_impl->set_maximum(8); |
layer_impl_tree_root->SetScrollable(true); |
layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); |
@@ -256,70 +266,73 @@ class ScrollbarLayerSolidColorThumbTest : public testing::Test { |
public: |
ScrollbarLayerSolidColorThumbTest() { |
LayerTreeSettings layer_tree_settings; |
- layer_tree_settings.solid_color_scrollbars = true; |
host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); |
- horizontal_scrollbar_layer_ = ScrollbarLayerImpl::Create( |
- host_impl_->active_tree(), 1, HORIZONTAL); |
- vertical_scrollbar_layer_ = ScrollbarLayerImpl::Create( |
- host_impl_->active_tree(), 2, VERTICAL); |
+ const int thumb_thickness = 3; |
+ const SkColor color = SkColorSetARGB(128, 128, 128, 128); |
+ |
+ horizontal_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( |
+ host_impl_->active_tree(), 1, HORIZONTAL, thumb_thickness, color); |
+ vertical_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( |
+ host_impl_->active_tree(), |
+ 2, |
+ VERTICAL, |
+ thumb_thickness, color); |
} |
protected: |
FakeImplProxy proxy_; |
scoped_ptr<FakeLayerTreeHostImpl> host_impl_; |
- scoped_ptr<ScrollbarLayerImpl> horizontal_scrollbar_layer_; |
- scoped_ptr<ScrollbarLayerImpl> vertical_scrollbar_layer_; |
+ scoped_ptr<SolidColorScrollbarLayerImpl> horizontal_scrollbar_layer_; |
+ scoped_ptr<SolidColorScrollbarLayerImpl> vertical_scrollbar_layer_; |
}; |
TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { |
- horizontal_scrollbar_layer_->SetCurrentPos(0); |
- horizontal_scrollbar_layer_->SetMaximum(10); |
- horizontal_scrollbar_layer_->set_thumb_thickness(3); |
+ horizontal_scrollbar_layer_->set_current_pos(0); |
+ horizontal_scrollbar_layer_->set_maximum(10); |
// Simple case - one third of the scrollable area is visible, so the thumb |
// should be one third as long as the track. |
horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.33f); |
- horizontal_scrollbar_layer_->set_track_length(100); |
+ horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
// The thumb's length should never be less than its thickness. |
horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.01f); |
- horizontal_scrollbar_layer_->set_track_length(100); |
+ horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
} |
TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { |
- horizontal_scrollbar_layer_->set_track_length(100); |
+ horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.1f); |
- horizontal_scrollbar_layer_->set_thumb_thickness(3); |
- horizontal_scrollbar_layer_->SetCurrentPos(0); |
- horizontal_scrollbar_layer_->SetMaximum(100); |
+ horizontal_scrollbar_layer_->set_current_pos(0); |
+ horizontal_scrollbar_layer_->set_maximum(100); |
EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
- horizontal_scrollbar_layer_->SetCurrentPos(100); |
+ horizontal_scrollbar_layer_->set_current_pos(100); |
// The thumb is 10px long and the track is 100px, so the maximum thumb |
// position is 90px. |
EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
- horizontal_scrollbar_layer_->SetCurrentPos(80); |
+ horizontal_scrollbar_layer_->set_current_pos(80); |
// The scroll position is 80% of the maximum, so the thumb's position should |
// be at 80% of its maximum or 72px. |
EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
} |
TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { |
- ScrollbarLayerImpl* layers[2] = |
+ SolidColorScrollbarLayerImpl* layers[2] = |
{ horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; |
for (size_t i = 0; i < 2; ++i) { |
- layers[i]->set_track_length(100); |
layers[i]->set_visible_to_total_length_ratio(0.2f); |
- layers[i]->set_thumb_thickness(3); |
- layers[i]->SetCurrentPos(25); |
- layers[i]->SetMaximum(100); |
+ layers[i]->set_current_pos(25); |
+ layers[i]->set_maximum(100); |
} |
+ layers[0]->SetBounds(gfx::Size(100, 3)); |
+ layers[1]->SetBounds(gfx::Size(3, 100)); |
EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), |
horizontal_scrollbar_layer_->ComputeThumbQuadRect()); |
@@ -415,15 +428,27 @@ class ScrollbarLayerTestResourceCreation : public testing::Test { |
ScrollbarLayerTestResourceCreation() |
: fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
- void TestResourceUpload(size_t expected_resources) { |
+ void TestResourceUpload(size_t expected_resources, |
+ bool use_solid_color_scrollbar) { |
layer_tree_host_.reset( |
new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); |
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); |
scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
scoped_refptr<Layer> content_layer = Layer::Create(); |
- scoped_refptr<Layer> scrollbar_layer = |
- ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); |
+ scoped_refptr<Layer> scrollbar_layer; |
+ if (use_solid_color_scrollbar) { |
+ SkColor color = SkColorSetARGB(128, 128, 128, 128); |
+ int thumb_thickness = 3; |
+ scrollbar_layer = |
+ SolidColorScrollbarLayer::Create(scrollbar->Orientation(), |
+ thumb_thickness, |
+ color, |
+ layer_tree_root->id()); |
+ } else { |
+ scrollbar_layer = |
+ ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); |
+ } |
layer_tree_root->AddChild(content_layer); |
layer_tree_root->AddChild(scrollbar_layer); |
@@ -470,13 +495,11 @@ class ScrollbarLayerTestResourceCreation : public testing::Test { |
}; |
TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { |
- layer_tree_settings_.solid_color_scrollbars = false; |
- TestResourceUpload(2); |
+ TestResourceUpload(2, false); |
} |
TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { |
- layer_tree_settings_.solid_color_scrollbars = true; |
- TestResourceUpload(0); |
+ TestResourceUpload(0, true); |
} |
class ScaledScrollbarLayerTestResourceCreation : public testing::Test { |
@@ -566,7 +589,6 @@ class ScaledScrollbarLayerTestResourceCreation : public testing::Test { |
}; |
TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { |
- layer_tree_settings_.solid_color_scrollbars = false; |
// Pick a test scale that moves the scrollbar's (non-zero) position to |
// a non-pixel-aligned location. |
TestResourceUpload(2, 1.41f); |