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 "grit/ui_resources.h"
16 // ----------------------------------------------------------------------------
17 // Defaults for properties which are stored in the browser theme pack. If you
18 // change these defaults, you must increment the version number in
19 // browser_theme_pack.h
22 #if defined(OS_CHROMEOS)
23 // Used for theme fallback colors.
24 const SkColor kDefaultColorFrame
= SkColorSetRGB(109, 109, 109);
25 const SkColor kDefaultColorFrameInactive
= SkColorSetRGB(176, 176, 176);
27 const SkColor kDefaultColorFrame
= SkColorSetRGB(66, 116, 201);
28 const SkColor kDefaultColorFrameInactive
= SkColorSetRGB(161, 182, 228);
30 const SkColor kDefaultColorFrameIncognito
= SkColorSetRGB(83, 106, 139);
31 const SkColor kDefaultColorFrameIncognitoInactive
=
32 SkColorSetRGB(126, 139, 156);
33 #if defined(OS_MACOSX)
34 const SkColor kDefaultColorToolbar
= SkColorSetRGB(230, 230, 230);
36 const SkColor kDefaultColorToolbar
= SkColorSetRGB(223, 223, 223);
38 const SkColor kDefaultColorTabText
= SK_ColorBLACK
;
39 #if defined(OS_MACOSX)
40 const SkColor kDefaultColorBackgroundTabText
= SK_ColorBLACK
;
42 const SkColor kDefaultColorBackgroundTabText
= SkColorSetRGB(64, 64, 64);
44 const SkColor kDefaultColorBookmarkText
= SK_ColorBLACK
;
46 const SkColor kDefaultColorNTPBackground
=
47 color_utils::GetSysSkColor(COLOR_WINDOW
);
48 const SkColor kDefaultColorNTPText
=
49 color_utils::GetSysSkColor(COLOR_WINDOWTEXT
);
50 const SkColor kDefaultColorNTPLink
=
51 color_utils::GetSysSkColor(COLOR_HOTLIGHT
);
53 // TODO(beng): source from theme provider.
54 const SkColor kDefaultColorNTPBackground
= SK_ColorWHITE
;
55 const SkColor kDefaultColorNTPText
= SK_ColorBLACK
;
56 const SkColor kDefaultColorNTPLink
= SkColorSetRGB(6, 55, 116);
58 const SkColor kDefaultColorNTPHeader
= SkColorSetRGB(150, 150, 150);
59 const SkColor kDefaultColorNTPSection
= SkColorSetRGB(229, 229, 229);
60 const SkColor kDefaultColorNTPSectionText
= SK_ColorBLACK
;
61 const SkColor kDefaultColorNTPSectionLink
= SkColorSetRGB(6, 55, 116);
62 const SkColor kDefaultColorButtonBackground
= SkColorSetARGB(0, 0, 0, 0);
65 const color_utils::HSL kDefaultTintButtons
= { -1, -1, -1 };
66 const color_utils::HSL kDefaultTintFrame
= { -1, -1, -1 };
67 const color_utils::HSL kDefaultTintFrameInactive
= { -1, -1, 0.75f
};
68 const color_utils::HSL kDefaultTintFrameIncognito
= { -1, 0.2f
, 0.35f
};
69 const color_utils::HSL kDefaultTintFrameIncognitoInactive
= { -1, 0.3f
, 0.6f
};
70 const color_utils::HSL kDefaultTintBackgroundTab
= { -1, 0.5, 0.75 };
72 // Default display properties.
73 const int kDefaultDisplayPropertyNTPAlignment
=
74 ThemeProperties::ALIGN_CENTER
;
75 const int kDefaultDisplayPropertyNTPTiling
=
76 ThemeProperties::NO_REPEAT
;
77 // By default, we do not use the ntp alternate logo.
78 const int kDefaultDisplayPropertyNTPAlternateLogo
= 0;
80 // ----------------------------------------------------------------------------
81 // Defaults for properties which are not stored in the browser theme pack.
83 const SkColor kDefaultColorControlBackground
= SK_ColorWHITE
;
84 const SkColor kDefaultColorToolbarSeparator
= SkColorSetRGB(170, 170, 171);
86 #if defined(OS_MACOSX)
87 const SkColor kDefaultColorToolbarButtonStroke
= SkColorSetARGB(75, 81, 81, 81);
88 const SkColor kDefaultColorToolbarButtonStrokeInactive
=
89 SkColorSetARGB(75, 99, 99, 99);
90 const SkColor kDefaultColorToolbarBezel
= SkColorSetRGB(204, 204, 204);
91 const SkColor kDefaultColorToolbarStroke
= SkColorSetRGB(103, 103, 103);
92 const SkColor kDefaultColorToolbarStrokeInactive
= SkColorSetRGB(163, 163, 163);
95 // ----------------------------------------------------------------------------
97 // Strings used in alignment properties.
98 const char* kAlignmentCenter
= "center";
99 const char* kAlignmentTop
= "top";
100 const char* kAlignmentBottom
= "bottom";
101 const char* kAlignmentLeft
= "left";
102 const char* kAlignmentRight
= "right";
104 // Strings used in background tiling repetition properties.
105 const char* kTilingNoRepeat
= "no-repeat";
106 const char* kTilingRepeatX
= "repeat-x";
107 const char* kTilingRepeatY
= "repeat-y";
108 const char* kTilingRepeat
= "repeat";
110 // The image resources that will be tinted by the 'button' tint value.
111 // If you change this list, you must increment the version number in
112 // browser_theme_pack.cc, and you should assign persistent IDs to the
113 // data table at the start of said file or else tinted versions of
114 // these resources will not be created.
115 const int kToolbarButtonIDs
[] = {
116 IDR_BACK
, IDR_BACK_D
, IDR_BACK_H
, IDR_BACK_P
,
117 IDR_FORWARD
, IDR_FORWARD_D
, IDR_FORWARD_H
, IDR_FORWARD_P
,
118 IDR_HOME
, IDR_HOME_H
, IDR_HOME_P
,
119 IDR_RELOAD
, IDR_RELOAD_H
, IDR_RELOAD_P
,
120 IDR_STOP
, IDR_STOP_D
, IDR_STOP_H
, IDR_STOP_P
,
121 IDR_BROWSER_ACTIONS_OVERFLOW
, IDR_BROWSER_ACTIONS_OVERFLOW_H
,
122 IDR_BROWSER_ACTIONS_OVERFLOW_P
,
123 IDR_TOOLS
, IDR_TOOLS_H
, IDR_TOOLS_P
,
125 IDR_THROBBER
, IDR_THROBBER_WAITING
, IDR_THROBBER_LIGHT
,
126 IDR_TOOLBAR_BEZEL_HOVER
, IDR_TOOLBAR_BEZEL_PRESSED
, IDR_TOOLS_BAR
,
129 SkColor
TintForUnderline(SkColor input
) {
130 return SkColorSetA(input
, SkColorGetA(input
) / 3);
136 int ThemeProperties::StringToAlignment(const std::string
& alignment
) {
137 std::vector
<std::string
> split
;
138 base::SplitStringAlongWhitespace(alignment
, &split
);
140 int alignment_mask
= 0;
141 for (std::vector
<std::string
>::iterator
component(split
.begin());
142 component
!= split
.end(); ++component
) {
143 if (LowerCaseEqualsASCII(*component
, kAlignmentTop
))
144 alignment_mask
|= ALIGN_TOP
;
145 else if (LowerCaseEqualsASCII(*component
, kAlignmentBottom
))
146 alignment_mask
|= ALIGN_BOTTOM
;
147 else if (LowerCaseEqualsASCII(*component
, kAlignmentLeft
))
148 alignment_mask
|= ALIGN_LEFT
;
149 else if (LowerCaseEqualsASCII(*component
, kAlignmentRight
))
150 alignment_mask
|= ALIGN_RIGHT
;
152 return alignment_mask
;
156 int ThemeProperties::StringToTiling(const std::string
& tiling
) {
157 const char* component
= tiling
.c_str();
159 if (base::strcasecmp(component
, kTilingRepeatX
) == 0)
161 if (base::strcasecmp(component
, kTilingRepeatY
) == 0)
163 if (base::strcasecmp(component
, kTilingRepeat
) == 0)
165 // NO_REPEAT is the default choice.
170 std::string
ThemeProperties::AlignmentToString(int alignment
) {
171 // Convert from an AlignmentProperty back into a string.
172 std::string
vertical_string(kAlignmentCenter
);
173 std::string
horizontal_string(kAlignmentCenter
);
175 if (alignment
& ALIGN_TOP
)
176 vertical_string
= kAlignmentTop
;
177 else if (alignment
& ALIGN_BOTTOM
)
178 vertical_string
= kAlignmentBottom
;
180 if (alignment
& ALIGN_LEFT
)
181 horizontal_string
= kAlignmentLeft
;
182 else if (alignment
& ALIGN_RIGHT
)
183 horizontal_string
= kAlignmentRight
;
185 return horizontal_string
+ " " + vertical_string
;
189 std::string
ThemeProperties::TilingToString(int tiling
) {
190 // Convert from a TilingProperty back into a string.
191 if (tiling
== REPEAT_X
)
192 return kTilingRepeatX
;
193 if (tiling
== REPEAT_Y
)
194 return kTilingRepeatY
;
195 if (tiling
== REPEAT
)
196 return kTilingRepeat
;
197 return kTilingNoRepeat
;
201 bool ThemeProperties::IsThemeableImage(int id
) {
202 // TODO(pkotwicz): Cache results to improve lookup speed.
203 std::set
<int> themeable_idrs
;
204 BrowserThemePack::GetThemeableImageIDRs(&themeable_idrs
);
205 return themeable_idrs
.find(id
) != themeable_idrs
.end();
209 const std::set
<int>& ThemeProperties::GetTintableToolbarButtons() {
210 CR_DEFINE_STATIC_LOCAL(std::set
<int>, button_set
, ());
211 if (button_set
.empty()) {
212 button_set
= std::set
<int>(
214 kToolbarButtonIDs
+ arraysize(kToolbarButtonIDs
));
221 color_utils::HSL
ThemeProperties::GetDefaultTint(int id
) {
224 return kDefaultTintFrame
;
225 case TINT_FRAME_INACTIVE
:
226 return kDefaultTintFrameInactive
;
227 case TINT_FRAME_INCOGNITO
:
228 return kDefaultTintFrameIncognito
;
229 case TINT_FRAME_INCOGNITO_INACTIVE
:
230 return kDefaultTintFrameIncognitoInactive
;
232 return kDefaultTintButtons
;
233 case TINT_BACKGROUND_TAB
:
234 return kDefaultTintBackgroundTab
;
236 color_utils::HSL result
= {-1, -1, -1};
242 SkColor
ThemeProperties::GetDefaultColor(int id
) {
244 // Properties stored in theme pack.
246 return kDefaultColorFrame
;
247 case COLOR_FRAME_INACTIVE
:
248 return kDefaultColorFrameInactive
;
249 case COLOR_FRAME_INCOGNITO
:
250 return kDefaultColorFrameIncognito
;
251 case COLOR_FRAME_INCOGNITO_INACTIVE
:
252 return kDefaultColorFrameIncognitoInactive
;
254 return kDefaultColorToolbar
;
256 return kDefaultColorTabText
;
257 case COLOR_BACKGROUND_TAB_TEXT
:
258 return kDefaultColorBackgroundTabText
;
259 case COLOR_BOOKMARK_TEXT
:
260 return kDefaultColorBookmarkText
;
261 case COLOR_NTP_BACKGROUND
:
262 return kDefaultColorNTPBackground
;
264 return kDefaultColorNTPText
;
266 return kDefaultColorNTPLink
;
267 case COLOR_NTP_LINK_UNDERLINE
:
268 return TintForUnderline(kDefaultColorNTPLink
);
269 case COLOR_NTP_HEADER
:
270 return kDefaultColorNTPHeader
;
271 case COLOR_NTP_SECTION
:
272 return kDefaultColorNTPSection
;
273 case COLOR_NTP_SECTION_TEXT
:
274 return kDefaultColorNTPSectionText
;
275 case COLOR_NTP_SECTION_LINK
:
276 return kDefaultColorNTPSectionLink
;
277 case COLOR_NTP_SECTION_LINK_UNDERLINE
:
278 return TintForUnderline(kDefaultColorNTPSectionLink
);
279 case COLOR_BUTTON_BACKGROUND
:
280 return kDefaultColorButtonBackground
;
282 // Properties not stored in theme pack.
283 case COLOR_CONTROL_BACKGROUND
:
284 return kDefaultColorControlBackground
;
285 case COLOR_TOOLBAR_SEPARATOR
:
286 return kDefaultColorToolbarSeparator
;
287 #if defined(OS_MACOSX)
288 case COLOR_TOOLBAR_BUTTON_STROKE
:
289 return kDefaultColorToolbarButtonStroke
;
290 case COLOR_TOOLBAR_BUTTON_STROKE_INACTIVE
:
291 return kDefaultColorToolbarButtonStrokeInactive
;
292 case COLOR_TOOLBAR_BEZEL
:
293 return kDefaultColorToolbarBezel
;
294 case COLOR_TOOLBAR_STROKE
:
295 return kDefaultColorToolbarStroke
;
296 case COLOR_TOOLBAR_STROKE_INACTIVE
:
297 return kDefaultColorToolbarStrokeInactive
;
300 // Return a debugging red color.
306 int ThemeProperties::GetDefaultDisplayProperty(int id
) {
308 case NTP_BACKGROUND_ALIGNMENT
:
309 return kDefaultDisplayPropertyNTPAlignment
;
310 case NTP_BACKGROUND_TILING
:
311 return kDefaultDisplayPropertyNTPTiling
;
312 case NTP_LOGO_ALTERNATE
:
313 return kDefaultDisplayPropertyNTPAlternateLogo
;