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/layout/box_layout.h" | 5 #include "ui/views/layout/box_layout.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/views/test/test_views.h" | 10 #include "ui/views/test/test_views.h" |
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
622 TEST_F(BoxLayoutTest, MinimumCrossAxisHorizontal) { | 622 TEST_F(BoxLayoutTest, MinimumCrossAxisHorizontal) { |
623 BoxLayout* layout = new BoxLayout(BoxLayout::kHorizontal, 0, 0, 0); | 623 BoxLayout* layout = new BoxLayout(BoxLayout::kHorizontal, 0, 0, 0); |
624 host_->SetLayoutManager(layout); | 624 host_->SetLayoutManager(layout); |
625 View* v1 = new StaticSizedView(gfx::Size(20, 10)); | 625 View* v1 = new StaticSizedView(gfx::Size(20, 10)); |
626 host_->AddChildView(v1); | 626 host_->AddChildView(v1); |
627 layout->set_minimum_cross_axis_size(30); | 627 layout->set_minimum_cross_axis_size(30); |
628 | 628 |
629 EXPECT_EQ(gfx::Size(20, 30), layout->GetPreferredSize(host_.get())); | 629 EXPECT_EQ(gfx::Size(20, 30), layout->GetPreferredSize(host_.get())); |
630 } | 630 } |
631 | 631 |
| 632 TEST_F(BoxLayoutTest, MarginsUncollapsedHorizontal) { |
| 633 BoxLayout* layout = new BoxLayout(BoxLayout::kHorizontal, 0, 0, 0, false); |
| 634 host_->SetLayoutManager(layout); |
| 635 View* v1 = new StaticSizedView(gfx::Size(20, 10)); |
| 636 v1->SetProperty(kMarginsKey, new gfx::Insets(5, 5, 5, 5)); |
| 637 host_->AddChildView(v1); |
| 638 View* v2 = new StaticSizedView(gfx::Size(20, 10)); |
| 639 v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 6, 4)); |
| 640 host_->AddChildView(v2); |
| 641 |
| 642 EXPECT_EQ(gfx::Size(58, 22), layout->GetPreferredSize(host_.get())); |
| 643 host_->SizeToPreferredSize(); |
| 644 layout->Layout(host_.get()); |
| 645 EXPECT_EQ(gfx::Rect(5, 5, 20, 12), v1->bounds()); |
| 646 EXPECT_EQ(gfx::Rect(34, 6, 20, 10), v2->bounds()); |
| 647 } |
| 648 |
| 649 TEST_F(BoxLayoutTest, MarginsCollapsedHorizontal) { |
| 650 BoxLayout* layout = new BoxLayout(BoxLayout::kHorizontal, 0, 0, 0, true); |
| 651 host_->SetLayoutManager(layout); |
| 652 View* v1 = new StaticSizedView(gfx::Size(20, 10)); |
| 653 v1->SetProperty(kMarginsKey, new gfx::Insets(5, 5, 5, 5)); |
| 654 host_->AddChildView(v1); |
| 655 View* v2 = new StaticSizedView(gfx::Size(20, 10)); |
| 656 v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 6, 4)); |
| 657 host_->AddChildView(v2); |
| 658 |
| 659 EXPECT_EQ(gfx::Size(54, 22), layout->GetPreferredSize(host_.get())); |
| 660 host_->SizeToPreferredSize(); |
| 661 layout->Layout(host_.get()); |
| 662 EXPECT_EQ(gfx::Rect(5, 6, 20, 10), v1->bounds()); |
| 663 EXPECT_EQ(gfx::Rect(30, 6, 20, 10), v2->bounds()); |
| 664 } |
| 665 |
| 666 TEST_F(BoxLayoutTest, MarginsUncollapsedVertical) { |
| 667 BoxLayout* layout = new BoxLayout(BoxLayout::kVertical, 0, 0, 0, false); |
| 668 host_->SetLayoutManager(layout); |
| 669 View* v1 = new StaticSizedView(gfx::Size(20, 10)); |
| 670 v1->SetProperty(kMarginsKey, new gfx::Insets(5, 5, 5, 5)); |
| 671 host_->AddChildView(v1); |
| 672 View* v2 = new StaticSizedView(gfx::Size(20, 10)); |
| 673 v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 6, 4)); |
| 674 host_->AddChildView(v2); |
| 675 |
| 676 EXPECT_EQ(gfx::Size(30, 42), layout->GetPreferredSize(host_.get())); |
| 677 host_->SizeToPreferredSize(); |
| 678 layout->Layout(host_.get()); |
| 679 EXPECT_EQ(gfx::Rect(5, 5, 20, 10), v1->bounds()); |
| 680 EXPECT_EQ(gfx::Rect(4, 26, 22, 10), v2->bounds()); |
| 681 } |
| 682 |
| 683 TEST_F(BoxLayoutTest, MarginsCollapsedVertical) { |
| 684 BoxLayout* layout = new BoxLayout(BoxLayout::kVertical, 0, 0, 0, true); |
| 685 host_->SetLayoutManager(layout); |
| 686 View* v1 = new StaticSizedView(gfx::Size(20, 10)); |
| 687 v1->SetProperty(kMarginsKey, new gfx::Insets(5, 5, 5, 5)); |
| 688 host_->AddChildView(v1); |
| 689 View* v2 = new StaticSizedView(gfx::Size(20, 10)); |
| 690 v2->SetProperty(kMarginsKey, new gfx::Insets(6, 4, 6, 4)); |
| 691 host_->AddChildView(v2); |
| 692 |
| 693 EXPECT_EQ(gfx::Size(30, 37), layout->GetPreferredSize(host_.get())); |
| 694 host_->SizeToPreferredSize(); |
| 695 layout->Layout(host_.get()); |
| 696 EXPECT_EQ(gfx::Rect(5, 5, 20, 10), v1->bounds()); |
| 697 EXPECT_EQ(gfx::Rect(5, 21, 20, 10), v2->bounds()); |
| 698 } |
| 699 |
632 } // namespace views | 700 } // namespace views |
OLD | NEW |