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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 #include "ui/views/align_attribute.h" | 8 #include "ui/views/align_attribute.h" |
9 #include "ui/views/anchor_attribute.h" | 9 #include "ui/views/anchor_attribute.h" |
10 #include "ui/views/layout/align_layout.h" | 10 #include "ui/views/layout/align_layout_state.h" |
11 #include "ui/views/test/test_views.h" | 11 #include "ui/views/test/test_views.h" |
12 #include "ui/views/view.h" | 12 #include "ui/views/view.h" |
13 | 13 |
14 namespace views { | 14 namespace views { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 class AnchorLayoutTest : public testing::Test { | 18 class AnchorLayoutStateTest : public testing::Test { |
19 public: | 19 public: |
20 void SetUp() override { | 20 void SetUp() override { |
21 host_.reset(new View); | 21 host_.reset(new View); |
22 host_->SetBounds(0, 0, 100, 100); | 22 host_->SetBounds(0, 0, 100, 100); |
23 } | 23 } |
24 | 24 |
25 std::unique_ptr<View> host_; | 25 std::unique_ptr<View> host_; |
26 }; | 26 }; |
27 | 27 |
28 } // namespace | 28 } // namespace |
29 | 29 |
30 TEST_F(AnchorLayoutTest, Empty) { | 30 TEST_F(AnchorLayoutStateTest, Empty) { |
31 AlignLayout* layout = new AlignLayout(); | 31 AlignLayoutState* layout = new AlignLayoutState(); |
32 host_->SetLayoutManager(layout); | 32 host_->SetLayoutManager(layout); |
33 EXPECT_EQ(gfx::Size(0, 0), layout->GetPreferredSize(host_.get())); | 33 EXPECT_EQ(gfx::Size(0, 0), layout->GetPreferredSize(host_.get())); |
34 } | 34 } |
35 | 35 |
36 TEST_F(AnchorLayoutTest, AnchorLeftTop) { | 36 TEST_F(AnchorLayoutStateTest, AnchorLeftTop) { |
37 AlignLayout* layout = new AlignLayout(); | 37 AlignLayoutState* layout = new AlignLayoutState(); |
38 host_->SetLayoutManager(layout); | 38 host_->SetLayoutManager(layout); |
39 View* v1 = new View(); | 39 View* v1 = new View(); |
40 v1->attributes().Add( | 40 layout->AnchorView(v1, {Anchor::Left, Anchor::Top}); |
41 base::WrapUnique(new AnchorAttribute({Anchor::Left, Anchor::Top}))); | |
42 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); | 41 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); |
43 v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10); | 42 layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10); |
44 host_->AddChildView(v1); | 43 host_->AddChildView(v1); |
45 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 44 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
46 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 45 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
47 host_->SetBounds(0, 0, 120, 120); | 46 host_->SetBounds(0, 0, 120, 120); |
48 host_->Layout(); | 47 host_->Layout(); |
49 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 48 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
50 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 49 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
51 } | 50 } |
52 | 51 |
53 TEST_F(AnchorLayoutTest, AnchorTop) { | 52 TEST_F(AnchorLayoutStateTest, AnchorTop) { |
54 AlignLayout* layout = new AlignLayout(); | 53 AlignLayoutState* layout = new AlignLayoutState(); |
55 host_->SetLayoutManager(layout); | 54 host_->SetLayoutManager(layout); |
56 View* v1 = new View(); | 55 View* v1 = new View(); |
57 v1->attributes().Add(base::WrapUnique(new AnchorAttribute({Anchor::Top}))); | 56 layout->AnchorView(v1, {Anchor::Top}); |
58 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); | 57 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); |
59 v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10); | 58 layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10); |
60 host_->AddChildView(v1); | 59 host_->AddChildView(v1); |
61 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 60 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
62 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 61 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
63 host_->SetBounds(0, 0, 120, 120); | 62 host_->SetBounds(0, 0, 120, 120); |
64 host_->Layout(); | 63 host_->Layout(); |
65 EXPECT_EQ(gfx::Rect(v1pos.x() + 10, v1pos.y(), 10, 10), v1->bounds()); | 64 EXPECT_EQ(gfx::Rect(v1pos.x() + 10, v1pos.y(), 10, 10), v1->bounds()); |
66 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 65 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
67 } | 66 } |
68 | 67 |
69 TEST_F(AnchorLayoutTest, AnchorLeft) { | 68 TEST_F(AnchorLayoutStateTest, AnchorLeft) { |
70 AlignLayout* layout = new AlignLayout(); | 69 AlignLayoutState* layout = new AlignLayoutState(); |
71 host_->SetLayoutManager(layout); | 70 host_->SetLayoutManager(layout); |
72 View* v1 = new View(); | 71 View* v1 = new View(); |
73 v1->attributes().Add(base::WrapUnique(new AnchorAttribute({Anchor::Left}))); | 72 layout->AnchorView(v1, {Anchor::Left}); |
74 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); | 73 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); |
75 v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10); | 74 layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10); |
76 host_->AddChildView(v1); | 75 host_->AddChildView(v1); |
77 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 76 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
78 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 77 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
79 host_->SetBounds(0, 0, 120, 120); | 78 host_->SetBounds(0, 0, 120, 120); |
80 host_->Layout(); | 79 host_->Layout(); |
81 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y() + 10, 10, 10), v1->bounds()); | 80 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y() + 10, 10, 10), v1->bounds()); |
82 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 81 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
83 } | 82 } |
84 | 83 |
85 TEST_F(AnchorLayoutTest, AnchorRightTop) { | 84 TEST_F(AnchorLayoutStateTest, AnchorRightTop) { |
86 AlignLayout* layout = new AlignLayout(); | 85 AlignLayoutState* layout = new AlignLayoutState(); |
87 host_->SetLayoutManager(layout); | 86 host_->SetLayoutManager(layout); |
88 View* v1 = new View(); | 87 View* v1 = new View(); |
89 v1->attributes().Add( | 88 layout->AnchorView(v1, {Anchor::Right, Anchor::Top}); |
90 base::WrapUnique(new AnchorAttribute({Anchor::Right, Anchor::Top}))); | |
91 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); | 89 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); |
92 v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10); | 90 layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10); |
93 host_->AddChildView(v1); | 91 host_->AddChildView(v1); |
94 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 92 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
95 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 93 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
96 host_->SetBounds(0, 0, 120, 120); | 94 host_->SetBounds(0, 0, 120, 120); |
97 host_->Layout(); | 95 host_->Layout(); |
98 EXPECT_EQ(gfx::Rect(v1pos.x() + 20, v1pos.y(), 10, 10), v1->bounds()); | 96 EXPECT_EQ(gfx::Rect(v1pos.x() + 20, v1pos.y(), 10, 10), v1->bounds()); |
99 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 97 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
100 } | 98 } |
101 | 99 |
102 TEST_F(AnchorLayoutTest, AnchorLeftTopRight) { | 100 TEST_F(AnchorLayoutStateTest, AnchorLeftTopRight) { |
103 AlignLayout* layout = new AlignLayout(); | 101 AlignLayoutState* layout = new AlignLayoutState(); |
104 host_->SetLayoutManager(layout); | 102 host_->SetLayoutManager(layout); |
105 View* v1 = new View(); | 103 View* v1 = new View(); |
106 v1->attributes().Add(base::WrapUnique( | 104 layout->AnchorView(v1, {Anchor::Left, Anchor::Top, Anchor::Right}); |
107 new AnchorAttribute({Anchor::Left, Anchor::Top, Anchor::Right}))); | |
108 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); | 105 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); |
109 v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10); | 106 layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10); |
110 host_->AddChildView(v1); | 107 host_->AddChildView(v1); |
111 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 108 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
112 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 109 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
113 host_->SetBounds(0, 0, 120, 120); | 110 host_->SetBounds(0, 0, 120, 120); |
114 host_->Layout(); | 111 host_->Layout(); |
115 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 30, 10), v1->bounds()); | 112 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 30, 10), v1->bounds()); |
116 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 113 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
117 } | 114 } |
118 | 115 |
119 TEST_F(AnchorLayoutTest, AnchorLeftTopBottom) { | 116 TEST_F(AnchorLayoutStateTest, AnchorLeftTopBottom) { |
120 AlignLayout* layout = new AlignLayout(); | 117 AlignLayoutState* layout = new AlignLayoutState(); |
121 host_->SetLayoutManager(layout); | 118 host_->SetLayoutManager(layout); |
122 View* v1 = new View(); | 119 View* v1 = new View(); |
123 v1->attributes().Add(base::WrapUnique( | 120 layout->AnchorView(v1, {Anchor::Left, Anchor::Top, Anchor::Bottom}); |
124 new AnchorAttribute({Anchor::Left, Anchor::Top, Anchor::Bottom}))); | |
125 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); | 121 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); |
126 v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10); | 122 layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10); |
127 host_->AddChildView(v1); | 123 host_->AddChildView(v1); |
128 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 124 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
129 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 125 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
130 host_->SetBounds(0, 0, 120, 120); | 126 host_->SetBounds(0, 0, 120, 120); |
131 host_->Layout(); | 127 host_->Layout(); |
132 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 30), v1->bounds()); | 128 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 30), v1->bounds()); |
133 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 129 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
134 } | 130 } |
135 | 131 |
136 TEST_F(AnchorLayoutTest, AnchorLeftRight) { | 132 TEST_F(AnchorLayoutStateTest, AnchorLeftRight) { |
137 AlignLayout* layout = new AlignLayout(); | 133 AlignLayoutState* layout = new AlignLayoutState(); |
138 host_->SetLayoutManager(layout); | 134 host_->SetLayoutManager(layout); |
139 View* v1 = new View(); | 135 View* v1 = new View(); |
140 v1->attributes().Add(base::WrapUnique( | 136 layout->AnchorView(v1, {Anchor::Left, Anchor::Right}); |
141 new AnchorAttribute({Anchor::Left, Anchor::Right}))); | |
142 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); | 137 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); |
143 v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10); | 138 layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10); |
144 host_->AddChildView(v1); | 139 host_->AddChildView(v1); |
145 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 140 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
146 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 141 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
147 host_->SetBounds(0, 0, 120, 120); | 142 host_->SetBounds(0, 0, 120, 120); |
148 host_->Layout(); | 143 host_->Layout(); |
149 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y() + 10, 30, 10), v1->bounds()); | 144 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y() + 10, 30, 10), v1->bounds()); |
150 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 145 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
151 } | 146 } |
152 | 147 |
153 TEST_F(AnchorLayoutTest, AnchorTopBottom) { | 148 TEST_F(AnchorLayoutStateTest, AnchorTopBottom) { |
154 AlignLayout* layout = new AlignLayout(); | 149 AlignLayoutState* layout = new AlignLayoutState(); |
155 host_->SetLayoutManager(layout); | 150 host_->SetLayoutManager(layout); |
156 View* v1 = new View(); | 151 View* v1 = new View(); |
157 v1->attributes().Add(base::WrapUnique( | 152 layout->AnchorView(v1, {Anchor::Top, Anchor::Bottom}); |
158 new AnchorAttribute({Anchor::Top, Anchor::Bottom}))); | |
159 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); | 153 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); |
160 v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10); | 154 layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10); |
161 host_->AddChildView(v1); | 155 host_->AddChildView(v1); |
162 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 156 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
163 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 157 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
164 host_->SetBounds(0, 0, 120, 120); | 158 host_->SetBounds(0, 0, 120, 120); |
165 host_->Layout(); | 159 host_->Layout(); |
166 EXPECT_EQ(gfx::Rect(v1pos.x() + 10, v1pos.y(), 10, 30), v1->bounds()); | 160 EXPECT_EQ(gfx::Rect(v1pos.x() + 10, v1pos.y(), 10, 30), v1->bounds()); |
167 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 161 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
168 } | 162 } |
169 | 163 |
170 TEST_F(AnchorLayoutTest, AnchorNone) { | 164 TEST_F(AnchorLayoutStateTest, AnchorNone) { |
171 AlignLayout* layout = new AlignLayout(); | 165 AlignLayoutState* layout = new AlignLayoutState(); |
172 host_->SetLayoutManager(layout); | 166 host_->SetLayoutManager(layout); |
173 View* v1 = new View(); | 167 View* v1 = new View(); |
174 v1->attributes().Add(base::WrapUnique(new AnchorAttribute(Anchors()))); | 168 layout->AnchorView(v1, Anchors()); |
175 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); | 169 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); |
176 v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10); | 170 layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10); |
177 host_->AddChildView(v1); | 171 host_->AddChildView(v1); |
178 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 172 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
179 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 173 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
180 host_->SetBounds(0, 0, 120, 120); | 174 host_->SetBounds(0, 0, 120, 120); |
181 host_->Layout(); | 175 host_->Layout(); |
182 EXPECT_EQ(gfx::Rect(v1pos.x() + 10, v1pos.y() + 10, 10, 10), v1->bounds()); | 176 EXPECT_EQ(gfx::Rect(v1pos.x() + 10, v1pos.y() + 10, 10, 10), v1->bounds()); |
183 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 177 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
184 } | 178 } |
185 | 179 |
186 TEST_F(AnchorLayoutTest, AnchorRightBottom) { | 180 TEST_F(AnchorLayoutStateTest, AnchorRightBottom) { |
187 AlignLayout* layout = new AlignLayout(); | 181 AlignLayoutState* layout = new AlignLayoutState(); |
188 host_->SetLayoutManager(layout); | 182 host_->SetLayoutManager(layout); |
189 View* v1 = new View(); | 183 View* v1 = new View(); |
190 v1->attributes().Add(base::WrapUnique( | 184 layout->AnchorView(v1, {Anchor::Right, Anchor::Bottom}); |
191 new AnchorAttribute({Anchor::Right, Anchor::Bottom}))); | |
192 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); | 185 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); |
193 v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10); | 186 layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10); |
194 host_->AddChildView(v1); | 187 host_->AddChildView(v1); |
195 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 188 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
196 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 189 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
197 host_->SetBounds(0, 0, 120, 120); | 190 host_->SetBounds(0, 0, 120, 120); |
198 host_->Layout(); | 191 host_->Layout(); |
199 EXPECT_EQ(gfx::Rect(v1pos.x() + 20, v1pos.y() + 20, 10, 10), v1->bounds()); | 192 EXPECT_EQ(gfx::Rect(v1pos.x() + 20, v1pos.y() + 20, 10, 10), v1->bounds()); |
200 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 193 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
201 } | 194 } |
202 | 195 |
203 TEST_F(AnchorLayoutTest, AnchorRight) { | 196 TEST_F(AnchorLayoutStateTest, AnchorRight) { |
204 AlignLayout* layout = new AlignLayout(); | 197 AlignLayoutState* layout = new AlignLayoutState(); |
205 host_->SetLayoutManager(layout); | 198 host_->SetLayoutManager(layout); |
206 View* v1 = new View(); | 199 View* v1 = new View(); |
207 v1->attributes().Add(base::WrapUnique(new AnchorAttribute({Anchor::Right}))); | 200 layout->AnchorView(v1, {Anchor::Right}); |
208 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); | 201 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); |
209 v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10); | 202 layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10); |
210 host_->AddChildView(v1); | 203 host_->AddChildView(v1); |
211 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 204 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
212 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 205 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
213 host_->SetBounds(0, 0, 120, 120); | 206 host_->SetBounds(0, 0, 120, 120); |
214 host_->Layout(); | 207 host_->Layout(); |
215 EXPECT_EQ(gfx::Rect(v1pos.x() + 20, v1pos.y() + 10, 10, 10), v1->bounds()); | 208 EXPECT_EQ(gfx::Rect(v1pos.x() + 20, v1pos.y() + 10, 10, 10), v1->bounds()); |
216 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 209 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
217 } | 210 } |
218 | 211 |
219 TEST_F(AnchorLayoutTest, AnchorBottom) { | 212 TEST_F(AnchorLayoutStateTest, AnchorBottom) { |
220 AlignLayout* layout = new AlignLayout(); | 213 AlignLayoutState* layout = new AlignLayoutState(); |
221 host_->SetLayoutManager(layout); | 214 host_->SetLayoutManager(layout); |
222 View* v1 = new View(); | 215 View* v1 = new View(); |
223 v1->attributes().Add(base::WrapUnique(new AnchorAttribute({Anchor::Bottom}))); | 216 layout->AnchorView(v1, {Anchor::Bottom}); |
224 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); | 217 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); |
225 v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10); | 218 layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10); |
226 host_->AddChildView(v1); | 219 host_->AddChildView(v1); |
227 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 220 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
228 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 221 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
229 host_->SetBounds(0, 0, 120, 120); | 222 host_->SetBounds(0, 0, 120, 120); |
230 host_->Layout(); | 223 host_->Layout(); |
231 EXPECT_EQ(gfx::Rect(v1pos.x() + 10, v1pos.y() + 20, 10, 10), v1->bounds()); | 224 EXPECT_EQ(gfx::Rect(v1pos.x() + 10, v1pos.y() + 20, 10, 10), v1->bounds()); |
232 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 225 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
233 } | 226 } |
234 | 227 |
235 TEST_F(AnchorLayoutTest, AnchorTopRightBottom) { | 228 TEST_F(AnchorLayoutStateTest, AnchorTopRightBottom) { |
236 AlignLayout* layout = new AlignLayout(); | 229 AlignLayoutState* layout = new AlignLayoutState(); |
237 host_->SetLayoutManager(layout); | 230 host_->SetLayoutManager(layout); |
238 View* v1 = new View(); | 231 View* v1 = new View(); |
239 v1->attributes().Add(base::WrapUnique( | 232 layout->AnchorView(v1, {Anchor::Top, Anchor::Right, Anchor::Bottom}); |
240 new AnchorAttribute({Anchor::Top, Anchor::Right, Anchor::Bottom}))); | |
241 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); | 233 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); |
242 v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10); | 234 layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10); |
243 host_->AddChildView(v1); | 235 host_->AddChildView(v1); |
244 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 236 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
245 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 237 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
246 host_->SetBounds(0, 0, 120, 120); | 238 host_->SetBounds(0, 0, 120, 120); |
247 host_->Layout(); | 239 host_->Layout(); |
248 EXPECT_EQ(gfx::Rect(v1pos.x() + 20, v1pos.y(), 10, 30), v1->bounds()); | 240 EXPECT_EQ(gfx::Rect(v1pos.x() + 20, v1pos.y(), 10, 30), v1->bounds()); |
249 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 241 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
250 } | 242 } |
251 | 243 |
252 TEST_F(AnchorLayoutTest, AnchorLeftTopRightBottom) { | 244 TEST_F(AnchorLayoutStateTest, AnchorLeftTopRightBottom) { |
253 AlignLayout* layout = new AlignLayout(); | 245 AlignLayoutState* layout = new AlignLayoutState(); |
254 host_->SetLayoutManager(layout); | 246 host_->SetLayoutManager(layout); |
255 View* v1 = new View(); | 247 View* v1 = new View(); |
256 v1->attributes().Add(base::WrapUnique(new AnchorAttribute( | 248 layout->AnchorView(v1, |
257 {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom}))); | 249 {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom}); |
258 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); | 250 gfx::Point v1pos((host_->width() - 10) / 2, (host_->height() - 10) / 2); |
259 v1->SetBounds(v1pos.x(), v1pos.y(), 10, 10); | 251 layout->SetViewBounds(v1, v1pos.x(), v1pos.y(), 10, 10); |
260 host_->AddChildView(v1); | 252 host_->AddChildView(v1); |
261 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); | 253 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 10, 10), v1->bounds()); |
262 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 254 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
263 host_->SetBounds(0, 0, 120, 120); | 255 host_->SetBounds(0, 0, 120, 120); |
264 host_->Layout(); | 256 host_->Layout(); |
265 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 30, 30), v1->bounds()); | 257 EXPECT_EQ(gfx::Rect(v1pos.x(), v1pos.y(), 30, 30), v1->bounds()); |
266 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 258 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
267 } | 259 } |
268 | 260 |
269 TEST_F(AnchorLayoutTest, AlignTopAnchorAll) { | 261 TEST_F(AnchorLayoutStateTest, AlignTopAnchorAll) { |
270 AlignLayout* layout = new AlignLayout(); | 262 AlignLayoutState* layout = new AlignLayoutState(); |
271 host_->SetLayoutManager(layout); | 263 host_->SetLayoutManager(layout); |
272 View* v1 = new View(); | 264 View* v1 = new View(); |
273 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Top))); | 265 layout->AlignView(v1, Align::Top); |
274 v1->attributes().Add(base::WrapUnique(new AnchorAttribute( | 266 layout->AnchorView(v1, |
275 {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom}))); | 267 {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom}); |
276 v1->SetBounds(0, 0, 10, 10); | 268 layout->SetViewBounds(v1, 0, 0, 10, 10); |
277 host_->AddChildView(v1); | 269 host_->AddChildView(v1); |
278 host_->Layout(); | 270 host_->Layout(); |
279 EXPECT_EQ(gfx::Rect(0, 0, 100, 10), v1->bounds()); | 271 EXPECT_EQ(gfx::Rect(0, 0, 100, 10), v1->bounds()); |
280 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 272 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
281 host_->SetBounds(0, 0, 120, 120); | 273 host_->SetBounds(0, 0, 120, 120); |
282 host_->Layout(); | 274 host_->Layout(); |
283 EXPECT_EQ(gfx::Rect(0, 0, 120, 30), v1->bounds()); | 275 EXPECT_EQ(gfx::Rect(0, 0, 120, 30), v1->bounds()); |
284 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 276 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
285 } | 277 } |
286 | 278 |
287 TEST_F(AnchorLayoutTest, AlignBottomAnchorAll) { | 279 TEST_F(AnchorLayoutStateTest, AlignBottomAnchorAll) { |
288 AlignLayout* layout = new AlignLayout(); | 280 AlignLayoutState* layout = new AlignLayoutState(); |
289 host_->SetLayoutManager(layout); | 281 host_->SetLayoutManager(layout); |
290 View* v1 = new View(); | 282 View* v1 = new View(); |
291 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Bottom))); | 283 layout->AlignView(v1, Align::Bottom); |
292 v1->attributes().Add(base::WrapUnique(new AnchorAttribute( | 284 layout->AnchorView(v1, |
293 {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom}))); | 285 {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom}); |
294 v1->SetBounds(0, 0, 10, 10); | 286 layout->SetViewBounds(v1, 0, 0, 10, 10); |
295 host_->AddChildView(v1); | 287 host_->AddChildView(v1); |
296 host_->Layout(); | 288 host_->Layout(); |
297 EXPECT_EQ(gfx::Rect(0, 90, 100, 10), v1->bounds()); | 289 EXPECT_EQ(gfx::Rect(0, 90, 100, 10), v1->bounds()); |
298 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 290 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
299 host_->SetBounds(0, 0, 120, 120); | 291 host_->SetBounds(0, 0, 120, 120); |
300 host_->Layout(); | 292 host_->Layout(); |
301 EXPECT_EQ(gfx::Rect(0, 90, 120, 30), v1->bounds()); | 293 EXPECT_EQ(gfx::Rect(0, 90, 120, 30), v1->bounds()); |
302 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 294 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
303 } | 295 } |
304 | 296 |
305 TEST_F(AnchorLayoutTest, AlignLeftAnchorAll) { | 297 TEST_F(AnchorLayoutStateTest, AlignLeftAnchorAll) { |
306 AlignLayout* layout = new AlignLayout(); | 298 AlignLayoutState* layout = new AlignLayoutState(); |
307 host_->SetLayoutManager(layout); | 299 host_->SetLayoutManager(layout); |
308 View* v1 = new View(); | 300 View* v1 = new View(); |
309 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Left))); | 301 layout->AlignView(v1, Align::Left); |
310 v1->attributes().Add(base::WrapUnique(new AnchorAttribute( | 302 layout->AnchorView(v1, |
311 {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom}))); | 303 {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom}); |
312 v1->SetBounds(0, 0, 10, 10); | 304 layout->SetViewBounds(v1, 0, 0, 10, 10); |
313 host_->AddChildView(v1); | 305 host_->AddChildView(v1); |
314 host_->Layout(); | 306 host_->Layout(); |
315 EXPECT_EQ(gfx::Rect(0, 0, 10, 100), v1->bounds()); | 307 EXPECT_EQ(gfx::Rect(0, 0, 10, 100), v1->bounds()); |
316 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 308 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
317 host_->SetBounds(0, 0, 120, 120); | 309 host_->SetBounds(0, 0, 120, 120); |
318 host_->Layout(); | 310 host_->Layout(); |
319 EXPECT_EQ(gfx::Rect(0, 0, 30, 120), v1->bounds()); | 311 EXPECT_EQ(gfx::Rect(0, 0, 30, 120), v1->bounds()); |
320 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 312 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
321 } | 313 } |
322 | 314 |
323 TEST_F(AnchorLayoutTest, AlignRightAnchorAll) { | 315 TEST_F(AnchorLayoutStateTest, AlignRightAnchorAll) { |
324 AlignLayout* layout = new AlignLayout(); | 316 AlignLayoutState* layout = new AlignLayoutState(); |
325 host_->SetLayoutManager(layout); | 317 host_->SetLayoutManager(layout); |
326 View* v1 = new View(); | 318 View* v1 = new View(); |
327 v1->attributes().Add(base::WrapUnique(new AlignAttribute(Align::Right))); | 319 layout->AlignView(v1, Align::Right); |
328 v1->attributes().Add(base::WrapUnique(new AnchorAttribute( | 320 layout->AnchorView(v1, |
329 {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom}))); | 321 {Anchor::Left, Anchor::Top, Anchor::Right, Anchor::Bottom}); |
330 v1->SetBounds(0, 0, 10, 10); | 322 layout->SetViewBounds(v1, 0, 0, 10, 10); |
331 host_->AddChildView(v1); | 323 host_->AddChildView(v1); |
332 host_->Layout(); | 324 host_->Layout(); |
333 EXPECT_EQ(gfx::Rect(90, 0, 10, 100), v1->bounds()); | 325 EXPECT_EQ(gfx::Rect(90, 0, 10, 100), v1->bounds()); |
334 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); | 326 EXPECT_EQ(gfx::Rect(0, 0, 100, 100), host_->bounds()); |
335 host_->SetBounds(0, 0, 120, 120); | 327 host_->SetBounds(0, 0, 120, 120); |
336 host_->Layout(); | 328 host_->Layout(); |
337 EXPECT_EQ(gfx::Rect(90, 0, 30, 120), v1->bounds()); | 329 EXPECT_EQ(gfx::Rect(90, 0, 30, 120), v1->bounds()); |
338 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); | 330 EXPECT_EQ(gfx::Rect(0, 0, 120, 120), host_->bounds()); |
339 } | 331 } |
340 | 332 |
341 } // namespace views | 333 } // namespace views |
OLD | NEW |