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

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

Issue 2616273002: Native Themes: Add table header colors (Closed)
Patch Set: Add gradients back 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/views/controls/table/table_header.h ('k') | ui/views/examples/scroll_view_example.cc » ('j') | 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 }
63 54
64 void TableHeader::Layout() { 55 void TableHeader::Layout() {
65 SetBounds(x(), y(), table_->width(), GetPreferredSize().height()); 56 SetBounds(x(), y(), table_->width(), GetPreferredSize().height());
66 } 57 }
67 58
68 void TableHeader::OnPaint(gfx::Canvas* canvas) { 59 void TableHeader::OnPaint(gfx::Canvas* canvas) {
60 ui::NativeTheme* theme = GetNativeTheme();
61 const SkColor text_color =
62 theme->GetSystemColor(ui::NativeTheme::kColorId_TableHeaderText);
63 const SkColor separator_color =
64 theme->GetSystemColor(ui::NativeTheme::kColorId_TableHeaderSeparator);
69 // Paint the background and a separator at the bottom. The separator color 65 // Paint the background and a separator at the bottom. The separator color
70 // matches that of the border around the scrollview. 66 // matches that of the border around the scrollview.
71 OnPaintBackground(canvas); 67 OnPaintBackground(canvas);
72 SkColor border_color = GetNativeTheme()->GetSystemColor( 68 SkColor border_color =
73 ui::NativeTheme::kColorId_UnfocusedBorderColor); 69 theme->GetSystemColor(ui::NativeTheme::kColorId_UnfocusedBorderColor);
74 canvas->DrawLine(gfx::Point(0, height() - 1), 70 canvas->DrawLine(gfx::Point(0, height() - 1),
75 gfx::Point(width(), height() - 1), border_color); 71 gfx::Point(width(), height() - 1), border_color);
76 72
77 const Columns& columns = table_->visible_columns(); 73 const Columns& columns = table_->visible_columns();
78 const int sorted_column_id = table_->sort_descriptors().empty() ? -1 : 74 const int sorted_column_id = table_->sort_descriptors().empty() ? -1 :
79 table_->sort_descriptors()[0].column_id; 75 table_->sort_descriptors()[0].column_id;
80 for (size_t i = 0; i < columns.size(); ++i) { 76 for (size_t i = 0; i < columns.size(); ++i) {
81 if (columns[i].width >= 2) { 77 if (columns[i].width >= 2) {
82 const int separator_x = GetMirroredXInView( 78 const int separator_x = GetMirroredXInView(
83 columns[i].x + columns[i].width - 1); 79 columns[i].x + columns[i].width - 1);
84 canvas->DrawLine(gfx::Point(separator_x, kSeparatorPadding), 80 canvas->DrawLine(gfx::Point(separator_x, kSeparatorPadding),
85 gfx::Point(separator_x, height() - kSeparatorPadding), 81 gfx::Point(separator_x, height() - kSeparatorPadding),
86 kSeparatorColor); 82 separator_color);
87 } 83 }
88 84
89 const int x = columns[i].x + kHorizontalPadding; 85 const int x = columns[i].x + kHorizontalPadding;
90 int width = columns[i].width - kHorizontalPadding - kHorizontalPadding; 86 int width = columns[i].width - kHorizontalPadding - kHorizontalPadding;
91 if (width <= 0) 87 if (width <= 0)
92 continue; 88 continue;
93 89
94 const int title_width = 90 const int title_width =
95 gfx::GetStringWidth(columns[i].column.title, font_list_); 91 gfx::GetStringWidth(columns[i].column.title, font_list_);
96 const bool paint_sort_indicator = 92 const bool paint_sort_indicator =
97 (columns[i].column.id == sorted_column_id && 93 (columns[i].column.id == sorted_column_id &&
98 title_width + kSortIndicatorWidth <= width); 94 title_width + kSortIndicatorWidth <= width);
99 95
100 if (paint_sort_indicator && 96 if (paint_sort_indicator &&
101 columns[i].column.alignment == ui::TableColumn::RIGHT) { 97 columns[i].column.alignment == ui::TableColumn::RIGHT) {
102 width -= kSortIndicatorWidth; 98 width -= kSortIndicatorWidth;
103 } 99 }
104 100
105 canvas->DrawStringRectWithFlags( 101 canvas->DrawStringRectWithFlags(
106 columns[i].column.title, font_list_, kTextColor, 102 columns[i].column.title, font_list_, text_color,
107 gfx::Rect(GetMirroredXWithWidthInView(x, width), kVerticalPadding, 103 gfx::Rect(GetMirroredXWithWidthInView(x, width), kVerticalPadding,
108 width, height() - kVerticalPadding * 2), 104 width, height() - kVerticalPadding * 2),
109 TableColumnAlignmentToCanvasAlignment(columns[i].column.alignment)); 105 TableColumnAlignmentToCanvasAlignment(columns[i].column.alignment));
110 106
111 if (paint_sort_indicator) { 107 if (paint_sort_indicator) {
112 SkPaint paint; 108 SkPaint paint;
113 paint.setColor(kTextColor); 109 paint.setColor(text_color);
114 paint.setStyle(SkPaint::kFill_Style); 110 paint.setStyle(SkPaint::kFill_Style);
115 paint.setAntiAlias(true); 111 paint.setAntiAlias(true);
116 112
117 int indicator_x = 0; 113 int indicator_x = 0;
118 ui::TableColumn::Alignment alignment = columns[i].column.alignment; 114 ui::TableColumn::Alignment alignment = columns[i].column.alignment;
119 if (base::i18n::IsRTL()) { 115 if (base::i18n::IsRTL()) {
120 if (alignment == ui::TableColumn::LEFT) 116 if (alignment == ui::TableColumn::LEFT)
121 alignment = ui::TableColumn::RIGHT; 117 alignment = ui::TableColumn::RIGHT;
122 else if (alignment == ui::TableColumn::RIGHT) 118 else if (alignment == ui::TableColumn::RIGHT)
123 alignment = ui::TableColumn::LEFT; 119 alignment = ui::TableColumn::LEFT;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 break; 218 break;
223 case ui::ET_GESTURE_SCROLL_END: 219 case ui::ET_GESTURE_SCROLL_END:
224 resize_details_.reset(); 220 resize_details_.reset();
225 break; 221 break;
226 default: 222 default:
227 return; 223 return;
228 } 224 }
229 event->SetHandled(); 225 event->SetHandled();
230 } 226 }
231 227
228 void TableHeader::OnNativeThemeChanged(const ui::NativeTheme* theme) {
229 set_background(Background::CreateSolidBackground(
230 theme->GetSystemColor(ui::NativeTheme::kColorId_TableHeaderBackground)));
231 }
232
232 bool TableHeader::StartResize(const ui::LocatedEvent& event) { 233 bool TableHeader::StartResize(const ui::LocatedEvent& event) {
233 if (is_resizing()) 234 if (is_resizing())
234 return false; 235 return false;
235 236
236 const int index = GetResizeColumn(GetMirroredXInView(event.x())); 237 const int index = GetResizeColumn(GetMirroredXInView(event.x()));
237 if (index == -1) 238 if (index == -1)
238 return false; 239 return false;
239 240
240 resize_details_.reset(new ColumnResizeDetails); 241 resize_details_.reset(new ColumnResizeDetails);
241 resize_details_->column_index = index; 242 resize_details_->column_index = index;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 if (index > 0 && x >= column.x - kResizePadding && 280 if (index > 0 && x >= column.x - kResizePadding &&
280 x <= column.x + kResizePadding) { 281 x <= column.x + kResizePadding) {
281 return index - 1; 282 return index - 1;
282 } 283 }
283 const int max_x = column.x + column.width; 284 const int max_x = column.x + column.width;
284 return (x >= max_x - kResizePadding && x <= max_x + kResizePadding) ? 285 return (x >= max_x - kResizePadding && x <= max_x + kResizePadding) ?
285 index : -1; 286 index : -1;
286 } 287 }
287 288
288 } // namespace views 289 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/table/table_header.h ('k') | ui/views/examples/scroll_view_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698