OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/libgtk2ui/native_theme_gtk2.h" | 5 #include "chrome/browser/ui/libgtk2ui/native_theme_gtk2.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include "chrome/browser/ui/libgtk2ui/chrome_gtk_frame.h" | |
9 #include "chrome/browser/ui/libgtk2ui/chrome_gtk_menu_subclasses.h" | 10 #include "chrome/browser/ui/libgtk2ui/chrome_gtk_menu_subclasses.h" |
10 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" | 11 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h" |
11 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h" | 12 #include "chrome/browser/ui/libgtk2ui/gtk2_util.h" |
12 #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" | 13 #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" |
13 #include "third_party/skia/include/core/SkColor.h" | 14 #include "third_party/skia/include/core/SkColor.h" |
14 #include "ui/gfx/color_utils.h" | 15 #include "ui/gfx/color_utils.h" |
15 #include "ui/gfx/geometry/rect.h" | 16 #include "ui/gfx/geometry/rect.h" |
16 #include "ui/gfx/geometry/size.h" | 17 #include "ui/gfx/geometry/size.h" |
17 #include "ui/gfx/path.h" | 18 #include "ui/gfx/path.h" |
18 #include "ui/gfx/skia_util.h" | 19 #include "ui/gfx/skia_util.h" |
19 #include "ui/native_theme/common_theme.h" | 20 #include "ui/native_theme/common_theme.h" |
20 | 21 |
22 | |
23 #if GTK_MAJOR_VERSION == 2 | |
24 | |
25 #define GET_FG_COLOR(gtkwidget, gtkstate) \ | |
26 GdkColorToSkColor(gtk_rc_get_style(gtkwidget)->fg[GTK_STATE_ ## gtkstate]) | |
Elliot Glaysher
2015/09/09 17:58:10
Prefer inline functions to #define.
| |
27 | |
28 #define GET_BG_COLOR(gtkwidget, gtkstate) \ | |
29 GdkColorToSkColor(gtk_rc_get_style(gtkwidget)->bg[GTK_STATE_ ## gtkstate]) | |
30 | |
31 #define GET_TEXT_COLOR(gtkwidget, gtkstate) \ | |
32 GdkColorToSkColor(gtk_rc_get_style(gtkwidget)->text[GTK_STATE_ ## gtkstate]) | |
33 | |
34 #define GET_TEXT_AA_COLOR(gtkwidget, gtkstate) \ | |
35 GdkColorToSkColor(gtk_rc_get_style(gtkwidget)->text_aa[GTK_STATE_ ## gtkstate] ) | |
36 | |
37 #define GET_BASE_COLOR(gtkwidget, gtkstate) \ | |
38 GdkColorToSkColor(gtk_rc_get_style(gtkwidget)->base[GTK_STATE_ ## gtkstate]) | |
39 | |
40 #else | |
41 | |
42 inline SkColor FgColorToSkColor(GtkWidget* widget, GtkStateFlags flags) { | |
43 GdkRGBA color; | |
44 gtk_style_context_get_color( | |
45 gtk_widget_get_style_context(widget), flags, &color); | |
46 return SkColorSetRGB(color.red * 255, color.green * 255, color.blue * 255); | |
47 } | |
48 inline SkColor BgColorToSkColor(GtkWidget* widget, GtkStateFlags flags) { | |
49 GdkRGBA color; | |
50 | |
51 G_GNUC_BEGIN_IGNORE_DEPRECATIONS | |
52 gtk_style_context_get_background_color( | |
53 gtk_widget_get_style_context(widget), flags, &color); | |
54 G_GNUC_END_IGNORE_DEPRECATIONS | |
55 | |
56 //Hack for default color | |
57 if (color.alpha == 0.0) | |
58 color = {1, 1, 1, 1}; | |
59 | |
60 return SkColorSetRGB(color.red * 255, color.green * 255, color.blue * 255); | |
61 } | |
62 | |
63 | |
64 #define GET_FG_COLOR(gtkwidget, gtkstate) \ | |
65 FgColorToSkColor(gtkwidget, GTK_STATE_FLAG_ ## gtkstate) | |
66 | |
67 #define GET_BG_COLOR(gtkwidget, gtkstate) \ | |
68 BgColorToSkColor(gtkwidget, GTK_STATE_FLAG_ ## gtkstate) | |
69 | |
70 #define GET_TEXT_COLOR GET_FG_COLOR | |
71 #define GET_TEXT_AA_COLOR GET_FG_COLOR | |
72 #define GET_BASE_COLOR GET_BG_COLOR | |
73 | |
74 #endif | |
75 | |
76 | |
21 namespace { | 77 namespace { |
22 | 78 |
23 // Theme colors returned by GetSystemColor(). | 79 // Theme colors returned by GetSystemColor(). |
24 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); | 80 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); |
25 | 81 const SkColor kURLTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); |
26 const GdkColor kURLTextColor = GDK_COLOR_RGB(0x0b, 0x80, 0x43); | |
27 | |
28 GdkColor GdkAlphaBlend(GdkColor foreground, | |
29 GdkColor background, | |
30 SkAlpha alpha) { | |
31 return libgtk2ui::SkColorToGdkColor( | |
32 color_utils::AlphaBlend(libgtk2ui::GdkColorToSkColor(foreground), | |
33 libgtk2ui::GdkColorToSkColor(background), alpha)); | |
34 } | |
35 | 82 |
36 // Generates the normal URL color, a green color used in unhighlighted URL | 83 // Generates the normal URL color, a green color used in unhighlighted URL |
37 // text. It is a mix of |kURLTextColor| and the current text color. Unlike the | 84 // text. It is a mix of |kURLTextColor| and the current text color. Unlike the |
38 // selected text color, it is more important to match the qualities of the | 85 // selected text color, it is more important to match the qualities of the |
39 // foreground typeface color instead of taking the background into account. | 86 // foreground typeface color instead of taking the background into account. |
40 GdkColor NormalURLColor(GdkColor foreground) { | 87 SkColor NormalURLColor(SkColor foreground) { |
41 color_utils::HSL fg_hsl; | 88 color_utils::HSL fg_hsl, hue_hsl; |
42 color_utils::SkColorToHSL(libgtk2ui::GdkColorToSkColor(foreground), &fg_hsl); | 89 color_utils::SkColorToHSL(foreground, &fg_hsl); |
43 | 90 color_utils::SkColorToHSL(kURLTextColor, &hue_hsl); |
44 color_utils::HSL hue_hsl; | |
45 color_utils::SkColorToHSL(libgtk2ui::GdkColorToSkColor(kURLTextColor), | |
46 &hue_hsl); | |
47 | 91 |
48 // Only allow colors that have a fair amount of saturation in them (color vs | 92 // Only allow colors that have a fair amount of saturation in them (color vs |
49 // white). This means that our output color will always be fairly green. | 93 // white). This means that our output color will always be fairly green. |
50 double s = std::max(0.5, fg_hsl.s); | 94 double s = std::max(0.5, fg_hsl.s); |
51 | 95 |
52 // Make sure the luminance is at least as bright as the |kURLTextColor| green | 96 // Make sure the luminance is at least as bright as the |kURLTextColor| green |
53 // would be if we were to use that. | 97 // would be if we were to use that. |
54 double l; | 98 double l; |
55 if (fg_hsl.l < hue_hsl.l) | 99 if (fg_hsl.l < hue_hsl.l) |
56 l = hue_hsl.l; | 100 l = hue_hsl.l; |
57 else | 101 else |
58 l = (fg_hsl.l + hue_hsl.l) / 2; | 102 l = (fg_hsl.l + hue_hsl.l) / 2; |
59 | 103 |
60 color_utils::HSL output = { hue_hsl.h, s, l }; | 104 color_utils::HSL output = { hue_hsl.h, s, l }; |
61 return libgtk2ui::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255)); | 105 return color_utils::HSLToSkColor(output, 255); |
62 } | 106 } |
63 | 107 |
64 // Generates the selected URL color, a green color used on URL text in the | 108 // Generates the selected URL color, a green color used on URL text in the |
65 // currently highlighted entry in the autocomplete popup. It's a mix of | 109 // currently highlighted entry in the autocomplete popup. It's a mix of |
66 // |kURLTextColor|, the current text color, and the background color (the | 110 // |kURLTextColor|, the current text color, and the background color (the |
67 // select highlight). It is more important to contrast with the background | 111 // select highlight). It is more important to contrast with the background |
68 // saturation than to look exactly like the foreground color. | 112 // saturation than to look exactly like the foreground color. |
69 GdkColor SelectedURLColor(GdkColor foreground, GdkColor background) { | 113 SkColor SelectedURLColor(SkColor foreground, SkColor background) { |
70 color_utils::HSL fg_hsl; | 114 color_utils::HSL fg_hsl, bg_hsl, hue_hsl; |
71 color_utils::SkColorToHSL(libgtk2ui::GdkColorToSkColor(foreground), | 115 color_utils::SkColorToHSL(foreground, &fg_hsl); |
72 &fg_hsl); | 116 color_utils::SkColorToHSL(background, &bg_hsl); |
73 | 117 color_utils::SkColorToHSL(kURLTextColor, &hue_hsl); |
74 color_utils::HSL bg_hsl; | |
75 color_utils::SkColorToHSL(libgtk2ui::GdkColorToSkColor(background), | |
76 &bg_hsl); | |
77 | |
78 color_utils::HSL hue_hsl; | |
79 color_utils::SkColorToHSL(libgtk2ui::GdkColorToSkColor(kURLTextColor), | |
80 &hue_hsl); | |
81 | 118 |
82 // The saturation of the text should be opposite of the background, clamped | 119 // The saturation of the text should be opposite of the background, clamped |
83 // to 0.2-0.8. We make sure it's greater than 0.2 so there's some color, but | 120 // to 0.2-0.8. We make sure it's greater than 0.2 so there's some color, but |
84 // less than 0.8 so it's not the oversaturated neon-color. | 121 // less than 0.8 so it's not the oversaturated neon-color. |
85 double opposite_s = 1 - bg_hsl.s; | 122 double opposite_s = 1 - bg_hsl.s; |
86 double s = std::max(0.2, std::min(0.8, opposite_s)); | 123 double s = std::max(0.2, std::min(0.8, opposite_s)); |
87 | 124 |
88 // The luminance should match the luminance of the foreground text. Again, | 125 // The luminance should match the luminance of the foreground text. Again, |
89 // we clamp so as to have at some amount of color (green) in the text. | 126 // we clamp so as to have at some amount of color (green) in the text. |
90 double opposite_l = fg_hsl.l; | 127 double opposite_l = fg_hsl.l; |
91 double l = std::max(0.1, std::min(0.9, opposite_l)); | 128 double l = std::max(0.1, std::min(0.9, opposite_l)); |
92 | 129 |
93 color_utils::HSL output = { hue_hsl.h, s, l }; | 130 color_utils::HSL output = { hue_hsl.h, s, l }; |
94 return libgtk2ui::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255)); | 131 return color_utils::HSLToSkColor(output, 255); |
95 } | |
96 | |
97 GdkColor GetReadableColor(SkColor color, const GdkColor& background) { | |
98 return libgtk2ui::SkColorToGdkColor(color_utils::GetReadableColor( | |
99 color, libgtk2ui::GdkColorToSkColor(background))); | |
100 } | 132 } |
101 | 133 |
102 } // namespace | 134 } // namespace |
103 | 135 |
104 | 136 |
105 namespace libgtk2ui { | 137 namespace libgtk2ui { |
106 | 138 |
107 // static | 139 // static |
108 NativeThemeGtk2* NativeThemeGtk2::instance() { | 140 NativeThemeGtk2* NativeThemeGtk2::instance() { |
109 CR_DEFINE_STATIC_LOCAL(NativeThemeGtk2, s_native_theme, ()); | 141 CR_DEFINE_STATIC_LOCAL(NativeThemeGtk2, s_native_theme, ()); |
110 return &s_native_theme; | 142 return &s_native_theme; |
111 } | 143 } |
112 | 144 |
113 NativeThemeGtk2::NativeThemeGtk2() | 145 //Constructors automatically called |
114 : fake_window_(NULL), | 146 NativeThemeGtk2::NativeThemeGtk2() {} |
115 fake_tooltip_(NULL), | 147 //This doesn't actually get called |
116 fake_menu_item_(NULL) { | 148 NativeThemeGtk2::~NativeThemeGtk2() {} |
117 } | |
118 | 149 |
119 NativeThemeGtk2::~NativeThemeGtk2() { | |
120 if (fake_window_) | |
121 gtk_widget_destroy(fake_window_); | |
122 if (fake_tooltip_) | |
123 gtk_widget_destroy(fake_tooltip_); | |
124 | 150 |
125 fake_entry_.Destroy(); | |
126 fake_label_.Destroy(); | |
127 fake_button_.Destroy(); | |
128 fake_tree_.Destroy(); | |
129 fake_menu_.Destroy(); | |
130 } | |
131 | |
132 gfx::Size NativeThemeGtk2::GetPartSize(Part part, | |
133 State state, | |
134 const ExtraParams& extra) const { | |
135 if (part == kComboboxArrow) | |
136 return gfx::Size(12, 12); | |
137 | |
138 return ui::NativeThemeBase::GetPartSize(part, state, extra); | |
139 } | |
140 | |
141 void NativeThemeGtk2::Paint(SkCanvas* canvas, | |
142 Part part, | |
143 State state, | |
144 const gfx::Rect& rect, | |
145 const ExtraParams& extra) const { | |
146 if (rect.IsEmpty()) | |
147 return; | |
148 | |
149 switch (part) { | |
150 case kComboboxArrow: | |
151 PaintComboboxArrow(canvas, GetGtkState(state), rect); | |
152 return; | |
153 | |
154 default: | |
155 NativeThemeBase::Paint(canvas, part, state, rect, extra); | |
156 } | |
157 } | |
158 | |
159 SkColor NativeThemeGtk2::GetSystemColor(ColorId color_id) const { | |
160 if (color_id == kColorId_BlueButtonShadowColor) | |
161 return SK_ColorTRANSPARENT; | |
162 | |
163 return GdkColorToSkColor(GetSystemGdkColor(color_id)); | |
164 } | |
165 | 151 |
166 void NativeThemeGtk2::PaintMenuPopupBackground( | 152 void NativeThemeGtk2::PaintMenuPopupBackground( |
167 SkCanvas* canvas, | 153 SkCanvas* canvas, |
168 const gfx::Size& size, | 154 const gfx::Size& size, |
169 const MenuBackgroundExtraParams& menu_background) const { | 155 const MenuBackgroundExtraParams& menu_background) const { |
170 if (menu_background.corner_radius > 0) { | 156 if (menu_background.corner_radius > 0) { |
171 SkPaint paint; | 157 SkPaint paint; |
172 paint.setStyle(SkPaint::kFill_Style); | 158 paint.setStyle(SkPaint::kFill_Style); |
173 paint.setFlags(SkPaint::kAntiAlias_Flag); | 159 paint.setFlags(SkPaint::kAntiAlias_Flag); |
174 paint.setColor(GetSystemColor(kColorId_MenuBackgroundColor)); | 160 paint.setColor(GetSystemColor(kColorId_MenuBackgroundColor)); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 NativeTheme::kColorId_FocusedMenuItemBackgroundColor); | 192 NativeTheme::kColorId_FocusedMenuItemBackgroundColor); |
207 paint.setColor(color); | 193 paint.setColor(color); |
208 break; | 194 break; |
209 default: | 195 default: |
210 NOTREACHED() << "Invalid state " << state; | 196 NOTREACHED() << "Invalid state " << state; |
211 break; | 197 break; |
212 } | 198 } |
213 canvas->drawRect(gfx::RectToSkRect(rect), paint); | 199 canvas->drawRect(gfx::RectToSkRect(rect), paint); |
214 } | 200 } |
215 | 201 |
216 GdkColor NativeThemeGtk2::GetSystemGdkColor(ColorId color_id) const { | 202 SkColor NativeThemeGtk2::GetSystemColor(ColorId color_id) const { |
203 if (color_id == kColorId_BlueButtonShadowColor) | |
204 return SK_ColorTRANSPARENT; | |
205 | |
217 const SkColor kPositiveTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); | 206 const SkColor kPositiveTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); |
218 const SkColor kNegativeTextColor = SkColorSetRGB(0xc5, 0x39, 0x29); | 207 const SkColor kNegativeTextColor = SkColorSetRGB(0xc5, 0x39, 0x29); |
208 | |
219 switch (color_id) { | 209 switch (color_id) { |
220 // Windows | 210 // Windows |
221 case kColorId_WindowBackground: | 211 case kColorId_WindowBackground: |
222 return GetWindowStyle()->bg[GTK_STATE_NORMAL]; | 212 return GET_BG_COLOR(GetWindow(), SELECTED); |
223 | 213 |
224 // Dialogs | 214 // Dialogs |
225 case kColorId_DialogBackground: | 215 case kColorId_DialogBackground: |
226 return GetWindowStyle()->bg[GTK_STATE_NORMAL]; | 216 return GET_BG_COLOR(GetWindow(), NORMAL); |
227 | 217 |
228 // FocusableBorder | 218 // FocusableBorder |
229 case kColorId_FocusedBorderColor: | 219 case kColorId_FocusedBorderColor: |
230 return GetEntryStyle()->bg[GTK_STATE_SELECTED]; | 220 return GET_BG_COLOR(GetEntry(), SELECTED); |
231 case kColorId_UnfocusedBorderColor: | 221 case kColorId_UnfocusedBorderColor: |
232 return GetEntryStyle()->text_aa[GTK_STATE_NORMAL]; | 222 return GET_TEXT_AA_COLOR(GetEntry(), NORMAL); |
233 | 223 |
234 // MenuItem | 224 // MenuItem |
235 case kColorId_EnabledMenuItemForegroundColor: | 225 case kColorId_EnabledMenuItemForegroundColor: |
236 case kColorId_DisabledEmphasizedMenuItemForegroundColor: | 226 case kColorId_DisabledEmphasizedMenuItemForegroundColor: |
237 return GetMenuItemStyle()->text[GTK_STATE_NORMAL]; | 227 return GET_TEXT_COLOR(GetMenuItem(), NORMAL); |
238 case kColorId_DisabledMenuItemForegroundColor: | 228 case kColorId_DisabledMenuItemForegroundColor: |
239 return GetMenuItemStyle()->text[GTK_STATE_INSENSITIVE]; | 229 return GET_TEXT_COLOR(GetMenuItem(), INSENSITIVE); |
240 case kColorId_SelectedMenuItemForegroundColor: | 230 case kColorId_SelectedMenuItemForegroundColor: |
241 return GetMenuItemStyle()->text[GTK_STATE_SELECTED]; | 231 return GET_TEXT_COLOR(GetMenuItem(), SELECTED); |
242 case kColorId_FocusedMenuItemBackgroundColor: | 232 case kColorId_FocusedMenuItemBackgroundColor: |
243 return GetMenuItemStyle()->bg[GTK_STATE_SELECTED]; | 233 return GET_BG_COLOR(GetMenuItem(), SELECTED); |
244 case kColorId_HoverMenuItemBackgroundColor: | 234 case kColorId_HoverMenuItemBackgroundColor: |
245 return GetMenuItemStyle()->bg[GTK_STATE_PRELIGHT]; | 235 return GET_BG_COLOR(GetMenuItem(), PRELIGHT); |
246 case kColorId_FocusedMenuButtonBorderColor: | 236 case kColorId_FocusedMenuButtonBorderColor: |
247 return GetEntryStyle()->bg[GTK_STATE_NORMAL]; | 237 return GET_BG_COLOR(GetEntry(), NORMAL); |
248 case kColorId_HoverMenuButtonBorderColor: | 238 case kColorId_HoverMenuButtonBorderColor: |
249 return GetEntryStyle()->text_aa[GTK_STATE_PRELIGHT]; | 239 return GET_TEXT_AA_COLOR(GetEntry(), PRELIGHT); |
250 case kColorId_MenuBorderColor: | 240 case kColorId_MenuBorderColor: |
251 case kColorId_EnabledMenuButtonBorderColor: | 241 case kColorId_EnabledMenuButtonBorderColor: |
252 case kColorId_MenuSeparatorColor: { | 242 case kColorId_MenuSeparatorColor: { |
253 return GetMenuItemStyle()->text[GTK_STATE_INSENSITIVE]; | 243 return GET_TEXT_COLOR(GetMenuItem(), INSENSITIVE); |
254 } | 244 } |
255 case kColorId_MenuBackgroundColor: | 245 case kColorId_MenuBackgroundColor: |
256 return GetMenuStyle()->bg[GTK_STATE_NORMAL]; | 246 return GET_BG_COLOR(GetMenu(), NORMAL); |
257 | 247 |
258 // Label | 248 // Label |
259 case kColorId_LabelEnabledColor: | 249 case kColorId_LabelEnabledColor: |
260 return GetLabelStyle()->text[GTK_STATE_NORMAL]; | 250 return GET_TEXT_COLOR(GetEntry(), NORMAL); |
261 case kColorId_LabelDisabledColor: | 251 case kColorId_LabelDisabledColor: |
262 return GetLabelStyle()->text[GTK_STATE_INSENSITIVE]; | 252 return GET_TEXT_COLOR(GetLabel(), INSENSITIVE); |
263 case kColorId_LabelBackgroundColor: | 253 case kColorId_LabelBackgroundColor: |
264 return GetWindowStyle()->bg[GTK_STATE_NORMAL]; | 254 return GET_BG_COLOR(GetWindow(), NORMAL); |
265 | 255 |
266 // Button | 256 // Button |
267 case kColorId_ButtonBackgroundColor: | 257 case kColorId_ButtonBackgroundColor: |
268 return GetButtonStyle()->bg[GTK_STATE_NORMAL]; | 258 return GET_BG_COLOR(GetButton(), NORMAL); |
269 case kColorId_ButtonEnabledColor: | 259 case kColorId_ButtonEnabledColor: |
270 case kColorId_BlueButtonEnabledColor: | 260 case kColorId_BlueButtonEnabledColor: |
271 return GetButtonStyle()->text[GTK_STATE_NORMAL]; | 261 return GET_TEXT_COLOR(GetButton(), NORMAL); |
272 case kColorId_ButtonDisabledColor: | 262 case kColorId_ButtonDisabledColor: |
273 case kColorId_BlueButtonDisabledColor: | 263 case kColorId_BlueButtonDisabledColor: |
274 return GetButtonStyle()->text[GTK_STATE_INSENSITIVE]; | 264 return GET_TEXT_COLOR(GetButton(), INSENSITIVE); |
275 case kColorId_ButtonHighlightColor: | 265 case kColorId_ButtonHighlightColor: |
276 return GetButtonStyle()->base[GTK_STATE_SELECTED]; | 266 return GET_BASE_COLOR(GetButton(), SELECTED); |
277 case kColorId_ButtonHoverColor: | 267 case kColorId_ButtonHoverColor: |
278 case kColorId_BlueButtonHoverColor: | 268 case kColorId_BlueButtonHoverColor: |
279 return GetButtonStyle()->text[GTK_STATE_PRELIGHT]; | 269 return GET_TEXT_COLOR(GetButton(), PRELIGHT); |
280 case kColorId_ButtonHoverBackgroundColor: | 270 case kColorId_ButtonHoverBackgroundColor: |
281 return GetButtonStyle()->bg[GTK_STATE_PRELIGHT]; | 271 return GET_BG_COLOR(GetButton(), PRELIGHT); |
282 case kColorId_BlueButtonPressedColor: | 272 case kColorId_BlueButtonPressedColor: |
283 return GetButtonStyle()->text[GTK_STATE_ACTIVE]; | 273 return GET_TEXT_COLOR(GetButton(), ACTIVE); |
284 case kColorId_BlueButtonShadowColor: | 274 case kColorId_BlueButtonShadowColor: |
285 // Should be handled in GetSystemColor(). | 275 // Should be handled in GetSystemColor(). |
286 NOTREACHED(); | 276 NOTREACHED(); |
287 return GetButtonStyle()->text[GTK_STATE_NORMAL]; | 277 return GET_TEXT_COLOR(GetButton(), NORMAL); |
288 | 278 |
289 // Textfield | 279 // Textfield |
290 case kColorId_TextfieldDefaultColor: | 280 case kColorId_TextfieldDefaultColor: |
291 return GetEntryStyle()->text[GTK_STATE_NORMAL]; | 281 return GET_TEXT_COLOR(GetEntry(), NORMAL); |
292 case kColorId_TextfieldDefaultBackground: | 282 case kColorId_TextfieldDefaultBackground: |
293 return GetEntryStyle()->base[GTK_STATE_NORMAL]; | 283 return GET_BASE_COLOR(GetEntry(), NORMAL); |
294 case kColorId_TextfieldReadOnlyColor: | 284 case kColorId_TextfieldReadOnlyColor: |
295 return GetEntryStyle()->text[GTK_STATE_INSENSITIVE]; | 285 return GET_TEXT_COLOR(GetEntry(), INSENSITIVE); |
296 case kColorId_TextfieldReadOnlyBackground: | 286 case kColorId_TextfieldReadOnlyBackground: |
297 return GetEntryStyle()->base[GTK_STATE_INSENSITIVE]; | 287 return GET_BASE_COLOR(GetEntry(), INSENSITIVE); |
298 case kColorId_TextfieldSelectionColor: | 288 case kColorId_TextfieldSelectionColor: |
299 return GetEntryStyle()->text[GTK_STATE_SELECTED]; | 289 return GET_TEXT_COLOR(GetEntry(), SELECTED); |
300 case kColorId_TextfieldSelectionBackgroundFocused: | 290 case kColorId_TextfieldSelectionBackgroundFocused: |
301 return GetEntryStyle()->base[GTK_STATE_SELECTED]; | 291 return GET_BASE_COLOR(GetEntry(), SELECTED); |
302 | 292 |
303 // Tooltips | 293 // Tooltips |
304 case kColorId_TooltipBackground: | 294 case kColorId_TooltipBackground: |
305 return GetTooltipStyle()->bg[GTK_STATE_NORMAL]; | 295 return GET_BG_COLOR(GetTooltip(), NORMAL); |
306 case kColorId_TooltipText: | 296 case kColorId_TooltipText: |
307 return GetTooltipStyle()->fg[GTK_STATE_NORMAL]; | 297 return GET_FG_COLOR(GetTooltip(), NORMAL); |
308 | 298 |
309 // Trees and Tables (implemented on GTK using the same class) | 299 // Trees and Tables (implemented on GTK using the same class) |
310 case kColorId_TableBackground: | 300 case kColorId_TableBackground: |
311 case kColorId_TreeBackground: | 301 case kColorId_TreeBackground: |
312 return GetTreeStyle()->bg[GTK_STATE_NORMAL]; | 302 return GET_BG_COLOR(GetTree(), NORMAL); |
313 case kColorId_TableText: | 303 case kColorId_TableText: |
314 case kColorId_TreeText: | 304 case kColorId_TreeText: |
315 return GetTreeStyle()->text[GTK_STATE_NORMAL]; | 305 return GET_TEXT_COLOR(GetTree(), NORMAL); |
316 case kColorId_TableSelectedText: | 306 case kColorId_TableSelectedText: |
317 case kColorId_TableSelectedTextUnfocused: | 307 case kColorId_TableSelectedTextUnfocused: |
318 case kColorId_TreeSelectedText: | 308 case kColorId_TreeSelectedText: |
319 case kColorId_TreeSelectedTextUnfocused: | 309 case kColorId_TreeSelectedTextUnfocused: |
320 return GetTreeStyle()->text[GTK_STATE_SELECTED]; | 310 return GET_TEXT_COLOR(GetTree(), SELECTED); |
321 case kColorId_TableSelectionBackgroundFocused: | 311 case kColorId_TableSelectionBackgroundFocused: |
322 case kColorId_TableSelectionBackgroundUnfocused: | 312 case kColorId_TableSelectionBackgroundUnfocused: |
323 case kColorId_TreeSelectionBackgroundFocused: | 313 case kColorId_TreeSelectionBackgroundFocused: |
324 case kColorId_TreeSelectionBackgroundUnfocused: | 314 case kColorId_TreeSelectionBackgroundUnfocused: |
325 return GetTreeStyle()->bg[GTK_STATE_SELECTED]; | 315 return GET_BG_COLOR(GetTree(), SELECTED); |
326 case kColorId_TreeArrow: | 316 case kColorId_TreeArrow: |
327 return GetTreeStyle()->fg[GTK_STATE_NORMAL]; | 317 return GET_FG_COLOR(GetTree(), NORMAL); |
328 case kColorId_TableGroupingIndicatorColor: | 318 case kColorId_TableGroupingIndicatorColor: |
329 return GetTreeStyle()->text_aa[GTK_STATE_NORMAL]; | 319 return GET_TEXT_AA_COLOR(GetTree(), NORMAL); |
330 | 320 |
331 // Results Table | 321 // Results Table |
332 case kColorId_ResultsTableNormalBackground: | 322 case kColorId_ResultsTableNormalBackground: |
333 return GetEntryStyle()->base[GTK_STATE_NORMAL]; | 323 return GET_BASE_COLOR(GetEntry(), NORMAL); |
334 case kColorId_ResultsTableHoveredBackground: { | 324 case kColorId_ResultsTableHoveredBackground: |
335 GtkStyle* entry_style = GetEntryStyle(); | 325 return color_utils::AlphaBlend(GET_BASE_COLOR(GetEntry(), NORMAL), |
336 return GdkAlphaBlend( | 326 GET_BASE_COLOR(GetEntry(), SELECTED), |
337 entry_style->base[GTK_STATE_NORMAL], | 327 0x80); |
338 entry_style->base[GTK_STATE_SELECTED], 0x80); | |
339 } | |
340 case kColorId_ResultsTableSelectedBackground: | 328 case kColorId_ResultsTableSelectedBackground: |
341 return GetEntryStyle()->base[GTK_STATE_SELECTED]; | 329 return GET_BASE_COLOR(GetEntry(), SELECTED); |
342 case kColorId_ResultsTableNormalText: | 330 case kColorId_ResultsTableNormalText: |
343 case kColorId_ResultsTableHoveredText: | 331 case kColorId_ResultsTableHoveredText: |
344 return GetEntryStyle()->text[GTK_STATE_NORMAL]; | 332 return GET_TEXT_COLOR(GetEntry(), NORMAL); |
345 case kColorId_ResultsTableSelectedText: | 333 case kColorId_ResultsTableSelectedText: |
346 return GetEntryStyle()->text[GTK_STATE_SELECTED]; | 334 return GET_TEXT_COLOR(GetEntry(), SELECTED); |
347 case kColorId_ResultsTableNormalDimmedText: | 335 case kColorId_ResultsTableNormalDimmedText: |
348 case kColorId_ResultsTableHoveredDimmedText: { | 336 case kColorId_ResultsTableHoveredDimmedText: |
349 GtkStyle* entry_style = GetEntryStyle(); | 337 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetEntry(), NORMAL), |
350 return GdkAlphaBlend( | 338 GET_BASE_COLOR(GetEntry(), NORMAL), |
351 entry_style->text[GTK_STATE_NORMAL], | 339 0x80); |
352 entry_style->base[GTK_STATE_NORMAL], 0x80); | 340 case kColorId_ResultsTableSelectedDimmedText: |
353 } | 341 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetEntry(), SELECTED), |
354 case kColorId_ResultsTableSelectedDimmedText: { | 342 GET_BASE_COLOR(GetEntry(), NORMAL), |
355 GtkStyle* entry_style = GetEntryStyle(); | 343 0x80); |
356 return GdkAlphaBlend( | |
357 entry_style->text[GTK_STATE_SELECTED], | |
358 entry_style->base[GTK_STATE_NORMAL], 0x80); | |
359 } | |
360 case kColorId_ResultsTableNormalUrl: | 344 case kColorId_ResultsTableNormalUrl: |
361 case kColorId_ResultsTableHoveredUrl: { | 345 case kColorId_ResultsTableHoveredUrl: |
362 return NormalURLColor(GetEntryStyle()->text[GTK_STATE_NORMAL]); | 346 return NormalURLColor(GET_TEXT_COLOR(GetEntry(), NORMAL)); |
363 } | 347 |
364 case kColorId_ResultsTableSelectedUrl: { | 348 case kColorId_ResultsTableSelectedUrl: |
365 GtkStyle* entry_style = GetEntryStyle(); | 349 return SelectedURLColor(GET_TEXT_COLOR(GetEntry(), SELECTED), |
366 return SelectedURLColor(entry_style->text[GTK_STATE_SELECTED], | 350 GET_BASE_COLOR(GetEntry(), SELECTED)); |
367 entry_style->base[GTK_STATE_SELECTED]); | 351 case kColorId_ResultsTableNormalDivider: |
368 } | 352 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetWindow(), NORMAL), |
369 case kColorId_ResultsTableNormalDivider: { | 353 GET_BG_COLOR(GetWindow(), NORMAL), |
370 GtkStyle* win_style = GetWindowStyle(); | 354 0x34); |
371 return GdkAlphaBlend(win_style->text[GTK_STATE_NORMAL], | 355 case kColorId_ResultsTableHoveredDivider: |
372 win_style->bg[GTK_STATE_NORMAL], 0x34); | 356 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetWindow(), PRELIGHT), |
373 } | 357 GET_BG_COLOR(GetWindow(), PRELIGHT), |
374 case kColorId_ResultsTableHoveredDivider: { | 358 0x34); |
375 GtkStyle* win_style = GetWindowStyle(); | 359 case kColorId_ResultsTableSelectedDivider: |
376 return GdkAlphaBlend(win_style->text[GTK_STATE_PRELIGHT], | 360 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetWindow(), SELECTED), |
377 win_style->bg[GTK_STATE_PRELIGHT], 0x34); | 361 GET_BG_COLOR(GetWindow(), SELECTED), |
378 } | 362 0x34); |
379 case kColorId_ResultsTableSelectedDivider: { | 363 |
380 GtkStyle* win_style = GetWindowStyle(); | |
381 return GdkAlphaBlend(win_style->text[GTK_STATE_SELECTED], | |
382 win_style->bg[GTK_STATE_SELECTED], 0x34); | |
383 } | |
384 case kColorId_ResultsTablePositiveText: { | 364 case kColorId_ResultsTablePositiveText: { |
385 return GetReadableColor(kPositiveTextColor, | 365 return color_utils::GetReadableColor(kPositiveTextColor, |
386 GetEntryStyle()->base[GTK_STATE_NORMAL]); | 366 GET_BASE_COLOR(GetEntry(), NORMAL)); |
387 } | 367 } |
388 case kColorId_ResultsTablePositiveHoveredText: { | 368 case kColorId_ResultsTablePositiveHoveredText: { |
389 return GetReadableColor(kPositiveTextColor, | 369 return color_utils::GetReadableColor(kPositiveTextColor, |
390 GetEntryStyle()->base[GTK_STATE_PRELIGHT]); | 370 GET_BASE_COLOR(GetEntry(), PRELIGHT)) ; |
391 } | 371 } |
392 case kColorId_ResultsTablePositiveSelectedText: { | 372 case kColorId_ResultsTablePositiveSelectedText: { |
393 return GetReadableColor(kPositiveTextColor, | 373 return color_utils::GetReadableColor(kPositiveTextColor, |
394 GetEntryStyle()->base[GTK_STATE_SELECTED]); | 374 GET_BASE_COLOR(GetEntry(), SELECTED)) ; |
395 } | 375 } |
396 case kColorId_ResultsTableNegativeText: { | 376 case kColorId_ResultsTableNegativeText: { |
397 return GetReadableColor(kNegativeTextColor, | 377 return color_utils::GetReadableColor(kNegativeTextColor, |
398 GetEntryStyle()->base[GTK_STATE_NORMAL]); | 378 GET_BASE_COLOR(GetEntry(), NORMAL)); |
399 } | 379 } |
400 case kColorId_ResultsTableNegativeHoveredText: { | 380 case kColorId_ResultsTableNegativeHoveredText: { |
401 return GetReadableColor(kNegativeTextColor, | 381 return color_utils::GetReadableColor(kNegativeTextColor, |
402 GetEntryStyle()->base[GTK_STATE_PRELIGHT]); | 382 GET_BASE_COLOR(GetEntry(), PRELIGHT)) ; |
403 } | 383 } |
404 case kColorId_ResultsTableNegativeSelectedText: { | 384 case kColorId_ResultsTableNegativeSelectedText: { |
405 return GetReadableColor(kNegativeTextColor, | 385 return color_utils::GetReadableColor(kNegativeTextColor, |
406 GetEntryStyle()->base[GTK_STATE_SELECTED]); | 386 GET_BASE_COLOR(GetEntry(), SELECTED)) ; |
407 } | 387 } |
408 | 388 |
409 // Throbber | 389 // Throbber |
410 case kColorId_ThrobberSpinningColor: | 390 case kColorId_ThrobberSpinningColor: |
411 case kColorId_ThrobberLightColor: { | 391 case kColorId_ThrobberLightColor: { |
412 return GetEntryStyle()->bg[GTK_STATE_SELECTED]; | 392 return GET_BG_COLOR(GetEntry(), SELECTED); |
413 } | 393 } |
414 | 394 |
415 case kColorId_ThrobberWaitingColor: { | 395 case kColorId_ThrobberWaitingColor: { |
416 return GdkAlphaBlend(GetEntryStyle()->bg[GTK_STATE_SELECTED], | 396 return color_utils::AlphaBlend(GET_BG_COLOR(GetEntry(), SELECTED), |
417 GetWindowStyle()->bg[GTK_STATE_NORMAL], 0xff / 2); | 397 GET_BG_COLOR(GetWindow(), NORMAL), |
398 0x80); | |
418 } | 399 } |
419 | 400 |
420 case kColorId_ChromeIconGrey: | 401 case kColorId_ChromeIconGrey: |
421 case kColorId_GoogleBlue: | 402 case kColorId_GoogleBlue: |
422 case kColorId_NumColors: | 403 case kColorId_NumColors: |
423 NOTREACHED(); | 404 NOTREACHED(); |
424 break; | 405 break; |
425 } | 406 } |
426 | 407 |
427 return SkColorToGdkColor(kInvalidColorIdColor); | 408 return kInvalidColorIdColor; |
428 } | 409 } |
429 | 410 |
430 GtkWidget* NativeThemeGtk2::GetRealizedWindow() const { | 411 GtkWidget* NativeThemeGtk2::GetWindow() const { |
431 if (!fake_window_) { | 412 if (!fake_window_.get()) { |
432 fake_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 413 fake_window_.Own(chrome_gtk_frame_new()); |
433 gtk_widget_realize(fake_window_); | 414 gtk_widget_realize(fake_window_.get()); |
434 } | 415 } |
435 | 416 |
436 return fake_window_; | 417 return fake_window_.get(); |
437 } | 418 } |
438 | 419 |
439 GtkStyle* NativeThemeGtk2::GetWindowStyle() const { | 420 GtkWidget* NativeThemeGtk2::GetEntry() const { |
440 return gtk_rc_get_style(GetRealizedWindow()); | |
441 } | |
442 | |
443 GtkStyle* NativeThemeGtk2::GetEntryStyle() const { | |
444 if (!fake_entry_.get()) { | 421 if (!fake_entry_.get()) { |
445 fake_entry_.Own(gtk_entry_new()); | 422 fake_entry_.Own(gtk_entry_new()); |
446 | 423 |
447 // The fake entry needs to be in the window so it can be realized so we can | 424 // The fake entry needs to be in the window so it can be realized so we can |
448 // use the computed parts of the style. | 425 // use the computed parts of the style. |
449 gtk_container_add(GTK_CONTAINER(GetRealizedWindow()), fake_entry_.get()); | 426 gtk_container_add(GTK_CONTAINER(GetWindow()), fake_entry_.get()); |
450 gtk_widget_realize(fake_entry_.get()); | 427 gtk_widget_realize(fake_entry_.get()); |
451 } | 428 } |
452 return gtk_rc_get_style(fake_entry_.get()); | 429 |
430 return fake_entry_.get(); | |
453 } | 431 } |
454 | 432 |
455 GtkStyle* NativeThemeGtk2::GetLabelStyle() const { | 433 GtkWidget* NativeThemeGtk2::GetLabel() const { |
456 if (!fake_label_.get()) | 434 if (!fake_label_.get()) |
457 fake_label_.Own(gtk_label_new("")); | 435 fake_label_.Own(gtk_label_new("")); |
458 | 436 |
459 return gtk_rc_get_style(fake_label_.get()); | 437 return fake_label_.get(); |
460 } | 438 } |
461 | 439 |
462 GtkStyle* NativeThemeGtk2::GetButtonStyle() const { | 440 GtkWidget* NativeThemeGtk2::GetButton() const { |
463 if (!fake_button_.get()) | 441 if (!fake_button_.get()) |
464 fake_button_.Own(gtk_button_new()); | 442 fake_button_.Own(gtk_button_new()); |
465 | 443 |
466 return gtk_rc_get_style(fake_button_.get()); | 444 return fake_button_.get(); |
467 } | 445 } |
468 | 446 |
469 GtkStyle* NativeThemeGtk2::GetTreeStyle() const { | 447 GtkWidget* NativeThemeGtk2::GetTree() const { |
470 if (!fake_tree_.get()) | 448 if (!fake_tree_.get()) |
471 fake_tree_.Own(gtk_tree_view_new()); | 449 fake_tree_.Own(gtk_tree_view_new()); |
472 | 450 |
473 return gtk_rc_get_style(fake_tree_.get()); | 451 return fake_tree_.get(); |
474 } | 452 } |
475 | 453 |
476 GtkStyle* NativeThemeGtk2::GetTooltipStyle() const { | 454 GtkWidget* NativeThemeGtk2::GetTooltip() const { |
477 if (!fake_tooltip_) { | 455 if (!fake_tooltip_.get()) { |
478 fake_tooltip_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 456 fake_tooltip_.Own(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
479 gtk_widget_set_name(fake_tooltip_, "gtk-tooltip"); | 457 gtk_widget_set_name(fake_tooltip_.get(), "gtk-tooltip"); |
480 gtk_widget_realize(fake_tooltip_); | 458 gtk_widget_realize(fake_tooltip_.get()); |
481 } | 459 } |
482 return gtk_rc_get_style(fake_tooltip_); | 460 |
461 return fake_tooltip_.get(); | |
483 } | 462 } |
484 | 463 |
485 GtkStyle* NativeThemeGtk2::GetMenuStyle() const { | 464 GtkWidget* NativeThemeGtk2::GetMenu() const { |
486 if (!fake_menu_.get()) | 465 if (!fake_menu_.get()) |
487 fake_menu_.Own(gtk_custom_menu_new()); | 466 fake_menu_.Own(gtk_custom_menu_new()); |
488 return gtk_rc_get_style(fake_menu_.get()); | 467 |
468 return fake_menu_.get(); | |
489 } | 469 } |
490 | 470 |
491 GtkStyle* NativeThemeGtk2::GetMenuItemStyle() const { | 471 GtkWidget* NativeThemeGtk2::GetMenuItem() const { |
492 if (!fake_menu_item_) { | 472 if (!fake_menu_item_.get()) { |
493 if (!fake_menu_.get()) | 473 fake_menu_item_.Own(gtk_custom_menu_item_new()); |
494 fake_menu_.Own(gtk_custom_menu_new()); | 474 gtk_menu_shell_append(GTK_MENU_SHELL(GetMenu()), fake_menu_item_.get()); |
495 | |
496 fake_menu_item_ = gtk_custom_menu_item_new(); | |
497 gtk_menu_shell_append(GTK_MENU_SHELL(fake_menu_.get()), fake_menu_item_); | |
498 } | 475 } |
499 | 476 |
500 return gtk_rc_get_style(fake_menu_item_); | 477 return fake_menu_item_.get(); |
501 } | |
502 | |
503 void NativeThemeGtk2::PaintComboboxArrow(SkCanvas* canvas, | |
504 GtkStateType state, | |
505 const gfx::Rect& rect) const { | |
506 GdkPixmap* pm = gdk_pixmap_new(gtk_widget_get_window(GetRealizedWindow()), | |
507 rect.width(), | |
508 rect.height(), | |
509 -1); | |
510 // Paint the background. | |
511 gtk_paint_flat_box(GetWindowStyle(), | |
512 pm, | |
513 state, | |
514 GTK_SHADOW_NONE, | |
515 NULL, | |
516 GetRealizedWindow(), | |
517 NULL, 0, 0, rect.width(), rect.height()); | |
518 gtk_paint_arrow(GetWindowStyle(), | |
519 pm, | |
520 state, | |
521 GTK_SHADOW_NONE, | |
522 NULL, | |
523 GetRealizedWindow(), | |
524 NULL, | |
525 GTK_ARROW_DOWN, | |
526 true, | |
527 0, 0, rect.width(), rect.height()); | |
528 GdkPixbuf* pb = gdk_pixbuf_get_from_drawable(NULL, | |
529 pm, | |
530 gdk_drawable_get_colormap(pm), | |
531 0, 0, | |
532 0, 0, | |
533 rect.width(), rect.height()); | |
534 SkBitmap arrow = GdkPixbufToImageSkia(pb); | |
535 canvas->drawBitmap(arrow, rect.x(), rect.y()); | |
536 | |
537 g_object_unref(pb); | |
538 g_object_unref(pm); | |
539 } | 478 } |
540 | 479 |
541 } // namespace libgtk2ui | 480 } // namespace libgtk2ui |
OLD | NEW |