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 "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/views/test/test_views.h" | 8 #include "ui/views/test/test_views.h" |
9 #include "ui/views/view.h" | 9 #include "ui/views/view.h" |
10 | 10 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 host_->AddChildView(v1); | 48 host_->AddChildView(v1); |
49 View* v2 = new StaticSizedView(gfx::Size(10, 10)); | 49 View* v2 = new StaticSizedView(gfx::Size(10, 10)); |
50 host_->AddChildView(v2); | 50 host_->AddChildView(v2); |
51 EXPECT_EQ(gfx::Size(20, 20), layout_->GetPreferredSize(host_.get())); | 51 EXPECT_EQ(gfx::Size(20, 20), layout_->GetPreferredSize(host_.get())); |
52 host_->SetBounds(0, 0, 20, 20); | 52 host_->SetBounds(0, 0, 20, 20); |
53 layout_->Layout(host_.get()); | 53 layout_->Layout(host_.get()); |
54 EXPECT_EQ(gfx::Rect(0, 0, 20, 10), v1->bounds()); | 54 EXPECT_EQ(gfx::Rect(0, 0, 20, 10), v1->bounds()); |
55 EXPECT_EQ(gfx::Rect(0, 10, 20, 10), v2->bounds()); | 55 EXPECT_EQ(gfx::Rect(0, 10, 20, 10), v2->bounds()); |
56 } | 56 } |
57 | 57 |
| 58 TEST_F(BoxLayoutTest, SetInsideBorderInsets) { |
| 59 layout_.reset(new BoxLayout(BoxLayout::kHorizontal, 10, 20, 0)); |
| 60 View* v1 = new StaticSizedView(gfx::Size(10, 20)); |
| 61 host_->AddChildView(v1); |
| 62 View* v2 = new StaticSizedView(gfx::Size(10, 10)); |
| 63 host_->AddChildView(v2); |
| 64 EXPECT_EQ(gfx::Size(40, 60), layout_->GetPreferredSize(host_.get())); |
| 65 host_->SetBounds(0, 0, 40, 60); |
| 66 layout_->Layout(host_.get()); |
| 67 EXPECT_EQ(gfx::Rect(10, 20, 10, 20), v1->bounds()); |
| 68 EXPECT_EQ(gfx::Rect(20, 20, 10, 20), v2->bounds()); |
| 69 |
| 70 layout_->set_inside_border_insets( |
| 71 gfx::Insets(5, 10, 15, 20)); |
| 72 EXPECT_EQ(gfx::Size(50, 40), layout_->GetPreferredSize(host_.get())); |
| 73 host_->SetBounds(0, 0, 50, 40); |
| 74 layout_->Layout(host_.get()); |
| 75 EXPECT_EQ(gfx::Rect(10, 5, 10, 20), v1->bounds()); |
| 76 EXPECT_EQ(gfx::Rect(20, 5, 10, 20), v2->bounds()); |
| 77 } |
| 78 |
58 TEST_F(BoxLayoutTest, Spacing) { | 79 TEST_F(BoxLayoutTest, Spacing) { |
59 layout_.reset(new BoxLayout(BoxLayout::kHorizontal, 7, 7, 8)); | 80 layout_.reset(new BoxLayout(BoxLayout::kHorizontal, 7, 7, 8)); |
60 View* v1 = new StaticSizedView(gfx::Size(10, 20)); | 81 View* v1 = new StaticSizedView(gfx::Size(10, 20)); |
61 host_->AddChildView(v1); | 82 host_->AddChildView(v1); |
62 View* v2 = new StaticSizedView(gfx::Size(10, 20)); | 83 View* v2 = new StaticSizedView(gfx::Size(10, 20)); |
63 host_->AddChildView(v2); | 84 host_->AddChildView(v2); |
64 EXPECT_EQ(gfx::Size(42, 34), layout_->GetPreferredSize(host_.get())); | 85 EXPECT_EQ(gfx::Size(42, 34), layout_->GetPreferredSize(host_.get())); |
65 host_->SetBounds(0, 0, 100, 100); | 86 host_->SetBounds(0, 0, 100, 100); |
66 layout_->Layout(host_.get()); | 87 layout_->Layout(host_.get()); |
67 EXPECT_EQ(gfx::Rect(7, 7, 10, 86), v1->bounds()); | 88 EXPECT_EQ(gfx::Rect(7, 7, 10, 86), v1->bounds()); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 260 |
240 // Aligns children to the end of the host vertically, accounting for the | 261 // Aligns children to the end of the host vertically, accounting for the |
241 // inside border spacing. | 262 // inside border spacing. |
242 layout_->set_main_axis_alignment(BoxLayout::MAIN_AXIS_ALIGNMENT_END); | 263 layout_->set_main_axis_alignment(BoxLayout::MAIN_AXIS_ALIGNMENT_END); |
243 layout_->Layout(host_.get()); | 264 layout_->Layout(host_.get()); |
244 EXPECT_EQ(gfx::Rect(10, 50, 20, 20).ToString(), v1->bounds().ToString()); | 265 EXPECT_EQ(gfx::Rect(10, 50, 20, 20).ToString(), v1->bounds().ToString()); |
245 EXPECT_EQ(gfx::Rect(10, 80, 20, 10).ToString(), v2->bounds().ToString()); | 266 EXPECT_EQ(gfx::Rect(10, 80, 20, 10).ToString(), v2->bounds().ToString()); |
246 } | 267 } |
247 | 268 |
248 } // namespace views | 269 } // namespace views |
OLD | NEW |