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

Side by Side Diff: cc/layers/scrollbar_layer_unittest.cc

Issue 1895873008: cc : Replace LayerImpl::children calls with LayerById (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « no previous file | cc/layers/texture_layer_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include <unordered_map> 7 #include <unordered_map>
8 8
9 #include "base/thread_task_runner_handle.h" 9 #include "base/thread_task_runner_handle.h"
10 #include "cc/input/scrollbar_animation_controller.h" 10 #include "cc/input/scrollbar_animation_controller.h"
(...skipping 19 matching lines...) Expand all
30 #include "cc/trees/layer_tree_impl.h" 30 #include "cc/trees/layer_tree_impl.h"
31 #include "cc/trees/occlusion_tracker.h" 31 #include "cc/trees/occlusion_tracker.h"
32 #include "cc/trees/single_thread_proxy.h" 32 #include "cc/trees/single_thread_proxy.h"
33 #include "cc/trees/tree_synchronizer.h" 33 #include "cc/trees/tree_synchronizer.h"
34 #include "testing/gmock/include/gmock/gmock.h" 34 #include "testing/gmock/include/gmock/gmock.h"
35 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
36 36
37 namespace cc { 37 namespace cc {
38 namespace { 38 namespace {
39 39
40 LayerImpl* LayerImplForScrollAreaAndScrollbar(
41 FakeLayerTreeHost* host,
42 std::unique_ptr<Scrollbar> scrollbar,
43 bool reverse_order,
44 bool use_solid_color_scrollbar,
45 int thumb_thickness,
46 int track_start) {
47 scoped_refptr<Layer> layer_tree_root = Layer::Create();
48 scoped_refptr<Layer> child1 = Layer::Create();
49 scoped_refptr<Layer> child2;
50 if (use_solid_color_scrollbar) {
51 const bool kIsLeftSideVerticalScrollbar = false;
52 child2 = SolidColorScrollbarLayer::Create(
53 scrollbar->Orientation(), thumb_thickness, track_start,
54 kIsLeftSideVerticalScrollbar, child1->id());
55 } else {
56 child2 = PaintedScrollbarLayer::Create(std::move(scrollbar), child1->id());
57 }
58 layer_tree_root->AddChild(child1);
59 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1);
60 host->SetRootLayer(layer_tree_root);
61 return host->CommitAndCreateLayerImplTree();
62 }
63
64 class FakeResourceTrackingLayerTreeHost : public FakeLayerTreeHost { 40 class FakeResourceTrackingLayerTreeHost : public FakeLayerTreeHost {
65 public: 41 public:
66 FakeResourceTrackingLayerTreeHost(FakeLayerTreeHostClient* client, 42 FakeResourceTrackingLayerTreeHost(FakeLayerTreeHostClient* client,
67 LayerTreeHost::InitParams* params) 43 LayerTreeHost::InitParams* params)
68 : FakeLayerTreeHost(client, params, CompositorMode::SINGLE_THREADED), 44 : FakeLayerTreeHost(client, params, CompositorMode::SINGLE_THREADED),
69 next_id_(1), 45 next_id_(1),
70 total_ui_resource_created_(0), 46 total_ui_resource_created_(0),
71 total_ui_resource_deleted_(0) { 47 total_ui_resource_deleted_(0) {
72 InitializeSingleThreaded(client, base::ThreadTaskRunnerHandle::Get(), 48 InitializeSingleThreaded(client, base::ThreadTaskRunnerHandle::Get(),
73 nullptr); 49 nullptr);
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 std::unordered_map<UIResourceId, UIResourceBitmap>; 89 std::unordered_map<UIResourceId, UIResourceBitmap>;
114 UIResourceBitmapMap ui_resource_bitmap_map_; 90 UIResourceBitmapMap ui_resource_bitmap_map_;
115 91
116 int next_id_; 92 int next_id_;
117 int total_ui_resource_created_; 93 int total_ui_resource_created_;
118 int total_ui_resource_deleted_; 94 int total_ui_resource_deleted_;
119 }; 95 };
120 96
121 class ScrollbarLayerTest : public testing::Test { 97 class ScrollbarLayerTest : public testing::Test {
122 public: 98 public:
123 ScrollbarLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) { 99 ScrollbarLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {
ajuma 2016/04/21 18:33:19 initialize scrollbar_layer_id_ here too
jaydasika 2016/04/21 18:47:00 Done.
124 layer_tree_settings_.single_thread_proxy_scheduler = false; 100 layer_tree_settings_.single_thread_proxy_scheduler = false;
125 layer_tree_settings_.use_zero_copy = true; 101 layer_tree_settings_.use_zero_copy = true;
126 102
127 LayerTreeHost::InitParams params; 103 LayerTreeHost::InitParams params;
128 params.client = &fake_client_; 104 params.client = &fake_client_;
129 params.settings = &layer_tree_settings_; 105 params.settings = &layer_tree_settings_;
130 params.task_graph_runner = &task_graph_runner_; 106 params.task_graph_runner = &task_graph_runner_;
131 107
132 layer_tree_host_.reset( 108 layer_tree_host_.reset(
133 new FakeResourceTrackingLayerTreeHost(&fake_client_, &params)); 109 new FakeResourceTrackingLayerTreeHost(&fake_client_, &params));
134 layer_tree_host_->SetVisible(true); 110 layer_tree_host_->SetVisible(true);
135 fake_client_.SetLayerTreeHost(layer_tree_host_.get()); 111 fake_client_.SetLayerTreeHost(layer_tree_host_.get());
136 // Force output surface creation for renderer capabilities. 112 // Force output surface creation for renderer capabilities.
137 layer_tree_host_->Composite(base::TimeTicks()); 113 layer_tree_host_->Composite(base::TimeTicks());
138 EXPECT_FALSE(layer_tree_host_->output_surface_lost()); 114 EXPECT_FALSE(layer_tree_host_->output_surface_lost());
139 } 115 }
140 116
117 LayerImpl* LayerImplForScrollAreaAndScrollbar(
118 FakeLayerTreeHost* host,
119 std::unique_ptr<Scrollbar> scrollbar,
120 bool reverse_order,
121 bool use_solid_color_scrollbar,
122 int thumb_thickness,
123 int track_start) {
124 scoped_refptr<Layer> layer_tree_root = Layer::Create();
125 scoped_refptr<Layer> child1 = Layer::Create();
126 scoped_refptr<Layer> child2;
127 if (use_solid_color_scrollbar) {
128 const bool kIsLeftSideVerticalScrollbar = false;
129 child2 = SolidColorScrollbarLayer::Create(
130 scrollbar->Orientation(), thumb_thickness, track_start,
131 kIsLeftSideVerticalScrollbar, child1->id());
132 } else {
133 child2 =
134 PaintedScrollbarLayer::Create(std::move(scrollbar), child1->id());
135 }
136 layer_tree_root->AddChild(child1);
137 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1);
138 scrollbar_layer_id_ = reverse_order ? child1->id() : child2->id();
139 host->SetRootLayer(layer_tree_root);
140 return host->CommitAndCreateLayerImplTree();
141 }
142
141 protected: 143 protected:
142 FakeLayerTreeHostClient fake_client_; 144 FakeLayerTreeHostClient fake_client_;
143 TestTaskGraphRunner task_graph_runner_; 145 TestTaskGraphRunner task_graph_runner_;
144 LayerTreeSettings layer_tree_settings_; 146 LayerTreeSettings layer_tree_settings_;
145 std::unique_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_; 147 std::unique_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_;
148 int scrollbar_layer_id_;
146 }; 149 };
147 150
148 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { 151 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
149 // Create and attach a non-overlay scrollbar. 152 // Create and attach a non-overlay scrollbar.
150 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar); 153 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar);
151 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 154 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
152 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0); 155 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0);
153 PaintedScrollbarLayerImpl* scrollbar_layer_impl = 156 PaintedScrollbarLayerImpl* scrollbar_layer_impl =
154 static_cast<PaintedScrollbarLayerImpl*>( 157 static_cast<PaintedScrollbarLayerImpl*>(
155 layer_impl_tree_root->children()[1]); 158 layer_impl_tree_root->layer_tree_impl()->LayerById(
159 scrollbar_layer_id_));
156 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting(); 160 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting();
157 ScrollTree& scroll_tree = 161 ScrollTree& scroll_tree =
158 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree; 162 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree;
159 ScrollNode* scroll_node = 163 ScrollNode* scroll_node =
160 scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index()); 164 scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index());
161 165
162 // When the scrollbar is not an overlay scrollbar, the scroll should be 166 // When the scrollbar is not an overlay scrollbar, the scroll should be
163 // responded to on the main thread as the compositor does not yet implement 167 // responded to on the main thread as the compositor does not yet implement
164 // scrollbar scrolling. 168 // scrollbar scrolling.
165 InputHandler::ScrollStatus status = layer_tree_host_->host_impl()->TryScroll( 169 InputHandler::ScrollStatus status = layer_tree_host_->host_impl()->TryScroll(
166 gfx::PointF(), InputHandler::TOUCHSCREEN, scroll_tree, scroll_node); 170 gfx::PointF(), InputHandler::TOUCHSCREEN, scroll_tree, scroll_node);
167 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread); 171 EXPECT_EQ(InputHandler::SCROLL_ON_MAIN_THREAD, status.thread);
168 EXPECT_EQ(MainThreadScrollingReason::kScrollbarScrolling, 172 EXPECT_EQ(MainThreadScrollingReason::kScrollbarScrolling,
169 status.main_thread_scrolling_reasons); 173 status.main_thread_scrolling_reasons);
170 174
171 // Create and attach an overlay scrollbar. 175 // Create and attach an overlay scrollbar.
172 scrollbar.reset(new FakeScrollbar(false, false, true)); 176 scrollbar.reset(new FakeScrollbar(false, false, true));
173 177
174 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 178 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
175 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0); 179 layer_tree_host_.get(), std::move(scrollbar), false, false, 0, 0);
176 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( 180 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
177 layer_impl_tree_root->children()[1]); 181 layer_impl_tree_root->layer_tree_impl()->LayerById(scrollbar_layer_id_));
178 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting(); 182 layer_impl_tree_root->layer_tree_impl()->BuildPropertyTreesForTesting();
179 scroll_tree = 183 scroll_tree =
180 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree; 184 layer_impl_tree_root->layer_tree_impl()->property_trees()->scroll_tree;
181 scroll_node = scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index()); 185 scroll_node = scroll_tree.Node(scrollbar_layer_impl->scroll_tree_index());
182 186
183 // The user shouldn't be able to drag an overlay scrollbar and the scroll 187 // The user shouldn't be able to drag an overlay scrollbar and the scroll
184 // may be handled in the compositor. 188 // may be handled in the compositor.
185 status = layer_tree_host_->host_impl()->TryScroll( 189 status = layer_tree_host_->host_impl()->TryScroll(
186 gfx::PointF(), InputHandler::TOUCHSCREEN, scroll_tree, scroll_node); 190 gfx::PointF(), InputHandler::TOUCHSCREEN, scroll_tree, scroll_node);
187 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread); 191 EXPECT_EQ(InputHandler::SCROLL_IGNORED, status.thread);
(...skipping 24 matching lines...) Expand all
212 216
213 layer_tree_root->SavePaintProperties(); 217 layer_tree_root->SavePaintProperties();
214 content_layer->SavePaintProperties(); 218 content_layer->SavePaintProperties();
215 219
216 layer_tree_host_->UpdateLayers(); 220 layer_tree_host_->UpdateLayers();
217 LayerImpl* layer_impl_tree_root = 221 LayerImpl* layer_impl_tree_root =
218 layer_tree_host_->CommitAndCreateLayerImplTree(); 222 layer_tree_host_->CommitAndCreateLayerImplTree();
219 223
220 ScrollbarLayerImplBase* cc_scrollbar_layer = 224 ScrollbarLayerImplBase* cc_scrollbar_layer =
221 static_cast<PaintedScrollbarLayerImpl*>( 225 static_cast<PaintedScrollbarLayerImpl*>(
222 layer_impl_tree_root->children()[1]); 226 layer_impl_tree_root->layer_tree_impl()->LayerById(
227 scrollbar_layer->id()));
223 228
224 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); 229 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos());
225 EXPECT_EQ(30, cc_scrollbar_layer->scroll_layer_length() - 230 EXPECT_EQ(30, cc_scrollbar_layer->scroll_layer_length() -
226 cc_scrollbar_layer->clip_layer_length()); 231 cc_scrollbar_layer->clip_layer_length());
227 232
228 layer_tree_root->SetBounds(gfx::Size(700, 1500)); 233 layer_tree_root->SetBounds(gfx::Size(700, 1500));
229 layer_tree_root->SavePaintProperties(); 234 layer_tree_root->SavePaintProperties();
230 scroll_layer->SetBounds(gfx::Size(1000, 2000)); 235 scroll_layer->SetBounds(gfx::Size(1000, 2000));
231 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200)); 236 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200));
232 scroll_layer->SavePaintProperties(); 237 scroll_layer->SavePaintProperties();
233 content_layer->SetBounds(gfx::Size(1000, 2000)); 238 content_layer->SetBounds(gfx::Size(1000, 2000));
234 content_layer->SavePaintProperties(); 239 content_layer->SavePaintProperties();
235 240
236 layer_tree_host_->UpdateLayers(); 241 layer_tree_host_->UpdateLayers();
237 layer_impl_tree_root = layer_tree_host_->CommitAndCreateLayerImplTree(); 242 layer_impl_tree_root = layer_tree_host_->CommitAndCreateLayerImplTree();
238 243
239 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos()); 244 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos());
240 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() - 245 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() -
241 cc_scrollbar_layer->clip_layer_length()); 246 cc_scrollbar_layer->clip_layer_length());
242 247
243 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; 248 LayerImpl* scroll_layer_impl =
249 layer_impl_tree_root->layer_tree_impl()->LayerById(scroll_layer->id());
244 scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34)); 250 scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34));
245 251
246 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); 252 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos());
247 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() - 253 EXPECT_EQ(300, cc_scrollbar_layer->scroll_layer_length() -
248 cc_scrollbar_layer->clip_layer_length()); 254 cc_scrollbar_layer->clip_layer_length());
249 } 255 }
250 256
251 #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \ 257 #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \
252 do { \ 258 do { \
253 scrollbar_layer->UpdateInternalContentScale(); \ 259 scrollbar_layer->UpdateInternalContentScale(); \
254 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ 260 scrollbar_layer->UpdateThumbAndTrackGeometry(); \
255 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \ 261 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \
256 root_layer_impl = root_clip_layer_impl->children()[0]; \
257 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ 262 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \
258 root_layer_impl->children()[1]); \ 263 root_clip_layer_impl->layer_tree_impl()->LayerById( \
264 scrollbar_layer->id())); \
259 } while (false) 265 } while (false)
260 266
261 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { 267 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) {
262 scoped_refptr<Layer> root_clip_layer = Layer::Create(); 268 scoped_refptr<Layer> root_clip_layer = Layer::Create();
263 scoped_refptr<Layer> root_layer = Layer::Create(); 269 scoped_refptr<Layer> root_layer = Layer::Create();
264 scoped_refptr<Layer> content_layer = Layer::Create(); 270 scoped_refptr<Layer> content_layer = Layer::Create();
265 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 271 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
266 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); 272 FakePaintedScrollbarLayer::Create(false, true, root_layer->id());
267 273
268 root_layer->SetScrollClipLayerId(root_clip_layer->id()); 274 root_layer->SetScrollClipLayerId(root_clip_layer->id());
269 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). 275 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0).
270 root_clip_layer->SetBounds(gfx::Size(20, 50)); 276 root_clip_layer->SetBounds(gfx::Size(20, 50));
271 root_layer->SetBounds(gfx::Size(100, 50)); 277 root_layer->SetBounds(gfx::Size(100, 50));
272 content_layer->SetBounds(gfx::Size(100, 50)); 278 content_layer->SetBounds(gfx::Size(100, 50));
273 279
274 layer_tree_host_->SetRootLayer(root_clip_layer); 280 layer_tree_host_->SetRootLayer(root_clip_layer);
275 root_clip_layer->AddChild(root_layer); 281 root_clip_layer->AddChild(root_layer);
276 root_layer->AddChild(content_layer); 282 root_layer->AddChild(content_layer);
277 root_layer->AddChild(scrollbar_layer); 283 root_layer->AddChild(scrollbar_layer);
278 284
279 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); 285 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
280 scrollbar_layer->SetBounds(gfx::Size(70, 10)); 286 scrollbar_layer->SetBounds(gfx::Size(70, 10));
281 scrollbar_layer->SetScrollLayer(root_layer->id()); 287 scrollbar_layer->SetScrollLayer(root_layer->id());
282 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); 288 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
283 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); 289 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
284 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); 290 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
285 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); 291 scrollbar_layer->fake_scrollbar()->set_thumb_length(4);
286 LayerImpl* root_clip_layer_impl = nullptr; 292 LayerImpl* root_clip_layer_impl = nullptr;
287 LayerImpl* root_layer_impl = nullptr;
288 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr; 293 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr;
289 294
290 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 295 UPDATE_AND_EXTRACT_LAYER_POINTERS();
291 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), 296 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(),
292 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 297 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
293 298
294 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); 299 scrollbar_layer->fake_scrollbar()->set_has_thumb(false);
295 300
296 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 301 UPDATE_AND_EXTRACT_LAYER_POINTERS();
297 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), 302 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(),
(...skipping 20 matching lines...) Expand all
318 323
319 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); 324 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
320 scrollbar_layer->SetBounds(gfx::Size(70, 10)); 325 scrollbar_layer->SetBounds(gfx::Size(70, 10));
321 scrollbar_layer->SetScrollLayer(root_layer->id()); 326 scrollbar_layer->SetScrollLayer(root_layer->id());
322 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); 327 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
323 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); 328 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
324 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); 329 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
325 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); 330 scrollbar_layer->fake_scrollbar()->set_thumb_length(4);
326 layer_tree_host_->UpdateLayers(); 331 layer_tree_host_->UpdateLayers();
327 LayerImpl* root_clip_layer_impl = nullptr; 332 LayerImpl* root_clip_layer_impl = nullptr;
328 LayerImpl* root_layer_impl = nullptr;
329 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr; 333 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr;
330 334
331 // Thumb is at the edge of the scrollbar (should be inset to 335 // Thumb is at the edge of the scrollbar (should be inset to
332 // the start of the track within the scrollbar layer's 336 // the start of the track within the scrollbar layer's
333 // position). 337 // position).
334 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 338 UPDATE_AND_EXTRACT_LAYER_POINTERS();
335 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), 339 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(),
336 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 340 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
337 341
338 // Under-scroll (thumb position should clamp and be unchanged). 342 // Under-scroll (thumb position should clamp and be unchanged).
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 const int kThumbThickness = 3; 384 const int kThumbThickness = 3;
381 const int kTrackStart = 1; 385 const int kTrackStart = 1;
382 const int kTrackLength = 100; 386 const int kTrackLength = 100;
383 387
384 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 388 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
385 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 389 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
386 layer_tree_host_.get(), std::move(scrollbar), false, true, 390 layer_tree_host_.get(), std::move(scrollbar), false, true,
387 kThumbThickness, kTrackStart); 391 kThumbThickness, kTrackStart);
388 ScrollbarLayerImplBase* scrollbar_layer_impl = 392 ScrollbarLayerImplBase* scrollbar_layer_impl =
389 static_cast<SolidColorScrollbarLayerImpl*>( 393 static_cast<SolidColorScrollbarLayerImpl*>(
390 layer_impl_tree_root->children()[1]); 394 layer_impl_tree_root->layer_tree_impl()->LayerById(
395 scrollbar_layer_id_));
391 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); 396 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
392 scrollbar_layer_impl->SetCurrentPos(10.f); 397 scrollbar_layer_impl->SetCurrentPos(10.f);
393 scrollbar_layer_impl->SetClipLayerLength(200 / 3.f); 398 scrollbar_layer_impl->SetClipLayerLength(200 / 3.f);
394 scrollbar_layer_impl->SetScrollLayerLength(100 + 200 / 3.f); 399 scrollbar_layer_impl->SetScrollLayerLength(100 + 200 / 3.f);
395 400
396 // Thickness should be overridden to 3. 401 // Thickness should be overridden to 3.
397 { 402 {
398 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 403 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
399 AppendQuadsData data; 404 AppendQuadsData data;
400 scrollbar_layer_impl->AppendQuads(render_pass.get(), &data); 405 scrollbar_layer_impl->AppendQuads(render_pass.get(), &data);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 } 441 }
437 } 442 }
438 443
439 TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { 444 TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) {
440 const int kThumbThickness = 3; 445 const int kThumbThickness = 3;
441 const int kTrackStart = 0; 446 const int kTrackStart = 0;
442 const int kTrackLength = 10; 447 const int kTrackLength = 10;
443 448
444 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 449 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
445 450
446 { 451 scoped_refptr<Layer> layer_tree_root = Layer::Create();
447 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 452 scoped_refptr<Layer> scroll_layer = Layer::Create();
448 scoped_refptr<Layer> scroll_layer = Layer::Create(); 453 scroll_layer->SetScrollClipLayerId(layer_tree_root->id());
449 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); 454 scoped_refptr<Layer> child1 = Layer::Create();
450 scoped_refptr<Layer> child1 = Layer::Create(); 455 scoped_refptr<Layer> child2;
451 scoped_refptr<Layer> child2; 456 const bool kIsLeftSideVerticalScrollbar = false;
452 const bool kIsLeftSideVerticalScrollbar = false; 457 child2 = SolidColorScrollbarLayer::Create(
453 child2 = SolidColorScrollbarLayer::Create( 458 scrollbar->Orientation(), kThumbThickness, kTrackStart,
454 scrollbar->Orientation(), kThumbThickness, kTrackStart, 459 kIsLeftSideVerticalScrollbar, child1->id());
455 kIsLeftSideVerticalScrollbar, child1->id()); 460 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id());
456 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); 461 scroll_layer->AddChild(child1);
457 scroll_layer->AddChild(child1); 462 scroll_layer->InsertChild(child2, 1);
458 scroll_layer->InsertChild(child2, 1); 463 layer_tree_root->AddChild(scroll_layer);
459 layer_tree_root->AddChild(scroll_layer); 464 layer_tree_host_->SetRootLayer(layer_tree_root);
460 layer_tree_host_->SetRootLayer(layer_tree_root);
461 465
462 // Choose layer bounds to give max_scroll_offset = (8, 8). 466 // Choose layer bounds to give max_scroll_offset = (8, 8).
463 layer_tree_root->SetBounds(gfx::Size(2, 2)); 467 layer_tree_root->SetBounds(gfx::Size(2, 2));
464 scroll_layer->SetBounds(gfx::Size(10, 10)); 468 scroll_layer->SetBounds(gfx::Size(10, 10));
465 469
466 layer_tree_host_->UpdateLayers(); 470 layer_tree_host_->UpdateLayers();
467 }
468 471
469 LayerImpl* layer_impl_tree_root = 472 LayerImpl* layer_impl_tree_root =
470 layer_tree_host_->CommitAndCreateLayerImplTree(); 473 layer_tree_host_->CommitAndCreateLayerImplTree();
471 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; 474 LayerImpl* scroll_layer_impl =
475 layer_impl_tree_root->layer_tree_impl()->LayerById(scroll_layer->id());
472 476
473 auto* scrollbar_layer_impl = 477 auto* scrollbar_layer_impl = static_cast<ScrollbarLayerImplBase*>(
474 static_cast<ScrollbarLayerImplBase*>(scroll_layer_impl->children()[1]); 478 scroll_layer_impl->layer_tree_impl()->LayerById(child2->id()));
475 479
476 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f)); 480 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f));
477 481
478 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); 482 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
479 scrollbar_layer_impl->SetCurrentPos(4.f); 483 scrollbar_layer_impl->SetCurrentPos(4.f);
480 484
481 { 485 {
482 std::unique_ptr<RenderPass> render_pass = RenderPass::Create(); 486 std::unique_ptr<RenderPass> render_pass = RenderPass::Create();
483 487
484 AppendQuadsData data; 488 AppendQuadsData data;
(...skipping 528 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); 1017 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f);
1014 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); 1018 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f);
1015 1019
1016 // Horizontal Scrollbars. 1020 // Horizontal Scrollbars.
1017 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); 1021 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f);
1018 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); 1022 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f);
1019 } 1023 }
1020 1024
1021 } // namespace 1025 } // namespace
1022 } // namespace cc 1026 } // namespace cc
OLDNEW
« no previous file with comments | « no previous file | cc/layers/texture_layer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698