| 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 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 int TableView::ViewToModel(int view_index) const { | 310 int TableView::ViewToModel(int view_index) const { |
| 311 if (!is_sorted()) | 311 if (!is_sorted()) |
| 312 return view_index; | 312 return view_index; |
| 313 DCHECK_GE(view_index, 0) << " negative view_index " << view_index; | 313 DCHECK_GE(view_index, 0) << " negative view_index " << view_index; |
| 314 DCHECK_LT(view_index, RowCount()) << " out of bounds view_index " << | 314 DCHECK_LT(view_index, RowCount()) << " out of bounds view_index " << |
| 315 view_index; | 315 view_index; |
| 316 return view_to_model_[view_index]; | 316 return view_to_model_[view_index]; |
| 317 } | 317 } |
| 318 | 318 |
| 319 void TableView::Layout() { | 319 void TableView::Layout() { |
| 320 // parent()->parent() is the scrollview. When its width changes we force | 320 // When the scroll view width changes, recalculate column sizes. |
| 321 // recalculating column sizes. | 321 ScrollView* scroll_view = EnclosingScrollView(); |
| 322 View* scroll_view = parent() ? parent()->parent() : NULL; | |
| 323 if (scroll_view) { | 322 if (scroll_view) { |
| 324 const int scroll_view_width = scroll_view->GetContentsBounds().width(); | 323 const int scroll_view_width = scroll_view->GetContentsBounds().width(); |
| 325 if (scroll_view_width != last_parent_width_) { | 324 if (scroll_view_width != last_parent_width_) { |
| 326 last_parent_width_ = scroll_view_width; | 325 last_parent_width_ = scroll_view_width; |
| 327 if (!in_set_visible_column_width_) { | 326 if (!in_set_visible_column_width_) { |
| 328 // Layout to the parent (the Viewport), which differs from | 327 // Layout to the visible width (the Viewport), which differs from |
| 329 // |scroll_view_width| when scrollbars are present. | 328 // |scroll_view_width| when scrollbars are present. |
| 330 layout_width_ = parent()->width(); | 329 layout_width_ = scroll_view->GetVisibleRect().width(); |
| 331 UpdateVisibleColumnSizes(); | 330 UpdateVisibleColumnSizes(); |
| 332 } | 331 } |
| 333 } | 332 } |
| 334 } | 333 } |
| 335 // We have to override Layout like this since we're contained in a ScrollView. | 334 // We have to override Layout like this since we're contained in a ScrollView. |
| 336 gfx::Size pref = GetPreferredSize(); | 335 gfx::Size pref = GetPreferredSize(); |
| 337 int width = pref.width(); | 336 int width = pref.width(); |
| 338 int height = pref.height(); | 337 int height = pref.height(); |
| 339 if (parent()) { | 338 if (parent()) { |
| 340 width = std::max(parent()->width(), width); | 339 width = std::max(parent()->width(), width); |
| (...skipping 616 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 if (tooltip) | 956 if (tooltip) |
| 958 *tooltip = text; | 957 *tooltip = text; |
| 959 if (tooltip_origin) { | 958 if (tooltip_origin) { |
| 960 tooltip_origin->SetPoint(cell_bounds.x(), | 959 tooltip_origin->SetPoint(cell_bounds.x(), |
| 961 cell_bounds.y() + kTextVerticalPadding); | 960 cell_bounds.y() + kTextVerticalPadding); |
| 962 } | 961 } |
| 963 return true; | 962 return true; |
| 964 } | 963 } |
| 965 | 964 |
| 966 } // namespace views | 965 } // namespace views |
| OLD | NEW |