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

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

Issue 2827163005: Remove scroll layer ids from scrollbar layers (Closed)
Patch Set: Created 3 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
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/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/threading/thread_task_runner_handle.h" 10 #include "base/threading/thread_task_runner_handle.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 bool use_solid_color_scrollbar, 145 bool use_solid_color_scrollbar,
146 int thumb_thickness, 146 int thumb_thickness,
147 int track_start) { 147 int track_start) {
148 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 148 scoped_refptr<Layer> layer_tree_root = Layer::Create();
149 scoped_refptr<Layer> child1 = Layer::Create(); 149 scoped_refptr<Layer> child1 = Layer::Create();
150 scoped_refptr<Layer> child2; 150 scoped_refptr<Layer> child2;
151 if (use_solid_color_scrollbar) { 151 if (use_solid_color_scrollbar) {
152 const bool kIsLeftSideVerticalScrollbar = false; 152 const bool kIsLeftSideVerticalScrollbar = false;
153 child2 = SolidColorScrollbarLayer::Create( 153 child2 = SolidColorScrollbarLayer::Create(
154 scrollbar->Orientation(), thumb_thickness, track_start, 154 scrollbar->Orientation(), thumb_thickness, track_start,
155 kIsLeftSideVerticalScrollbar, child1->id(), child1->element_id()); 155 kIsLeftSideVerticalScrollbar, child1->element_id());
156 } else { 156 } else {
157 child2 = PaintedScrollbarLayer::Create(std::move(scrollbar), child1->id(), 157 child2 = PaintedScrollbarLayer::Create(std::move(scrollbar),
158 child1->element_id()); 158 child1->element_id());
159 } 159 }
160 layer_tree_root->AddChild(child1); 160 layer_tree_root->AddChild(child1);
161 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); 161 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1);
162 scrollbar_layer_id_ = reverse_order ? child1->id() : child2->id(); 162 scrollbar_layer_id_ = reverse_order ? child1->id() : child2->id();
163 host->SetRootLayer(layer_tree_root); 163 host->SetRootLayer(layer_tree_root);
164 host->BuildPropertyTreesForTesting(); 164 host->BuildPropertyTreesForTesting();
165 return host->CommitAndCreateLayerImplTree(); 165 return host->CommitAndCreateLayerImplTree();
166 } 166 }
167 167
(...skipping 24 matching lines...) Expand all
192 // after its been disposed, even if Blink doesn't think it requires a repaint. 192 // after its been disposed, even if Blink doesn't think it requires a repaint.
193 // crbug.com/704656. 193 // crbug.com/704656.
194 TEST_F(ScrollbarLayerTest, RepaintOverlayWhenResourceDisposed) { 194 TEST_F(ScrollbarLayerTest, RepaintOverlayWhenResourceDisposed) {
195 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 195 scoped_refptr<Layer> layer_tree_root = Layer::Create();
196 scoped_refptr<Layer> content_layer = Layer::Create(); 196 scoped_refptr<Layer> content_layer = Layer::Create();
197 std::unique_ptr<FakePaintedOverlayScrollbar> scrollbar( 197 std::unique_ptr<FakePaintedOverlayScrollbar> scrollbar(
198 new FakePaintedOverlayScrollbar); 198 new FakePaintedOverlayScrollbar);
199 FakePaintedOverlayScrollbar* fake_scrollbar = scrollbar.get(); 199 FakePaintedOverlayScrollbar* fake_scrollbar = scrollbar.get();
200 scoped_refptr<PaintedOverlayScrollbarLayer> scrollbar_layer = 200 scoped_refptr<PaintedOverlayScrollbarLayer> scrollbar_layer =
201 PaintedOverlayScrollbarLayer::Create(std::move(scrollbar), 201 PaintedOverlayScrollbarLayer::Create(std::move(scrollbar),
202 layer_tree_root->id(),
203 layer_tree_root->element_id()); 202 layer_tree_root->element_id());
204 203
205 // Setup. 204 // Setup.
206 { 205 {
207 layer_tree_root->AddChild(content_layer); 206 layer_tree_root->AddChild(content_layer);
208 layer_tree_root->AddChild(scrollbar_layer); 207 layer_tree_root->AddChild(scrollbar_layer);
209 layer_tree_host_->SetRootLayer(layer_tree_root); 208 layer_tree_host_->SetRootLayer(layer_tree_root);
210 scrollbar_layer->SetIsDrawable(true); 209 scrollbar_layer->SetIsDrawable(true);
211 scrollbar_layer->SetBounds(gfx::Size(100, 100)); 210 scrollbar_layer->SetBounds(gfx::Size(100, 100));
212 layer_tree_root->SetBounds(gfx::Size(100, 200)); 211 layer_tree_root->SetBounds(gfx::Size(100, 200));
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 status.main_thread_scrolling_reasons); 288 status.main_thread_scrolling_reasons);
290 } 289 }
291 290
292 TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { 291 TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) {
293 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar); 292 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar);
294 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 293 scoped_refptr<Layer> layer_tree_root = Layer::Create();
295 scoped_refptr<Layer> scroll_layer = Layer::Create(); 294 scoped_refptr<Layer> scroll_layer = Layer::Create();
296 scroll_layer->SetElementId(LayerIdToElementIdForTesting(scroll_layer->id())); 295 scroll_layer->SetElementId(LayerIdToElementIdForTesting(scroll_layer->id()));
297 scoped_refptr<Layer> content_layer = Layer::Create(); 296 scoped_refptr<Layer> content_layer = Layer::Create();
298 scoped_refptr<Layer> scrollbar_layer = PaintedScrollbarLayer::Create( 297 scoped_refptr<Layer> scrollbar_layer = PaintedScrollbarLayer::Create(
299 std::move(scrollbar), scroll_layer->id(), scroll_layer->element_id()); 298 std::move(scrollbar), scroll_layer->element_id());
300 299
301 // Choose bounds to give max_scroll_offset = (30, 50). 300 // Choose bounds to give max_scroll_offset = (30, 50).
302 layer_tree_root->SetBounds(gfx::Size(70, 150)); 301 layer_tree_root->SetBounds(gfx::Size(70, 150));
303 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); 302 scroll_layer->SetScrollClipLayerId(layer_tree_root->id());
304 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); 303 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20));
305 scroll_layer->SetBounds(gfx::Size(100, 200)); 304 scroll_layer->SetBounds(gfx::Size(100, 200));
306 content_layer->SetBounds(gfx::Size(100, 200)); 305 content_layer->SetBounds(gfx::Size(100, 200));
307 306
308 layer_tree_host_->SetRootLayer(layer_tree_root); 307 layer_tree_host_->SetRootLayer(layer_tree_root);
309 layer_tree_root->AddChild(scroll_layer); 308 layer_tree_root->AddChild(scroll_layer);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ 356 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \
358 root_clip_layer_impl->layer_tree_impl()->LayerById( \ 357 root_clip_layer_impl->layer_tree_impl()->LayerById( \
359 scrollbar_layer->id())); \ 358 scrollbar_layer->id())); \
360 } while (false) 359 } while (false)
361 360
362 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { 361 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) {
363 scoped_refptr<Layer> root_clip_layer = Layer::Create(); 362 scoped_refptr<Layer> root_clip_layer = Layer::Create();
364 scoped_refptr<Layer> root_layer = Layer::Create(); 363 scoped_refptr<Layer> root_layer = Layer::Create();
365 scoped_refptr<Layer> content_layer = Layer::Create(); 364 scoped_refptr<Layer> content_layer = Layer::Create();
366 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 365 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
367 FakePaintedScrollbarLayer::Create(false, true, root_layer->id(), 366 FakePaintedScrollbarLayer::Create(false, true, root_layer->element_id());
368 root_layer->element_id());
369 367
370 root_layer->SetScrollClipLayerId(root_clip_layer->id()); 368 root_layer->SetScrollClipLayerId(root_clip_layer->id());
371 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). 369 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0).
372 root_clip_layer->SetBounds(gfx::Size(20, 50)); 370 root_clip_layer->SetBounds(gfx::Size(20, 50));
373 root_layer->SetBounds(gfx::Size(100, 50)); 371 root_layer->SetBounds(gfx::Size(100, 50));
374 content_layer->SetBounds(gfx::Size(100, 50)); 372 content_layer->SetBounds(gfx::Size(100, 50));
375 373
376 layer_tree_host_->SetRootLayer(root_clip_layer); 374 layer_tree_host_->SetRootLayer(root_clip_layer);
377 root_clip_layer->AddChild(root_layer); 375 root_clip_layer->AddChild(root_layer);
378 root_layer->AddChild(content_layer); 376 root_layer->AddChild(content_layer);
379 root_layer->AddChild(scrollbar_layer); 377 root_layer->AddChild(scrollbar_layer);
380 378
381 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); 379 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
382 scrollbar_layer->SetBounds(gfx::Size(70, 10)); 380 scrollbar_layer->SetBounds(gfx::Size(70, 10));
383 scrollbar_layer->SetScrollInfo(root_layer->id(), root_layer->element_id()); 381 scrollbar_layer->SetScrollElementId(root_layer->element_id());
384 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); 382 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
385 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); 383 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
386 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); 384 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
387 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); 385 scrollbar_layer->fake_scrollbar()->set_thumb_length(4);
388 LayerImpl* root_clip_layer_impl = nullptr; 386 LayerImpl* root_clip_layer_impl = nullptr;
389 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr; 387 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr;
390 388
391 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 389 UPDATE_AND_EXTRACT_LAYER_POINTERS();
392 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), 390 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(),
393 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 391 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
394 392
395 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); 393 scrollbar_layer->fake_scrollbar()->set_has_thumb(false);
396 394
397 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 395 UPDATE_AND_EXTRACT_LAYER_POINTERS();
398 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), 396 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(),
399 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 397 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
400 } 398 }
401 399
402 TEST_F(ScrollbarLayerTest, ThumbRect) { 400 TEST_F(ScrollbarLayerTest, ThumbRect) {
403 scoped_refptr<Layer> root_clip_layer = Layer::Create(); 401 scoped_refptr<Layer> root_clip_layer = Layer::Create();
404 scoped_refptr<Layer> root_layer = Layer::Create(); 402 scoped_refptr<Layer> root_layer = Layer::Create();
405 scoped_refptr<Layer> content_layer = Layer::Create(); 403 scoped_refptr<Layer> content_layer = Layer::Create();
406 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 404 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
407 FakePaintedScrollbarLayer::Create(false, true, root_layer->id(), 405 FakePaintedScrollbarLayer::Create(false, true, root_layer->element_id());
408 root_layer->element_id());
409 406
410 root_layer->SetElementId(LayerIdToElementIdForTesting(root_layer->id())); 407 root_layer->SetElementId(LayerIdToElementIdForTesting(root_layer->id()));
411 root_layer->SetScrollClipLayerId(root_clip_layer->id()); 408 root_layer->SetScrollClipLayerId(root_clip_layer->id());
412 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). 409 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0).
413 root_clip_layer->SetBounds(gfx::Size(20, 50)); 410 root_clip_layer->SetBounds(gfx::Size(20, 50));
414 root_layer->SetBounds(gfx::Size(100, 50)); 411 root_layer->SetBounds(gfx::Size(100, 50));
415 content_layer->SetBounds(gfx::Size(100, 50)); 412 content_layer->SetBounds(gfx::Size(100, 50));
416 413
417 layer_tree_host_->SetRootLayer(root_clip_layer); 414 layer_tree_host_->SetRootLayer(root_clip_layer);
418 root_clip_layer->AddChild(root_layer); 415 root_clip_layer->AddChild(root_layer);
419 root_layer->AddChild(content_layer); 416 root_layer->AddChild(content_layer);
420 root_layer->AddChild(scrollbar_layer); 417 root_layer->AddChild(scrollbar_layer);
421 418
422 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); 419 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
423 scrollbar_layer->SetBounds(gfx::Size(70, 10)); 420 scrollbar_layer->SetBounds(gfx::Size(70, 10));
424 scrollbar_layer->SetScrollInfo(root_layer->id(), root_layer->element_id()); 421 scrollbar_layer->SetScrollElementId(root_layer->element_id());
425 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); 422 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
426 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); 423 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
427 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); 424 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
428 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); 425 scrollbar_layer->fake_scrollbar()->set_thumb_length(4);
429 layer_tree_host_->UpdateLayers(); 426 layer_tree_host_->UpdateLayers();
430 LayerImpl* root_clip_layer_impl = nullptr; 427 LayerImpl* root_clip_layer_impl = nullptr;
431 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr; 428 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr;
432 429
433 // Thumb is at the edge of the scrollbar (should be inset to 430 // Thumb is at the edge of the scrollbar (should be inset to
434 // the start of the track within the scrollbar layer's 431 // the start of the track within the scrollbar layer's
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), 474 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(),
478 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 475 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
479 } 476 }
480 477
481 TEST_F(ScrollbarLayerTest, ThumbRectForOverlayLeftSideVerticalScrollbar) { 478 TEST_F(ScrollbarLayerTest, ThumbRectForOverlayLeftSideVerticalScrollbar) {
482 scoped_refptr<Layer> root_clip_layer = Layer::Create(); 479 scoped_refptr<Layer> root_clip_layer = Layer::Create();
483 scoped_refptr<Layer> root_layer = Layer::Create(); 480 scoped_refptr<Layer> root_layer = Layer::Create();
484 // Create an overlay left side vertical scrollbar. 481 // Create an overlay left side vertical scrollbar.
485 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 482 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
486 FakePaintedScrollbarLayer::Create(false, true, VERTICAL, true, true, 483 FakePaintedScrollbarLayer::Create(false, true, VERTICAL, true, true,
487 root_layer->id(),
488 root_layer->element_id()); 484 root_layer->element_id());
489 root_layer->SetScrollClipLayerId(root_clip_layer->id()); 485 root_layer->SetScrollClipLayerId(root_clip_layer->id());
490 root_clip_layer->SetBounds(gfx::Size(50, 20)); 486 root_clip_layer->SetBounds(gfx::Size(50, 20));
491 root_layer->SetBounds(gfx::Size(50, 100)); 487 root_layer->SetBounds(gfx::Size(50, 100));
492 488
493 layer_tree_host_->SetRootLayer(root_clip_layer); 489 layer_tree_host_->SetRootLayer(root_clip_layer);
494 root_clip_layer->AddChild(root_layer); 490 root_clip_layer->AddChild(root_layer);
495 root_layer->AddChild(scrollbar_layer); 491 root_layer->AddChild(scrollbar_layer);
496 492
497 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); 493 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
498 scrollbar_layer->SetBounds(gfx::Size(10, 20)); 494 scrollbar_layer->SetBounds(gfx::Size(10, 20));
499 scrollbar_layer->SetScrollInfo(root_layer->id(), root_layer->element_id()); 495 scrollbar_layer->SetScrollElementId(root_layer->element_id());
500 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(0, 0, 10, 20)); 496 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(0, 0, 10, 20));
501 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); 497 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
502 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); 498 scrollbar_layer->fake_scrollbar()->set_thumb_length(4);
503 layer_tree_host_->UpdateLayers(); 499 layer_tree_host_->UpdateLayers();
504 LayerImpl* root_clip_layer_impl = nullptr; 500 LayerImpl* root_clip_layer_impl = nullptr;
505 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr; 501 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr;
506 502
507 // Thumb is at the edge of the scrollbar (should be inset to 503 // Thumb is at the edge of the scrollbar (should be inset to
508 // the start of the track within the scrollbar layer's 504 // the start of the track within the scrollbar layer's
509 // position). 505 // position).
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 595
600 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 596 scoped_refptr<Layer> layer_tree_root = Layer::Create();
601 scoped_refptr<Layer> scroll_layer = Layer::Create(); 597 scoped_refptr<Layer> scroll_layer = Layer::Create();
602 scroll_layer->SetElementId(LayerIdToElementIdForTesting(scroll_layer->id())); 598 scroll_layer->SetElementId(LayerIdToElementIdForTesting(scroll_layer->id()));
603 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); 599 scroll_layer->SetScrollClipLayerId(layer_tree_root->id());
604 scoped_refptr<Layer> child1 = Layer::Create(); 600 scoped_refptr<Layer> child1 = Layer::Create();
605 scoped_refptr<Layer> child2; 601 scoped_refptr<Layer> child2;
606 const bool kIsLeftSideVerticalScrollbar = false; 602 const bool kIsLeftSideVerticalScrollbar = false;
607 child2 = SolidColorScrollbarLayer::Create( 603 child2 = SolidColorScrollbarLayer::Create(
608 scrollbar->Orientation(), kThumbThickness, kTrackStart, 604 scrollbar->Orientation(), kThumbThickness, kTrackStart,
609 kIsLeftSideVerticalScrollbar, scroll_layer->id(), 605 kIsLeftSideVerticalScrollbar, scroll_layer->element_id());
610 scroll_layer->element_id());
611 scroll_layer->AddChild(child1); 606 scroll_layer->AddChild(child1);
612 scroll_layer->InsertChild(child2, 1); 607 scroll_layer->InsertChild(child2, 1);
613 layer_tree_root->AddChild(scroll_layer); 608 layer_tree_root->AddChild(scroll_layer);
614 layer_tree_host_->SetRootLayer(layer_tree_root); 609 layer_tree_host_->SetRootLayer(layer_tree_root);
615 610
616 // Choose layer bounds to give max_scroll_offset = (8, 8). 611 // Choose layer bounds to give max_scroll_offset = (8, 8).
617 layer_tree_root->SetBounds(gfx::Size(2, 2)); 612 layer_tree_root->SetBounds(gfx::Size(2, 2));
618 scroll_layer->SetBounds(gfx::Size(10, 10)); 613 scroll_layer->SetBounds(gfx::Size(10, 10));
619 614
620 layer_tree_host_->UpdateLayers(); 615 layer_tree_host_->UpdateLayers();
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 647 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
653 648
654 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 649 scoped_refptr<Layer> layer_tree_root = Layer::Create();
655 scoped_refptr<Layer> scroll_layer = Layer::Create(); 650 scoped_refptr<Layer> scroll_layer = Layer::Create();
656 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); 651 scroll_layer->SetScrollClipLayerId(layer_tree_root->id());
657 scoped_refptr<Layer> child1 = Layer::Create(); 652 scoped_refptr<Layer> child1 = Layer::Create();
658 scoped_refptr<Layer> scrollbar_layer; 653 scoped_refptr<Layer> scrollbar_layer;
659 const bool kIsLeftSideVerticalScrollbar = false; 654 const bool kIsLeftSideVerticalScrollbar = false;
660 scrollbar_layer = SolidColorScrollbarLayer::Create( 655 scrollbar_layer = SolidColorScrollbarLayer::Create(
661 scrollbar->Orientation(), kThumbThickness, kTrackStart, 656 scrollbar->Orientation(), kThumbThickness, kTrackStart,
662 kIsLeftSideVerticalScrollbar, scroll_layer->id(), 657 kIsLeftSideVerticalScrollbar, scroll_layer->element_id());
663 scroll_layer->element_id());
664 scroll_layer->AddChild(child1); 658 scroll_layer->AddChild(child1);
665 scroll_layer->InsertChild(scrollbar_layer, 1); 659 scroll_layer->InsertChild(scrollbar_layer, 1);
666 layer_tree_root->AddChild(scroll_layer); 660 layer_tree_root->AddChild(scroll_layer);
667 layer_tree_host_->SetRootLayer(layer_tree_root); 661 layer_tree_host_->SetRootLayer(layer_tree_root);
668 662
669 // Choose layer bounds to give max_scroll_offset = (8, 8). 663 // Choose layer bounds to give max_scroll_offset = (8, 8).
670 layer_tree_root->SetBounds(gfx::Size(2, 2)); 664 layer_tree_root->SetBounds(gfx::Size(2, 2));
671 scroll_layer->SetBounds(gfx::Size(10, 10)); 665 scroll_layer->SetBounds(gfx::Size(10, 10));
672 666
673 // Building property trees twice shouldn't change the size of 667 // Building property trees twice shouldn't change the size of
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 729
736 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 730 scoped_refptr<Layer> layer_tree_root = Layer::Create();
737 scoped_refptr<Layer> scroll_layer = Layer::Create(); 731 scoped_refptr<Layer> scroll_layer = Layer::Create();
738 scroll_layer->SetElementId(LayerIdToElementIdForTesting(scroll_layer->id())); 732 scroll_layer->SetElementId(LayerIdToElementIdForTesting(scroll_layer->id()));
739 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); 733 scroll_layer->SetScrollClipLayerId(layer_tree_root->id());
740 scoped_refptr<Layer> child1 = Layer::Create(); 734 scoped_refptr<Layer> child1 = Layer::Create();
741 scoped_refptr<Layer> scrollbar_layer; 735 scoped_refptr<Layer> scrollbar_layer;
742 const bool kIsLeftSideVerticalScrollbar = false; 736 const bool kIsLeftSideVerticalScrollbar = false;
743 scrollbar_layer = SolidColorScrollbarLayer::Create( 737 scrollbar_layer = SolidColorScrollbarLayer::Create(
744 scrollbar->Orientation(), kThumbThickness, kTrackStart, 738 scrollbar->Orientation(), kThumbThickness, kTrackStart,
745 kIsLeftSideVerticalScrollbar, scroll_layer->id(), 739 kIsLeftSideVerticalScrollbar, scroll_layer->element_id());
746 scroll_layer->element_id());
747 scroll_layer->AddChild(child1); 740 scroll_layer->AddChild(child1);
748 scroll_layer->InsertChild(scrollbar_layer, 1); 741 scroll_layer->InsertChild(scrollbar_layer, 1);
749 layer_tree_root->AddChild(scroll_layer); 742 layer_tree_root->AddChild(scroll_layer);
750 layer_tree_host_->SetRootLayer(layer_tree_root); 743 layer_tree_host_->SetRootLayer(layer_tree_root);
751 744
752 layer_tree_root->SetBounds(gfx::Size(2, 2)); 745 layer_tree_root->SetBounds(gfx::Size(2, 2));
753 scroll_layer->SetBounds(gfx::Size(10, 10)); 746 scroll_layer->SetBounds(gfx::Size(10, 10));
754 layer_tree_host_->UpdateLayers(); 747 layer_tree_host_->UpdateLayers();
755 layer_tree_host_->CommitAndCreateLayerImplTree(); 748 layer_tree_host_->CommitAndCreateLayerImplTree();
756 LayerTreeHostImpl* host_impl = layer_tree_host_->host_impl(); 749 LayerTreeHostImpl* host_impl = layer_tree_host_->host_impl();
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
883 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); 876 std::unique_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false));
884 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 877 scoped_refptr<Layer> layer_tree_root = Layer::Create();
885 scoped_refptr<Layer> content_layer = Layer::Create(); 878 scoped_refptr<Layer> content_layer = Layer::Create();
886 scoped_refptr<Layer> scrollbar_layer; 879 scoped_refptr<Layer> scrollbar_layer;
887 if (use_solid_color_scrollbar) { 880 if (use_solid_color_scrollbar) {
888 const int kThumbThickness = 3; 881 const int kThumbThickness = 3;
889 const int kTrackStart = 0; 882 const int kTrackStart = 0;
890 const bool kIsLeftSideVerticalScrollbar = false; 883 const bool kIsLeftSideVerticalScrollbar = false;
891 scrollbar_layer = SolidColorScrollbarLayer::Create( 884 scrollbar_layer = SolidColorScrollbarLayer::Create(
892 scrollbar->Orientation(), kThumbThickness, kTrackStart, 885 scrollbar->Orientation(), kThumbThickness, kTrackStart,
893 kIsLeftSideVerticalScrollbar, layer_tree_root->id(), 886 kIsLeftSideVerticalScrollbar, layer_tree_root->element_id());
894 layer_tree_root->element_id());
895 } else { 887 } else {
896 scrollbar_layer = PaintedScrollbarLayer::Create( 888 scrollbar_layer = PaintedScrollbarLayer::Create(
897 std::move(scrollbar), layer_tree_root->id(), 889 std::move(scrollbar), layer_tree_root->element_id());
898 layer_tree_root->element_id());
899 } 890 }
900 layer_tree_root->AddChild(content_layer); 891 layer_tree_root->AddChild(content_layer);
901 layer_tree_root->AddChild(scrollbar_layer); 892 layer_tree_root->AddChild(scrollbar_layer);
902 893
903 layer_tree_host_->SetRootLayer(layer_tree_root); 894 layer_tree_host_->SetRootLayer(layer_tree_root);
904 895
905 scrollbar_layer->SetIsDrawable(true); 896 scrollbar_layer->SetIsDrawable(true);
906 scrollbar_layer->SetBounds(gfx::Size(100, 100)); 897 scrollbar_layer->SetBounds(gfx::Size(100, 100));
907 layer_tree_root->SetScrollOffset(gfx::ScrollOffset(10, 20)); 898 layer_tree_root->SetScrollOffset(gfx::ScrollOffset(10, 20));
908 layer_tree_root->SetBounds(gfx::Size(100, 200)); 899 layer_tree_root->SetBounds(gfx::Size(100, 200));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 bool use_solid_color_scrollbars = true; 938 bool use_solid_color_scrollbars = true;
948 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); 939 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
949 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); 940 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars);
950 } 941 }
951 942
952 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) { 943 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) {
953 gfx::Point scrollbar_location(0, 185); 944 gfx::Point scrollbar_location(0, 185);
954 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 945 scoped_refptr<Layer> layer_tree_root = Layer::Create();
955 scoped_refptr<Layer> content_layer = Layer::Create(); 946 scoped_refptr<Layer> content_layer = Layer::Create();
956 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 947 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
957 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id(), 948 FakePaintedScrollbarLayer::Create(false, true,
958 layer_tree_root->element_id()); 949 layer_tree_root->element_id());
959 950
960 layer_tree_root->AddChild(content_layer); 951 layer_tree_root->AddChild(content_layer);
961 layer_tree_root->AddChild(scrollbar_layer); 952 layer_tree_root->AddChild(scrollbar_layer);
962 953
963 layer_tree_host_->SetRootLayer(layer_tree_root); 954 layer_tree_host_->SetRootLayer(layer_tree_root);
964 955
965 scrollbar_layer->SetIsDrawable(true); 956 scrollbar_layer->SetIsDrawable(true);
966 scrollbar_layer->SetBounds(gfx::Size(100, 15)); 957 scrollbar_layer->SetBounds(gfx::Size(100, 15));
967 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); 958 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location));
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 1099 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
1109 } 1100 }
1110 1101
1111 class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest { 1102 class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest {
1112 public: 1103 public:
1113 void TestResourceUpload(float test_scale) { 1104 void TestResourceUpload(float test_scale) {
1114 gfx::Point scrollbar_location(0, 185); 1105 gfx::Point scrollbar_location(0, 185);
1115 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 1106 scoped_refptr<Layer> layer_tree_root = Layer::Create();
1116 scoped_refptr<Layer> content_layer = Layer::Create(); 1107 scoped_refptr<Layer> content_layer = Layer::Create();
1117 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 1108 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
1118 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id(), 1109 FakePaintedScrollbarLayer::Create(false, true,
1119 layer_tree_root->element_id()); 1110 layer_tree_root->element_id());
1120 1111
1121 layer_tree_root->AddChild(content_layer); 1112 layer_tree_root->AddChild(content_layer);
1122 layer_tree_root->AddChild(scrollbar_layer); 1113 layer_tree_root->AddChild(scrollbar_layer);
1123 1114
1124 layer_tree_host_->SetRootLayer(layer_tree_root); 1115 layer_tree_host_->SetRootLayer(layer_tree_root);
1125 1116
1126 scrollbar_layer->SetIsDrawable(true); 1117 scrollbar_layer->SetIsDrawable(true);
1127 scrollbar_layer->SetBounds(gfx::Size(100, 15)); 1118 scrollbar_layer->SetBounds(gfx::Size(100, 15));
1128 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location)); 1119 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_location));
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 } 1170 }
1180 1171
1181 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { 1172 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest {
1182 public: 1173 public:
1183 void TestScale(const gfx::Rect& scrollbar_rect, float test_scale) { 1174 void TestScale(const gfx::Rect& scrollbar_rect, float test_scale) {
1184 bool paint_during_update = true; 1175 bool paint_during_update = true;
1185 bool has_thumb = false; 1176 bool has_thumb = false;
1186 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 1177 scoped_refptr<Layer> layer_tree_root = Layer::Create();
1187 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 1178 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
1188 FakePaintedScrollbarLayer::Create(paint_during_update, has_thumb, 1179 FakePaintedScrollbarLayer::Create(paint_during_update, has_thumb,
1189 layer_tree_root->id(),
1190 layer_tree_root->element_id()); 1180 layer_tree_root->element_id());
1191 1181
1192 layer_tree_root->AddChild(scrollbar_layer); 1182 layer_tree_root->AddChild(scrollbar_layer);
1193 1183
1194 layer_tree_host_->SetRootLayer(layer_tree_root); 1184 layer_tree_host_->SetRootLayer(layer_tree_root);
1195 1185
1196 scrollbar_layer->SetBounds(scrollbar_rect.size()); 1186 scrollbar_layer->SetBounds(scrollbar_rect.size());
1197 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_rect.origin())); 1187 scrollbar_layer->SetPosition(gfx::PointF(scrollbar_rect.origin()));
1198 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin()); 1188 scrollbar_layer->fake_scrollbar()->set_location(scrollbar_rect.origin());
1199 scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect); 1189 scrollbar_layer->fake_scrollbar()->set_track_rect(scrollbar_rect);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1249 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); 1239 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f);
1250 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); 1240 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f);
1251 1241
1252 // Horizontal Scrollbars. 1242 // Horizontal Scrollbars.
1253 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); 1243 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f);
1254 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); 1244 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f);
1255 } 1245 }
1256 1246
1257 } // namespace 1247 } // namespace
1258 } // namespace cc 1248 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698