| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/views/grid_layout.h" | 5 #include "chrome/views/grid_layout.h" |
| 6 #include "chrome/views/view.h" | 6 #include "chrome/views/view.h" |
| 7 | 7 |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 using ChromeViews::ColumnSet; | 10 using ChromeViews::ColumnSet; |
| 11 using ChromeViews::GridLayout; | 11 using ChromeViews::GridLayout; |
| 12 using ChromeViews::View; | 12 using ChromeViews::View; |
| 13 | 13 |
| 14 static void ExpectViewBoundsEquals(int x, int y, int w, int h, | 14 static void ExpectViewBoundsEquals(int x, int y, int w, int h, |
| 15 const View* view) { | 15 const View* view) { |
| 16 EXPECT_EQ(x, view->x()); | 16 EXPECT_EQ(x, view->x()); |
| 17 EXPECT_EQ(y, view->y()); | 17 EXPECT_EQ(y, view->y()); |
| 18 EXPECT_EQ(w, view->width()); | 18 EXPECT_EQ(w, view->width()); |
| 19 EXPECT_EQ(h, view->height()); | 19 EXPECT_EQ(h, view->height()); |
| 20 } | 20 } |
| 21 | 21 |
| 22 class SettableSizeView : public View { | 22 class SettableSizeView : public View { |
| 23 public: | 23 public: |
| 24 explicit SettableSizeView(const CSize& pref) { | 24 explicit SettableSizeView(const gfx::Size& pref) { |
| 25 pref_ = pref; | 25 pref_ = pref; |
| 26 } | 26 } |
| 27 | 27 |
| 28 virtual void GetPreferredSize(CSize *out) { | 28 virtual gfx::Size GetPreferredSize() { |
| 29 *out = pref_; | 29 return pref_; |
| 30 } | 30 } |
| 31 | 31 |
| 32 private: | 32 private: |
| 33 CSize pref_; | 33 gfx::Size pref_; |
| 34 }; | 34 }; |
| 35 | 35 |
| 36 class GridLayoutTest : public testing::Test { | 36 class GridLayoutTest : public testing::Test { |
| 37 public: | 37 public: |
| 38 virtual void SetUp() { | 38 virtual void SetUp() { |
| 39 layout = new GridLayout(&host); | 39 layout = new GridLayout(&host); |
| 40 } | 40 } |
| 41 | 41 |
| 42 virtual void TearDown() { | 42 virtual void TearDown() { |
| 43 delete layout; | 43 delete layout; |
| 44 } | 44 } |
| 45 | 45 |
| 46 virtual void RemoveAll() { | 46 virtual void RemoveAll() { |
| 47 for (int i = host.GetChildViewCount() - 1; i >= 0; i--) { | 47 for (int i = host.GetChildViewCount() - 1; i >= 0; i--) { |
| 48 host.RemoveChildView(host.GetChildViewAt(i)); | 48 host.RemoveChildView(host.GetChildViewAt(i)); |
| 49 } | 49 } |
| 50 } | 50 } |
| 51 | 51 |
| 52 void GetPreferredSize() { | 52 void GetPreferredSize() { |
| 53 layout->GetPreferredSize(&host, &pref); | 53 pref = layout->GetPreferredSize(&host); |
| 54 } | 54 } |
| 55 | 55 |
| 56 CSize pref; | 56 gfx::Size pref; |
| 57 CRect bounds; | 57 CRect bounds; |
| 58 View host; | 58 View host; |
| 59 GridLayout* layout; | 59 GridLayout* layout; |
| 60 }; | 60 }; |
| 61 | 61 |
| 62 class GridLayoutAlignmentTest : public testing::Test { | 62 class GridLayoutAlignmentTest : public testing::Test { |
| 63 public: | 63 public: |
| 64 GridLayoutAlignmentTest() : | 64 GridLayoutAlignmentTest() : |
| 65 host(), | 65 host(), |
| 66 v1(CSize(10, 20)), | 66 v1(gfx::Size(10, 20)), |
| 67 layout(new GridLayout(&host)) {} | 67 layout(new GridLayout(&host)) {} |
| 68 | 68 |
| 69 virtual void SetUp() { | 69 virtual void SetUp() { |
| 70 } | 70 } |
| 71 | 71 |
| 72 virtual void TearDown() { | 72 virtual void TearDown() { |
| 73 delete layout; | 73 delete layout; |
| 74 } | 74 } |
| 75 | 75 |
| 76 virtual void RemoveAll() { | 76 virtual void RemoveAll() { |
| 77 for (int i = host.GetChildViewCount() - 1; i >= 0; i--) { | 77 for (int i = host.GetChildViewCount() - 1; i >= 0; i--) { |
| 78 host.RemoveChildView(host.GetChildViewAt(i)); | 78 host.RemoveChildView(host.GetChildViewAt(i)); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 void TestAlignment(GridLayout::Alignment alignment, CRect* bounds) { | 82 void TestAlignment(GridLayout::Alignment alignment, CRect* bounds) { |
| 83 ColumnSet* c1 = layout->AddColumnSet(0); | 83 ColumnSet* c1 = layout->AddColumnSet(0); |
| 84 c1->AddColumn(alignment, alignment, 1, GridLayout::USE_PREF, 0, 0); | 84 c1->AddColumn(alignment, alignment, 1, GridLayout::USE_PREF, 0, 0); |
| 85 layout->StartRow(1, 0); | 85 layout->StartRow(1, 0); |
| 86 layout->AddView(&v1); | 86 layout->AddView(&v1); |
| 87 CSize pref; | 87 gfx::Size pref = layout->GetPreferredSize(&host); |
| 88 layout->GetPreferredSize(&host, &pref); | 88 EXPECT_TRUE(gfx::Size(10, 20) == pref); |
| 89 EXPECT_TRUE(CSize(10, 20) == pref); | |
| 90 host.SetBounds(0, 0, 100, 100); | 89 host.SetBounds(0, 0, 100, 100); |
| 91 layout->Layout(&host); | 90 layout->Layout(&host); |
| 92 *bounds = v1.bounds().ToRECT(); | 91 *bounds = v1.bounds().ToRECT(); |
| 93 RemoveAll(); | 92 RemoveAll(); |
| 94 } | 93 } |
| 95 | 94 |
| 96 View host; | 95 View host; |
| 97 SettableSizeView v1; | 96 SettableSizeView v1; |
| 98 GridLayout* layout; | 97 GridLayout* layout; |
| 99 }; | 98 }; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 116 EXPECT_TRUE(CRect(45, 40, 55, 60) == bounds); | 115 EXPECT_TRUE(CRect(45, 40, 55, 60) == bounds); |
| 117 } | 116 } |
| 118 | 117 |
| 119 TEST_F(GridLayoutAlignmentTest, Trailing) { | 118 TEST_F(GridLayoutAlignmentTest, Trailing) { |
| 120 CRect bounds; | 119 CRect bounds; |
| 121 TestAlignment(GridLayout::TRAILING, &bounds); | 120 TestAlignment(GridLayout::TRAILING, &bounds); |
| 122 EXPECT_TRUE(CRect(90, 80, 100, 100) == bounds); | 121 EXPECT_TRUE(CRect(90, 80, 100, 100) == bounds); |
| 123 } | 122 } |
| 124 | 123 |
| 125 TEST_F(GridLayoutTest, TwoColumns) { | 124 TEST_F(GridLayoutTest, TwoColumns) { |
| 126 SettableSizeView v1(CSize(10, 20)); | 125 SettableSizeView v1(gfx::Size(10, 20)); |
| 127 SettableSizeView v2(CSize(20, 20)); | 126 SettableSizeView v2(gfx::Size(20, 20)); |
| 128 ColumnSet* c1 = layout->AddColumnSet(0); | 127 ColumnSet* c1 = layout->AddColumnSet(0); |
| 129 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 128 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 130 0, GridLayout::USE_PREF, 0, 0); | 129 0, GridLayout::USE_PREF, 0, 0); |
| 131 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 130 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 132 0, GridLayout::USE_PREF, 0, 0); | 131 0, GridLayout::USE_PREF, 0, 0); |
| 133 layout->StartRow(0, 0); | 132 layout->StartRow(0, 0); |
| 134 layout->AddView(&v1); | 133 layout->AddView(&v1); |
| 135 layout->AddView(&v2); | 134 layout->AddView(&v2); |
| 136 | 135 |
| 137 GetPreferredSize(); | 136 GetPreferredSize(); |
| 138 EXPECT_TRUE(CSize(30, 20) == pref); | 137 EXPECT_TRUE(gfx::Size(30, 20) == pref); |
| 139 | 138 |
| 140 host.SetBounds(0, 0, pref.cx, pref.cy); | 139 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 141 layout->Layout(&host); | 140 layout->Layout(&host); |
| 142 ExpectViewBoundsEquals(0, 0, 10, 20, &v1); | 141 ExpectViewBoundsEquals(0, 0, 10, 20, &v1); |
| 143 ExpectViewBoundsEquals(10, 0, 20, 20, &v2); | 142 ExpectViewBoundsEquals(10, 0, 20, 20, &v2); |
| 144 | 143 |
| 145 RemoveAll(); | 144 RemoveAll(); |
| 146 } | 145 } |
| 147 | 146 |
| 148 TEST_F(GridLayoutTest, ColSpan1) { | 147 TEST_F(GridLayoutTest, ColSpan1) { |
| 149 SettableSizeView v1(CSize(100, 20)); | 148 SettableSizeView v1(gfx::Size(100, 20)); |
| 150 SettableSizeView v2(CSize(10, 40)); | 149 SettableSizeView v2(gfx::Size(10, 40)); |
| 151 ColumnSet* c1 = layout->AddColumnSet(0); | 150 ColumnSet* c1 = layout->AddColumnSet(0); |
| 152 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 151 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 153 0, GridLayout::USE_PREF, 0, 0); | 152 0, GridLayout::USE_PREF, 0, 0); |
| 154 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 153 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 155 1, GridLayout::USE_PREF, 0, 0); | 154 1, GridLayout::USE_PREF, 0, 0); |
| 156 layout->StartRow(0, 0); | 155 layout->StartRow(0, 0); |
| 157 layout->AddView(&v1, 2, 1); | 156 layout->AddView(&v1, 2, 1); |
| 158 layout->StartRow(0, 0); | 157 layout->StartRow(0, 0); |
| 159 layout->AddView(&v2); | 158 layout->AddView(&v2); |
| 160 | 159 |
| 161 GetPreferredSize(); | 160 GetPreferredSize(); |
| 162 EXPECT_TRUE(CSize(100, 60) == pref); | 161 EXPECT_TRUE(gfx::Size(100, 60) == pref); |
| 163 | 162 |
| 164 host.SetBounds(0, 0, pref.cx, pref.cy); | 163 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 165 layout->Layout(&host); | 164 layout->Layout(&host); |
| 166 ExpectViewBoundsEquals(0, 0, 100, 20, &v1); | 165 ExpectViewBoundsEquals(0, 0, 100, 20, &v1); |
| 167 ExpectViewBoundsEquals(0, 20, 10, 40, &v2); | 166 ExpectViewBoundsEquals(0, 20, 10, 40, &v2); |
| 168 | 167 |
| 169 RemoveAll(); | 168 RemoveAll(); |
| 170 } | 169 } |
| 171 | 170 |
| 172 TEST_F(GridLayoutTest, ColSpan2) { | 171 TEST_F(GridLayoutTest, ColSpan2) { |
| 173 SettableSizeView v1(CSize(100, 20)); | 172 SettableSizeView v1(gfx::Size(100, 20)); |
| 174 SettableSizeView v2(CSize(10, 20)); | 173 SettableSizeView v2(gfx::Size(10, 20)); |
| 175 ColumnSet* c1 = layout->AddColumnSet(0); | 174 ColumnSet* c1 = layout->AddColumnSet(0); |
| 176 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 175 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 177 1, GridLayout::USE_PREF, 0, 0); | 176 1, GridLayout::USE_PREF, 0, 0); |
| 178 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 177 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 179 0, GridLayout::USE_PREF, 0, 0); | 178 0, GridLayout::USE_PREF, 0, 0); |
| 180 layout->StartRow(0, 0); | 179 layout->StartRow(0, 0); |
| 181 layout->AddView(&v1, 2, 1); | 180 layout->AddView(&v1, 2, 1); |
| 182 layout->StartRow(0, 0); | 181 layout->StartRow(0, 0); |
| 183 layout->SkipColumns(1); | 182 layout->SkipColumns(1); |
| 184 layout->AddView(&v2); | 183 layout->AddView(&v2); |
| 185 | 184 |
| 186 GetPreferredSize(); | 185 GetPreferredSize(); |
| 187 EXPECT_TRUE(CSize(100, 40) == pref); | 186 EXPECT_TRUE(gfx::Size(100, 40) == pref); |
| 188 | 187 |
| 189 host.SetBounds(0, 0, pref.cx, pref.cy); | 188 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 190 layout->Layout(&host); | 189 layout->Layout(&host); |
| 191 ExpectViewBoundsEquals(0, 0, 100, 20, &v1); | 190 ExpectViewBoundsEquals(0, 0, 100, 20, &v1); |
| 192 ExpectViewBoundsEquals(90, 20, 10, 20, &v2); | 191 ExpectViewBoundsEquals(90, 20, 10, 20, &v2); |
| 193 | 192 |
| 194 RemoveAll(); | 193 RemoveAll(); |
| 195 } | 194 } |
| 196 | 195 |
| 197 TEST_F(GridLayoutTest, ColSpan3) { | 196 TEST_F(GridLayoutTest, ColSpan3) { |
| 198 SettableSizeView v1(CSize(100, 20)); | 197 SettableSizeView v1(gfx::Size(100, 20)); |
| 199 SettableSizeView v2(CSize(10, 20)); | 198 SettableSizeView v2(gfx::Size(10, 20)); |
| 200 SettableSizeView v3(CSize(10, 20)); | 199 SettableSizeView v3(gfx::Size(10, 20)); |
| 201 ColumnSet* c1 = layout->AddColumnSet(0); | 200 ColumnSet* c1 = layout->AddColumnSet(0); |
| 202 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 201 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 203 0, GridLayout::USE_PREF, 0, 0); | 202 0, GridLayout::USE_PREF, 0, 0); |
| 204 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 203 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 205 0, GridLayout::USE_PREF, 0, 0); | 204 0, GridLayout::USE_PREF, 0, 0); |
| 206 layout->StartRow(0, 0); | 205 layout->StartRow(0, 0); |
| 207 layout->AddView(&v1, 2, 1); | 206 layout->AddView(&v1, 2, 1); |
| 208 layout->StartRow(0, 0); | 207 layout->StartRow(0, 0); |
| 209 layout->AddView(&v2); | 208 layout->AddView(&v2); |
| 210 layout->AddView(&v3); | 209 layout->AddView(&v3); |
| 211 | 210 |
| 212 GetPreferredSize(); | 211 GetPreferredSize(); |
| 213 EXPECT_TRUE(CSize(100, 40) == pref); | 212 EXPECT_TRUE(gfx::Size(100, 40) == pref); |
| 214 | 213 |
| 215 host.SetBounds(0, 0, pref.cx, pref.cy); | 214 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 216 layout->Layout(&host); | 215 layout->Layout(&host); |
| 217 ExpectViewBoundsEquals(0, 0, 100, 20, &v1); | 216 ExpectViewBoundsEquals(0, 0, 100, 20, &v1); |
| 218 ExpectViewBoundsEquals(0, 20, 10, 20, &v2); | 217 ExpectViewBoundsEquals(0, 20, 10, 20, &v2); |
| 219 ExpectViewBoundsEquals(50, 20, 10, 20, &v3); | 218 ExpectViewBoundsEquals(50, 20, 10, 20, &v3); |
| 220 | 219 |
| 221 RemoveAll(); | 220 RemoveAll(); |
| 222 } | 221 } |
| 223 | 222 |
| 224 | 223 |
| 225 TEST_F(GridLayoutTest, ColSpan4) { | 224 TEST_F(GridLayoutTest, ColSpan4) { |
| 226 ChromeViews::ColumnSet* set = layout->AddColumnSet(0); | 225 ChromeViews::ColumnSet* set = layout->AddColumnSet(0); |
| 227 | 226 |
| 228 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, | 227 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, |
| 229 GridLayout::USE_PREF, 0, 0); | 228 GridLayout::USE_PREF, 0, 0); |
| 230 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, | 229 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, |
| 231 GridLayout::USE_PREF, 0, 0); | 230 GridLayout::USE_PREF, 0, 0); |
| 232 | 231 |
| 233 SettableSizeView v1(CSize(10, 10)); | 232 SettableSizeView v1(gfx::Size(10, 10)); |
| 234 SettableSizeView v2(CSize(10, 10)); | 233 SettableSizeView v2(gfx::Size(10, 10)); |
| 235 SettableSizeView v3(CSize(25, 20)); | 234 SettableSizeView v3(gfx::Size(25, 20)); |
| 236 layout->StartRow(0, 0); | 235 layout->StartRow(0, 0); |
| 237 layout->AddView(&v1); | 236 layout->AddView(&v1); |
| 238 layout->AddView(&v2); | 237 layout->AddView(&v2); |
| 239 layout->StartRow(0, 0); | 238 layout->StartRow(0, 0); |
| 240 layout->AddView(&v3, 2, 1); | 239 layout->AddView(&v3, 2, 1); |
| 241 | 240 |
| 242 GetPreferredSize(); | 241 GetPreferredSize(); |
| 243 EXPECT_TRUE(CSize(25, 30) == pref); | 242 EXPECT_TRUE(gfx::Size(25, 30) == pref); |
| 244 | 243 |
| 245 host.SetBounds(0, 0, pref.cx, pref.cy); | 244 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 246 layout->Layout(&host); | 245 layout->Layout(&host); |
| 247 ExpectViewBoundsEquals(0, 0, 10, 10, &v1); | 246 ExpectViewBoundsEquals(0, 0, 10, 10, &v1); |
| 248 ExpectViewBoundsEquals(12, 0, 10, 10, &v2); | 247 ExpectViewBoundsEquals(12, 0, 10, 10, &v2); |
| 249 ExpectViewBoundsEquals(0, 10, 25, 20, &v3); | 248 ExpectViewBoundsEquals(0, 10, 25, 20, &v3); |
| 250 | 249 |
| 251 RemoveAll(); | 250 RemoveAll(); |
| 252 } | 251 } |
| 253 | 252 |
| 254 TEST_F(GridLayoutTest, SameSizeColumns) { | 253 TEST_F(GridLayoutTest, SameSizeColumns) { |
| 255 SettableSizeView v1(CSize(50, 20)); | 254 SettableSizeView v1(gfx::Size(50, 20)); |
| 256 SettableSizeView v2(CSize(10, 10)); | 255 SettableSizeView v2(gfx::Size(10, 10)); |
| 257 ColumnSet* c1 = layout->AddColumnSet(0); | 256 ColumnSet* c1 = layout->AddColumnSet(0); |
| 258 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 257 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 259 0, GridLayout::USE_PREF, 0, 0); | 258 0, GridLayout::USE_PREF, 0, 0); |
| 260 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 259 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 261 0, GridLayout::USE_PREF, 0, 0); | 260 0, GridLayout::USE_PREF, 0, 0); |
| 262 c1->LinkColumnSizes(0, 1, -1); | 261 c1->LinkColumnSizes(0, 1, -1); |
| 263 layout->StartRow(0, 0); | 262 layout->StartRow(0, 0); |
| 264 layout->AddView(&v1); | 263 layout->AddView(&v1); |
| 265 layout->AddView(&v2); | 264 layout->AddView(&v2); |
| 266 | 265 |
| 267 CSize pref; | 266 gfx::Size pref = layout->GetPreferredSize(&host); |
| 268 layout->GetPreferredSize(&host, &pref); | 267 EXPECT_TRUE(gfx::Size(100, 20) == pref); |
| 269 EXPECT_TRUE(CSize(100, 20) == pref); | |
| 270 | 268 |
| 271 host.SetBounds(0, 0, pref.cx, pref.cy); | 269 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 272 layout->Layout(&host); | 270 layout->Layout(&host); |
| 273 ExpectViewBoundsEquals(0, 0, 50, 20, &v1); | 271 ExpectViewBoundsEquals(0, 0, 50, 20, &v1); |
| 274 ExpectViewBoundsEquals(50, 0, 10, 10, &v2); | 272 ExpectViewBoundsEquals(50, 0, 10, 10, &v2); |
| 275 | 273 |
| 276 RemoveAll(); | 274 RemoveAll(); |
| 277 } | 275 } |
| 278 | 276 |
| 279 TEST_F(GridLayoutTest, HorizontalResizeTest1) { | 277 TEST_F(GridLayoutTest, HorizontalResizeTest1) { |
| 280 SettableSizeView v1(CSize(50, 20)); | 278 SettableSizeView v1(gfx::Size(50, 20)); |
| 281 SettableSizeView v2(CSize(10, 10)); | 279 SettableSizeView v2(gfx::Size(10, 10)); |
| 282 ColumnSet* c1 = layout->AddColumnSet(0); | 280 ColumnSet* c1 = layout->AddColumnSet(0); |
| 283 c1->AddColumn(GridLayout::FILL, GridLayout::LEADING, | 281 c1->AddColumn(GridLayout::FILL, GridLayout::LEADING, |
| 284 1, GridLayout::USE_PREF, 0, 0); | 282 1, GridLayout::USE_PREF, 0, 0); |
| 285 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 283 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 286 0, GridLayout::USE_PREF, 0, 0); | 284 0, GridLayout::USE_PREF, 0, 0); |
| 287 layout->StartRow(0, 0); | 285 layout->StartRow(0, 0); |
| 288 layout->AddView(&v1); | 286 layout->AddView(&v1); |
| 289 layout->AddView(&v2); | 287 layout->AddView(&v2); |
| 290 | 288 |
| 291 host.SetBounds(0, 0, 110, 20); | 289 host.SetBounds(0, 0, 110, 20); |
| 292 layout->Layout(&host); | 290 layout->Layout(&host); |
| 293 ExpectViewBoundsEquals(0, 0, 100, 20, &v1); | 291 ExpectViewBoundsEquals(0, 0, 100, 20, &v1); |
| 294 ExpectViewBoundsEquals(100, 0, 10, 10, &v2); | 292 ExpectViewBoundsEquals(100, 0, 10, 10, &v2); |
| 295 | 293 |
| 296 RemoveAll(); | 294 RemoveAll(); |
| 297 } | 295 } |
| 298 | 296 |
| 299 TEST_F(GridLayoutTest, HorizontalResizeTest2) { | 297 TEST_F(GridLayoutTest, HorizontalResizeTest2) { |
| 300 SettableSizeView v1(CSize(50, 20)); | 298 SettableSizeView v1(gfx::Size(50, 20)); |
| 301 SettableSizeView v2(CSize(10, 10)); | 299 SettableSizeView v2(gfx::Size(10, 10)); |
| 302 ColumnSet* c1 = layout->AddColumnSet(0); | 300 ColumnSet* c1 = layout->AddColumnSet(0); |
| 303 c1->AddColumn(GridLayout::FILL, GridLayout::LEADING, | 301 c1->AddColumn(GridLayout::FILL, GridLayout::LEADING, |
| 304 1, GridLayout::USE_PREF, 0, 0); | 302 1, GridLayout::USE_PREF, 0, 0); |
| 305 c1->AddColumn(GridLayout::TRAILING, GridLayout::LEADING, | 303 c1->AddColumn(GridLayout::TRAILING, GridLayout::LEADING, |
| 306 1, GridLayout::USE_PREF, 0, 0); | 304 1, GridLayout::USE_PREF, 0, 0); |
| 307 layout->StartRow(0, 0); | 305 layout->StartRow(0, 0); |
| 308 layout->AddView(&v1); | 306 layout->AddView(&v1); |
| 309 layout->AddView(&v2); | 307 layout->AddView(&v2); |
| 310 | 308 |
| 311 host.SetBounds(0, 0, 120, 20); | 309 host.SetBounds(0, 0, 120, 20); |
| 312 layout->Layout(&host); | 310 layout->Layout(&host); |
| 313 ExpectViewBoundsEquals(0, 0, 80, 20, &v1); | 311 ExpectViewBoundsEquals(0, 0, 80, 20, &v1); |
| 314 ExpectViewBoundsEquals(110, 0, 10, 10, &v2); | 312 ExpectViewBoundsEquals(110, 0, 10, 10, &v2); |
| 315 | 313 |
| 316 RemoveAll(); | 314 RemoveAll(); |
| 317 } | 315 } |
| 318 | 316 |
| 319 TEST_F(GridLayoutTest, TestVerticalResize1) { | 317 TEST_F(GridLayoutTest, TestVerticalResize1) { |
| 320 SettableSizeView v1(CSize(50, 20)); | 318 SettableSizeView v1(gfx::Size(50, 20)); |
| 321 SettableSizeView v2(CSize(10, 10)); | 319 SettableSizeView v2(gfx::Size(10, 10)); |
| 322 ColumnSet* c1 = layout->AddColumnSet(0); | 320 ColumnSet* c1 = layout->AddColumnSet(0); |
| 323 c1->AddColumn(GridLayout::FILL, GridLayout::FILL, | 321 c1->AddColumn(GridLayout::FILL, GridLayout::FILL, |
| 324 1, GridLayout::USE_PREF, 0, 0); | 322 1, GridLayout::USE_PREF, 0, 0); |
| 325 layout->StartRow(1, 0); | 323 layout->StartRow(1, 0); |
| 326 layout->AddView(&v1); | 324 layout->AddView(&v1); |
| 327 layout->StartRow(0, 0); | 325 layout->StartRow(0, 0); |
| 328 layout->AddView(&v2); | 326 layout->AddView(&v2); |
| 329 | 327 |
| 330 GetPreferredSize(); | 328 GetPreferredSize(); |
| 331 EXPECT_TRUE(CSize(50, 30) == pref); | 329 EXPECT_TRUE(gfx::Size(50, 30) == pref); |
| 332 | 330 |
| 333 host.SetBounds(0, 0, 50, 100); | 331 host.SetBounds(0, 0, 50, 100); |
| 334 layout->Layout(&host); | 332 layout->Layout(&host); |
| 335 ExpectViewBoundsEquals(0, 0, 50, 90, &v1); | 333 ExpectViewBoundsEquals(0, 0, 50, 90, &v1); |
| 336 ExpectViewBoundsEquals(0, 90, 50, 10, &v2); | 334 ExpectViewBoundsEquals(0, 90, 50, 10, &v2); |
| 337 | 335 |
| 338 RemoveAll(); | 336 RemoveAll(); |
| 339 } | 337 } |
| 340 | 338 |
| 341 TEST_F(GridLayoutTest, Insets) { | 339 TEST_F(GridLayoutTest, Insets) { |
| 342 SettableSizeView v1(CSize(10, 20)); | 340 SettableSizeView v1(gfx::Size(10, 20)); |
| 343 ColumnSet* c1 = layout->AddColumnSet(0); | 341 ColumnSet* c1 = layout->AddColumnSet(0); |
| 344 layout->SetInsets(1, 2, 3, 4); | 342 layout->SetInsets(1, 2, 3, 4); |
| 345 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 343 c1->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 346 0, GridLayout::USE_PREF, 0, 0); | 344 0, GridLayout::USE_PREF, 0, 0); |
| 347 layout->StartRow(0, 0); | 345 layout->StartRow(0, 0); |
| 348 layout->AddView(&v1); | 346 layout->AddView(&v1); |
| 349 | 347 |
| 350 GetPreferredSize(); | 348 GetPreferredSize(); |
| 351 EXPECT_TRUE(CSize(16, 24) == pref); | 349 EXPECT_TRUE(gfx::Size(16, 24) == pref); |
| 352 | 350 |
| 353 host.SetBounds(0, 0, pref.cx, pref.cy); | 351 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 354 layout->Layout(&host); | 352 layout->Layout(&host); |
| 355 ExpectViewBoundsEquals(2, 1, 10, 20, &v1); | 353 ExpectViewBoundsEquals(2, 1, 10, 20, &v1); |
| 356 | 354 |
| 357 RemoveAll(); | 355 RemoveAll(); |
| 358 } | 356 } |
| 359 | 357 |
| 360 TEST_F(GridLayoutTest, FixedSize) { | 358 TEST_F(GridLayoutTest, FixedSize) { |
| 361 layout->SetInsets(2, 2, 2, 2); | 359 layout->SetInsets(2, 2, 2, 2); |
| 362 | 360 |
| 363 ChromeViews::ColumnSet* set = layout->AddColumnSet(0); | 361 ChromeViews::ColumnSet* set = layout->AddColumnSet(0); |
| 364 | 362 |
| 365 int column_count = 4; | 363 int column_count = 4; |
| 366 int title_width = 100; | 364 int title_width = 100; |
| 367 int row_count = 2; | 365 int row_count = 2; |
| 368 int pref_width = 10; | 366 int pref_width = 10; |
| 369 int pref_height = 20; | 367 int pref_height = 20; |
| 370 | 368 |
| 371 for (int i = 0; i < column_count; ++i) { | 369 for (int i = 0; i < column_count; ++i) { |
| 372 set->AddColumn(ChromeViews::GridLayout::CENTER, | 370 set->AddColumn(ChromeViews::GridLayout::CENTER, |
| 373 ChromeViews::GridLayout::CENTER, | 371 ChromeViews::GridLayout::CENTER, |
| 374 0, | 372 0, |
| 375 ChromeViews::GridLayout::FIXED, | 373 ChromeViews::GridLayout::FIXED, |
| 376 title_width, | 374 title_width, |
| 377 title_width); | 375 title_width); |
| 378 } | 376 } |
| 379 | 377 |
| 380 for (int row = 0; row < row_count; ++row) { | 378 for (int row = 0; row < row_count; ++row) { |
| 381 layout->StartRow(0, 0); | 379 layout->StartRow(0, 0); |
| 382 for (int col = 0; col < column_count; ++col) { | 380 for (int col = 0; col < column_count; ++col) { |
| 383 layout->AddView(new SettableSizeView(CSize(pref_width, pref_height))); | 381 layout->AddView(new SettableSizeView(gfx::Size(pref_width, pref_height))); |
| 384 } | 382 } |
| 385 } | 383 } |
| 386 | 384 |
| 387 layout->Layout(&host); | 385 layout->Layout(&host); |
| 388 | 386 |
| 389 for (int i = 0; i < column_count; ++i) { | 387 for (int i = 0; i < column_count; ++i) { |
| 390 for (int row = 0; row < row_count; ++row) { | 388 for (int row = 0; row < row_count; ++row) { |
| 391 View* view = host.GetChildViewAt(row * column_count + i); | 389 View* view = host.GetChildViewAt(row * column_count + i); |
| 392 ExpectViewBoundsEquals(2 + title_width * i + (title_width - pref_width) /
2, | 390 ExpectViewBoundsEquals(2 + title_width * i + (title_width - pref_width) /
2, |
| 393 2 + pref_height * row, | 391 2 + pref_height * row, |
| 394 pref_width, pref_height, view); | 392 pref_width, pref_height, view); |
| 395 } | 393 } |
| 396 } | 394 } |
| 397 | 395 |
| 398 GetPreferredSize(); | 396 GetPreferredSize(); |
| 399 EXPECT_TRUE(CSize(column_count * title_width + 4, | 397 EXPECT_TRUE(gfx::Size(column_count * title_width + 4, |
| 400 row_count * pref_height + 4) == pref); | 398 row_count * pref_height + 4) == pref); |
| 401 } | 399 } |
| 402 | 400 |
| 403 TEST_F(GridLayoutTest, RowSpanWithPaddingRow) { | 401 TEST_F(GridLayoutTest, RowSpanWithPaddingRow) { |
| 404 ChromeViews::ColumnSet* set = layout->AddColumnSet(0); | 402 ChromeViews::ColumnSet* set = layout->AddColumnSet(0); |
| 405 | 403 |
| 406 set->AddColumn(ChromeViews::GridLayout::CENTER, | 404 set->AddColumn(ChromeViews::GridLayout::CENTER, |
| 407 ChromeViews::GridLayout::CENTER, | 405 ChromeViews::GridLayout::CENTER, |
| 408 0, | 406 0, |
| 409 ChromeViews::GridLayout::FIXED, | 407 ChromeViews::GridLayout::FIXED, |
| 410 10, | 408 10, |
| 411 10); | 409 10); |
| 412 | 410 |
| 413 layout->StartRow(0, 0); | 411 layout->StartRow(0, 0); |
| 414 layout->AddView(new SettableSizeView(CSize(10, 10)), 1, 2); | 412 layout->AddView(new SettableSizeView(gfx::Size(10, 10)), 1, 2); |
| 415 layout->AddPaddingRow(0, 10); | 413 layout->AddPaddingRow(0, 10); |
| 416 } | 414 } |
| 417 | 415 |
| 418 TEST_F(GridLayoutTest, RowSpan) { | 416 TEST_F(GridLayoutTest, RowSpan) { |
| 419 ChromeViews::ColumnSet* set = layout->AddColumnSet(0); | 417 ChromeViews::ColumnSet* set = layout->AddColumnSet(0); |
| 420 | 418 |
| 421 set->AddColumn(ChromeViews::GridLayout::LEADING, | 419 set->AddColumn(ChromeViews::GridLayout::LEADING, |
| 422 ChromeViews::GridLayout::LEADING, | 420 ChromeViews::GridLayout::LEADING, |
| 423 0, | 421 0, |
| 424 ChromeViews::GridLayout::USE_PREF, | 422 ChromeViews::GridLayout::USE_PREF, |
| 425 0, | 423 0, |
| 426 0); | 424 0); |
| 427 set->AddColumn(ChromeViews::GridLayout::LEADING, | 425 set->AddColumn(ChromeViews::GridLayout::LEADING, |
| 428 ChromeViews::GridLayout::LEADING, | 426 ChromeViews::GridLayout::LEADING, |
| 429 0, | 427 0, |
| 430 ChromeViews::GridLayout::USE_PREF, | 428 ChromeViews::GridLayout::USE_PREF, |
| 431 0, | 429 0, |
| 432 0); | 430 0); |
| 433 | 431 |
| 434 layout->StartRow(0, 0); | 432 layout->StartRow(0, 0); |
| 435 layout->AddView(new SettableSizeView(CSize(20, 10))); | 433 layout->AddView(new SettableSizeView(gfx::Size(20, 10))); |
| 436 layout->AddView(new SettableSizeView(CSize(20, 40)), 1, 2); | 434 layout->AddView(new SettableSizeView(gfx::Size(20, 40)), 1, 2); |
| 437 layout->StartRow(1, 0); | 435 layout->StartRow(1, 0); |
| 438 ChromeViews::View* s3 = new SettableSizeView(CSize(20, 10)); | 436 ChromeViews::View* s3 = new SettableSizeView(gfx::Size(20, 10)); |
| 439 layout->AddView(s3); | 437 layout->AddView(s3); |
| 440 | 438 |
| 441 GetPreferredSize(); | 439 GetPreferredSize(); |
| 442 EXPECT_TRUE(CSize(40, 40) == pref); | 440 EXPECT_TRUE(gfx::Size(40, 40) == pref); |
| 443 | 441 |
| 444 host.SetBounds(0, 0, pref.cx, pref.cy); | 442 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 445 layout->Layout(&host); | 443 layout->Layout(&host); |
| 446 ExpectViewBoundsEquals(0, 10, 20, 10, s3); | 444 ExpectViewBoundsEquals(0, 10, 20, 10, s3); |
| 447 } | 445 } |
| 448 | 446 |
| 449 TEST_F(GridLayoutTest, RowSpan2) { | 447 TEST_F(GridLayoutTest, RowSpan2) { |
| 450 ChromeViews::ColumnSet* set = layout->AddColumnSet(0); | 448 ChromeViews::ColumnSet* set = layout->AddColumnSet(0); |
| 451 | 449 |
| 452 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 450 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 453 0, GridLayout::USE_PREF, 0, 0); | 451 0, GridLayout::USE_PREF, 0, 0); |
| 454 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 452 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 455 0,GridLayout::USE_PREF, 0, 0); | 453 0,GridLayout::USE_PREF, 0, 0); |
| 456 | 454 |
| 457 layout->StartRow(0, 0); | 455 layout->StartRow(0, 0); |
| 458 layout->AddView(new SettableSizeView(CSize(20, 20))); | 456 layout->AddView(new SettableSizeView(gfx::Size(20, 20))); |
| 459 ChromeViews::View* s3 = new SettableSizeView(CSize(64, 64)); | 457 ChromeViews::View* s3 = new SettableSizeView(gfx::Size(64, 64)); |
| 460 layout->AddView(s3, 1, 3); | 458 layout->AddView(s3, 1, 3); |
| 461 | 459 |
| 462 layout->AddPaddingRow(0, 10); | 460 layout->AddPaddingRow(0, 10); |
| 463 | 461 |
| 464 layout->StartRow(0, 0); | 462 layout->StartRow(0, 0); |
| 465 layout->AddView(new SettableSizeView(CSize(10, 20))); | 463 layout->AddView(new SettableSizeView(gfx::Size(10, 20))); |
| 466 | 464 |
| 467 GetPreferredSize(); | 465 GetPreferredSize(); |
| 468 EXPECT_TRUE(CSize(84, 64) == pref); | 466 EXPECT_TRUE(gfx::Size(84, 64) == pref); |
| 469 | 467 |
| 470 host.SetBounds(0, 0, pref.cx, pref.cy); | 468 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 471 layout->Layout(&host); | 469 layout->Layout(&host); |
| 472 ExpectViewBoundsEquals(20, 0, 64, 64, s3); | 470 ExpectViewBoundsEquals(20, 0, 64, 64, s3); |
| 473 } | 471 } |
| 474 | 472 |
| 475 TEST_F(GridLayoutTest, FixedViewWidth) { | 473 TEST_F(GridLayoutTest, FixedViewWidth) { |
| 476 ChromeViews::ColumnSet* set = layout->AddColumnSet(0); | 474 ChromeViews::ColumnSet* set = layout->AddColumnSet(0); |
| 477 | 475 |
| 478 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 476 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 479 0, GridLayout::USE_PREF, 0, 0); | 477 0, GridLayout::USE_PREF, 0, 0); |
| 480 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 478 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 481 0,GridLayout::USE_PREF, 0, 0); | 479 0,GridLayout::USE_PREF, 0, 0); |
| 482 | 480 |
| 483 layout->StartRow(0, 0); | 481 layout->StartRow(0, 0); |
| 484 View* view = new SettableSizeView(CSize(30, 40)); | 482 View* view = new SettableSizeView(gfx::Size(30, 40)); |
| 485 layout->AddView(view, 1, 1, GridLayout::LEADING, GridLayout::LEADING, 10, 0); | 483 layout->AddView(view, 1, 1, GridLayout::LEADING, GridLayout::LEADING, 10, 0); |
| 486 | 484 |
| 487 GetPreferredSize(); | 485 GetPreferredSize(); |
| 488 EXPECT_EQ(10, pref.cx); | 486 EXPECT_EQ(10, pref.width()); |
| 489 EXPECT_EQ(40, pref.cy); | 487 EXPECT_EQ(40, pref.height()); |
| 490 | 488 |
| 491 host.SetBounds(0, 0, pref.cx, pref.cy); | 489 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 492 layout->Layout(&host); | 490 layout->Layout(&host); |
| 493 ExpectViewBoundsEquals(0, 0, 10, 40, view); | 491 ExpectViewBoundsEquals(0, 0, 10, 40, view); |
| 494 } | 492 } |
| 495 | 493 |
| 496 TEST_F(GridLayoutTest, FixedViewHeight) { | 494 TEST_F(GridLayoutTest, FixedViewHeight) { |
| 497 ChromeViews::ColumnSet* set = layout->AddColumnSet(0); | 495 ChromeViews::ColumnSet* set = layout->AddColumnSet(0); |
| 498 | 496 |
| 499 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 497 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 500 0, GridLayout::USE_PREF, 0, 0); | 498 0, GridLayout::USE_PREF, 0, 0); |
| 501 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 499 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 502 0,GridLayout::USE_PREF, 0, 0); | 500 0,GridLayout::USE_PREF, 0, 0); |
| 503 | 501 |
| 504 layout->StartRow(0, 0); | 502 layout->StartRow(0, 0); |
| 505 View* view = new SettableSizeView(CSize(30, 40)); | 503 View* view = new SettableSizeView(gfx::Size(30, 40)); |
| 506 layout->AddView(view, 1, 1, GridLayout::LEADING, GridLayout::LEADING, 0, 10); | 504 layout->AddView(view, 1, 1, GridLayout::LEADING, GridLayout::LEADING, 0, 10); |
| 507 | 505 |
| 508 GetPreferredSize(); | 506 GetPreferredSize(); |
| 509 EXPECT_EQ(30, pref.cx); | 507 EXPECT_EQ(30, pref.width()); |
| 510 EXPECT_EQ(10, pref.cy); | 508 EXPECT_EQ(10, pref.height()); |
| 511 | 509 |
| 512 host.SetBounds(0, 0, pref.cx, pref.cy); | 510 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 513 layout->Layout(&host); | 511 layout->Layout(&host); |
| 514 ExpectViewBoundsEquals(0, 0, 30, 10, view); | 512 ExpectViewBoundsEquals(0, 0, 30, 10, view); |
| 515 } | 513 } |
| 516 | 514 |
| OLD | NEW |