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

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

Issue 2389803006: Revert of Fix task manager's default sizing. (Closed)
Patch Set: Created 4 years, 2 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_layout_width_(0), 140 last_parent_width_(0),
141 layout_width_(0),
141 grouper_(NULL), 142 grouper_(NULL),
142 in_set_visible_column_width_(false) { 143 in_set_visible_column_width_(false) {
143 for (size_t i = 0; i < columns.size(); ++i) { 144 for (size_t i = 0; i < columns.size(); ++i) {
144 VisibleColumn visible_column; 145 VisibleColumn visible_column;
145 visible_column.column = columns[i]; 146 visible_column.column = columns[i];
146 visible_columns_.push_back(visible_column); 147 visible_columns_.push_back(visible_column);
147 } 148 }
148 // Always focusable, even on Mac (consistent with NSTableView). 149 // Always focusable, even on Mac (consistent with NSTableView).
149 SetFocusBehavior(FocusBehavior::ALWAYS); 150 SetFocusBehavior(FocusBehavior::ALWAYS);
150 SetModel(model); 151 SetModel(model);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 int TableView::ViewToModel(int view_index) const { 310 int TableView::ViewToModel(int view_index) const {
310 if (!is_sorted()) 311 if (!is_sorted())
311 return view_index; 312 return view_index;
312 DCHECK_GE(view_index, 0) << " negative view_index " << view_index; 313 DCHECK_GE(view_index, 0) << " negative view_index " << view_index;
313 DCHECK_LT(view_index, RowCount()) << " out of bounds view_index " << 314 DCHECK_LT(view_index, RowCount()) << " out of bounds view_index " <<
314 view_index; 315 view_index;
315 return view_to_model_[view_index]; 316 return view_to_model_[view_index];
316 } 317 }
317 318
318 void TableView::Layout() { 319 void TableView::Layout() {
319 View* viewport = parent(); 320 // parent()->parent() is the scrollview. When its width changes we force
320 if (viewport && last_layout_width_ != viewport->width() && 321 // recalculating column sizes.
321 !in_set_visible_column_width_) { 322 View* scroll_view = parent() ? parent()->parent() : NULL;
322 last_layout_width_ = viewport->width(); 323 if (scroll_view) {
323 UpdateVisibleColumnSizes(); 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 }
324 } 334 }
325 // We have to override Layout like this since we're contained in a ScrollView. 335 // We have to override Layout like this since we're contained in a ScrollView.
326 gfx::Size pref = GetPreferredSize(); 336 gfx::Size pref = GetPreferredSize();
327 if (viewport) 337 int width = pref.width();
328 pref.SetToMax(viewport->size()); 338 int height = pref.height();
329 SetSize(pref); 339 if (parent()) {
340 width = std::max(parent()->width(), width);
341 height = std::max(parent()->height(), height);
342 }
343 SetBounds(x(), y(), width, height);
330 } 344 }
331 345
332 const char* TableView::GetClassName() const { 346 const char* TableView::GetClassName() const {
333 return kViewClassName; 347 return kViewClassName;
334 } 348 }
335 349
336 gfx::Size TableView::GetPreferredSize() const { 350 gfx::Size TableView::GetPreferredSize() const {
337 int width = 50; 351 int width = 50;
338 if (header_ && !visible_columns_.empty()) 352 if (header_ && !visible_columns_.empty())
339 width = visible_columns_.back().x + visible_columns_.back().width; 353 width = visible_columns_.back().x + visible_columns_.back().width;
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 for (size_t i = 0; i < visible_columns_.size(); ++i) 734 for (size_t i = 0; i < visible_columns_.size(); ++i)
721 columns.push_back(visible_columns_[i].column); 735 columns.push_back(visible_columns_[i].column);
722 736
723 int first_column_padding = 0; 737 int first_column_padding = 0;
724 if (table_type_ == ICON_AND_TEXT && header_) 738 if (table_type_ == ICON_AND_TEXT && header_)
725 first_column_padding += kImageSize + kTextHorizontalPadding; 739 first_column_padding += kImageSize + kTextHorizontalPadding;
726 if (grouper_) 740 if (grouper_)
727 first_column_padding += kGroupingIndicatorSize + kTextHorizontalPadding; 741 first_column_padding += kGroupingIndicatorSize + kTextHorizontalPadding;
728 742
729 std::vector<int> sizes = views::CalculateTableColumnSizes( 743 std::vector<int> sizes = views::CalculateTableColumnSizes(
730 last_layout_width_, first_column_padding, header_->font_list(), 744 layout_width_, first_column_padding, header_->font_list(), font_list_,
731 font_list_,
732 std::max(kTextHorizontalPadding, TableHeader::kHorizontalPadding) * 2, 745 std::max(kTextHorizontalPadding, TableHeader::kHorizontalPadding) * 2,
733 TableHeader::kSortIndicatorWidth, columns, model_); 746 TableHeader::kSortIndicatorWidth, columns, model_);
734 DCHECK_EQ(visible_columns_.size(), sizes.size()); 747 DCHECK_EQ(visible_columns_.size(), sizes.size());
735 int x = 0; 748 int x = 0;
736 for (size_t i = 0; i < visible_columns_.size(); ++i) { 749 for (size_t i = 0; i < visible_columns_.size(); ++i) {
737 visible_columns_[i].x = x; 750 visible_columns_[i].x = x;
738 visible_columns_[i].width = sizes[i]; 751 visible_columns_[i].width = sizes[i];
739 x += sizes[i]; 752 x += sizes[i];
740 } 753 }
741 } 754 }
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
944 if (tooltip) 957 if (tooltip)
945 *tooltip = text; 958 *tooltip = text;
946 if (tooltip_origin) { 959 if (tooltip_origin) {
947 tooltip_origin->SetPoint(cell_bounds.x(), 960 tooltip_origin->SetPoint(cell_bounds.x(),
948 cell_bounds.y() + kTextVerticalPadding); 961 cell_bounds.y() + kTextVerticalPadding);
949 } 962 }
950 return true; 963 return true;
951 } 964 }
952 965
953 } // namespace views 966 } // 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