diff options
author | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-05 07:57:10 +0000 |
---|---|---|
committer | mnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-05 07:57:10 +0000 |
commit | f861719588545d92ba979f491f4cd10cbf544016 (patch) | |
tree | 5f5a64d4ba48a8d884ee360a562fb08371404ed6 /views/grid_layout_unittest.cc | |
parent | 84aa957953cf6eb36c4e8886a28aede5fd98f748 (diff) | |
download | chromium_src-f861719588545d92ba979f491f4cd10cbf544016.zip chromium_src-f861719588545d92ba979f491f4cd10cbf544016.tar.gz chromium_src-f861719588545d92ba979f491f4cd10cbf544016.tar.bz2 |
Re-land r51526
Auto-size the views version of the options dialog.
This adds support for auto-sizing tab controls, adjusts the options dialog to
use it and takes care of any fallout due to the new layout handling. Also fixes
a couple of small bugs in the views Layout() machinery and sanitizes layouting
of options pages.
BUG=36497
TEST=unit tests in tabbed_pane_unittest.cc and grid_layout_unittest.cc, as well as checking the options dialog in any supported language.
original issuse: http://codereview.chromium.org/2812026/show
Review URL: http://codereview.chromium.org/2883022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51628 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/grid_layout_unittest.cc')
-rw-r--r-- | views/grid_layout_unittest.cc | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/views/grid_layout_unittest.cc b/views/grid_layout_unittest.cc index c5e56fd..a70ae5f 100644 --- a/views/grid_layout_unittest.cc +++ b/views/grid_layout_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -32,6 +32,25 @@ class SettableSizeView : public View { gfx::Size pref_; }; +// A view with fixed circumference that trades height for width. +class FlexibleView : public View { + public: + explicit FlexibleView(int circumference) { + circumference_ = circumference; + } + + virtual gfx::Size GetPreferredSize() { + return gfx::Size(0, circumference_ / 2); + } + + virtual int GetHeightForWidth(int width) { + return std::max(0, circumference_ / 2 - width); + } + + private: + int circumference_; +}; + class GridLayoutTest : public testing::Test { public: virtual void SetUp() { @@ -548,3 +567,42 @@ TEST_F(GridLayoutTest, ColumnSpanResizing) { // 4 + (6 * 4 / 6). ExpectViewBoundsEquals(4, 40, 8, 40, view2); } + +// Check that GetPreferredSize() takes resizing of columns into account when +// there is additional space in the case we have column sets of different +// preferred sizes. +TEST_F(GridLayoutTest, ColumnResizingOnGetPreferredSize) { + views::ColumnSet* set = layout->AddColumnSet(0); + set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, + 1, views::GridLayout::USE_PREF, 0, 0); + + set = layout->AddColumnSet(1); + set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, + 1, views::GridLayout::USE_PREF, 0, 0); + + set = layout->AddColumnSet(2); + set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, + 1, views::GridLayout::USE_PREF, 0, 0); + + // Make a row containing a flexible view that trades width for height. + layout->StartRow(0, 0); + View* view1 = new FlexibleView(100); + layout->AddView(view1, 1, 1, GridLayout::FILL, GridLayout::LEADING); + + // The second row contains a view of fixed size that will enforce a column + // width of 20 pixels. + layout->StartRow(0, 1); + View* view2 = new SettableSizeView(gfx::Size(20, 20)); + layout->AddView(view2, 1, 1, GridLayout::FILL, GridLayout::LEADING); + + // Add another flexible view in row three in order to ensure column set + // ordering doesn't influence sizing behaviour. + layout->StartRow(0, 2); + View* view3 = new FlexibleView(40); + layout->AddView(view3, 1, 1, GridLayout::FILL, GridLayout::LEADING); + + // We expect a height of 50: 30 from the variable width view in the first row + // plus 20 from the statically sized view in the second row. The flexible + // view in the third row should contribute no height. + EXPECT_EQ(gfx::Size(20, 50), layout->GetPreferredSize(&host)); +} |