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