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