1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/native_theme/native_theme_aura.h"
#include "base/logging.h"
#include "grit/ui_resources.h"
#include "ui/base/layout.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
#include "ui/gfx/skbitmap_operations.h"
#include "ui/native_theme/common_theme.h"
namespace {
const SkColor kMenuBackgroundColor = SK_ColorWHITE;
// Theme colors returned by GetSystemColor().
const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128);
// Windows:
const SkColor kWindowBackgroundColor = SK_ColorWHITE;
// Dialogs:
const SkColor kDialogBackgroundColor = SkColorSetRGB(251, 251, 251);
// FocusableBorder:
const SkColor kFocusedBorderColor = SkColorSetRGB(0x4D, 0x90, 0xFE);
const SkColor kUnfocusedBorderColor = SkColorSetRGB(0xD9, 0xD9, 0xD9);
// TextButton:
const SkColor kTextButtonBackgroundColor = SkColorSetRGB(0xDE, 0xDE, 0xDE);
const SkColor kTextButtonEnabledColor = SkColorSetRGB(0x22, 0x22, 0x22);
const SkColor kTextButtonDisabledColor = SkColorSetRGB(0x99, 0x99, 0x99);
const SkColor kTextButtonHighlightColor = SkColorSetRGB(0, 0, 0);
const SkColor kTextButtonHoverColor = kTextButtonEnabledColor;
// MenuItem:
const SkColor kEnabledMenuItemForegroundColor = kTextButtonEnabledColor;
const SkColor kDisabledMenuItemForegroundColor = kTextButtonDisabledColor;
const SkColor kFocusedMenuItemBackgroundColor = SkColorSetRGB(0xF1, 0xF1, 0xF1);
const SkColor kMenuSeparatorColor = SkColorSetRGB(0xED, 0xED, 0xED);
// Label:
const SkColor kLabelEnabledColor = kTextButtonEnabledColor;
const SkColor kLabelDisabledColor = kTextButtonDisabledColor;
const SkColor kLabelBackgroundColor = SK_ColorWHITE;
// Textfield:
const SkColor kTextfieldDefaultColor = SK_ColorBLACK;
const SkColor kTextfieldDefaultBackground = SK_ColorWHITE;
const SkColor kTextfieldReadOnlyColor = SK_ColorDKGRAY;
const SkColor kTextfieldReadOnlyBackground = SK_ColorWHITE;
const SkColor kTextfieldSelectionBackgroundFocused =
SkColorSetARGB(0x54, 0x60, 0xA8, 0xEB);
const SkColor kTextfieldSelectionBackgroundUnfocused = SK_ColorLTGRAY;
const SkColor kTextfieldSelectionColor =
color_utils::AlphaBlend(SK_ColorBLACK,
kTextfieldSelectionBackgroundFocused, 0xdd);
// Tree
const SkColor kTreeBackground = SK_ColorWHITE;
const SkColor kTreeTextColor = SK_ColorBLACK;
const SkColor kTreeSelectedTextColor = SK_ColorBLACK;
const SkColor kTreeSelectionBackgroundColor = SkColorSetRGB(0xEE, 0xEE, 0xEE);
const SkColor kTreeArrowColor = SkColorSetRGB(0x7A, 0x7A, 0x7A);
// Table
const SkColor kTableBackground = SK_ColorWHITE;
const SkColor kTableTextColor = SK_ColorBLACK;
const SkColor kTableSelectedTextColor = SK_ColorBLACK;
const SkColor kTableSelectionBackgroundColor = SkColorSetRGB(0xEE, 0xEE, 0xEE);
const SkColor kTableGroupingIndicatorColor = SkColorSetRGB(0xCC, 0xCC, 0xCC);
} // namespace
namespace ui {
// static
NativeTheme* NativeTheme::instance() {
return NativeThemeAura::instance();
}
// static
NativeThemeAura* NativeThemeAura::instance() {
CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, ());
return &s_native_theme;
}
NativeThemeAura::NativeThemeAura() {
// We don't draw scrollbar buttons.
set_scrollbar_button_length(0);
}
NativeThemeAura::~NativeThemeAura() {
}
SkColor NativeThemeAura::GetSystemColor(ColorId color_id) const {
// This implementation returns hardcoded colors.
SkColor color;
if (IsNewMenuStyleEnabled() && CommonThemeGetSystemColor(color_id, &color))
return color;
switch (color_id) {
// Windows
case kColorId_WindowBackground:
return kWindowBackgroundColor;
// Dialogs
case kColorId_DialogBackground:
return kDialogBackgroundColor;
// FocusableBorder
case kColorId_FocusedBorderColor:
return kFocusedBorderColor;
case kColorId_UnfocusedBorderColor:
return kUnfocusedBorderColor;
// TextButton
case kColorId_TextButtonBackgroundColor:
return kTextButtonBackgroundColor;
case kColorId_TextButtonEnabledColor:
return kTextButtonEnabledColor;
case kColorId_TextButtonDisabledColor:
return kTextButtonDisabledColor;
case kColorId_TextButtonHighlightColor:
return kTextButtonHighlightColor;
case kColorId_TextButtonHoverColor:
return kTextButtonHoverColor;
// MenuItem
case kColorId_EnabledMenuItemForegroundColor:
return kEnabledMenuItemForegroundColor;
case kColorId_DisabledMenuItemForegroundColor:
return kDisabledMenuItemForegroundColor;
case kColorId_FocusedMenuItemBackgroundColor:
return kFocusedMenuItemBackgroundColor;
case kColorId_MenuSeparatorColor:
return kMenuSeparatorColor;
// Label
case kColorId_LabelEnabledColor:
return kLabelEnabledColor;
case kColorId_LabelDisabledColor:
return kLabelDisabledColor;
case kColorId_LabelBackgroundColor:
return kLabelBackgroundColor;
// Textfield
case kColorId_TextfieldDefaultColor:
return kTextfieldDefaultColor;
case kColorId_TextfieldDefaultBackground:
return kTextfieldDefaultBackground;
case kColorId_TextfieldReadOnlyColor:
return kTextfieldReadOnlyColor;
case kColorId_TextfieldReadOnlyBackground:
return kTextfieldReadOnlyBackground;
case kColorId_TextfieldSelectionColor:
return kTextfieldSelectionColor;
case kColorId_TextfieldSelectionBackgroundFocused:
return kTextfieldSelectionBackgroundFocused;
case kColorId_TextfieldSelectionBackgroundUnfocused:
return kTextfieldSelectionBackgroundUnfocused;
// Tree
case kColorId_TreeBackground:
return kTreeBackground;
case kColorId_TreeText:
return kTreeTextColor;
case kColorId_TreeSelectedText:
case kColorId_TreeSelectedTextUnfocused:
return kTreeSelectedTextColor;
case kColorId_TreeSelectionBackgroundFocused:
case kColorId_TreeSelectionBackgroundUnfocused:
return kTreeSelectionBackgroundColor;
case kColorId_TreeArrow:
return kTreeArrowColor;
// Table
case kColorId_TableBackground:
return kTableBackground;
case kColorId_TableText:
return kTableTextColor;
case kColorId_TableSelectedText:
case kColorId_TableSelectedTextUnfocused:
return kTableSelectedTextColor;
case kColorId_TableSelectionBackgroundFocused:
case kColorId_TableSelectionBackgroundUnfocused:
return kTableSelectionBackgroundColor;
case kColorId_TableGroupingIndicatorColor:
return kTableGroupingIndicatorColor;
case kColorId_MenuBackgroundColor:
case kColorId_MenuBorderColor:
NOTREACHED();
break;
}
return kInvalidColorIdColor;
}
void NativeThemeAura::PaintMenuPopupBackground(SkCanvas* canvas,
const gfx::Size& size) const {
canvas->drawColor(kMenuBackgroundColor, SkXfermode::kSrc_Mode);
}
void NativeThemeAura::PaintScrollbarTrack(
SkCanvas* canvas,
Part part,
State state,
const ScrollbarTrackExtraParams& extra_params,
const gfx::Rect& rect) const {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
if (part == kScrollbarVerticalTrack) {
int center_offset = 0;
int center_height = rect.height();
if (rect.y() == extra_params.track_y) {
// TODO(derat): Honor |state| instead of only using the highlighted images
// after updating WebKit so we can draw the entire track in one go instead
// of as two separate pieces: otherwise, only the portion of the scrollbar
// that the mouse is over gets the highlighted state.
gfx::ImageSkia* top = rb.GetImageSkiaNamed(
IDR_SCROLL_BASE_VERTICAL_TOP_H);
DrawTiledImage(canvas, *top,
0, 0, 1.0, 1.0,
rect.x(), rect.y(), top->width(), top->height());
center_offset += top->height();
center_height -= top->height();
}
if (rect.y() + rect.height() ==
extra_params.track_y + extra_params.track_height) {
gfx::ImageSkia* bottom = rb.GetImageSkiaNamed(
IDR_SCROLL_BASE_VERTICAL_BOTTOM_H);
DrawTiledImage(canvas, *bottom,
0, 0, 1.0, 1.0,
rect.x(), rect.y() + rect.height() - bottom->height(),
bottom->width(), bottom->height());
center_height -= bottom->height();
}
if (center_height > 0) {
gfx::ImageSkia* center = rb.GetImageSkiaNamed(
IDR_SCROLL_BASE_VERTICAL_CENTER_H);
DrawTiledImage(canvas, *center,
0, 0, 1.0, 1.0,
rect.x(), rect.y() + center_offset,
center->width(), center_height);
}
} else {
int center_offset = 0;
int center_width = rect.width();
if (rect.x() == extra_params.track_x) {
gfx::ImageSkia* left = rb.GetImageSkiaNamed(
IDR_SCROLL_BASE_HORIZONTAL_LEFT_H);
DrawTiledImage(canvas, *left,
0, 0, 1.0, 1.0,
rect.x(), rect.y(), left->width(), left->height());
center_offset += left->width();
center_width -= left->width();
}
if (rect.x() + rect.width() ==
extra_params.track_x + extra_params.track_width) {
gfx::ImageSkia* right = rb.GetImageSkiaNamed(
IDR_SCROLL_BASE_HORIZONTAL_RIGHT_H);
DrawTiledImage(canvas, *right,
0, 0, 1.0, 1.0,
rect.x() + rect.width() - right->width(), rect.y(),
right->width(), right->height());
center_width -= right->width();
}
if (center_width > 0) {
gfx::ImageSkia* center = rb.GetImageSkiaNamed(
IDR_SCROLL_BASE_HORIZONTAL_CENTER_H);
DrawTiledImage(canvas, *center,
0, 0, 1.0, 1.0,
rect.x() + center_offset, rect.y(),
center_width, center->height());
}
}
}
void NativeThemeAura::PaintScrollbarThumb(SkCanvas* canvas,
Part part,
State state,
const gfx::Rect& rect) const {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
if (part == kScrollbarVerticalThumb) {
int top_resource_id =
state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_TOP_H :
state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_TOP_P :
IDR_SCROLL_THUMB_VERTICAL_TOP;
gfx::ImageSkia* top = rb.GetImageSkiaNamed(top_resource_id);
DrawTiledImage(canvas, *top,
0, 0, 1.0, 1.0,
rect.x(), rect.y(), top->width(), top->height());
int bottom_resource_id =
state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_BOTTOM_H :
state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_BOTTOM_P :
IDR_SCROLL_THUMB_VERTICAL_BOTTOM;
gfx::ImageSkia* bottom = rb.GetImageSkiaNamed(bottom_resource_id);
DrawTiledImage(canvas, *bottom,
0, 0, 1.0, 1.0,
rect.x(), rect.y() + rect.height() - bottom->height(),
bottom->width(), bottom->height());
if (rect.height() > top->height() + bottom->height()) {
int center_resource_id =
state == kHovered ? IDR_SCROLL_THUMB_VERTICAL_CENTER_H :
state == kPressed ? IDR_SCROLL_THUMB_VERTICAL_CENTER_P :
IDR_SCROLL_THUMB_VERTICAL_CENTER;
gfx::ImageSkia* center = rb.GetImageSkiaNamed(center_resource_id);
DrawTiledImage(canvas, *center,
0, 0, 1.0, 1.0,
rect.x(), rect.y() + top->height(),
center->width(),
rect.height() - top->height() - bottom->height());
}
} else {
int left_resource_id =
state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_LEFT_H :
state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_LEFT_P :
IDR_SCROLL_THUMB_HORIZONTAL_LEFT;
gfx::ImageSkia* left = rb.GetImageSkiaNamed(left_resource_id);
DrawTiledImage(canvas, *left,
0, 0, 1.0, 1.0,
rect.x(), rect.y(), left->width(), left->height());
int right_resource_id =
state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_RIGHT_H :
state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_RIGHT_P :
IDR_SCROLL_THUMB_HORIZONTAL_RIGHT;
gfx::ImageSkia* right = rb.GetImageSkiaNamed(right_resource_id);
DrawTiledImage(canvas, *right,
0, 0, 1.0, 1.0,
rect.x() + rect.width() - right->width(), rect.y(),
right->width(), right->height());
if (rect.width() > left->width() + right->width()) {
int center_resource_id =
state == kHovered ? IDR_SCROLL_THUMB_HORIZONTAL_CENTER_H :
state == kPressed ? IDR_SCROLL_THUMB_HORIZONTAL_CENTER_P :
IDR_SCROLL_THUMB_HORIZONTAL_CENTER;
gfx::ImageSkia* center = rb.GetImageSkiaNamed(center_resource_id);
DrawTiledImage(canvas, *center,
0, 0, 1.0, 1.0,
rect.x() + left->width(), rect.y(),
rect.width() - left->width() - right->width(),
center->height());
}
}
}
} // namespace ui
|