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

Unified Diff: cc/layers/scrollbar_layer_unittest.cc

Issue 18341009: Refactor cc scrollbar layers to separate solid-color vs desktop. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address tfarina@'s comments. Created 7 years, 5 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 f8b009b583a30862aea7cc9b9b3cc4a3f054d001..7a30bb8f38ad026ba4e689dd89ad88883b7ed41e 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"
@@ -31,12 +34,19 @@ namespace {
scoped_ptr<LayerImpl> LayerImplForScrollAreaAndScrollbar(
FakeLayerTreeHostImpl* host_impl,
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);
scoped_ptr<LayerImpl> layer_impl =
@@ -55,7 +65,7 @@ TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) {
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
scoped_ptr<LayerImpl> layer_impl_tree_root =
LayerImplForScrollAreaAndScrollbar(
- &host_impl, scrollbar.Pass(), false);
+ &host_impl, scrollbar.Pass(), false, false, 0);
LayerImpl* cc_child1 = layer_impl_tree_root->children()[0];
ScrollbarLayerImpl* cc_child2 = static_cast<ScrollbarLayerImpl*>(
@@ -68,7 +78,7 @@ TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) {
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
scoped_ptr<LayerImpl> layer_impl_tree_root =
LayerImplForScrollAreaAndScrollbar(
- &host_impl, scrollbar.Pass(), true);
+ &host_impl, scrollbar.Pass(), true, false, 0);
ScrollbarLayerImpl* cc_child1 = static_cast<ScrollbarLayerImpl*>(
layer_impl_tree_root->children()[0]);
@@ -85,7 +95,8 @@ TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
// Create and attach a non-overlay scrollbar.
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
scoped_ptr<LayerImpl> layer_impl_tree_root =
- LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false);
+ LayerImplForScrollAreaAndScrollbar(
+ &host_impl, scrollbar.Pass(), false, false, 0);
ScrollbarLayerImpl* scrollbar_layer_impl =
static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
@@ -99,8 +110,8 @@ TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
// Create and attach an overlay scrollbar.
scrollbar.reset(new FakeScrollbar(false, false, true));
- layer_impl_tree_root =
- LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false);
+ layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
+ &host_impl, scrollbar.Pass(), false, false, 0);
scrollbar_layer_impl =
static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
@@ -172,21 +183,22 @@ TEST(ScrollbarLayerTest, ScrollOffsetSynchronization) {
}
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;
FakeImplProxy proxy;
FakeLayerTreeHostImpl host_impl(layer_tree_settings, &proxy);
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
scoped_ptr<LayerImpl> layer_impl_tree_root =
- LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false);
- ScrollbarLayerImpl* scrollbar_layer_impl =
- static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
- scrollbar_layer_impl->set_thumb_thickness(3);
+ LayerImplForScrollAreaAndScrollbar(
+ &host_impl, scrollbar.Pass(), false, true, thumb_thickness);
+ ScrollbarLayerImplBase* scrollbar_layer_impl =
+ static_cast<ScrollbarLayerImplBase*>(layer_impl_tree_root->children()[1]);
+ scrollbar_layer_impl->SetBounds(gfx::Size(track_length, thumb_thickness));
scrollbar_layer_impl->SetCurrentPos(10.f);
scrollbar_layer_impl->SetMaximum(100);
- scrollbar_layer_impl->set_track_length(100);
scrollbar_layer_impl->set_visible_to_total_length_ratio(0.4f);
// Thickness should be overridden to 3.
@@ -233,20 +245,21 @@ TEST(ScrollbarLayerTest, SolidColorDrawQuads) {
}
TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) {
+ const int thumb_thickness = 3;
+ 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;
FakeImplProxy proxy;
FakeLayerTreeHostImpl host_impl(layer_tree_settings, &proxy);
scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
scoped_ptr<LayerImpl> layer_impl_tree_root =
- LayerImplForScrollAreaAndScrollbar(&host_impl, scrollbar.Pass(), false);
- ScrollbarLayerImpl* scrollbar_layer_impl =
- static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]);
+ LayerImplForScrollAreaAndScrollbar(
+ &host_impl, scrollbar.Pass(), false, true, thumb_thickness);
+ ScrollbarLayerImplBase* scrollbar_layer_impl =
+ static_cast<ScrollbarLayerImplBase*>(layer_impl_tree_root->children()[1]);
- scrollbar_layer_impl->set_thumb_thickness(3);
- scrollbar_layer_impl->set_track_length(10);
+ scrollbar_layer_impl->SetBounds(gfx::Size(track_length, thumb_thickness));
scrollbar_layer_impl->SetCurrentPos(4.f);
scrollbar_layer_impl->SetMaximum(8);
@@ -271,43 +284,46 @@ 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);
// 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);
@@ -326,15 +342,15 @@ TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) {
}
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[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());
@@ -430,15 +446,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);
@@ -482,13 +510,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 {
@@ -575,7 +601,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);

Powered by Google App Engine
This is Rietveld 408576698