summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-24 22:17:03 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-24 22:17:03 +0000
commita665d47914ca6ded9dab9ca1c11f8eebf4eccfeb (patch)
tree85cf32659d670e02ba74176b5fb8a259fa55a442
parentd478b3f2db3a2c12694d8b318274fbb0c11327c8 (diff)
downloadchromium_src-a665d47914ca6ded9dab9ca1c11f8eebf4eccfeb.zip
chromium_src-a665d47914ca6ded9dab9ca1c11f8eebf4eccfeb.tar.gz
chromium_src-a665d47914ca6ded9dab9ca1c11f8eebf4eccfeb.tar.bz2
Changes grid layout such that if a view that spans columns preferred
width is bigger than the sum of preferred width of the views that don't span columns, then the extra space is distributed using the resize percent rather than evenly distributed. BUG=34156 TEST=none (covered by unit tests) Review URL: http://codereview.chromium.org/660001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39933 0039d316-1c4b-4281-b951-d872f2087c98
-rwxr-xr-xchrome/chrome_tests.gypi4
-rw-r--r--views/grid_layout.cc21
-rw-r--r--views/grid_layout_unittest.cc36
3 files changed, 48 insertions, 13 deletions
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index 88cb3cb..d377b95f 100755
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -25,9 +25,6 @@
'../views/focus/focus_manager_unittest.cc',
'../views/controls/label_unittest.cc',
'../views/controls/table/table_view_unittest.cc',
- ],
- 'views_unit_tests_sources_win_specific': [
- # TODO(jcampan): make the following tests work on Linux.
'../views/grid_layout_unittest.cc',
],
},
@@ -1021,7 +1018,6 @@
'test/data/resource.rc',
'<@(views_unit_tests_sources)',
- '<@(views_unit_tests_sources_win_specific)',
# TODO: It would be nice to have these pulled in
# automatically from direct_dependent_settings in
diff --git a/views/grid_layout.cc b/views/grid_layout.cc
index 9b44372..e2b00b1 100644
--- a/views/grid_layout.cc
+++ b/views/grid_layout.cc
@@ -545,8 +545,10 @@ void ColumnSet::DistributeRemainingWidth(ViewState* view_state) {
int pref_size_columns = 0;
int start_col = view_state->start_col;
int max_col = view_state->start_col + view_state->col_span;
+ float total_resize = 0;
for (int i = start_col; i < max_col; ++i) {
if (columns_[i]->IsResizable()) {
+ total_resize += columns_[i]->ResizePercent();
resizable_columns++;
} else if (columns_[i]->size_type_ == GridLayout::USE_PREF) {
pref_size_columns++;
@@ -554,16 +556,17 @@ void ColumnSet::DistributeRemainingWidth(ViewState* view_state) {
}
if (resizable_columns > 0) {
- // There are resizable columns, give the remaining width to them.
- int to_distribute = width / resizable_columns;
- for (int i = start_col; i < max_col; ++i) {
+ // There are resizable columns, give them the remaining width. The extra
+ // width is distributed using the resize values of each column.
+ int remaining_width = width;
+ for (int i = start_col, resize_i = 0; i < max_col; ++i) {
if (columns_[i]->IsResizable()) {
- width -= to_distribute;
- if (width < to_distribute) {
- // Give all slop to the last column.
- to_distribute += width;
- }
- columns_[i]->SetSize(columns_[i]->Size() + to_distribute);
+ resize_i++;
+ int delta = (resize_i == resizable_columns) ? remaining_width :
+ static_cast<int>(width * columns_[i]->ResizePercent() /
+ total_resize);
+ remaining_width -= delta;
+ columns_[i]->SetSize(columns_[i]->Size() + delta);
}
}
} else if (pref_size_columns > 0) {
diff --git a/views/grid_layout_unittest.cc b/views/grid_layout_unittest.cc
index 571030c..c5e56fd 100644
--- a/views/grid_layout_unittest.cc
+++ b/views/grid_layout_unittest.cc
@@ -512,3 +512,39 @@ TEST_F(GridLayoutTest, FixedViewHeight) {
layout->Layout(&host);
ExpectViewBoundsEquals(0, 0, 30, 10, view);
}
+
+// Make sure that for views that span columns the underlying columns are resized
+// based on the resize percent of the column.
+TEST_F(GridLayoutTest, ColumnSpanResizing) {
+ views::ColumnSet* set = layout->AddColumnSet(0);
+
+ set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
+ 2, views::GridLayout::USE_PREF, 0, 0);
+ set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER,
+ 4, views::GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0, 0);
+ // span_view spans two columns and is twice as big the views added below.
+ View* span_view = new SettableSizeView(gfx::Size(12, 40));
+ layout->AddView(span_view, 2, 1, GridLayout::LEADING, GridLayout::LEADING);
+
+ layout->StartRow(0, 0);
+ View* view1 = new SettableSizeView(gfx::Size(2, 40));
+ View* view2 = new SettableSizeView(gfx::Size(4, 40));
+ layout->AddView(view1);
+ layout->AddView(view2);
+
+ host.SetBounds(0, 0, 12, 80);
+ layout->Layout(&host);
+
+ ExpectViewBoundsEquals(0, 0, 12, 40, span_view);
+
+ // view1 should be 4 pixels wide
+ // column_pref + (remaining_width * column_resize / total_column_resize) =
+ // 2 + (6 * 2 / 6).
+ ExpectViewBoundsEquals(0, 40, 4, 40, view1);
+
+ // And view2 should be 8 pixels wide:
+ // 4 + (6 * 4 / 6).
+ ExpectViewBoundsEquals(4, 40, 8, 40, view2);
+}