summaryrefslogtreecommitdiffstats
path: root/views/grid_layout.cc
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 /views/grid_layout.cc
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
Diffstat (limited to 'views/grid_layout.cc')
-rw-r--r--views/grid_layout.cc21
1 files changed, 12 insertions, 9 deletions
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) {