1 // Copyright (c) 2013 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 "chrome/browser/themes/theme_properties.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/string_split.h"
9 #include "base/strings/string_util.h"
10 #include "chrome/browser/themes/browser_theme_pack.h"
11 #include "grit/theme_resources.h"
12 #include "ui/base/resource/material_design/material_design_controller.h"
13 #include "ui/resources/grit/ui_resources.h"
17 // ----------------------------------------------------------------------------
18 // Defaults for properties which are stored in the browser theme pack. If you
19 // change these defaults, you must increment the version number in
20 // browser_theme_pack.h
23 #if defined(OS_CHROMEOS)
24 // Used for theme fallback colors.
25 const SkColor kDefaultColorFrame
[] = {
26 SkColorSetRGB(109, 109, 109), SkColorSetRGB(204, 204, 204)};
27 const SkColor kDefaultColorFrameInactive
[] = {
28 SkColorSetRGB(176, 176, 176), SkColorSetRGB(220, 220, 220)};
29 #elif defined(OS_MACOSX)
30 const SkColor kDefaultColorFrame
= SkColorSetRGB(224, 224, 224);
31 const SkColor kDefaultColorFrameInactive
= SkColorSetRGB(246, 246, 246);
33 const SkColor kDefaultColorFrame
= SkColorSetRGB(66, 116, 201);
34 const SkColor kDefaultColorFrameInactive
= SkColorSetRGB(161, 182, 228);
37 const SkColor kDefaultColorFrameIncognito
[] = {
38 SkColorSetRGB(83, 106, 139), SkColorSetRGB(160, 160, 162)};
39 const SkColor kDefaultColorFrameIncognitoInactive
[] = {
40 SkColorSetRGB(126, 139, 156), SkColorSetRGB(120, 120, 122)};
42 #if defined(OS_MACOSX)
43 const SkColor kDefaultColorToolbar
= SkColorSetRGB(230, 230, 230);
45 const SkColor kDefaultColorToolbar
[] = {
46 SkColorSetRGB(223, 223, 223), SkColorSetRGB(242, 242, 242)};
49 const SkColor kDefaultColorTabText
= SK_ColorBLACK
;
51 #if defined(OS_MACOSX)
52 const SkColor kDefaultColorBackgroundTabText
= SK_ColorBLACK
;
54 const SkColor kDefaultColorBackgroundTabText
[] = {
55 SkColorSetRGB(64, 64, 64), SK_ColorBLACK
};
58 const SkColor kDefaultColorBookmarkText
= SK_ColorBLACK
;
61 const SkColor kDefaultColorNTPBackground
=
62 color_utils::GetSysSkColor(COLOR_WINDOW
);
63 const SkColor kDefaultColorNTPText
=
64 color_utils::GetSysSkColor(COLOR_WINDOWTEXT
);
65 const SkColor kDefaultColorNTPLink
=
66 color_utils::GetSysSkColor(COLOR_HOTLIGHT
);
68 // TODO(beng): source from theme provider.
69 const SkColor kDefaultColorNTPBackground
= SK_ColorWHITE
;
70 const SkColor kDefaultColorNTPText
= SK_ColorBLACK
;
71 const SkColor kDefaultColorNTPLink
= SkColorSetRGB(6, 55, 116);
74 const SkColor kDefaultColorNTPHeader
= SkColorSetRGB(150, 150, 150);
75 const SkColor kDefaultColorNTPSection
= SkColorSetRGB(229, 229, 229);
76 const SkColor kDefaultColorNTPSectionText
= SK_ColorBLACK
;
77 const SkColor kDefaultColorNTPSectionLink
= SkColorSetRGB(6, 55, 116);
78 const SkColor kDefaultColorButtonBackground
= SkColorSetARGB(0, 0, 0, 0);
81 const color_utils::HSL kDefaultTintButtons
= { -1, -1, -1 };
82 const color_utils::HSL kDefaultTintFrame
= { -1, -1, -1 };
83 const color_utils::HSL kDefaultTintFrameInactive
= { -1, -1, 0.75f
};
84 const color_utils::HSL kDefaultTintFrameIncognito
= { -1, 0.2f
, 0.35f
};
85 const color_utils::HSL kDefaultTintFrameIncognitoInactive
= { -1, 0.3f
, 0.6f
};
86 const color_utils::HSL kDefaultTintBackgroundTab
= { -1, 0.5, 0.75 };
88 // ----------------------------------------------------------------------------
89 // Defaults for properties which are not stored in the browser theme pack.
91 const SkColor kDefaultColorControlBackground
= SK_ColorWHITE
;
92 const SkColor kDefaultColorToolbarSeparator
[] = {
93 SkColorSetRGB(170, 170, 171), SkColorSetRGB(182, 180, 182)};
95 #if defined(OS_MACOSX)
96 const SkColor kDefaultColorToolbarButtonStroke
= SkColorSetARGB(75, 81, 81, 81);
97 const SkColor kDefaultColorToolbarButtonStrokeInactive
=
98 SkColorSetARGB(75, 99, 99, 99);
99 const SkColor kDefaultColorToolbarBezel
= SkColorSetRGB(204, 204, 204);
100 const SkColor kDefaultColorToolbarStroke
= SkColorSetRGB(103, 103, 103);
101 const SkColor kDefaultColorToolbarStrokeInactive
= SkColorSetRGB(163, 163, 163);
104 // ----------------------------------------------------------------------------
106 // Strings used in alignment properties.
107 const char kAlignmentCenter
[] = "center";
108 const char kAlignmentTop
[] = "top";
109 const char kAlignmentBottom
[] = "bottom";
110 const char kAlignmentLeft
[] = "left";
111 const char kAlignmentRight
[] = "right";
113 // Strings used in background tiling repetition properties.
114 const char kTilingNoRepeat
[] = "no-repeat";
115 const char kTilingRepeatX
[] = "repeat-x";
116 const char kTilingRepeatY
[] = "repeat-y";
117 const char kTilingRepeat
[] = "repeat";
119 // The image resources that will be tinted by the 'button' tint value.
120 // If you change this list, you must increment the version number in
121 // browser_theme_pack.cc, and you should assign persistent IDs to the
122 // data table at the start of said file or else tinted versions of
123 // these resources will not be created.
125 // TODO(erg): The cocoa port is the last user of the IDR_*_[HP] variants. These
126 // should be removed once the cocoa port no longer uses them.
127 const int kToolbarButtonIDs
[] = {
128 IDR_BACK
, IDR_BACK_D
, IDR_BACK_H
, IDR_BACK_P
,
129 IDR_FORWARD
, IDR_FORWARD_D
, IDR_FORWARD_H
, IDR_FORWARD_P
,
130 IDR_HOME
, IDR_HOME_H
, IDR_HOME_P
,
131 IDR_RELOAD
, IDR_RELOAD_H
, IDR_RELOAD_P
,
132 IDR_STOP
, IDR_STOP_D
, IDR_STOP_H
, IDR_STOP_P
,
133 IDR_BROWSER_ACTIONS_OVERFLOW
, IDR_BROWSER_ACTIONS_OVERFLOW_H
,
134 IDR_BROWSER_ACTIONS_OVERFLOW_P
,
135 IDR_TOOLS
, IDR_TOOLS_H
, IDR_TOOLS_P
,
137 IDR_TOOLBAR_BEZEL_HOVER
, IDR_TOOLBAR_BEZEL_PRESSED
, IDR_TOOLS_BAR
,
140 SkColor
TintForUnderline(SkColor input
) {
141 return SkColorSetA(input
, SkColorGetA(input
) / 3);
147 int ThemeProperties::StringToAlignment(const std::string
& alignment
) {
148 int alignment_mask
= 0;
149 for (const std::string
& component
: base::SplitString(
150 alignment
, base::kWhitespaceASCII
,
151 base::TRIM_WHITESPACE
, base::SPLIT_WANT_NONEMPTY
)) {
152 if (base::LowerCaseEqualsASCII(component
, kAlignmentTop
))
153 alignment_mask
|= ALIGN_TOP
;
154 else if (base::LowerCaseEqualsASCII(component
, kAlignmentBottom
))
155 alignment_mask
|= ALIGN_BOTTOM
;
156 else if (base::LowerCaseEqualsASCII(component
, kAlignmentLeft
))
157 alignment_mask
|= ALIGN_LEFT
;
158 else if (base::LowerCaseEqualsASCII(component
, kAlignmentRight
))
159 alignment_mask
|= ALIGN_RIGHT
;
161 return alignment_mask
;
165 int ThemeProperties::StringToTiling(const std::string
& tiling
) {
166 if (base::LowerCaseEqualsASCII(tiling
, kTilingRepeatX
))
168 if (base::LowerCaseEqualsASCII(tiling
, kTilingRepeatY
))
170 if (base::LowerCaseEqualsASCII(tiling
, kTilingRepeat
))
172 // NO_REPEAT is the default choice.
177 std::string
ThemeProperties::AlignmentToString(int alignment
) {
178 // Convert from an AlignmentProperty back into a string.
179 std::string
vertical_string(kAlignmentCenter
);
180 std::string
horizontal_string(kAlignmentCenter
);
182 if (alignment
& ALIGN_TOP
)
183 vertical_string
= kAlignmentTop
;
184 else if (alignment
& ALIGN_BOTTOM
)
185 vertical_string
= kAlignmentBottom
;
187 if (alignment
& ALIGN_LEFT
)
188 horizontal_string
= kAlignmentLeft
;
189 else if (alignment
& ALIGN_RIGHT
)
190 horizontal_string
= kAlignmentRight
;
192 return horizontal_string
+ " " + vertical_string
;
196 std::string
ThemeProperties::TilingToString(int tiling
) {
197 // Convert from a TilingProperty back into a string.
198 if (tiling
== REPEAT_X
)
199 return kTilingRepeatX
;
200 if (tiling
== REPEAT_Y
)
201 return kTilingRepeatY
;
202 if (tiling
== REPEAT
)
203 return kTilingRepeat
;
204 return kTilingNoRepeat
;
208 const std::set
<int>& ThemeProperties::GetTintableToolbarButtons() {
209 CR_DEFINE_STATIC_LOCAL(std::set
<int>, button_set
, ());
210 if (button_set
.empty()) {
211 button_set
= std::set
<int>(
213 kToolbarButtonIDs
+ arraysize(kToolbarButtonIDs
));
220 color_utils::HSL
ThemeProperties::GetDefaultTint(int id
) {
223 return kDefaultTintFrame
;
224 case TINT_FRAME_INACTIVE
:
225 return kDefaultTintFrameInactive
;
226 case TINT_FRAME_INCOGNITO
:
227 return kDefaultTintFrameIncognito
;
228 case TINT_FRAME_INCOGNITO_INACTIVE
:
229 return kDefaultTintFrameIncognitoInactive
;
231 return kDefaultTintButtons
;
232 case TINT_BACKGROUND_TAB
:
233 return kDefaultTintBackgroundTab
;
235 color_utils::HSL result
= {-1, -1, -1};
241 SkColor
ThemeProperties::GetDefaultColor(int id
) {
242 int mode
= ui::MaterialDesignController::IsModeMaterial();
244 // Properties stored in theme pack.
246 #if defined(OS_CHROMEOS)
247 return kDefaultColorFrame
[mode
];
249 return kDefaultColorFrame
;
250 #endif // OS_CHROMEOS
251 case COLOR_FRAME_INACTIVE
:
252 #if defined(OS_CHROMEOS)
253 return kDefaultColorFrameInactive
[mode
];
255 return kDefaultColorFrameInactive
;
256 #endif // OS_CHROMEOS
257 case COLOR_FRAME_INCOGNITO
:
258 return kDefaultColorFrameIncognito
[mode
];
259 case COLOR_FRAME_INCOGNITO_INACTIVE
:
260 return kDefaultColorFrameIncognitoInactive
[mode
];
262 #if defined(OS_MACOSX)
263 return kDefaultColorToolbar
;
265 return kDefaultColorToolbar
[mode
];
268 return kDefaultColorTabText
;
269 case COLOR_BACKGROUND_TAB_TEXT
:
270 #if defined(OS_MACOSX)
271 return kDefaultColorBackgroundTabText
;
273 return kDefaultColorBackgroundTabText
[mode
];
275 case COLOR_BOOKMARK_TEXT
:
276 return kDefaultColorBookmarkText
;
277 case COLOR_NTP_BACKGROUND
:
278 return kDefaultColorNTPBackground
;
280 return kDefaultColorNTPText
;
282 return kDefaultColorNTPLink
;
283 case COLOR_NTP_LINK_UNDERLINE
:
284 return TintForUnderline(kDefaultColorNTPLink
);
285 case COLOR_NTP_HEADER
:
286 return kDefaultColorNTPHeader
;
287 case COLOR_NTP_SECTION
:
288 return kDefaultColorNTPSection
;
289 case COLOR_NTP_SECTION_TEXT
:
290 return kDefaultColorNTPSectionText
;
291 case COLOR_NTP_SECTION_LINK
:
292 return kDefaultColorNTPSectionLink
;
293 case COLOR_NTP_SECTION_LINK_UNDERLINE
:
294 return TintForUnderline(kDefaultColorNTPSectionLink
);
295 case COLOR_BUTTON_BACKGROUND
:
296 return kDefaultColorButtonBackground
;
298 // Properties not stored in theme pack.
299 case COLOR_CONTROL_BACKGROUND
:
300 return kDefaultColorControlBackground
;
301 case COLOR_TOOLBAR_SEPARATOR
:
302 return kDefaultColorToolbarSeparator
[mode
];
303 #if defined(OS_MACOSX)
304 case COLOR_TOOLBAR_BUTTON_STROKE
:
305 return kDefaultColorToolbarButtonStroke
;
306 case COLOR_TOOLBAR_BUTTON_STROKE_INACTIVE
:
307 return kDefaultColorToolbarButtonStrokeInactive
;
308 case COLOR_TOOLBAR_BEZEL
:
309 return kDefaultColorToolbarBezel
;
310 case COLOR_TOOLBAR_STROKE
:
311 return kDefaultColorToolbarStroke
;
312 case COLOR_TOOLBAR_STROKE_INACTIVE
:
313 return kDefaultColorToolbarStrokeInactive
;
316 // Return a debugging red color.