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 10 matching lines...) Expand all Loading... |
21 #include "ui/gfx/geometry/rect_conversions.h" | 21 #include "ui/gfx/geometry/rect_conversions.h" |
22 #include "ui/gfx/image/image_skia.h" | 22 #include "ui/gfx/image/image_skia.h" |
23 #include "ui/gfx/skia_util.h" | 23 #include "ui/gfx/skia_util.h" |
24 #include "ui/gfx/text_utils.h" | 24 #include "ui/gfx/text_utils.h" |
25 #include "ui/native_theme/native_theme.h" | 25 #include "ui/native_theme/native_theme.h" |
26 #include "ui/views/controls/scroll_view.h" | 26 #include "ui/views/controls/scroll_view.h" |
27 #include "ui/views/controls/table/table_grouper.h" | 27 #include "ui/views/controls/table/table_grouper.h" |
28 #include "ui/views/controls/table/table_header.h" | 28 #include "ui/views/controls/table/table_header.h" |
29 #include "ui/views/controls/table/table_utils.h" | 29 #include "ui/views/controls/table/table_utils.h" |
30 #include "ui/views/controls/table/table_view_observer.h" | 30 #include "ui/views/controls/table/table_view_observer.h" |
31 #include "ui/views/controls/table/table_view_row_background_painter.h" | |
32 | 31 |
33 // Padding around the text (on each side). | 32 // Padding around the text (on each side). |
34 static const int kTextVerticalPadding = 3; | 33 static const int kTextVerticalPadding = 3; |
35 static const int kTextHorizontalPadding = 6; | 34 static const int kTextHorizontalPadding = 6; |
36 | 35 |
37 // Size of images. | 36 // Size of images. |
38 static const int kImageSize = 16; | 37 static const int kImageSize = 16; |
39 | 38 |
40 static const int kGroupingIndicatorSize = 6; | 39 static const int kGroupingIndicatorSize = 6; |
41 | 40 |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 | 172 |
174 View* TableView::CreateParentIfNecessary() { | 173 View* TableView::CreateParentIfNecessary() { |
175 ScrollView* scroll_view = ScrollView::CreateScrollViewWithBorder(); | 174 ScrollView* scroll_view = ScrollView::CreateScrollViewWithBorder(); |
176 scroll_view->SetContents(this); | 175 scroll_view->SetContents(this); |
177 CreateHeaderIfNecessary(); | 176 CreateHeaderIfNecessary(); |
178 if (header_) | 177 if (header_) |
179 scroll_view->SetHeader(header_); | 178 scroll_view->SetHeader(header_); |
180 return scroll_view; | 179 return scroll_view; |
181 } | 180 } |
182 | 181 |
183 void TableView::SetRowBackgroundPainter( | |
184 std::unique_ptr<TableViewRowBackgroundPainter> painter) { | |
185 row_background_painter_ = std::move(painter); | |
186 } | |
187 | |
188 void TableView::SetGrouper(TableGrouper* grouper) { | 182 void TableView::SetGrouper(TableGrouper* grouper) { |
189 grouper_ = grouper; | 183 grouper_ = grouper; |
190 SortItemsAndUpdateMapping(); | 184 SortItemsAndUpdateMapping(); |
191 } | 185 } |
192 | 186 |
193 int TableView::RowCount() const { | 187 int TableView::RowCount() const { |
194 return model_ ? model_->RowCount() : 0; | 188 return model_ ? model_->RowCount() : 0; |
195 } | 189 } |
196 | 190 |
197 void TableView::Select(int model_row) { | 191 void TableView::Select(int model_row) { |
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 | 537 |
544 const SkColor selected_bg_color = GetNativeTheme()->GetSystemColor( | 538 const SkColor selected_bg_color = GetNativeTheme()->GetSystemColor( |
545 text_background_color_id(HasFocus())); | 539 text_background_color_id(HasFocus())); |
546 const SkColor fg_color = GetNativeTheme()->GetSystemColor( | 540 const SkColor fg_color = GetNativeTheme()->GetSystemColor( |
547 ui::NativeTheme::kColorId_TableText); | 541 ui::NativeTheme::kColorId_TableText); |
548 const SkColor selected_fg_color = GetNativeTheme()->GetSystemColor( | 542 const SkColor selected_fg_color = GetNativeTheme()->GetSystemColor( |
549 selected_text_color_id(HasFocus())); | 543 selected_text_color_id(HasFocus())); |
550 for (int i = region.min_row; i < region.max_row; ++i) { | 544 for (int i = region.min_row; i < region.max_row; ++i) { |
551 const int model_index = ViewToModel(i); | 545 const int model_index = ViewToModel(i); |
552 const bool is_selected = selection_model_.IsSelected(model_index); | 546 const bool is_selected = selection_model_.IsSelected(model_index); |
553 if (is_selected) { | 547 if (is_selected) |
554 canvas->FillRect(GetRowBounds(i), selected_bg_color); | 548 canvas->FillRect(GetRowBounds(i), selected_bg_color); |
555 } else if (row_background_painter_) { | |
556 row_background_painter_->PaintRowBackground(model_index, | |
557 GetRowBounds(i), | |
558 canvas); | |
559 } | |
560 if (selection_model_.active() == model_index && HasFocus()) | 549 if (selection_model_.active() == model_index && HasFocus()) |
561 canvas->DrawFocusRect(GetRowBounds(i)); | 550 canvas->DrawFocusRect(GetRowBounds(i)); |
562 for (int j = region.min_column; j < region.max_column; ++j) { | 551 for (int j = region.min_column; j < region.max_column; ++j) { |
563 const gfx::Rect cell_bounds(GetCellBounds(i, j)); | 552 const gfx::Rect cell_bounds(GetCellBounds(i, j)); |
564 int text_x = kTextHorizontalPadding + cell_bounds.x(); | 553 int text_x = kTextHorizontalPadding + cell_bounds.x(); |
565 | 554 |
566 // Provide space for the grouping indicator, but draw it separately. | 555 // Provide space for the grouping indicator, but draw it separately. |
567 if (j == 0 && grouper_) | 556 if (j == 0 && grouper_) |
568 text_x += kGroupingIndicatorSize + kTextHorizontalPadding; | 557 text_x += kGroupingIndicatorSize + kTextHorizontalPadding; |
569 | 558 |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 if (tooltip) | 944 if (tooltip) |
956 *tooltip = text; | 945 *tooltip = text; |
957 if (tooltip_origin) { | 946 if (tooltip_origin) { |
958 tooltip_origin->SetPoint(cell_bounds.x(), | 947 tooltip_origin->SetPoint(cell_bounds.x(), |
959 cell_bounds.y() + kTextVerticalPadding); | 948 cell_bounds.y() + kTextVerticalPadding); |
960 } | 949 } |
961 return true; | 950 return true; |
962 } | 951 } |
963 | 952 |
964 } // namespace views | 953 } // namespace views |
OLD | NEW |