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
3 // found in the LICENSE file.
5 #include "ui/native_theme/fallback_theme.h"
7 #include "base/basictypes.h"
8 #include "base/logging.h"
9 #include "ui/base/resource/material_design/material_design_controller.h"
10 #include "ui/gfx/color_utils.h"
11 #include "ui/native_theme/common_theme.h"
13 #define COLOR_FOR_MODE(ARRAY, MODE) \
14 DCHECK_LT(MODE, arraysize(ARRAY)); \
19 FallbackTheme::FallbackTheme() {
22 FallbackTheme::~FallbackTheme() {
25 SkColor
FallbackTheme::GetSystemColor(ColorId color_id
) const {
26 // This implementation returns hardcoded colors.
28 size_t mode
= ui::MaterialDesignController::IsModeMaterial();
30 static const SkColor kInvalidColorIdColor
= SkColorSetRGB(255, 0, 128);
32 static const SkColor kWindowBackgroundColor
= SK_ColorWHITE
;
34 static const SkColor kDialogBackgroundColor
= SkColorSetRGB(251, 251, 251);
36 static const SkColor kFocusedBorderColor
= SkColorSetRGB(0x4D, 0x90, 0xFE);
37 static const SkColor kUnfocusedBorderColor
= SkColorSetRGB(0xD9, 0xD9, 0xD9);
39 static const SkColor kButtonBackgroundColor
= SkColorSetRGB(0xDE, 0xDE, 0xDE);
40 static const SkColor kButtonEnabledColor
= SkColorSetRGB(0x22, 0x22, 0x22);
41 static const SkColor kButtonHighlightColor
= SkColorSetRGB(0, 0, 0);
42 static const SkColor kButtonHoverColor
= kButtonEnabledColor
;
44 static const SkColor kLabelEnabledColor
= kButtonEnabledColor
;
45 static const SkColor kLabelBackgroundColor
= SK_ColorWHITE
;
47 static const SkColor kTextfieldDefaultColor
= SK_ColorBLACK
;
48 static const SkColor kTextfieldDefaultBackground
= SK_ColorWHITE
;
49 static const SkColor kTextfieldReadOnlyColor
= SK_ColorDKGRAY
;
50 static const SkColor kTextfieldReadOnlyBackground
= SK_ColorWHITE
;
51 static const SkColor kTextfieldSelectionBackgroundFocused
=
52 SkColorSetARGB(0x54, 0x60, 0xA8, 0xEB);
53 static const SkColor kTextfieldSelectionColor
=
54 color_utils::AlphaBlend(SK_ColorBLACK
,
55 kTextfieldSelectionBackgroundFocused
, 0xdd);
57 static const SkColor kTooltipBackground
= 0xFFFFFFCC;
58 static const SkColor kTooltipTextColor
= kLabelEnabledColor
;
60 static const SkColor kTreeBackground
= SK_ColorWHITE
;
61 static const SkColor kTreeTextColor
= SK_ColorBLACK
;
62 static const SkColor kTreeSelectedTextColor
= SK_ColorBLACK
;
63 static const SkColor kTreeSelectionBackgroundColor
=
64 SkColorSetRGB(0xEE, 0xEE, 0xEE);
65 static const SkColor kTreeArrowColor
= SkColorSetRGB(0x7A, 0x7A, 0x7A);
67 static const SkColor kTableBackground
= SK_ColorWHITE
;
68 static const SkColor kTableTextColor
= SK_ColorBLACK
;
69 static const SkColor kTableSelectedTextColor
= SK_ColorBLACK
;
70 static const SkColor kTableSelectionBackgroundColor
=
71 SkColorSetRGB(0xEE, 0xEE, 0xEE);
72 static const SkColor kTableGroupingIndicatorColor
=
73 SkColorSetRGB(0xCC, 0xCC, 0xCC);
75 static const SkColor kResultsTableTextMD
= SK_ColorBLACK
;
76 static const SkColor kResultsTableDimmedTextMD
=
77 SkColorSetRGB(0x64, 0x64, 0x64);
78 static const SkColor kResultsTableUrlMD
= SkColorSetRGB(0x33, 0x67, 0xD6);
79 static const SkColor kResultsTableHoveredBackground
[] = {
80 color_utils::AlphaBlend(kTextfieldSelectionBackgroundFocused
,
81 kTextfieldDefaultBackground
, 0x40),
82 SkColorSetARGB(0x0D, 0x00, 0x00, 0x00)};
83 static const SkColor kResultsTableSelectedBackground
[] = {
84 kTextfieldSelectionBackgroundFocused
,
85 SkColorSetARGB(0x15, 0x00, 0x00, 0x00)};
86 static const SkColor kResultsTableNormalText
[] = {
87 color_utils::AlphaBlend(SK_ColorBLACK
, kTextfieldDefaultBackground
, 0xDD),
89 static const SkColor kResultsTableHoveredText
[] = {
90 color_utils::AlphaBlend(
91 SK_ColorBLACK
, kResultsTableHoveredBackground
[mode
], 0xDD),
93 static const SkColor kResultsTableSelectedText
[] = {
94 color_utils::AlphaBlend(
95 SK_ColorBLACK
, kTextfieldSelectionBackgroundFocused
, 0xDD),
97 static const SkColor kResultsTableNormalDimmedText
[] = {
98 color_utils::AlphaBlend(SK_ColorBLACK
, kTextfieldDefaultBackground
, 0xBB),
99 kResultsTableDimmedTextMD
};
100 static const SkColor kResultsTableHoveredDimmedText
[] = {
101 color_utils::AlphaBlend(
102 SK_ColorBLACK
, kResultsTableHoveredBackground
[mode
], 0xBB),
103 kResultsTableDimmedTextMD
};
104 static const SkColor kResultsTableSelectedDimmedText
[] = {
105 color_utils::AlphaBlend(
106 SK_ColorBLACK
, kTextfieldSelectionBackgroundFocused
, 0xBB),
107 kResultsTableDimmedTextMD
};
108 static const SkColor kResultsTableNormalUrl
[] = {
109 kTextfieldSelectionColor
,
111 static const SkColor kResultsTableSelectedOrHoveredUrl
[] = {
112 SkColorSetARGB(0xff, 0x0b, 0x80, 0x43),
114 static const SkColor kResultsTableNormalDivider
= color_utils::AlphaBlend(
115 kResultsTableNormalText
[mode
], kTextfieldDefaultBackground
, 0x34);
116 static const SkColor kResultsTableHoveredDivider
= color_utils::AlphaBlend(
117 kResultsTableHoveredText
[mode
],
118 kResultsTableHoveredBackground
[mode
], 0x34);
119 static const SkColor kResultsTabSelectedDivider
= color_utils::AlphaBlend(
120 kResultsTableSelectedText
[mode
],
121 kTextfieldSelectionBackgroundFocused
, 0x34);
122 const SkColor kPositiveTextColor
= SkColorSetRGB(0x0b, 0x80, 0x43);
123 const SkColor kNegativeTextColor
= SkColorSetRGB(0xc5, 0x39, 0x29);
124 static const SkColor kResultsTablePositiveText
[] = {
125 color_utils::AlphaBlend(
126 kPositiveTextColor
, kTextfieldDefaultBackground
, 0xDD),
128 static const SkColor kResultsTablePositiveHoveredText
[] = {
129 color_utils::AlphaBlend(
130 kPositiveTextColor
, kResultsTableHoveredBackground
[mode
], 0xDD),
132 static const SkColor kResultsTablePositiveSelectedText
[] = {
133 color_utils::AlphaBlend(
134 kPositiveTextColor
, kTextfieldSelectionBackgroundFocused
, 0xDD),
136 static const SkColor kResultsTableNegativeText
[] = {
137 color_utils::AlphaBlend(
138 kNegativeTextColor
, kTextfieldDefaultBackground
, 0xDD),
140 static const SkColor kResultsTableNegativeHoveredText
[] = {
141 color_utils::AlphaBlend(
142 kNegativeTextColor
, kResultsTableHoveredBackground
[mode
], 0xDD),
144 static const SkColor kResultsTableNegativeSelectedText
[] = {
145 color_utils::AlphaBlend(
146 kNegativeTextColor
, kTextfieldSelectionBackgroundFocused
, 0xDD),
150 if (CommonThemeGetSystemColor(color_id
, &color
))
155 case kColorId_WindowBackground
:
156 return kWindowBackgroundColor
;
159 case kColorId_DialogBackground
:
160 return kDialogBackgroundColor
;
163 case kColorId_FocusedBorderColor
:
164 return kFocusedBorderColor
;
165 case kColorId_UnfocusedBorderColor
:
166 return kUnfocusedBorderColor
;
169 case kColorId_ButtonBackgroundColor
:
170 return kButtonBackgroundColor
;
171 case kColorId_ButtonEnabledColor
:
172 return kButtonEnabledColor
;
173 case kColorId_ButtonHighlightColor
:
174 return kButtonHighlightColor
;
175 case kColorId_ButtonHoverColor
:
176 return kButtonHoverColor
;
179 case kColorId_LabelEnabledColor
:
180 return kLabelEnabledColor
;
181 case kColorId_LabelDisabledColor
:
182 return GetSystemColor(kColorId_ButtonDisabledColor
);
183 case kColorId_LabelBackgroundColor
:
184 return kLabelBackgroundColor
;
187 case kColorId_TextfieldDefaultColor
:
188 return kTextfieldDefaultColor
;
189 case kColorId_TextfieldDefaultBackground
:
190 return kTextfieldDefaultBackground
;
191 case kColorId_TextfieldReadOnlyColor
:
192 return kTextfieldReadOnlyColor
;
193 case kColorId_TextfieldReadOnlyBackground
:
194 return kTextfieldReadOnlyBackground
;
195 case kColorId_TextfieldSelectionColor
:
196 return kTextfieldSelectionColor
;
197 case kColorId_TextfieldSelectionBackgroundFocused
:
198 return kTextfieldSelectionBackgroundFocused
;
201 case kColorId_TooltipBackground
:
202 return kTooltipBackground
;
203 case kColorId_TooltipText
:
204 return kTooltipTextColor
;
207 case kColorId_TreeBackground
:
208 return kTreeBackground
;
209 case kColorId_TreeText
:
210 return kTreeTextColor
;
211 case kColorId_TreeSelectedText
:
212 case kColorId_TreeSelectedTextUnfocused
:
213 return kTreeSelectedTextColor
;
214 case kColorId_TreeSelectionBackgroundFocused
:
215 case kColorId_TreeSelectionBackgroundUnfocused
:
216 return kTreeSelectionBackgroundColor
;
217 case kColorId_TreeArrow
:
218 return kTreeArrowColor
;
221 case kColorId_TableBackground
:
222 return kTableBackground
;
223 case kColorId_TableText
:
224 return kTableTextColor
;
225 case kColorId_TableSelectedText
:
226 case kColorId_TableSelectedTextUnfocused
:
227 return kTableSelectedTextColor
;
228 case kColorId_TableSelectionBackgroundFocused
:
229 case kColorId_TableSelectionBackgroundUnfocused
:
230 return kTableSelectionBackgroundColor
;
231 case kColorId_TableGroupingIndicatorColor
:
232 return kTableGroupingIndicatorColor
;
235 case kColorId_ResultsTableNormalBackground
:
236 return kTextfieldDefaultBackground
;
237 case kColorId_ResultsTableHoveredBackground
:
238 COLOR_FOR_MODE(kResultsTableHoveredBackground
, mode
);
239 case kColorId_ResultsTableSelectedBackground
:
240 COLOR_FOR_MODE(kResultsTableSelectedBackground
, mode
);
241 case kColorId_ResultsTableNormalText
:
242 COLOR_FOR_MODE(kResultsTableNormalText
, mode
);
243 case kColorId_ResultsTableHoveredText
:
244 COLOR_FOR_MODE(kResultsTableHoveredText
, mode
);
245 case kColorId_ResultsTableSelectedText
:
246 COLOR_FOR_MODE(kResultsTableSelectedText
, mode
);
247 case kColorId_ResultsTableNormalDimmedText
:
248 COLOR_FOR_MODE(kResultsTableNormalDimmedText
, mode
);
249 case kColorId_ResultsTableHoveredDimmedText
:
250 COLOR_FOR_MODE(kResultsTableHoveredDimmedText
, mode
);
251 case kColorId_ResultsTableSelectedDimmedText
:
252 COLOR_FOR_MODE(kResultsTableSelectedDimmedText
, mode
);
253 case kColorId_ResultsTableNormalUrl
:
254 COLOR_FOR_MODE(kResultsTableNormalUrl
, mode
);
255 case kColorId_ResultsTableHoveredUrl
:
256 case kColorId_ResultsTableSelectedUrl
:
257 COLOR_FOR_MODE(kResultsTableSelectedOrHoveredUrl
, mode
);
258 case kColorId_ResultsTableNormalDivider
:
259 return kResultsTableNormalDivider
;
260 case kColorId_ResultsTableHoveredDivider
:
261 return kResultsTableHoveredDivider
;
262 case kColorId_ResultsTableSelectedDivider
:
263 return kResultsTabSelectedDivider
;
264 case kColorId_ResultsTablePositiveText
:
265 COLOR_FOR_MODE(kResultsTablePositiveText
, mode
);
266 case kColorId_ResultsTablePositiveHoveredText
:
267 COLOR_FOR_MODE(kResultsTablePositiveHoveredText
, mode
);
268 case kColorId_ResultsTablePositiveSelectedText
:
269 COLOR_FOR_MODE(kResultsTablePositiveSelectedText
, mode
);
270 case kColorId_ResultsTableNegativeText
:
271 COLOR_FOR_MODE(kResultsTableNegativeText
, mode
);
272 case kColorId_ResultsTableNegativeHoveredText
:
273 COLOR_FOR_MODE(kResultsTableNegativeHoveredText
, mode
);
274 case kColorId_ResultsTableNegativeSelectedText
:
275 COLOR_FOR_MODE(kResultsTableNegativeSelectedText
, mode
);
282 return kInvalidColorIdColor
;