| 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_views.h" | 5 #include "ui/views/controls/table/table_view_views.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "ui/base/events/event.h" | 10 #include "ui/base/events/event.h" |
| (...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 } | 231 } |
| 232 | 232 |
| 233 bool TableView::IsColumnVisible(int id) const { | 233 bool TableView::IsColumnVisible(int id) const { |
| 234 for (size_t i = 0; i < visible_columns_.size(); ++i) { | 234 for (size_t i = 0; i < visible_columns_.size(); ++i) { |
| 235 if (visible_columns_[i].column.id == id) | 235 if (visible_columns_[i].column.id == id) |
| 236 return true; | 236 return true; |
| 237 } | 237 } |
| 238 return false; | 238 return false; |
| 239 } | 239 } |
| 240 | 240 |
| 241 void TableView::AddColumn(const ui::TableColumn& col) { |
| 242 DCHECK(!HasColumn(col.id)); |
| 243 columns_.push_back(col); |
| 244 } |
| 245 |
| 246 bool TableView::HasColumn(int id) const { |
| 247 for (size_t i = 0; i < columns_.size(); ++i) { |
| 248 if (columns_[i].id == id) |
| 249 return true; |
| 250 } |
| 251 return false; |
| 252 } |
| 253 |
| 241 void TableView::SetVisibleColumnWidth(int index, int width) { | 254 void TableView::SetVisibleColumnWidth(int index, int width) { |
| 242 DCHECK(index >= 0 && index < static_cast<int>(visible_columns_.size())); | 255 DCHECK(index >= 0 && index < static_cast<int>(visible_columns_.size())); |
| 243 if (visible_columns_[index].width == width) | 256 if (visible_columns_[index].width == width) |
| 244 return; | 257 return; |
| 245 visible_columns_[index].width = width; | 258 visible_columns_[index].width = width; |
| 246 for (size_t i = index + 1; i < visible_columns_.size(); ++i) { | 259 for (size_t i = index + 1; i < visible_columns_.size(); ++i) { |
| 247 visible_columns_[i].x = | 260 visible_columns_[i].x = |
| 248 visible_columns_[i - 1].x + visible_columns_[i - 1].width; | 261 visible_columns_[i - 1].x + visible_columns_[i - 1].width; |
| 249 } | 262 } |
| 250 PreferredSizeChanged(); | 263 PreferredSizeChanged(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 266 DCHECK_GE(view_index, 0) << " negative view_index " << view_index; | 279 DCHECK_GE(view_index, 0) << " negative view_index " << view_index; |
| 267 DCHECK_LT(view_index, RowCount()) << " out of bounds view_index " << | 280 DCHECK_LT(view_index, RowCount()) << " out of bounds view_index " << |
| 268 view_index; | 281 view_index; |
| 269 return view_to_model_[view_index]; | 282 return view_to_model_[view_index]; |
| 270 } | 283 } |
| 271 | 284 |
| 272 void TableView::Layout() { | 285 void TableView::Layout() { |
| 273 // parent()->parent() is the scrollview. When its width changes we force | 286 // parent()->parent() is the scrollview. When its width changes we force |
| 274 // recalculating column sizes. | 287 // recalculating column sizes. |
| 275 View* scroll_view = parent() ? parent()->parent() : NULL; | 288 View* scroll_view = parent() ? parent()->parent() : NULL; |
| 276 if (scroll_view && scroll_view->width() != last_parent_width_) { | 289 if (scroll_view) { |
| 277 last_parent_width_ = scroll_view->width(); | 290 const int scroll_view_width = scroll_view->GetContentsBounds().width(); |
| 278 UpdateVisibleColumnSizes(); | 291 if (scroll_view_width != last_parent_width_) { |
| 292 last_parent_width_ = scroll_view_width; |
| 293 UpdateVisibleColumnSizes(); |
| 294 } |
| 279 } | 295 } |
| 280 // We have to override Layout like this since we're contained in a ScrollView. | 296 // We have to override Layout like this since we're contained in a ScrollView. |
| 281 gfx::Size pref = GetPreferredSize(); | 297 gfx::Size pref = GetPreferredSize(); |
| 282 int width = pref.width(); | 298 int width = pref.width(); |
| 283 int height = pref.height(); | 299 int height = pref.height(); |
| 284 if (parent()) { | 300 if (parent()) { |
| 285 width = std::max(parent()->width(), width); | 301 width = std::max(parent()->width(), width); |
| 286 height = std::max(parent()->height(), height); | 302 height = std::max(parent()->height(), height); |
| 287 } | 303 } |
| 288 SetBounds(x(), y(), width, height); | 304 SetBounds(x(), y(), width, height); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 image, 0, 0, image.width(), image.height(), | 451 image, 0, 0, image.width(), image.height(), |
| 436 image_x, | 452 image_x, |
| 437 cell_bounds.y() + (cell_bounds.height() - kImageSize) / 2, | 453 cell_bounds.y() + (cell_bounds.height() - kImageSize) / 2, |
| 438 kImageSize, kImageSize, true); | 454 kImageSize, kImageSize, true); |
| 439 } | 455 } |
| 440 text_x += kImageSize + kImageToTextPadding; | 456 text_x += kImageSize + kImageToTextPadding; |
| 441 } | 457 } |
| 442 canvas->DrawStringInt( | 458 canvas->DrawStringInt( |
| 443 model_->GetText(model_index, visible_columns_[j].column.id), font_, | 459 model_->GetText(model_index, visible_columns_[j].column.id), font_, |
| 444 kTextColor, | 460 kTextColor, |
| 445 GetMirroredXWithWidthInView(text_x, cell_bounds.right() - text_x), | 461 GetMirroredXWithWidthInView(text_x, cell_bounds.right() - text_x - |
| 462 kTextHorizontalPadding), |
| 446 cell_bounds.y() + kTextVerticalPadding, | 463 cell_bounds.y() + kTextVerticalPadding, |
| 447 cell_bounds.right() - text_x, | 464 cell_bounds.right() - text_x, |
| 448 cell_bounds.height() - kTextVerticalPadding * 2, | 465 cell_bounds.height() - kTextVerticalPadding * 2, |
| 449 TableColumnAlignmentToCanvasAlignment( | 466 TableColumnAlignmentToCanvasAlignment( |
| 450 visible_columns_[j].column.alignment)); | 467 visible_columns_[j].column.alignment)); |
| 451 } | 468 } |
| 452 } | 469 } |
| 453 } | 470 } |
| 454 | 471 |
| 455 void TableView::OnFocus() { | 472 void TableView::OnFocus() { |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 header_ = new TableHeader(this); | 546 header_ = new TableHeader(this); |
| 530 } | 547 } |
| 531 | 548 |
| 532 void TableView::UpdateVisibleColumnSizes() { | 549 void TableView::UpdateVisibleColumnSizes() { |
| 533 if (!header_) | 550 if (!header_) |
| 534 return; | 551 return; |
| 535 | 552 |
| 536 std::vector<ui::TableColumn> columns; | 553 std::vector<ui::TableColumn> columns; |
| 537 for (size_t i = 0; i < visible_columns_.size(); ++i) | 554 for (size_t i = 0; i < visible_columns_.size(); ++i) |
| 538 columns.push_back(visible_columns_[i].column); | 555 columns.push_back(visible_columns_[i].column); |
| 539 std::vector<int> sizes = | 556 std::vector<int> sizes = views::CalculateTableColumnSizes( |
| 540 views::CalculateTableColumnSizes(last_parent_width_, header_->font(), | 557 last_parent_width_, header_->font(), font_, |
| 541 font_, 0, // TODO: fix this | 558 std::max(kTextHorizontalPadding, TableHeader::kHorizontalPadding) * 2, |
| 542 columns, model_); | 559 columns, model_); |
| 543 DCHECK_EQ(visible_columns_.size(), sizes.size()); | 560 DCHECK_EQ(visible_columns_.size(), sizes.size()); |
| 544 int x = 0; | 561 int x = 0; |
| 545 for (size_t i = 0; i < visible_columns_.size(); ++i) { | 562 for (size_t i = 0; i < visible_columns_.size(); ++i) { |
| 546 visible_columns_[i].x = x; | 563 visible_columns_[i].x = x; |
| 547 visible_columns_[i].width = sizes[i]; | 564 visible_columns_[i].width = sizes[i]; |
| 548 x += sizes[i]; | 565 x += sizes[i]; |
| 549 } | 566 } |
| 550 } | 567 } |
| 551 | 568 |
| 552 TableView::PaintRegion TableView::GetPaintRegion( | 569 TableView::PaintRegion TableView::GetPaintRegion( |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 if (grouper_) { | 695 if (grouper_) { |
| 679 grouper_->GetGroupRange(model_index, &range); | 696 grouper_->GetGroupRange(model_index, &range); |
| 680 } else { | 697 } else { |
| 681 range.start = model_index; | 698 range.start = model_index; |
| 682 range.length = 1; | 699 range.length = 1; |
| 683 } | 700 } |
| 684 return range; | 701 return range; |
| 685 } | 702 } |
| 686 | 703 |
| 687 } // namespace views | 704 } // namespace views |
| OLD | NEW |