OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "ui/views/view.h" | 5 #include "ui/views/view.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <map> | 9 #include <map> |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/i18n/rtl.h" | 12 #include "base/i18n/rtl.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "base/strings/stringprintf.h" | 17 #include "base/strings/stringprintf.h" |
18 #include "base/strings/utf_string_conversions.h" | 18 #include "base/strings/utf_string_conversions.h" |
19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
20 #include "cc/paint/display_item_list.h" | 20 #include "cc/paint/display_item_list.h" |
21 #include "ui/base/accelerators/accelerator.h" | 21 #include "ui/base/accelerators/accelerator.h" |
22 #include "ui/base/clipboard/clipboard.h" | 22 #include "ui/base/clipboard/clipboard.h" |
23 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
24 #include "ui/compositor/compositor.h" | 24 #include "ui/compositor/compositor.h" |
25 #include "ui/compositor/layer.h" | 25 #include "ui/compositor/layer.h" |
26 #include "ui/compositor/layer_animator.h" | 26 #include "ui/compositor/layer_animator.h" |
27 #include "ui/compositor/paint_context.h" | 27 #include "ui/compositor/paint_context.h" |
| 28 #include "ui/compositor/paint_info.h" |
28 #include "ui/compositor/test/draw_waiter_for_test.h" | 29 #include "ui/compositor/test/draw_waiter_for_test.h" |
29 #include "ui/events/event.h" | 30 #include "ui/events/event.h" |
30 #include "ui/events/event_utils.h" | 31 #include "ui/events/event_utils.h" |
31 #include "ui/events/keycodes/keyboard_codes.h" | 32 #include "ui/events/keycodes/keyboard_codes.h" |
32 #include "ui/events/scoped_target_handler.h" | 33 #include "ui/events/scoped_target_handler.h" |
33 #include "ui/events/test/event_generator.h" | 34 #include "ui/events/test/event_generator.h" |
34 #include "ui/gfx/canvas.h" | 35 #include "ui/gfx/canvas.h" |
35 #include "ui/gfx/path.h" | 36 #include "ui/gfx/path.h" |
36 #include "ui/gfx/transform.h" | 37 #include "ui/gfx/transform.h" |
37 #include "ui/native_theme/native_theme.h" | 38 #include "ui/native_theme/native_theme.h" |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 v1->AddChildView(v11); | 521 v1->AddChildView(v11); |
521 | 522 |
522 // |v2| is not. | 523 // |v2| is not. |
523 TestView* v2 = new TestView; | 524 TestView* v2 = new TestView; |
524 v2->SetBounds(3, 4, 6, 5); | 525 v2->SetBounds(3, 4, 6, 5); |
525 root_view->AddChildView(v2); | 526 root_view->AddChildView(v2); |
526 | 527 |
527 // Paint "everything". | 528 // Paint "everything". |
528 gfx::Rect first_paint(1, 1); | 529 gfx::Rect first_paint(1, 1); |
529 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 530 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
530 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 531 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, first_paint), |
| 532 first_paint.size())); |
531 | 533 |
532 // The empty view has nothing to paint so it doesn't try build a cache, nor do | 534 // The empty view has nothing to paint so it doesn't try build a cache, nor do |
533 // its children which would be clipped by its (empty) self. | 535 // its children which would be clipped by its (empty) self. |
534 EXPECT_FALSE(v1->did_paint_); | 536 EXPECT_FALSE(v1->did_paint_); |
535 EXPECT_FALSE(v11->did_paint_); | 537 EXPECT_FALSE(v11->did_paint_); |
536 EXPECT_TRUE(v2->did_paint_); | 538 EXPECT_TRUE(v2->did_paint_); |
537 } | 539 } |
538 | 540 |
539 TEST_F(ViewTest, PaintWithMovedViewUsesCache) { | 541 TEST_F(ViewTest, PaintWithMovedViewUsesCache) { |
540 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 542 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
541 View* root_view = widget->GetRootView(); | 543 View* root_view = widget->GetRootView(); |
542 TestView* v1 = new TestView; | 544 TestView* v1 = new TestView; |
543 v1->SetBounds(10, 11, 12, 13); | 545 v1->SetBounds(10, 11, 12, 13); |
544 root_view->AddChildView(v1); | 546 root_view->AddChildView(v1); |
545 | 547 |
546 // Paint everything once, since it has to build its cache. Then we can test | 548 // Paint everything once, since it has to build its cache. Then we can test |
547 // invalidation. | 549 // invalidation. |
548 gfx::Rect pixel_rect = gfx::Rect(1, 1); | 550 gfx::Rect pixel_rect = gfx::Rect(1, 1); |
549 float device_scale_factor = 1.f; | 551 float device_scale_factor = 1.f; |
550 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 552 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
551 root_view->Paint( | 553 root_view->Paint(ui::PaintInfo( |
552 ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); | 554 ui::PaintContext(list.get(), device_scale_factor, pixel_rect), |
| 555 pixel_rect.size())); |
553 EXPECT_TRUE(v1->did_paint_); | 556 EXPECT_TRUE(v1->did_paint_); |
554 v1->Reset(); | 557 v1->Reset(); |
555 // The visual rects for (clip, drawing, transform) should be in layer space. | 558 // The visual rects for (clip, drawing, transform) should be in layer space. |
556 gfx::Rect expected_visual_rect_in_layer_space(10, 11, 12, 13); | 559 gfx::Rect expected_visual_rect_in_layer_space(10, 11, 12, 13); |
557 int item_index = 3; | 560 int item_index = 3; |
558 EXPECT_EQ(expected_visual_rect_in_layer_space, | 561 EXPECT_EQ(expected_visual_rect_in_layer_space, |
559 list->VisualRectForTesting(item_index++)); | 562 list->VisualRectForTesting(item_index++)); |
560 EXPECT_EQ(expected_visual_rect_in_layer_space, | 563 EXPECT_EQ(expected_visual_rect_in_layer_space, |
561 list->VisualRectForTesting(item_index++)); | 564 list->VisualRectForTesting(item_index++)); |
562 EXPECT_EQ(expected_visual_rect_in_layer_space, | 565 EXPECT_EQ(expected_visual_rect_in_layer_space, |
563 list->VisualRectForTesting(item_index)); | 566 list->VisualRectForTesting(item_index)); |
564 | 567 |
565 // If invalidation doesn't intersect v1, we paint with the cache. | 568 // If invalidation doesn't intersect v1, we paint with the cache. |
566 list = base::MakeRefCounted<cc::DisplayItemList>(); | 569 list = base::MakeRefCounted<cc::DisplayItemList>(); |
567 root_view->Paint( | 570 root_view->Paint(ui::PaintInfo( |
568 ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); | 571 ui::PaintContext(list.get(), device_scale_factor, pixel_rect), |
| 572 root_view->size())); |
569 EXPECT_FALSE(v1->did_paint_); | 573 EXPECT_FALSE(v1->did_paint_); |
570 v1->Reset(); | 574 v1->Reset(); |
571 | 575 |
572 // If invalidation does intersect v1, we don't paint with the cache. | 576 // If invalidation does intersect v1, we don't paint with the cache. |
573 list = base::MakeRefCounted<cc::DisplayItemList>(); | 577 list = base::MakeRefCounted<cc::DisplayItemList>(); |
574 root_view->Paint( | 578 root_view->Paint(ui::PaintInfo( |
575 ui::PaintContext(list.get(), device_scale_factor, v1->bounds())); | 579 ui::PaintContext(list.get(), device_scale_factor, v1->bounds()), |
| 580 root_view->size())); |
576 EXPECT_TRUE(v1->did_paint_); | 581 EXPECT_TRUE(v1->did_paint_); |
577 v1->Reset(); | 582 v1->Reset(); |
578 | 583 |
579 // Moving the view should still use the cache when the invalidation doesn't | 584 // Moving the view should still use the cache when the invalidation doesn't |
580 // intersect v1. | 585 // intersect v1. |
581 list = base::MakeRefCounted<cc::DisplayItemList>(); | 586 list = base::MakeRefCounted<cc::DisplayItemList>(); |
582 v1->SetX(9); | 587 v1->SetX(9); |
583 root_view->Paint( | 588 root_view->Paint(ui::PaintInfo( |
584 ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); | 589 ui::PaintContext(list.get(), device_scale_factor, pixel_rect), |
| 590 root_view->size())); |
585 EXPECT_FALSE(v1->did_paint_); | 591 EXPECT_FALSE(v1->did_paint_); |
586 v1->Reset(); | 592 v1->Reset(); |
587 item_index = 3; | 593 item_index = 3; |
588 expected_visual_rect_in_layer_space.SetRect(9, 11, 12, 13); | 594 expected_visual_rect_in_layer_space.SetRect(9, 11, 12, 13); |
589 EXPECT_EQ(expected_visual_rect_in_layer_space, | 595 EXPECT_EQ(expected_visual_rect_in_layer_space, |
590 list->VisualRectForTesting(item_index++)); | 596 list->VisualRectForTesting(item_index++)); |
591 EXPECT_EQ(expected_visual_rect_in_layer_space, | 597 EXPECT_EQ(expected_visual_rect_in_layer_space, |
592 list->VisualRectForTesting(item_index++)); | 598 list->VisualRectForTesting(item_index++)); |
593 EXPECT_EQ(expected_visual_rect_in_layer_space, | 599 EXPECT_EQ(expected_visual_rect_in_layer_space, |
594 list->VisualRectForTesting(item_index)); | 600 list->VisualRectForTesting(item_index)); |
595 | 601 |
596 // Moving the view should not use the cache when painting without | 602 // Moving the view should not use the cache when painting without |
597 // invalidation. | 603 // invalidation. |
598 list = base::MakeRefCounted<cc::DisplayItemList>(); | 604 list = base::MakeRefCounted<cc::DisplayItemList>(); |
599 v1->SetX(8); | 605 v1->SetX(8); |
600 root_view->Paint(ui::PaintContext( | 606 root_view->Paint(ui::PaintInfo(ui::PaintInfo( |
601 ui::PaintContext(list.get(), device_scale_factor, pixel_rect), | 607 ui::PaintContext(list.get(), device_scale_factor, pixel_rect), |
602 ui::PaintContext::CLONE_WITHOUT_INVALIDATION)); | 608 root_view->size()))); |
603 EXPECT_TRUE(v1->did_paint_); | 609 EXPECT_TRUE(v1->did_paint_); |
604 v1->Reset(); | 610 v1->Reset(); |
605 item_index = 3; | 611 item_index = 3; |
606 expected_visual_rect_in_layer_space.SetRect(8, 11, 12, 13); | 612 expected_visual_rect_in_layer_space.SetRect(8, 11, 12, 13); |
607 EXPECT_EQ(expected_visual_rect_in_layer_space, | 613 EXPECT_EQ(expected_visual_rect_in_layer_space, |
608 list->VisualRectForTesting(item_index++)); | 614 list->VisualRectForTesting(item_index++)); |
609 EXPECT_EQ(expected_visual_rect_in_layer_space, | 615 EXPECT_EQ(expected_visual_rect_in_layer_space, |
610 list->VisualRectForTesting(item_index++)); | 616 list->VisualRectForTesting(item_index++)); |
611 EXPECT_EQ(expected_visual_rect_in_layer_space, | 617 EXPECT_EQ(expected_visual_rect_in_layer_space, |
612 list->VisualRectForTesting(item_index)); | 618 list->VisualRectForTesting(item_index)); |
613 } | 619 } |
614 | 620 |
615 TEST_F(ViewTest, PaintWithMovedViewUsesCacheInRTL) { | 621 TEST_F(ViewTest, PaintWithMovedViewUsesCacheInRTL) { |
616 ScopedRTL rtl; | 622 ScopedRTL rtl; |
617 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 623 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
618 View* root_view = widget->GetRootView(); | 624 View* root_view = widget->GetRootView(); |
619 TestView* v1 = new TestView; | 625 TestView* v1 = new TestView; |
620 v1->SetBounds(10, 11, 12, 13); | 626 v1->SetBounds(10, 11, 12, 13); |
621 root_view->AddChildView(v1); | 627 root_view->AddChildView(v1); |
622 | 628 |
623 // Paint everything once, since it has to build its cache. Then we can test | 629 // Paint everything once, since it has to build its cache. Then we can test |
624 // invalidation. | 630 // invalidation. |
625 gfx::Rect pixel_rect = gfx::Rect(1, 1); | 631 gfx::Rect pixel_rect = gfx::Rect(1, 1); |
626 float device_scale_factor = 1.f; | 632 float device_scale_factor = 1.f; |
627 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 633 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
628 root_view->Paint( | 634 root_view->Paint(ui::PaintInfo( |
629 ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); | 635 ui::PaintContext(list.get(), device_scale_factor, pixel_rect), |
| 636 root_view->size())); |
630 EXPECT_TRUE(v1->did_paint_); | 637 EXPECT_TRUE(v1->did_paint_); |
631 v1->Reset(); | 638 v1->Reset(); |
632 // The visual rects for (clip, drawing, transform) should be in layer space. | 639 // The visual rects for (clip, drawing, transform) should be in layer space. |
633 // x: 25 - 10(x) - 12(width) = 3 | 640 // x: 25 - 10(x) - 12(width) = 3 |
634 gfx::Rect expected_visual_rect_in_layer_space(3, 11, 12, 13); | 641 gfx::Rect expected_visual_rect_in_layer_space(3, 11, 12, 13); |
635 int item_index = 3; | 642 int item_index = 3; |
636 EXPECT_EQ(expected_visual_rect_in_layer_space, | 643 EXPECT_EQ(expected_visual_rect_in_layer_space, |
637 list->VisualRectForTesting(item_index++)); | 644 list->VisualRectForTesting(item_index++)); |
638 EXPECT_EQ(expected_visual_rect_in_layer_space, | 645 EXPECT_EQ(expected_visual_rect_in_layer_space, |
639 list->VisualRectForTesting(item_index++)); | 646 list->VisualRectForTesting(item_index++)); |
640 EXPECT_EQ(expected_visual_rect_in_layer_space, | 647 EXPECT_EQ(expected_visual_rect_in_layer_space, |
641 list->VisualRectForTesting(item_index)); | 648 list->VisualRectForTesting(item_index)); |
642 | 649 |
643 // If invalidation doesn't intersect v1, we paint with the cache. | 650 // If invalidation doesn't intersect v1, we paint with the cache. |
644 list = base::MakeRefCounted<cc::DisplayItemList>(); | 651 list = base::MakeRefCounted<cc::DisplayItemList>(); |
645 root_view->Paint( | 652 root_view->Paint(ui::PaintInfo( |
646 ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); | 653 ui::PaintContext(list.get(), device_scale_factor, pixel_rect), |
| 654 root_view->size())); |
647 EXPECT_FALSE(v1->did_paint_); | 655 EXPECT_FALSE(v1->did_paint_); |
648 v1->Reset(); | 656 v1->Reset(); |
649 | 657 |
650 // If invalidation does intersect v1, we don't paint with the cache. | 658 // If invalidation does intersect v1, we don't paint with the cache. |
651 list = base::MakeRefCounted<cc::DisplayItemList>(); | 659 list = base::MakeRefCounted<cc::DisplayItemList>(); |
652 root_view->Paint( | 660 root_view->Paint(ui::PaintInfo( |
653 ui::PaintContext(list.get(), device_scale_factor, v1->bounds())); | 661 ui::PaintContext(list.get(), device_scale_factor, v1->bounds()), |
| 662 root_view->size())); |
654 EXPECT_TRUE(v1->did_paint_); | 663 EXPECT_TRUE(v1->did_paint_); |
655 v1->Reset(); | 664 v1->Reset(); |
656 | 665 |
657 // Moving the view should still use the cache when the invalidation doesn't | 666 // Moving the view should still use the cache when the invalidation doesn't |
658 // intersect v1. | 667 // intersect v1. |
659 list = base::MakeRefCounted<cc::DisplayItemList>(); | 668 list = base::MakeRefCounted<cc::DisplayItemList>(); |
660 v1->SetX(9); | 669 v1->SetX(9); |
661 root_view->Paint( | 670 root_view->Paint(ui::PaintInfo( |
662 ui::PaintContext(list.get(), device_scale_factor, pixel_rect)); | 671 ui::PaintContext(list.get(), device_scale_factor, pixel_rect), |
| 672 root_view->size())); |
663 EXPECT_FALSE(v1->did_paint_); | 673 EXPECT_FALSE(v1->did_paint_); |
664 v1->Reset(); | 674 v1->Reset(); |
665 item_index = 3; | 675 item_index = 3; |
666 // x: 25 - 9(x) - 12(width) = 4 | 676 // x: 25 - 9(x) - 12(width) = 4 |
667 expected_visual_rect_in_layer_space.SetRect(4, 11, 12, 13); | 677 expected_visual_rect_in_layer_space.SetRect(4, 11, 12, 13); |
668 EXPECT_EQ(expected_visual_rect_in_layer_space, | 678 EXPECT_EQ(expected_visual_rect_in_layer_space, |
669 list->VisualRectForTesting(item_index++)); | 679 list->VisualRectForTesting(item_index++)); |
670 EXPECT_EQ(expected_visual_rect_in_layer_space, | 680 EXPECT_EQ(expected_visual_rect_in_layer_space, |
671 list->VisualRectForTesting(item_index++)); | 681 list->VisualRectForTesting(item_index++)); |
672 EXPECT_EQ(expected_visual_rect_in_layer_space, | 682 EXPECT_EQ(expected_visual_rect_in_layer_space, |
673 list->VisualRectForTesting(item_index)); | 683 list->VisualRectForTesting(item_index)); |
674 | 684 |
675 // Moving the view should not use the cache when painting without | 685 // Moving the view should not use the cache when painting without |
676 // invalidation. | 686 // invalidation. |
677 list = base::MakeRefCounted<cc::DisplayItemList>(); | 687 list = base::MakeRefCounted<cc::DisplayItemList>(); |
678 v1->SetX(8); | 688 v1->SetX(8); |
679 root_view->Paint(ui::PaintContext( | 689 root_view->Paint(ui::PaintInfo(ui::PaintInfo( |
680 ui::PaintContext(list.get(), device_scale_factor, pixel_rect), | 690 ui::PaintContext(list.get(), device_scale_factor, pixel_rect), |
681 ui::PaintContext::CLONE_WITHOUT_INVALIDATION)); | 691 root_view->size()))); |
682 EXPECT_TRUE(v1->did_paint_); | 692 EXPECT_TRUE(v1->did_paint_); |
683 v1->Reset(); | 693 v1->Reset(); |
684 item_index = 3; | 694 item_index = 3; |
685 // x: 25 - 8(x) - 12(width) = 5 | 695 // x: 25 - 8(x) - 12(width) = 5 |
686 expected_visual_rect_in_layer_space.SetRect(5, 11, 12, 13); | 696 expected_visual_rect_in_layer_space.SetRect(5, 11, 12, 13); |
687 EXPECT_EQ(expected_visual_rect_in_layer_space, | 697 EXPECT_EQ(expected_visual_rect_in_layer_space, |
688 list->VisualRectForTesting(item_index++)); | 698 list->VisualRectForTesting(item_index++)); |
689 EXPECT_EQ(expected_visual_rect_in_layer_space, | 699 EXPECT_EQ(expected_visual_rect_in_layer_space, |
690 list->VisualRectForTesting(item_index++)); | 700 list->VisualRectForTesting(item_index++)); |
691 EXPECT_EQ(expected_visual_rect_in_layer_space, | 701 EXPECT_EQ(expected_visual_rect_in_layer_space, |
692 list->VisualRectForTesting(item_index)); | 702 list->VisualRectForTesting(item_index)); |
693 } | 703 } |
694 | 704 |
695 TEST_F(ViewTest, PaintWithUnknownInvalidation) { | 705 TEST_F(ViewTest, PaintWithUnknownInvalidation) { |
696 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 706 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
697 View* root_view = widget->GetRootView(); | 707 View* root_view = widget->GetRootView(); |
698 | 708 |
699 TestView* v1 = new TestView; | 709 TestView* v1 = new TestView; |
700 v1->SetBounds(10, 11, 12, 13); | 710 v1->SetBounds(10, 11, 12, 13); |
701 root_view->AddChildView(v1); | 711 root_view->AddChildView(v1); |
702 | 712 |
703 TestView* v2 = new TestView; | 713 TestView* v2 = new TestView; |
704 v2->SetBounds(3, 4, 6, 5); | 714 v2->SetBounds(3, 4, 6, 5); |
705 v1->AddChildView(v2); | 715 v1->AddChildView(v2); |
706 | 716 |
707 // Paint everything once, since it has to build its cache. Then we can test | 717 // Paint everything once, since it has to build its cache. Then we can test |
708 // invalidation. | 718 // invalidation. |
709 gfx::Rect first_paint(1, 1); | 719 gfx::Rect first_paint(1, 1); |
710 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 720 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
711 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 721 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, first_paint), |
| 722 root_view->size())); |
712 v1->Reset(); | 723 v1->Reset(); |
713 v2->Reset(); | 724 v2->Reset(); |
714 | 725 |
715 gfx::Rect paint_area(1, 1); | 726 gfx::Rect paint_area(1, 1); |
716 gfx::Rect root_area(root_view->size()); | 727 gfx::Rect root_area(root_view->size()); |
717 list = base::MakeRefCounted<cc::DisplayItemList>(); | 728 list = base::MakeRefCounted<cc::DisplayItemList>(); |
718 | 729 |
719 // With a known invalidation, v1 and v2 are not painted. | 730 // With a known invalidation, v1 and v2 are not painted. |
720 EXPECT_FALSE(v1->did_paint_); | 731 EXPECT_FALSE(v1->did_paint_); |
721 EXPECT_FALSE(v2->did_paint_); | 732 EXPECT_FALSE(v2->did_paint_); |
722 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 733 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 734 root_view->size())); |
723 EXPECT_FALSE(v1->did_paint_); | 735 EXPECT_FALSE(v1->did_paint_); |
724 EXPECT_FALSE(v2->did_paint_); | 736 EXPECT_FALSE(v2->did_paint_); |
725 | 737 |
726 // With unknown invalidation, v1 and v2 are painted. | 738 // With unknown invalidation, v1 and v2 are painted. |
727 root_view->Paint( | 739 root_view->Paint(ui::PaintInfo(ui::PaintInfo( |
728 ui::PaintContext(ui::PaintContext(list.get(), 1.f, paint_area), | 740 ui::PaintContext(list.get(), 1.f, paint_area), root_view->size()))); |
729 ui::PaintContext::CLONE_WITHOUT_INVALIDATION)); | |
730 EXPECT_TRUE(v1->did_paint_); | 741 EXPECT_TRUE(v1->did_paint_); |
731 EXPECT_TRUE(v2->did_paint_); | 742 EXPECT_TRUE(v2->did_paint_); |
732 } | 743 } |
733 | 744 |
734 TEST_F(ViewTest, PaintContainsChildren) { | 745 TEST_F(ViewTest, PaintContainsChildren) { |
735 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 746 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
736 View* root_view = widget->GetRootView(); | 747 View* root_view = widget->GetRootView(); |
737 | 748 |
738 TestView* v1 = new TestView; | 749 TestView* v1 = new TestView; |
739 v1->SetBounds(10, 11, 12, 13); | 750 v1->SetBounds(10, 11, 12, 13); |
740 root_view->AddChildView(v1); | 751 root_view->AddChildView(v1); |
741 | 752 |
742 TestView* v2 = new TestView; | 753 TestView* v2 = new TestView; |
743 v2->SetBounds(3, 4, 6, 5); | 754 v2->SetBounds(3, 4, 6, 5); |
744 v1->AddChildView(v2); | 755 v1->AddChildView(v2); |
745 | 756 |
746 // Paint everything once, since it has to build its cache. Then we can test | 757 // Paint everything once, since it has to build its cache. Then we can test |
747 // invalidation. | 758 // invalidation. |
748 gfx::Rect first_paint(1, 1); | 759 gfx::Rect first_paint(1, 1); |
749 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 760 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
750 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 761 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, first_paint), |
| 762 root_view->size())); |
751 v1->Reset(); | 763 v1->Reset(); |
752 v2->Reset(); | 764 v2->Reset(); |
753 | 765 |
754 gfx::Rect paint_area(25, 26); | 766 gfx::Rect paint_area(25, 26); |
755 gfx::Rect root_area(root_view->size()); | 767 gfx::Rect root_area(root_view->size()); |
756 list = base::MakeRefCounted<cc::DisplayItemList>(); | 768 list = base::MakeRefCounted<cc::DisplayItemList>(); |
757 | 769 |
758 EXPECT_FALSE(v1->did_paint_); | 770 EXPECT_FALSE(v1->did_paint_); |
759 EXPECT_FALSE(v2->did_paint_); | 771 EXPECT_FALSE(v2->did_paint_); |
760 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 772 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 773 root_view->size())); |
761 EXPECT_TRUE(v1->did_paint_); | 774 EXPECT_TRUE(v1->did_paint_); |
762 EXPECT_TRUE(v2->did_paint_); | 775 EXPECT_TRUE(v2->did_paint_); |
763 } | 776 } |
764 | 777 |
765 TEST_F(ViewTest, PaintContainsChildrenInRTL) { | 778 TEST_F(ViewTest, PaintContainsChildrenInRTL) { |
766 ScopedRTL rtl; | 779 ScopedRTL rtl; |
767 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 780 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
768 View* root_view = widget->GetRootView(); | 781 View* root_view = widget->GetRootView(); |
769 | 782 |
770 TestView* v1 = new TestView; | 783 TestView* v1 = new TestView; |
(...skipping 12 matching lines...) Expand all Loading... |
783 | 796 |
784 v2->SetPaintToLayer(); | 797 v2->SetPaintToLayer(); |
785 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 | 798 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 |
786 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); | 799 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); |
787 v2->DestroyLayer(); | 800 v2->DestroyLayer(); |
788 | 801 |
789 // Paint everything once, since it has to build its cache. Then we can test | 802 // Paint everything once, since it has to build its cache. Then we can test |
790 // invalidation. | 803 // invalidation. |
791 gfx::Rect first_paint(1, 1); | 804 gfx::Rect first_paint(1, 1); |
792 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 805 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
793 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 806 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, first_paint), |
| 807 root_view->size())); |
794 v1->Reset(); | 808 v1->Reset(); |
795 v2->Reset(); | 809 v2->Reset(); |
796 | 810 |
797 gfx::Rect paint_area(25, 26); | 811 gfx::Rect paint_area(25, 26); |
798 gfx::Rect root_area(root_view->size()); | 812 gfx::Rect root_area(root_view->size()); |
799 list = base::MakeRefCounted<cc::DisplayItemList>(); | 813 list = base::MakeRefCounted<cc::DisplayItemList>(); |
800 | 814 |
801 EXPECT_FALSE(v1->did_paint_); | 815 EXPECT_FALSE(v1->did_paint_); |
802 EXPECT_FALSE(v2->did_paint_); | 816 EXPECT_FALSE(v2->did_paint_); |
803 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 817 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 818 root_view->size())); |
804 EXPECT_TRUE(v1->did_paint_); | 819 EXPECT_TRUE(v1->did_paint_); |
805 EXPECT_TRUE(v2->did_paint_); | 820 EXPECT_TRUE(v2->did_paint_); |
806 } | 821 } |
807 | 822 |
808 TEST_F(ViewTest, PaintIntersectsChildren) { | 823 TEST_F(ViewTest, PaintIntersectsChildren) { |
809 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 824 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
810 View* root_view = widget->GetRootView(); | 825 View* root_view = widget->GetRootView(); |
811 | 826 |
812 TestView* v1 = new TestView; | 827 TestView* v1 = new TestView; |
813 v1->SetBounds(10, 11, 12, 13); | 828 v1->SetBounds(10, 11, 12, 13); |
814 root_view->AddChildView(v1); | 829 root_view->AddChildView(v1); |
815 | 830 |
816 TestView* v2 = new TestView; | 831 TestView* v2 = new TestView; |
817 v2->SetBounds(3, 4, 6, 5); | 832 v2->SetBounds(3, 4, 6, 5); |
818 v1->AddChildView(v2); | 833 v1->AddChildView(v2); |
819 | 834 |
820 // Paint everything once, since it has to build its cache. Then we can test | 835 // Paint everything once, since it has to build its cache. Then we can test |
821 // invalidation. | 836 // invalidation. |
822 gfx::Rect first_paint(1, 1); | 837 gfx::Rect first_paint(1, 1); |
823 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 838 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
824 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 839 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, first_paint), |
| 840 root_view->size())); |
825 v1->Reset(); | 841 v1->Reset(); |
826 v2->Reset(); | 842 v2->Reset(); |
827 | 843 |
828 gfx::Rect paint_area(9, 10, 5, 6); | 844 gfx::Rect paint_area(9, 10, 5, 6); |
829 gfx::Rect root_area(root_view->size()); | 845 gfx::Rect root_area(root_view->size()); |
830 list = base::MakeRefCounted<cc::DisplayItemList>(); | 846 list = base::MakeRefCounted<cc::DisplayItemList>(); |
831 | 847 |
832 EXPECT_FALSE(v1->did_paint_); | 848 EXPECT_FALSE(v1->did_paint_); |
833 EXPECT_FALSE(v2->did_paint_); | 849 EXPECT_FALSE(v2->did_paint_); |
834 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 850 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 851 root_view->size())); |
835 EXPECT_TRUE(v1->did_paint_); | 852 EXPECT_TRUE(v1->did_paint_); |
836 EXPECT_TRUE(v2->did_paint_); | 853 EXPECT_TRUE(v2->did_paint_); |
837 } | 854 } |
838 | 855 |
839 TEST_F(ViewTest, PaintIntersectsChildrenInRTL) { | 856 TEST_F(ViewTest, PaintIntersectsChildrenInRTL) { |
840 ScopedRTL rtl; | 857 ScopedRTL rtl; |
841 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 858 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
842 View* root_view = widget->GetRootView(); | 859 View* root_view = widget->GetRootView(); |
843 | 860 |
844 TestView* v1 = new TestView; | 861 TestView* v1 = new TestView; |
(...skipping 12 matching lines...) Expand all Loading... |
857 | 874 |
858 v2->SetPaintToLayer(); | 875 v2->SetPaintToLayer(); |
859 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 | 876 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 |
860 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); | 877 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); |
861 v2->DestroyLayer(); | 878 v2->DestroyLayer(); |
862 | 879 |
863 // Paint everything once, since it has to build its cache. Then we can test | 880 // Paint everything once, since it has to build its cache. Then we can test |
864 // invalidation. | 881 // invalidation. |
865 gfx::Rect first_paint(1, 1); | 882 gfx::Rect first_paint(1, 1); |
866 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 883 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
867 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 884 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, first_paint), |
| 885 root_view->size())); |
868 v1->Reset(); | 886 v1->Reset(); |
869 v2->Reset(); | 887 v2->Reset(); |
870 | 888 |
871 gfx::Rect paint_area(2, 10, 5, 6); | 889 gfx::Rect paint_area(2, 10, 5, 6); |
872 gfx::Rect root_area(root_view->size()); | 890 gfx::Rect root_area(root_view->size()); |
873 list = base::MakeRefCounted<cc::DisplayItemList>(); | 891 list = base::MakeRefCounted<cc::DisplayItemList>(); |
874 | 892 |
875 EXPECT_FALSE(v1->did_paint_); | 893 EXPECT_FALSE(v1->did_paint_); |
876 EXPECT_FALSE(v2->did_paint_); | 894 EXPECT_FALSE(v2->did_paint_); |
877 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 895 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 896 root_view->size())); |
878 EXPECT_TRUE(v1->did_paint_); | 897 EXPECT_TRUE(v1->did_paint_); |
879 EXPECT_TRUE(v2->did_paint_); | 898 EXPECT_TRUE(v2->did_paint_); |
880 } | 899 } |
881 | 900 |
882 TEST_F(ViewTest, PaintIntersectsChildButNotGrandChild) { | 901 TEST_F(ViewTest, PaintIntersectsChildButNotGrandChild) { |
883 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 902 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
884 View* root_view = widget->GetRootView(); | 903 View* root_view = widget->GetRootView(); |
885 | 904 |
886 TestView* v1 = new TestView; | 905 TestView* v1 = new TestView; |
887 v1->SetBounds(10, 11, 12, 13); | 906 v1->SetBounds(10, 11, 12, 13); |
888 root_view->AddChildView(v1); | 907 root_view->AddChildView(v1); |
889 | 908 |
890 TestView* v2 = new TestView; | 909 TestView* v2 = new TestView; |
891 v2->SetBounds(3, 4, 6, 5); | 910 v2->SetBounds(3, 4, 6, 5); |
892 v1->AddChildView(v2); | 911 v1->AddChildView(v2); |
893 | 912 |
894 // Paint everything once, since it has to build its cache. Then we can test | 913 // Paint everything once, since it has to build its cache. Then we can test |
895 // invalidation. | 914 // invalidation. |
896 gfx::Rect first_paint(1, 1); | 915 gfx::Rect first_paint(1, 1); |
897 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 916 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
898 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 917 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, first_paint), |
| 918 root_view->size())); |
899 v1->Reset(); | 919 v1->Reset(); |
900 v2->Reset(); | 920 v2->Reset(); |
901 | 921 |
902 gfx::Rect paint_area(9, 10, 2, 3); | 922 gfx::Rect paint_area(9, 10, 2, 3); |
903 gfx::Rect root_area(root_view->size()); | 923 gfx::Rect root_area(root_view->size()); |
904 list = base::MakeRefCounted<cc::DisplayItemList>(); | 924 list = base::MakeRefCounted<cc::DisplayItemList>(); |
905 | 925 |
906 EXPECT_FALSE(v1->did_paint_); | 926 EXPECT_FALSE(v1->did_paint_); |
907 EXPECT_FALSE(v2->did_paint_); | 927 EXPECT_FALSE(v2->did_paint_); |
908 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 928 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 929 root_view->size())); |
909 EXPECT_TRUE(v1->did_paint_); | 930 EXPECT_TRUE(v1->did_paint_); |
910 EXPECT_FALSE(v2->did_paint_); | 931 EXPECT_FALSE(v2->did_paint_); |
911 } | 932 } |
912 | 933 |
913 TEST_F(ViewTest, PaintIntersectsChildButNotGrandChildInRTL) { | 934 TEST_F(ViewTest, PaintIntersectsChildButNotGrandChildInRTL) { |
914 ScopedRTL rtl; | 935 ScopedRTL rtl; |
915 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 936 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
916 View* root_view = widget->GetRootView(); | 937 View* root_view = widget->GetRootView(); |
917 | 938 |
918 TestView* v1 = new TestView; | 939 TestView* v1 = new TestView; |
(...skipping 12 matching lines...) Expand all Loading... |
931 | 952 |
932 v2->SetPaintToLayer(); | 953 v2->SetPaintToLayer(); |
933 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 | 954 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 |
934 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); | 955 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); |
935 v2->DestroyLayer(); | 956 v2->DestroyLayer(); |
936 | 957 |
937 // Paint everything once, since it has to build its cache. Then we can test | 958 // Paint everything once, since it has to build its cache. Then we can test |
938 // invalidation. | 959 // invalidation. |
939 gfx::Rect first_paint(1, 1); | 960 gfx::Rect first_paint(1, 1); |
940 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 961 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
941 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 962 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, first_paint), |
| 963 root_view->size())); |
942 v1->Reset(); | 964 v1->Reset(); |
943 v2->Reset(); | 965 v2->Reset(); |
944 | 966 |
945 gfx::Rect paint_area(2, 10, 2, 3); | 967 gfx::Rect paint_area(2, 10, 2, 3); |
946 gfx::Rect root_area(root_view->size()); | 968 gfx::Rect root_area(root_view->size()); |
947 list = base::MakeRefCounted<cc::DisplayItemList>(); | 969 list = base::MakeRefCounted<cc::DisplayItemList>(); |
948 | 970 |
949 EXPECT_FALSE(v1->did_paint_); | 971 EXPECT_FALSE(v1->did_paint_); |
950 EXPECT_FALSE(v2->did_paint_); | 972 EXPECT_FALSE(v2->did_paint_); |
951 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 973 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 974 root_view->size())); |
952 EXPECT_TRUE(v1->did_paint_); | 975 EXPECT_TRUE(v1->did_paint_); |
953 EXPECT_FALSE(v2->did_paint_); | 976 EXPECT_FALSE(v2->did_paint_); |
954 } | 977 } |
955 | 978 |
956 TEST_F(ViewTest, PaintIntersectsNoChildren) { | 979 TEST_F(ViewTest, PaintIntersectsNoChildren) { |
957 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 980 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
958 View* root_view = widget->GetRootView(); | 981 View* root_view = widget->GetRootView(); |
959 | 982 |
960 TestView* v1 = new TestView; | 983 TestView* v1 = new TestView; |
961 v1->SetBounds(10, 11, 12, 13); | 984 v1->SetBounds(10, 11, 12, 13); |
962 root_view->AddChildView(v1); | 985 root_view->AddChildView(v1); |
963 | 986 |
964 TestView* v2 = new TestView; | 987 TestView* v2 = new TestView; |
965 v2->SetBounds(3, 4, 6, 5); | 988 v2->SetBounds(3, 4, 6, 5); |
966 v1->AddChildView(v2); | 989 v1->AddChildView(v2); |
967 | 990 |
968 // Paint everything once, since it has to build its cache. Then we can test | 991 // Paint everything once, since it has to build its cache. Then we can test |
969 // invalidation. | 992 // invalidation. |
970 gfx::Rect first_paint(1, 1); | 993 gfx::Rect first_paint(1, 1); |
971 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 994 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
972 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 995 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, first_paint), |
| 996 root_view->size())); |
973 v1->Reset(); | 997 v1->Reset(); |
974 v2->Reset(); | 998 v2->Reset(); |
975 | 999 |
976 gfx::Rect paint_area(9, 10, 2, 1); | 1000 gfx::Rect paint_area(9, 10, 2, 1); |
977 gfx::Rect root_area(root_view->size()); | 1001 gfx::Rect root_area(root_view->size()); |
978 list = base::MakeRefCounted<cc::DisplayItemList>(); | 1002 list = base::MakeRefCounted<cc::DisplayItemList>(); |
979 | 1003 |
980 EXPECT_FALSE(v1->did_paint_); | 1004 EXPECT_FALSE(v1->did_paint_); |
981 EXPECT_FALSE(v2->did_paint_); | 1005 EXPECT_FALSE(v2->did_paint_); |
982 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 1006 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 1007 root_view->size())); |
983 EXPECT_FALSE(v1->did_paint_); | 1008 EXPECT_FALSE(v1->did_paint_); |
984 EXPECT_FALSE(v2->did_paint_); | 1009 EXPECT_FALSE(v2->did_paint_); |
985 } | 1010 } |
986 | 1011 |
987 TEST_F(ViewTest, PaintIntersectsNoChildrenInRTL) { | 1012 TEST_F(ViewTest, PaintIntersectsNoChildrenInRTL) { |
988 ScopedRTL rtl; | 1013 ScopedRTL rtl; |
989 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 1014 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
990 View* root_view = widget->GetRootView(); | 1015 View* root_view = widget->GetRootView(); |
991 | 1016 |
992 TestView* v1 = new TestView; | 1017 TestView* v1 = new TestView; |
(...skipping 12 matching lines...) Expand all Loading... |
1005 | 1030 |
1006 v2->SetPaintToLayer(); | 1031 v2->SetPaintToLayer(); |
1007 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 | 1032 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 |
1008 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); | 1033 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); |
1009 v2->DestroyLayer(); | 1034 v2->DestroyLayer(); |
1010 | 1035 |
1011 // Paint everything once, since it has to build its cache. Then we can test | 1036 // Paint everything once, since it has to build its cache. Then we can test |
1012 // invalidation. | 1037 // invalidation. |
1013 gfx::Rect first_paint(1, 1); | 1038 gfx::Rect first_paint(1, 1); |
1014 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 1039 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
1015 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 1040 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, first_paint), |
| 1041 root_view->size())); |
1016 v1->Reset(); | 1042 v1->Reset(); |
1017 v2->Reset(); | 1043 v2->Reset(); |
1018 | 1044 |
1019 gfx::Rect paint_area(2, 10, 2, 1); | 1045 gfx::Rect paint_area(2, 10, 2, 1); |
1020 gfx::Rect root_area(root_view->size()); | 1046 gfx::Rect root_area(root_view->size()); |
1021 list = base::MakeRefCounted<cc::DisplayItemList>(); | 1047 list = base::MakeRefCounted<cc::DisplayItemList>(); |
1022 | 1048 |
1023 EXPECT_FALSE(v1->did_paint_); | 1049 EXPECT_FALSE(v1->did_paint_); |
1024 EXPECT_FALSE(v2->did_paint_); | 1050 EXPECT_FALSE(v2->did_paint_); |
1025 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 1051 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 1052 root_view->size())); |
1026 EXPECT_FALSE(v1->did_paint_); | 1053 EXPECT_FALSE(v1->did_paint_); |
1027 EXPECT_FALSE(v2->did_paint_); | 1054 EXPECT_FALSE(v2->did_paint_); |
1028 } | 1055 } |
1029 | 1056 |
1030 TEST_F(ViewTest, PaintIntersectsOneChild) { | 1057 TEST_F(ViewTest, PaintIntersectsOneChild) { |
1031 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 1058 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
1032 View* root_view = widget->GetRootView(); | 1059 View* root_view = widget->GetRootView(); |
1033 | 1060 |
1034 TestView* v1 = new TestView; | 1061 TestView* v1 = new TestView; |
1035 v1->SetBounds(10, 11, 12, 13); | 1062 v1->SetBounds(10, 11, 12, 13); |
1036 root_view->AddChildView(v1); | 1063 root_view->AddChildView(v1); |
1037 | 1064 |
1038 TestView* v2 = new TestView; | 1065 TestView* v2 = new TestView; |
1039 v2->SetBounds(3, 4, 6, 5); | 1066 v2->SetBounds(3, 4, 6, 5); |
1040 root_view->AddChildView(v2); | 1067 root_view->AddChildView(v2); |
1041 | 1068 |
1042 // Paint everything once, since it has to build its cache. Then we can test | 1069 // Paint everything once, since it has to build its cache. Then we can test |
1043 // invalidation. | 1070 // invalidation. |
1044 gfx::Rect first_paint(1, 1); | 1071 gfx::Rect first_paint(1, 1); |
1045 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 1072 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
1046 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 1073 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, first_paint), |
| 1074 root_view->size())); |
1047 v1->Reset(); | 1075 v1->Reset(); |
1048 v2->Reset(); | 1076 v2->Reset(); |
1049 | 1077 |
1050 // Intersects with the second child only. | 1078 // Intersects with the second child only. |
1051 gfx::Rect paint_area(3, 3, 1, 2); | 1079 gfx::Rect paint_area(3, 3, 1, 2); |
1052 gfx::Rect root_area(root_view->size()); | 1080 gfx::Rect root_area(root_view->size()); |
1053 list = base::MakeRefCounted<cc::DisplayItemList>(); | 1081 list = base::MakeRefCounted<cc::DisplayItemList>(); |
1054 | 1082 |
1055 EXPECT_FALSE(v1->did_paint_); | 1083 EXPECT_FALSE(v1->did_paint_); |
1056 EXPECT_FALSE(v2->did_paint_); | 1084 EXPECT_FALSE(v2->did_paint_); |
1057 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 1085 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 1086 root_view->size())); |
1058 EXPECT_FALSE(v1->did_paint_); | 1087 EXPECT_FALSE(v1->did_paint_); |
1059 EXPECT_TRUE(v2->did_paint_); | 1088 EXPECT_TRUE(v2->did_paint_); |
1060 | 1089 |
1061 // Intersects with the first child only. | 1090 // Intersects with the first child only. |
1062 paint_area = gfx::Rect(20, 10, 1, 2); | 1091 paint_area = gfx::Rect(20, 10, 1, 2); |
1063 | 1092 |
1064 v1->Reset(); | 1093 v1->Reset(); |
1065 v2->Reset(); | 1094 v2->Reset(); |
1066 EXPECT_FALSE(v1->did_paint_); | 1095 EXPECT_FALSE(v1->did_paint_); |
1067 EXPECT_FALSE(v2->did_paint_); | 1096 EXPECT_FALSE(v2->did_paint_); |
1068 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 1097 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 1098 root_view->size())); |
1069 EXPECT_TRUE(v1->did_paint_); | 1099 EXPECT_TRUE(v1->did_paint_); |
1070 EXPECT_FALSE(v2->did_paint_); | 1100 EXPECT_FALSE(v2->did_paint_); |
1071 } | 1101 } |
1072 | 1102 |
1073 TEST_F(ViewTest, PaintIntersectsOneChildInRTL) { | 1103 TEST_F(ViewTest, PaintIntersectsOneChildInRTL) { |
1074 ScopedRTL rtl; | 1104 ScopedRTL rtl; |
1075 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 1105 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
1076 View* root_view = widget->GetRootView(); | 1106 View* root_view = widget->GetRootView(); |
1077 | 1107 |
1078 TestView* v1 = new TestView; | 1108 TestView* v1 = new TestView; |
(...skipping 12 matching lines...) Expand all Loading... |
1091 | 1121 |
1092 v2->SetPaintToLayer(); | 1122 v2->SetPaintToLayer(); |
1093 // x: 25 - 3(x) - 6(width) = 16 | 1123 // x: 25 - 3(x) - 6(width) = 16 |
1094 EXPECT_EQ(gfx::Rect(16, 4, 6, 5), v2->layer()->bounds()); | 1124 EXPECT_EQ(gfx::Rect(16, 4, 6, 5), v2->layer()->bounds()); |
1095 v2->DestroyLayer(); | 1125 v2->DestroyLayer(); |
1096 | 1126 |
1097 // Paint everything once, since it has to build its cache. Then we can test | 1127 // Paint everything once, since it has to build its cache. Then we can test |
1098 // invalidation. | 1128 // invalidation. |
1099 gfx::Rect first_paint(1, 1); | 1129 gfx::Rect first_paint(1, 1); |
1100 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 1130 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
1101 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 1131 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, first_paint), |
| 1132 root_view->size())); |
1102 v1->Reset(); | 1133 v1->Reset(); |
1103 v2->Reset(); | 1134 v2->Reset(); |
1104 | 1135 |
1105 // Intersects with the first child only. | 1136 // Intersects with the first child only. |
1106 gfx::Rect paint_area(3, 10, 1, 2); | 1137 gfx::Rect paint_area(3, 10, 1, 2); |
1107 gfx::Rect root_area(root_view->size()); | 1138 gfx::Rect root_area(root_view->size()); |
1108 list = base::MakeRefCounted<cc::DisplayItemList>(); | 1139 list = base::MakeRefCounted<cc::DisplayItemList>(); |
1109 | 1140 |
1110 EXPECT_FALSE(v1->did_paint_); | 1141 EXPECT_FALSE(v1->did_paint_); |
1111 EXPECT_FALSE(v2->did_paint_); | 1142 EXPECT_FALSE(v2->did_paint_); |
1112 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 1143 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 1144 root_view->size())); |
1113 EXPECT_TRUE(v1->did_paint_); | 1145 EXPECT_TRUE(v1->did_paint_); |
1114 EXPECT_FALSE(v2->did_paint_); | 1146 EXPECT_FALSE(v2->did_paint_); |
1115 | 1147 |
1116 // Intersects with the second child only. | 1148 // Intersects with the second child only. |
1117 paint_area = gfx::Rect(21, 3, 1, 2); | 1149 paint_area = gfx::Rect(21, 3, 1, 2); |
1118 | 1150 |
1119 v1->Reset(); | 1151 v1->Reset(); |
1120 v2->Reset(); | 1152 v2->Reset(); |
1121 EXPECT_FALSE(v1->did_paint_); | 1153 EXPECT_FALSE(v1->did_paint_); |
1122 EXPECT_FALSE(v2->did_paint_); | 1154 EXPECT_FALSE(v2->did_paint_); |
1123 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 1155 root_view->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 1156 root_view->size())); |
1124 EXPECT_FALSE(v1->did_paint_); | 1157 EXPECT_FALSE(v1->did_paint_); |
1125 EXPECT_TRUE(v2->did_paint_); | 1158 EXPECT_TRUE(v2->did_paint_); |
1126 } | 1159 } |
1127 | 1160 |
1128 TEST_F(ViewTest, PaintInPromotedToLayer) { | 1161 TEST_F(ViewTest, PaintInPromotedToLayer) { |
1129 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); | 1162 ScopedTestPaintWidget widget(CreateParams(Widget::InitParams::TYPE_POPUP)); |
1130 View* root_view = widget->GetRootView(); | 1163 View* root_view = widget->GetRootView(); |
1131 | 1164 |
1132 TestView* v1 = new TestView; | 1165 TestView* v1 = new TestView; |
1133 v1->SetPaintToLayer(); | 1166 v1->SetPaintToLayer(); |
1134 v1->SetBounds(10, 11, 12, 13); | 1167 v1->SetBounds(10, 11, 12, 13); |
1135 root_view->AddChildView(v1); | 1168 root_view->AddChildView(v1); |
1136 | 1169 |
1137 TestView* v2 = new TestView; | 1170 TestView* v2 = new TestView; |
1138 v2->SetBounds(3, 4, 6, 5); | 1171 v2->SetBounds(3, 4, 6, 5); |
1139 v1->AddChildView(v2); | 1172 v1->AddChildView(v2); |
1140 | 1173 |
1141 // Paint everything once, since it has to build its cache. Then we can test | 1174 // Paint everything once, since it has to build its cache. Then we can test |
1142 // invalidation. | 1175 // invalidation. |
1143 gfx::Rect first_paint(1, 1); | 1176 gfx::Rect first_paint(1, 1); |
1144 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 1177 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
1145 v1->Paint(ui::PaintContext(list.get(), 1.f, first_paint)); | 1178 v1->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, first_paint), |
| 1179 v1->size())); |
1146 v1->Reset(); | 1180 v1->Reset(); |
1147 v2->Reset(); | 1181 v2->Reset(); |
1148 | 1182 |
1149 { | 1183 { |
1150 gfx::Rect paint_area(25, 26); | 1184 gfx::Rect paint_area(25, 26); |
1151 gfx::Rect view_area(root_view->size()); | 1185 gfx::Rect view_area(root_view->size()); |
1152 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 1186 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
1153 | 1187 |
1154 // The promoted views are not painted as they are separate paint roots. | 1188 // The promoted views are not painted as they are separate paint roots. |
1155 root_view->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 1189 root_view->Paint(ui::PaintInfo( |
| 1190 ui::PaintContext(list.get(), 1.f, paint_area), root_view->size())); |
1156 EXPECT_FALSE(v1->did_paint_); | 1191 EXPECT_FALSE(v1->did_paint_); |
1157 EXPECT_FALSE(v2->did_paint_); | 1192 EXPECT_FALSE(v2->did_paint_); |
1158 } | 1193 } |
1159 | 1194 |
1160 { | 1195 { |
1161 gfx::Rect paint_area(1, 1); | 1196 gfx::Rect paint_area(1, 1); |
1162 gfx::Rect view_area(v1->size()); | 1197 gfx::Rect view_area(v1->size()); |
1163 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 1198 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
1164 | 1199 |
1165 // The |v1| view is painted. If it used its offset incorrect, it would think | 1200 // The |v1| view is painted. If it used its offset incorrect, it would think |
1166 // its at (10,11) instead of at (0,0) since it is the paint root. | 1201 // its at (10,11) instead of at (0,0) since it is the paint root. |
1167 v1->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 1202 v1->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 1203 v1->size())); |
1168 EXPECT_TRUE(v1->did_paint_); | 1204 EXPECT_TRUE(v1->did_paint_); |
1169 EXPECT_FALSE(v2->did_paint_); | 1205 EXPECT_FALSE(v2->did_paint_); |
1170 } | 1206 } |
1171 | 1207 |
1172 v1->Reset(); | 1208 v1->Reset(); |
1173 | 1209 |
1174 { | 1210 { |
1175 gfx::Rect paint_area(3, 3, 1, 2); | 1211 gfx::Rect paint_area(3, 3, 1, 2); |
1176 gfx::Rect view_area(v1->size()); | 1212 gfx::Rect view_area(v1->size()); |
1177 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 1213 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
1178 | 1214 |
1179 // The |v2| view is painted also. If it used its offset incorrect, it would | 1215 // The |v2| view is painted also. If it used its offset incorrect, it would |
1180 // think its at (13,15) instead of at (3,4) since |v1| is the paint root. | 1216 // think its at (13,15) instead of at (3,4) since |v1| is the paint root. |
1181 v1->Paint(ui::PaintContext(list.get(), 1.f, paint_area)); | 1217 v1->Paint(ui::PaintInfo(ui::PaintContext(list.get(), 1.f, paint_area), |
| 1218 v1->size())); |
1182 EXPECT_TRUE(v1->did_paint_); | 1219 EXPECT_TRUE(v1->did_paint_); |
1183 EXPECT_TRUE(v2->did_paint_); | 1220 EXPECT_TRUE(v2->did_paint_); |
1184 } | 1221 } |
1185 } | 1222 } |
1186 | 1223 |
1187 // A derived class for testing paint. | 1224 // A derived class for testing paint. |
1188 class TestPaintView : public TestView { | 1225 class TestPaintView : public TestView { |
1189 public: | 1226 public: |
1190 TestPaintView() : TestView(), canvas_bounds_(gfx::Rect()) {} | 1227 TestPaintView() : TestView(), canvas_bounds_(gfx::Rect()) {} |
1191 ~TestPaintView() override {} | 1228 ~TestPaintView() override {} |
(...skipping 24 matching lines...) Expand all Loading... |
1216 // of it is visible. The visible bounds does not intersect with |root_view|'s | 1253 // of it is visible. The visible bounds does not intersect with |root_view|'s |
1217 // bounds. | 1254 // bounds. |
1218 v1->SetBounds(0, -1000, 100, 1100); | 1255 v1->SetBounds(0, -1000, 100, 1100); |
1219 root_view->AddChildView(v1); | 1256 root_view->AddChildView(v1); |
1220 EXPECT_EQ(gfx::Rect(0, 0, 100, 1100), v1->GetLocalBounds()); | 1257 EXPECT_EQ(gfx::Rect(0, 0, 100, 1100), v1->GetLocalBounds()); |
1221 EXPECT_EQ(gfx::Rect(0, 1000, 100, 100), v1->GetVisibleBounds()); | 1258 EXPECT_EQ(gfx::Rect(0, 1000, 100, 100), v1->GetVisibleBounds()); |
1222 | 1259 |
1223 auto list = base::MakeRefCounted<cc::DisplayItemList>(); | 1260 auto list = base::MakeRefCounted<cc::DisplayItemList>(); |
1224 ui::PaintContext context(list.get(), 1.f, gfx::Rect()); | 1261 ui::PaintContext context(list.get(), 1.f, gfx::Rect()); |
1225 | 1262 |
1226 v1->Paint(context); | 1263 v1->Paint(ui::PaintInfo(context, gfx::Size())); |
1227 EXPECT_TRUE(v1->did_paint_); | 1264 EXPECT_TRUE(v1->did_paint_); |
1228 | 1265 |
1229 // Check that the canvas produced by |v1| for paint contains all of |v1|'s | 1266 // Check that the canvas produced by |v1| for paint contains all of |v1|'s |
1230 // visible bounds. | 1267 // visible bounds. |
1231 EXPECT_TRUE(v1->canvas_bounds().Contains(v1->GetVisibleBounds())); | 1268 EXPECT_TRUE(v1->canvas_bounds().Contains(v1->GetVisibleBounds())); |
1232 } | 1269 } |
1233 | 1270 |
1234 void TestView::SchedulePaintInRect(const gfx::Rect& rect) { | 1271 void TestView::SchedulePaintInRect(const gfx::Rect& rect) { |
1235 scheduled_paint_rects_.push_back(rect); | 1272 scheduled_paint_rects_.push_back(rect); |
1236 View::SchedulePaintInRect(rect); | 1273 View::SchedulePaintInRect(rect); |
(...skipping 3744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4981 EXPECT_TRUE(parent_view->received_layer_change_notification()); | 5018 EXPECT_TRUE(parent_view->received_layer_change_notification()); |
4982 EXPECT_EQ(1, parent_view->layer_change_count()); | 5019 EXPECT_EQ(1, parent_view->layer_change_count()); |
4983 | 5020 |
4984 parent_view->Reset(); | 5021 parent_view->Reset(); |
4985 child_view->SetPaintToLayer(ui::LAYER_SOLID_COLOR); | 5022 child_view->SetPaintToLayer(ui::LAYER_SOLID_COLOR); |
4986 EXPECT_TRUE(parent_view->received_layer_change_notification()); | 5023 EXPECT_TRUE(parent_view->received_layer_change_notification()); |
4987 EXPECT_EQ(1, parent_view->layer_change_count()); | 5024 EXPECT_EQ(1, parent_view->layer_change_count()); |
4988 } | 5025 } |
4989 | 5026 |
4990 } // namespace views | 5027 } // namespace views |
OLD | NEW |