Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(473)

Side by Side Diff: chrome/browser/ui/libgtk2ui/native_theme_gtk2.cc

Issue 1234223005: Initial gtk3 support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix colors Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 gtk_style_context_get_background_color(
51 gtk_widget_get_style_context(widget), flags, &color);
52
53 //Hack for default color
54 if (color.alpha == 0.0)
55 color = {1, 1, 1, 1};
56
57 return SkColorSetRGB(color.red * 255, color.green * 255, color.blue * 255);
58 }
59
60
61 #define GET_FG_COLOR(gtkwidget, gtkstate) \
62 FgColorToSkColor(gtkwidget, GTK_STATE_FLAG_ ## gtkstate)
63
64 #define GET_BG_COLOR(gtkwidget, gtkstate) \
65 BgColorToSkColor(gtkwidget, GTK_STATE_FLAG_ ## gtkstate)
66
67 #define GET_TEXT_COLOR GET_FG_COLOR
68 #define GET_TEXT_AA_COLOR GET_FG_COLOR
69 #define GET_BASE_COLOR GET_BG_COLOR
70
71 #endif
72
73
21 namespace { 74 namespace {
22 75
23 // Theme colors returned by GetSystemColor(). 76 // Theme colors returned by GetSystemColor().
24 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); 77 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128);
25 78 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 79
36 // Generates the normal URL color, a green color used in unhighlighted URL 80 // 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 81 // 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 82 // selected text color, it is more important to match the qualities of the
39 // foreground typeface color instead of taking the background into account. 83 // foreground typeface color instead of taking the background into account.
40 GdkColor NormalURLColor(GdkColor foreground) { 84 SkColor NormalURLColor(SkColor foreground) {
41 color_utils::HSL fg_hsl; 85 color_utils::HSL fg_hsl, hue_hsl;
42 color_utils::SkColorToHSL(libgtk2ui::GdkColorToSkColor(foreground), &fg_hsl); 86 color_utils::SkColorToHSL(foreground, &fg_hsl);
43 87 color_utils::SkColorToHSL(kURLTextColor, &hue_hsl);
44 color_utils::HSL hue_hsl;
45 color_utils::SkColorToHSL(libgtk2ui::GdkColorToSkColor(kURLTextColor),
46 &hue_hsl);
47 88
48 // Only allow colors that have a fair amount of saturation in them (color vs 89 // 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. 90 // white). This means that our output color will always be fairly green.
50 double s = std::max(0.5, fg_hsl.s); 91 double s = std::max(0.5, fg_hsl.s);
51 92
52 // Make sure the luminance is at least as bright as the |kURLTextColor| green 93 // Make sure the luminance is at least as bright as the |kURLTextColor| green
53 // would be if we were to use that. 94 // would be if we were to use that.
54 double l; 95 double l;
55 if (fg_hsl.l < hue_hsl.l) 96 if (fg_hsl.l < hue_hsl.l)
56 l = hue_hsl.l; 97 l = hue_hsl.l;
57 else 98 else
58 l = (fg_hsl.l + hue_hsl.l) / 2; 99 l = (fg_hsl.l + hue_hsl.l) / 2;
59 100
60 color_utils::HSL output = { hue_hsl.h, s, l }; 101 color_utils::HSL output = { hue_hsl.h, s, l };
61 return libgtk2ui::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255)); 102 return color_utils::HSLToSkColor(output, 255);
62 } 103 }
63 104
64 // Generates the selected URL color, a green color used on URL text in the 105 // 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 106 // currently highlighted entry in the autocomplete popup. It's a mix of
66 // |kURLTextColor|, the current text color, and the background color (the 107 // |kURLTextColor|, the current text color, and the background color (the
67 // select highlight). It is more important to contrast with the background 108 // select highlight). It is more important to contrast with the background
68 // saturation than to look exactly like the foreground color. 109 // saturation than to look exactly like the foreground color.
69 GdkColor SelectedURLColor(GdkColor foreground, GdkColor background) { 110 SkColor SelectedURLColor(SkColor foreground, SkColor background) {
70 color_utils::HSL fg_hsl; 111 color_utils::HSL fg_hsl, bg_hsl, hue_hsl;
71 color_utils::SkColorToHSL(libgtk2ui::GdkColorToSkColor(foreground), 112 color_utils::SkColorToHSL(foreground, &fg_hsl);
72 &fg_hsl); 113 color_utils::SkColorToHSL(background, &bg_hsl);
73 114 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 115
82 // The saturation of the text should be opposite of the background, clamped 116 // 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 117 // 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. 118 // less than 0.8 so it's not the oversaturated neon-color.
85 double opposite_s = 1 - bg_hsl.s; 119 double opposite_s = 1 - bg_hsl.s;
86 double s = std::max(0.2, std::min(0.8, opposite_s)); 120 double s = std::max(0.2, std::min(0.8, opposite_s));
87 121
88 // The luminance should match the luminance of the foreground text. Again, 122 // 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. 123 // we clamp so as to have at some amount of color (green) in the text.
90 double opposite_l = fg_hsl.l; 124 double opposite_l = fg_hsl.l;
91 double l = std::max(0.1, std::min(0.9, opposite_l)); 125 double l = std::max(0.1, std::min(0.9, opposite_l));
92 126
93 color_utils::HSL output = { hue_hsl.h, s, l }; 127 color_utils::HSL output = { hue_hsl.h, s, l };
94 return libgtk2ui::SkColorToGdkColor(color_utils::HSLToSkColor(output, 255)); 128 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 } 129 }
101 130
102 } // namespace 131 } // namespace
103 132
104 133
105 namespace libgtk2ui { 134 namespace libgtk2ui {
106 135
107 // static 136 // static
108 NativeThemeGtk2* NativeThemeGtk2::instance() { 137 NativeThemeGtk2* NativeThemeGtk2::instance() {
109 CR_DEFINE_STATIC_LOCAL(NativeThemeGtk2, s_native_theme, ()); 138 CR_DEFINE_STATIC_LOCAL(NativeThemeGtk2, s_native_theme, ());
110 return &s_native_theme; 139 return &s_native_theme;
111 } 140 }
112 141
113 NativeThemeGtk2::NativeThemeGtk2() 142 //Constructors automatically called
114 : fake_window_(NULL), 143 NativeThemeGtk2::NativeThemeGtk2() {}
115 fake_tooltip_(NULL), 144 //This doesn't actually get called
116 fake_menu_item_(NULL) { 145 NativeThemeGtk2::~NativeThemeGtk2() {}
117 }
118 146
119 NativeThemeGtk2::~NativeThemeGtk2() {
120 if (fake_window_)
121 gtk_widget_destroy(fake_window_);
122 if (fake_tooltip_)
123 gtk_widget_destroy(fake_tooltip_);
124 147
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 148
166 void NativeThemeGtk2::PaintMenuPopupBackground( 149 void NativeThemeGtk2::PaintMenuPopupBackground(
167 SkCanvas* canvas, 150 SkCanvas* canvas,
168 const gfx::Size& size, 151 const gfx::Size& size,
169 const MenuBackgroundExtraParams& menu_background) const { 152 const MenuBackgroundExtraParams& menu_background) const {
170 if (menu_background.corner_radius > 0) { 153 if (menu_background.corner_radius > 0) {
171 SkPaint paint; 154 SkPaint paint;
172 paint.setStyle(SkPaint::kFill_Style); 155 paint.setStyle(SkPaint::kFill_Style);
173 paint.setFlags(SkPaint::kAntiAlias_Flag); 156 paint.setFlags(SkPaint::kAntiAlias_Flag);
174 paint.setColor(GetSystemColor(kColorId_MenuBackgroundColor)); 157 paint.setColor(GetSystemColor(kColorId_MenuBackgroundColor));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 NativeTheme::kColorId_FocusedMenuItemBackgroundColor); 189 NativeTheme::kColorId_FocusedMenuItemBackgroundColor);
207 paint.setColor(color); 190 paint.setColor(color);
208 break; 191 break;
209 default: 192 default:
210 NOTREACHED() << "Invalid state " << state; 193 NOTREACHED() << "Invalid state " << state;
211 break; 194 break;
212 } 195 }
213 canvas->drawRect(gfx::RectToSkRect(rect), paint); 196 canvas->drawRect(gfx::RectToSkRect(rect), paint);
214 } 197 }
215 198
216 GdkColor NativeThemeGtk2::GetSystemGdkColor(ColorId color_id) const { 199 SkColor NativeThemeGtk2::GetSystemColor(ColorId color_id) const {
200 if (color_id == kColorId_BlueButtonShadowColor)
201 return SK_ColorTRANSPARENT;
202
217 const SkColor kPositiveTextColor = SkColorSetRGB(0x0b, 0x80, 0x43); 203 const SkColor kPositiveTextColor = SkColorSetRGB(0x0b, 0x80, 0x43);
218 const SkColor kNegativeTextColor = SkColorSetRGB(0xc5, 0x39, 0x29); 204 const SkColor kNegativeTextColor = SkColorSetRGB(0xc5, 0x39, 0x29);
205
219 switch (color_id) { 206 switch (color_id) {
220 // Windows 207 // Windows
221 case kColorId_WindowBackground: 208 case kColorId_WindowBackground:
222 return GetWindowStyle()->bg[GTK_STATE_NORMAL];
223
224 // Dialogs
225 case kColorId_DialogBackground: 209 case kColorId_DialogBackground:
226 return GetWindowStyle()->bg[GTK_STATE_NORMAL]; 210 return GET_BG_COLOR(GetWindow(), NORMAL);
227 211
228 // FocusableBorder 212 // FocusableBorder
229 case kColorId_FocusedBorderColor: 213 case kColorId_FocusedBorderColor:
230 return GetEntryStyle()->bg[GTK_STATE_SELECTED]; 214 return GET_BG_COLOR(GetEntry(), SELECTED);
231 case kColorId_UnfocusedBorderColor: 215 case kColorId_UnfocusedBorderColor:
232 return GetEntryStyle()->text_aa[GTK_STATE_NORMAL]; 216 return GET_TEXT_AA_COLOR(GetEntry(), NORMAL);
233 217
234 // MenuItem 218 // MenuItem
235 case kColorId_EnabledMenuItemForegroundColor: 219 case kColorId_EnabledMenuItemForegroundColor:
236 case kColorId_DisabledEmphasizedMenuItemForegroundColor: 220 case kColorId_DisabledEmphasizedMenuItemForegroundColor:
237 return GetMenuItemStyle()->text[GTK_STATE_NORMAL]; 221 return GET_TEXT_COLOR(GetMenuItem(), NORMAL);
238 case kColorId_DisabledMenuItemForegroundColor: 222 case kColorId_DisabledMenuItemForegroundColor:
239 return GetMenuItemStyle()->text[GTK_STATE_INSENSITIVE]; 223 return GET_TEXT_COLOR(GetMenuItem(), INSENSITIVE);
240 case kColorId_SelectedMenuItemForegroundColor: 224 case kColorId_SelectedMenuItemForegroundColor:
241 return GetMenuItemStyle()->text[GTK_STATE_SELECTED]; 225 return GET_TEXT_COLOR(GetMenuItem(), PRELIGHT);
242 case kColorId_FocusedMenuItemBackgroundColor: 226 case kColorId_FocusedMenuItemBackgroundColor:
243 return GetMenuItemStyle()->bg[GTK_STATE_SELECTED]; 227 return GET_BG_COLOR(GetMenuItem(), PRELIGHT);
244 case kColorId_HoverMenuItemBackgroundColor: 228 case kColorId_HoverMenuItemBackgroundColor:
245 return GetMenuItemStyle()->bg[GTK_STATE_PRELIGHT]; 229 return GET_BG_COLOR(GetMenuItem(), PRELIGHT);
246 case kColorId_FocusedMenuButtonBorderColor: 230 case kColorId_FocusedMenuButtonBorderColor:
247 return GetEntryStyle()->bg[GTK_STATE_NORMAL]; 231 return GET_BG_COLOR(GetEntry(), NORMAL);
248 case kColorId_HoverMenuButtonBorderColor: 232 case kColorId_HoverMenuButtonBorderColor:
249 return GetEntryStyle()->text_aa[GTK_STATE_PRELIGHT]; 233 return GET_TEXT_AA_COLOR(GetEntry(), PRELIGHT);
250 case kColorId_MenuBorderColor: 234 case kColorId_MenuBorderColor:
251 case kColorId_EnabledMenuButtonBorderColor: 235 case kColorId_EnabledMenuButtonBorderColor:
252 case kColorId_MenuSeparatorColor: { 236 case kColorId_MenuSeparatorColor: {
253 return GetMenuItemStyle()->text[GTK_STATE_INSENSITIVE]; 237 return GET_TEXT_COLOR(GetMenuItem(), INSENSITIVE);
254 } 238 }
255 case kColorId_MenuBackgroundColor: 239 case kColorId_MenuBackgroundColor:
256 return GetMenuStyle()->bg[GTK_STATE_NORMAL]; 240 return GET_BG_COLOR(GetMenu(), NORMAL);
257 241
258 // Label 242 // Label
259 case kColorId_LabelEnabledColor: 243 case kColorId_LabelEnabledColor:
260 return GetLabelStyle()->text[GTK_STATE_NORMAL]; 244 return GET_TEXT_COLOR(GetEntry(), NORMAL);
261 case kColorId_LabelDisabledColor: 245 case kColorId_LabelDisabledColor:
262 return GetLabelStyle()->text[GTK_STATE_INSENSITIVE]; 246 return GET_TEXT_COLOR(GetLabel(), INSENSITIVE);
263 case kColorId_LabelBackgroundColor: 247 case kColorId_LabelBackgroundColor:
264 return GetWindowStyle()->bg[GTK_STATE_NORMAL]; 248 return GET_BG_COLOR(GetWindow(), NORMAL);
265 249
266 // Button 250 // Button
267 case kColorId_ButtonBackgroundColor: 251 case kColorId_ButtonBackgroundColor:
268 return GetButtonStyle()->bg[GTK_STATE_NORMAL]; 252 return GET_BG_COLOR(GetButton(), NORMAL);
269 case kColorId_ButtonEnabledColor: 253 case kColorId_ButtonEnabledColor:
270 case kColorId_BlueButtonEnabledColor: 254 case kColorId_BlueButtonEnabledColor:
271 return GetButtonStyle()->text[GTK_STATE_NORMAL]; 255 return GET_TEXT_COLOR(GetButton(), NORMAL);
272 case kColorId_ButtonDisabledColor: 256 case kColorId_ButtonDisabledColor:
273 case kColorId_BlueButtonDisabledColor: 257 case kColorId_BlueButtonDisabledColor:
274 return GetButtonStyle()->text[GTK_STATE_INSENSITIVE]; 258 return GET_TEXT_COLOR(GetButton(), INSENSITIVE);
275 case kColorId_ButtonHighlightColor: 259 case kColorId_ButtonHighlightColor:
276 return GetButtonStyle()->base[GTK_STATE_SELECTED]; 260 return GET_BASE_COLOR(GetButton(), SELECTED);
277 case kColorId_ButtonHoverColor: 261 case kColorId_ButtonHoverColor:
278 case kColorId_BlueButtonHoverColor: 262 case kColorId_BlueButtonHoverColor:
279 return GetButtonStyle()->text[GTK_STATE_PRELIGHT]; 263 return GET_TEXT_COLOR(GetButton(), PRELIGHT);
280 case kColorId_ButtonHoverBackgroundColor: 264 case kColorId_ButtonHoverBackgroundColor:
281 return GetButtonStyle()->bg[GTK_STATE_PRELIGHT]; 265 return GET_BG_COLOR(GetButton(), PRELIGHT);
282 case kColorId_BlueButtonPressedColor: 266 case kColorId_BlueButtonPressedColor:
283 return GetButtonStyle()->text[GTK_STATE_ACTIVE]; 267 return GET_TEXT_COLOR(GetButton(), ACTIVE);
284 case kColorId_BlueButtonShadowColor: 268 case kColorId_BlueButtonShadowColor:
285 // Should be handled in GetSystemColor(). 269 // Should be handled in GetSystemColor().
286 NOTREACHED(); 270 NOTREACHED();
287 return GetButtonStyle()->text[GTK_STATE_NORMAL]; 271 return GET_TEXT_COLOR(GetButton(), NORMAL);
288 272
289 // Textfield 273 // Textfield
290 case kColorId_TextfieldDefaultColor: 274 case kColorId_TextfieldDefaultColor:
291 return GetEntryStyle()->text[GTK_STATE_NORMAL]; 275 return GET_TEXT_COLOR(GetEntry(), NORMAL);
292 case kColorId_TextfieldDefaultBackground: 276 case kColorId_TextfieldDefaultBackground:
293 return GetEntryStyle()->base[GTK_STATE_NORMAL]; 277 return GET_BASE_COLOR(GetEntry(), NORMAL);
294 case kColorId_TextfieldReadOnlyColor: 278 case kColorId_TextfieldReadOnlyColor:
295 return GetEntryStyle()->text[GTK_STATE_INSENSITIVE]; 279 return GET_TEXT_COLOR(GetEntry(), INSENSITIVE);
296 case kColorId_TextfieldReadOnlyBackground: 280 case kColorId_TextfieldReadOnlyBackground:
297 return GetEntryStyle()->base[GTK_STATE_INSENSITIVE]; 281 return GET_BASE_COLOR(GetEntry(), INSENSITIVE);
298 case kColorId_TextfieldSelectionColor: 282 case kColorId_TextfieldSelectionColor:
299 return GetEntryStyle()->text[GTK_STATE_SELECTED]; 283 return GET_TEXT_COLOR(GetEntry(), SELECTED);
300 case kColorId_TextfieldSelectionBackgroundFocused: 284 case kColorId_TextfieldSelectionBackgroundFocused:
301 return GetEntryStyle()->base[GTK_STATE_SELECTED]; 285 return GET_BASE_COLOR(GetEntry(), SELECTED);
302 286
303 // Tooltips 287 // Tooltips
304 case kColorId_TooltipBackground: 288 case kColorId_TooltipBackground:
305 return GetTooltipStyle()->bg[GTK_STATE_NORMAL]; 289 return GET_BG_COLOR(GetTooltip(), NORMAL);
306 case kColorId_TooltipText: 290 case kColorId_TooltipText:
307 return GetTooltipStyle()->fg[GTK_STATE_NORMAL]; 291 return GET_FG_COLOR(GetTooltip(), NORMAL);
308 292
309 // Trees and Tables (implemented on GTK using the same class) 293 // Trees and Tables (implemented on GTK using the same class)
310 case kColorId_TableBackground: 294 case kColorId_TableBackground:
311 case kColorId_TreeBackground: 295 case kColorId_TreeBackground:
312 return GetTreeStyle()->bg[GTK_STATE_NORMAL]; 296 return GET_BG_COLOR(GetTree(), NORMAL);
313 case kColorId_TableText: 297 case kColorId_TableText:
314 case kColorId_TreeText: 298 case kColorId_TreeText:
315 return GetTreeStyle()->text[GTK_STATE_NORMAL]; 299 return GET_TEXT_COLOR(GetTree(), NORMAL);
316 case kColorId_TableSelectedText: 300 case kColorId_TableSelectedText:
317 case kColorId_TableSelectedTextUnfocused: 301 case kColorId_TableSelectedTextUnfocused:
318 case kColorId_TreeSelectedText: 302 case kColorId_TreeSelectedText:
319 case kColorId_TreeSelectedTextUnfocused: 303 case kColorId_TreeSelectedTextUnfocused:
320 return GetTreeStyle()->text[GTK_STATE_SELECTED]; 304 return GET_TEXT_COLOR(GetTree(), SELECTED);
321 case kColorId_TableSelectionBackgroundFocused: 305 case kColorId_TableSelectionBackgroundFocused:
322 case kColorId_TableSelectionBackgroundUnfocused: 306 case kColorId_TableSelectionBackgroundUnfocused:
323 case kColorId_TreeSelectionBackgroundFocused: 307 case kColorId_TreeSelectionBackgroundFocused:
324 case kColorId_TreeSelectionBackgroundUnfocused: 308 case kColorId_TreeSelectionBackgroundUnfocused:
325 return GetTreeStyle()->bg[GTK_STATE_SELECTED]; 309 return GET_BG_COLOR(GetTree(), SELECTED);
326 case kColorId_TreeArrow: 310 case kColorId_TreeArrow:
327 return GetTreeStyle()->fg[GTK_STATE_NORMAL]; 311 return GET_FG_COLOR(GetTree(), NORMAL);
328 case kColorId_TableGroupingIndicatorColor: 312 case kColorId_TableGroupingIndicatorColor:
329 return GetTreeStyle()->text_aa[GTK_STATE_NORMAL]; 313 return GET_TEXT_AA_COLOR(GetTree(), NORMAL);
330 314
331 // Results Table 315 // Results Table
332 case kColorId_ResultsTableNormalBackground: 316 case kColorId_ResultsTableNormalBackground:
333 return GetEntryStyle()->base[GTK_STATE_NORMAL]; 317 return GET_BASE_COLOR(GetEntry(), NORMAL);
334 case kColorId_ResultsTableHoveredBackground: { 318 case kColorId_ResultsTableHoveredBackground:
335 GtkStyle* entry_style = GetEntryStyle(); 319 return color_utils::AlphaBlend(GET_BASE_COLOR(GetEntry(), NORMAL),
336 return GdkAlphaBlend( 320 GET_BASE_COLOR(GetEntry(), SELECTED),
337 entry_style->base[GTK_STATE_NORMAL], 321 0x80);
338 entry_style->base[GTK_STATE_SELECTED], 0x80);
339 }
340 case kColorId_ResultsTableSelectedBackground: 322 case kColorId_ResultsTableSelectedBackground:
341 return GetEntryStyle()->base[GTK_STATE_SELECTED]; 323 return GET_BASE_COLOR(GetEntry(), SELECTED);
342 case kColorId_ResultsTableNormalText: 324 case kColorId_ResultsTableNormalText:
343 case kColorId_ResultsTableHoveredText: 325 case kColorId_ResultsTableHoveredText:
344 return GetEntryStyle()->text[GTK_STATE_NORMAL]; 326 return GET_TEXT_COLOR(GetEntry(), NORMAL);
345 case kColorId_ResultsTableSelectedText: 327 case kColorId_ResultsTableSelectedText:
346 return GetEntryStyle()->text[GTK_STATE_SELECTED]; 328 return GET_TEXT_COLOR(GetEntry(), SELECTED);
347 case kColorId_ResultsTableNormalDimmedText: 329 case kColorId_ResultsTableNormalDimmedText:
348 case kColorId_ResultsTableHoveredDimmedText: { 330 case kColorId_ResultsTableHoveredDimmedText:
349 GtkStyle* entry_style = GetEntryStyle(); 331 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetEntry(), NORMAL),
350 return GdkAlphaBlend( 332 GET_BASE_COLOR(GetEntry(), NORMAL),
351 entry_style->text[GTK_STATE_NORMAL], 333 0x80);
352 entry_style->base[GTK_STATE_NORMAL], 0x80); 334 case kColorId_ResultsTableSelectedDimmedText:
353 } 335 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetEntry(), SELECTED),
354 case kColorId_ResultsTableSelectedDimmedText: { 336 GET_BASE_COLOR(GetEntry(), NORMAL),
355 GtkStyle* entry_style = GetEntryStyle(); 337 0x80);
356 return GdkAlphaBlend(
357 entry_style->text[GTK_STATE_SELECTED],
358 entry_style->base[GTK_STATE_NORMAL], 0x80);
359 }
360 case kColorId_ResultsTableNormalUrl: 338 case kColorId_ResultsTableNormalUrl:
361 case kColorId_ResultsTableHoveredUrl: { 339 case kColorId_ResultsTableHoveredUrl:
362 return NormalURLColor(GetEntryStyle()->text[GTK_STATE_NORMAL]); 340 return NormalURLColor(GET_TEXT_COLOR(GetEntry(), NORMAL));
363 } 341
364 case kColorId_ResultsTableSelectedUrl: { 342 case kColorId_ResultsTableSelectedUrl:
365 GtkStyle* entry_style = GetEntryStyle(); 343 return SelectedURLColor(GET_TEXT_COLOR(GetEntry(), SELECTED),
366 return SelectedURLColor(entry_style->text[GTK_STATE_SELECTED], 344 GET_BASE_COLOR(GetEntry(), SELECTED));
367 entry_style->base[GTK_STATE_SELECTED]); 345 case kColorId_ResultsTableNormalDivider:
368 } 346 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetWindow(), NORMAL),
369 case kColorId_ResultsTableNormalDivider: { 347 GET_BG_COLOR(GetWindow(), NORMAL),
370 GtkStyle* win_style = GetWindowStyle(); 348 0x34);
371 return GdkAlphaBlend(win_style->text[GTK_STATE_NORMAL], 349 case kColorId_ResultsTableHoveredDivider:
372 win_style->bg[GTK_STATE_NORMAL], 0x34); 350 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetWindow(), PRELIGHT),
373 } 351 GET_BG_COLOR(GetWindow(), PRELIGHT),
374 case kColorId_ResultsTableHoveredDivider: { 352 0x34);
375 GtkStyle* win_style = GetWindowStyle(); 353 case kColorId_ResultsTableSelectedDivider:
376 return GdkAlphaBlend(win_style->text[GTK_STATE_PRELIGHT], 354 return color_utils::AlphaBlend(GET_TEXT_COLOR(GetWindow(), SELECTED),
377 win_style->bg[GTK_STATE_PRELIGHT], 0x34); 355 GET_BG_COLOR(GetWindow(), SELECTED),
378 } 356 0x34);
379 case kColorId_ResultsTableSelectedDivider: { 357
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: { 358 case kColorId_ResultsTablePositiveText: {
385 return GetReadableColor(kPositiveTextColor, 359 return color_utils::GetReadableColor(kPositiveTextColor,
386 GetEntryStyle()->base[GTK_STATE_NORMAL]); 360 GET_BASE_COLOR(GetEntry(), NORMAL));
387 } 361 }
388 case kColorId_ResultsTablePositiveHoveredText: { 362 case kColorId_ResultsTablePositiveHoveredText: {
389 return GetReadableColor(kPositiveTextColor, 363 return color_utils::GetReadableColor(kPositiveTextColor,
390 GetEntryStyle()->base[GTK_STATE_PRELIGHT]); 364 GET_BASE_COLOR(GetEntry(), PRELIGHT)) ;
391 } 365 }
392 case kColorId_ResultsTablePositiveSelectedText: { 366 case kColorId_ResultsTablePositiveSelectedText: {
393 return GetReadableColor(kPositiveTextColor, 367 return color_utils::GetReadableColor(kPositiveTextColor,
394 GetEntryStyle()->base[GTK_STATE_SELECTED]); 368 GET_BASE_COLOR(GetEntry(), SELECTED)) ;
395 } 369 }
396 case kColorId_ResultsTableNegativeText: { 370 case kColorId_ResultsTableNegativeText: {
397 return GetReadableColor(kNegativeTextColor, 371 return color_utils::GetReadableColor(kNegativeTextColor,
398 GetEntryStyle()->base[GTK_STATE_NORMAL]); 372 GET_BASE_COLOR(GetEntry(), NORMAL));
399 } 373 }
400 case kColorId_ResultsTableNegativeHoveredText: { 374 case kColorId_ResultsTableNegativeHoveredText: {
401 return GetReadableColor(kNegativeTextColor, 375 return color_utils::GetReadableColor(kNegativeTextColor,
402 GetEntryStyle()->base[GTK_STATE_PRELIGHT]); 376 GET_BASE_COLOR(GetEntry(), PRELIGHT)) ;
403 } 377 }
404 case kColorId_ResultsTableNegativeSelectedText: { 378 case kColorId_ResultsTableNegativeSelectedText: {
405 return GetReadableColor(kNegativeTextColor, 379 return color_utils::GetReadableColor(kNegativeTextColor,
406 GetEntryStyle()->base[GTK_STATE_SELECTED]); 380 GET_BASE_COLOR(GetEntry(), SELECTED)) ;
407 } 381 }
408 382
409 // Throbber 383 // Throbber
410 case kColorId_ThrobberSpinningColor: 384 case kColorId_ThrobberSpinningColor:
411 case kColorId_ThrobberLightColor: { 385 case kColorId_ThrobberLightColor: {
412 return GetEntryStyle()->bg[GTK_STATE_SELECTED]; 386 return GET_BG_COLOR(GetEntry(), SELECTED);
413 } 387 }
414 388
415 case kColorId_ThrobberWaitingColor: { 389 case kColorId_ThrobberWaitingColor: {
416 return GdkAlphaBlend(GetEntryStyle()->bg[GTK_STATE_SELECTED], 390 return color_utils::AlphaBlend(GET_BG_COLOR(GetEntry(), SELECTED),
417 GetWindowStyle()->bg[GTK_STATE_NORMAL], 0xff / 2); 391 GET_BG_COLOR(GetWindow(), NORMAL),
392 0x80);
418 } 393 }
419 394
420 case kColorId_ChromeIconGrey: 395 case kColorId_ChromeIconGrey:
421 case kColorId_GoogleBlue: 396 case kColorId_GoogleBlue:
422 case kColorId_NumColors: 397 case kColorId_NumColors:
423 NOTREACHED(); 398 NOTREACHED();
424 break; 399 break;
425 } 400 }
426 401
427 return SkColorToGdkColor(kInvalidColorIdColor); 402 return kInvalidColorIdColor;
428 } 403 }
429 404
430 GtkWidget* NativeThemeGtk2::GetRealizedWindow() const { 405 GtkWidget* NativeThemeGtk2::GetWindow() const {
431 if (!fake_window_) { 406 if (!fake_window_.get()) {
432 fake_window_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); 407 fake_window_.Own(chrome_gtk_frame_new());
433 gtk_widget_realize(fake_window_); 408 gtk_widget_realize(fake_window_.get());
434 } 409 }
435 410
436 return fake_window_; 411 return fake_window_.get();
437 } 412 }
438 413
439 GtkStyle* NativeThemeGtk2::GetWindowStyle() const { 414 GtkWidget* NativeThemeGtk2::GetEntry() const {
440 return gtk_rc_get_style(GetRealizedWindow());
441 }
442
443 GtkStyle* NativeThemeGtk2::GetEntryStyle() const {
444 if (!fake_entry_.get()) { 415 if (!fake_entry_.get()) {
445 fake_entry_.Own(gtk_entry_new()); 416 fake_entry_.Own(gtk_entry_new());
446 417
447 // The fake entry needs to be in the window so it can be realized so we can 418 // 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. 419 // use the computed parts of the style.
449 gtk_container_add(GTK_CONTAINER(GetRealizedWindow()), fake_entry_.get()); 420 gtk_container_add(GTK_CONTAINER(GetWindow()), fake_entry_.get());
450 gtk_widget_realize(fake_entry_.get()); 421 gtk_widget_realize(fake_entry_.get());
451 } 422 }
452 return gtk_rc_get_style(fake_entry_.get()); 423
424 return fake_entry_.get();
453 } 425 }
454 426
455 GtkStyle* NativeThemeGtk2::GetLabelStyle() const { 427 GtkWidget* NativeThemeGtk2::GetLabel() const {
456 if (!fake_label_.get()) 428 if (!fake_label_.get())
457 fake_label_.Own(gtk_label_new("")); 429 fake_label_.Own(gtk_label_new(""));
458 430
459 return gtk_rc_get_style(fake_label_.get()); 431 return fake_label_.get();
460 } 432 }
461 433
462 GtkStyle* NativeThemeGtk2::GetButtonStyle() const { 434 GtkWidget* NativeThemeGtk2::GetButton() const {
463 if (!fake_button_.get()) 435 if (!fake_button_.get())
464 fake_button_.Own(gtk_button_new()); 436 fake_button_.Own(gtk_button_new());
465 437
466 return gtk_rc_get_style(fake_button_.get()); 438 return fake_button_.get();
467 } 439 }
468 440
469 GtkStyle* NativeThemeGtk2::GetTreeStyle() const { 441 GtkWidget* NativeThemeGtk2::GetTree() const {
470 if (!fake_tree_.get()) 442 if (!fake_tree_.get())
471 fake_tree_.Own(gtk_tree_view_new()); 443 fake_tree_.Own(gtk_tree_view_new());
472 444
473 return gtk_rc_get_style(fake_tree_.get()); 445 return fake_tree_.get();
474 } 446 }
475 447
476 GtkStyle* NativeThemeGtk2::GetTooltipStyle() const { 448 GtkWidget* NativeThemeGtk2::GetTooltip() const {
477 if (!fake_tooltip_) { 449 if (!fake_tooltip_.get()) {
478 fake_tooltip_ = gtk_window_new(GTK_WINDOW_TOPLEVEL); 450 fake_tooltip_.Own(gtk_window_new(GTK_WINDOW_TOPLEVEL));
479 gtk_widget_set_name(fake_tooltip_, "gtk-tooltip"); 451 gtk_widget_set_name(fake_tooltip_.get(), "gtk-tooltip");
480 gtk_widget_realize(fake_tooltip_); 452 gtk_widget_realize(fake_tooltip_.get());
481 } 453 }
482 return gtk_rc_get_style(fake_tooltip_); 454
455 return fake_tooltip_.get();
483 } 456 }
484 457
485 GtkStyle* NativeThemeGtk2::GetMenuStyle() const { 458 GtkWidget* NativeThemeGtk2::GetMenu() const {
486 if (!fake_menu_.get()) 459 if (!fake_menu_.get())
487 fake_menu_.Own(gtk_custom_menu_new()); 460 fake_menu_.Own(gtk_custom_menu_new());
488 return gtk_rc_get_style(fake_menu_.get()); 461
462 return fake_menu_.get();
489 } 463 }
490 464
491 GtkStyle* NativeThemeGtk2::GetMenuItemStyle() const { 465 GtkWidget* NativeThemeGtk2::GetMenuItem() const {
492 if (!fake_menu_item_) { 466 if (!fake_menu_item_.get()) {
493 if (!fake_menu_.get()) 467 fake_menu_item_.Own(gtk_custom_menu_item_new());
494 fake_menu_.Own(gtk_custom_menu_new()); 468 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 } 469 }
499 470
500 return gtk_rc_get_style(fake_menu_item_); 471 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 } 472 }
540 473
541 } // namespace libgtk2ui 474 } // namespace libgtk2ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698