Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1171)

Side by Side Diff: ui/views/controls/table/table_header.cc

Issue 2616273002: Native Themes: Add table header colors (Closed)
Patch Set: Update default colors Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/native_theme/native_theme_dark_aura.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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(
58 kBackgroundColor1, kBackgroundColor2));
59 }
60 52
61 TableHeader::~TableHeader() { 53 TableHeader::~TableHeader() {
62 } 54 }
63 55
64 void TableHeader::Layout() { 56 void TableHeader::Layout() {
65 SetBounds(x(), y(), table_->width(), GetPreferredSize().height()); 57 SetBounds(x(), y(), table_->width(), GetPreferredSize().height());
66 } 58 }
67 59
68 void TableHeader::OnPaint(gfx::Canvas* canvas) { 60 void TableHeader::OnPaint(gfx::Canvas* canvas) {
61 auto* theme = GetNativeTheme();
Elliot Glaysher 2017/01/18 00:01:55 ui::NativeTheme is short enough that you should pr
Tom (Use chromium acct) 2017/01/18 23:55:27 Done.
62 set_background(Background::CreateSolidBackground(
sky 2017/01/18 16:21:16 Why do you need to set the background on every pai
Tom (Use chromium acct) 2017/01/18 23:55:27 Done.
63 theme->GetSystemColor(ui::NativeTheme::kColorId_TableHeaderBackground)));
64 const SkColor text_color =
65 theme->GetSystemColor(ui::NativeTheme::kColorId_TableHeaderText);
66 const SkColor separator_color =
67 theme->GetSystemColor(ui::NativeTheme::kColorId_TableHeaderSeparator);
69 // Paint the background and a separator at the bottom. The separator color 68 // Paint the background and a separator at the bottom. The separator color
70 // matches that of the border around the scrollview. 69 // matches that of the border around the scrollview.
71 OnPaintBackground(canvas); 70 OnPaintBackground(canvas);
72 SkColor border_color = GetNativeTheme()->GetSystemColor( 71 SkColor border_color =
73 ui::NativeTheme::kColorId_UnfocusedBorderColor); 72 theme->GetSystemColor(ui::NativeTheme::kColorId_UnfocusedBorderColor);
74 canvas->DrawLine(gfx::Point(0, height() - 1), 73 canvas->DrawLine(gfx::Point(0, height() - 1),
75 gfx::Point(width(), height() - 1), border_color); 74 gfx::Point(width(), height() - 1), border_color);
76 75
77 const Columns& columns = table_->visible_columns(); 76 const Columns& columns = table_->visible_columns();
78 const int sorted_column_id = table_->sort_descriptors().empty() ? -1 : 77 const int sorted_column_id = table_->sort_descriptors().empty() ? -1 :
79 table_->sort_descriptors()[0].column_id; 78 table_->sort_descriptors()[0].column_id;
80 for (size_t i = 0; i < columns.size(); ++i) { 79 for (size_t i = 0; i < columns.size(); ++i) {
81 if (columns[i].width >= 2) { 80 if (columns[i].width >= 2) {
82 const int separator_x = GetMirroredXInView( 81 const int separator_x = GetMirroredXInView(
83 columns[i].x + columns[i].width - 1); 82 columns[i].x + columns[i].width - 1);
84 canvas->DrawLine(gfx::Point(separator_x, kSeparatorPadding), 83 canvas->DrawLine(gfx::Point(separator_x, kSeparatorPadding),
85 gfx::Point(separator_x, height() - kSeparatorPadding), 84 gfx::Point(separator_x, height() - kSeparatorPadding),
86 kSeparatorColor); 85 separator_color);
87 } 86 }
88 87
89 const int x = columns[i].x + kHorizontalPadding; 88 const int x = columns[i].x + kHorizontalPadding;
90 int width = columns[i].width - kHorizontalPadding - kHorizontalPadding; 89 int width = columns[i].width - kHorizontalPadding - kHorizontalPadding;
91 if (width <= 0) 90 if (width <= 0)
92 continue; 91 continue;
93 92
94 const int title_width = 93 const int title_width =
95 gfx::GetStringWidth(columns[i].column.title, font_list_); 94 gfx::GetStringWidth(columns[i].column.title, font_list_);
96 const bool paint_sort_indicator = 95 const bool paint_sort_indicator =
97 (columns[i].column.id == sorted_column_id && 96 (columns[i].column.id == sorted_column_id &&
98 title_width + kSortIndicatorWidth <= width); 97 title_width + kSortIndicatorWidth <= width);
99 98
100 if (paint_sort_indicator && 99 if (paint_sort_indicator &&
101 columns[i].column.alignment == ui::TableColumn::RIGHT) { 100 columns[i].column.alignment == ui::TableColumn::RIGHT) {
102 width -= kSortIndicatorWidth; 101 width -= kSortIndicatorWidth;
103 } 102 }
104 103
105 canvas->DrawStringRectWithFlags( 104 canvas->DrawStringRectWithFlags(
106 columns[i].column.title, font_list_, kTextColor, 105 columns[i].column.title, font_list_, text_color,
107 gfx::Rect(GetMirroredXWithWidthInView(x, width), kVerticalPadding, 106 gfx::Rect(GetMirroredXWithWidthInView(x, width), kVerticalPadding,
108 width, height() - kVerticalPadding * 2), 107 width, height() - kVerticalPadding * 2),
109 TableColumnAlignmentToCanvasAlignment(columns[i].column.alignment)); 108 TableColumnAlignmentToCanvasAlignment(columns[i].column.alignment));
110 109
111 if (paint_sort_indicator) { 110 if (paint_sort_indicator) {
112 SkPaint paint; 111 SkPaint paint;
113 paint.setColor(kTextColor); 112 paint.setColor(text_color);
114 paint.setStyle(SkPaint::kFill_Style); 113 paint.setStyle(SkPaint::kFill_Style);
115 paint.setAntiAlias(true); 114 paint.setAntiAlias(true);
116 115
117 int indicator_x = 0; 116 int indicator_x = 0;
118 ui::TableColumn::Alignment alignment = columns[i].column.alignment; 117 ui::TableColumn::Alignment alignment = columns[i].column.alignment;
119 if (base::i18n::IsRTL()) { 118 if (base::i18n::IsRTL()) {
120 if (alignment == ui::TableColumn::LEFT) 119 if (alignment == ui::TableColumn::LEFT)
121 alignment = ui::TableColumn::RIGHT; 120 alignment = ui::TableColumn::RIGHT;
122 else if (alignment == ui::TableColumn::RIGHT) 121 else if (alignment == ui::TableColumn::RIGHT)
123 alignment = ui::TableColumn::LEFT; 122 alignment = ui::TableColumn::LEFT;
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 if (index > 0 && x >= column.x - kResizePadding && 278 if (index > 0 && x >= column.x - kResizePadding &&
280 x <= column.x + kResizePadding) { 279 x <= column.x + kResizePadding) {
281 return index - 1; 280 return index - 1;
282 } 281 }
283 const int max_x = column.x + column.width; 282 const int max_x = column.x + column.width;
284 return (x >= max_x - kResizePadding && x <= max_x + kResizePadding) ? 283 return (x >= max_x - kResizePadding && x <= max_x + kResizePadding) ?
285 index : -1; 284 index : -1;
286 } 285 }
287 286
288 } // namespace views 287 } // namespace views
OLDNEW
« no previous file with comments | « ui/native_theme/native_theme_dark_aura.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698