Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / ui / libgtk2ui / gtk2_ui.h
blob6c88fbcb5b11687d1d402378c2067bb6dc0f5f38
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_LIBGTK2UI_GTK2_UI_H_
6 #define CHROME_BROWSER_UI_LIBGTK2UI_GTK2_UI_H_
8 #include <map>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/compiler_specific.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/observer_list.h"
15 #include "chrome/browser/ui/libgtk2ui/gtk2_signal.h"
16 #include "chrome/browser/ui/libgtk2ui/gtk2_signal_registrar.h"
17 #include "chrome/browser/ui/libgtk2ui/libgtk2ui_export.h"
18 #include "chrome/browser/ui/libgtk2ui/owned_widget_gtk2.h"
19 #include "ui/events/linux/text_edit_key_bindings_delegate_auralinux.h"
20 #include "ui/gfx/color_utils.h"
21 #include "ui/views/linux_ui/linux_ui.h"
22 #include "ui/views/window/frame_buttons.h"
24 typedef struct _GtkBorder GtkBorder;
25 typedef struct _GtkStyle GtkStyle;
26 typedef struct _GtkWidget GtkWidget;
28 class SkBitmap;
30 namespace gfx {
31 class Image;
34 namespace libgtk2ui {
35 class Gtk2Border;
36 class Gtk2KeyBindingsHandler;
37 class Gtk2SignalRegistrar;
38 class GConfListener;
40 // Interface to GTK2 desktop features.
42 class Gtk2UI : public views::LinuxUI {
43 public:
44 Gtk2UI();
45 ~Gtk2UI() override;
47 typedef base::Callback<ui::NativeTheme*(aura::Window* window)>
48 NativeThemeGetter;
50 // Setters used by GConfListener:
51 void SetWindowButtonOrdering(
52 const std::vector<views::FrameButton>& leading_buttons,
53 const std::vector<views::FrameButton>& trailing_buttons);
54 void SetNonClientMiddleClickAction(NonClientMiddleClickAction action);
56 // Draws the GTK button border with the given properties onto a bitmap.
57 SkBitmap DrawGtkButtonBorder(const char* class_name,
58 ui::NativeTheme::State state,
59 int width,
60 int height) const;
62 // Called when gtk style changes
63 void ResetStyle();
65 // ui::LinuxInputMethodContextFactory:
66 scoped_ptr<ui::LinuxInputMethodContext> CreateInputMethodContext(
67 ui::LinuxInputMethodContextDelegate* delegate,
68 bool is_simple) const override;
70 // gfx::LinuxFontDelegate:
71 gfx::FontRenderParams GetDefaultFontRenderParams() const override;
72 void GetDefaultFontDescription(
73 std::string* family_out,
74 int* size_pixels_out,
75 int* style_out,
76 gfx::FontRenderParams* params_out) const override;
78 // ui::LinuxShellDialog:
79 ui::SelectFileDialog* CreateSelectFileDialog(
80 ui::SelectFileDialog::Listener* listener,
81 ui::SelectFilePolicy* policy) const override;
83 // ui::LinuxUI:
84 void Initialize() override;
85 gfx::Image GetThemeImageNamed(int id) const override;
86 bool GetColor(int id, SkColor* color) const override;
87 bool HasCustomImage(int id) const override;
88 SkColor GetFocusRingColor() const override;
89 SkColor GetThumbActiveColor() const override;
90 SkColor GetThumbInactiveColor() const override;
91 SkColor GetTrackColor() const override;
92 SkColor GetActiveSelectionBgColor() const override;
93 SkColor GetActiveSelectionFgColor() const override;
94 SkColor GetInactiveSelectionBgColor() const override;
95 SkColor GetInactiveSelectionFgColor() const override;
96 double GetCursorBlinkInterval() const override;
97 ui::NativeTheme* GetNativeTheme(aura::Window* window) const override;
98 void SetNativeThemeOverride(const NativeThemeGetter& callback) override;
99 bool GetDefaultUsesSystemTheme() const override;
100 void SetDownloadCount(int count) const override;
101 void SetProgressFraction(float percentage) const override;
102 bool IsStatusIconSupported() const override;
103 scoped_ptr<views::StatusIconLinux> CreateLinuxStatusIcon(
104 const gfx::ImageSkia& image,
105 const base::string16& tool_tip) const override;
106 gfx::Image GetIconForContentType(const std::string& content_type,
107 int size) const override;
108 scoped_ptr<views::Border> CreateNativeBorder(
109 views::LabelButton* owning_button,
110 scoped_ptr<views::LabelButtonBorder> border) override;
111 void AddWindowButtonOrderObserver(
112 views::WindowButtonOrderObserver* observer) override;
113 void RemoveWindowButtonOrderObserver(
114 views::WindowButtonOrderObserver* observer) override;
115 bool UnityIsRunning() override;
116 NonClientMiddleClickAction GetNonClientMiddleClickAction() override;
117 void NotifyWindowManagerStartupComplete() override;
119 // ui::TextEditKeybindingDelegate:
120 bool MatchEvent(const ui::Event& event,
121 std::vector<ui::TextEditCommandAuraLinux>* commands) override;
123 // ui::Views::LinuxUI:
124 void UpdateDeviceScaleFactor(float device_scale_factor) override;
125 float GetDeviceScaleFactor() const override;
127 private:
128 typedef std::map<int, SkColor> ColorMap;
129 typedef std::map<int, color_utils::HSL> TintMap;
130 typedef std::map<int, gfx::Image> ImageCache;
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
134 // thumb part and of the track colors.
135 void SetScrollbarColors();
137 // Extracts colors and tints from the GTK theme, both for the
138 // ThemeService interface and the colors we send to webkit.
139 void LoadGtkValues();
141 // Reads in explicit theme frame colors from the ChromeGtkFrame style class
142 // or generates them per our fallback algorithm.
143 SkColor BuildFrameColors();
145 // Sets the underlying theme tints.
146 void SetThemeTint(int id, SkColor color);
148 // Lazily generates each image used in the gtk theme.
149 gfx::Image GenerateGtkThemeImage(int id) const;
150 SkBitmap GenerateGtkThemeBitmap(int id) const;
152 // Creates a GTK+ version of IDR_THEME_FRAME. Instead of tinting, this
153 // creates a theme configurable gradient ending with |color_id| at the
154 // bottom, and |gradient_name| at the top if that color is specified in the
155 // theme.
156 SkBitmap GenerateFrameImage(int color_id,
157 const char* gradient_name) const;
159 // Takes the base frame image |base_id| and tints it with |tint_id|.
160 SkBitmap GenerateTabImage(int base_id) const;
162 // Tints an icon based on tint.
163 SkBitmap GenerateTintedIcon(int base_id,
164 const color_utils::HSL& tint) const;
166 // Renders a GTK button border the size of the image |sizing_idr| in
167 // |state|.
168 SkBitmap GenerateToolbarBezel(ui::NativeTheme::State state,
169 int sizing_idr) const;
171 // Returns the tint for buttons that contrasts with the normal window
172 // background color.
173 void GetNormalButtonTintHSL(color_utils::HSL* tint) const;
175 // Returns a tint that's the color of the current normal text in an entry.
176 void GetNormalEntryForegroundHSL(color_utils::HSL* tint) const;
178 // Returns a tint that's the color of the current highlighted text in an
179 // entry.
180 void GetSelectedEntryForegroundHSL(color_utils::HSL* tint) const;
182 // Gets a color for the background of the call to action button.
183 SkColor CallToActionBgColor(int gtk_state) const;
185 // Frees all calculated images and color data.
186 void ClearAllThemeData();
188 // Updates |default_font_*|.
189 void UpdateDefaultFont();
191 // Tints and colors calculated by LoadGtkValues() that are given to the
192 // caller while |use_gtk_| is true.
193 ColorMap colors_;
194 TintMap tints_;
196 // Colors used to tint certain icons.
197 color_utils::HSL button_tint_;
198 color_utils::HSL entry_tint_;
199 color_utils::HSL selected_entry_tint_;
201 // Colors that we pass to WebKit. These are generated each time the theme
202 // changes.
203 SkColor focus_ring_color_;
204 SkColor thumb_active_color_;
205 SkColor thumb_inactive_color_;
206 SkColor track_color_;
207 SkColor active_selection_bg_color_;
208 SkColor active_selection_fg_color_;
209 SkColor inactive_selection_bg_color_;
210 SkColor inactive_selection_fg_color_;
212 // Details about the default UI font.
213 std::string default_font_family_;
214 int default_font_size_pixels_;
215 int default_font_style_; // Bitfield of gfx::Font::Style values.
216 gfx::FontRenderParams default_font_render_params_;
218 #if defined(USE_GCONF)
219 // Currently, the only source of window button configuration. This will
220 // change if we ever have to support XFCE's configuration system or KDE's.
221 scoped_ptr<GConfListener> gconf_listener_;
222 #endif // defined(USE_GCONF)
224 // If either of these vectors are non-empty, they represent the current
225 // window button configuration.
226 std::vector<views::FrameButton> leading_buttons_;
227 std::vector<views::FrameButton> trailing_buttons_;
229 scoped_ptr<Gtk2KeyBindingsHandler> key_bindings_handler_;
231 // Objects to notify when the window frame button order changes.
232 base::ObserverList<views::WindowButtonOrderObserver> observer_list_;
234 // Whether we should lower the window on a middle click to the non client
235 // area.
236 NonClientMiddleClickAction middle_click_action_;
238 // Image cache of lazily created images.
239 mutable ImageCache gtk_images_;
241 // Used to override the native theme for a window. If no override is provided
242 // or the callback returns NULL, Gtk2UI will default to a NativeThemeGtk2
243 // instance.
244 NativeThemeGetter native_theme_overrider_;
246 float device_scale_factor_;
248 DISALLOW_COPY_AND_ASSIGN(Gtk2UI);
251 } // namespace libgtk2ui
253 // Access point to the GTK2 desktop system. This should be the only symbol that
254 // is exported in the library; everything else should be used through the
255 // interface, because eventually this .so will be loaded through dlopen at
256 // runtime so our main binary can conditionally load GTK2 or GTK3 or EFL or
257 // QT or whatever.
258 LIBGTK2UI_EXPORT views::LinuxUI* BuildGtk2UI();
260 #endif // CHROME_BROWSER_UI_LIBGTK2UI_GTK2_UI_H_