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

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

Issue 2625083003: Implement Harmony-style consistent button widths for Collected Cookies. (Closed)
Patch Set: selfnits Created 3 years, 9 months 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
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"
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 UnifySameSizedColumnSizes(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
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::UnifySameSizedColumnSizes(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 if (column->Size() <= size_limit)
247 column->SetSize(size);
Peter Kasting 2017/03/07 02:50:37 Nit: Or (allows not adding {}): column->SetSi
tapted 2017/03/07 12:06:41 Done. (I suppose we should rename: SetSize -> set_
248 }
245 } 249 }
246 250
247 void Column::AdjustSize(int size) { 251 void Column::AdjustSize(int size) {
248 if (size_type_ == GridLayout::USE_PREF) 252 if (size_type_ == GridLayout::USE_PREF)
249 LayoutElement::AdjustSize(size); 253 LayoutElement::AdjustSize(size);
250 } 254 }
251 255
252 // Row ------------------------------------------------------------- 256 // Row -------------------------------------------------------------
253 257
254 class Row : public LayoutElement { 258 class Row : public LayoutElement {
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 return v1->col_span < v2->col_span; 362 return v1->col_span < v2->col_span;
359 } 363 }
360 364
361 static bool CompareByRowSpan(const std::unique_ptr<ViewState>& v1, 365 static bool CompareByRowSpan(const std::unique_ptr<ViewState>& v1,
362 const ViewState* v2) { 366 const ViewState* v2) {
363 return v1->row_span < v2->row_span; 367 return v1->row_span < v2->row_span;
364 } 368 }
365 369
366 // ColumnSet ------------------------------------------------------------- 370 // ColumnSet -------------------------------------------------------------
367 371
368 ColumnSet::ColumnSet(int id) : id_(id) { 372 ColumnSet::ColumnSet(int id) : id_(id), linked_column_size_limit_(INT_MAX) {}
Peter Kasting 2017/03/07 02:50:37 Nit: I wonder if it makes any sense for readabilit
tapted 2017/03/07 12:06:41 0 is convenient for other things (i.e. effectively
Peter Kasting 2017/03/07 21:22:49 Oh, do we actually use that? I figured allowing c
tapted 2017/03/07 22:39:19 Yup, that's the approach here for collected cookie
369 }
370 373
371 ColumnSet::~ColumnSet() { 374 ColumnSet::~ColumnSet() {
372 } 375 }
373 376
374 void ColumnSet::AddPaddingColumn(float resize_percent, int width) { 377 void ColumnSet::AddPaddingColumn(float resize_percent, int width) {
375 AddColumn(GridLayout::FILL, GridLayout::FILL, resize_percent, 378 AddColumn(GridLayout::FILL, GridLayout::FILL, resize_percent,
376 GridLayout::FIXED, width, width, true); 379 GridLayout::FIXED, width, width, true);
377 } 380 }
378 381
379 void ColumnSet::AddColumn(GridLayout::Alignment h_align, 382 void ColumnSet::AddColumn(GridLayout::Alignment h_align,
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 } 493 }
491 // At this point, GetLastMasterColumn may not == master_column 494 // At this point, GetLastMasterColumn may not == master_column
492 // (may have to go through a few Columns)_. Reset master_column to 495 // (may have to go through a few Columns)_. Reset master_column to
493 // avoid hops. 496 // avoid hops.
494 column->master_column_ = master_column; 497 column->master_column_ = master_column;
495 } 498 }
496 } 499 }
497 500
498 void ColumnSet::UnifySameSizedColumnSizes() { 501 void ColumnSet::UnifySameSizedColumnSizes() {
499 for (auto* column : master_columns_) 502 for (auto* column : master_columns_)
500 column->UnifySameSizedColumnSizes(); 503 column->UnifySameSizedColumnSizes(linked_column_size_limit_);
501 } 504 }
502 505
503 void ColumnSet::UpdateRemainingWidth(ViewState* view_state) { 506 void ColumnSet::UpdateRemainingWidth(ViewState* view_state) {
504 for (int i = view_state->start_col, 507 for (int i = view_state->start_col,
505 max_col = view_state->start_col + view_state->col_span; 508 max_col = view_state->start_col + view_state->col_span;
506 i < max_col; ++i) { 509 i < max_col; ++i) {
507 view_state->remaining_width -= columns_[i]->Size(); 510 view_state->remaining_width -= columns_[i]->Size();
508 } 511 }
509 } 512 }
510 513
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1020 1023
1021 ColumnSet* GridLayout::GetLastValidColumnSet() { 1024 ColumnSet* GridLayout::GetLastValidColumnSet() {
1022 for (int i = current_row_ - 1; i >= 0; --i) { 1025 for (int i = current_row_ - 1; i >= 0; --i) {
1023 if (rows_[i]->column_set()) 1026 if (rows_[i]->column_set())
1024 return rows_[i]->column_set(); 1027 return rows_[i]->column_set();
1025 } 1028 }
1026 return nullptr; 1029 return nullptr;
1027 } 1030 }
1028 1031
1029 } // namespace views 1032 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698