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_menu_subclasses.h" | 9 #include "chrome/browser/ui/libgtk2ui/chrome_gtk_menu_subclasses.h" |
10 #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" | 10 #include "chrome/browser/ui/libgtk2ui/skia_utils_gtk2.h" |
11 #include "ui/gfx/color_utils.h" | 11 #include "ui/gfx/color_utils.h" |
12 #include "ui/gfx/path.h" | 12 #include "ui/gfx/path.h" |
13 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
14 #include "ui/gfx/size.h" | 14 #include "ui/gfx/size.h" |
15 #include "ui/gfx/skia_util.h" | 15 #include "ui/gfx/skia_util.h" |
16 #include "ui/native_theme/common_theme.h" | 16 #include "ui/native_theme/common_theme.h" |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 // Theme colors returned by GetSystemColor(). | 20 // Theme colors returned by GetSystemColor(). |
21 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); | 21 const SkColor kInvalidColorIdColor = SkColorSetRGB(255, 0, 128); |
22 // Tree | |
23 const SkColor kTreeBackground = SK_ColorWHITE; | |
24 const SkColor kTreeTextColor = SK_ColorBLACK; | |
25 const SkColor kTreeSelectedTextColor = SK_ColorBLACK; | |
26 const SkColor kTreeSelectionBackgroundColor = SkColorSetRGB(0xEE, 0xEE, 0xEE); | |
27 const SkColor kTreeArrowColor = SkColorSetRGB(0x7A, 0x7A, 0x7A); | |
28 // Table | |
29 const SkColor kTableBackground = SK_ColorWHITE; | |
30 const SkColor kTableTextColor = SK_ColorBLACK; | |
31 const SkColor kTableSelectedTextColor = SK_ColorBLACK; | |
32 const SkColor kTableSelectionBackgroundColor = SkColorSetRGB(0xEE, 0xEE, 0xEE); | |
33 const SkColor kTableGroupingIndicatorColor = SkColorSetRGB(0xCC, 0xCC, 0xCC); | |
34 | 22 |
35 } // namespace | 23 } // namespace |
36 | 24 |
37 | 25 |
38 namespace libgtk2ui { | 26 namespace libgtk2ui { |
39 | 27 |
40 // static | 28 // static |
41 NativeThemeGtk2* NativeThemeGtk2::instance() { | 29 NativeThemeGtk2* NativeThemeGtk2::instance() { |
42 CR_DEFINE_STATIC_LOCAL(NativeThemeGtk2, s_native_theme, ()); | 30 CR_DEFINE_STATIC_LOCAL(NativeThemeGtk2, s_native_theme, ()); |
43 return &s_native_theme; | 31 return &s_native_theme; |
44 } | 32 } |
45 | 33 |
46 NativeThemeGtk2::NativeThemeGtk2() | 34 NativeThemeGtk2::NativeThemeGtk2() |
47 : fake_window_(NULL), | 35 : fake_window_(NULL), |
48 fake_menu_item_(NULL) { | 36 fake_menu_item_(NULL) { |
49 } | 37 } |
50 | 38 |
51 NativeThemeGtk2::~NativeThemeGtk2() { | 39 NativeThemeGtk2::~NativeThemeGtk2() { |
52 if (fake_window_) | 40 if (fake_window_) |
53 gtk_widget_destroy(fake_window_); | 41 gtk_widget_destroy(fake_window_); |
54 fake_entry_.Destroy(); | 42 fake_entry_.Destroy(); |
55 fake_label_.Destroy(); | 43 fake_label_.Destroy(); |
56 fake_button_.Destroy(); | 44 fake_button_.Destroy(); |
| 45 fake_tree_.Destroy(); |
57 fake_menu_.Destroy(); | 46 fake_menu_.Destroy(); |
58 } | 47 } |
59 | 48 |
60 SkColor NativeThemeGtk2::GetSystemColor(ColorId color_id) const { | 49 SkColor NativeThemeGtk2::GetSystemColor(ColorId color_id) const { |
61 switch (color_id) { | |
62 // TODO(erg): Still need to fish the colors out of trees and tables. | |
63 | |
64 // Tree | |
65 case kColorId_TreeBackground: | |
66 return kTreeBackground; | |
67 case kColorId_TreeText: | |
68 return kTreeTextColor; | |
69 case kColorId_TreeSelectedText: | |
70 case kColorId_TreeSelectedTextUnfocused: | |
71 return kTreeSelectedTextColor; | |
72 case kColorId_TreeSelectionBackgroundFocused: | |
73 case kColorId_TreeSelectionBackgroundUnfocused: | |
74 return kTreeSelectionBackgroundColor; | |
75 case kColorId_TreeArrow: | |
76 return kTreeArrowColor; | |
77 | |
78 // Table | |
79 case kColorId_TableBackground: | |
80 return kTableBackground; | |
81 case kColorId_TableText: | |
82 return kTableTextColor; | |
83 case kColorId_TableSelectedText: | |
84 case kColorId_TableSelectedTextUnfocused: | |
85 return kTableSelectedTextColor; | |
86 case kColorId_TableSelectionBackgroundFocused: | |
87 case kColorId_TableSelectionBackgroundUnfocused: | |
88 return kTableSelectionBackgroundColor; | |
89 case kColorId_TableGroupingIndicatorColor: | |
90 return kTableGroupingIndicatorColor; | |
91 | |
92 default: | |
93 // Fall through. | |
94 break; | |
95 } | |
96 | |
97 return GdkColorToSkColor(GetSystemGdkColor(color_id)); | 50 return GdkColorToSkColor(GetSystemGdkColor(color_id)); |
98 } | 51 } |
99 | 52 |
100 void NativeThemeGtk2::PaintMenuPopupBackground( | 53 void NativeThemeGtk2::PaintMenuPopupBackground( |
101 SkCanvas* canvas, | 54 SkCanvas* canvas, |
102 const gfx::Size& size, | 55 const gfx::Size& size, |
103 const MenuBackgroundExtraParams& menu_background) const { | 56 const MenuBackgroundExtraParams& menu_background) const { |
104 if (menu_background.corner_radius > 0) { | 57 if (menu_background.corner_radius > 0) { |
105 SkPaint paint; | 58 SkPaint paint; |
106 paint.setStyle(SkPaint::kFill_Style); | 59 paint.setStyle(SkPaint::kFill_Style); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 return GetEntryStyle()->base[GTK_STATE_NORMAL]; | 166 return GetEntryStyle()->base[GTK_STATE_NORMAL]; |
214 case kColorId_TextfieldReadOnlyColor: | 167 case kColorId_TextfieldReadOnlyColor: |
215 return GetEntryStyle()->text[GTK_STATE_INSENSITIVE]; | 168 return GetEntryStyle()->text[GTK_STATE_INSENSITIVE]; |
216 case kColorId_TextfieldReadOnlyBackground: | 169 case kColorId_TextfieldReadOnlyBackground: |
217 return GetEntryStyle()->base[GTK_STATE_INSENSITIVE]; | 170 return GetEntryStyle()->base[GTK_STATE_INSENSITIVE]; |
218 case kColorId_TextfieldSelectionColor: | 171 case kColorId_TextfieldSelectionColor: |
219 return GetEntryStyle()->text[GTK_STATE_SELECTED]; | 172 return GetEntryStyle()->text[GTK_STATE_SELECTED]; |
220 case kColorId_TextfieldSelectionBackgroundFocused: | 173 case kColorId_TextfieldSelectionBackgroundFocused: |
221 return GetEntryStyle()->base[GTK_STATE_SELECTED]; | 174 return GetEntryStyle()->base[GTK_STATE_SELECTED]; |
222 | 175 |
223 // Tree | 176 // Trees and Tables (implemented on GTK using the same class) |
224 // Table | 177 case kColorId_TableBackground: |
| 178 case kColorId_TreeBackground: |
| 179 return GetTreeStyle()->bg[GTK_STATE_NORMAL]; |
| 180 case kColorId_TableText: |
| 181 case kColorId_TreeText: |
| 182 return GetTreeStyle()->text[GTK_STATE_NORMAL]; |
| 183 case kColorId_TableSelectedText: |
| 184 case kColorId_TableSelectedTextUnfocused: |
| 185 case kColorId_TreeSelectedText: |
| 186 case kColorId_TreeSelectedTextUnfocused: |
| 187 return GetTreeStyle()->text[GTK_STATE_SELECTED]; |
| 188 case kColorId_TableSelectionBackgroundFocused: |
| 189 case kColorId_TableSelectionBackgroundUnfocused: |
| 190 case kColorId_TreeSelectionBackgroundFocused: |
| 191 case kColorId_TreeSelectionBackgroundUnfocused: |
| 192 return GetTreeStyle()->bg[GTK_STATE_SELECTED]; |
| 193 case kColorId_TreeArrow: |
| 194 return GetTreeStyle()->fg[GTK_STATE_NORMAL]; |
| 195 case kColorId_TableGroupingIndicatorColor: |
| 196 return GetTreeStyle()->text_aa[GTK_STATE_NORMAL]; |
225 | 197 |
226 default: | 198 default: |
227 // Fall through | 199 // Fall through |
228 break; | 200 break; |
229 } | 201 } |
230 | 202 |
231 return SkColorToGdkColor(kInvalidColorIdColor); | 203 return SkColorToGdkColor(kInvalidColorIdColor); |
232 } | 204 } |
233 | 205 |
234 GtkWidget* NativeThemeGtk2::GetRealizedWindow() const { | 206 GtkWidget* NativeThemeGtk2::GetRealizedWindow() const { |
(...skipping 28 matching lines...) Expand all Loading... |
263 return gtk_rc_get_style(fake_label_.get()); | 235 return gtk_rc_get_style(fake_label_.get()); |
264 } | 236 } |
265 | 237 |
266 GtkStyle* NativeThemeGtk2::GetButtonStyle() const { | 238 GtkStyle* NativeThemeGtk2::GetButtonStyle() const { |
267 if (!fake_button_.get()) | 239 if (!fake_button_.get()) |
268 fake_button_.Own(gtk_button_new()); | 240 fake_button_.Own(gtk_button_new()); |
269 | 241 |
270 return gtk_rc_get_style(fake_button_.get()); | 242 return gtk_rc_get_style(fake_button_.get()); |
271 } | 243 } |
272 | 244 |
| 245 GtkStyle* NativeThemeGtk2::GetTreeStyle() const { |
| 246 if (!fake_tree_.get()) |
| 247 fake_tree_.Own(gtk_tree_view_new()); |
| 248 |
| 249 return gtk_rc_get_style(fake_tree_.get()); |
| 250 } |
| 251 |
273 GtkStyle* NativeThemeGtk2::GetMenuStyle() const { | 252 GtkStyle* NativeThemeGtk2::GetMenuStyle() const { |
274 if (!fake_menu_.get()) | 253 if (!fake_menu_.get()) |
275 fake_menu_.Own(gtk_menu_new()); | 254 fake_menu_.Own(gtk_menu_new()); |
276 return gtk_rc_get_style(fake_menu_.get()); | 255 return gtk_rc_get_style(fake_menu_.get()); |
277 } | 256 } |
278 | 257 |
279 GtkStyle* NativeThemeGtk2::GetMenuItemStyle() const { | 258 GtkStyle* NativeThemeGtk2::GetMenuItemStyle() const { |
280 if (!fake_menu_item_) { | 259 if (!fake_menu_item_) { |
281 if (!fake_menu_.get()) | 260 if (!fake_menu_.get()) |
282 fake_menu_.Own(gtk_custom_menu_new()); | 261 fake_menu_.Own(gtk_custom_menu_new()); |
283 | 262 |
284 fake_menu_item_ = gtk_custom_menu_item_new(); | 263 fake_menu_item_ = gtk_custom_menu_item_new(); |
285 gtk_menu_shell_append(GTK_MENU_SHELL(fake_menu_.get()), fake_menu_item_); | 264 gtk_menu_shell_append(GTK_MENU_SHELL(fake_menu_.get()), fake_menu_item_); |
286 } | 265 } |
287 | 266 |
288 return gtk_rc_get_style(fake_menu_item_); | 267 return gtk_rc_get_style(fake_menu_item_); |
289 } | 268 } |
290 | 269 |
291 } // namespace libgtk2ui | 270 } // namespace libgtk2ui |
OLD | NEW |