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);
26 #elif defined(OS_MACOSX)
27 const SkColor kDefaultColorFrame
= SkColorSetRGB(224, 224, 224);
28 const SkColor kDefaultColorFrameInactive
= SkColorSetRGB(246, 246, 246);
30 const SkColor kDefaultColorFrame
= SkColorSetRGB(66, 116, 201);
31 const SkColor kDefaultColorFrameInactive
= SkColorSetRGB(161, 182, 228);
33 const SkColor kDefaultColorFrameIncognito
= SkColorSetRGB(83, 106, 139);
34 const SkColor kDefaultColorFrameIncognitoInactive
=
35 SkColorSetRGB(126, 139, 156);
36 #if defined(OS_MACOSX)
37 const SkColor kDefaultColorToolbar
= SkColorSetRGB(230, 230, 230);
39 const SkColor kDefaultColorToolbar
= SkColorSetRGB(223, 223, 223);
41 const SkColor kDefaultColorTabText
= SK_ColorBLACK
;
42 #if defined(OS_MACOSX)
43 const SkColor kDefaultColorBackgroundTabText
= SK_ColorBLACK
;
45 const SkColor kDefaultColorBackgroundTabText
= SkColorSetRGB(64, 64, 64);
47 const SkColor kDefaultColorBookmarkText
= SK_ColorBLACK
;
49 const SkColor kDefaultColorNTPBackground
=
50 color_utils::GetSysSkColor(COLOR_WINDOW
);
51 const SkColor kDefaultColorNTPText
=
52 color_utils::GetSysSkColor(COLOR_WINDOWTEXT
);
53 const SkColor kDefaultColorNTPLink
=
54 color_utils::GetSysSkColor(COLOR_HOTLIGHT
);
56 // TODO(beng): source from theme provider.
57 const SkColor kDefaultColorNTPBackground
= SK_ColorWHITE
;
58 const SkColor kDefaultColorNTPText
= SK_ColorBLACK
;
59 const SkColor kDefaultColorNTPLink
= SkColorSetRGB(6, 55, 116);
61 const SkColor kDefaultColorNTPHeader
= SkColorSetRGB(150, 150, 150);
62 const SkColor kDefaultColorNTPSection
= SkColorSetRGB(229, 229, 229);
63 const SkColor kDefaultColorNTPSectionText
= SK_ColorBLACK
;
64 const SkColor kDefaultColorNTPSectionLink
= SkColorSetRGB(6, 55, 116);
65 const SkColor kDefaultColorButtonBackground
= SkColorSetARGB(0, 0, 0, 0);
68 const color_utils::HSL kDefaultTintButtons
= { -1, -1, -1 };
69 const color_utils::HSL kDefaultTintFrame
= { -1, -1, -1 };
70 const color_utils::HSL kDefaultTintFrameInactive
= { -1, -1, 0.75f
};
71 const color_utils::HSL kDefaultTintFrameIncognito
= { -1, 0.2f
, 0.35f
};
72 const color_utils::HSL kDefaultTintFrameIncognitoInactive
= { -1, 0.3f
, 0.6f
};
73 const color_utils::HSL kDefaultTintBackgroundTab
= { -1, 0.5, 0.75 };
75 // Default display properties.
76 const int kDefaultDisplayPropertyNTPAlignment
=
77 ThemeProperties::ALIGN_CENTER
;
78 const int kDefaultDisplayPropertyNTPTiling
=
79 ThemeProperties::NO_REPEAT
;
80 // By default, we do not use the ntp alternate logo.
81 const int kDefaultDisplayPropertyNTPAlternateLogo
= 0;
83 // ----------------------------------------------------------------------------
84 // Defaults for properties which are not stored in the browser theme pack.
86 const SkColor kDefaultColorControlBackground
= SK_ColorWHITE
;
87 const SkColor kDefaultColorToolbarSeparator
= SkColorSetRGB(170, 170, 171);
89 #if defined(OS_MACOSX)
90 const SkColor kDefaultColorToolbarButtonStroke
= SkColorSetARGB(75, 81, 81, 81);
91 const SkColor kDefaultColorToolbarButtonStrokeInactive
=
92 SkColorSetARGB(75, 99, 99, 99);
93 const SkColor kDefaultColorToolbarBezel
= SkColorSetRGB(204, 204, 204);
94 const SkColor kDefaultColorToolbarStroke
= SkColorSetRGB(103, 103, 103);
95 const SkColor kDefaultColorToolbarStrokeInactive
= SkColorSetRGB(163, 163, 163);
98 // ----------------------------------------------------------------------------
100 // Strings used in alignment properties.
101 const char kAlignmentCenter
[] = "center";
102 const char kAlignmentTop
[] = "top";
103 const char kAlignmentBottom
[] = "bottom";
104 const char kAlignmentLeft
[] = "left";
105 const char kAlignmentRight
[] = "right";
107 // Strings used in background tiling repetition properties.
108 const char kTilingNoRepeat
[] = "no-repeat";
109 const char kTilingRepeatX
[] = "repeat-x";
110 const char kTilingRepeatY
[] = "repeat-y";
111 const char kTilingRepeat
[] = "repeat";
113 // The image resources that will be tinted by the 'button' tint value.
114 // If you change this list, you must increment the version number in
115 // browser_theme_pack.cc, and you should assign persistent IDs to the
116 // data table at the start of said file or else tinted versions of
117 // these resources will not be created.
119 // TODO(erg): The cocoa port is the last user of the IDR_*_[HP] variants. These
120 // should be removed once the cocoa port no longer uses them.
121 const int kToolbarButtonIDs
[] = {
122 IDR_BACK
, IDR_BACK_D
, IDR_BACK_H
, IDR_BACK_P
,
123 IDR_FORWARD
, IDR_FORWARD_D
, IDR_FORWARD_H
, IDR_FORWARD_P
,
124 IDR_HOME
, IDR_HOME_H
, IDR_HOME_P
,
125 IDR_RELOAD
, IDR_RELOAD_H
, IDR_RELOAD_P
,
126 IDR_STOP
, IDR_STOP_D
, IDR_STOP_H
, IDR_STOP_P
,
127 IDR_BROWSER_ACTIONS_OVERFLOW
, IDR_BROWSER_ACTIONS_OVERFLOW_H
,
128 IDR_BROWSER_ACTIONS_OVERFLOW_P
,
129 IDR_TOOLS
, IDR_TOOLS_H
, IDR_TOOLS_P
,
131 IDR_THROBBER
, IDR_THROBBER_WAITING
, IDR_THROBBER_LIGHT
,
132 IDR_TOOLBAR_BEZEL_HOVER
, IDR_TOOLBAR_BEZEL_PRESSED
, IDR_TOOLS_BAR
,
135 SkColor
TintForUnderline(SkColor input
) {
136 return SkColorSetA(input
, SkColorGetA(input
) / 3);
142 int ThemeProperties::StringToAlignment(const std::string
& alignment
) {
143 std::vector
<std::string
> split
;
144 base::SplitStringAlongWhitespace(alignment
, &split
);
146 int alignment_mask
= 0;
147 for (std::vector
<std::string
>::iterator
component(split
.begin());
148 component
!= split
.end(); ++component
) {
149 if (LowerCaseEqualsASCII(*component
, kAlignmentTop
))
150 alignment_mask
|= ALIGN_TOP
;
151 else if (LowerCaseEqualsASCII(*component
, kAlignmentBottom
))
152 alignment_mask
|= ALIGN_BOTTOM
;
153 else if (LowerCaseEqualsASCII(*component
, kAlignmentLeft
))
154 alignment_mask
|= ALIGN_LEFT
;
155 else if (LowerCaseEqualsASCII(*component
, kAlignmentRight
))
156 alignment_mask
|= ALIGN_RIGHT
;
158 return alignment_mask
;
162 int ThemeProperties::StringToTiling(const std::string
& tiling
) {
163 if (LowerCaseEqualsASCII(tiling
, kTilingRepeatX
))
165 if (LowerCaseEqualsASCII(tiling
, kTilingRepeatY
))
167 if (LowerCaseEqualsASCII(tiling
, kTilingRepeat
))
169 // NO_REPEAT is the default choice.
174 std::string
ThemeProperties::AlignmentToString(int alignment
) {
175 // Convert from an AlignmentProperty back into a string.
176 std::string
vertical_string(kAlignmentCenter
);
177 std::string
horizontal_string(kAlignmentCenter
);
179 if (alignment
& ALIGN_TOP
)
180 vertical_string
= kAlignmentTop
;
181 else if (alignment
& ALIGN_BOTTOM
)
182 vertical_string
= kAlignmentBottom
;
184 if (alignment
& ALIGN_LEFT
)
185 horizontal_string
= kAlignmentLeft
;
186 else if (alignment
& ALIGN_RIGHT
)
187 horizontal_string
= kAlignmentRight
;
189 return horizontal_string
+ " " + vertical_string
;
193 std::string
ThemeProperties::TilingToString(int tiling
) {
194 // Convert from a TilingProperty back into a string.
195 if (tiling
== REPEAT_X
)
196 return kTilingRepeatX
;
197 if (tiling
== REPEAT_Y
)
198 return kTilingRepeatY
;
199 if (tiling
== REPEAT
)
200 return kTilingRepeat
;
201 return kTilingNoRepeat
;
205 const std::set
<int>& ThemeProperties::GetTintableToolbarButtons() {
206 CR_DEFINE_STATIC_LOCAL(std::set
<int>, button_set
, ());
207 if (button_set
.empty()) {
208 button_set
= std::set
<int>(
210 kToolbarButtonIDs
+ arraysize(kToolbarButtonIDs
));
217 color_utils::HSL
ThemeProperties::GetDefaultTint(int id
) {
220 return kDefaultTintFrame
;
221 case TINT_FRAME_INACTIVE
:
222 return kDefaultTintFrameInactive
;
223 case TINT_FRAME_INCOGNITO
:
224 return kDefaultTintFrameIncognito
;
225 case TINT_FRAME_INCOGNITO_INACTIVE
:
226 return kDefaultTintFrameIncognitoInactive
;
228 return kDefaultTintButtons
;
229 case TINT_BACKGROUND_TAB
:
230 return kDefaultTintBackgroundTab
;
232 color_utils::HSL result
= {-1, -1, -1};
238 SkColor
ThemeProperties::GetDefaultColor(int id
) {
240 // Properties stored in theme pack.
242 return kDefaultColorFrame
;
243 case COLOR_FRAME_INACTIVE
:
244 return kDefaultColorFrameInactive
;
245 case COLOR_FRAME_INCOGNITO
:
246 return kDefaultColorFrameIncognito
;
247 case COLOR_FRAME_INCOGNITO_INACTIVE
:
248 return kDefaultColorFrameIncognitoInactive
;
250 return kDefaultColorToolbar
;
252 return kDefaultColorTabText
;
253 case COLOR_BACKGROUND_TAB_TEXT
:
254 return kDefaultColorBackgroundTabText
;
255 case COLOR_BOOKMARK_TEXT
:
256 return kDefaultColorBookmarkText
;
257 case COLOR_NTP_BACKGROUND
:
258 return kDefaultColorNTPBackground
;
260 return kDefaultColorNTPText
;
262 return kDefaultColorNTPLink
;
263 case COLOR_NTP_LINK_UNDERLINE
:
264 return TintForUnderline(kDefaultColorNTPLink
);
265 case COLOR_NTP_HEADER
:
266 return kDefaultColorNTPHeader
;
267 case COLOR_NTP_SECTION
:
268 return kDefaultColorNTPSection
;
269 case COLOR_NTP_SECTION_TEXT
:
270 return kDefaultColorNTPSectionText
;
271 case COLOR_NTP_SECTION_LINK
:
272 return kDefaultColorNTPSectionLink
;
273 case COLOR_NTP_SECTION_LINK_UNDERLINE
:
274 return TintForUnderline(kDefaultColorNTPSectionLink
);
275 case COLOR_BUTTON_BACKGROUND
:
276 return kDefaultColorButtonBackground
;
278 // Properties not stored in theme pack.
279 case COLOR_CONTROL_BACKGROUND
:
280 return kDefaultColorControlBackground
;
281 case COLOR_TOOLBAR_SEPARATOR
:
282 return kDefaultColorToolbarSeparator
;
283 #if defined(OS_MACOSX)
284 case COLOR_TOOLBAR_BUTTON_STROKE
:
285 return kDefaultColorToolbarButtonStroke
;
286 case COLOR_TOOLBAR_BUTTON_STROKE_INACTIVE
:
287 return kDefaultColorToolbarButtonStrokeInactive
;
288 case COLOR_TOOLBAR_BEZEL
:
289 return kDefaultColorToolbarBezel
;
290 case COLOR_TOOLBAR_STROKE
:
291 return kDefaultColorToolbarStroke
;
292 case COLOR_TOOLBAR_STROKE_INACTIVE
:
293 return kDefaultColorToolbarStrokeInactive
;
296 // Return a debugging red color.
302 int ThemeProperties::GetDefaultDisplayProperty(int id
) {
304 case NTP_BACKGROUND_ALIGNMENT
:
305 return kDefaultDisplayPropertyNTPAlignment
;
306 case NTP_BACKGROUND_TILING
:
307 return kDefaultDisplayPropertyNTPTiling
;
308 case NTP_LOGO_ALTERNATE
:
309 return kDefaultDisplayPropertyNTPAlternateLogo
;