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

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

Powered by Google App Engine
This is Rietveld 408576698