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/resources/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.
116 // TODO(erg): The cocoa port is the last user of the IDR_*_[HP] variants. These
117 // should be removed once the cocoa port no longer uses them.
118 const int kToolbarButtonIDs
[] = {
119 IDR_BACK
, IDR_BACK_D
, IDR_BACK_H
, IDR_BACK_P
,
120 IDR_FORWARD
, IDR_FORWARD_D
, IDR_FORWARD_H
, IDR_FORWARD_P
,
121 IDR_HOME
, IDR_HOME_H
, IDR_HOME_P
,
122 IDR_RELOAD
, IDR_RELOAD_H
, IDR_RELOAD_P
,
123 IDR_STOP
, IDR_STOP_D
, IDR_STOP_H
, IDR_STOP_P
,
124 IDR_BROWSER_ACTIONS_OVERFLOW
, IDR_BROWSER_ACTIONS_OVERFLOW_H
,
125 IDR_BROWSER_ACTIONS_OVERFLOW_P
,
126 IDR_TOOLS
, IDR_TOOLS_H
, IDR_TOOLS_P
,
128 IDR_THROBBER
, IDR_THROBBER_WAITING
, IDR_THROBBER_LIGHT
,
129 IDR_TOOLBAR_BEZEL_HOVER
, IDR_TOOLBAR_BEZEL_PRESSED
, IDR_TOOLS_BAR
,
132 SkColor
TintForUnderline(SkColor input
) {
133 return SkColorSetA(input
, SkColorGetA(input
) / 3);
139 int ThemeProperties::StringToAlignment(const std::string
& alignment
) {
140 std::vector
<std::string
> split
;
141 base::SplitStringAlongWhitespace(alignment
, &split
);
143 int alignment_mask
= 0;
144 for (std::vector
<std::string
>::iterator
component(split
.begin());
145 component
!= split
.end(); ++component
) {
146 if (LowerCaseEqualsASCII(*component
, kAlignmentTop
))
147 alignment_mask
|= ALIGN_TOP
;
148 else if (LowerCaseEqualsASCII(*component
, kAlignmentBottom
))
149 alignment_mask
|= ALIGN_BOTTOM
;
150 else if (LowerCaseEqualsASCII(*component
, kAlignmentLeft
))
151 alignment_mask
|= ALIGN_LEFT
;
152 else if (LowerCaseEqualsASCII(*component
, kAlignmentRight
))
153 alignment_mask
|= ALIGN_RIGHT
;
155 return alignment_mask
;
159 int ThemeProperties::StringToTiling(const std::string
& tiling
) {
160 if (LowerCaseEqualsASCII(tiling
, kTilingRepeatX
))
162 if (LowerCaseEqualsASCII(tiling
, kTilingRepeatY
))
164 if (LowerCaseEqualsASCII(tiling
, kTilingRepeat
))
166 // NO_REPEAT is the default choice.
171 std::string
ThemeProperties::AlignmentToString(int alignment
) {
172 // Convert from an AlignmentProperty back into a string.
173 std::string
vertical_string(kAlignmentCenter
);
174 std::string
horizontal_string(kAlignmentCenter
);
176 if (alignment
& ALIGN_TOP
)
177 vertical_string
= kAlignmentTop
;
178 else if (alignment
& ALIGN_BOTTOM
)
179 vertical_string
= kAlignmentBottom
;
181 if (alignment
& ALIGN_LEFT
)
182 horizontal_string
= kAlignmentLeft
;
183 else if (alignment
& ALIGN_RIGHT
)
184 horizontal_string
= kAlignmentRight
;
186 return horizontal_string
+ " " + vertical_string
;
190 std::string
ThemeProperties::TilingToString(int tiling
) {
191 // Convert from a TilingProperty back into a string.
192 if (tiling
== REPEAT_X
)
193 return kTilingRepeatX
;
194 if (tiling
== REPEAT_Y
)
195 return kTilingRepeatY
;
196 if (tiling
== REPEAT
)
197 return kTilingRepeat
;
198 return kTilingNoRepeat
;
202 const std::set
<int>& ThemeProperties::GetTintableToolbarButtons() {
203 CR_DEFINE_STATIC_LOCAL(std::set
<int>, button_set
, ());
204 if (button_set
.empty()) {
205 button_set
= std::set
<int>(
207 kToolbarButtonIDs
+ arraysize(kToolbarButtonIDs
));
214 color_utils::HSL
ThemeProperties::GetDefaultTint(int id
) {
217 return kDefaultTintFrame
;
218 case TINT_FRAME_INACTIVE
:
219 return kDefaultTintFrameInactive
;
220 case TINT_FRAME_INCOGNITO
:
221 return kDefaultTintFrameIncognito
;
222 case TINT_FRAME_INCOGNITO_INACTIVE
:
223 return kDefaultTintFrameIncognitoInactive
;
225 return kDefaultTintButtons
;
226 case TINT_BACKGROUND_TAB
:
227 return kDefaultTintBackgroundTab
;
229 color_utils::HSL result
= {-1, -1, -1};
235 SkColor
ThemeProperties::GetDefaultColor(int id
) {
237 // Properties stored in theme pack.
239 return kDefaultColorFrame
;
240 case COLOR_FRAME_INACTIVE
:
241 return kDefaultColorFrameInactive
;
242 case COLOR_FRAME_INCOGNITO
:
243 return kDefaultColorFrameIncognito
;
244 case COLOR_FRAME_INCOGNITO_INACTIVE
:
245 return kDefaultColorFrameIncognitoInactive
;
247 return kDefaultColorToolbar
;
249 return kDefaultColorTabText
;
250 case COLOR_BACKGROUND_TAB_TEXT
:
251 return kDefaultColorBackgroundTabText
;
252 case COLOR_BOOKMARK_TEXT
:
253 return kDefaultColorBookmarkText
;
254 case COLOR_NTP_BACKGROUND
:
255 return kDefaultColorNTPBackground
;
257 return kDefaultColorNTPText
;
259 return kDefaultColorNTPLink
;
260 case COLOR_NTP_LINK_UNDERLINE
:
261 return TintForUnderline(kDefaultColorNTPLink
);
262 case COLOR_NTP_HEADER
:
263 return kDefaultColorNTPHeader
;
264 case COLOR_NTP_SECTION
:
265 return kDefaultColorNTPSection
;
266 case COLOR_NTP_SECTION_TEXT
:
267 return kDefaultColorNTPSectionText
;
268 case COLOR_NTP_SECTION_LINK
:
269 return kDefaultColorNTPSectionLink
;
270 case COLOR_NTP_SECTION_LINK_UNDERLINE
:
271 return TintForUnderline(kDefaultColorNTPSectionLink
);
272 case COLOR_BUTTON_BACKGROUND
:
273 return kDefaultColorButtonBackground
;
275 // Properties not stored in theme pack.
276 case COLOR_CONTROL_BACKGROUND
:
277 return kDefaultColorControlBackground
;
278 case COLOR_TOOLBAR_SEPARATOR
:
279 return kDefaultColorToolbarSeparator
;
280 #if defined(OS_MACOSX)
281 case COLOR_TOOLBAR_BUTTON_STROKE
:
282 return kDefaultColorToolbarButtonStroke
;
283 case COLOR_TOOLBAR_BUTTON_STROKE_INACTIVE
:
284 return kDefaultColorToolbarButtonStrokeInactive
;
285 case COLOR_TOOLBAR_BEZEL
:
286 return kDefaultColorToolbarBezel
;
287 case COLOR_TOOLBAR_STROKE
:
288 return kDefaultColorToolbarStroke
;
289 case COLOR_TOOLBAR_STROKE_INACTIVE
:
290 return kDefaultColorToolbarStrokeInactive
;
293 // Return a debugging red color.
299 int ThemeProperties::GetDefaultDisplayProperty(int id
) {
301 case NTP_BACKGROUND_ALIGNMENT
:
302 return kDefaultDisplayPropertyNTPAlignment
;
303 case NTP_BACKGROUND_TILING
:
304 return kDefaultDisplayPropertyNTPTiling
;
305 case NTP_LOGO_ALTERNATE
:
306 return kDefaultDisplayPropertyNTPAlternateLogo
;