forked from Pissandshittium/pissandshittium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_theme.cc
398 lines (366 loc) · 16.3 KB
/
common_theme.cc
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
// 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/common_theme.h"
#include "base/logging.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/skia_util.h"
namespace ui {
SkColor GetAuraColor(NativeTheme::ColorId color_id,
const NativeTheme* base_theme) {
// High contrast overrides the normal colors for certain ColorIds to be much
// darker or lighter.
if (base_theme->UsesHighContrastColors()) {
switch (color_id) {
case NativeTheme::kColorId_ButtonEnabledColor:
case NativeTheme::kColorId_ButtonHoverColor:
return SK_ColorBLACK;
case NativeTheme::kColorId_MenuBorderColor:
case NativeTheme::kColorId_MenuSeparatorColor:
return SK_ColorBLACK;
case NativeTheme::kColorId_SeparatorColor:
return SK_ColorBLACK;
case NativeTheme::kColorId_FocusedBorderColor:
return gfx::kGoogleBlue900;
case NativeTheme::kColorId_UnfocusedBorderColor:
return SK_ColorBLACK;
case NativeTheme::kColorId_TabBottomBorder:
return SK_ColorBLACK;
case NativeTheme::kColorId_ProminentButtonColor:
return gfx::kGoogleBlue900;
default:
break;
}
}
// Second wave of MD colors (colors that only appear in secondary UI).
if (ui::MaterialDesignController::IsSecondaryUiMaterial()) {
static const SkColor kPrimaryTextColor = SK_ColorBLACK;
switch (color_id) {
// Labels
case NativeTheme::kColorId_LabelEnabledColor:
return kPrimaryTextColor;
case NativeTheme::kColorId_LabelDisabledColor:
return SkColorSetA(
base_theme->GetSystemColor(NativeTheme::kColorId_LabelEnabledColor),
gfx::kDisabledControlAlpha);
// FocusableBorder
case NativeTheme::kColorId_UnfocusedBorderColor:
return SkColorSetA(SK_ColorBLACK, 0x4e);
// Textfields
case NativeTheme::kColorId_TextfieldDefaultColor:
return kPrimaryTextColor;
case NativeTheme::kColorId_TextfieldDefaultBackground:
return base_theme->GetSystemColor(
NativeTheme::kColorId_DialogBackground);
case NativeTheme::kColorId_TextfieldReadOnlyColor:
return SkColorSetA(base_theme->GetSystemColor(
NativeTheme::kColorId_TextfieldDefaultColor),
gfx::kDisabledControlAlpha);
default:
break;
}
}
// Shared constant for disabled text.
static const SkColor kDisabledTextColor = SkColorSetRGB(0xA1, 0xA1, 0x92);
// Dialogs:
static const SkColor kDialogBackgroundColor = SK_ColorWHITE;
// Buttons:
static const SkColor kButtonEnabledColor = gfx::kChromeIconGrey;
static const SkColor kProminentButtonColor = gfx::kGoogleBlue500;
static const SkColor kProminentButtonTextColor = SK_ColorWHITE;
static const SkColor kBlueButtonTextColor = SK_ColorWHITE;
static const SkColor kBlueButtonShadowColor = SkColorSetRGB(0x53, 0x8C, 0xEA);
// MenuItem:
static const SkColor kTouchableMenuItemLabelColor =
SkColorSetRGB(0x20, 0x21, 0x24);
static const SkColor kActionableSubmenuVerticalSeparatorColor =
SkColorSetARGB(0x24, 0x20, 0x21, 0x24);
static const SkColor kMenuBackgroundColor = SK_ColorWHITE;
static const SkColor kMenuHighlightBackgroundColor =
SkColorSetA(SK_ColorBLACK, 0x14);
static const SkColor kSelectedMenuItemForegroundColor = SK_ColorBLACK;
static const SkColor kMenuBorderColor = SkColorSetRGB(0xBA, 0xBA, 0xBA);
static const SkColor kMenuSeparatorColor = SkColorSetRGB(0xE9, 0xE9, 0xE9);
static const SkColor kEnabledMenuItemForegroundColor = SK_ColorBLACK;
static const SkColor kMenuItemMinorTextColor =
SkColorSetA(SK_ColorBLACK, 0x89);
// Separator:
static const SkColor kSeparatorColor = SkColorSetRGB(0xE9, 0xE9, 0xE9);
// Link:
static const SkColor kLinkEnabledColor = gfx::kGoogleBlue700;
// Text selection colors:
static const SkColor kTextSelectionBackgroundFocused =
SkColorSetARGB(0x54, 0x60, 0xA8, 0xEB);
static const SkColor kTextSelectionColor = color_utils::AlphaBlend(
SK_ColorBLACK, kTextSelectionBackgroundFocused, 0xdd);
// Textfield:
static const SkColor kTextfieldDefaultColor = SK_ColorBLACK;
static const SkColor kTextfieldDefaultBackground = SK_ColorWHITE;
static const SkColor kTextfieldReadOnlyColor = kDisabledTextColor;
static const SkColor kTextfieldReadOnlyBackground = SK_ColorWHITE;
// Results tables:
static const SkColor kResultsTableText = SK_ColorBLACK;
static const SkColor kResultsTableDimmedText =
SkColorSetRGB(0x64, 0x64, 0x64);
static const SkColor kResultsTableHoveredBackground = color_utils::AlphaBlend(
kTextSelectionBackgroundFocused, kTextfieldDefaultBackground, 0x40);
const SkColor kPositiveTextColor = SkColorSetRGB(0x0b, 0x80, 0x43);
const SkColor kNegativeTextColor = SkColorSetRGB(0xc5, 0x39, 0x29);
static const SkColor kResultsTablePositiveText = color_utils::AlphaBlend(
kPositiveTextColor, kTextfieldDefaultBackground, 0xDD);
static const SkColor kResultsTablePositiveHoveredText =
color_utils::AlphaBlend(kPositiveTextColor,
kResultsTableHoveredBackground, 0xDD);
static const SkColor kResultsTablePositiveSelectedText =
color_utils::AlphaBlend(kPositiveTextColor,
kTextSelectionBackgroundFocused, 0xDD);
static const SkColor kResultsTableNegativeText = color_utils::AlphaBlend(
kNegativeTextColor, kTextfieldDefaultBackground, 0xDD);
static const SkColor kResultsTableNegativeHoveredText =
color_utils::AlphaBlend(kNegativeTextColor,
kResultsTableHoveredBackground, 0xDD);
static const SkColor kResultsTableNegativeSelectedText =
color_utils::AlphaBlend(kNegativeTextColor,
kTextSelectionBackgroundFocused, 0xDD);
// Tooltip:
static const SkColor kTooltipBackground = SkColorSetA(SK_ColorBLACK, 0xCC);
static const SkColor kTooltipTextColor = SkColorSetA(SK_ColorWHITE, 0xDE);
// Tree:
static const SkColor kTreeBackground = SK_ColorWHITE;
static const SkColor kTreeTextColor = SK_ColorBLACK;
static const SkColor kTreeSelectedTextColor = SK_ColorBLACK;
static const SkColor kTreeSelectionBackgroundColor =
SkColorSetRGB(0xEE, 0xEE, 0xEE);
// Table:
static const SkColor kTableBackground = SK_ColorWHITE;
static const SkColor kTableTextColor = SK_ColorBLACK;
static const SkColor kTableSelectedTextColor = SK_ColorBLACK;
static const SkColor kTableSelectionBackgroundColor =
SkColorSetRGB(0xEE, 0xEE, 0xEE);
static const SkColor kTableGroupingIndicatorColor =
SkColorSetRGB(0xCC, 0xCC, 0xCC);
// Material spinner/throbber:
static const SkColor kThrobberSpinningColor = gfx::kGoogleBlue500;
static const SkColor kThrobberWaitingColor = SkColorSetRGB(0xA6, 0xA6, 0xA6);
static const SkColor kThrobberLightColor = SkColorSetRGB(0xF4, 0xF8, 0xFD);
switch (color_id) {
// Dialogs
case NativeTheme::kColorId_WindowBackground:
case NativeTheme::kColorId_DialogBackground:
case NativeTheme::kColorId_BubbleBackground:
return kDialogBackgroundColor;
// Buttons
case NativeTheme::kColorId_ButtonEnabledColor:
case NativeTheme::kColorId_ButtonHoverColor:
return kButtonEnabledColor;
// TODO(estade): remove the BlueButton colors.
case NativeTheme::kColorId_BlueButtonEnabledColor:
case NativeTheme::kColorId_BlueButtonDisabledColor:
case NativeTheme::kColorId_BlueButtonPressedColor:
case NativeTheme::kColorId_BlueButtonHoverColor:
return kBlueButtonTextColor;
case NativeTheme::kColorId_BlueButtonShadowColor:
return kBlueButtonShadowColor;
case NativeTheme::kColorId_ProminentButtonColor:
return kProminentButtonColor;
case NativeTheme::kColorId_TextOnProminentButtonColor:
return kProminentButtonTextColor;
case NativeTheme::kColorId_ButtonPressedShade:
return SK_ColorTRANSPARENT;
case NativeTheme::kColorId_ButtonDisabledColor:
return kDisabledTextColor;
// MenuItem
case NativeTheme::kColorId_TouchableMenuItemLabelColor:
return kTouchableMenuItemLabelColor;
case NativeTheme::kColorId_ActionableSubmenuVerticalSeparatorColor:
return kActionableSubmenuVerticalSeparatorColor;
case NativeTheme::kColorId_SelectedMenuItemForegroundColor:
return kSelectedMenuItemForegroundColor;
case NativeTheme::kColorId_MenuBorderColor:
return kMenuBorderColor;
case NativeTheme::kColorId_MenuSeparatorColor:
return kMenuSeparatorColor;
case NativeTheme::kColorId_MenuBackgroundColor:
return kMenuBackgroundColor;
case NativeTheme::kColorId_FocusedMenuItemBackgroundColor:
return kMenuHighlightBackgroundColor;
case NativeTheme::kColorId_EnabledMenuItemForegroundColor:
return kEnabledMenuItemForegroundColor;
case NativeTheme::kColorId_DisabledMenuItemForegroundColor:
return kDisabledTextColor;
case NativeTheme::kColorId_MenuItemMinorTextColor:
return kMenuItemMinorTextColor;
// Label
case NativeTheme::kColorId_LabelEnabledColor:
return kButtonEnabledColor;
case NativeTheme::kColorId_LabelDisabledColor:
return base_theme->GetSystemColor(
NativeTheme::kColorId_ButtonDisabledColor);
case NativeTheme::kColorId_LabelTextSelectionColor:
return kTextSelectionColor;
case NativeTheme::kColorId_LabelTextSelectionBackgroundFocused:
return kTextSelectionBackgroundFocused;
// Link
// TODO(estade): where, if anywhere, do we use disabled links in Chrome?
case NativeTheme::kColorId_LinkDisabled:
return SK_ColorBLACK;
case NativeTheme::kColorId_LinkEnabled:
case NativeTheme::kColorId_LinkPressed:
return kLinkEnabledColor;
// Separator
case NativeTheme::kColorId_SeparatorColor:
return kSeparatorColor;
// TabbedPane
case NativeTheme::kColorId_TabTitleColorActive:
return SkColorSetRGB(0x42, 0x85, 0xF4);
case NativeTheme::kColorId_TabTitleColorInactive:
return SkColorSetRGB(0x75, 0x75, 0x75);
case NativeTheme::kColorId_TabBottomBorder:
return SkColorSetA(SK_ColorBLACK, 0x1E);
// Textfield
case NativeTheme::kColorId_TextfieldDefaultColor:
return kTextfieldDefaultColor;
case NativeTheme::kColorId_TextfieldDefaultBackground:
return kTextfieldDefaultBackground;
case NativeTheme::kColorId_TextfieldReadOnlyColor:
return kTextfieldReadOnlyColor;
case NativeTheme::kColorId_TextfieldReadOnlyBackground:
return kTextfieldReadOnlyBackground;
case NativeTheme::kColorId_TextfieldSelectionColor:
return kTextSelectionColor;
case NativeTheme::kColorId_TextfieldSelectionBackgroundFocused:
return kTextSelectionBackgroundFocused;
// Tooltip
case NativeTheme::kColorId_TooltipBackground:
return kTooltipBackground;
case NativeTheme::kColorId_TooltipText:
return kTooltipTextColor;
// Tree
case NativeTheme::kColorId_TreeBackground:
return kTreeBackground;
case NativeTheme::kColorId_TreeText:
return kTreeTextColor;
case NativeTheme::kColorId_TreeSelectedText:
case NativeTheme::kColorId_TreeSelectedTextUnfocused:
return kTreeSelectedTextColor;
case NativeTheme::kColorId_TreeSelectionBackgroundFocused:
case NativeTheme::kColorId_TreeSelectionBackgroundUnfocused:
return kTreeSelectionBackgroundColor;
// Table
case NativeTheme::kColorId_TableBackground:
return kTableBackground;
case NativeTheme::kColorId_TableText:
return kTableTextColor;
case NativeTheme::kColorId_TableSelectedText:
case NativeTheme::kColorId_TableSelectedTextUnfocused:
return kTableSelectedTextColor;
case NativeTheme::kColorId_TableSelectionBackgroundFocused:
case NativeTheme::kColorId_TableSelectionBackgroundUnfocused:
return kTableSelectionBackgroundColor;
case NativeTheme::kColorId_TableGroupingIndicatorColor:
return kTableGroupingIndicatorColor;
// Table Header
case NativeTheme::kColorId_TableHeaderText:
return base_theme->GetSystemColor(
NativeTheme::kColorId_EnabledMenuItemForegroundColor);
case NativeTheme::kColorId_TableHeaderBackground:
return base_theme->GetSystemColor(
NativeTheme::kColorId_MenuBackgroundColor);
case NativeTheme::kColorId_TableHeaderSeparator:
return base_theme->GetSystemColor(NativeTheme::kColorId_MenuBorderColor);
// FocusableBorder
case NativeTheme::kColorId_FocusedBorderColor:
return gfx::kGoogleBlue500;
case NativeTheme::kColorId_UnfocusedBorderColor:
return SkColorSetA(SK_ColorBLACK, 0x66);
// Results Tables
case NativeTheme::kColorId_ResultsTableNormalBackground:
return kTextfieldDefaultBackground;
case NativeTheme::kColorId_ResultsTableHoveredBackground:
return SkColorSetA(base_theme->GetSystemColor(
NativeTheme::kColorId_ResultsTableNormalText),
0x0D);
case NativeTheme::kColorId_ResultsTableSelectedBackground:
return SkColorSetA(base_theme->GetSystemColor(
NativeTheme::kColorId_ResultsTableNormalText),
0x14);
case NativeTheme::kColorId_ResultsTableNormalText:
case NativeTheme::kColorId_ResultsTableHoveredText:
case NativeTheme::kColorId_ResultsTableSelectedText:
return kResultsTableText;
case NativeTheme::kColorId_ResultsTableNormalDimmedText:
case NativeTheme::kColorId_ResultsTableHoveredDimmedText:
case NativeTheme::kColorId_ResultsTableSelectedDimmedText:
return kResultsTableDimmedText;
case NativeTheme::kColorId_ResultsTableNormalUrl:
case NativeTheme::kColorId_ResultsTableHoveredUrl:
case NativeTheme::kColorId_ResultsTableSelectedUrl:
return base_theme->GetSystemColor(NativeTheme::kColorId_LinkEnabled);
case NativeTheme::kColorId_ResultsTablePositiveText:
return kResultsTablePositiveText;
case NativeTheme::kColorId_ResultsTablePositiveHoveredText:
return kResultsTablePositiveHoveredText;
case NativeTheme::kColorId_ResultsTablePositiveSelectedText:
return kResultsTablePositiveSelectedText;
case NativeTheme::kColorId_ResultsTableNegativeText:
return kResultsTableNegativeText;
case NativeTheme::kColorId_ResultsTableNegativeHoveredText:
return kResultsTableNegativeHoveredText;
case NativeTheme::kColorId_ResultsTableNegativeSelectedText:
return kResultsTableNegativeSelectedText;
// Material spinner/throbber
case NativeTheme::kColorId_ThrobberSpinningColor:
return kThrobberSpinningColor;
case NativeTheme::kColorId_ThrobberWaitingColor:
return kThrobberWaitingColor;
case NativeTheme::kColorId_ThrobberLightColor:
return kThrobberLightColor;
// Alert icon colors
case NativeTheme::kColorId_AlertSeverityLow:
return gfx::kGoogleGreen700;
case NativeTheme::kColorId_AlertSeverityMedium:
return gfx::kGoogleYellow700;
case NativeTheme::kColorId_AlertSeverityHigh:
return gfx::kGoogleRed700;
case NativeTheme::kColorId_NumColors:
break;
}
NOTREACHED();
return gfx::kPlaceholderColor;
}
void CommonThemePaintMenuItemBackground(
const NativeTheme* theme,
cc::PaintCanvas* canvas,
NativeTheme::State state,
const gfx::Rect& rect,
const NativeTheme::MenuItemExtraParams& menu_item) {
cc::PaintFlags flags;
switch (state) {
case NativeTheme::kNormal:
case NativeTheme::kDisabled:
flags.setColor(
theme->GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor));
break;
case NativeTheme::kHovered:
flags.setColor(theme->GetSystemColor(
NativeTheme::kColorId_FocusedMenuItemBackgroundColor));
break;
default:
NOTREACHED() << "Invalid state " << state;
break;
}
if (menu_item.corner_radius > 0) {
const SkScalar radius = SkIntToScalar(menu_item.corner_radius);
canvas->drawRoundRect(gfx::RectToSkRect(rect), radius, radius, flags);
return;
}
canvas->drawRect(gfx::RectToSkRect(rect), flags);
}
} // namespace ui