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/view.h" | 8 #include "ui/views/view.h" |
9 | 9 |
10 namespace views { | 10 namespace views { |
11 | 11 |
12 namespace { | 12 namespace { |
13 | 13 |
14 class StaticSizedView : public View { | 14 class StaticSizedView : public View { |
15 public: | 15 public: |
16 explicit StaticSizedView(const gfx::Size& size) | 16 explicit StaticSizedView(const gfx::Size& size) |
17 : size_(size) { | 17 : size_(size) { |
18 } | 18 } |
19 virtual ~StaticSizedView() {} | |
19 | 20 |
20 virtual gfx::Size GetPreferredSize() OVERRIDE{ | 21 virtual gfx::Size GetPreferredSize() OVERRIDE { |
21 return size_; | 22 return size_; |
22 } | 23 } |
23 | 24 |
24 private: | 25 private: |
25 gfx::Size size_; | 26 gfx::Size size_; |
26 }; | 27 }; |
27 | 28 |
29 class ProportionallySizedView : public View { | |
30 public: | |
31 explicit ProportionallySizedView(int factor) : factor_(factor) {} | |
32 virtual ~ProportionallySizedView() {} | |
33 | |
34 virtual int GetHeightForWidth(int w) OVERRIDE { | |
35 return w * factor_; | |
36 } | |
37 | |
38 private: | |
39 // The multiplicative factor between width and height, i.e. | |
40 // height = width * factor_. | |
41 int factor_; | |
42 }; | |
sky
2013/03/13 14:03:03
DISALLOW_...
Evan Stade
2013/03/13 23:49:56
Done.
| |
43 | |
28 class BoxLayoutTest : public testing::Test { | 44 class BoxLayoutTest : public testing::Test { |
29 public: | 45 public: |
30 virtual void SetUp() OVERRIDE { | 46 virtual void SetUp() OVERRIDE { |
31 host_.reset(new View); | 47 host_.reset(new View); |
32 } | 48 } |
33 | 49 |
34 scoped_ptr<View> host_; | 50 scoped_ptr<View> host_; |
35 scoped_ptr<BoxLayout> layout_; | 51 scoped_ptr<BoxLayout> layout_; |
36 }; | 52 }; |
37 | 53 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 View* v2 = new StaticSizedView(gfx::Size(10, 10)); | 140 View* v2 = new StaticSizedView(gfx::Size(10, 10)); |
125 host_->AddChildView(v2); | 141 host_->AddChildView(v2); |
126 EXPECT_EQ(gfx::Size(60, 40), layout_->GetPreferredSize(host_.get())); | 142 EXPECT_EQ(gfx::Size(60, 40), layout_->GetPreferredSize(host_.get())); |
127 | 143 |
128 host_->SetBounds(0, 0, 100, 40); | 144 host_->SetBounds(0, 0, 100, 40); |
129 layout_->Layout(host_.get()); | 145 layout_->Layout(host_.get()); |
130 EXPECT_EQ(gfx::Rect(10, 10, 40, 20).ToString(), v1->bounds().ToString()); | 146 EXPECT_EQ(gfx::Rect(10, 10, 40, 20).ToString(), v1->bounds().ToString()); |
131 EXPECT_EQ(gfx::Rect(60, 10, 30, 20).ToString(), v2->bounds().ToString()); | 147 EXPECT_EQ(gfx::Rect(60, 10, 30, 20).ToString(), v2->bounds().ToString()); |
132 } | 148 } |
133 | 149 |
150 TEST_F(BoxLayoutTest, UseHeightForWidth) { | |
151 layout_.reset(new BoxLayout(BoxLayout::kVertical, 0, 0, 0)); | |
152 View* v1 = new StaticSizedView(gfx::Size(20, 10)); | |
153 host_->AddChildView(v1); | |
154 View* v2 = new ProportionallySizedView(2); | |
155 host_->AddChildView(v2); | |
156 EXPECT_EQ(gfx::Size(20, 50), layout_->GetPreferredSize(host_.get())); | |
157 | |
158 host_->SetBounds(0, 0, 20, 50); | |
159 layout_->Layout(host_.get()); | |
160 EXPECT_EQ(gfx::Rect(0, 0, 20, 10), v1->bounds()); | |
161 EXPECT_EQ(gfx::Rect(0, 10, 20, 40), v2->bounds()); | |
162 } | |
163 | |
134 } // namespace views | 164 } // namespace views |
OLD | NEW |