Infobar material design refresh: layout
[chromium-blink-merge.git] / chrome / browser / ui / libgtk2ui / gtk2_ui.h
blob5497591a7c5a42c6af2a58cf9889c0abe417168f
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 _GdkColor GdkColor;
25 typedef struct _GtkBorder GtkBorder;
26 typedef struct _GtkStyle GtkStyle;
27 typedef struct _GtkWidget GtkWidget;
28 typedef struct _PangoFontDescription PangoFontDescription;
30 class SkBitmap;
32 namespace gfx {
33 class Image;
36 namespace libgtk2ui {
37 class Gtk2Border;
38 class Gtk2KeyBindingsHandler;
39 class Gtk2SignalRegistrar;
40 class GConfListener;
42 // Interface to GTK2 desktop features.
44 class Gtk2UI : public views::LinuxUI {
45 public:
46 Gtk2UI();
47 ~Gtk2UI() override;
49 typedef base::Callback<ui::NativeTheme*(aura::Window* window)>
50 NativeThemeGetter;
52 // Setters used by GConfListener:
53 void SetWindowButtonOrdering(
54 const std::vector<views::FrameButton>& leading_buttons,
55 const std::vector<views::FrameButton>& trailing_buttons);
56 void SetNonClientMiddleClickAction(NonClientMiddleClickAction action);
58 // Draws the GTK button border for state |gtk_state| onto a bitmap.
59 SkBitmap DrawGtkButtonBorder(int gtk_state,
60 bool focused,
61 bool call_to_action,
62 int width,
63 int height) const;
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 GetScrollbarColors(GdkColor* thumb_active_color,
136 GdkColor* thumb_inactive_color,
137 GdkColor* track_color);
139 // Extracts colors and tints from the GTK theme, both for the
140 // ThemeService interface and the colors we send to webkit.
141 void LoadGtkValues();
143 // Reads in explicit theme frame colors from the ChromeGtkFrame style class
144 // or generates them per our fallback algorithm.
145 GdkColor BuildFrameColors(GtkStyle* frame_style);
147 // Sets the underlying theme colors/tints from a GTK color.
148 void SetThemeColorFromGtk(int id, const GdkColor* color);
149 void SetThemeTintFromGtk(int id, const GdkColor* color);
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);
160 // Lazily generates each bitmap used in the gtk theme.
161 SkBitmap GenerateGtkThemeBitmap(int id) const;
163 // Creates a GTK+ version of IDR_THEME_FRAME. Instead of tinting, this
164 // 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
166 // theme.
167 SkBitmap GenerateFrameImage(int color_id,
168 const char* gradient_name) const;
170 // Takes the base frame image |base_id| and tints it with |tint_id|.
171 SkBitmap GenerateTabImage(int base_id) const;
173 // Tints an icon based on tint.
174 SkBitmap GenerateTintedIcon(int base_id,
175 const color_utils::HSL& tint) const;
177 // Renders a GTK icon as a SkBitmap, with prelight/active border if
178 // appropriate.
179 SkBitmap GenerateGTKIcon(int base_id) const;
181 // Renders a GTK button border the size of the image |sizing_idr| in
182 // |gtk_state|.
183 SkBitmap GenerateToolbarBezel(int gtk_state, int sizing_idr) const;
185 // Returns the tint for buttons that contrasts with the normal window
186 // background color.
187 void GetNormalButtonTintHSL(color_utils::HSL* tint) const;
189 // Returns a tint that's the color of the current normal text in an entry.
190 void GetNormalEntryForegroundHSL(color_utils::HSL* tint) const;
192 // Returns a tint that's the color of the current highlighted text in an
193 // entry.
194 void GetSelectedEntryForegroundHSL(color_utils::HSL* tint) const;
196 // Gets a color for the background of the call to action button.
197 SkColor CallToActionBgColor(int gtk_state) const;
199 // Frees all calculated images and color data.
200 void ClearAllThemeData();
202 // Updates |default_font_*| based on |desc|.
203 void UpdateDefaultFont(const PangoFontDescription* desc);
205 // Handles signal from GTK that our theme has been changed.
206 CHROMEGTK_CALLBACK_1(Gtk2UI, void, OnStyleSet, GtkStyle*);
208 GtkWidget* fake_window_;
209 GtkWidget* fake_frame_;
210 OwnedWidgetGtk fake_label_;
211 OwnedWidgetGtk fake_entry_;
213 // Tracks all the signals we have connected to on various widgets.
214 scoped_ptr<Gtk2SignalRegistrar> signals_;
216 // Tints and colors calculated by LoadGtkValues() that are given to the
217 // caller while |use_gtk_| is true.
218 ColorMap colors_;
219 TintMap tints_;
221 // Colors used to tint certain icons.
222 color_utils::HSL button_tint_;
223 color_utils::HSL entry_tint_;
224 color_utils::HSL selected_entry_tint_;
226 // Colors that we pass to WebKit. These are generated each time the theme
227 // changes.
228 SkColor focus_ring_color_;
229 SkColor thumb_active_color_;
230 SkColor thumb_inactive_color_;
231 SkColor track_color_;
232 SkColor active_selection_bg_color_;
233 SkColor active_selection_fg_color_;
234 SkColor inactive_selection_bg_color_;
235 SkColor inactive_selection_fg_color_;
237 // Details about the default UI font.
238 std::string default_font_family_;
239 int default_font_size_pixels_;
240 int default_font_style_; // Bitfield of gfx::Font::Style values.
241 gfx::FontRenderParams default_font_render_params_;
243 #if defined(USE_GCONF)
244 // Currently, the only source of window button configuration. This will
245 // change if we ever have to support XFCE's configuration system or KDE's.
246 scoped_ptr<GConfListener> gconf_listener_;
247 #endif // defined(USE_GCONF)
249 // If either of these vectors are non-empty, they represent the current
250 // window button configuration.
251 std::vector<views::FrameButton> leading_buttons_;
252 std::vector<views::FrameButton> trailing_buttons_;
254 scoped_ptr<Gtk2KeyBindingsHandler> key_bindings_handler_;
256 // Objects to notify when the window frame button order changes.
257 base::ObserverList<views::WindowButtonOrderObserver> observer_list_;
259 // Whether we should lower the window on a middle click to the non client
260 // area.
261 NonClientMiddleClickAction middle_click_action_;
263 // Image cache of lazily created images.
264 mutable ImageCache gtk_images_;
266 // Used to override the native theme for a window. If no override is provided
267 // or the callback returns NULL, Gtk2UI will default to a NativeThemeGtk2
268 // instance.
269 NativeThemeGetter native_theme_overrider_;
271 float device_scale_factor_;
273 DISALLOW_COPY_AND_ASSIGN(Gtk2UI);
276 } // namespace libgtk2ui
278 // 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
280 // 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
282 // QT or whatever.
283 LIBGTK2UI_EXPORT views::LinuxUI* BuildGtk2UI();
285 #endif // CHROME_BROWSER_UI_LIBGTK2UI_GTK2_UI_H_