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_header.h" | 5 #include "ui/views/controls/table/table_header.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
10 #include "third_party/skia/include/core/SkPaint.h" | 10 #include "third_party/skia/include/core/SkPaint.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
26 | 26 |
27 // The minimum width we allow a column to go down to. | 27 // The minimum width we allow a column to go down to. |
28 const int kMinColumnWidth = 10; | 28 const int kMinColumnWidth = 10; |
29 | 29 |
30 // Distace from edge columns can be resized by. | 30 // Distace from edge columns can be resized by. |
31 const int kResizePadding = 5; | 31 const int kResizePadding = 5; |
32 | 32 |
33 // Amount of space above/below the separator. | 33 // Amount of space above/below the separator. |
34 const int kSeparatorPadding = 4; | 34 const int kSeparatorPadding = 4; |
35 | 35 |
36 const SkColor kTextColor = SK_ColorBLACK; | |
37 const SkColor kBackgroundColor1 = SkColorSetRGB(0xF9, 0xF9, 0xF9); | |
38 const SkColor kBackgroundColor2 = SkColorSetRGB(0xE8, 0xE8, 0xE8); | |
39 const SkColor kSeparatorColor = SkColorSetRGB(0xAA, 0xAA, 0xAA); | |
40 | |
41 // Size of the sort indicator (doesn't include padding). | 36 // Size of the sort indicator (doesn't include padding). |
42 const int kSortIndicatorSize = 8; | 37 const int kSortIndicatorSize = 8; |
43 | 38 |
44 } // namespace | 39 } // namespace |
45 | 40 |
46 // static | 41 // static |
47 const char TableHeader::kViewClassName[] = "TableHeader"; | 42 const char TableHeader::kViewClassName[] = "TableHeader"; |
48 // static | 43 // static |
49 const int TableHeader::kHorizontalPadding = 7; | 44 const int TableHeader::kHorizontalPadding = 7; |
50 // static | 45 // static |
51 const int TableHeader::kSortIndicatorWidth = kSortIndicatorSize + | 46 const int TableHeader::kSortIndicatorWidth = kSortIndicatorSize + |
52 TableHeader::kHorizontalPadding * 2; | 47 TableHeader::kHorizontalPadding * 2; |
53 | 48 |
54 typedef std::vector<TableView::VisibleColumn> Columns; | 49 typedef std::vector<TableView::VisibleColumn> Columns; |
55 | 50 |
56 TableHeader::TableHeader(TableView* table) : table_(table) { | 51 TableHeader::TableHeader(TableView* table) : table_(table) { |
57 set_background(Background::CreateVerticalGradientBackground( | 52 set_background( |
sky
2017/01/19 00:40:37
OnNativeThemeChanged should always be called (firs
Tom (Use chromium acct)
2017/01/19 02:03:23
Done.
| |
58 kBackgroundColor1, kBackgroundColor2)); | 53 Background::CreateSolidBackground(GetNativeTheme()->GetSystemColor( |
54 ui::NativeTheme::kColorId_TableHeaderBackground))); | |
59 } | 55 } |
60 | 56 |
61 TableHeader::~TableHeader() { | 57 TableHeader::~TableHeader() {} |
62 } | |
63 | 58 |
64 void TableHeader::Layout() { | 59 void TableHeader::Layout() { |
65 SetBounds(x(), y(), table_->width(), GetPreferredSize().height()); | 60 SetBounds(x(), y(), table_->width(), GetPreferredSize().height()); |
66 } | 61 } |
67 | 62 |
68 void TableHeader::OnPaint(gfx::Canvas* canvas) { | 63 void TableHeader::OnPaint(gfx::Canvas* canvas) { |
64 ui::NativeTheme* theme = GetNativeTheme(); | |
65 const SkColor text_color = | |
66 theme->GetSystemColor(ui::NativeTheme::kColorId_TableHeaderText); | |
67 const SkColor separator_color = | |
68 theme->GetSystemColor(ui::NativeTheme::kColorId_TableHeaderSeparator); | |
69 // Paint the background and a separator at the bottom. The separator color | 69 // Paint the background and a separator at the bottom. The separator color |
70 // matches that of the border around the scrollview. | 70 // matches that of the border around the scrollview. |
71 OnPaintBackground(canvas); | 71 OnPaintBackground(canvas); |
72 SkColor border_color = GetNativeTheme()->GetSystemColor( | 72 SkColor border_color = |
73 ui::NativeTheme::kColorId_UnfocusedBorderColor); | 73 theme->GetSystemColor(ui::NativeTheme::kColorId_UnfocusedBorderColor); |
74 canvas->DrawLine(gfx::Point(0, height() - 1), | 74 canvas->DrawLine(gfx::Point(0, height() - 1), |
75 gfx::Point(width(), height() - 1), border_color); | 75 gfx::Point(width(), height() - 1), border_color); |
76 | 76 |
77 const Columns& columns = table_->visible_columns(); | 77 const Columns& columns = table_->visible_columns(); |
78 const int sorted_column_id = table_->sort_descriptors().empty() ? -1 : | 78 const int sorted_column_id = table_->sort_descriptors().empty() ? -1 : |
79 table_->sort_descriptors()[0].column_id; | 79 table_->sort_descriptors()[0].column_id; |
80 for (size_t i = 0; i < columns.size(); ++i) { | 80 for (size_t i = 0; i < columns.size(); ++i) { |
81 if (columns[i].width >= 2) { | 81 if (columns[i].width >= 2) { |
82 const int separator_x = GetMirroredXInView( | 82 const int separator_x = GetMirroredXInView( |
83 columns[i].x + columns[i].width - 1); | 83 columns[i].x + columns[i].width - 1); |
84 canvas->DrawLine(gfx::Point(separator_x, kSeparatorPadding), | 84 canvas->DrawLine(gfx::Point(separator_x, kSeparatorPadding), |
85 gfx::Point(separator_x, height() - kSeparatorPadding), | 85 gfx::Point(separator_x, height() - kSeparatorPadding), |
86 kSeparatorColor); | 86 separator_color); |
87 } | 87 } |
88 | 88 |
89 const int x = columns[i].x + kHorizontalPadding; | 89 const int x = columns[i].x + kHorizontalPadding; |
90 int width = columns[i].width - kHorizontalPadding - kHorizontalPadding; | 90 int width = columns[i].width - kHorizontalPadding - kHorizontalPadding; |
91 if (width <= 0) | 91 if (width <= 0) |
92 continue; | 92 continue; |
93 | 93 |
94 const int title_width = | 94 const int title_width = |
95 gfx::GetStringWidth(columns[i].column.title, font_list_); | 95 gfx::GetStringWidth(columns[i].column.title, font_list_); |
96 const bool paint_sort_indicator = | 96 const bool paint_sort_indicator = |
97 (columns[i].column.id == sorted_column_id && | 97 (columns[i].column.id == sorted_column_id && |
98 title_width + kSortIndicatorWidth <= width); | 98 title_width + kSortIndicatorWidth <= width); |
99 | 99 |
100 if (paint_sort_indicator && | 100 if (paint_sort_indicator && |
101 columns[i].column.alignment == ui::TableColumn::RIGHT) { | 101 columns[i].column.alignment == ui::TableColumn::RIGHT) { |
102 width -= kSortIndicatorWidth; | 102 width -= kSortIndicatorWidth; |
103 } | 103 } |
104 | 104 |
105 canvas->DrawStringRectWithFlags( | 105 canvas->DrawStringRectWithFlags( |
106 columns[i].column.title, font_list_, kTextColor, | 106 columns[i].column.title, font_list_, text_color, |
107 gfx::Rect(GetMirroredXWithWidthInView(x, width), kVerticalPadding, | 107 gfx::Rect(GetMirroredXWithWidthInView(x, width), kVerticalPadding, |
108 width, height() - kVerticalPadding * 2), | 108 width, height() - kVerticalPadding * 2), |
109 TableColumnAlignmentToCanvasAlignment(columns[i].column.alignment)); | 109 TableColumnAlignmentToCanvasAlignment(columns[i].column.alignment)); |
110 | 110 |
111 if (paint_sort_indicator) { | 111 if (paint_sort_indicator) { |
112 SkPaint paint; | 112 SkPaint paint; |
113 paint.setColor(kTextColor); | 113 paint.setColor(text_color); |
114 paint.setStyle(SkPaint::kFill_Style); | 114 paint.setStyle(SkPaint::kFill_Style); |
115 paint.setAntiAlias(true); | 115 paint.setAntiAlias(true); |
116 | 116 |
117 int indicator_x = 0; | 117 int indicator_x = 0; |
118 ui::TableColumn::Alignment alignment = columns[i].column.alignment; | 118 ui::TableColumn::Alignment alignment = columns[i].column.alignment; |
119 if (base::i18n::IsRTL()) { | 119 if (base::i18n::IsRTL()) { |
120 if (alignment == ui::TableColumn::LEFT) | 120 if (alignment == ui::TableColumn::LEFT) |
121 alignment = ui::TableColumn::RIGHT; | 121 alignment = ui::TableColumn::RIGHT; |
122 else if (alignment == ui::TableColumn::RIGHT) | 122 else if (alignment == ui::TableColumn::RIGHT) |
123 alignment = ui::TableColumn::LEFT; | 123 alignment = ui::TableColumn::LEFT; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 break; | 222 break; |
223 case ui::ET_GESTURE_SCROLL_END: | 223 case ui::ET_GESTURE_SCROLL_END: |
224 resize_details_.reset(); | 224 resize_details_.reset(); |
225 break; | 225 break; |
226 default: | 226 default: |
227 return; | 227 return; |
228 } | 228 } |
229 event->SetHandled(); | 229 event->SetHandled(); |
230 } | 230 } |
231 | 231 |
232 void TableHeader::OnNativeThemeChanged(const ui::NativeTheme* theme) { | |
233 set_background(Background::CreateSolidBackground( | |
234 theme->GetSystemColor(ui::NativeTheme::kColorId_TableHeaderBackground))); | |
235 } | |
236 | |
232 bool TableHeader::StartResize(const ui::LocatedEvent& event) { | 237 bool TableHeader::StartResize(const ui::LocatedEvent& event) { |
233 if (is_resizing()) | 238 if (is_resizing()) |
234 return false; | 239 return false; |
235 | 240 |
236 const int index = GetResizeColumn(GetMirroredXInView(event.x())); | 241 const int index = GetResizeColumn(GetMirroredXInView(event.x())); |
237 if (index == -1) | 242 if (index == -1) |
238 return false; | 243 return false; |
239 | 244 |
240 resize_details_.reset(new ColumnResizeDetails); | 245 resize_details_.reset(new ColumnResizeDetails); |
241 resize_details_->column_index = index; | 246 resize_details_->column_index = index; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 if (index > 0 && x >= column.x - kResizePadding && | 284 if (index > 0 && x >= column.x - kResizePadding && |
280 x <= column.x + kResizePadding) { | 285 x <= column.x + kResizePadding) { |
281 return index - 1; | 286 return index - 1; |
282 } | 287 } |
283 const int max_x = column.x + column.width; | 288 const int max_x = column.x + column.width; |
284 return (x >= max_x - kResizePadding && x <= max_x + kResizePadding) ? | 289 return (x >= max_x - kResizePadding && x <= max_x + kResizePadding) ? |
285 index : -1; | 290 index : -1; |
286 } | 291 } |
287 | 292 |
288 } // namespace views | 293 } // namespace views |
OLD | NEW |