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