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_GTK2_UI_H_ | 5 #ifndef CHROME_BROWSER_UI_LIBGTK2UI_GTK2_UI_H_ |
6 #define CHROME_BROWSER_UI_LIBGTK2UI_GTK2_UI_H_ | 6 #define CHROME_BROWSER_UI_LIBGTK2UI_GTK2_UI_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/observer_list.h" | 14 #include "base/observer_list.h" |
15 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h" | 15 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h" |
16 #include "chrome/browser/ui/libgtk2ui/gtk2_signal_registrar.h" | 16 #include "chrome/browser/ui/libgtk2ui/gtk2_signal_registrar.h" |
17 #include "chrome/browser/ui/libgtk2ui/libgtk2ui_export.h" | 17 #include "chrome/browser/ui/libgtk2ui/libgtk2ui_export.h" |
18 #include "chrome/browser/ui/libgtk2ui/owned_widget_gtk2.h" | 18 #include "chrome/browser/ui/libgtk2ui/owned_widget_gtk2.h" |
19 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h" | 19 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h" |
20 #include "ui/gfx/color_utils.h" | 20 #include "ui/gfx/color_utils.h" |
21 #include "ui/views/linux_ui/linux_ui.h" | 21 #include "ui/views/linux_ui/linux_ui.h" |
22 #include "ui/views/window/frame_buttons.h" | 22 #include "ui/views/window/frame_buttons.h" |
23 | 23 |
24 typedef struct _GdkColor GdkColor; | |
25 typedef struct _GtkBorder GtkBorder; | 24 typedef struct _GtkBorder GtkBorder; |
26 typedef struct _GtkStyle GtkStyle; | 25 typedef struct _GtkStyle GtkStyle; |
27 typedef struct _GtkWidget GtkWidget; | 26 typedef struct _GtkWidget GtkWidget; |
28 typedef struct _PangoFontDescription PangoFontDescription; | |
29 | 27 |
30 class SkBitmap; | 28 class SkBitmap; |
31 | 29 |
32 namespace gfx { | 30 namespace gfx { |
33 class Image; | 31 class Image; |
34 } | 32 } |
35 | 33 |
36 namespace libgtk2ui { | 34 namespace libgtk2ui { |
37 class Gtk2Border; | 35 class Gtk2Border; |
38 class Gtk2KeyBindingsHandler; | 36 class Gtk2KeyBindingsHandler; |
39 class Gtk2SignalRegistrar; | 37 class Gtk2SignalRegistrar; |
40 class GConfListener; | 38 class GConfListener; |
41 | 39 |
42 // Interface to GTK2 desktop features. | 40 // Interface to GTK2 desktop features. |
43 // | 41 // |
44 class Gtk2UI : public views::LinuxUI { | 42 class Gtk2UI : public views::LinuxUI { |
45 public: | 43 public: |
46 Gtk2UI(); | 44 Gtk2UI(); |
47 ~Gtk2UI() override; | 45 ~Gtk2UI() override; |
48 | 46 |
49 typedef base::Callback<ui::NativeTheme*(aura::Window* window)> | 47 typedef base::Callback<ui::NativeTheme*(aura::Window* window)> |
50 NativeThemeGetter; | 48 NativeThemeGetter; |
51 | 49 |
52 // Setters used by GConfListener: | 50 // Setters used by GConfListener: |
53 void SetWindowButtonOrdering( | 51 void SetWindowButtonOrdering( |
54 const std::vector<views::FrameButton>& leading_buttons, | 52 const std::vector<views::FrameButton>& leading_buttons, |
55 const std::vector<views::FrameButton>& trailing_buttons); | 53 const std::vector<views::FrameButton>& trailing_buttons); |
56 void SetNonClientMiddleClickAction(NonClientMiddleClickAction action); | 54 void SetNonClientMiddleClickAction(NonClientMiddleClickAction action); |
57 | 55 |
58 // Draws the GTK button border for state |gtk_state| onto a bitmap. | 56 // Draws the GTK button border with the given properties onto a bitmap. |
59 SkBitmap DrawGtkButtonBorder(int gtk_state, | 57 SkBitmap DrawGtkButtonBorder(const char* class_name, |
60 bool focused, | 58 ui::NativeTheme::State state, |
61 bool call_to_action, | |
62 int width, | 59 int width, |
63 int height) const; | 60 int height) const; |
64 | 61 |
| 62 // Called when gtk style changes |
| 63 void ResetStyle(); |
| 64 |
65 // ui::LinuxInputMethodContextFactory: | 65 // ui::LinuxInputMethodContextFactory: |
66 scoped_ptr<ui::LinuxInputMethodContext> CreateInputMethodContext( | 66 scoped_ptr<ui::LinuxInputMethodContext> CreateInputMethodContext( |
67 ui::LinuxInputMethodContextDelegate* delegate, | 67 ui::LinuxInputMethodContextDelegate* delegate, |
68 bool is_simple) const override; | 68 bool is_simple) const override; |
69 | 69 |
70 // gfx::LinuxFontDelegate: | 70 // gfx::LinuxFontDelegate: |
71 gfx::FontRenderParams GetDefaultFontRenderParams() const override; | 71 gfx::FontRenderParams GetDefaultFontRenderParams() const override; |
72 void GetDefaultFontDescription( | 72 void GetDefaultFontDescription( |
73 std::string* family_out, | 73 std::string* family_out, |
74 int* size_pixels_out, | 74 int* size_pixels_out, |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 float GetDeviceScaleFactor() const override; | 125 float GetDeviceScaleFactor() const override; |
126 | 126 |
127 private: | 127 private: |
128 typedef std::map<int, SkColor> ColorMap; | 128 typedef std::map<int, SkColor> ColorMap; |
129 typedef std::map<int, color_utils::HSL> TintMap; | 129 typedef std::map<int, color_utils::HSL> TintMap; |
130 typedef std::map<int, gfx::Image> ImageCache; | 130 typedef std::map<int, gfx::Image> ImageCache; |
131 | 131 |
132 // This method returns the colors webkit will use for the scrollbars. When no | 132 // This method returns the colors webkit will use for the scrollbars. When no |
133 // colors are specified by the GTK+ theme, this function averages of the | 133 // colors are specified by the GTK+ theme, this function averages of the |
134 // thumb part and of the track colors. | 134 // thumb part and of the track colors. |
135 void GetScrollbarColors(GdkColor* thumb_active_color, | 135 void SetScrollbarColors(); |
136 GdkColor* thumb_inactive_color, | |
137 GdkColor* track_color); | |
138 | 136 |
139 // Extracts colors and tints from the GTK theme, both for the | 137 // Extracts colors and tints from the GTK theme, both for the |
140 // ThemeService interface and the colors we send to webkit. | 138 // ThemeService interface and the colors we send to webkit. |
141 void LoadGtkValues(); | 139 void LoadGtkValues(); |
142 | 140 |
143 // Reads in explicit theme frame colors from the ChromeGtkFrame style class | 141 // Reads in explicit theme frame colors from the ChromeGtkFrame style class |
144 // or generates them per our fallback algorithm. | 142 // or generates them per our fallback algorithm. |
145 GdkColor BuildFrameColors(GtkStyle* frame_style); | 143 SkColor BuildFrameColors(); |
146 | 144 |
147 // Sets the underlying theme colors/tints from a GTK color. | 145 // Sets the underlying theme tints. |
148 void SetThemeColorFromGtk(int id, const GdkColor* color); | 146 void SetThemeTint(int id, SkColor color); |
149 void SetThemeTintFromGtk(int id, const GdkColor* color); | |
150 | |
151 // Creates and returns a frame color, either using |gtk_base| verbatim if | |
152 // non-NULL, or tinting |base| with |tint|. Also sets |color_id| and | |
153 // |tint_id| to the returned color. | |
154 GdkColor BuildAndSetFrameColor(const GdkColor* base, | |
155 const GdkColor* gtk_base, | |
156 const color_utils::HSL& tint, | |
157 int color_id, | |
158 int tint_id); | |
159 | 147 |
160 // Lazily generates each bitmap used in the gtk theme. | 148 // Lazily generates each bitmap used in the gtk theme. |
161 SkBitmap GenerateGtkThemeBitmap(int id) const; | 149 SkBitmap GenerateGtkThemeBitmap(int id) const; |
162 | 150 |
163 // Creates a GTK+ version of IDR_THEME_FRAME. Instead of tinting, this | 151 // Creates a GTK+ version of IDR_THEME_FRAME. Instead of tinting, this |
164 // creates a theme configurable gradient ending with |color_id| at the | 152 // creates a theme configurable gradient ending with |color_id| at the |
165 // bottom, and |gradient_name| at the top if that color is specified in the | 153 // bottom, and |gradient_name| at the top if that color is specified in the |
166 // theme. | 154 // theme. |
167 SkBitmap GenerateFrameImage(int color_id, | 155 SkBitmap GenerateFrameImage(int color_id, |
168 const char* gradient_name) const; | 156 const char* gradient_name) const; |
169 | 157 |
170 // Takes the base frame image |base_id| and tints it with |tint_id|. | 158 // Takes the base frame image |base_id| and tints it with |tint_id|. |
171 SkBitmap GenerateTabImage(int base_id) const; | 159 SkBitmap GenerateTabImage(int base_id) const; |
172 | 160 |
173 // Tints an icon based on tint. | 161 // Tints an icon based on tint. |
174 SkBitmap GenerateTintedIcon(int base_id, | 162 SkBitmap GenerateTintedIcon(int base_id, |
175 const color_utils::HSL& tint) const; | 163 const color_utils::HSL& tint) const; |
176 | 164 |
177 // Renders a GTK icon as a SkBitmap, with prelight/active border if | 165 // Renders a GTK icon as a SkBitmap, with prelight/active border if |
178 // appropriate. | 166 // appropriate. |
179 SkBitmap GenerateGTKIcon(int base_id) const; | 167 SkBitmap GenerateGTKIcon(int base_id) const; |
180 | 168 |
181 // Renders a GTK button border the size of the image |sizing_idr| in | 169 // Renders a GTK button border the size of the image |sizing_idr| in |
182 // |gtk_state|. | 170 // |state|. |
183 SkBitmap GenerateToolbarBezel(int gtk_state, int sizing_idr) const; | 171 SkBitmap GenerateToolbarBezel(ui::NativeTheme::State state, |
| 172 int sizing_idr) const; |
184 | 173 |
185 // Returns the tint for buttons that contrasts with the normal window | 174 // Returns the tint for buttons that contrasts with the normal window |
186 // background color. | 175 // background color. |
187 void GetNormalButtonTintHSL(color_utils::HSL* tint) const; | 176 void GetNormalButtonTintHSL(color_utils::HSL* tint) const; |
188 | 177 |
189 // Returns a tint that's the color of the current normal text in an entry. | 178 // Returns a tint that's the color of the current normal text in an entry. |
190 void GetNormalEntryForegroundHSL(color_utils::HSL* tint) const; | 179 void GetNormalEntryForegroundHSL(color_utils::HSL* tint) const; |
191 | 180 |
192 // Returns a tint that's the color of the current highlighted text in an | 181 // Returns a tint that's the color of the current highlighted text in an |
193 // entry. | 182 // entry. |
194 void GetSelectedEntryForegroundHSL(color_utils::HSL* tint) const; | 183 void GetSelectedEntryForegroundHSL(color_utils::HSL* tint) const; |
195 | 184 |
196 // Gets a color for the background of the call to action button. | 185 // Gets a color for the background of the call to action button. |
197 SkColor CallToActionBgColor(int gtk_state) const; | 186 SkColor CallToActionBgColor(int gtk_state) const; |
198 | 187 |
199 // Frees all calculated images and color data. | 188 // Frees all calculated images and color data. |
200 void ClearAllThemeData(); | 189 void ClearAllThemeData(); |
201 | 190 |
202 // Updates |default_font_*| based on |desc|. | 191 // Updates |default_font_*|. |
203 void UpdateDefaultFont(const PangoFontDescription* desc); | 192 void UpdateDefaultFont(); |
204 | |
205 // Handles signal from GTK that our theme has been changed. | |
206 CHROMEGTK_CALLBACK_1(Gtk2UI, void, OnStyleSet, GtkStyle*); | |
207 | |
208 GtkWidget* fake_window_; | |
209 GtkWidget* fake_frame_; | |
210 OwnedWidgetGtk fake_label_; | |
211 OwnedWidgetGtk fake_entry_; | |
212 | |
213 // Tracks all the signals we have connected to on various widgets. | |
214 scoped_ptr<Gtk2SignalRegistrar> signals_; | |
215 | 193 |
216 // Tints and colors calculated by LoadGtkValues() that are given to the | 194 // Tints and colors calculated by LoadGtkValues() that are given to the |
217 // caller while |use_gtk_| is true. | 195 // caller while |use_gtk_| is true. |
218 ColorMap colors_; | 196 ColorMap colors_; |
219 TintMap tints_; | 197 TintMap tints_; |
220 | 198 |
221 // Colors used to tint certain icons. | 199 // Colors used to tint certain icons. |
222 color_utils::HSL button_tint_; | 200 color_utils::HSL button_tint_; |
223 color_utils::HSL entry_tint_; | 201 color_utils::HSL entry_tint_; |
224 color_utils::HSL selected_entry_tint_; | 202 color_utils::HSL selected_entry_tint_; |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 } // namespace libgtk2ui | 254 } // namespace libgtk2ui |
277 | 255 |
278 // Access point to the GTK2 desktop system. This should be the only symbol that | 256 // Access point to the GTK2 desktop system. This should be the only symbol that |
279 // is exported in the library; everything else should be used through the | 257 // is exported in the library; everything else should be used through the |
280 // interface, because eventually this .so will be loaded through dlopen at | 258 // interface, because eventually this .so will be loaded through dlopen at |
281 // runtime so our main binary can conditionally load GTK2 or GTK3 or EFL or | 259 // runtime so our main binary can conditionally load GTK2 or GTK3 or EFL or |
282 // QT or whatever. | 260 // QT or whatever. |
283 LIBGTK2UI_EXPORT views::LinuxUI* BuildGtk2UI(); | 261 LIBGTK2UI_EXPORT views::LinuxUI* BuildGtk2UI(); |
284 | 262 |
285 #endif // CHROME_BROWSER_UI_LIBGTK2UI_GTK2_UI_H_ | 263 #endif // CHROME_BROWSER_UI_LIBGTK2UI_GTK2_UI_H_ |
OLD | NEW |