Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1075)

Side by Side Diff: ui/views/layout/grid_layout.cc

Issue 2445513002: Remove stl_util's deletion function use from ui/views/. (Closed)
Patch Set: drop Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/layout/grid_layout.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 5 #include "ui/views/layout/grid_layout.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/stl_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "ui/views/layout/layout_constants.h" 12 #include "ui/views/layout/layout_constants.h"
13 #include "ui/views/view.h" 13 #include "ui/views/view.h"
14 #include "ui/views/window/dialog_delegate.h" 14 #include "ui/views/window/dialog_delegate.h"
15 15
16 namespace views { 16 namespace views {
17 17
18 // LayoutElement ------------------------------------------------------ 18 // LayoutElement ------------------------------------------------------
19 19
20 // A LayoutElement has a size and location along one axis. It contains 20 // A LayoutElement has a size and location along one axis. It contains
21 // methods that are used along both axis. 21 // methods that are used along both axis.
22 class LayoutElement { 22 class LayoutElement {
23 public: 23 public:
24 // Invokes ResetSize on all the layout elements. 24 // Invokes ResetSize on all the layout elements.
25 template <class T> 25 template <class T>
26 static void ResetSizes(std::vector<T*>* elements) { 26 static void ResetSizes(std::vector<std::unique_ptr<T>>* elements) {
27 // Reset the layout width of each column. 27 // Reset the layout width of each column.
28 for (typename std::vector<T*>::iterator i = elements->begin(); 28 for (const auto& element : *elements)
29 i != elements->end(); ++i) { 29 element->ResetSize();
30 (*i)->ResetSize();
31 }
32 } 30 }
33 31
34 // Sets the location of each element to be the sum of the sizes of the 32 // Sets the location of each element to be the sum of the sizes of the
35 // preceding elements. 33 // preceding elements.
36 template <class T> 34 template <class T>
37 static void CalculateLocationsFromSize(std::vector<T*>* elements) { 35 static void CalculateLocationsFromSize(
36 std::vector<std::unique_ptr<T>>* elements) {
38 // Reset the layout width of each column. 37 // Reset the layout width of each column.
39 int location = 0; 38 int location = 0;
40 for (typename std::vector<T*>::iterator i = elements->begin(); 39 for (const auto& element : *elements) {
41 i != elements->end(); ++i) { 40 element->SetLocation(location);
42 (*i)->SetLocation(location); 41 location += element->Size();
43 location += (*i)->Size();
44 } 42 }
45 } 43 }
46 44
47 // Distributes delta among the resizable elements. 45 // Distributes delta among the resizable elements.
48 // Each resizable element is given ResizePercent / total_percent * delta 46 // Each resizable element is given ResizePercent / total_percent * delta
49 // pixels extra of space. 47 // pixels extra of space.
50 template <class T> 48 template <class T>
51 static void DistributeDelta(int delta, std::vector<T*>* elements) { 49 static void DistributeDelta(int delta,
50 std::vector<std::unique_ptr<T>>* elements) {
52 if (delta == 0) 51 if (delta == 0)
53 return; 52 return;
54 53
55 float total_percent = 0; 54 float total_percent = 0;
56 int resize_count = 0; 55 int resize_count = 0;
57 for (typename std::vector<T*>::iterator i = elements->begin(); 56 for (const auto& element : *elements) {
58 i != elements->end(); ++i) { 57 total_percent += element->ResizePercent();
59 total_percent += (*i)->ResizePercent(); 58 if (element->ResizePercent() > 0)
60 if ((*i)->ResizePercent() > 0)
61 resize_count++; 59 resize_count++;
62 } 60 }
63 if (total_percent == 0) { 61 if (total_percent == 0) {
64 // None of the elements are resizable, return. 62 // None of the elements are resizable, return.
65 return; 63 return;
66 } 64 }
67 int remaining = delta; 65 int remaining = delta;
68 int resized = resize_count; 66 int resized = resize_count;
69 for (typename std::vector<T*>::iterator i = elements->begin(); 67 for (const auto& element : *elements) {
70 i != elements->end(); ++i) {
71 T* element = *i;
72 if (element->ResizePercent() > 0) { 68 if (element->ResizePercent() > 0) {
73 int to_give; 69 int to_give;
74 if (--resized == 0) { 70 if (--resized == 0) {
75 to_give = remaining; 71 to_give = remaining;
76 } else { 72 } else {
77 to_give = static_cast<int>(delta * 73 to_give = static_cast<int>(delta *
78 (element->resize_percent_ / total_percent)); 74 (element->resize_percent_ / total_percent));
79 remaining -= to_give; 75 remaining -= to_give;
80 } 76 }
81 element->SetSize(element->Size() + to_give); 77 element->SetSize(element->Size() + to_give);
82 } 78 }
83 } 79 }
84 } 80 }
85 81
86 // Returns the sum of the size of the elements from start to start + length. 82 // Returns the sum of the size of the elements from start to start + length.
87 template <class T> 83 template <class T>
88 static int TotalSize(int start, int length, std::vector<T*>* elements) { 84 static int TotalSize(int start,
85 int length,
86 std::vector<std::unique_ptr<T>>* elements) {
89 DCHECK(start >= 0 && length > 0 && 87 DCHECK(start >= 0 && length > 0 &&
90 start + length <= static_cast<int>(elements->size())); 88 start + length <= static_cast<int>(elements->size()));
91 int size = 0; 89 int size = 0;
92 for (int i = start, max = start + length; i < max; ++i) { 90 for (int i = start, max = start + length; i < max; ++i) {
93 size += (*elements)[i]->Size(); 91 size += (*elements)[i]->Size();
94 } 92 }
95 return size; 93 return size;
96 } 94 }
97 95
98 explicit LayoutElement(float resize_percent) 96 explicit LayoutElement(float resize_percent)
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // values for views originating in this column. 154 // values for views originating in this column.
157 class Column : public LayoutElement { 155 class Column : public LayoutElement {
158 public: 156 public:
159 Column(GridLayout::Alignment h_align, 157 Column(GridLayout::Alignment h_align,
160 GridLayout::Alignment v_align, 158 GridLayout::Alignment v_align,
161 float resize_percent, 159 float resize_percent,
162 GridLayout::SizeType size_type, 160 GridLayout::SizeType size_type,
163 int fixed_width, 161 int fixed_width,
164 int min_width, 162 int min_width,
165 bool is_padding) 163 bool is_padding)
166 : LayoutElement(resize_percent), 164 : LayoutElement(resize_percent),
167 h_align_(h_align), 165 h_align_(h_align),
168 v_align_(v_align), 166 v_align_(v_align),
169 size_type_(size_type), 167 size_type_(size_type),
170 same_size_column_(-1), 168 same_size_column_(-1),
171 fixed_width_(fixed_width), 169 fixed_width_(fixed_width),
172 min_width_(min_width), 170 min_width_(min_width),
173 is_padding_(is_padding), 171 is_padding_(is_padding),
174 master_column_(NULL) {} 172 master_column_(nullptr) {}
175 173
176 ~Column() override {} 174 ~Column() override {}
177 175
178 GridLayout::Alignment h_align() { return h_align_; } 176 GridLayout::Alignment h_align() { return h_align_; }
179 GridLayout::Alignment v_align() { return v_align_; } 177 GridLayout::Alignment v_align() { return v_align_; }
180 178
181 void ResetSize() override; 179 void ResetSize() override;
182 180
183 private: 181 private:
184 friend class ColumnSet; 182 friend class ColumnSet;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 215
218 void Column::ResetSize() { 216 void Column::ResetSize() {
219 if (size_type_ == GridLayout::FIXED) { 217 if (size_type_ == GridLayout::FIXED) {
220 SetSize(fixed_width_); 218 SetSize(fixed_width_);
221 } else { 219 } else {
222 SetSize(min_width_); 220 SetSize(min_width_);
223 } 221 }
224 } 222 }
225 223
226 Column* Column::GetLastMasterColumn() { 224 Column* Column::GetLastMasterColumn() {
227 if (master_column_ == NULL) { 225 if (master_column_ == nullptr) {
228 return NULL; 226 return nullptr;
229 } 227 }
230 if (master_column_ == this) { 228 if (master_column_ == this) {
231 return this; 229 return this;
232 } 230 }
233 return master_column_->GetLastMasterColumn(); 231 return master_column_->GetLastMasterColumn();
234 } 232 }
235 233
236 void Column::UnifySameSizedColumnSizes() { 234 void Column::UnifySameSizedColumnSizes() {
237 DCHECK(master_column_ == this); 235 DCHECK(master_column_ == this);
238 236
239 // Accumulate the size first. 237 // Accumulate the size first.
240 int size = 0; 238 int size = 0;
241 for (std::vector<Column*>::iterator i = same_size_columns_.begin(); 239 for (auto column : same_size_columns_)
242 i != same_size_columns_.end(); ++i) { 240 size = std::max(size, column->Size());
243 size = std::max(size, (*i)->Size());
244 }
245 241
246 // Then apply it. 242 // Then apply it.
247 for (std::vector<Column*>::iterator i = same_size_columns_.begin(); 243 for (auto column : same_size_columns_)
248 i != same_size_columns_.end(); ++i) { 244 column->SetSize(size);
249 (*i)->SetSize(size);
250 }
251 } 245 }
252 246
253 void Column::AdjustSize(int size) { 247 void Column::AdjustSize(int size) {
254 if (size_type_ == GridLayout::USE_PREF) 248 if (size_type_ == GridLayout::USE_PREF)
255 LayoutElement::AdjustSize(size); 249 LayoutElement::AdjustSize(size);
256 } 250 }
257 251
258 // Row ------------------------------------------------------------- 252 // Row -------------------------------------------------------------
259 253
260 class Row : public LayoutElement { 254 class Row : public LayoutElement {
(...skipping 10 matching lines...) Expand all
271 265
272 void ResetSize() override { 266 void ResetSize() override {
273 max_ascent_ = max_descent_ = 0; 267 max_ascent_ = max_descent_ = 0;
274 SetSize(height_); 268 SetSize(height_);
275 } 269 }
276 270
277 ColumnSet* column_set() { 271 ColumnSet* column_set() {
278 return column_set_; 272 return column_set_;
279 } 273 }
280 274
281 // Adjusts the size to accomodate the specified ascent/descent. 275 // Adjusts the size to accommodate the specified ascent/descent.
282 void AdjustSizeForBaseline(int ascent, int descent) { 276 void AdjustSizeForBaseline(int ascent, int descent) {
283 max_ascent_ = std::max(ascent, max_ascent_); 277 max_ascent_ = std::max(ascent, max_ascent_);
284 max_descent_ = std::max(descent, max_descent_); 278 max_descent_ = std::max(descent, max_descent_);
285 AdjustSize(max_ascent_ + max_descent_); 279 AdjustSize(max_ascent_ + max_descent_);
286 } 280 }
287 281
288 int max_ascent() const { 282 int max_ascent() const {
289 return max_ascent_; 283 return max_ascent_;
290 } 284 }
291 285
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 351
358 // The baseline. Only used if the view is vertically aligned along the 352 // The baseline. Only used if the view is vertically aligned along the
359 // baseline. 353 // baseline.
360 int baseline; 354 int baseline;
361 }; 355 };
362 356
363 static bool CompareByColumnSpan(const ViewState* v1, const ViewState* v2) { 357 static bool CompareByColumnSpan(const ViewState* v1, const ViewState* v2) {
364 return v1->col_span < v2->col_span; 358 return v1->col_span < v2->col_span;
365 } 359 }
366 360
367 static bool CompareByRowSpan(const ViewState* v1, const ViewState* v2) { 361 static bool CompareByRowSpan(const std::unique_ptr<ViewState>& v1,
362 const ViewState* v2) {
368 return v1->row_span < v2->row_span; 363 return v1->row_span < v2->row_span;
369 } 364 }
370 365
371 // ColumnSet ------------------------------------------------------------- 366 // ColumnSet -------------------------------------------------------------
372 367
373 ColumnSet::ColumnSet(int id) : id_(id) { 368 ColumnSet::ColumnSet(int id) : id_(id) {
374 } 369 }
375 370
376 ColumnSet::~ColumnSet() { 371 ColumnSet::~ColumnSet() {
377 base::STLDeleteElements(&columns_);
378 } 372 }
379 373
380 void ColumnSet::AddPaddingColumn(float resize_percent, int width) { 374 void ColumnSet::AddPaddingColumn(float resize_percent, int width) {
381 AddColumn(GridLayout::FILL, GridLayout::FILL, resize_percent, 375 AddColumn(GridLayout::FILL, GridLayout::FILL, resize_percent,
382 GridLayout::FIXED, width, width, true); 376 GridLayout::FIXED, width, width, true);
383 } 377 }
384 378
385 void ColumnSet::AddColumn(GridLayout::Alignment h_align, 379 void ColumnSet::AddColumn(GridLayout::Alignment h_align,
386 GridLayout::Alignment v_align, 380 GridLayout::Alignment v_align,
387 float resize_percent, 381 float resize_percent,
(...skipping 18 matching lines...) Expand all
406 va_end(marker); 400 va_end(marker);
407 } 401 }
408 402
409 void ColumnSet::AddColumn(GridLayout::Alignment h_align, 403 void ColumnSet::AddColumn(GridLayout::Alignment h_align,
410 GridLayout::Alignment v_align, 404 GridLayout::Alignment v_align,
411 float resize_percent, 405 float resize_percent,
412 GridLayout::SizeType size_type, 406 GridLayout::SizeType size_type,
413 int fixed_width, 407 int fixed_width,
414 int min_width, 408 int min_width,
415 bool is_padding) { 409 bool is_padding) {
416 Column* column = new Column(h_align, v_align, resize_percent, size_type, 410 columns_.push_back(base::MakeUnique<Column>(h_align, v_align, resize_percent,
417 fixed_width, min_width, is_padding); 411 size_type, fixed_width, min_width,
418 columns_.push_back(column); 412 is_padding));
419 } 413 }
420 414
421 void ColumnSet::AddViewState(ViewState* view_state) { 415 void ColumnSet::AddViewState(ViewState* view_state) {
422 // view_states are ordered by column_span (in ascending order). 416 // view_states are ordered by column_span (in ascending order).
423 std::vector<ViewState*>::iterator i = std::lower_bound(view_states_.begin(), 417 auto i = std::lower_bound(view_states_.begin(), view_states_.end(),
424 view_states_.end(), 418 view_state, CompareByColumnSpan);
425 view_state,
426 CompareByColumnSpan);
427 view_states_.insert(i, view_state); 419 view_states_.insert(i, view_state);
428 } 420 }
429 421
430 void ColumnSet::CalculateMasterColumns() { 422 void ColumnSet::CalculateMasterColumns() {
431 for (std::vector<Column*>::iterator i = columns_.begin(); 423 for (const auto& column : columns_) {
432 i != columns_.end(); ++i) {
433 Column* column = *i;
434 int same_size_column_index = column->same_size_column_; 424 int same_size_column_index = column->same_size_column_;
435 if (same_size_column_index != -1) { 425 if (same_size_column_index != -1) {
436 DCHECK(same_size_column_index >= 0 && 426 DCHECK(same_size_column_index >= 0 &&
437 same_size_column_index < static_cast<int>(columns_.size())); 427 same_size_column_index < static_cast<int>(columns_.size()));
438 Column* master_column = column->master_column_; 428 Column* master_column = column->master_column_;
439 Column* same_size_column = columns_[same_size_column_index]; 429 Column* same_size_column = columns_[same_size_column_index].get();
440 Column* same_size_column_master = same_size_column->master_column_; 430 Column* same_size_column_master = same_size_column->master_column_;
441 if (master_column == NULL) { 431 if (master_column == nullptr) {
442 // Current column is not linked to any other column. 432 // Current column is not linked to any other column.
443 if (same_size_column_master == NULL) { 433 if (same_size_column_master == nullptr) {
444 // Both columns are not linked. 434 // Both columns are not linked.
445 column->master_column_ = column; 435 column->master_column_ = column.get();
446 same_size_column->master_column_ = column; 436 same_size_column->master_column_ = column.get();
447 column->same_size_columns_.push_back(same_size_column); 437 column->same_size_columns_.push_back(same_size_column);
448 column->same_size_columns_.push_back(column); 438 column->same_size_columns_.push_back(column.get());
449 } else { 439 } else {
450 // Column to link to is linked with other columns. 440 // Column to link to is linked with other columns.
451 // Add current column to list of linked columns in other columns 441 // Add current column to list of linked columns in other columns
452 // master column. 442 // master column.
453 same_size_column->GetLastMasterColumn()-> 443 same_size_column->GetLastMasterColumn()->same_size_columns_.push_back(
454 same_size_columns_.push_back(column); 444 column.get());
455 // And update the master column for the current column to that 445 // And update the master column for the current column to that
456 // of the same sized column. 446 // of the same sized column.
457 column->master_column_ = same_size_column; 447 column->master_column_ = same_size_column;
458 } 448 }
459 } else { 449 } else {
460 // Current column is already linked with another column. 450 // Current column is already linked with another column.
461 if (same_size_column_master == NULL) { 451 if (same_size_column_master == nullptr) {
462 // Column to link with is not linked to any other columns. 452 // Column to link with is not linked to any other columns.
463 // Update it's master_column. 453 // Update it's master_column.
464 same_size_column->master_column_ = column; 454 same_size_column->master_column_ = column.get();
465 // Add linked column to list of linked column. 455 // Add linked column to list of linked column.
466 column->GetLastMasterColumn()->same_size_columns_. 456 column->GetLastMasterColumn()->same_size_columns_.
467 push_back(same_size_column); 457 push_back(same_size_column);
468 } else if (column->GetLastMasterColumn() != 458 } else if (column->GetLastMasterColumn() !=
469 same_size_column->GetLastMasterColumn()) { 459 same_size_column->GetLastMasterColumn()) {
470 // The two columns are already linked with other columns. 460 // The two columns are already linked with other columns.
471 std::vector<Column*>* same_size_columns = 461 std::vector<Column*>* same_size_columns =
472 &(column->GetLastMasterColumn()->same_size_columns_); 462 &(column->GetLastMasterColumn()->same_size_columns_);
473 std::vector<Column*>* other_same_size_columns = 463 std::vector<Column*>* other_same_size_columns =
474 &(same_size_column->GetLastMasterColumn()->same_size_columns_); 464 &(same_size_column->GetLastMasterColumn()->same_size_columns_);
475 // Add all the columns from the others master to current columns 465 // Add all the columns from the others master to current columns
476 // master. 466 // master.
477 same_size_columns->insert(same_size_columns->end(), 467 same_size_columns->insert(same_size_columns->end(),
478 other_same_size_columns->begin(), 468 other_same_size_columns->begin(),
479 other_same_size_columns->end()); 469 other_same_size_columns->end());
480 // The other master is no longer a master, clear its vector of 470 // The other master is no longer a master, clear its vector of
481 // linked columns, and reset its master_column. 471 // linked columns, and reset its master_column.
482 other_same_size_columns->clear(); 472 other_same_size_columns->clear();
483 same_size_column->GetLastMasterColumn()->master_column_ = column; 473 same_size_column->GetLastMasterColumn()->master_column_ =
474 column.get();
484 } 475 }
485 } 476 }
486 } 477 }
487 } 478 }
488 AccumulateMasterColumns(); 479 AccumulateMasterColumns();
489 } 480 }
490 481
491 void ColumnSet::AccumulateMasterColumns() { 482 void ColumnSet::AccumulateMasterColumns() {
492 DCHECK(master_columns_.empty()); 483 DCHECK(master_columns_.empty());
493 for (std::vector<Column*>::iterator i = columns_.begin(); 484 for (const auto& column : columns_) {
494 i != columns_.end(); ++i) {
495 Column* column = *i;
496 Column* master_column = column->GetLastMasterColumn(); 485 Column* master_column = column->GetLastMasterColumn();
497 if (master_column && 486 if (master_column &&
498 std::find(master_columns_.begin(), master_columns_.end(), 487 std::find(master_columns_.begin(), master_columns_.end(),
499 master_column) == master_columns_.end()) { 488 master_column) == master_columns_.end()) {
500 master_columns_.push_back(master_column); 489 master_columns_.push_back(master_column);
501 } 490 }
502 // At this point, GetLastMasterColumn may not == master_column 491 // At this point, GetLastMasterColumn may not == master_column
503 // (may have to go through a few Columns)_. Reset master_column to 492 // (may have to go through a few Columns)_. Reset master_column to
504 // avoid hops. 493 // avoid hops.
505 column->master_column_ = master_column; 494 column->master_column_ = master_column;
506 } 495 }
507 } 496 }
508 497
509 void ColumnSet::UnifySameSizedColumnSizes() { 498 void ColumnSet::UnifySameSizedColumnSizes() {
510 for (std::vector<Column*>::iterator i = master_columns_.begin(); 499 for (auto column : master_columns_)
511 i != master_columns_.end(); ++i) { 500 column->UnifySameSizedColumnSizes();
512 (*i)->UnifySameSizedColumnSizes();
513 }
514 } 501 }
515 502
516 void ColumnSet::UpdateRemainingWidth(ViewState* view_state) { 503 void ColumnSet::UpdateRemainingWidth(ViewState* view_state) {
517 for (int i = view_state->start_col, 504 for (int i = view_state->start_col,
518 max_col = view_state->start_col + view_state->col_span; 505 max_col = view_state->start_col + view_state->col_span;
519 i < max_col; ++i) { 506 i < max_col; ++i) {
520 view_state->remaining_width -= columns_[i]->Size(); 507 view_state->remaining_width -= columns_[i]->Size();
521 } 508 }
522 } 509 }
523 510
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 if (width < to_distribute) 559 if (width < to_distribute)
573 to_distribute += width; 560 to_distribute += width;
574 columns_[i]->SetSize(columns_[i]->Size() + to_distribute); 561 columns_[i]->SetSize(columns_[i]->Size() + to_distribute);
575 } 562 }
576 } 563 }
577 } 564 }
578 } 565 }
579 566
580 int ColumnSet::LayoutWidth() { 567 int ColumnSet::LayoutWidth() {
581 int width = 0; 568 int width = 0;
582 for (std::vector<Column*>::iterator i = columns_.begin(); 569 for (const auto& column : columns_)
583 i != columns_.end(); ++i) { 570 width += column->Size();
584 width += (*i)->Size(); 571
585 }
586 return width; 572 return width;
587 } 573 }
588 574
589 int ColumnSet::GetColumnWidth(int start_col, int col_span) { 575 int ColumnSet::GetColumnWidth(int start_col, int col_span) {
590 return LayoutElement::TotalSize(start_col, col_span, &columns_); 576 return LayoutElement::TotalSize(start_col, col_span, &columns_);
591 } 577 }
592 578
593 void ColumnSet::ResetColumnXCoordinates() { 579 void ColumnSet::ResetColumnXCoordinates() {
594 LayoutElement::CalculateLocationsFromSize(&columns_); 580 LayoutElement::CalculateLocationsFromSize(&columns_);
595 } 581 }
596 582
597 void ColumnSet::CalculateSize() { 583 void ColumnSet::CalculateSize() {
598 gfx::Size pref; 584 gfx::Size pref;
599 // Reset the preferred and remaining sizes. 585 // Reset the preferred and remaining sizes.
600 for (std::vector<ViewState*>::iterator i = view_states_.begin(); 586 for (const auto& view_state : view_states_) {
601 i != view_states_.end(); ++i) {
602 ViewState* view_state = *i;
603 if (!view_state->pref_width_fixed || !view_state->pref_height_fixed) { 587 if (!view_state->pref_width_fixed || !view_state->pref_height_fixed) {
604 pref = view_state->view->GetPreferredSize(); 588 pref = view_state->view->GetPreferredSize();
605 if (!view_state->pref_width_fixed) 589 if (!view_state->pref_width_fixed)
606 view_state->pref_width = pref.width(); 590 view_state->pref_width = pref.width();
607 if (!view_state->pref_height_fixed) 591 if (!view_state->pref_height_fixed)
608 view_state->pref_height = pref.height(); 592 view_state->pref_height = pref.height();
609 } 593 }
610 view_state->remaining_width = pref.width(); 594 view_state->remaining_width = pref.width();
611 view_state->remaining_height = pref.height(); 595 view_state->remaining_height = pref.height();
612 } 596 }
613 597
614 // Let layout element reset the sizes for us. 598 // Let layout element reset the sizes for us.
615 LayoutElement::ResetSizes(&columns_); 599 LayoutElement::ResetSizes(&columns_);
616 600
617 // Distribute the size of each view with a col span == 1. 601 // Distribute the size of each view with a col span == 1.
618 std::vector<ViewState*>::iterator view_state_iterator = 602 auto view_state_iterator = view_states_.begin();
619 view_states_.begin();
620 for (; view_state_iterator != view_states_.end() && 603 for (; view_state_iterator != view_states_.end() &&
621 (*view_state_iterator)->col_span == 1; ++view_state_iterator) { 604 (*view_state_iterator)->col_span == 1; ++view_state_iterator) {
622 ViewState* view_state = *view_state_iterator; 605 ViewState* view_state = *view_state_iterator;
623 Column* column = columns_[view_state->start_col]; 606 Column* column = columns_[view_state->start_col].get();
624 column->AdjustSize(view_state->pref_width); 607 column->AdjustSize(view_state->pref_width);
625 view_state->remaining_width -= column->Size(); 608 view_state->remaining_width -= column->Size();
626 } 609 }
627 610
628 // Make sure all linked columns have the same size. 611 // Make sure all linked columns have the same size.
629 UnifySameSizedColumnSizes(); 612 UnifySameSizedColumnSizes();
630 613
631 // Distribute the size of each view with a column span > 1. 614 // Distribute the size of each view with a column span > 1.
632 for (; view_state_iterator != view_states_.end(); ++view_state_iterator) { 615 for (; view_state_iterator != view_states_.end(); ++view_state_iterator) {
633 ViewState* view_state = *view_state_iterator; 616 ViewState* view_state = *view_state_iterator;
(...skipping 15 matching lines...) Expand all
649 } 632 }
650 633
651 // GridLayout ------------------------------------------------------------- 634 // GridLayout -------------------------------------------------------------
652 635
653 GridLayout::GridLayout(View* host) 636 GridLayout::GridLayout(View* host)
654 : host_(host), 637 : host_(host),
655 calculated_master_columns_(false), 638 calculated_master_columns_(false),
656 remaining_row_span_(0), 639 remaining_row_span_(0),
657 current_row_(-1), 640 current_row_(-1),
658 next_column_(0), 641 next_column_(0),
659 current_row_col_set_(NULL), 642 current_row_col_set_(nullptr),
660 adding_view_(false) { 643 adding_view_(false) {
661 DCHECK(host); 644 DCHECK(host);
662 } 645 }
663 646
664 GridLayout::~GridLayout() { 647 GridLayout::~GridLayout() {
665 base::STLDeleteElements(&column_sets_);
666 base::STLDeleteElements(&view_states_);
667 base::STLDeleteElements(&rows_);
668 } 648 }
669 649
670 // static 650 // static
671 GridLayout* GridLayout::CreatePanel(View* host) { 651 GridLayout* GridLayout::CreatePanel(View* host) {
672 GridLayout* layout = new GridLayout(host); 652 GridLayout* layout = new GridLayout(host);
673 layout->SetInsets(kPanelVertMargin, kButtonHEdgeMarginNew, 653 layout->SetInsets(kPanelVertMargin, kButtonHEdgeMarginNew,
674 kPanelVertMargin, kButtonHEdgeMarginNew); 654 kPanelVertMargin, kButtonHEdgeMarginNew);
675 return layout; 655 return layout;
676 } 656 }
677 657
678 void GridLayout::SetInsets(int top, int left, int bottom, int right) { 658 void GridLayout::SetInsets(int top, int left, int bottom, int right) {
679 insets_.Set(top, left, bottom, right); 659 insets_.Set(top, left, bottom, right);
680 } 660 }
681 661
682 void GridLayout::SetInsets(const gfx::Insets& insets) { 662 void GridLayout::SetInsets(const gfx::Insets& insets) {
683 insets_ = insets; 663 insets_ = insets;
684 } 664 }
685 665
686 ColumnSet* GridLayout::AddColumnSet(int id) { 666 ColumnSet* GridLayout::AddColumnSet(int id) {
687 DCHECK(GetColumnSet(id) == NULL); 667 DCHECK(GetColumnSet(id) == nullptr);
688 ColumnSet* column_set = new ColumnSet(id); 668 column_sets_.push_back(base::WrapUnique(new ColumnSet(id)));
689 column_sets_.push_back(column_set); 669 return column_sets_.back().get();
690 return column_set;
691 } 670 }
692 671
693 ColumnSet* GridLayout::GetColumnSet(int id) { 672 ColumnSet* GridLayout::GetColumnSet(int id) {
694 for (std::vector<ColumnSet*>::iterator i = column_sets_.begin(); 673 for (const auto& column_set : column_sets_) {
695 i != column_sets_.end(); ++i) { 674 if (column_set->id_ == id) {
696 if ((*i)->id_ == id) { 675 return column_set.get();
697 return *i;
698 } 676 }
699 } 677 }
700 return NULL; 678 return nullptr;
701 } 679 }
702 680
703 void GridLayout::StartRowWithPadding(float vertical_resize, int column_set_id, 681 void GridLayout::StartRowWithPadding(float vertical_resize, int column_set_id,
704 float padding_resize, int padding) { 682 float padding_resize, int padding) {
705 AddPaddingRow(padding_resize, padding); 683 AddPaddingRow(padding_resize, padding);
706 StartRow(vertical_resize, column_set_id); 684 StartRow(vertical_resize, column_set_id);
707 } 685 }
708 686
709 void GridLayout::StartRow(float vertical_resize, int column_set_id) { 687 void GridLayout::StartRow(float vertical_resize, int column_set_id) {
710 ColumnSet* column_set = GetColumnSet(column_set_id); 688 ColumnSet* column_set = GetColumnSet(column_set_id);
711 DCHECK(column_set); 689 DCHECK(column_set);
712 AddRow(new Row(0, vertical_resize, column_set)); 690 AddRow(base::MakeUnique<Row>(0, vertical_resize, column_set));
713 } 691 }
714 692
715 void GridLayout::AddPaddingRow(float vertical_resize, int pixel_count) { 693 void GridLayout::AddPaddingRow(float vertical_resize, int pixel_count) {
716 AddRow(new Row(pixel_count, vertical_resize, NULL)); 694 AddRow(base::MakeUnique<Row>(pixel_count, vertical_resize, nullptr));
717 } 695 }
718 696
719 void GridLayout::SkipColumns(int col_count) { 697 void GridLayout::SkipColumns(int col_count) {
720 DCHECK(col_count > 0); 698 DCHECK(col_count > 0);
721 next_column_ += col_count; 699 next_column_ += col_count;
722 DCHECK(current_row_col_set_ && 700 DCHECK(current_row_col_set_ &&
723 next_column_ <= current_row_col_set_->num_columns()); 701 next_column_ <= current_row_col_set_->num_columns());
724 SkipPaddingColumns(); 702 SkipPaddingColumns();
725 } 703 }
726 704
727 void GridLayout::AddView(View* view) { 705 void GridLayout::AddView(View* view) {
728 AddView(view, 1, 1); 706 AddView(view, 1, 1);
729 } 707 }
730 708
731 void GridLayout::AddView(View* view, int col_span, int row_span) { 709 void GridLayout::AddView(View* view, int col_span, int row_span) {
732 DCHECK(current_row_col_set_ && 710 DCHECK(current_row_col_set_ &&
733 next_column_ < current_row_col_set_->num_columns()); 711 next_column_ < current_row_col_set_->num_columns());
734 Column* column = current_row_col_set_->columns_[next_column_]; 712 Column* column = current_row_col_set_->columns_[next_column_].get();
735 AddView(view, col_span, row_span, column->h_align(), column->v_align()); 713 AddView(view, col_span, row_span, column->h_align(), column->v_align());
736 } 714 }
737 715
738 void GridLayout::AddView(View* view, int col_span, int row_span, 716 void GridLayout::AddView(View* view, int col_span, int row_span,
739 Alignment h_align, Alignment v_align) { 717 Alignment h_align, Alignment v_align) {
740 AddView(view, col_span, row_span, h_align, v_align, 0, 0); 718 AddView(view, col_span, row_span, h_align, v_align, 0, 0);
741 } 719 }
742 720
743 void GridLayout::AddView(View* view, int col_span, int row_span, 721 void GridLayout::AddView(View* view, int col_span, int row_span,
744 Alignment h_align, Alignment v_align, 722 Alignment h_align, Alignment v_align,
745 int pref_width, int pref_height) { 723 int pref_width, int pref_height) {
746 DCHECK(current_row_col_set_ && col_span > 0 && row_span > 0 && 724 DCHECK(current_row_col_set_ && col_span > 0 && row_span > 0 &&
747 (next_column_ + col_span) <= current_row_col_set_->num_columns()); 725 (next_column_ + col_span) <= current_row_col_set_->num_columns());
748 // We don't support baseline alignment of views spanning rows. Please add if 726 // We don't support baseline alignment of views spanning rows. Please add if
749 // you need it. 727 // you need it.
750 DCHECK(v_align != BASELINE || row_span == 1); 728 DCHECK(v_align != BASELINE || row_span == 1);
751 ViewState* state = 729 AddViewState(base::MakeUnique<ViewState>(
752 new ViewState(current_row_col_set_, view, next_column_, current_row_, 730 current_row_col_set_, view, next_column_, current_row_, col_span,
753 col_span, row_span, h_align, v_align, pref_width, 731 row_span, h_align, v_align, pref_width, pref_height));
754 pref_height);
755 AddViewState(state);
756 } 732 }
757 733
758 static void CalculateSize(int pref_size, GridLayout::Alignment alignment, 734 static void CalculateSize(int pref_size, GridLayout::Alignment alignment,
759 int* location, int* size) { 735 int* location, int* size) {
760 if (alignment != GridLayout::FILL) { 736 if (alignment != GridLayout::FILL) {
761 int available_size = *size; 737 int available_size = *size;
762 *size = std::min(*size, pref_size); 738 *size = std::min(*size, pref_size);
763 switch (alignment) { 739 switch (alignment) {
764 case GridLayout::LEADING: 740 case GridLayout::LEADING:
765 // Nothing to do, location already points to start. 741 // Nothing to do, location already points to start.
(...skipping 26 matching lines...) Expand all
792 } 768 }
793 769
794 void GridLayout::Layout(View* host) { 770 void GridLayout::Layout(View* host) {
795 DCHECK(host_ == host); 771 DCHECK(host_ == host);
796 // SizeRowsAndColumns sets the size and location of each row/column, but 772 // SizeRowsAndColumns sets the size and location of each row/column, but
797 // not of the views. 773 // not of the views.
798 gfx::Size pref; 774 gfx::Size pref;
799 SizeRowsAndColumns(true, host_->width(), host_->height(), &pref); 775 SizeRowsAndColumns(true, host_->width(), host_->height(), &pref);
800 776
801 // Size each view. 777 // Size each view.
802 for (std::vector<ViewState*>::iterator i = view_states_.begin(); 778 for (const auto& view_state : view_states_) {
803 i != view_states_.end(); ++i) {
804 ViewState* view_state = *i;
805 ColumnSet* column_set = view_state->column_set; 779 ColumnSet* column_set = view_state->column_set;
806 View* view = (*i)->view; 780 View* view = view_state->view;
807 DCHECK(view); 781 DCHECK(view);
808 int x = column_set->columns_[view_state->start_col]->Location() + 782 int x = column_set->columns_[view_state->start_col]->Location() +
809 insets_.left(); 783 insets_.left();
810 int width = column_set->GetColumnWidth(view_state->start_col, 784 int width = column_set->GetColumnWidth(view_state->start_col,
811 view_state->col_span); 785 view_state->col_span);
812 CalculateSize(view_state->pref_width, view_state->h_align, 786 CalculateSize(view_state->pref_width, view_state->h_align,
813 &x, &width); 787 &x, &width);
814 int y = rows_[view_state->start_row]->Location() + insets_.top(); 788 int y = rows_[view_state->start_row]->Location() + insets_.top();
815 int height = LayoutElement::TotalSize(view_state->start_row, 789 int height = LayoutElement::TotalSize(view_state->start_row,
816 view_state->row_span, &rows_); 790 view_state->row_span, &rows_);
(...skipping 27 matching lines...) Expand all
844 gfx::Size* pref) const { 818 gfx::Size* pref) const {
845 // Make sure the master columns have been calculated. 819 // Make sure the master columns have been calculated.
846 CalculateMasterColumnsIfNecessary(); 820 CalculateMasterColumnsIfNecessary();
847 pref->SetSize(0, 0); 821 pref->SetSize(0, 0);
848 if (rows_.empty()) 822 if (rows_.empty())
849 return; 823 return;
850 824
851 // Calculate the preferred width of each of the columns. Some views' 825 // Calculate the preferred width of each of the columns. Some views'
852 // preferred heights are derived from their width, as such we need to 826 // preferred heights are derived from their width, as such we need to
853 // calculate the size of the columns first. 827 // calculate the size of the columns first.
854 for (std::vector<ColumnSet*>::iterator i = column_sets_.begin(); 828 for (const auto& column_set : column_sets_) {
855 i != column_sets_.end(); ++i) { 829 column_set->CalculateSize();
856 (*i)->CalculateSize(); 830 pref->set_width(std::max(pref->width(), column_set->LayoutWidth()));
857 pref->set_width(std::max(pref->width(), (*i)->LayoutWidth()));
858 } 831 }
859 pref->set_width(pref->width() + insets_.width()); 832 pref->set_width(pref->width() + insets_.width());
860 833
861 // Go over the columns again and set them all to the size we settled for. 834 // Go over the columns again and set them all to the size we settled for.
862 width = width ? width : pref->width(); 835 width = width ? width : pref->width();
863 for (std::vector<ColumnSet*>::iterator i = column_sets_.begin(); 836 for (const auto& column_set : column_sets_) {
864 i != column_sets_.end(); ++i) { 837 // We're doing a layout, divvy up any extra space.
865 // We're doing a layout, divy up any extra space. 838 column_set->Resize(width - column_set->LayoutWidth() - insets_.left() -
866 (*i)->Resize(width - (*i)->LayoutWidth() - insets_.left() - 839 insets_.right());
867 insets_.right());
868 // And reset the x coordinates. 840 // And reset the x coordinates.
869 (*i)->ResetColumnXCoordinates(); 841 column_set->ResetColumnXCoordinates();
870 } 842 }
871 843
872 // Reset the height of each row. 844 // Reset the height of each row.
873 LayoutElement::ResetSizes(&rows_); 845 LayoutElement::ResetSizes(&rows_);
874 846
875 // Do the following: 847 // Do the following:
876 // . If the view is aligned along it's baseline, obtain the baseline from the 848 // . If the view is aligned along it's baseline, obtain the baseline from the
877 // view and update the rows ascent/descent. 849 // view and update the rows ascent/descent.
878 // . Reset the remaining_height of each view state. 850 // . Reset the remaining_height of each view state.
879 // . If the width the view will be given is different than it's pref, ask 851 // . If the width the view will be given is different than it's pref, ask
880 // for the height given a particularly width. 852 // for the height given a particularly width.
881 for (std::vector<ViewState*>::iterator i= view_states_.begin(); 853 for (const auto& view_state : view_states_) {
882 i != view_states_.end() ; ++i) {
883 ViewState* view_state = *i;
884 view_state->remaining_height = view_state->pref_height; 854 view_state->remaining_height = view_state->pref_height;
885 855
886 if (view_state->v_align == BASELINE) 856 if (view_state->v_align == BASELINE)
887 view_state->baseline = view_state->view->GetBaseline(); 857 view_state->baseline = view_state->view->GetBaseline();
888 858
889 if (view_state->h_align == FILL) { 859 if (view_state->h_align == FILL) {
890 // The view is resizable. As the pref height may vary with the width, 860 // The view is resizable. As the pref height may vary with the width,
891 // ask for the pref again. 861 // ask for the pref again.
892 int actual_width = 862 int actual_width =
893 view_state->column_set->GetColumnWidth(view_state->start_col, 863 view_state->column_set->GetColumnWidth(view_state->start_col,
894 view_state->col_span); 864 view_state->col_span);
895 if (actual_width != view_state->pref_width && 865 if (actual_width != view_state->pref_width &&
896 !view_state->pref_height_fixed) { 866 !view_state->pref_height_fixed) {
897 // The width this view will get differs from its preferred. Some Views 867 // The width this view will get differs from its preferred. Some Views
898 // pref height varies with its width; ask for the preferred again. 868 // pref height varies with its width; ask for the preferred again.
899 view_state->pref_height = 869 view_state->pref_height =
900 view_state->view->GetHeightForWidth(actual_width); 870 view_state->view->GetHeightForWidth(actual_width);
901 view_state->remaining_height = view_state->pref_height; 871 view_state->remaining_height = view_state->pref_height;
902 } 872 }
903 } 873 }
904 } 874 }
905 875
906 // Update the height/ascent/descent of each row from the views. 876 // Update the height/ascent/descent of each row from the views.
907 std::vector<ViewState*>::iterator view_states_iterator = view_states_.begin(); 877 auto view_states_iterator = view_states_.begin();
908 for (; view_states_iterator != view_states_.end() && 878 for (; view_states_iterator != view_states_.end() &&
909 (*view_states_iterator)->row_span == 1; ++view_states_iterator) { 879 (*view_states_iterator)->row_span == 1; ++view_states_iterator) {
910 ViewState* view_state = *view_states_iterator; 880 ViewState* view_state = view_states_iterator->get();
911 Row* row = rows_[view_state->start_row]; 881 Row* row = rows_[view_state->start_row].get();
912 row->AdjustSize(view_state->remaining_height); 882 row->AdjustSize(view_state->remaining_height);
913 if (view_state->baseline != -1 && 883 if (view_state->baseline != -1 &&
914 view_state->baseline <= view_state->pref_height) { 884 view_state->baseline <= view_state->pref_height) {
915 row->AdjustSizeForBaseline(view_state->baseline, 885 row->AdjustSizeForBaseline(view_state->baseline,
916 view_state->pref_height - view_state->baseline); 886 view_state->pref_height - view_state->baseline);
917 } 887 }
918 view_state->remaining_height = 0; 888 view_state->remaining_height = 0;
919 } 889 }
920 890
921 // Distribute the height of each view with a row span > 1. 891 // Distribute the height of each view with a row span > 1.
922 for (; view_states_iterator != view_states_.end(); ++view_states_iterator) { 892 for (; view_states_iterator != view_states_.end(); ++view_states_iterator) {
923 ViewState* view_state = *view_states_iterator; 893 ViewState* view_state = view_states_iterator->get();
924 894
925 // Update the remaining_width from columns this view_state touches. 895 // Update the remaining_width from columns this view_state touches.
926 UpdateRemainingHeightFromRows(view_state); 896 UpdateRemainingHeightFromRows(view_state);
927 897
928 // Distribute the remaining height. 898 // Distribute the remaining height.
929 DistributeRemainingHeight(view_state); 899 DistributeRemainingHeight(view_state);
930 } 900 }
931 901
932 // Update the location of each of the rows. 902 // Update the location of each of the rows.
933 LayoutElement::CalculateLocationsFromSize(&rows_); 903 LayoutElement::CalculateLocationsFromSize(&rows_);
934 904
935 // We now know the preferred height, set it here. 905 // We now know the preferred height, set it here.
936 pref->set_height(rows_.back()->Location() + rows_.back()->Size() + 906 pref->set_height(rows_.back()->Location() + rows_.back()->Size() +
937 insets_.height()); 907 insets_.height());
938 908
939 if (layout && height != pref->height()) { 909 if (layout && height != pref->height()) {
940 // We're doing a layout, and the height differs from the preferred height, 910 // We're doing a layout, and the height differs from the preferred height,
941 // divy up the extra space. 911 // divvy up the extra space.
942 LayoutElement::DistributeDelta(height - pref->height(), &rows_); 912 LayoutElement::DistributeDelta(height - pref->height(), &rows_);
943 913
944 // Reset y locations. 914 // Reset y locations.
945 LayoutElement::CalculateLocationsFromSize(&rows_); 915 LayoutElement::CalculateLocationsFromSize(&rows_);
946 } 916 }
947 } 917 }
948 918
949 void GridLayout::CalculateMasterColumnsIfNecessary() const { 919 void GridLayout::CalculateMasterColumnsIfNecessary() const {
950 if (!calculated_master_columns_) { 920 if (!calculated_master_columns_) {
951 calculated_master_columns_ = true; 921 calculated_master_columns_ = true;
952 for (std::vector<ColumnSet*>::iterator i = column_sets_.begin(); 922 for (const auto& column_set : column_sets_) {
953 i != column_sets_.end(); ++i) { 923 column_set->CalculateMasterColumns();
954 (*i)->CalculateMasterColumns();
955 } 924 }
956 } 925 }
957 } 926 }
958 927
959 void GridLayout::AddViewState(ViewState* view_state) { 928 void GridLayout::AddViewState(std::unique_ptr<ViewState> view_state) {
960 DCHECK(view_state->view && (view_state->view->parent() == NULL || 929 DCHECK(view_state->view && (view_state->view->parent() == nullptr ||
961 view_state->view->parent() == host_)); 930 view_state->view->parent() == host_));
962 if (!view_state->view->parent()) { 931 if (!view_state->view->parent()) {
963 adding_view_ = true; 932 adding_view_ = true;
964 host_->AddChildView(view_state->view); 933 host_->AddChildView(view_state->view);
965 adding_view_ = false; 934 adding_view_ = false;
966 } 935 }
967 remaining_row_span_ = std::max(remaining_row_span_, view_state->row_span); 936 remaining_row_span_ = std::max(remaining_row_span_, view_state->row_span);
968 next_column_ += view_state->col_span; 937 next_column_ += view_state->col_span;
969 current_row_col_set_->AddViewState(view_state); 938 current_row_col_set_->AddViewState(view_state.get());
970 // view_states are ordered by row_span (in ascending order). 939 // view_states are ordered by row_span (in ascending order).
971 std::vector<ViewState*>::iterator i = std::lower_bound(view_states_.begin(), 940 auto i = std::lower_bound(view_states_.begin(), view_states_.end(),
972 view_states_.end(), 941 view_state.get(), CompareByRowSpan);
973 view_state, 942 view_states_.insert(i, std::move(view_state));
974 CompareByRowSpan);
975 view_states_.insert(i, view_state);
976 SkipPaddingColumns(); 943 SkipPaddingColumns();
977 } 944 }
978 945
979 void GridLayout::AddRow(Row* row) { 946 void GridLayout::AddRow(std::unique_ptr<Row> row) {
980 current_row_++; 947 current_row_++;
981 remaining_row_span_--; 948 remaining_row_span_--;
982 // GridLayout requires that if you add a View with a row span you use the same 949 // GridLayout requires that if you add a View with a row span you use the same
983 // column set for each of the rows the view lands it. This DCHECK verifies 950 // column set for each of the rows the view lands it. This DCHECK verifies
984 // that. 951 // that.
985 DCHECK(remaining_row_span_ <= 0 || 952 DCHECK(remaining_row_span_ <= 0 || row->column_set() == nullptr ||
986 row->column_set() == NULL ||
987 row->column_set() == GetLastValidColumnSet()); 953 row->column_set() == GetLastValidColumnSet());
988 next_column_ = 0; 954 next_column_ = 0;
989 rows_.push_back(row);
990 current_row_col_set_ = row->column_set(); 955 current_row_col_set_ = row->column_set();
956 rows_.push_back(std::move(row));
991 SkipPaddingColumns(); 957 SkipPaddingColumns();
992 } 958 }
993 959
994 void GridLayout::UpdateRemainingHeightFromRows(ViewState* view_state) const { 960 void GridLayout::UpdateRemainingHeightFromRows(ViewState* view_state) const {
995 for (int i = 0, start_row = view_state->start_row; 961 for (int i = 0, start_row = view_state->start_row;
996 i < view_state->row_span; ++i) { 962 i < view_state->row_span; ++i) {
997 view_state->remaining_height -= rows_[i + start_row]->Size(); 963 view_state->remaining_height -= rows_[i + start_row]->Size();
998 } 964 }
999 } 965 }
1000 966
(...skipping 19 matching lines...) Expand all
1020 if (rows_[i]->IsResizable()) { 986 if (rows_[i]->IsResizable()) {
1021 height -= to_distribute; 987 height -= to_distribute;
1022 if (height < to_distribute) { 988 if (height < to_distribute) {
1023 // Give all slop to the last column. 989 // Give all slop to the last column.
1024 to_distribute += height; 990 to_distribute += height;
1025 } 991 }
1026 rows_[i]->SetSize(rows_[i]->Size() + to_distribute); 992 rows_[i]->SetSize(rows_[i]->Size() + to_distribute);
1027 } 993 }
1028 } 994 }
1029 } else { 995 } else {
1030 // None of the rows are resizable, divy the remaining height up equally 996 // None of the rows are resizable, divvy the remaining height up equally
1031 // among all rows the view touches. 997 // among all rows the view touches.
1032 int each_row_height = height / view_state->row_span; 998 int each_row_height = height / view_state->row_span;
1033 for (int i = start_row; i < max_row; ++i) { 999 for (int i = start_row; i < max_row; ++i) {
1034 height -= each_row_height; 1000 height -= each_row_height;
1035 if (height < each_row_height) 1001 if (height < each_row_height)
1036 each_row_height += height; 1002 each_row_height += height;
1037 rows_[i]->SetSize(rows_[i]->Size() + each_row_height); 1003 rows_[i]->SetSize(rows_[i]->Size() + each_row_height);
1038 } 1004 }
1039 view_state->remaining_height = 0; 1005 view_state->remaining_height = 0;
1040 } 1006 }
1041 } 1007 }
1042 1008
1043 void GridLayout::SkipPaddingColumns() { 1009 void GridLayout::SkipPaddingColumns() {
1044 if (!current_row_col_set_) 1010 if (!current_row_col_set_)
1045 return; 1011 return;
1046 while (next_column_ < current_row_col_set_->num_columns() && 1012 while (next_column_ < current_row_col_set_->num_columns() &&
1047 current_row_col_set_->columns_[next_column_]->is_padding_) { 1013 current_row_col_set_->columns_[next_column_]->is_padding_) {
1048 next_column_++; 1014 next_column_++;
1049 } 1015 }
1050 } 1016 }
1051 1017
1052 ColumnSet* GridLayout::GetLastValidColumnSet() { 1018 ColumnSet* GridLayout::GetLastValidColumnSet() {
1053 for (int i = current_row_ - 1; i >= 0; --i) { 1019 for (int i = current_row_ - 1; i >= 0; --i) {
1054 if (rows_[i]->column_set()) 1020 if (rows_[i]->column_set())
1055 return rows_[i]->column_set(); 1021 return rows_[i]->column_set();
1056 } 1022 }
1057 return NULL; 1023 return nullptr;
1058 } 1024 }
1059 1025
1060 } // namespace views 1026 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/layout/grid_layout.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698