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 #ifndef CHROME_BROWSER_UI_LIBGTK2UI_NATIVE_THEME_GTK2_H_ | 5 #ifndef CHROME_BROWSER_UI_LIBGTK2UI_NATIVE_THEME_GTK2_H_ |
6 #define CHROME_BROWSER_UI_LIBGTK2UI_NATIVE_THEME_GTK2_H_ | 6 #define CHROME_BROWSER_UI_LIBGTK2UI_NATIVE_THEME_GTK2_H_ |
7 | 7 |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include "chrome/browser/ui/libgtk2ui/owned_widget_gtk2.h" | 10 #include "chrome/browser/ui/libgtk2ui/owned_widget_gtk2.h" |
11 #include "ui/native_theme/native_theme_base.h" | 11 #include "ui/native_theme/native_theme_base.h" |
12 | 12 |
13 typedef struct _GdkColor GdkColor; | 13 |
| 14 |
| 15 //if GTK_MAJOR_VERSION == 2 |
| 16 #if 1 |
| 17 |
| 18 #define GET_FG_COLOR(gtkwidget, gtkstate) \ |
| 19 GdkColorToSkColor(gtk_rc_get_style(gtkwidget)->fg[GTK_STATE_ ## gtkstate]) |
| 20 |
| 21 #define GET_BG_COLOR(gtkwidget, gtkstate) \ |
| 22 GdkColorToSkColor(gtk_rc_get_style(gtkwidget)->bg[GTK_STATE_ ## gtkstate]) |
| 23 |
| 24 #define GET_TEXT_COLOR(gtkwidget, gtkstate) \ |
| 25 GdkColorToSkColor(gtk_rc_get_style(gtkwidget)->text[GTK_STATE_ ## gtkstate]) |
| 26 |
| 27 #define GET_TEXT_AA_COLOR(gtkwidget, gtkstate) \ |
| 28 GdkColorToSkColor(gtk_rc_get_style(gtkwidget)->text_aa[GTK_STATE_ ## gtkstate]
) |
| 29 |
| 30 #define GET_BASE_COLOR(gtkwidget, gtkstate) \ |
| 31 GdkColorToSkColor(gtk_rc_get_style(gtkwidget)->base[GTK_STATE_ ## gtkstate]) |
| 32 |
| 33 #else |
| 34 |
| 35 inline SkColor FgColorToSkColor(GtkWidget* widget, GtkStateFlags flags) { |
| 36 GdkRGBA color; |
| 37 gtk_style_context_get_color( |
| 38 gtk_widget_get_style_context(widget), flags, &color); |
| 39 return SkColorSetRGB(color.red * 255, color.green * 255, color.blue * 255); |
| 40 } |
| 41 inline SkColor BgColorToSkColor(GtkWidget* widget, GtkStateFlags flags) { |
| 42 GdkRGBA color; |
| 43 gtk_style_context_get_background_color( |
| 44 gtk_widget_get_style_context(widget), flags, &color); |
| 45 |
| 46 //Hack for default color |
| 47 if (color.alpha == 0.0) |
| 48 color = {1, 1, 1, 1}; |
| 49 |
| 50 return SkColorSetRGB(color.red * 255, color.green * 255, color.blue * 255); |
| 51 } |
| 52 |
| 53 |
| 54 #define GET_FG_COLOR(gtkwidget, gtkstate) \ |
| 55 FgColorToSkColor(gtkwidget, GTK_STATE_FLAG_ ## gtkstate) |
| 56 |
| 57 #define GET_BG_COLOR(gtkwidget, gtkstate) \ |
| 58 BgColorToSkColor(gtkwidget, GTK_STATE_FLAG_ ## gtkstate) |
| 59 |
| 60 |
| 61 |
| 62 #define GET_TEXT_COLOR GET_FG_COLOR |
| 63 #define GET_TEXT_AA_COLOR GET_FG_COLOR |
| 64 #define GET_BASE_COLOR GET_BG_COLOR |
| 65 |
| 66 #endif |
| 67 |
| 68 |
14 | 69 |
15 namespace libgtk2ui { | 70 namespace libgtk2ui { |
16 | 71 |
17 // A version of NativeTheme that uses GTK2 supplied colours instead of the | 72 // A version of NativeTheme that uses GTK2 supplied colours instead of the |
18 // default aura colours. Analogue to NativeThemeWin, except that can't be | 73 // default aura colours. Analogue to NativeThemeWin, except that can't be |
19 // compiled into the main chrome binary like the Windows code can. | 74 // compiled into the main chrome binary like the Windows code can. |
20 class NativeThemeGtk2 : public ui::NativeThemeBase { | 75 class NativeThemeGtk2 : public ui::NativeThemeBase { |
21 public: | 76 public: |
22 static NativeThemeGtk2* instance(); | 77 static NativeThemeGtk2* instance(); |
23 | 78 |
(...skipping 10 matching lines...) Expand all Loading... |
34 void PaintMenuPopupBackground( | 89 void PaintMenuPopupBackground( |
35 SkCanvas* canvas, | 90 SkCanvas* canvas, |
36 const gfx::Size& size, | 91 const gfx::Size& size, |
37 const MenuBackgroundExtraParams& menu_background) const override; | 92 const MenuBackgroundExtraParams& menu_background) const override; |
38 void PaintMenuItemBackground( | 93 void PaintMenuItemBackground( |
39 SkCanvas* canvas, | 94 SkCanvas* canvas, |
40 State state, | 95 State state, |
41 const gfx::Rect& rect, | 96 const gfx::Rect& rect, |
42 const MenuListExtraParams& menu_list) const override; | 97 const MenuListExtraParams& menu_list) const override; |
43 | 98 |
| 99 // Returns various widgets for theming use. |
| 100 GtkWidget* GetWindow() const; |
| 101 GtkWidget* GetEntry() const; |
| 102 GtkWidget* GetLabel() const; |
| 103 GtkWidget* GetButton() const; |
| 104 GtkWidget* GetTree() const; |
| 105 GtkWidget* GetTooltip() const; |
| 106 GtkWidget* GetMenu() const; |
| 107 GtkWidget* GetMenuItem() const; |
| 108 |
44 private: | 109 private: |
45 NativeThemeGtk2(); | 110 NativeThemeGtk2(); |
46 ~NativeThemeGtk2() override; | 111 ~NativeThemeGtk2() override; |
47 | 112 |
48 // Implementation of GetSystemColor. | |
49 GdkColor GetSystemGdkColor(ColorId color_id) const; | |
50 | |
51 // Returns styles associated with various widget types. | |
52 GtkWidget* GetRealizedWindow() const; | |
53 GtkStyle* GetWindowStyle() const; | |
54 GtkStyle* GetEntryStyle() const; | |
55 GtkStyle* GetLabelStyle() const; | |
56 GtkStyle* GetButtonStyle() const; | |
57 GtkStyle* GetTreeStyle() const; | |
58 GtkStyle* GetTooltipStyle() const; | |
59 GtkStyle* GetMenuStyle() const; | |
60 GtkStyle* GetMenuItemStyle() const; | |
61 | |
62 void PaintComboboxArrow(SkCanvas* canvas, | 113 void PaintComboboxArrow(SkCanvas* canvas, |
63 GtkStateType state, | 114 State state, |
64 const gfx::Rect& rect) const; | 115 const gfx::Rect& rect) const; |
65 | 116 |
66 mutable GtkWidget* fake_window_; | 117 mutable OwnedWidgetGtk fake_window_; |
67 mutable GtkWidget* fake_tooltip_; | |
68 mutable OwnedWidgetGtk fake_entry_; | 118 mutable OwnedWidgetGtk fake_entry_; |
69 mutable OwnedWidgetGtk fake_label_; | 119 mutable OwnedWidgetGtk fake_label_; |
70 mutable OwnedWidgetGtk fake_button_; | 120 mutable OwnedWidgetGtk fake_button_; |
71 mutable OwnedWidgetGtk fake_tree_; | 121 mutable OwnedWidgetGtk fake_tree_; |
72 | 122 mutable OwnedWidgetGtk fake_tooltip_; |
73 mutable OwnedWidgetGtk fake_menu_; | 123 mutable OwnedWidgetGtk fake_menu_; |
74 mutable GtkWidget* fake_menu_item_; | 124 mutable OwnedWidgetGtk fake_menu_item_; |
75 | 125 |
76 DISALLOW_COPY_AND_ASSIGN(NativeThemeGtk2); | 126 DISALLOW_COPY_AND_ASSIGN(NativeThemeGtk2); |
77 }; | 127 }; |
78 | 128 |
79 } // namespace libgtk2ui | 129 } // namespace libgtk2ui |
80 | 130 |
81 #endif // CHROME_BROWSER_UI_LIBGTK2UI_NATIVE_THEME_GTK2_H_ | 131 #endif // CHROME_BROWSER_UI_LIBGTK2UI_NATIVE_THEME_GTK2_H_ |
OLD | NEW |