| 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 <map> | 5 #include <map> |
| 6 | 6 |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/rand_util.h" | 8 #include "base/rand_util.h" |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 12 #include "cc/playback/display_item_list.h" |
| 13 #include "cc/playback/display_item_list_settings.h" |
| 12 #include "ui/base/accelerators/accelerator.h" | 14 #include "ui/base/accelerators/accelerator.h" |
| 13 #include "ui/base/clipboard/clipboard.h" | 15 #include "ui/base/clipboard/clipboard.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/compositor/compositor.h" | 17 #include "ui/compositor/compositor.h" |
| 16 #include "ui/compositor/layer.h" | 18 #include "ui/compositor/layer.h" |
| 17 #include "ui/compositor/layer_animator.h" | 19 #include "ui/compositor/layer_animator.h" |
| 18 #include "ui/compositor/paint_context.h" | 20 #include "ui/compositor/paint_context.h" |
| 19 #include "ui/compositor/test/draw_waiter_for_test.h" | 21 #include "ui/compositor/test/draw_waiter_for_test.h" |
| 20 #include "ui/events/event.h" | 22 #include "ui/events/event.h" |
| 21 #include "ui/events/event_utils.h" | 23 #include "ui/events/event_utils.h" |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 438 root_view->SetBounds(0, 0, 25, 26); | 440 root_view->SetBounds(0, 0, 25, 26); |
| 439 | 441 |
| 440 TestView* v1 = new TestView; | 442 TestView* v1 = new TestView; |
| 441 v1->SetBounds(10, 11, 12, 13); | 443 v1->SetBounds(10, 11, 12, 13); |
| 442 root_view->AddChildView(v1); | 444 root_view->AddChildView(v1); |
| 443 | 445 |
| 444 TestView* v2 = new TestView; | 446 TestView* v2 = new TestView; |
| 445 v2->SetBounds(3, 4, 6, 5); | 447 v2->SetBounds(3, 4, 6, 5); |
| 446 v1->AddChildView(v2); | 448 v1->AddChildView(v2); |
| 447 | 449 |
| 448 gfx::Canvas canvas(root_view->size(), 1.f, true); | 450 // Paint everything once, since it has to build its cache. Then we can test |
| 451 // invalidation. |
| 452 gfx::Rect first_paint(1, 1); |
| 453 scoped_refptr<cc::DisplayItemList> list = |
| 454 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings()); |
| 455 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint)); |
| 456 v1->Reset(); |
| 457 v2->Reset(); |
| 458 |
| 449 gfx::Rect paint_area(1, 1); | 459 gfx::Rect paint_area(1, 1); |
| 460 gfx::Rect root_area(root_view->size()); |
| 461 list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings()); |
| 450 | 462 |
| 463 // With a known invalidation, v1 and v2 are not painted. |
| 451 EXPECT_FALSE(v1->did_paint_); | 464 EXPECT_FALSE(v1->did_paint_); |
| 452 EXPECT_FALSE(v2->did_paint_); | 465 EXPECT_FALSE(v2->did_paint_); |
| 453 root_view->Paint(ui::PaintContext(&canvas)); | 466 root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area)); |
| 454 EXPECT_TRUE(v1->did_paint_); | |
| 455 EXPECT_TRUE(v2->did_paint_); | |
| 456 | |
| 457 v1->Reset(); | |
| 458 v2->Reset(); | |
| 459 EXPECT_FALSE(v1->did_paint_); | 467 EXPECT_FALSE(v1->did_paint_); |
| 460 EXPECT_FALSE(v2->did_paint_); | 468 EXPECT_FALSE(v2->did_paint_); |
| 469 |
| 470 // With unknown invalidation, v1 and v2 are painted. |
| 461 root_view->Paint( | 471 root_view->Paint( |
| 462 ui::PaintContext(ui::PaintContext(&canvas, paint_area), | 472 ui::PaintContext(ui::PaintContext(list.get(), 1.f, root_area, paint_area), |
| 463 ui::PaintContext::CLONE_WITHOUT_INVALIDATION)); | 473 ui::PaintContext::CLONE_WITHOUT_INVALIDATION)); |
| 464 EXPECT_TRUE(v1->did_paint_); | 474 EXPECT_TRUE(v1->did_paint_); |
| 465 EXPECT_TRUE(v2->did_paint_); | 475 EXPECT_TRUE(v2->did_paint_); |
| 466 } | 476 } |
| 467 | 477 |
| 468 TEST_F(ViewTest, PaintContainsChildren) { | 478 TEST_F(ViewTest, PaintContainsChildren) { |
| 469 Widget* widget = new Widget; | 479 Widget* widget = new Widget; |
| 470 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 480 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 471 widget->Init(params); | 481 widget->Init(params); |
| 472 View* root_view = widget->GetRootView(); | 482 View* root_view = widget->GetRootView(); |
| 473 root_view->SetBounds(0, 0, 25, 26); | 483 root_view->SetBounds(0, 0, 25, 26); |
| 474 | 484 |
| 475 TestView* v1 = new TestView; | 485 TestView* v1 = new TestView; |
| 476 v1->SetBounds(10, 11, 12, 13); | 486 v1->SetBounds(10, 11, 12, 13); |
| 477 root_view->AddChildView(v1); | 487 root_view->AddChildView(v1); |
| 478 | 488 |
| 479 TestView* v2 = new TestView; | 489 TestView* v2 = new TestView; |
| 480 v2->SetBounds(3, 4, 6, 5); | 490 v2->SetBounds(3, 4, 6, 5); |
| 481 v1->AddChildView(v2); | 491 v1->AddChildView(v2); |
| 482 | 492 |
| 483 gfx::Canvas canvas(root_view->size(), 1.f, true); | 493 // Paint everything once, since it has to build its cache. Then we can test |
| 494 // invalidation. |
| 495 gfx::Rect first_paint(1, 1); |
| 496 scoped_refptr<cc::DisplayItemList> list = |
| 497 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings()); |
| 498 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint)); |
| 499 v1->Reset(); |
| 500 v2->Reset(); |
| 501 |
| 484 gfx::Rect paint_area(25, 26); | 502 gfx::Rect paint_area(25, 26); |
| 503 gfx::Rect root_area(root_view->size()); |
| 504 list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings()); |
| 485 | 505 |
| 486 EXPECT_FALSE(v1->did_paint_); | 506 EXPECT_FALSE(v1->did_paint_); |
| 487 EXPECT_FALSE(v2->did_paint_); | 507 EXPECT_FALSE(v2->did_paint_); |
| 488 root_view->Paint(ui::PaintContext(&canvas, paint_area)); | 508 root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area)); |
| 489 EXPECT_TRUE(v1->did_paint_); | 509 EXPECT_TRUE(v1->did_paint_); |
| 490 EXPECT_TRUE(v2->did_paint_); | 510 EXPECT_TRUE(v2->did_paint_); |
| 491 } | 511 } |
| 492 | 512 |
| 493 TEST_F(ViewTest, PaintContainsChildrenInRTL) { | 513 TEST_F(ViewTest, PaintContainsChildrenInRTL) { |
| 494 ScopedRTL rtl; | 514 ScopedRTL rtl; |
| 495 | 515 |
| 496 Widget* widget = new Widget; | 516 Widget* widget = new Widget; |
| 497 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 517 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 498 widget->Init(params); | 518 widget->Init(params); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 511 v1->SetPaintToLayer(true); | 531 v1->SetPaintToLayer(true); |
| 512 // x: 25 - 10(x) - 12(width) = 3 | 532 // x: 25 - 10(x) - 12(width) = 3 |
| 513 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); | 533 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); |
| 514 v1->SetPaintToLayer(false); | 534 v1->SetPaintToLayer(false); |
| 515 | 535 |
| 516 v2->SetPaintToLayer(true); | 536 v2->SetPaintToLayer(true); |
| 517 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 | 537 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 |
| 518 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); | 538 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); |
| 519 v2->SetPaintToLayer(false); | 539 v2->SetPaintToLayer(false); |
| 520 | 540 |
| 521 gfx::Canvas canvas(root_view->size(), 1.f, true); | 541 // Paint everything once, since it has to build its cache. Then we can test |
| 542 // invalidation. |
| 543 gfx::Rect first_paint(1, 1); |
| 544 scoped_refptr<cc::DisplayItemList> list = |
| 545 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings()); |
| 546 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint)); |
| 547 v1->Reset(); |
| 548 v2->Reset(); |
| 549 |
| 522 gfx::Rect paint_area(25, 26); | 550 gfx::Rect paint_area(25, 26); |
| 551 gfx::Rect root_area(root_view->size()); |
| 552 list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings()); |
| 523 | 553 |
| 524 EXPECT_FALSE(v1->did_paint_); | 554 EXPECT_FALSE(v1->did_paint_); |
| 525 EXPECT_FALSE(v2->did_paint_); | 555 EXPECT_FALSE(v2->did_paint_); |
| 526 root_view->Paint(ui::PaintContext(&canvas, paint_area)); | 556 root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area)); |
| 527 EXPECT_TRUE(v1->did_paint_); | 557 EXPECT_TRUE(v1->did_paint_); |
| 528 EXPECT_TRUE(v2->did_paint_); | 558 EXPECT_TRUE(v2->did_paint_); |
| 529 } | 559 } |
| 530 | 560 |
| 531 TEST_F(ViewTest, PaintIntersectsChildren) { | 561 TEST_F(ViewTest, PaintIntersectsChildren) { |
| 532 Widget* widget = new Widget; | 562 Widget* widget = new Widget; |
| 533 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 563 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 534 widget->Init(params); | 564 widget->Init(params); |
| 535 View* root_view = widget->GetRootView(); | 565 View* root_view = widget->GetRootView(); |
| 536 root_view->SetBounds(0, 0, 25, 26); | 566 root_view->SetBounds(0, 0, 25, 26); |
| 537 | 567 |
| 538 TestView* v1 = new TestView; | 568 TestView* v1 = new TestView; |
| 539 v1->SetBounds(10, 11, 12, 13); | 569 v1->SetBounds(10, 11, 12, 13); |
| 540 root_view->AddChildView(v1); | 570 root_view->AddChildView(v1); |
| 541 | 571 |
| 542 TestView* v2 = new TestView; | 572 TestView* v2 = new TestView; |
| 543 v2->SetBounds(3, 4, 6, 5); | 573 v2->SetBounds(3, 4, 6, 5); |
| 544 v1->AddChildView(v2); | 574 v1->AddChildView(v2); |
| 545 | 575 |
| 546 gfx::Canvas canvas(root_view->size(), 1.f, true); | 576 // Paint everything once, since it has to build its cache. Then we can test |
| 577 // invalidation. |
| 578 gfx::Rect first_paint(1, 1); |
| 579 scoped_refptr<cc::DisplayItemList> list = |
| 580 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings()); |
| 581 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint)); |
| 582 v1->Reset(); |
| 583 v2->Reset(); |
| 584 |
| 547 gfx::Rect paint_area(9, 10, 5, 6); | 585 gfx::Rect paint_area(9, 10, 5, 6); |
| 586 gfx::Rect root_area(root_view->size()); |
| 587 list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings()); |
| 548 | 588 |
| 549 EXPECT_FALSE(v1->did_paint_); | 589 EXPECT_FALSE(v1->did_paint_); |
| 550 EXPECT_FALSE(v2->did_paint_); | 590 EXPECT_FALSE(v2->did_paint_); |
| 551 root_view->Paint(ui::PaintContext(&canvas, paint_area)); | 591 root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area)); |
| 552 EXPECT_TRUE(v1->did_paint_); | 592 EXPECT_TRUE(v1->did_paint_); |
| 553 EXPECT_TRUE(v2->did_paint_); | 593 EXPECT_TRUE(v2->did_paint_); |
| 554 } | 594 } |
| 555 | 595 |
| 556 TEST_F(ViewTest, PaintIntersectsChildrenInRTL) { | 596 TEST_F(ViewTest, PaintIntersectsChildrenInRTL) { |
| 557 ScopedRTL rtl; | 597 ScopedRTL rtl; |
| 558 | 598 |
| 559 Widget* widget = new Widget; | 599 Widget* widget = new Widget; |
| 560 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 600 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 561 widget->Init(params); | 601 widget->Init(params); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 574 v1->SetPaintToLayer(true); | 614 v1->SetPaintToLayer(true); |
| 575 // x: 25 - 10(x) - 12(width) = 3 | 615 // x: 25 - 10(x) - 12(width) = 3 |
| 576 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); | 616 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); |
| 577 v1->SetPaintToLayer(false); | 617 v1->SetPaintToLayer(false); |
| 578 | 618 |
| 579 v2->SetPaintToLayer(true); | 619 v2->SetPaintToLayer(true); |
| 580 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 | 620 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 |
| 581 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); | 621 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); |
| 582 v2->SetPaintToLayer(false); | 622 v2->SetPaintToLayer(false); |
| 583 | 623 |
| 584 gfx::Canvas canvas(root_view->size(), 1.f, true); | 624 // Paint everything once, since it has to build its cache. Then we can test |
| 625 // invalidation. |
| 626 gfx::Rect first_paint(1, 1); |
| 627 scoped_refptr<cc::DisplayItemList> list = |
| 628 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings()); |
| 629 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint)); |
| 630 v1->Reset(); |
| 631 v2->Reset(); |
| 632 |
| 585 gfx::Rect paint_area(2, 10, 5, 6); | 633 gfx::Rect paint_area(2, 10, 5, 6); |
| 634 gfx::Rect root_area(root_view->size()); |
| 635 list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings()); |
| 586 | 636 |
| 587 EXPECT_FALSE(v1->did_paint_); | 637 EXPECT_FALSE(v1->did_paint_); |
| 588 EXPECT_FALSE(v2->did_paint_); | 638 EXPECT_FALSE(v2->did_paint_); |
| 589 root_view->Paint(ui::PaintContext(&canvas, paint_area)); | 639 root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area)); |
| 590 EXPECT_TRUE(v1->did_paint_); | 640 EXPECT_TRUE(v1->did_paint_); |
| 591 EXPECT_TRUE(v2->did_paint_); | 641 EXPECT_TRUE(v2->did_paint_); |
| 592 } | 642 } |
| 593 | 643 |
| 594 TEST_F(ViewTest, PaintIntersectsChildButNotGrandChild) { | 644 TEST_F(ViewTest, PaintIntersectsChildButNotGrandChild) { |
| 595 Widget* widget = new Widget; | 645 Widget* widget = new Widget; |
| 596 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 646 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 597 widget->Init(params); | 647 widget->Init(params); |
| 598 View* root_view = widget->GetRootView(); | 648 View* root_view = widget->GetRootView(); |
| 599 root_view->SetBounds(0, 0, 25, 26); | 649 root_view->SetBounds(0, 0, 25, 26); |
| 600 | 650 |
| 601 TestView* v1 = new TestView; | 651 TestView* v1 = new TestView; |
| 602 v1->SetBounds(10, 11, 12, 13); | 652 v1->SetBounds(10, 11, 12, 13); |
| 603 root_view->AddChildView(v1); | 653 root_view->AddChildView(v1); |
| 604 | 654 |
| 605 TestView* v2 = new TestView; | 655 TestView* v2 = new TestView; |
| 606 v2->SetBounds(3, 4, 6, 5); | 656 v2->SetBounds(3, 4, 6, 5); |
| 607 v1->AddChildView(v2); | 657 v1->AddChildView(v2); |
| 608 | 658 |
| 609 gfx::Canvas canvas(root_view->size(), 1.f, true); | 659 // Paint everything once, since it has to build its cache. Then we can test |
| 660 // invalidation. |
| 661 gfx::Rect first_paint(1, 1); |
| 662 scoped_refptr<cc::DisplayItemList> list = |
| 663 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings()); |
| 664 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint)); |
| 665 v1->Reset(); |
| 666 v2->Reset(); |
| 667 |
| 610 gfx::Rect paint_area(9, 10, 2, 3); | 668 gfx::Rect paint_area(9, 10, 2, 3); |
| 669 gfx::Rect root_area(root_view->size()); |
| 670 list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings()); |
| 611 | 671 |
| 612 EXPECT_FALSE(v1->did_paint_); | 672 EXPECT_FALSE(v1->did_paint_); |
| 613 EXPECT_FALSE(v2->did_paint_); | 673 EXPECT_FALSE(v2->did_paint_); |
| 614 root_view->Paint(ui::PaintContext(&canvas, paint_area)); | 674 root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area)); |
| 615 EXPECT_TRUE(v1->did_paint_); | 675 EXPECT_TRUE(v1->did_paint_); |
| 616 EXPECT_FALSE(v2->did_paint_); | 676 EXPECT_FALSE(v2->did_paint_); |
| 617 } | 677 } |
| 618 | 678 |
| 619 TEST_F(ViewTest, PaintIntersectsChildButNotGrandChildInRTL) { | 679 TEST_F(ViewTest, PaintIntersectsChildButNotGrandChildInRTL) { |
| 620 ScopedRTL rtl; | 680 ScopedRTL rtl; |
| 621 | 681 |
| 622 Widget* widget = new Widget; | 682 Widget* widget = new Widget; |
| 623 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 683 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 624 widget->Init(params); | 684 widget->Init(params); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 637 v1->SetPaintToLayer(true); | 697 v1->SetPaintToLayer(true); |
| 638 // x: 25 - 10(x) - 12(width) = 3 | 698 // x: 25 - 10(x) - 12(width) = 3 |
| 639 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); | 699 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); |
| 640 v1->SetPaintToLayer(false); | 700 v1->SetPaintToLayer(false); |
| 641 | 701 |
| 642 v2->SetPaintToLayer(true); | 702 v2->SetPaintToLayer(true); |
| 643 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 | 703 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 |
| 644 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); | 704 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); |
| 645 v2->SetPaintToLayer(false); | 705 v2->SetPaintToLayer(false); |
| 646 | 706 |
| 647 gfx::Canvas canvas(root_view->size(), 1.f, true); | 707 // Paint everything once, since it has to build its cache. Then we can test |
| 708 // invalidation. |
| 709 gfx::Rect first_paint(1, 1); |
| 710 scoped_refptr<cc::DisplayItemList> list = |
| 711 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings()); |
| 712 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint)); |
| 713 v1->Reset(); |
| 714 v2->Reset(); |
| 715 |
| 648 gfx::Rect paint_area(2, 10, 2, 3); | 716 gfx::Rect paint_area(2, 10, 2, 3); |
| 717 gfx::Rect root_area(root_view->size()); |
| 718 list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings()); |
| 649 | 719 |
| 650 EXPECT_FALSE(v1->did_paint_); | 720 EXPECT_FALSE(v1->did_paint_); |
| 651 EXPECT_FALSE(v2->did_paint_); | 721 EXPECT_FALSE(v2->did_paint_); |
| 652 root_view->Paint(ui::PaintContext(&canvas, paint_area)); | 722 root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area)); |
| 653 EXPECT_TRUE(v1->did_paint_); | 723 EXPECT_TRUE(v1->did_paint_); |
| 654 EXPECT_FALSE(v2->did_paint_); | 724 EXPECT_FALSE(v2->did_paint_); |
| 655 } | 725 } |
| 656 | 726 |
| 657 TEST_F(ViewTest, PaintIntersectsNoChildren) { | 727 TEST_F(ViewTest, PaintIntersectsNoChildren) { |
| 658 Widget* widget = new Widget; | 728 Widget* widget = new Widget; |
| 659 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 729 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 660 widget->Init(params); | 730 widget->Init(params); |
| 661 View* root_view = widget->GetRootView(); | 731 View* root_view = widget->GetRootView(); |
| 662 root_view->SetBounds(0, 0, 25, 26); | 732 root_view->SetBounds(0, 0, 25, 26); |
| 663 | 733 |
| 664 TestView* v1 = new TestView; | 734 TestView* v1 = new TestView; |
| 665 v1->SetBounds(10, 11, 12, 13); | 735 v1->SetBounds(10, 11, 12, 13); |
| 666 root_view->AddChildView(v1); | 736 root_view->AddChildView(v1); |
| 667 | 737 |
| 668 TestView* v2 = new TestView; | 738 TestView* v2 = new TestView; |
| 669 v2->SetBounds(3, 4, 6, 5); | 739 v2->SetBounds(3, 4, 6, 5); |
| 670 v1->AddChildView(v2); | 740 v1->AddChildView(v2); |
| 671 | 741 |
| 672 gfx::Canvas canvas(root_view->size(), 1.f, true); | 742 // Paint everything once, since it has to build its cache. Then we can test |
| 743 // invalidation. |
| 744 gfx::Rect first_paint(1, 1); |
| 745 scoped_refptr<cc::DisplayItemList> list = |
| 746 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings()); |
| 747 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint)); |
| 748 v1->Reset(); |
| 749 v2->Reset(); |
| 750 |
| 673 gfx::Rect paint_area(9, 10, 2, 1); | 751 gfx::Rect paint_area(9, 10, 2, 1); |
| 752 gfx::Rect root_area(root_view->size()); |
| 753 list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings()); |
| 674 | 754 |
| 675 EXPECT_FALSE(v1->did_paint_); | 755 EXPECT_FALSE(v1->did_paint_); |
| 676 EXPECT_FALSE(v2->did_paint_); | 756 EXPECT_FALSE(v2->did_paint_); |
| 677 root_view->Paint(ui::PaintContext(&canvas, paint_area)); | 757 root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area)); |
| 678 EXPECT_FALSE(v1->did_paint_); | 758 EXPECT_FALSE(v1->did_paint_); |
| 679 EXPECT_FALSE(v2->did_paint_); | 759 EXPECT_FALSE(v2->did_paint_); |
| 680 } | 760 } |
| 681 | 761 |
| 682 TEST_F(ViewTest, PaintIntersectsNoChildrenInRTL) { | 762 TEST_F(ViewTest, PaintIntersectsNoChildrenInRTL) { |
| 683 ScopedRTL rtl; | 763 ScopedRTL rtl; |
| 684 | 764 |
| 685 Widget* widget = new Widget; | 765 Widget* widget = new Widget; |
| 686 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 766 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 687 widget->Init(params); | 767 widget->Init(params); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 700 v1->SetPaintToLayer(true); | 780 v1->SetPaintToLayer(true); |
| 701 // x: 25 - 10(x) - 12(width) = 3 | 781 // x: 25 - 10(x) - 12(width) = 3 |
| 702 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); | 782 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); |
| 703 v1->SetPaintToLayer(false); | 783 v1->SetPaintToLayer(false); |
| 704 | 784 |
| 705 v2->SetPaintToLayer(true); | 785 v2->SetPaintToLayer(true); |
| 706 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 | 786 // x: 25 - 10(parent x) - 3(x) - 6(width) = 6 |
| 707 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); | 787 EXPECT_EQ(gfx::Rect(6, 15, 6, 5), v2->layer()->bounds()); |
| 708 v2->SetPaintToLayer(false); | 788 v2->SetPaintToLayer(false); |
| 709 | 789 |
| 710 gfx::Canvas canvas(root_view->size(), 1.f, true); | 790 // Paint everything once, since it has to build its cache. Then we can test |
| 791 // invalidation. |
| 792 gfx::Rect first_paint(1, 1); |
| 793 scoped_refptr<cc::DisplayItemList> list = |
| 794 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings()); |
| 795 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint)); |
| 796 v1->Reset(); |
| 797 v2->Reset(); |
| 798 |
| 711 gfx::Rect paint_area(2, 10, 2, 1); | 799 gfx::Rect paint_area(2, 10, 2, 1); |
| 800 gfx::Rect root_area(root_view->size()); |
| 801 list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings()); |
| 712 | 802 |
| 713 EXPECT_FALSE(v1->did_paint_); | 803 EXPECT_FALSE(v1->did_paint_); |
| 714 EXPECT_FALSE(v2->did_paint_); | 804 EXPECT_FALSE(v2->did_paint_); |
| 715 root_view->Paint(ui::PaintContext(&canvas, paint_area)); | 805 root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area)); |
| 716 EXPECT_FALSE(v1->did_paint_); | 806 EXPECT_FALSE(v1->did_paint_); |
| 717 EXPECT_FALSE(v2->did_paint_); | 807 EXPECT_FALSE(v2->did_paint_); |
| 718 } | 808 } |
| 719 | 809 |
| 720 TEST_F(ViewTest, PaintIntersectsOneChild) { | 810 TEST_F(ViewTest, PaintIntersectsOneChild) { |
| 721 Widget* widget = new Widget; | 811 Widget* widget = new Widget; |
| 722 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 812 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 723 widget->Init(params); | 813 widget->Init(params); |
| 724 View* root_view = widget->GetRootView(); | 814 View* root_view = widget->GetRootView(); |
| 725 root_view->SetBounds(0, 0, 25, 26); | 815 root_view->SetBounds(0, 0, 25, 26); |
| 726 | 816 |
| 727 TestView* v1 = new TestView; | 817 TestView* v1 = new TestView; |
| 728 v1->SetBounds(10, 11, 12, 13); | 818 v1->SetBounds(10, 11, 12, 13); |
| 729 root_view->AddChildView(v1); | 819 root_view->AddChildView(v1); |
| 730 | 820 |
| 731 TestView* v2 = new TestView; | 821 TestView* v2 = new TestView; |
| 732 v2->SetBounds(3, 4, 6, 5); | 822 v2->SetBounds(3, 4, 6, 5); |
| 733 root_view->AddChildView(v2); | 823 root_view->AddChildView(v2); |
| 734 | 824 |
| 735 gfx::Canvas canvas(root_view->size(), 1.f, true); | 825 // Paint everything once, since it has to build its cache. Then we can test |
| 826 // invalidation. |
| 827 gfx::Rect first_paint(1, 1); |
| 828 scoped_refptr<cc::DisplayItemList> list = |
| 829 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings()); |
| 830 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint)); |
| 831 v1->Reset(); |
| 832 v2->Reset(); |
| 833 |
| 736 // Intersects with the second child only. | 834 // Intersects with the second child only. |
| 737 gfx::Rect paint_area(3, 3, 1, 2); | 835 gfx::Rect paint_area(3, 3, 1, 2); |
| 836 gfx::Rect root_area(root_view->size()); |
| 837 list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings()); |
| 738 | 838 |
| 739 EXPECT_FALSE(v1->did_paint_); | 839 EXPECT_FALSE(v1->did_paint_); |
| 740 EXPECT_FALSE(v2->did_paint_); | 840 EXPECT_FALSE(v2->did_paint_); |
| 741 root_view->Paint(ui::PaintContext(&canvas, paint_area)); | 841 root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area)); |
| 742 EXPECT_FALSE(v1->did_paint_); | 842 EXPECT_FALSE(v1->did_paint_); |
| 743 EXPECT_TRUE(v2->did_paint_); | 843 EXPECT_TRUE(v2->did_paint_); |
| 744 | 844 |
| 745 // Intersects with the first child only. | 845 // Intersects with the first child only. |
| 746 paint_area = gfx::Rect(20, 10, 1, 2); | 846 paint_area = gfx::Rect(20, 10, 1, 2); |
| 747 | 847 |
| 748 v1->Reset(); | 848 v1->Reset(); |
| 749 v2->Reset(); | 849 v2->Reset(); |
| 750 EXPECT_FALSE(v1->did_paint_); | 850 EXPECT_FALSE(v1->did_paint_); |
| 751 EXPECT_FALSE(v2->did_paint_); | 851 EXPECT_FALSE(v2->did_paint_); |
| 752 root_view->Paint(ui::PaintContext(&canvas, paint_area)); | 852 root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area)); |
| 753 EXPECT_TRUE(v1->did_paint_); | 853 EXPECT_TRUE(v1->did_paint_); |
| 754 EXPECT_FALSE(v2->did_paint_); | 854 EXPECT_FALSE(v2->did_paint_); |
| 755 } | 855 } |
| 756 | 856 |
| 757 TEST_F(ViewTest, PaintIntersectsOneChildInRTL) { | 857 TEST_F(ViewTest, PaintIntersectsOneChildInRTL) { |
| 758 ScopedRTL rtl; | 858 ScopedRTL rtl; |
| 759 | 859 |
| 760 Widget* widget = new Widget; | 860 Widget* widget = new Widget; |
| 761 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 861 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 762 widget->Init(params); | 862 widget->Init(params); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 775 v1->SetPaintToLayer(true); | 875 v1->SetPaintToLayer(true); |
| 776 // x: 25 - 10(x) - 12(width) = 3 | 876 // x: 25 - 10(x) - 12(width) = 3 |
| 777 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); | 877 EXPECT_EQ(gfx::Rect(3, 11, 12, 13), v1->layer()->bounds()); |
| 778 v1->SetPaintToLayer(false); | 878 v1->SetPaintToLayer(false); |
| 779 | 879 |
| 780 v2->SetPaintToLayer(true); | 880 v2->SetPaintToLayer(true); |
| 781 // x: 25 - 3(x) - 6(width) = 16 | 881 // x: 25 - 3(x) - 6(width) = 16 |
| 782 EXPECT_EQ(gfx::Rect(16, 4, 6, 5), v2->layer()->bounds()); | 882 EXPECT_EQ(gfx::Rect(16, 4, 6, 5), v2->layer()->bounds()); |
| 783 v2->SetPaintToLayer(false); | 883 v2->SetPaintToLayer(false); |
| 784 | 884 |
| 785 gfx::Canvas canvas(root_view->size(), 1.f, true); | 885 // Paint everything once, since it has to build its cache. Then we can test |
| 886 // invalidation. |
| 887 gfx::Rect first_paint(1, 1); |
| 888 scoped_refptr<cc::DisplayItemList> list = |
| 889 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings()); |
| 890 root_view->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint)); |
| 891 v1->Reset(); |
| 892 v2->Reset(); |
| 893 |
| 786 // Intersects with the first child only. | 894 // Intersects with the first child only. |
| 787 gfx::Rect paint_area(3, 10, 1, 2); | 895 gfx::Rect paint_area(3, 10, 1, 2); |
| 896 gfx::Rect root_area(root_view->size()); |
| 897 list = cc::DisplayItemList::Create(root_area, cc::DisplayItemListSettings()); |
| 788 | 898 |
| 789 EXPECT_FALSE(v1->did_paint_); | 899 EXPECT_FALSE(v1->did_paint_); |
| 790 EXPECT_FALSE(v2->did_paint_); | 900 EXPECT_FALSE(v2->did_paint_); |
| 791 root_view->Paint(ui::PaintContext(&canvas, paint_area)); | 901 root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area)); |
| 792 EXPECT_TRUE(v1->did_paint_); | 902 EXPECT_TRUE(v1->did_paint_); |
| 793 EXPECT_FALSE(v2->did_paint_); | 903 EXPECT_FALSE(v2->did_paint_); |
| 794 | 904 |
| 795 // Intersects with the second child only. | 905 // Intersects with the second child only. |
| 796 paint_area = gfx::Rect(21, 3, 1, 2); | 906 paint_area = gfx::Rect(21, 3, 1, 2); |
| 797 | 907 |
| 798 v1->Reset(); | 908 v1->Reset(); |
| 799 v2->Reset(); | 909 v2->Reset(); |
| 800 EXPECT_FALSE(v1->did_paint_); | 910 EXPECT_FALSE(v1->did_paint_); |
| 801 EXPECT_FALSE(v2->did_paint_); | 911 EXPECT_FALSE(v2->did_paint_); |
| 802 root_view->Paint(ui::PaintContext(&canvas, paint_area)); | 912 root_view->Paint(ui::PaintContext(list.get(), 1.f, root_area, paint_area)); |
| 803 EXPECT_FALSE(v1->did_paint_); | 913 EXPECT_FALSE(v1->did_paint_); |
| 804 EXPECT_TRUE(v2->did_paint_); | 914 EXPECT_TRUE(v2->did_paint_); |
| 805 } | 915 } |
| 806 | 916 |
| 807 TEST_F(ViewTest, PaintInPromotedToLayer) { | 917 TEST_F(ViewTest, PaintInPromotedToLayer) { |
| 808 Widget* widget = new Widget; | 918 Widget* widget = new Widget; |
| 809 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 919 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 810 widget->Init(params); | 920 widget->Init(params); |
| 811 View* root_view = widget->GetRootView(); | 921 View* root_view = widget->GetRootView(); |
| 812 root_view->SetBounds(0, 0, 25, 26); | 922 root_view->SetBounds(0, 0, 25, 26); |
| 813 | 923 |
| 814 TestView* v1 = new TestView; | 924 TestView* v1 = new TestView; |
| 815 v1->SetPaintToLayer(true); | 925 v1->SetPaintToLayer(true); |
| 816 v1->SetBounds(10, 11, 12, 13); | 926 v1->SetBounds(10, 11, 12, 13); |
| 817 root_view->AddChildView(v1); | 927 root_view->AddChildView(v1); |
| 818 | 928 |
| 819 TestView* v2 = new TestView; | 929 TestView* v2 = new TestView; |
| 820 v2->SetBounds(3, 4, 6, 5); | 930 v2->SetBounds(3, 4, 6, 5); |
| 821 v1->AddChildView(v2); | 931 v1->AddChildView(v2); |
| 822 | 932 |
| 823 EXPECT_FALSE(v1->did_paint_); | 933 // Paint everything once, since it has to build its cache. Then we can test |
| 824 EXPECT_FALSE(v2->did_paint_); | 934 // invalidation. |
| 935 gfx::Rect first_paint(1, 1); |
| 936 scoped_refptr<cc::DisplayItemList> list = |
| 937 cc::DisplayItemList::Create(first_paint, cc::DisplayItemListSettings()); |
| 938 v1->Paint(ui::PaintContext(list.get(), 1.f, first_paint, first_paint)); |
| 939 v1->Reset(); |
| 940 v2->Reset(); |
| 825 | 941 |
| 826 { | 942 { |
| 827 gfx::Canvas canvas(root_view->size(), 1.f, true); | |
| 828 gfx::Rect paint_area(25, 26); | 943 gfx::Rect paint_area(25, 26); |
| 944 gfx::Rect view_area(root_view->size()); |
| 945 scoped_refptr<cc::DisplayItemList> list = |
| 946 cc::DisplayItemList::Create(view_area, cc::DisplayItemListSettings()); |
| 829 | 947 |
| 830 // The promoted views are not painted as they are separate paint roots. | 948 // The promoted views are not painted as they are separate paint roots. |
| 831 root_view->Paint(ui::PaintContext(&canvas, paint_area)); | 949 root_view->Paint(ui::PaintContext(list.get(), 1.f, view_area, paint_area)); |
| 832 EXPECT_FALSE(v1->did_paint_); | 950 EXPECT_FALSE(v1->did_paint_); |
| 833 EXPECT_FALSE(v2->did_paint_); | 951 EXPECT_FALSE(v2->did_paint_); |
| 834 } | 952 } |
| 835 | 953 |
| 836 { | 954 { |
| 837 gfx::Canvas canvas(v1->size(), 1.f, true); | |
| 838 gfx::Rect paint_area(1, 1); | 955 gfx::Rect paint_area(1, 1); |
| 956 gfx::Rect view_area(v1->size()); |
| 957 scoped_refptr<cc::DisplayItemList> list = |
| 958 cc::DisplayItemList::Create(view_area, cc::DisplayItemListSettings()); |
| 839 | 959 |
| 840 // The |v1| view is painted. If it used its offset incorrect, it would think | 960 // The |v1| view is painted. If it used its offset incorrect, it would think |
| 841 // its at (10,11) instead of at (0,0) since it is the paint root. | 961 // its at (10,11) instead of at (0,0) since it is the paint root. |
| 842 v1->Paint(ui::PaintContext(&canvas, paint_area)); | 962 v1->Paint(ui::PaintContext(list.get(), 1.f, view_area, paint_area)); |
| 843 EXPECT_TRUE(v1->did_paint_); | 963 EXPECT_TRUE(v1->did_paint_); |
| 844 EXPECT_FALSE(v2->did_paint_); | 964 EXPECT_FALSE(v2->did_paint_); |
| 845 } | 965 } |
| 846 | 966 |
| 847 v1->Reset(); | 967 v1->Reset(); |
| 848 | 968 |
| 849 { | 969 { |
| 850 gfx::Canvas canvas(v1->size(), 1.f, true); | |
| 851 gfx::Rect paint_area(3, 3, 1, 2); | 970 gfx::Rect paint_area(3, 3, 1, 2); |
| 971 gfx::Rect view_area(v1->size()); |
| 972 scoped_refptr<cc::DisplayItemList> list = |
| 973 cc::DisplayItemList::Create(view_area, cc::DisplayItemListSettings()); |
| 852 | 974 |
| 853 // The |v2| view is painted also. If it used its offset incorrect, it would | 975 // The |v2| view is painted also. If it used its offset incorrect, it would |
| 854 // think its at (13,15) instead of at (3,4) since |v1| is the paint root. | 976 // think its at (13,15) instead of at (3,4) since |v1| is the paint root. |
| 855 v1->Paint(ui::PaintContext(&canvas, paint_area)); | 977 v1->Paint(ui::PaintContext(list.get(), 1.f, view_area, paint_area)); |
| 856 EXPECT_TRUE(v1->did_paint_); | 978 EXPECT_TRUE(v1->did_paint_); |
| 857 EXPECT_TRUE(v2->did_paint_); | 979 EXPECT_TRUE(v2->did_paint_); |
| 858 } | 980 } |
| 859 } | 981 } |
| 860 | 982 |
| 861 void TestView::SchedulePaintInRect(const gfx::Rect& rect) { | 983 void TestView::SchedulePaintInRect(const gfx::Rect& rect) { |
| 862 scheduled_paint_rects_.push_back(rect); | 984 scheduled_paint_rects_.push_back(rect); |
| 863 View::SchedulePaintInRect(rect); | 985 View::SchedulePaintInRect(rect); |
| 864 } | 986 } |
| 865 | 987 |
| (...skipping 3032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3898 // notification. | 4020 // notification. |
| 3899 TestView* test_view_child_2 = new TestView(); | 4021 TestView* test_view_child_2 = new TestView(); |
| 3900 test_view->AddChildView(test_view_child_2); | 4022 test_view->AddChildView(test_view_child_2); |
| 3901 EXPECT_TRUE(test_view_child_2->native_theme_); | 4023 EXPECT_TRUE(test_view_child_2->native_theme_); |
| 3902 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); | 4024 EXPECT_EQ(widget->GetNativeTheme(), test_view_child_2->native_theme_); |
| 3903 | 4025 |
| 3904 widget->CloseNow(); | 4026 widget->CloseNow(); |
| 3905 } | 4027 } |
| 3906 | 4028 |
| 3907 } // namespace views | 4029 } // namespace views |
| OLD | NEW |