| 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/grid_layout.h" |
| 6 |
| 7 #include "base/compiler_specific.h" |
| 5 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 6 #include "ui/views/layout/grid_layout.h" | |
| 7 #include "ui/views/view.h" | 9 #include "ui/views/view.h" |
| 8 | 10 |
| 9 using views::ColumnSet; | 11 namespace views { |
| 10 using views::GridLayout; | |
| 11 using views::View; | |
| 12 | 12 |
| 13 static void ExpectViewBoundsEquals(int x, int y, int w, int h, | 13 void ExpectViewBoundsEquals(int x, int y, int w, int h, |
| 14 const View* view) { | 14 const View* view) { |
| 15 EXPECT_EQ(x, view->x()); | 15 EXPECT_EQ(x, view->x()); |
| 16 EXPECT_EQ(y, view->y()); | 16 EXPECT_EQ(y, view->y()); |
| 17 EXPECT_EQ(w, view->width()); | 17 EXPECT_EQ(w, view->width()); |
| 18 EXPECT_EQ(h, view->height()); | 18 EXPECT_EQ(h, view->height()); |
| 19 } | 19 } |
| 20 | 20 |
| 21 class SettableSizeView : public View { | 21 class SettableSizeView : public View { |
| 22 public: | 22 public: |
| 23 explicit SettableSizeView(const gfx::Size& pref) { | 23 explicit SettableSizeView(const gfx::Size& pref) { |
| 24 pref_ = pref; | 24 pref_ = pref; |
| 25 } | 25 } |
| 26 | 26 |
| 27 virtual gfx::Size GetPreferredSize() { | 27 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 28 return pref_; | 28 return pref_; |
| 29 } | 29 } |
| 30 | 30 |
| 31 private: | 31 private: |
| 32 gfx::Size pref_; | 32 gfx::Size pref_; |
| 33 }; | 33 }; |
| 34 | 34 |
| 35 // A view with fixed circumference that trades height for width. | 35 // A view with fixed circumference that trades height for width. |
| 36 class FlexibleView : public View { | 36 class FlexibleView : public View { |
| 37 public: | 37 public: |
| 38 explicit FlexibleView(int circumference) { | 38 explicit FlexibleView(int circumference) { |
| 39 circumference_ = circumference; | 39 circumference_ = circumference; |
| 40 } | 40 } |
| 41 | 41 |
| 42 virtual gfx::Size GetPreferredSize() { | 42 virtual gfx::Size GetPreferredSize() OVERRIDE { |
| 43 return gfx::Size(0, circumference_ / 2); | 43 return gfx::Size(0, circumference_ / 2); |
| 44 } | 44 } |
| 45 | 45 |
| 46 virtual int GetHeightForWidth(int width) { | 46 virtual int GetHeightForWidth(int width) OVERRIDE { |
| 47 return std::max(0, circumference_ / 2 - width); | 47 return std::max(0, circumference_ / 2 - width); |
| 48 } | 48 } |
| 49 | 49 |
| 50 private: | 50 private: |
| 51 int circumference_; | 51 int circumference_; |
| 52 }; | 52 }; |
| 53 | 53 |
| 54 class GridLayoutTest : public testing::Test { | 54 class GridLayoutTest : public testing::Test { |
| 55 public: | 55 public: |
| 56 virtual void SetUp() { | 56 virtual void SetUp() OVERRIDE { |
| 57 layout = new GridLayout(&host); | 57 layout = new GridLayout(&host); |
| 58 } | 58 } |
| 59 | 59 |
| 60 virtual void TearDown() { | 60 virtual void TearDown() OVERRIDE { |
| 61 delete layout; | 61 delete layout; |
| 62 } | 62 } |
| 63 | 63 |
| 64 virtual void RemoveAll() { | 64 void RemoveAll() { |
| 65 for (int i = host.child_count() - 1; i >= 0; i--) | 65 for (int i = host.child_count() - 1; i >= 0; i--) |
| 66 host.RemoveChildView(host.child_at(i)); | 66 host.RemoveChildView(host.child_at(i)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void GetPreferredSize() { | 69 void GetPreferredSize() { |
| 70 pref = layout->GetPreferredSize(&host); | 70 pref = layout->GetPreferredSize(&host); |
| 71 } | 71 } |
| 72 | 72 |
| 73 gfx::Size pref; | 73 gfx::Size pref; |
| 74 gfx::Rect bounds; | 74 gfx::Rect bounds; |
| 75 View host; | 75 View host; |
| 76 GridLayout* layout; | 76 GridLayout* layout; |
| 77 }; | 77 }; |
| 78 | 78 |
| 79 class GridLayoutAlignmentTest : public testing::Test { | 79 class GridLayoutAlignmentTest : public testing::Test { |
| 80 public: | 80 public: |
| 81 GridLayoutAlignmentTest() : | 81 GridLayoutAlignmentTest() : |
| 82 host(), | 82 host(), |
| 83 v1(gfx::Size(10, 20)), | 83 v1(gfx::Size(10, 20)), |
| 84 layout(new GridLayout(&host)) {} | 84 layout(new GridLayout(&host)) {} |
| 85 | 85 |
| 86 virtual void SetUp() { | 86 virtual void SetUp() OVERRIDE {} |
| 87 } | |
| 88 | 87 |
| 89 virtual void TearDown() { | 88 virtual void TearDown() OVERRIDE { |
| 90 delete layout; | 89 delete layout; |
| 91 } | 90 } |
| 92 | 91 |
| 93 virtual void RemoveAll() { | 92 void RemoveAll() { |
| 94 for (int i = host.child_count() - 1; i >= 0; i--) | 93 for (int i = host.child_count() - 1; i >= 0; i--) |
| 95 host.RemoveChildView(host.child_at(i)); | 94 host.RemoveChildView(host.child_at(i)); |
| 96 } | 95 } |
| 97 | 96 |
| 98 void TestAlignment(GridLayout::Alignment alignment, gfx::Rect* bounds) { | 97 void TestAlignment(GridLayout::Alignment alignment, gfx::Rect* bounds) { |
| 99 ColumnSet* c1 = layout->AddColumnSet(0); | 98 ColumnSet* c1 = layout->AddColumnSet(0); |
| 100 c1->AddColumn(alignment, alignment, 1, GridLayout::USE_PREF, 0, 0); | 99 c1->AddColumn(alignment, alignment, 1, GridLayout::USE_PREF, 0, 0); |
| 101 layout->StartRow(1, 0); | 100 layout->StartRow(1, 0); |
| 102 layout->AddView(&v1); | 101 layout->AddView(&v1); |
| 103 gfx::Size pref = layout->GetPreferredSize(&host); | 102 gfx::Size pref = layout->GetPreferredSize(&host); |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 layout->Layout(&host); | 230 layout->Layout(&host); |
| 232 ExpectViewBoundsEquals(0, 0, 100, 20, &v1); | 231 ExpectViewBoundsEquals(0, 0, 100, 20, &v1); |
| 233 ExpectViewBoundsEquals(0, 20, 10, 20, &v2); | 232 ExpectViewBoundsEquals(0, 20, 10, 20, &v2); |
| 234 ExpectViewBoundsEquals(50, 20, 10, 20, &v3); | 233 ExpectViewBoundsEquals(50, 20, 10, 20, &v3); |
| 235 | 234 |
| 236 RemoveAll(); | 235 RemoveAll(); |
| 237 } | 236 } |
| 238 | 237 |
| 239 | 238 |
| 240 TEST_F(GridLayoutTest, ColSpan4) { | 239 TEST_F(GridLayoutTest, ColSpan4) { |
| 241 views::ColumnSet* set = layout->AddColumnSet(0); | 240 ColumnSet* set = layout->AddColumnSet(0); |
| 242 | 241 |
| 243 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, | 242 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, |
| 244 GridLayout::USE_PREF, 0, 0); | 243 GridLayout::USE_PREF, 0, 0); |
| 245 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, | 244 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, 0, |
| 246 GridLayout::USE_PREF, 0, 0); | 245 GridLayout::USE_PREF, 0, 0); |
| 247 | 246 |
| 248 SettableSizeView v1(gfx::Size(10, 10)); | 247 SettableSizeView v1(gfx::Size(10, 10)); |
| 249 SettableSizeView v2(gfx::Size(10, 10)); | 248 SettableSizeView v2(gfx::Size(10, 10)); |
| 250 SettableSizeView v3(gfx::Size(25, 20)); | 249 SettableSizeView v3(gfx::Size(25, 20)); |
| 251 layout->StartRow(0, 0); | 250 layout->StartRow(0, 0); |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 host.SetBounds(0, 0, pref.width(), pref.height()); | 366 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 368 layout->Layout(&host); | 367 layout->Layout(&host); |
| 369 ExpectViewBoundsEquals(2, 1, 10, 20, &v1); | 368 ExpectViewBoundsEquals(2, 1, 10, 20, &v1); |
| 370 | 369 |
| 371 RemoveAll(); | 370 RemoveAll(); |
| 372 } | 371 } |
| 373 | 372 |
| 374 TEST_F(GridLayoutTest, FixedSize) { | 373 TEST_F(GridLayoutTest, FixedSize) { |
| 375 layout->SetInsets(2, 2, 2, 2); | 374 layout->SetInsets(2, 2, 2, 2); |
| 376 | 375 |
| 377 views::ColumnSet* set = layout->AddColumnSet(0); | 376 ColumnSet* set = layout->AddColumnSet(0); |
| 378 | 377 |
| 379 int column_count = 4; | 378 int column_count = 4; |
| 380 int title_width = 100; | 379 int title_width = 100; |
| 381 int row_count = 2; | 380 int row_count = 2; |
| 382 int pref_width = 10; | 381 int pref_width = 10; |
| 383 int pref_height = 20; | 382 int pref_height = 20; |
| 384 | 383 |
| 385 for (int i = 0; i < column_count; ++i) { | 384 for (int i = 0; i < column_count; ++i) { |
| 386 set->AddColumn(views::GridLayout::CENTER, | 385 set->AddColumn(GridLayout::CENTER, |
| 387 views::GridLayout::CENTER, | 386 GridLayout::CENTER, |
| 388 0, | 387 0, |
| 389 views::GridLayout::FIXED, | 388 GridLayout::FIXED, |
| 390 title_width, | 389 title_width, |
| 391 title_width); | 390 title_width); |
| 392 } | 391 } |
| 393 | 392 |
| 394 for (int row = 0; row < row_count; ++row) { | 393 for (int row = 0; row < row_count; ++row) { |
| 395 layout->StartRow(0, 0); | 394 layout->StartRow(0, 0); |
| 396 for (int col = 0; col < column_count; ++col) { | 395 for (int col = 0; col < column_count; ++col) { |
| 397 layout->AddView(new SettableSizeView(gfx::Size(pref_width, pref_height))); | 396 layout->AddView(new SettableSizeView(gfx::Size(pref_width, pref_height))); |
| 398 } | 397 } |
| 399 } | 398 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 410 pref_height, view); | 409 pref_height, view); |
| 411 } | 410 } |
| 412 } | 411 } |
| 413 | 412 |
| 414 GetPreferredSize(); | 413 GetPreferredSize(); |
| 415 EXPECT_EQ(gfx::Size(column_count * title_width + 4, | 414 EXPECT_EQ(gfx::Size(column_count * title_width + 4, |
| 416 row_count * pref_height + 4), pref); | 415 row_count * pref_height + 4), pref); |
| 417 } | 416 } |
| 418 | 417 |
| 419 TEST_F(GridLayoutTest, RowSpanWithPaddingRow) { | 418 TEST_F(GridLayoutTest, RowSpanWithPaddingRow) { |
| 420 views::ColumnSet* set = layout->AddColumnSet(0); | 419 ColumnSet* set = layout->AddColumnSet(0); |
| 421 | 420 |
| 422 set->AddColumn(views::GridLayout::CENTER, | 421 set->AddColumn(GridLayout::CENTER, |
| 423 views::GridLayout::CENTER, | 422 GridLayout::CENTER, |
| 424 0, | 423 0, |
| 425 views::GridLayout::FIXED, | 424 GridLayout::FIXED, |
| 426 10, | 425 10, |
| 427 10); | 426 10); |
| 428 | 427 |
| 429 layout->StartRow(0, 0); | 428 layout->StartRow(0, 0); |
| 430 layout->AddView(new SettableSizeView(gfx::Size(10, 10)), 1, 2); | 429 layout->AddView(new SettableSizeView(gfx::Size(10, 10)), 1, 2); |
| 431 layout->AddPaddingRow(0, 10); | 430 layout->AddPaddingRow(0, 10); |
| 432 } | 431 } |
| 433 | 432 |
| 434 TEST_F(GridLayoutTest, RowSpan) { | 433 TEST_F(GridLayoutTest, RowSpan) { |
| 435 views::ColumnSet* set = layout->AddColumnSet(0); | 434 ColumnSet* set = layout->AddColumnSet(0); |
| 436 | 435 |
| 437 set->AddColumn(views::GridLayout::LEADING, | 436 set->AddColumn(GridLayout::LEADING, |
| 438 views::GridLayout::LEADING, | 437 GridLayout::LEADING, |
| 439 0, | 438 0, |
| 440 views::GridLayout::USE_PREF, | 439 GridLayout::USE_PREF, |
| 441 0, | 440 0, |
| 442 0); | 441 0); |
| 443 set->AddColumn(views::GridLayout::LEADING, | 442 set->AddColumn(GridLayout::LEADING, |
| 444 views::GridLayout::LEADING, | 443 GridLayout::LEADING, |
| 445 0, | 444 0, |
| 446 views::GridLayout::USE_PREF, | 445 GridLayout::USE_PREF, |
| 447 0, | 446 0, |
| 448 0); | 447 0); |
| 449 | 448 |
| 450 layout->StartRow(0, 0); | 449 layout->StartRow(0, 0); |
| 451 layout->AddView(new SettableSizeView(gfx::Size(20, 10))); | 450 layout->AddView(new SettableSizeView(gfx::Size(20, 10))); |
| 452 layout->AddView(new SettableSizeView(gfx::Size(20, 40)), 1, 2); | 451 layout->AddView(new SettableSizeView(gfx::Size(20, 40)), 1, 2); |
| 453 layout->StartRow(1, 0); | 452 layout->StartRow(1, 0); |
| 454 views::View* s3 = new SettableSizeView(gfx::Size(20, 10)); | 453 View* s3 = new SettableSizeView(gfx::Size(20, 10)); |
| 455 layout->AddView(s3); | 454 layout->AddView(s3); |
| 456 | 455 |
| 457 GetPreferredSize(); | 456 GetPreferredSize(); |
| 458 EXPECT_EQ(gfx::Size(40, 40), pref); | 457 EXPECT_EQ(gfx::Size(40, 40), pref); |
| 459 | 458 |
| 460 host.SetBounds(0, 0, pref.width(), pref.height()); | 459 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 461 layout->Layout(&host); | 460 layout->Layout(&host); |
| 462 ExpectViewBoundsEquals(0, 10, 20, 10, s3); | 461 ExpectViewBoundsEquals(0, 10, 20, 10, s3); |
| 463 } | 462 } |
| 464 | 463 |
| 465 TEST_F(GridLayoutTest, RowSpan2) { | 464 TEST_F(GridLayoutTest, RowSpan2) { |
| 466 views::ColumnSet* set = layout->AddColumnSet(0); | 465 ColumnSet* set = layout->AddColumnSet(0); |
| 467 | 466 |
| 468 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 467 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 469 0, GridLayout::USE_PREF, 0, 0); | 468 0, GridLayout::USE_PREF, 0, 0); |
| 470 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 469 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 471 0,GridLayout::USE_PREF, 0, 0); | 470 0,GridLayout::USE_PREF, 0, 0); |
| 472 | 471 |
| 473 layout->StartRow(0, 0); | 472 layout->StartRow(0, 0); |
| 474 layout->AddView(new SettableSizeView(gfx::Size(20, 20))); | 473 layout->AddView(new SettableSizeView(gfx::Size(20, 20))); |
| 475 views::View* s3 = new SettableSizeView(gfx::Size(64, 64)); | 474 View* s3 = new SettableSizeView(gfx::Size(64, 64)); |
| 476 layout->AddView(s3, 1, 3); | 475 layout->AddView(s3, 1, 3); |
| 477 | 476 |
| 478 layout->AddPaddingRow(0, 10); | 477 layout->AddPaddingRow(0, 10); |
| 479 | 478 |
| 480 layout->StartRow(0, 0); | 479 layout->StartRow(0, 0); |
| 481 layout->AddView(new SettableSizeView(gfx::Size(10, 20))); | 480 layout->AddView(new SettableSizeView(gfx::Size(10, 20))); |
| 482 | 481 |
| 483 GetPreferredSize(); | 482 GetPreferredSize(); |
| 484 EXPECT_EQ(gfx::Size(84, 64), pref); | 483 EXPECT_EQ(gfx::Size(84, 64), pref); |
| 485 | 484 |
| 486 host.SetBounds(0, 0, pref.width(), pref.height()); | 485 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 487 layout->Layout(&host); | 486 layout->Layout(&host); |
| 488 ExpectViewBoundsEquals(20, 0, 64, 64, s3); | 487 ExpectViewBoundsEquals(20, 0, 64, 64, s3); |
| 489 } | 488 } |
| 490 | 489 |
| 491 TEST_F(GridLayoutTest, FixedViewWidth) { | 490 TEST_F(GridLayoutTest, FixedViewWidth) { |
| 492 views::ColumnSet* set = layout->AddColumnSet(0); | 491 ColumnSet* set = layout->AddColumnSet(0); |
| 493 | 492 |
| 494 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 493 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 495 0, GridLayout::USE_PREF, 0, 0); | 494 0, GridLayout::USE_PREF, 0, 0); |
| 496 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 495 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 497 0,GridLayout::USE_PREF, 0, 0); | 496 0,GridLayout::USE_PREF, 0, 0); |
| 498 | 497 |
| 499 layout->StartRow(0, 0); | 498 layout->StartRow(0, 0); |
| 500 View* view = new SettableSizeView(gfx::Size(30, 40)); | 499 View* view = new SettableSizeView(gfx::Size(30, 40)); |
| 501 layout->AddView(view, 1, 1, GridLayout::LEADING, GridLayout::LEADING, 10, 0); | 500 layout->AddView(view, 1, 1, GridLayout::LEADING, GridLayout::LEADING, 10, 0); |
| 502 | 501 |
| 503 GetPreferredSize(); | 502 GetPreferredSize(); |
| 504 EXPECT_EQ(10, pref.width()); | 503 EXPECT_EQ(10, pref.width()); |
| 505 EXPECT_EQ(40, pref.height()); | 504 EXPECT_EQ(40, pref.height()); |
| 506 | 505 |
| 507 host.SetBounds(0, 0, pref.width(), pref.height()); | 506 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 508 layout->Layout(&host); | 507 layout->Layout(&host); |
| 509 ExpectViewBoundsEquals(0, 0, 10, 40, view); | 508 ExpectViewBoundsEquals(0, 0, 10, 40, view); |
| 510 } | 509 } |
| 511 | 510 |
| 512 TEST_F(GridLayoutTest, FixedViewHeight) { | 511 TEST_F(GridLayoutTest, FixedViewHeight) { |
| 513 views::ColumnSet* set = layout->AddColumnSet(0); | 512 ColumnSet* set = layout->AddColumnSet(0); |
| 514 | 513 |
| 515 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 514 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 516 0, GridLayout::USE_PREF, 0, 0); | 515 0, GridLayout::USE_PREF, 0, 0); |
| 517 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, | 516 set->AddColumn(GridLayout::LEADING, GridLayout::LEADING, |
| 518 0,GridLayout::USE_PREF, 0, 0); | 517 0,GridLayout::USE_PREF, 0, 0); |
| 519 | 518 |
| 520 layout->StartRow(0, 0); | 519 layout->StartRow(0, 0); |
| 521 View* view = new SettableSizeView(gfx::Size(30, 40)); | 520 View* view = new SettableSizeView(gfx::Size(30, 40)); |
| 522 layout->AddView(view, 1, 1, GridLayout::LEADING, GridLayout::LEADING, 0, 10); | 521 layout->AddView(view, 1, 1, GridLayout::LEADING, GridLayout::LEADING, 0, 10); |
| 523 | 522 |
| 524 GetPreferredSize(); | 523 GetPreferredSize(); |
| 525 EXPECT_EQ(30, pref.width()); | 524 EXPECT_EQ(30, pref.width()); |
| 526 EXPECT_EQ(10, pref.height()); | 525 EXPECT_EQ(10, pref.height()); |
| 527 | 526 |
| 528 host.SetBounds(0, 0, pref.width(), pref.height()); | 527 host.SetBounds(0, 0, pref.width(), pref.height()); |
| 529 layout->Layout(&host); | 528 layout->Layout(&host); |
| 530 ExpectViewBoundsEquals(0, 0, 30, 10, view); | 529 ExpectViewBoundsEquals(0, 0, 30, 10, view); |
| 531 } | 530 } |
| 532 | 531 |
| 533 // Make sure that for views that span columns the underlying columns are resized | 532 // Make sure that for views that span columns the underlying columns are resized |
| 534 // based on the resize percent of the column. | 533 // based on the resize percent of the column. |
| 535 TEST_F(GridLayoutTest, ColumnSpanResizing) { | 534 TEST_F(GridLayoutTest, ColumnSpanResizing) { |
| 536 views::ColumnSet* set = layout->AddColumnSet(0); | 535 ColumnSet* set = layout->AddColumnSet(0); |
| 537 | 536 |
| 538 set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 537 set->AddColumn(GridLayout::FILL, GridLayout::CENTER, |
| 539 2, views::GridLayout::USE_PREF, 0, 0); | 538 2, GridLayout::USE_PREF, 0, 0); |
| 540 set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 539 set->AddColumn(GridLayout::FILL, GridLayout::CENTER, |
| 541 4, views::GridLayout::USE_PREF, 0, 0); | 540 4, GridLayout::USE_PREF, 0, 0); |
| 542 | 541 |
| 543 layout->StartRow(0, 0); | 542 layout->StartRow(0, 0); |
| 544 // span_view spans two columns and is twice as big the views added below. | 543 // span_view spans two columns and is twice as big the views added below. |
| 545 View* span_view = new SettableSizeView(gfx::Size(12, 40)); | 544 View* span_view = new SettableSizeView(gfx::Size(12, 40)); |
| 546 layout->AddView(span_view, 2, 1, GridLayout::LEADING, GridLayout::LEADING); | 545 layout->AddView(span_view, 2, 1, GridLayout::LEADING, GridLayout::LEADING); |
| 547 | 546 |
| 548 layout->StartRow(0, 0); | 547 layout->StartRow(0, 0); |
| 549 View* view1 = new SettableSizeView(gfx::Size(2, 40)); | 548 View* view1 = new SettableSizeView(gfx::Size(2, 40)); |
| 550 View* view2 = new SettableSizeView(gfx::Size(4, 40)); | 549 View* view2 = new SettableSizeView(gfx::Size(4, 40)); |
| 551 layout->AddView(view1); | 550 layout->AddView(view1); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 563 | 562 |
| 564 // And view2 should be 8 pixels wide: | 563 // And view2 should be 8 pixels wide: |
| 565 // 4 + (6 * 4 / 6). | 564 // 4 + (6 * 4 / 6). |
| 566 ExpectViewBoundsEquals(4, 40, 8, 40, view2); | 565 ExpectViewBoundsEquals(4, 40, 8, 40, view2); |
| 567 } | 566 } |
| 568 | 567 |
| 569 // Check that GetPreferredSize() takes resizing of columns into account when | 568 // Check that GetPreferredSize() takes resizing of columns into account when |
| 570 // there is additional space in the case we have column sets of different | 569 // there is additional space in the case we have column sets of different |
| 571 // preferred sizes. | 570 // preferred sizes. |
| 572 TEST_F(GridLayoutTest, ColumnResizingOnGetPreferredSize) { | 571 TEST_F(GridLayoutTest, ColumnResizingOnGetPreferredSize) { |
| 573 views::ColumnSet* set = layout->AddColumnSet(0); | 572 ColumnSet* set = layout->AddColumnSet(0); |
| 574 set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 573 set->AddColumn(GridLayout::FILL, GridLayout::CENTER, |
| 575 1, views::GridLayout::USE_PREF, 0, 0); | 574 1, GridLayout::USE_PREF, 0, 0); |
| 576 | 575 |
| 577 set = layout->AddColumnSet(1); | 576 set = layout->AddColumnSet(1); |
| 578 set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 577 set->AddColumn(GridLayout::FILL, GridLayout::CENTER, |
| 579 1, views::GridLayout::USE_PREF, 0, 0); | 578 1, GridLayout::USE_PREF, 0, 0); |
| 580 | 579 |
| 581 set = layout->AddColumnSet(2); | 580 set = layout->AddColumnSet(2); |
| 582 set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, | 581 set->AddColumn(GridLayout::FILL, GridLayout::CENTER, |
| 583 1, views::GridLayout::USE_PREF, 0, 0); | 582 1, GridLayout::USE_PREF, 0, 0); |
| 584 | 583 |
| 585 // Make a row containing a flexible view that trades width for height. | 584 // Make a row containing a flexible view that trades width for height. |
| 586 layout->StartRow(0, 0); | 585 layout->StartRow(0, 0); |
| 587 View* view1 = new FlexibleView(100); | 586 View* view1 = new FlexibleView(100); |
| 588 layout->AddView(view1, 1, 1, GridLayout::FILL, GridLayout::LEADING); | 587 layout->AddView(view1, 1, 1, GridLayout::FILL, GridLayout::LEADING); |
| 589 | 588 |
| 590 // The second row contains a view of fixed size that will enforce a column | 589 // The second row contains a view of fixed size that will enforce a column |
| 591 // width of 20 pixels. | 590 // width of 20 pixels. |
| 592 layout->StartRow(0, 1); | 591 layout->StartRow(0, 1); |
| 593 View* view2 = new SettableSizeView(gfx::Size(20, 20)); | 592 View* view2 = new SettableSizeView(gfx::Size(20, 20)); |
| 594 layout->AddView(view2, 1, 1, GridLayout::FILL, GridLayout::LEADING); | 593 layout->AddView(view2, 1, 1, GridLayout::FILL, GridLayout::LEADING); |
| 595 | 594 |
| 596 // Add another flexible view in row three in order to ensure column set | 595 // Add another flexible view in row three in order to ensure column set |
| 597 // ordering doesn't influence sizing behaviour. | 596 // ordering doesn't influence sizing behaviour. |
| 598 layout->StartRow(0, 2); | 597 layout->StartRow(0, 2); |
| 599 View* view3 = new FlexibleView(40); | 598 View* view3 = new FlexibleView(40); |
| 600 layout->AddView(view3, 1, 1, GridLayout::FILL, GridLayout::LEADING); | 599 layout->AddView(view3, 1, 1, GridLayout::FILL, GridLayout::LEADING); |
| 601 | 600 |
| 602 // We expect a height of 50: 30 from the variable width view in the first row | 601 // We expect a height of 50: 30 from the variable width view in the first row |
| 603 // plus 20 from the statically sized view in the second row. The flexible | 602 // plus 20 from the statically sized view in the second row. The flexible |
| 604 // view in the third row should contribute no height. | 603 // view in the third row should contribute no height. |
| 605 EXPECT_EQ(gfx::Size(20, 50), layout->GetPreferredSize(&host)); | 604 EXPECT_EQ(gfx::Size(20, 50), layout->GetPreferredSize(&host)); |
| 606 } | 605 } |
| 607 | 606 |
| 608 TEST_F(GridLayoutTest, MinimumPreferredSize) { | 607 TEST_F(GridLayoutTest, MinimumPreferredSize) { |
| 609 SettableSizeView v1(gfx::Size(10, 20)); | 608 SettableSizeView v1(gfx::Size(10, 20)); |
| 610 views::ColumnSet* set = layout->AddColumnSet(0); | 609 ColumnSet* set = layout->AddColumnSet(0); |
| 611 set->AddColumn(GridLayout::FILL, GridLayout::FILL, | 610 set->AddColumn(GridLayout::FILL, GridLayout::FILL, |
| 612 0, GridLayout::USE_PREF, 0, 0); | 611 0, GridLayout::USE_PREF, 0, 0); |
| 613 layout->StartRow(0, 0); | 612 layout->StartRow(0, 0); |
| 614 layout->AddView(&v1); | 613 layout->AddView(&v1); |
| 615 | 614 |
| 616 GetPreferredSize(); | 615 GetPreferredSize(); |
| 617 EXPECT_EQ(gfx::Size(10, 20), pref); | 616 EXPECT_EQ(gfx::Size(10, 20), pref); |
| 618 | 617 |
| 619 layout->set_minimum_size(gfx::Size(40, 40)); | 618 layout->set_minimum_size(gfx::Size(40, 40)); |
| 620 GetPreferredSize(); | 619 GetPreferredSize(); |
| 621 EXPECT_EQ(gfx::Size(40, 40), pref); | 620 EXPECT_EQ(gfx::Size(40, 40), pref); |
| 622 | 621 |
| 623 RemoveAll(); | 622 RemoveAll(); |
| 624 } | 623 } |
| 624 |
| 625 } // namespace views |
| OLD | NEW |