1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_LIBGTK2UI_GTK2_UI_H_
#define CHROME_BROWSER_UI_LIBGTK2UI_GTK2_UI_H_
#include <map>
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/observer_list.h"
#include "chrome/browser/ui/libgtk2ui/libgtk2ui_export.h"
#include "chrome/browser/ui/libgtk2ui/owned_widget_gtk2.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/views/linux_ui/linux_ui.h"
#include "ui/views/window/frame_buttons.h"
typedef struct _GdkColor GdkColor;
typedef struct _GtkBorder GtkBorder;
typedef struct _GtkStyle GtkStyle;
typedef struct _GtkWidget GtkWidget;
class SkBitmap;
namespace gfx {
class Image;
}
namespace libgtk2ui {
class Gtk2Border;
class GConfTitlebarListener;
// Interface to GTK2 desktop features.
//
class Gtk2UI : public views::LinuxUI {
public:
Gtk2UI();
virtual ~Gtk2UI();
void SetWindowButtonOrdering(
const std::vector<views::FrameButton>& leading_buttons,
const std::vector<views::FrameButton>& trailing_buttons);
// Draws the GTK button border for state |gtk_state| onto a bitmap.
SkBitmap DrawGtkButtonBorder(int gtk_state,
bool focused,
int width,
int height) const;
// Returns the current insets for a button.
gfx::Insets GetButtonInsets() const;
// We keep track of live Gtk2Border objects since we must alert them to theme
// changes.
void AddGtkBorder(Gtk2Border* border);
void RemoveGtkBorder(Gtk2Border* border);
// ui::LinuxInputMethodContextFactory:
virtual scoped_ptr<ui::LinuxInputMethodContext> CreateInputMethodContext(
ui::LinuxInputMethodContextDelegate* delegate) const OVERRIDE;
// gfx::LinuxFontDelegate:
virtual bool UseAntialiasing() const OVERRIDE;
virtual gfx::FontRenderParams::Hinting GetHintingStyle() const OVERRIDE;
virtual gfx::FontRenderParams::SubpixelRendering
GetSubpixelRenderingStyle() const OVERRIDE;
virtual std::string GetDefaultFontName() const OVERRIDE;
// ui::LinuxShellDialog:
virtual ui::SelectFileDialog* CreateSelectFileDialog(
ui::SelectFileDialog::Listener* listener,
ui::SelectFilePolicy* policy) const OVERRIDE;
// ui::LinuxUI:
virtual void Initialize() OVERRIDE;
virtual gfx::Image GetThemeImageNamed(int id) const OVERRIDE;
virtual bool GetColor(int id, SkColor* color) const OVERRIDE;
virtual bool HasCustomImage(int id) const OVERRIDE;
virtual SkColor GetFocusRingColor() const OVERRIDE;
virtual SkColor GetThumbActiveColor() const OVERRIDE;
virtual SkColor GetThumbInactiveColor() const OVERRIDE;
virtual SkColor GetTrackColor() const OVERRIDE;
virtual SkColor GetActiveSelectionBgColor() const OVERRIDE;
virtual SkColor GetActiveSelectionFgColor() const OVERRIDE;
virtual SkColor GetInactiveSelectionBgColor() const OVERRIDE;
virtual SkColor GetInactiveSelectionFgColor() const OVERRIDE;
virtual double GetCursorBlinkInterval() const OVERRIDE;
virtual ui::NativeTheme* GetNativeTheme() const OVERRIDE;
virtual void SetUseSystemTheme(bool use_system_theme) OVERRIDE;
virtual bool GetUseSystemTheme() const OVERRIDE;
virtual bool GetDefaultUsesSystemTheme() const OVERRIDE;
virtual void SetDownloadCount(int count) const OVERRIDE;
virtual void SetProgressFraction(float percentage) const OVERRIDE;
virtual bool IsStatusIconSupported() const OVERRIDE;
virtual scoped_ptr<views::StatusIconLinux> CreateLinuxStatusIcon(
const gfx::ImageSkia& image,
const base::string16& tool_tip) const OVERRIDE;
virtual gfx::Image GetIconForContentType(
const std::string& content_type, int size) const OVERRIDE;
virtual scoped_ptr<views::Border> CreateNativeBorder(
views::LabelButton* owning_button,
scoped_ptr<views::Border> border) OVERRIDE;
virtual void AddWindowButtonOrderObserver(
views::WindowButtonOrderObserver* observer) OVERRIDE;
virtual void RemoveWindowButtonOrderObserver(
views::WindowButtonOrderObserver* observer) OVERRIDE;
virtual bool UnityIsRunning() OVERRIDE;
private:
typedef std::map<int, SkColor> ColorMap;
typedef std::map<int, color_utils::HSL> TintMap;
typedef std::map<int, gfx::Image> ImageCache;
// This method returns the colors webkit will use for the scrollbars. When no
// colors are specified by the GTK+ theme, this function averages of the
// thumb part and of the track colors.
void GetScrollbarColors(GdkColor* thumb_active_color,
GdkColor* thumb_inactive_color,
GdkColor* track_color);
// Gets the name of the current icon theme and passes it to our low level XDG
// integration.
void SetXDGIconTheme();
// Extracts colors and tints from the GTK theme, both for the
// ThemeService interface and the colors we send to webkit.
void LoadGtkValues();
// Reads in explicit theme frame colors from the ChromeGtkFrame style class
// or generates them per our fallback algorithm.
GdkColor BuildFrameColors(GtkStyle* frame_style);
// Sets the underlying theme colors/tints from a GTK color.
void SetThemeColorFromGtk(int id, const GdkColor* color);
void SetThemeTintFromGtk(int id, const GdkColor* color);
// Creates and returns a frame color, either using |gtk_base| verbatim if
// non-NULL, or tinting |base| with |tint|. Also sets |color_id| and
// |tint_id| to the returned color.
GdkColor BuildAndSetFrameColor(const GdkColor* base,
const GdkColor* gtk_base,
const color_utils::HSL& tint,
int color_id,
int tint_id);
// Lazily generates each bitmap used in the gtk theme.
SkBitmap GenerateGtkThemeBitmap(int id) const;
// Creates a GTK+ version of IDR_THEME_FRAME. Instead of tinting, this
// creates a theme configurable gradient ending with |color_id| at the
// bottom, and |gradient_name| at the top if that color is specified in the
// theme.
SkBitmap GenerateFrameImage(int color_id,
const char* gradient_name) const;
// Takes the base frame image |base_id| and tints it with |tint_id|.
SkBitmap GenerateTabImage(int base_id) const;
// Tints an icon based on tint.
SkBitmap GenerateTintedIcon(int base_id,
const color_utils::HSL& tint) const;
// Renders a GTK icon as a SkBitmap, with prelight/active border if
// appropriate.
SkBitmap GenerateGTKIcon(int base_id) const;
// Renders a GTK button border the size of the image |sizing_idr| in
// |gtk_state|.
SkBitmap GenerateToolbarBezel(int gtk_state, int sizing_idr) const;
// Returns the tint for buttons that contrasts with the normal window
// background color.
void GetNormalButtonTintHSL(color_utils::HSL* tint) const;
// Returns a tint that's the color of the current normal text in an entry.
void GetNormalEntryForegroundHSL(color_utils::HSL* tint) const;
// Returns a tint that's the color of the current highlighted text in an
// entry.
void GetSelectedEntryForegroundHSL(color_utils::HSL* tint) const;
// Create a GTK window and button and queries what "default-border" is, which
// corresponds with our insets.
void UpdateButtonInsets();
// Frees all calculated images and color data.
void ClearAllThemeData();
GtkWidget* fake_window_;
GtkWidget* fake_frame_;
OwnedWidgetGtk fake_label_;
OwnedWidgetGtk fake_entry_;
// Tints and colors calculated by LoadGtkValues() that are given to the
// caller while |use_gtk_| is true.
ColorMap colors_;
TintMap tints_;
// Colors used to tint certain icons.
color_utils::HSL button_tint_;
color_utils::HSL entry_tint_;
color_utils::HSL selected_entry_tint_;
// Colors that we pass to WebKit. These are generated each time the theme
// changes.
SkColor focus_ring_color_;
SkColor thumb_active_color_;
SkColor thumb_inactive_color_;
SkColor track_color_;
SkColor active_selection_bg_color_;
SkColor active_selection_fg_color_;
SkColor inactive_selection_bg_color_;
SkColor inactive_selection_fg_color_;
gfx::Insets button_insets_;
#if defined(USE_GCONF)
// Currently, the only source of window button configuration. This will
// change if we ever have to support XFCE's configuration system or KDE's.
scoped_ptr<GConfTitlebarListener> titlebar_listener_;
#endif // defined(USE_GCONF)
// If either of these vectors are non-empty, they represent the current
// window button configuration.
std::vector<views::FrameButton> leading_buttons_;
std::vector<views::FrameButton> trailing_buttons_;
// Objects to notify when the window frame button order changes.
ObserverList<views::WindowButtonOrderObserver> observer_list_;
// Borders to notify when the theme state changes.
ObserverList<Gtk2Border> border_list_;
// Image cache of lazily created images.
mutable ImageCache gtk_images_;
// Whether to use the Gtk2 version of the native theme.
bool use_gtk_;
DISALLOW_COPY_AND_ASSIGN(Gtk2UI);
};
} // namespace libgtk2ui
// Access point to the GTK2 desktop system. This should be the only symbol that
// is exported in the library; everything else should be used through the
// interface, because eventually this .so will be loaded through dlopen at
// runtime so our main binary can conditionally load GTK2 or GTK3 or EFL or
// QT or whatever.
LIBGTK2UI_EXPORT views::LinuxUI* BuildGtk2UI();
#endif // CHROME_BROWSER_UI_LIBGTK2UI_GTK2_UI_H_
|