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]) |
| 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]; | |
223 | |
224 // Dialogs | |
225 case kColorId_DialogBackground: | 212 case kColorId_DialogBackground: |
226 return GetWindowStyle()->bg[GTK_STATE_NORMAL]; | 213 return GET_BG_COLOR(GetWindow(), NORMAL); |
227 | 214 |
228 // FocusableBorder | 215 // FocusableBorder |
229 case kColorId_FocusedBorderColor: | 216 case kColorId_FocusedBorderColor: |
230 return GetEntryStyle()->bg[GTK_STATE_SELECTED]; | 217 return GET_BG_COLOR(GetEntry(), SELECTED); |
231 case kColorId_UnfocusedBorderColor: | 218 case kColorId_UnfocusedBorderColor: |
232 return GetEntryStyle()->text_aa[GTK_STATE_NORMAL]; | 219 return GET_TEXT_AA_COLOR(GetEntry(), NORMAL); |
233 | 220 |
234 // MenuItem | 221 // MenuItem |
235 case kColorId_EnabledMenuItemForegroundColor: | 222 case kColorId_EnabledMenuItemForegroundColor: |
236 case kColorId_DisabledEmphasizedMenuItemForegroundColor: | 223 case kColorId_DisabledEmphasizedMenuItemForegroundColor: |
237 return GetMenuItemStyle()->text[GTK_STATE_NORMAL]; | 224 return GET_TEXT_COLOR(GetMenuItem(), NORMAL); |
238 case kColorId_DisabledMenuItemForegroundColor: | 225 case kColorId_DisabledMenuItemForegroundColor: |
239 return GetMenuItemStyle()->text[GTK_STATE_INSENSITIVE]; | 226 return GET_TEXT_COLOR(GetMenuItem(), INSENSITIVE); |
240 case kColorId_SelectedMenuItemForegroundColor: | 227 case kColorId_SelectedMenuItemForegroundColor: |
241 return GetMenuItemStyle()->text[GTK_STATE_SELECTED]; | 228 return GET_TEXT_COLOR(GetMenuItem(), PRELIGHT); |
242 case kColorId_FocusedMenuItemBackgroundColor: | 229 case kColorId_FocusedMenuItemBackgroundColor: |
243 return GetMenuItemStyle()->bg[GTK_STATE_SELECTED]; | 230 return GET_BG_COLOR(GetMenuItem(), PRELIGHT); |
244 case kColorId_HoverMenuItemBackgroundColor: | 231 case kColorId_HoverMenuItemBackgroundColor: |
245 return GetMenuItemStyle()->bg[GTK_STATE_PRELIGHT]; | 232 return GET_BG_COLOR(GetMenuItem(), PRELIGHT); |
246 case kColorId_FocusedMenuButtonBorderColor: | 233 case kColorId_FocusedMenuButtonBorderColor: |
247 return GetEntryStyle()->bg[GTK_STATE_NORMAL]; | 234 return GET_BG_COLOR(GetEntry(), NORMAL); |
248 case kColorId_HoverMenuButtonBorderColor: | 235 case kColorId_HoverMenuButtonBorderColor: |
249 return GetEntryStyle()->text_aa[GTK_STATE_PRELIGHT]; | 236 return GET_TEXT_AA_COLOR(GetEntry(), PRELIGHT); |
250 case kColorId_MenuBorderColor: | 237 case kColorId_MenuBorderColor: |
251 case kColorId_EnabledMenuButtonBorderColor: | 238 case kColorId_EnabledMenuButtonBorderColor: |
252 case kColorId_MenuSeparatorColor: { | 239 case kColorId_MenuSeparatorColor: { |
253 return GetMenuItemStyle()->text[GTK_STATE_INSENSITIVE]; | 240 return GET_TEXT_COLOR(GetMenuItem(), INSENSITIVE); |
254 } | 241 } |
255 case kColorId_MenuBackgroundColor: | 242 case kColorId_MenuBackgroundColor: |
256 return GetMenuStyle()->bg[GTK_STATE_NORMAL]; | 243 return GET_BG_COLOR(GetMenu(), NORMAL); |
257 | 244 |
258 // Label | 245 // Label |
259 case kColorId_LabelEnabledColor: | 246 case kColorId_LabelEnabledColor: |
260 return GetLabelStyle()->text[GTK_STATE_NORMAL]; | 247 return GET_TEXT_COLOR(GetEntry(), NORMAL); |
261 case kColorId_LabelDisabledColor: | 248 case kColorId_LabelDisabledColor: |
262 return GetLabelStyle()->text[GTK_STATE_INSENSITIVE]; | 249 return GET_TEXT_COLOR(GetLabel(), INSENSITIVE); |
263 case kColorId_LabelBackgroundColor: | 250 case kColorId_LabelBackgroundColor: |
264 return GetWindowStyle()->bg[GTK_STATE_NORMAL]; | 251 return GET_BG_COLOR(GetWindow(), NORMAL); |
265 | 252 |
266 // Button | 253 // Button |
267 case kColorId_ButtonBackgroundColor: | 254 case kColorId_ButtonBackgroundColor: |
268 return GetButtonStyle()->bg[GTK_STATE_NORMAL]; | 255 return GET_BG_COLOR(GetButton(), NORMAL); |
269 case kColorId_ButtonEnabledColor: | 256 case kColorId_ButtonEnabledColor: |
270 case kColorId_BlueButtonEnabledColor: | 257 case kColorId_BlueButtonEnabledColor: |
271 return GetButtonStyle()->text[GTK_STATE_NORMAL]; | 258 return GET_TEXT_COLOR(GetButton(), NORMAL); |
272 case kColorId_ButtonDisabledColor: | 259 case kColorId_ButtonDisabledColor: |
273 case kColorId_BlueButtonDisabledColor: | 260 case kColorId_BlueButtonDisabledColor: |
274 return GetButtonStyle()->text[GTK_STATE_INSENSITIVE]; | 261 return GET_TEXT_COLOR(GetButton(), INSENSITIVE); |
275 case kColorId_ButtonHighlightColor: | 262 case kColorId_ButtonHighlightColor: |
276 return GetButtonStyle()->base[GTK_STATE_SELECTED]; | 263 return GET_BASE_COLOR(GetButton(), SELECTED); |
277 case kColorId_ButtonHoverColor: | 264 case kColorId_ButtonHoverColor: |
278 case kColorId_BlueButtonHoverColor: | 265 case kColorId_BlueButtonHoverColor: |
279 return GetButtonStyle()->text[GTK_STATE_PRELIGHT]; | 266 return GET_TEXT_COLOR(GetButton(), PRELIGHT); |
280 case kColorId_ButtonHoverBackgroundColor: | 267 case kColorId_ButtonHoverBackgroundColor: |
281 return GetButtonStyle()->bg[GTK_STATE_PRELIGHT]; | 268 return GET_BG_COLOR(GetButton(), PRELIGHT); |
282 case kColorId_BlueButtonPressedColor: | 269 case kColorId_BlueButtonPressedColor: |
283 return GetButtonStyle()->text[GTK_STATE_ACTIVE]; | 270 return GET_TEXT_COLOR(GetButton(), ACTIVE); |
284 case kColorId_BlueButtonShadowColor: | 271 case kColorId_BlueButtonShadowColor: |
285 // Should be handled in GetSystemColor(). | 272 // Should be handled in GetSystemColor(). |
286 NOTREACHED(); | 273 NOTREACHED(); |
287 return GetButtonStyle()->text[GTK_STATE_NORMAL]; | 274 return GET_TEXT_COLOR(GetButton(), NORMAL); |
288 | 275 |
289 // Textfield | 276 // Textfield |
290 case kColorId_TextfieldDefaultColor: | 277 case kColorId_TextfieldDefaultColor: |
291 return GetEntryStyle()->text[GTK_STATE_NORMAL]; | 278 return GET_TEXT_COLOR(GetEntry(), NORMAL); |
292 case kColorId_TextfieldDefaultBackground: | 279 case kColorId_TextfieldDefaultBackground: |
293 return GetEntryStyle()->base[GTK_STATE_NORMAL]; | 280 return GET_BASE_COLOR(GetEntry(), NORMAL); |
294 case kColorId_TextfieldReadOnlyColor: | 281 case kColorId_TextfieldReadOnlyColor: |
295 return GetEntryStyle()->text[GTK_STATE_INSENSITIVE]; | 282 return GET_TEXT_COLOR(GetEntry(), INSENSITIVE); |
296 case kColorId_TextfieldReadOnlyBackground: | 283 case kColorId_TextfieldReadOnlyBackground: |
297 return GetEntryStyle()->base[GTK_STATE_INSENSITIVE]; | 284 return GET_BASE_COLOR(GetEntry(), INSENSITIVE); |
298 case kColorId_TextfieldSelectionColor: | 285 case kColorId_TextfieldSelectionColor: |
299 return GetEntryStyle()->text[GTK_STATE_SELECTED]; | 286 return GET_TEXT_COLOR(GetEntry(), SELECTED); |
300 case kColorId_TextfieldSelectionBackgroundFocused: | 287 case kColorId_TextfieldSelectionBackgroundFocused: |
301 return GetEntryStyle()->base[GTK_STATE_SELECTED]; | 288 return GET_BASE_COLOR(GetEntry(), SELECTED); |
302 | 289 |
303 // Tooltips | 290 // Tooltips |
304 case kColorId_TooltipBackground: | 291 case kColorId_TooltipBackground: |
305 return GetTooltipStyle()->bg[GTK_STATE_NORMAL]; | 292 return GET_BG_COLOR(GetTooltip(), NORMAL); |
306 case kColorId_TooltipText: | 293 case kColorId_TooltipText: |
307 return GetTooltipStyle()->fg[GTK_STATE_NORMAL]; | 294 return GET_FG_COLOR(GetTooltip(), NORMAL); |
308 | 295 |
309 // Trees and Tables (implemented on GTK using the same class) | 296 // Trees and Tables (implemented on GTK using the same class) |
310 case kColorId_TableBackground: | 297 case kColorId_TableBackground: |
311 case kColorId_TreeBackground: | 298 case kColorId_TreeBackground: |
312 return GetTreeStyle()->bg[GTK_STATE_NORMAL]; | 299 return GET_BG_COLOR(GetTree(), NORMAL); |
313 case kColorId_TableText: | 300 case kColorId_TableText: |
314 case kColorId_TreeText: | 301 case kColorId_TreeText: |
315 return GetTreeStyle()->text[GTK_STATE_NORMAL]; | 302 return GET_TEXT_COLOR(GetTree(), NORMAL); |
316 case kColorId_TableSelectedText: | 303 case kColorId_TableSelectedText: |
317 case kColorId_TableSelectedTextUnfocused: | 304 case kColorId_TableSelectedTextUnfocused: |
318 case kColorId_TreeSelectedText: | 305 case kColorId_TreeSelectedText: |
319 case kColorId_TreeSelectedTextUnfocused: | 306 case kColorId_TreeSelectedTextUnfocused: |
320 return GetTreeStyle()->text[GTK_STATE_SELECTED]; | 307 return GET_TEXT_COLOR(GetTree(), SELECTED); |
321 case kColorId_TableSelectionBackgroundFocused: | 308 case kColorId_TableSelectionBackgroundFocused: |
322 case kColorId_TableSelectionBackgroundUnfocused: | 309 case kColorId_TableSelectionBackgroundUnfocused: |
323 case kColorId_TreeSelectionBackgroundFocused: | 310 case kColorId_TreeSelectionBackgroundFocused: |
324 case kColorId_TreeSelectionBackgroundUnfocused: | 311 case kColorId_TreeSelectionBackgroundUnfocused: |
325 return GetTreeStyle()->bg[GTK_STATE_SELECTED]; | 312 return GET_BG_COLOR(GetTree(), SELECTED); |
326 case kColorId_TreeArrow: | 313 case kColorId_TreeArrow: |
327 return GetTreeStyle()->fg[GTK_STATE_NORMAL]; | 314 return GET_FG_COLOR(GetTree(), NORMAL); |
328 case kColorId_TableGroupingIndicatorColor: | 315 case kColorId_TableGroupingIndicatorColor: |
329 return GetTreeStyle()->text_aa[GTK_STATE_NORMAL]; | 316 return GET_TEXT_AA_COLOR(GetTree(), NORMAL); |
330 | 317 |
331 // Results Table | 318 // Results Table |
332 case kColorId_ResultsTableNormalBackground: | 319 case kColorId_ResultsTableNormalBackground: |
333 return GetEntryStyle()->base[GTK_STATE_NORMAL]; | 320 return GET_BASE_COLOR(GetEntry(), NORMAL); |
334 case kColorId_ResultsTableHoveredBackground: { | 321 case kColorId_ResultsTableHoveredBackground: |
335 GtkStyle* entry_style = GetEntryStyle(); | 322 return color_utils::AlphaBlend(GET_BASE_COLOR(GetEntry(), NORMAL), |
336 return GdkAlphaBlend( | 323 GET_BASE_COLOR(GetEntry(), SELECTED), |
337 entry_style->base[GTK_STATE_NORMAL], | 324 0x80); |
338 entry_style->base[GTK_STATE_SELECTED], 0x80); | |
339 } | |
340 case kColorId_ResultsTableSelectedBackground: | 325 case kColorId_ResultsTableSelectedBackground: |
341 return GetEntryStyle()->base[GTK_STATE_SELECTED]; | 326 return GET_BASE_COLOR(GetEntry(), SELECTED); |
342 case kColorId_ResultsTableNormalText: | 327 case kColorId_ResultsTableNormalText: |
343 case kColorId_ResultsTableHoveredText: | 328 case kColorId_ResultsTableHoveredText: |
344 return GetEntryStyle()->text[GTK_STATE_NORMAL]; | 329 return GET_TEXT_COLOR(GetEntry(), NORMAL); |
345 case kColorId_ResultsTableSelectedText: | 330 case kColorId_ResultsTableSelectedText: |
346 return GetEntryStyle()->text[GTK_STATE_SELECTED]; | 331 return GET_TEXT_COLOR(GetEntry(), SELECTED); |
347 case kColorId_ResultsTableNormalDimmedText: | 332 case kColorId_ResultsTableNormalDimmedText: |
348 case kColorId_ResultsTableHoveredDimmedText: { | 333 case kColorId_ResultsTableHoveredDimmedText: |
349 GtkStyle* entry_style = GetEntryStyle(); | 334 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetEntry(), NORMAL), |
350 return GdkAlphaBlend( | 335 GET_BASE_COLOR(GetEntry(), NORMAL), |
351 entry_style->text[GTK_STATE_NORMAL], | 336 0x80); |
352 entry_style->base[GTK_STATE_NORMAL], 0x80); | 337 case kColorId_ResultsTableSelectedDimmedText: |
353 } | 338 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetEntry(), SELECTED), |
354 case kColorId_ResultsTableSelectedDimmedText: { | 339 GET_BASE_COLOR(GetEntry(), NORMAL), |
355 GtkStyle* entry_style = GetEntryStyle(); | 340 0x80); |
356 return GdkAlphaBlend( | |
357 entry_style->text[GTK_STATE_SELECTED], | |
358 entry_style->base[GTK_STATE_NORMAL], 0x80); | |
359 } | |
360 case kColorId_ResultsTableNormalUrl: | 341 case kColorId_ResultsTableNormalUrl: |
361 case kColorId_ResultsTableHoveredUrl: { | 342 case kColorId_ResultsTableHoveredUrl: |
362 return NormalURLColor(GetEntryStyle()->text[GTK_STATE_NORMAL]); | 343 return NormalURLColor(GET_TEXT_COLOR(GetEntry(), NORMAL)); |
363 } | 344 |
364 case kColorId_ResultsTableSelectedUrl: { | 345 case kColorId_ResultsTableSelectedUrl: |
365 GtkStyle* entry_style = GetEntryStyle(); | 346 return SelectedURLColor(GET_TEXT_COLOR(GetEntry(), SELECTED), |
366 return SelectedURLColor(entry_style->text[GTK_STATE_SELECTED], | 347 GET_BASE_COLOR(GetEntry(), SELECTED)); |
367 entry_style->base[GTK_STATE_SELECTED]); | 348 case kColorId_ResultsTableNormalDivider: |
368 } | 349 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetWindow(), NORMAL), |
369 case kColorId_ResultsTableNormalDivider: { | 350 GET_BG_COLOR(GetWindow(), NORMAL), |
370 GtkStyle* win_style = GetWindowStyle(); | 351 0x34); |
371 return GdkAlphaBlend(win_style->text[GTK_STATE_NORMAL], | 352 case kColorId_ResultsTableHoveredDivider: |
372 win_style->bg[GTK_STATE_NORMAL], 0x34); | 353 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetWindow(), PRELIGHT), |
373 } | 354 GET_BG_COLOR(GetWindow(), PRELIGHT), |
374 case kColorId_ResultsTableHoveredDivider: { | 355 0x34); |
375 GtkStyle* win_style = GetWindowStyle(); | 356 case kColorId_ResultsTableSelectedDivider: |
376 return GdkAlphaBlend(win_style->text[GTK_STATE_PRELIGHT], | 357 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetWindow(), SELECTED), |
377 win_style->bg[GTK_STATE_PRELIGHT], 0x34); | 358 GET_BG_COLOR(GetWindow(), SELECTED), |
378 } | 359 0x34); |
379 case kColorId_ResultsTableSelectedDivider: { | 360 |
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: { | 361 case kColorId_ResultsTablePositiveText: { |
385 return GetReadableColor(kPositiveTextColor, | 362 return color_utils::GetReadableColor(kPositiveTextColor, |
386 GetEntryStyle()->base[GTK_STATE_NORMAL]); | 363 GET_BASE_COLOR(GetEntry(), NORMAL)); |
387 } | 364 } |
388 case kColorId_ResultsTablePositiveHoveredText: { | 365 case kColorId_ResultsTablePositiveHoveredText: { |
389 return GetReadableColor(kPositiveTextColor, | 366 return color_utils::GetReadableColor(kPositiveTextColor, |
390 GetEntryStyle()->base[GTK_STATE_PRELIGHT]); | 367 GET_BASE_COLOR(GetEntry(), PRELIGHT))
; |
391 } | 368 } |
392 case kColorId_ResultsTablePositiveSelectedText: { | 369 case kColorId_ResultsTablePositiveSelectedText: { |
393 return GetReadableColor(kPositiveTextColor, | 370 return color_utils::GetReadableColor(kPositiveTextColor, |
394 GetEntryStyle()->base[GTK_STATE_SELECTED]); | 371 GET_BASE_COLOR(GetEntry(), SELECTED))
; |
395 } | 372 } |
396 case kColorId_ResultsTableNegativeText: { | 373 case kColorId_ResultsTableNegativeText: { |
397 return GetReadableColor(kNegativeTextColor, | 374 return color_utils::GetReadableColor(kNegativeTextColor, |
398 GetEntryStyle()->base[GTK_STATE_NORMAL]); | 375 GET_BASE_COLOR(GetEntry(), NORMAL)); |
399 } | 376 } |
400 case kColorId_ResultsTableNegativeHoveredText: { | 377 case kColorId_ResultsTableNegativeHoveredText: { |
401 return GetReadableColor(kNegativeTextColor, | 378 return color_utils::GetReadableColor(kNegativeTextColor, |
402 GetEntryStyle()->base[GTK_STATE_PRELIGHT]); | 379 GET_BASE_COLOR(GetEntry(), PRELIGHT))
; |
403 } | 380 } |
404 case kColorId_ResultsTableNegativeSelectedText: { | 381 case kColorId_ResultsTableNegativeSelectedText: { |
405 return GetReadableColor(kNegativeTextColor, | 382 return color_utils::GetReadableColor(kNegativeTextColor, |
406 GetEntryStyle()->base[GTK_STATE_SELECTED]); | 383 GET_BASE_COLOR(GetEntry(), SELECTED))
; |
407 } | 384 } |
408 | 385 |
409 // Throbber | 386 // Throbber |
410 case kColorId_ThrobberSpinningColor: | 387 case kColorId_ThrobberSpinningColor: |
411 case kColorId_ThrobberLightColor: { | 388 case kColorId_ThrobberLightColor: { |
412 return GetEntryStyle()->bg[GTK_STATE_SELECTED]; | 389 return GET_BG_COLOR(GetEntry(), SELECTED); |
413 } | 390 } |
414 | 391 |
415 case kColorId_ThrobberWaitingColor: { | 392 case kColorId_ThrobberWaitingColor: { |
416 return GdkAlphaBlend(GetEntryStyle()->bg[GTK_STATE_SELECTED], | 393 return color_utils::AlphaBlend(GET_BG_COLOR(GetEntry(), SELECTED), |
417 GetWindowStyle()->bg[GTK_STATE_NORMAL], 0xff / 2); | 394 GET_BG_COLOR(GetWindow(), NORMAL), |
| 395 0x80); |
418 } | 396 } |
419 | 397 |
420 case kColorId_ChromeIconGrey: | 398 case kColorId_ChromeIconGrey: |
421 case kColorId_GoogleBlue: | 399 case kColorId_GoogleBlue: |
422 case kColorId_NumColors: | 400 case kColorId_NumColors: |
423 NOTREACHED(); | 401 NOTREACHED(); |
424 break; | 402 break; |
425 } | 403 } |
426 | 404 |
427 return SkColorToGdkColor(kInvalidColorIdColor); | 405 return kInvalidColorIdColor; |
428 } | 406 } |
429 | 407 |
430 GtkWidget* NativeThemeGtk2::GetRealizedWindow() const { | 408 GtkWidget* NativeThemeGtk2::GetWindow() const { |
431 if (!fake_window_) { | 409 if (!fake_window_.get()) { |
432 fake_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 410 fake_window_.Own(chrome_gtk_frame_new()); |
433 gtk_widget_realize(fake_window_); | 411 gtk_widget_realize(fake_window_.get()); |
434 } | 412 } |
435 | 413 |
436 return fake_window_; | 414 return fake_window_.get(); |
437 } | 415 } |
438 | 416 |
439 GtkStyle* NativeThemeGtk2::GetWindowStyle() const { | 417 GtkWidget* NativeThemeGtk2::GetEntry() const { |
440 return gtk_rc_get_style(GetRealizedWindow()); | |
441 } | |
442 | |
443 GtkStyle* NativeThemeGtk2::GetEntryStyle() const { | |
444 if (!fake_entry_.get()) { | 418 if (!fake_entry_.get()) { |
445 fake_entry_.Own(gtk_entry_new()); | 419 fake_entry_.Own(gtk_entry_new()); |
446 | 420 |
447 // The fake entry needs to be in the window so it can be realized so we can | 421 // 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. | 422 // use the computed parts of the style. |
449 gtk_container_add(GTK_CONTAINER(GetRealizedWindow()), fake_entry_.get()); | 423 gtk_container_add(GTK_CONTAINER(GetWindow()), fake_entry_.get()); |
450 gtk_widget_realize(fake_entry_.get()); | 424 gtk_widget_realize(fake_entry_.get()); |
451 } | 425 } |
452 return gtk_rc_get_style(fake_entry_.get()); | 426 |
| 427 return fake_entry_.get(); |
453 } | 428 } |
454 | 429 |
455 GtkStyle* NativeThemeGtk2::GetLabelStyle() const { | 430 GtkWidget* NativeThemeGtk2::GetLabel() const { |
456 if (!fake_label_.get()) | 431 if (!fake_label_.get()) |
457 fake_label_.Own(gtk_label_new("")); | 432 fake_label_.Own(gtk_label_new("")); |
458 | 433 |
459 return gtk_rc_get_style(fake_label_.get()); | 434 return fake_label_.get(); |
460 } | 435 } |
461 | 436 |
462 GtkStyle* NativeThemeGtk2::GetButtonStyle() const { | 437 GtkWidget* NativeThemeGtk2::GetButton() const { |
463 if (!fake_button_.get()) | 438 if (!fake_button_.get()) |
464 fake_button_.Own(gtk_button_new()); | 439 fake_button_.Own(gtk_button_new()); |
465 | 440 |
466 return gtk_rc_get_style(fake_button_.get()); | 441 return fake_button_.get(); |
467 } | 442 } |
468 | 443 |
469 GtkStyle* NativeThemeGtk2::GetTreeStyle() const { | 444 GtkWidget* NativeThemeGtk2::GetTree() const { |
470 if (!fake_tree_.get()) | 445 if (!fake_tree_.get()) |
471 fake_tree_.Own(gtk_tree_view_new()); | 446 fake_tree_.Own(gtk_tree_view_new()); |
472 | 447 |
473 return gtk_rc_get_style(fake_tree_.get()); | 448 return fake_tree_.get(); |
474 } | 449 } |
475 | 450 |
476 GtkStyle* NativeThemeGtk2::GetTooltipStyle() const { | 451 GtkWidget* NativeThemeGtk2::GetTooltip() const { |
477 if (!fake_tooltip_) { | 452 if (!fake_tooltip_.get()) { |
478 fake_tooltip_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); | 453 fake_tooltip_.Own(gtk_window_new(GTK_WINDOW_TOPLEVEL)); |
479 gtk_widget_set_name(fake_tooltip_, "gtk-tooltip"); | 454 gtk_widget_set_name(fake_tooltip_.get(), "gtk-tooltip"); |
480 gtk_widget_realize(fake_tooltip_); | 455 gtk_widget_realize(fake_tooltip_.get()); |
481 } | 456 } |
482 return gtk_rc_get_style(fake_tooltip_); | 457 |
| 458 return fake_tooltip_.get(); |
483 } | 459 } |
484 | 460 |
485 GtkStyle* NativeThemeGtk2::GetMenuStyle() const { | 461 GtkWidget* NativeThemeGtk2::GetMenu() const { |
486 if (!fake_menu_.get()) | 462 if (!fake_menu_.get()) |
487 fake_menu_.Own(gtk_custom_menu_new()); | 463 fake_menu_.Own(gtk_custom_menu_new()); |
488 return gtk_rc_get_style(fake_menu_.get()); | 464 |
| 465 return fake_menu_.get(); |
489 } | 466 } |
490 | 467 |
491 GtkStyle* NativeThemeGtk2::GetMenuItemStyle() const { | 468 GtkWidget* NativeThemeGtk2::GetMenuItem() const { |
492 if (!fake_menu_item_) { | 469 if (!fake_menu_item_.get()) { |
493 if (!fake_menu_.get()) | 470 fake_menu_item_.Own(gtk_custom_menu_item_new()); |
494 fake_menu_.Own(gtk_custom_menu_new()); | 471 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 } | 472 } |
499 | 473 |
500 return gtk_rc_get_style(fake_menu_item_); | 474 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 } | 475 } |
540 | 476 |
541 } // namespace libgtk2ui | 477 } // namespace libgtk2ui |
OLD | NEW |