| 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" | 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" |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 179 void ResetSize() override; | 179 void ResetSize() override; |
| 180 | 180 |
| 181 private: | 181 private: |
| 182 friend class ColumnSet; | 182 friend class ColumnSet; |
| 183 friend class GridLayout; | 183 friend class GridLayout; |
| 184 | 184 |
| 185 Column* GetLastMasterColumn(); | 185 Column* GetLastMasterColumn(); |
| 186 | 186 |
| 187 // Determines the max size of all linked columns, and sets each column | 187 // Determines the max size of all linked columns, and sets each column |
| 188 // to that size. This should only be used for the master column. | 188 // to that size. This should only be used for the master column. |
| 189 void UnifySameSizedColumnSizes(); | 189 void UnifyLinkedColumnSizes(int size_limit); |
| 190 | 190 |
| 191 void AdjustSize(int size) override; | 191 void AdjustSize(int size) override; |
| 192 | 192 |
| 193 const GridLayout::Alignment h_align_; | 193 const GridLayout::Alignment h_align_; |
| 194 const GridLayout::Alignment v_align_; | 194 const GridLayout::Alignment v_align_; |
| 195 const GridLayout::SizeType size_type_; | 195 const GridLayout::SizeType size_type_; |
| 196 int same_size_column_; | 196 int same_size_column_; |
| 197 const int fixed_width_; | 197 const int fixed_width_; |
| 198 const int min_width_; | 198 const int min_width_; |
| 199 | 199 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 224 Column* Column::GetLastMasterColumn() { | 224 Column* Column::GetLastMasterColumn() { |
| 225 if (master_column_ == nullptr) { | 225 if (master_column_ == nullptr) { |
| 226 return nullptr; | 226 return nullptr; |
| 227 } | 227 } |
| 228 if (master_column_ == this) { | 228 if (master_column_ == this) { |
| 229 return this; | 229 return this; |
| 230 } | 230 } |
| 231 return master_column_->GetLastMasterColumn(); | 231 return master_column_->GetLastMasterColumn(); |
| 232 } | 232 } |
| 233 | 233 |
| 234 void Column::UnifySameSizedColumnSizes() { | 234 void Column::UnifyLinkedColumnSizes(int size_limit) { |
| 235 DCHECK(master_column_ == this); | 235 DCHECK(master_column_ == this); |
| 236 | 236 |
| 237 // Accumulate the size first. | 237 // Accumulate the size first. |
| 238 int size = 0; | 238 int size = 0; |
| 239 for (auto* column : same_size_columns_) | 239 for (auto* column : same_size_columns_) { |
| 240 size = std::max(size, column->Size()); | 240 if (column->Size() <= size_limit) |
| 241 size = std::max(size, column->Size()); |
| 242 } |
| 241 | 243 |
| 242 // Then apply it. | 244 // Then apply it. |
| 243 for (auto* column : same_size_columns_) | 245 for (auto* column : same_size_columns_) |
| 244 column->SetSize(size); | 246 column->SetSize(std::max(size, column->Size())); |
| 245 } | 247 } |
| 246 | 248 |
| 247 void Column::AdjustSize(int size) { | 249 void Column::AdjustSize(int size) { |
| 248 if (size_type_ == GridLayout::USE_PREF) | 250 if (size_type_ == GridLayout::USE_PREF) |
| 249 LayoutElement::AdjustSize(size); | 251 LayoutElement::AdjustSize(size); |
| 250 } | 252 } |
| 251 | 253 |
| 252 // Row ------------------------------------------------------------- | 254 // Row ------------------------------------------------------------- |
| 253 | 255 |
| 254 class Row : public LayoutElement { | 256 class Row : public LayoutElement { |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 return v1->col_span < v2->col_span; | 360 return v1->col_span < v2->col_span; |
| 359 } | 361 } |
| 360 | 362 |
| 361 static bool CompareByRowSpan(const std::unique_ptr<ViewState>& v1, | 363 static bool CompareByRowSpan(const std::unique_ptr<ViewState>& v1, |
| 362 const ViewState* v2) { | 364 const ViewState* v2) { |
| 363 return v1->row_span < v2->row_span; | 365 return v1->row_span < v2->row_span; |
| 364 } | 366 } |
| 365 | 367 |
| 366 // ColumnSet ------------------------------------------------------------- | 368 // ColumnSet ------------------------------------------------------------- |
| 367 | 369 |
| 368 ColumnSet::ColumnSet(int id) : id_(id) { | 370 ColumnSet::ColumnSet(int id) : id_(id), linked_column_size_limit_(INT_MAX) {} |
| 369 } | |
| 370 | 371 |
| 371 ColumnSet::~ColumnSet() { | 372 ColumnSet::~ColumnSet() { |
| 372 } | 373 } |
| 373 | 374 |
| 374 void ColumnSet::AddPaddingColumn(float resize_percent, int width) { | 375 void ColumnSet::AddPaddingColumn(float resize_percent, int width) { |
| 375 AddColumn(GridLayout::FILL, GridLayout::FILL, resize_percent, | 376 AddColumn(GridLayout::FILL, GridLayout::FILL, resize_percent, |
| 376 GridLayout::FIXED, width, width, true); | 377 GridLayout::FIXED, width, width, true); |
| 377 } | 378 } |
| 378 | 379 |
| 379 void ColumnSet::AddColumn(GridLayout::Alignment h_align, | 380 void ColumnSet::AddColumn(GridLayout::Alignment h_align, |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 master_column) == master_columns_.end()) { | 489 master_column) == master_columns_.end()) { |
| 489 master_columns_.push_back(master_column); | 490 master_columns_.push_back(master_column); |
| 490 } | 491 } |
| 491 // At this point, GetLastMasterColumn may not == master_column | 492 // At this point, GetLastMasterColumn may not == master_column |
| 492 // (may have to go through a few Columns)_. Reset master_column to | 493 // (may have to go through a few Columns)_. Reset master_column to |
| 493 // avoid hops. | 494 // avoid hops. |
| 494 column->master_column_ = master_column; | 495 column->master_column_ = master_column; |
| 495 } | 496 } |
| 496 } | 497 } |
| 497 | 498 |
| 498 void ColumnSet::UnifySameSizedColumnSizes() { | 499 void ColumnSet::UnifyLinkedColumnSizes() { |
| 499 for (auto* column : master_columns_) | 500 for (auto* column : master_columns_) |
| 500 column->UnifySameSizedColumnSizes(); | 501 column->UnifyLinkedColumnSizes(linked_column_size_limit_); |
| 501 } | 502 } |
| 502 | 503 |
| 503 void ColumnSet::UpdateRemainingWidth(ViewState* view_state) { | 504 void ColumnSet::UpdateRemainingWidth(ViewState* view_state) { |
| 504 for (int i = view_state->start_col, | 505 for (int i = view_state->start_col, |
| 505 max_col = view_state->start_col + view_state->col_span; | 506 max_col = view_state->start_col + view_state->col_span; |
| 506 i < max_col; ++i) { | 507 i < max_col; ++i) { |
| 507 view_state->remaining_width -= columns_[i]->Size(); | 508 view_state->remaining_width -= columns_[i]->Size(); |
| 508 } | 509 } |
| 509 } | 510 } |
| 510 | 511 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 auto view_state_iterator = view_states_.begin(); | 603 auto view_state_iterator = view_states_.begin(); |
| 603 for (; view_state_iterator != view_states_.end() && | 604 for (; view_state_iterator != view_states_.end() && |
| 604 (*view_state_iterator)->col_span == 1; ++view_state_iterator) { | 605 (*view_state_iterator)->col_span == 1; ++view_state_iterator) { |
| 605 ViewState* view_state = *view_state_iterator; | 606 ViewState* view_state = *view_state_iterator; |
| 606 Column* column = columns_[view_state->start_col].get(); | 607 Column* column = columns_[view_state->start_col].get(); |
| 607 column->AdjustSize(view_state->pref_width); | 608 column->AdjustSize(view_state->pref_width); |
| 608 view_state->remaining_width -= column->Size(); | 609 view_state->remaining_width -= column->Size(); |
| 609 } | 610 } |
| 610 | 611 |
| 611 // Make sure all linked columns have the same size. | 612 // Make sure all linked columns have the same size. |
| 612 UnifySameSizedColumnSizes(); | 613 UnifyLinkedColumnSizes(); |
| 613 | 614 |
| 614 // Distribute the size of each view with a column span > 1. | 615 // Distribute the size of each view with a column span > 1. |
| 615 for (; view_state_iterator != view_states_.end(); ++view_state_iterator) { | 616 for (; view_state_iterator != view_states_.end(); ++view_state_iterator) { |
| 616 ViewState* view_state = *view_state_iterator; | 617 ViewState* view_state = *view_state_iterator; |
| 617 | 618 |
| 618 // Update the remaining_width from columns this view_state touches. | 619 // Update the remaining_width from columns this view_state touches. |
| 619 UpdateRemainingWidth(view_state); | 620 UpdateRemainingWidth(view_state); |
| 620 | 621 |
| 621 // Distribute the remaining width. | 622 // Distribute the remaining width. |
| 622 DistributeRemainingWidth(view_state); | 623 DistributeRemainingWidth(view_state); |
| 623 | 624 |
| 624 // Update the size of linked columns. | 625 // Update the size of linked columns. |
| 625 // This may need to be combined with previous step. | 626 // This may need to be combined with previous step. |
| 626 UnifySameSizedColumnSizes(); | 627 UnifyLinkedColumnSizes(); |
| 627 } | 628 } |
| 628 } | 629 } |
| 629 | 630 |
| 630 void ColumnSet::Resize(int delta) { | 631 void ColumnSet::Resize(int delta) { |
| 631 LayoutElement::DistributeDelta(delta, &columns_); | 632 LayoutElement::DistributeDelta(delta, &columns_); |
| 632 } | 633 } |
| 633 | 634 |
| 634 // GridLayout ------------------------------------------------------------- | 635 // GridLayout ------------------------------------------------------------- |
| 635 | 636 |
| 636 GridLayout::GridLayout(View* host) | 637 GridLayout::GridLayout(View* host) |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1020 | 1021 |
| 1021 ColumnSet* GridLayout::GetLastValidColumnSet() { | 1022 ColumnSet* GridLayout::GetLastValidColumnSet() { |
| 1022 for (int i = current_row_ - 1; i >= 0; --i) { | 1023 for (int i = current_row_ - 1; i >= 0; --i) { |
| 1023 if (rows_[i]->column_set()) | 1024 if (rows_[i]->column_set()) |
| 1024 return rows_[i]->column_set(); | 1025 return rows_[i]->column_set(); |
| 1025 } | 1026 } |
| 1026 return nullptr; | 1027 return nullptr; |
| 1027 } | 1028 } |
| 1028 | 1029 |
| 1029 } // namespace views | 1030 } // namespace views |
| OLD | NEW |