Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "cc/layers/scrollbar_layer.h" | 5 #include "cc/layers/scrollbar_layer.h" |
| 6 | 6 |
| 7 #include "cc/animation/scrollbar_animation_controller.h" | 7 #include "cc/animation/scrollbar_animation_controller.h" |
| 8 #include "cc/layers/append_quads_data.h" | 8 #include "cc/layers/append_quads_data.h" |
| 9 #include "cc/layers/scrollbar_layer_base.h" | |
| 9 #include "cc/layers/scrollbar_layer_impl.h" | 10 #include "cc/layers/scrollbar_layer_impl.h" |
| 11 #include "cc/layers/solid_color_scrollbar_layer.h" | |
| 12 #include "cc/layers/solid_color_scrollbar_layer_impl.h" | |
| 10 #include "cc/quads/solid_color_draw_quad.h" | 13 #include "cc/quads/solid_color_draw_quad.h" |
| 11 #include "cc/resources/prioritized_resource_manager.h" | 14 #include "cc/resources/prioritized_resource_manager.h" |
| 12 #include "cc/resources/priority_calculator.h" | 15 #include "cc/resources/priority_calculator.h" |
| 13 #include "cc/resources/resource_update_queue.h" | 16 #include "cc/resources/resource_update_queue.h" |
| 14 #include "cc/test/fake_impl_proxy.h" | 17 #include "cc/test/fake_impl_proxy.h" |
| 15 #include "cc/test/fake_layer_tree_host.h" | 18 #include "cc/test/fake_layer_tree_host.h" |
| 16 #include "cc/test/fake_layer_tree_host_client.h" | 19 #include "cc/test/fake_layer_tree_host_client.h" |
| 17 #include "cc/test/fake_layer_tree_host_impl.h" | 20 #include "cc/test/fake_layer_tree_host_impl.h" |
| 18 #include "cc/test/fake_scrollbar.h" | 21 #include "cc/test/fake_scrollbar.h" |
| 19 #include "cc/test/geometry_test_utils.h" | 22 #include "cc/test/geometry_test_utils.h" |
| 20 #include "cc/test/layer_tree_test.h" | 23 #include "cc/test/layer_tree_test.h" |
| 21 #include "cc/test/mock_quad_culler.h" | 24 #include "cc/test/mock_quad_culler.h" |
| 22 #include "cc/test/test_web_graphics_context_3d.h" | 25 #include "cc/test/test_web_graphics_context_3d.h" |
| 23 #include "cc/trees/layer_tree_impl.h" | 26 #include "cc/trees/layer_tree_impl.h" |
| 24 #include "cc/trees/single_thread_proxy.h" | 27 #include "cc/trees/single_thread_proxy.h" |
| 25 #include "cc/trees/tree_synchronizer.h" | 28 #include "cc/trees/tree_synchronizer.h" |
| 26 #include "testing/gmock/include/gmock/gmock.h" | 29 #include "testing/gmock/include/gmock/gmock.h" |
| 27 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
| 28 | 31 |
| 29 namespace cc { | 32 namespace cc { |
| 30 namespace { | 33 namespace { |
| 31 | 34 |
| 32 LayerImpl* LayerImplForScrollAreaAndScrollbar( | 35 LayerImpl* LayerImplForScrollAreaAndScrollbar( |
| 33 FakeLayerTreeHost* host, | 36 FakeLayerTreeHost* host, |
| 34 scoped_ptr<Scrollbar> scrollbar, | 37 scoped_ptr<Scrollbar> scrollbar, |
| 35 bool reverse_order) { | 38 bool reverse_order, |
| 39 bool use_solid_color_scrollbar, | |
| 40 int thumb_thickness) { | |
| 36 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 41 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 37 scoped_refptr<Layer> child1 = Layer::Create(); | 42 scoped_refptr<Layer> child1 = Layer::Create(); |
| 38 scoped_refptr<Layer> child2 = | 43 scoped_refptr<Layer> child2; |
| 39 ScrollbarLayer::Create(scrollbar.Pass(), | 44 if (use_solid_color_scrollbar) { |
| 40 child1->id()); | 45 SkColor color = SkColorSetARGB(128, 128, 128, 128); |
| 46 child2 = SolidColorScrollbarLayer::Create( | |
| 47 scrollbar->Orientation(), thumb_thickness, color, child1->id()); | |
| 48 } else { | |
| 49 child2 = ScrollbarLayer::Create(scrollbar.Pass(), child1->id()); | |
| 50 } | |
| 41 layer_tree_root->AddChild(child1); | 51 layer_tree_root->AddChild(child1); |
| 42 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); | 52 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); |
| 43 host->SetRootLayer(layer_tree_root); | 53 host->SetRootLayer(layer_tree_root); |
| 44 return host->CommitAndCreateLayerImplTree(); | 54 return host->CommitAndCreateLayerImplTree(); |
| 45 } | 55 } |
| 46 | 56 |
| 47 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { | 57 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { |
| 48 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 58 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 49 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 59 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 50 LayerImpl* layer_impl_tree_root = | 60 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 51 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); | 61 host.get(), scrollbar.Pass(), false, false, 0); |
| 52 | 62 |
| 53 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; | 63 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; |
| 54 ScrollbarLayerImpl* cc_child2 = static_cast<ScrollbarLayerImpl*>( | 64 ScrollbarLayerImpl* cc_child2 = static_cast<ScrollbarLayerImpl*>( |
| 55 layer_impl_tree_root->children()[1]); | 65 layer_impl_tree_root->children()[1]); |
| 56 | 66 |
| 57 EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2); | 67 EXPECT_EQ(cc_child1->horizontal_scrollbar_layer(), cc_child2); |
| 58 } | 68 } |
| 59 | 69 |
| 60 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { | 70 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { |
| 61 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 71 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 62 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 72 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 63 LayerImpl* layer_impl_tree_root = | 73 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 64 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), true); | 74 host.get(), scrollbar.Pass(), true, false, 0); |
| 65 | 75 |
| 66 ScrollbarLayerImpl* cc_child1 = static_cast<ScrollbarLayerImpl*>( | 76 ScrollbarLayerImpl* cc_child1 = static_cast<ScrollbarLayerImpl*>( |
| 67 layer_impl_tree_root->children()[0]); | 77 layer_impl_tree_root->children()[0]); |
| 68 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; | 78 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; |
| 69 | 79 |
| 70 EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1); | 80 EXPECT_EQ(cc_child2->horizontal_scrollbar_layer(), cc_child1); |
| 71 } | 81 } |
| 72 | 82 |
| 73 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { | 83 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { |
| 74 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); | 84 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(); |
| 75 | 85 |
| 76 // Create and attach a non-overlay scrollbar. | 86 // Create and attach a non-overlay scrollbar. |
| 77 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 87 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 78 LayerImpl* layer_impl_tree_root = | 88 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 79 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); | 89 host.get(), scrollbar.Pass(), false, false, 0); |
| 80 ScrollbarLayerImpl* scrollbar_layer_impl = | 90 ScrollbarLayerImpl* scrollbar_layer_impl = |
| 81 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); | 91 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); |
| 82 | 92 |
| 83 // When the scrollbar is not an overlay scrollbar, the scroll should be | 93 // When the scrollbar is not an overlay scrollbar, the scroll should be |
| 84 // responded to on the main thread as the compositor does not yet implement | 94 // responded to on the main thread as the compositor does not yet implement |
| 85 // scrollbar scrolling. | 95 // scrollbar scrolling. |
| 86 EXPECT_EQ(InputHandler::ScrollOnMainThread, | 96 EXPECT_EQ(InputHandler::ScrollOnMainThread, |
| 87 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), | 97 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), |
| 88 InputHandler::Gesture)); | 98 InputHandler::Gesture)); |
| 89 | 99 |
| 90 // Create and attach an overlay scrollbar. | 100 // Create and attach an overlay scrollbar. |
| 91 scrollbar.reset(new FakeScrollbar(false, false, true)); | 101 scrollbar.reset(new FakeScrollbar(false, false, true)); |
| 92 | 102 |
| 93 layer_impl_tree_root = | 103 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 94 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); | 104 host.get(), scrollbar.Pass(), false, false, 0); |
| 95 scrollbar_layer_impl = | 105 scrollbar_layer_impl = |
| 96 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); | 106 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); |
| 97 | 107 |
| 98 // The user shouldn't be able to drag an overlay scrollbar and the scroll | 108 // The user shouldn't be able to drag an overlay scrollbar and the scroll |
| 99 // may be handled in the compositor. | 109 // may be handled in the compositor. |
| 100 EXPECT_EQ(InputHandler::ScrollIgnored, | 110 EXPECT_EQ(InputHandler::ScrollIgnored, |
| 101 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), | 111 scrollbar_layer_impl->TryScroll(gfx::Point(0, 0), |
| 102 InputHandler::Gesture)); | 112 InputHandler::Gesture)); |
| 103 } | 113 } |
| 104 | 114 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 123 layer_tree_root->AddChild(scrollbar_layer); | 133 layer_tree_root->AddChild(scrollbar_layer); |
| 124 | 134 |
| 125 layer_tree_root->SavePaintProperties(); | 135 layer_tree_root->SavePaintProperties(); |
| 126 content_layer->SavePaintProperties(); | 136 content_layer->SavePaintProperties(); |
| 127 | 137 |
| 128 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); | 138 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); |
| 129 | 139 |
| 130 ScrollbarLayerImpl* cc_scrollbar_layer = | 140 ScrollbarLayerImpl* cc_scrollbar_layer = |
| 131 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); | 141 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); |
| 132 | 142 |
| 133 EXPECT_EQ(10.f, cc_scrollbar_layer->CurrentPos()); | 143 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); |
| 134 EXPECT_EQ(30, cc_scrollbar_layer->Maximum()); | 144 EXPECT_EQ(30, cc_scrollbar_layer->maximum()); |
| 135 | 145 |
| 136 layer_tree_root->SetScrollOffset(gfx::Vector2d(100, 200)); | 146 layer_tree_root->SetScrollOffset(gfx::Vector2d(100, 200)); |
| 137 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(300, 500)); | 147 layer_tree_root->SetMaxScrollOffset(gfx::Vector2d(300, 500)); |
| 138 layer_tree_root->SetBounds(gfx::Size(1000, 2000)); | 148 layer_tree_root->SetBounds(gfx::Size(1000, 2000)); |
| 139 layer_tree_root->SavePaintProperties(); | 149 layer_tree_root->SavePaintProperties(); |
| 140 content_layer->SetBounds(gfx::Size(1000, 2000)); | 150 content_layer->SetBounds(gfx::Size(1000, 2000)); |
| 141 content_layer->SavePaintProperties(); | 151 content_layer->SavePaintProperties(); |
| 142 | 152 |
| 143 ScrollbarAnimationController* scrollbar_controller = | 153 ScrollbarAnimationController* scrollbar_controller = |
| 144 layer_impl_tree_root->scrollbar_animation_controller(); | 154 layer_impl_tree_root->scrollbar_animation_controller(); |
| 145 layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); | 155 layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); |
| 146 EXPECT_EQ(scrollbar_controller, | 156 EXPECT_EQ(scrollbar_controller, |
| 147 layer_impl_tree_root->scrollbar_animation_controller()); | 157 layer_impl_tree_root->scrollbar_animation_controller()); |
| 148 | 158 |
| 149 EXPECT_EQ(100.f, cc_scrollbar_layer->CurrentPos()); | 159 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos()); |
| 150 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); | 160 EXPECT_EQ(300, cc_scrollbar_layer->maximum()); |
| 151 | 161 |
| 152 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34)); | 162 layer_impl_tree_root->ScrollBy(gfx::Vector2d(12, 34)); |
| 153 | 163 |
| 154 EXPECT_EQ(112.f, cc_scrollbar_layer->CurrentPos()); | 164 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); |
| 155 EXPECT_EQ(300, cc_scrollbar_layer->Maximum()); | 165 EXPECT_EQ(300, cc_scrollbar_layer->maximum()); |
| 156 } | 166 } |
| 157 | 167 |
| 158 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { | 168 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { |
| 169 const int thumb_thickness = 3; | |
| 170 const int track_length = 100; | |
| 171 | |
| 159 LayerTreeSettings layer_tree_settings; | 172 LayerTreeSettings layer_tree_settings; |
| 160 layer_tree_settings.solid_color_scrollbars = true; | |
| 161 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; | |
| 162 scoped_ptr<FakeLayerTreeHost> host = | 173 scoped_ptr<FakeLayerTreeHost> host = |
| 163 FakeLayerTreeHost::Create(layer_tree_settings); | 174 FakeLayerTreeHost::Create(layer_tree_settings); |
| 164 | 175 |
| 165 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 176 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 166 LayerImpl* layer_impl_tree_root = | 177 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 167 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); | 178 host.get(), scrollbar.Pass(), false, true, thumb_thickness); |
| 168 ScrollbarLayerImpl* scrollbar_layer_impl = | 179 ScrollbarLayerImplBase* scrollbar_layer_impl = |
| 169 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); | 180 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); |
| 170 scrollbar_layer_impl->set_thumb_thickness(3); | 181 scrollbar_layer_impl->SetBounds(gfx::Size(track_length, thumb_thickness)); |
| 171 scrollbar_layer_impl->SetCurrentPos(10.f); | 182 scrollbar_layer_impl->set_current_pos(10.f); |
| 172 scrollbar_layer_impl->SetMaximum(100); | 183 scrollbar_layer_impl->set_maximum(100); |
| 173 scrollbar_layer_impl->set_track_length(100); | |
| 174 scrollbar_layer_impl->set_visible_to_total_length_ratio(0.4f); | 184 scrollbar_layer_impl->set_visible_to_total_length_ratio(0.4f); |
| 175 | 185 |
| 176 // Thickness should be overridden to 3. | 186 // Thickness should be overridden to 3. |
| 177 { | 187 { |
| 178 MockQuadCuller quad_culler; | 188 MockQuadCuller quad_culler; |
| 179 AppendQuadsData data; | 189 AppendQuadsData data; |
| 180 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 190 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
| 181 | 191 |
| 182 const QuadList& quads = quad_culler.quad_list(); | 192 const QuadList& quads = quad_culler.quad_list(); |
| 183 ASSERT_EQ(1u, quads.size()); | 193 ASSERT_EQ(1u, quads.size()); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 210 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 220 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
| 211 | 221 |
| 212 const QuadList& quads = quad_culler.quad_list(); | 222 const QuadList& quads = quad_culler.quad_list(); |
| 213 ASSERT_EQ(1u, quads.size()); | 223 ASSERT_EQ(1u, quads.size()); |
| 214 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 224 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
| 215 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); | 225 EXPECT_RECT_EQ(gfx::Rect(8, 0, 20, 3), quads[0]->rect); |
| 216 } | 226 } |
| 217 } | 227 } |
| 218 | 228 |
| 219 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 229 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
| 230 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.
| |
| 231 const int track_length = 10; | |
| 232 | |
| 220 LayerTreeSettings layer_tree_settings; | 233 LayerTreeSettings layer_tree_settings; |
| 221 layer_tree_settings.solid_color_scrollbars = true; | |
| 222 layer_tree_settings.solid_color_scrollbar_thickness_dip = 3; | |
| 223 scoped_ptr<FakeLayerTreeHost> host = | 234 scoped_ptr<FakeLayerTreeHost> host = |
| 224 FakeLayerTreeHost::Create(layer_tree_settings); | 235 FakeLayerTreeHost::Create(layer_tree_settings); |
| 225 | 236 |
| 226 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); | 237 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 227 LayerImpl* layer_impl_tree_root = | 238 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 228 LayerImplForScrollAreaAndScrollbar(host.get(), scrollbar.Pass(), false); | 239 host.get(), scrollbar.Pass(), false, true, thumb_thickness); |
| 229 ScrollbarLayerImpl* scrollbar_layer_impl = | 240 ScrollbarLayerImplBase* scrollbar_layer_impl = |
| 230 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); | 241 static_cast<ScrollbarLayerImpl*>(layer_impl_tree_root->children()[1]); |
| 231 | 242 |
| 232 scrollbar_layer_impl->set_thumb_thickness(3); | 243 scrollbar_layer_impl->SetBounds(gfx::Size(track_length, thumb_thickness)); |
| 233 scrollbar_layer_impl->set_track_length(10); | 244 scrollbar_layer_impl->set_current_pos(4.f); |
| 234 scrollbar_layer_impl->SetCurrentPos(4.f); | 245 scrollbar_layer_impl->set_maximum(8); |
| 235 scrollbar_layer_impl->SetMaximum(8); | |
| 236 | 246 |
| 237 layer_impl_tree_root->SetScrollable(true); | 247 layer_impl_tree_root->SetScrollable(true); |
| 238 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); | 248 layer_impl_tree_root->SetHorizontalScrollbarLayer(scrollbar_layer_impl); |
| 239 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); | 249 layer_impl_tree_root->SetMaxScrollOffset(gfx::Vector2d(8, 8)); |
| 240 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); | 250 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); |
| 241 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); | 251 layer_impl_tree_root->ScrollBy(gfx::Vector2dF(4.f, 0.f)); |
| 242 | 252 |
| 243 { | 253 { |
| 244 MockQuadCuller quad_culler; | 254 MockQuadCuller quad_culler; |
| 245 AppendQuadsData data; | 255 AppendQuadsData data; |
| 246 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); | 256 scrollbar_layer_impl->AppendQuads(&quad_culler, &data); |
| 247 | 257 |
| 248 const QuadList& quads = quad_culler.quad_list(); | 258 const QuadList& quads = quad_culler.quad_list(); |
| 249 ASSERT_EQ(1u, quads.size()); | 259 ASSERT_EQ(1u, quads.size()); |
| 250 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); | 260 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads[0]->material); |
| 251 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); | 261 EXPECT_RECT_EQ(gfx::Rect(3, 0, 3, 3), quads[0]->rect); |
| 252 } | 262 } |
| 253 } | 263 } |
| 254 | 264 |
| 255 class ScrollbarLayerSolidColorThumbTest : public testing::Test { | 265 class ScrollbarLayerSolidColorThumbTest : public testing::Test { |
| 256 public: | 266 public: |
| 257 ScrollbarLayerSolidColorThumbTest() { | 267 ScrollbarLayerSolidColorThumbTest() { |
| 258 LayerTreeSettings layer_tree_settings; | 268 LayerTreeSettings layer_tree_settings; |
| 259 layer_tree_settings.solid_color_scrollbars = true; | |
| 260 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); | 269 host_impl_.reset(new FakeLayerTreeHostImpl(layer_tree_settings, &proxy_)); |
| 261 | 270 |
| 262 horizontal_scrollbar_layer_ = ScrollbarLayerImpl::Create( | 271 const int thumb_thickness = 3; |
| 263 host_impl_->active_tree(), 1, HORIZONTAL); | 272 const SkColor color = SkColorSetARGB(128, 128, 128, 128); |
| 264 vertical_scrollbar_layer_ = ScrollbarLayerImpl::Create( | 273 |
| 265 host_impl_->active_tree(), 2, VERTICAL); | 274 horizontal_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( |
| 275 host_impl_->active_tree(), 1, HORIZONTAL, thumb_thickness, color); | |
| 276 vertical_scrollbar_layer_ = SolidColorScrollbarLayerImpl::Create( | |
| 277 host_impl_->active_tree(), | |
| 278 2, | |
| 279 VERTICAL, | |
| 280 thumb_thickness, color); | |
| 266 } | 281 } |
| 267 | 282 |
| 268 protected: | 283 protected: |
| 269 FakeImplProxy proxy_; | 284 FakeImplProxy proxy_; |
| 270 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; | 285 scoped_ptr<FakeLayerTreeHostImpl> host_impl_; |
| 271 scoped_ptr<ScrollbarLayerImpl> horizontal_scrollbar_layer_; | 286 scoped_ptr<SolidColorScrollbarLayerImpl> horizontal_scrollbar_layer_; |
| 272 scoped_ptr<ScrollbarLayerImpl> vertical_scrollbar_layer_; | 287 scoped_ptr<SolidColorScrollbarLayerImpl> vertical_scrollbar_layer_; |
| 273 }; | 288 }; |
| 274 | 289 |
| 275 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { | 290 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbLength) { |
| 276 horizontal_scrollbar_layer_->SetCurrentPos(0); | 291 horizontal_scrollbar_layer_->set_current_pos(0); |
| 277 horizontal_scrollbar_layer_->SetMaximum(10); | 292 horizontal_scrollbar_layer_->set_maximum(10); |
| 278 horizontal_scrollbar_layer_->set_thumb_thickness(3); | |
| 279 | 293 |
| 280 // Simple case - one third of the scrollable area is visible, so the thumb | 294 // Simple case - one third of the scrollable area is visible, so the thumb |
| 281 // should be one third as long as the track. | 295 // should be one third as long as the track. |
| 282 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.33f); | 296 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.33f); |
| 283 horizontal_scrollbar_layer_->set_track_length(100); | 297 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
| 284 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 298 EXPECT_EQ(33, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
| 285 | 299 |
| 286 // The thumb's length should never be less than its thickness. | 300 // The thumb's length should never be less than its thickness. |
| 287 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.01f); | 301 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.01f); |
| 288 horizontal_scrollbar_layer_->set_track_length(100); | 302 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
| 289 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 303 EXPECT_EQ(3, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
| 290 } | 304 } |
| 291 | 305 |
| 292 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { | 306 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbPosition) { |
| 293 horizontal_scrollbar_layer_->set_track_length(100); | 307 horizontal_scrollbar_layer_->SetBounds(gfx::Size(100, 3)); |
| 294 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.1f); | 308 horizontal_scrollbar_layer_->set_visible_to_total_length_ratio(0.1f); |
| 295 horizontal_scrollbar_layer_->set_thumb_thickness(3); | |
| 296 | 309 |
| 297 horizontal_scrollbar_layer_->SetCurrentPos(0); | 310 horizontal_scrollbar_layer_->set_current_pos(0); |
| 298 horizontal_scrollbar_layer_->SetMaximum(100); | 311 horizontal_scrollbar_layer_->set_maximum(100); |
| 299 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 312 EXPECT_EQ(0, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
| 300 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); | 313 EXPECT_EQ(10, horizontal_scrollbar_layer_->ComputeThumbQuadRect().width()); |
| 301 | 314 |
| 302 horizontal_scrollbar_layer_->SetCurrentPos(100); | 315 horizontal_scrollbar_layer_->set_current_pos(100); |
| 303 // The thumb is 10px long and the track is 100px, so the maximum thumb | 316 // The thumb is 10px long and the track is 100px, so the maximum thumb |
| 304 // position is 90px. | 317 // position is 90px. |
| 305 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 318 EXPECT_EQ(90, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
| 306 | 319 |
| 307 horizontal_scrollbar_layer_->SetCurrentPos(80); | 320 horizontal_scrollbar_layer_->set_current_pos(80); |
| 308 // The scroll position is 80% of the maximum, so the thumb's position should | 321 // The scroll position is 80% of the maximum, so the thumb's position should |
| 309 // be at 80% of its maximum or 72px. | 322 // be at 80% of its maximum or 72px. |
| 310 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); | 323 EXPECT_EQ(72, horizontal_scrollbar_layer_->ComputeThumbQuadRect().x()); |
| 311 } | 324 } |
| 312 | 325 |
| 313 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { | 326 TEST_F(ScrollbarLayerSolidColorThumbTest, SolidColorThumbVerticalAdjust) { |
| 314 ScrollbarLayerImpl* layers[2] = | 327 SolidColorScrollbarLayerImpl* layers[2] = |
| 315 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; | 328 { horizontal_scrollbar_layer_.get(), vertical_scrollbar_layer_.get() }; |
| 316 for (size_t i = 0; i < 2; ++i) { | 329 for (size_t i = 0; i < 2; ++i) { |
| 317 layers[i]->set_track_length(100); | |
| 318 layers[i]->set_visible_to_total_length_ratio(0.2f); | 330 layers[i]->set_visible_to_total_length_ratio(0.2f); |
| 319 layers[i]->set_thumb_thickness(3); | 331 layers[i]->set_current_pos(25); |
| 320 layers[i]->SetCurrentPos(25); | 332 layers[i]->set_maximum(100); |
| 321 layers[i]->SetMaximum(100); | |
| 322 } | 333 } |
| 334 layers[0]->SetBounds(gfx::Size(100, 3)); | |
| 335 layers[1]->SetBounds(gfx::Size(3, 100)); | |
| 323 | 336 |
| 324 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), | 337 EXPECT_RECT_EQ(gfx::RectF(20.f, 0.f, 20.f, 3.f), |
| 325 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); | 338 horizontal_scrollbar_layer_->ComputeThumbQuadRect()); |
| 326 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), | 339 EXPECT_RECT_EQ(gfx::RectF(0.f, 20.f, 3.f, 20.f), |
| 327 vertical_scrollbar_layer_->ComputeThumbQuadRect()); | 340 vertical_scrollbar_layer_->ComputeThumbQuadRect()); |
| 328 | 341 |
| 329 horizontal_scrollbar_layer_->set_vertical_adjust(10.f); | 342 horizontal_scrollbar_layer_->set_vertical_adjust(10.f); |
| 330 vertical_scrollbar_layer_->set_vertical_adjust(10.f); | 343 vertical_scrollbar_layer_->set_vertical_adjust(10.f); |
| 331 | 344 |
| 332 // The vertical adjustment factor has two effects: | 345 // The vertical adjustment factor has two effects: |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 Initialize(NULL); | 421 Initialize(NULL); |
| 409 } | 422 } |
| 410 }; | 423 }; |
| 411 | 424 |
| 412 | 425 |
| 413 class ScrollbarLayerTestResourceCreation : public testing::Test { | 426 class ScrollbarLayerTestResourceCreation : public testing::Test { |
| 414 public: | 427 public: |
| 415 ScrollbarLayerTestResourceCreation() | 428 ScrollbarLayerTestResourceCreation() |
| 416 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | 429 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
| 417 | 430 |
| 418 void TestResourceUpload(size_t expected_resources) { | 431 void TestResourceUpload(size_t expected_resources, |
| 432 bool use_solid_color_scrollbar) { | |
| 419 layer_tree_host_.reset( | 433 layer_tree_host_.reset( |
| 420 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); | 434 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); |
| 421 | 435 |
| 422 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); | 436 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); |
| 423 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 437 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 424 scoped_refptr<Layer> content_layer = Layer::Create(); | 438 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 425 scoped_refptr<Layer> scrollbar_layer = | 439 scoped_refptr<Layer> scrollbar_layer; |
| 426 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); | 440 if (use_solid_color_scrollbar) { |
| 441 SkColor color = SkColorSetARGB(128, 128, 128, 128); | |
| 442 int thumb_thickness = 3; | |
| 443 scrollbar_layer = | |
| 444 SolidColorScrollbarLayer::Create(scrollbar->Orientation(), | |
| 445 thumb_thickness, | |
| 446 color, | |
| 447 layer_tree_root->id()); | |
| 448 } else { | |
| 449 scrollbar_layer = | |
| 450 ScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); | |
| 451 } | |
| 427 layer_tree_root->AddChild(content_layer); | 452 layer_tree_root->AddChild(content_layer); |
| 428 layer_tree_root->AddChild(scrollbar_layer); | 453 layer_tree_root->AddChild(scrollbar_layer); |
| 429 | 454 |
| 430 layer_tree_host_->InitializeOutputSurfaceIfNeeded(); | 455 layer_tree_host_->InitializeOutputSurfaceIfNeeded(); |
| 431 layer_tree_host_->contents_texture_manager()-> | 456 layer_tree_host_->contents_texture_manager()-> |
| 432 SetMaxMemoryLimitBytes(1024 * 1024); | 457 SetMaxMemoryLimitBytes(1024 * 1024); |
| 433 layer_tree_host_->SetRootLayer(layer_tree_root); | 458 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 434 | 459 |
| 435 scrollbar_layer->SetIsDrawable(true); | 460 scrollbar_layer->SetIsDrawable(true); |
| 436 scrollbar_layer->SetBounds(gfx::Size(100, 100)); | 461 scrollbar_layer->SetBounds(gfx::Size(100, 100)); |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 463 scrollbar_layer->ClearRenderSurface(); | 488 scrollbar_layer->ClearRenderSurface(); |
| 464 } | 489 } |
| 465 | 490 |
| 466 protected: | 491 protected: |
| 467 FakeLayerTreeHostClient fake_client_; | 492 FakeLayerTreeHostClient fake_client_; |
| 468 LayerTreeSettings layer_tree_settings_; | 493 LayerTreeSettings layer_tree_settings_; |
| 469 scoped_ptr<MockLayerTreeHost> layer_tree_host_; | 494 scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
| 470 }; | 495 }; |
| 471 | 496 |
| 472 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { | 497 TEST_F(ScrollbarLayerTestResourceCreation, ResourceUpload) { |
| 473 layer_tree_settings_.solid_color_scrollbars = false; | 498 TestResourceUpload(2, false); |
| 474 TestResourceUpload(2); | |
| 475 } | 499 } |
| 476 | 500 |
| 477 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { | 501 TEST_F(ScrollbarLayerTestResourceCreation, SolidColorNoResourceUpload) { |
| 478 layer_tree_settings_.solid_color_scrollbars = true; | 502 TestResourceUpload(0, true); |
| 479 TestResourceUpload(0); | |
| 480 } | 503 } |
| 481 | 504 |
| 482 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { | 505 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { |
| 483 public: | 506 public: |
| 484 ScaledScrollbarLayerTestResourceCreation() | 507 ScaledScrollbarLayerTestResourceCreation() |
| 485 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | 508 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} |
| 486 | 509 |
| 487 void TestResourceUpload(size_t expected_resources, const float test_scale) { | 510 void TestResourceUpload(size_t expected_resources, const float test_scale) { |
| 488 layer_tree_host_.reset( | 511 layer_tree_host_.reset( |
| 489 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); | 512 new MockLayerTreeHost(&fake_client_, layer_tree_settings_)); |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 559 scrollbar_layer->ClearRenderSurface(); | 582 scrollbar_layer->ClearRenderSurface(); |
| 560 } | 583 } |
| 561 | 584 |
| 562 protected: | 585 protected: |
| 563 FakeLayerTreeHostClient fake_client_; | 586 FakeLayerTreeHostClient fake_client_; |
| 564 LayerTreeSettings layer_tree_settings_; | 587 LayerTreeSettings layer_tree_settings_; |
| 565 scoped_ptr<MockLayerTreeHost> layer_tree_host_; | 588 scoped_ptr<MockLayerTreeHost> layer_tree_host_; |
| 566 }; | 589 }; |
| 567 | 590 |
| 568 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { | 591 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { |
| 569 layer_tree_settings_.solid_color_scrollbars = false; | |
| 570 // Pick a test scale that moves the scrollbar's (non-zero) position to | 592 // Pick a test scale that moves the scrollbar's (non-zero) position to |
| 571 // a non-pixel-aligned location. | 593 // a non-pixel-aligned location. |
| 572 TestResourceUpload(2, 1.41f); | 594 TestResourceUpload(2, 1.41f); |
| 573 } | 595 } |
| 574 | 596 |
| 575 } // namespace | 597 } // namespace |
| 576 } // namespace cc | 598 } // namespace cc |
| OLD | NEW |