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

Side by Side Diff: ui/views/controls/table/table_view.cc

Issue 2344703002: Fix task manager's default sizing. (Closed)
Patch Set: rabbit holes Created 4 years, 3 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
« no previous file with comments | « ui/views/controls/table/table_view.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/controls/table/table_view.h" 5 #include "ui/views/controls/table/table_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 TableTypes table_type, 130 TableTypes table_type,
131 bool single_selection) 131 bool single_selection)
132 : model_(NULL), 132 : model_(NULL),
133 columns_(columns), 133 columns_(columns),
134 header_(NULL), 134 header_(NULL),
135 table_type_(table_type), 135 table_type_(table_type),
136 single_selection_(single_selection), 136 single_selection_(single_selection),
137 select_on_remove_(true), 137 select_on_remove_(true),
138 table_view_observer_(NULL), 138 table_view_observer_(NULL),
139 row_height_(font_list_.GetHeight() + kTextVerticalPadding * 2), 139 row_height_(font_list_.GetHeight() + kTextVerticalPadding * 2),
140 last_parent_width_(0),
141 layout_width_(0),
142 grouper_(NULL), 140 grouper_(NULL),
143 in_set_visible_column_width_(false) { 141 in_set_visible_column_width_(false) {
144 for (size_t i = 0; i < columns.size(); ++i) { 142 for (size_t i = 0; i < columns.size(); ++i) {
145 VisibleColumn visible_column; 143 VisibleColumn visible_column;
146 visible_column.column = columns[i]; 144 visible_column.column = columns[i];
147 visible_columns_.push_back(visible_column); 145 visible_columns_.push_back(visible_column);
148 } 146 }
149 // Always focusable, even on Mac (consistent with NSTableView). 147 // Always focusable, even on Mac (consistent with NSTableView).
150 SetFocusBehavior(FocusBehavior::ALWAYS); 148 SetFocusBehavior(FocusBehavior::ALWAYS);
151 SetModel(model); 149 SetModel(model);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 int TableView::ViewToModel(int view_index) const { 308 int TableView::ViewToModel(int view_index) const {
311 if (!is_sorted()) 309 if (!is_sorted())
312 return view_index; 310 return view_index;
313 DCHECK_GE(view_index, 0) << " negative view_index " << view_index; 311 DCHECK_GE(view_index, 0) << " negative view_index " << view_index;
314 DCHECK_LT(view_index, RowCount()) << " out of bounds view_index " << 312 DCHECK_LT(view_index, RowCount()) << " out of bounds view_index " <<
315 view_index; 313 view_index;
316 return view_to_model_[view_index]; 314 return view_to_model_[view_index];
317 } 315 }
318 316
319 void TableView::Layout() { 317 void TableView::Layout() {
320 // parent()->parent() is the scrollview. When its width changes we force 318 View* viewport = parent();
321 // recalculating column sizes. 319 if (viewport && width() != viewport->width() && !in_set_visible_column_width_)
sky 2016/09/16 21:28:58 I believe your change will result in forcing a cal
Evan Stade 2016/09/22 16:19:13 I guess that's right. We're already calling it eve
322 View* scroll_view = parent() ? parent()->parent() : NULL; 320 UpdateVisibleColumnSizes();
323 if (scroll_view) {
324 const int scroll_view_width = scroll_view->GetContentsBounds().width();
325 if (scroll_view_width != last_parent_width_) {
326 last_parent_width_ = scroll_view_width;
327 if (!in_set_visible_column_width_) {
328 // Layout to the parent (the Viewport), which differs from
329 // |scroll_view_width| when scrollbars are present.
330 layout_width_ = parent()->width();
331 UpdateVisibleColumnSizes();
332 }
333 }
334 }
335 // We have to override Layout like this since we're contained in a ScrollView. 321 // We have to override Layout like this since we're contained in a ScrollView.
336 gfx::Size pref = GetPreferredSize(); 322 gfx::Size pref = GetPreferredSize();
337 int width = pref.width(); 323 if (viewport)
338 int height = pref.height(); 324 pref.SetToMax(viewport->size());
339 if (parent()) { 325 SetSize(pref);
340 width = std::max(parent()->width(), width);
341 height = std::max(parent()->height(), height);
342 }
343 SetBounds(x(), y(), width, height);
344 } 326 }
345 327
346 const char* TableView::GetClassName() const { 328 const char* TableView::GetClassName() const {
347 return kViewClassName; 329 return kViewClassName;
348 } 330 }
349 331
350 gfx::Size TableView::GetPreferredSize() const { 332 gfx::Size TableView::GetPreferredSize() const {
351 int width = 50; 333 int width = 50;
352 if (header_ && !visible_columns_.empty()) 334 if (header_ && !visible_columns_.empty())
353 width = visible_columns_.back().x + visible_columns_.back().width; 335 width = visible_columns_.back().x + visible_columns_.back().width;
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
734 for (size_t i = 0; i < visible_columns_.size(); ++i) 716 for (size_t i = 0; i < visible_columns_.size(); ++i)
735 columns.push_back(visible_columns_[i].column); 717 columns.push_back(visible_columns_[i].column);
736 718
737 int first_column_padding = 0; 719 int first_column_padding = 0;
738 if (table_type_ == ICON_AND_TEXT && header_) 720 if (table_type_ == ICON_AND_TEXT && header_)
739 first_column_padding += kImageSize + kTextHorizontalPadding; 721 first_column_padding += kImageSize + kTextHorizontalPadding;
740 if (grouper_) 722 if (grouper_)
741 first_column_padding += kGroupingIndicatorSize + kTextHorizontalPadding; 723 first_column_padding += kGroupingIndicatorSize + kTextHorizontalPadding;
742 724
743 std::vector<int> sizes = views::CalculateTableColumnSizes( 725 std::vector<int> sizes = views::CalculateTableColumnSizes(
744 layout_width_, first_column_padding, header_->font_list(), font_list_, 726 parent() ? parent()->width() : 0, first_column_padding,
727 header_->font_list(), font_list_,
745 std::max(kTextHorizontalPadding, TableHeader::kHorizontalPadding) * 2, 728 std::max(kTextHorizontalPadding, TableHeader::kHorizontalPadding) * 2,
746 TableHeader::kSortIndicatorWidth, columns, model_); 729 TableHeader::kSortIndicatorWidth, columns, model_);
747 DCHECK_EQ(visible_columns_.size(), sizes.size()); 730 DCHECK_EQ(visible_columns_.size(), sizes.size());
748 int x = 0; 731 int x = 0;
749 for (size_t i = 0; i < visible_columns_.size(); ++i) { 732 for (size_t i = 0; i < visible_columns_.size(); ++i) {
750 visible_columns_[i].x = x; 733 visible_columns_[i].x = x;
751 visible_columns_[i].width = sizes[i]; 734 visible_columns_[i].width = sizes[i];
752 x += sizes[i]; 735 x += sizes[i];
753 } 736 }
754 } 737 }
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 if (tooltip) 940 if (tooltip)
958 *tooltip = text; 941 *tooltip = text;
959 if (tooltip_origin) { 942 if (tooltip_origin) {
960 tooltip_origin->SetPoint(cell_bounds.x(), 943 tooltip_origin->SetPoint(cell_bounds.x(),
961 cell_bounds.y() + kTextVerticalPadding); 944 cell_bounds.y() + kTextVerticalPadding);
962 } 945 }
963 return true; 946 return true;
964 } 947 }
965 948
966 } // namespace views 949 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/table/table_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698