Revert 168224 - Update V8 to version 3.15.4.
[chromium-blink-merge.git] / chrome / browser / ui / libgtk2ui / gtk2_ui.h
blob5ad52422fa5d854367bc46bc89cf4d15deceeb06
1 // Copyright (c) 2012 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>
10 #include "base/basictypes.h"
11 #include "base/compiler_specific.h"
12 #include "chrome/browser/ui/libgtk2ui/libgtk2ui_export.h"
13 #include "chrome/browser/ui/libgtk2ui/owned_widget_gtk2.h"
14 #include "ui/base/linux_ui.h"
15 #include "ui/gfx/color_utils.h"
17 typedef struct _GdkColor GdkColor;
18 typedef struct _GtkStyle GtkStyle;
19 typedef struct _GtkWidget GtkWidget;
21 class SkBitmap;
23 namespace gfx {
24 class Image;
27 namespace libgtk2ui {
29 // Interface to GTK2 desktop features.
31 class Gtk2UI : public ui::LinuxUI {
32 public:
33 Gtk2UI();
34 virtual ~Gtk2UI();
36 // ui::LinuxUI:
37 virtual bool UseNativeTheme() const OVERRIDE;
38 virtual gfx::Image* GetThemeImageNamed(int id) const OVERRIDE;
39 virtual bool GetColor(int id, SkColor* color) const OVERRIDE;
40 virtual ui::SelectFileDialog* CreateSelectFileDialog(
41 ui::SelectFileDialog::Listener* listener,
42 ui::SelectFilePolicy* policy) const OVERRIDE;
44 private:
45 typedef std::map<int, SkColor> ColorMap;
46 typedef std::map<int, color_utils::HSL> TintMap;
47 typedef std::map<int, gfx::Image*> ImageCache;
49 // This method returns the colors webkit will use for the scrollbars. When no
50 // colors are specified by the GTK+ theme, this function averages of the
51 // thumb part and of the track colors.
52 void GetScrollbarColors(GdkColor* thumb_active_color,
53 GdkColor* thumb_inactive_color,
54 GdkColor* track_color);
56 // Extracts colors and tints from the GTK theme, both for the
57 // ThemeService interface and the colors we send to webkit.
58 void LoadGtkValues();
60 // Reads in explicit theme frame colors from the ChromeGtkFrame style class
61 // or generates them per our fallback algorithm.
62 GdkColor BuildFrameColors(GtkStyle* frame_style);
64 // Sets the underlying theme colors/tints from a GTK color.
65 void SetThemeColorFromGtk(int id, const GdkColor* color);
66 void SetThemeTintFromGtk(int id, const GdkColor* color);
68 // Creates and returns a frame color, either using |gtk_base| verbatim if
69 // non-NULL, or tinting |base| with |tint|. Also sets |color_id| and
70 // |tint_id| to the returned color.
71 GdkColor BuildAndSetFrameColor(const GdkColor* base,
72 const GdkColor* gtk_base,
73 const color_utils::HSL& tint,
74 int color_id,
75 int tint_id);
77 // Lazily generates each bitmap used in the gtk theme.
78 SkBitmap GenerateGtkThemeBitmap(int id) const;
80 // Creates a GTK+ version of IDR_THEME_FRAME. Instead of tinting, this
81 // creates a theme configurable gradient ending with |color_id| at the
82 // bottom, and |gradient_name| at the top if that color is specified in the
83 // theme.
84 SkBitmap GenerateFrameImage(int color_id,
85 const char* gradient_name) const;
87 // Takes the base frame image |base_id| and tints it with |tint_id|.
88 SkBitmap GenerateTabImage(int base_id) const;
90 // Tints an icon based on tint.
91 SkBitmap GenerateTintedIcon(int base_id,
92 const color_utils::HSL& tint) const;
94 // Renders a GTK icon as a SkBitmap, with prelight/active border if
95 // appropriate.
96 SkBitmap GenerateGTKIcon(int base_id) const;
98 // Renders a GTK button border around a tinted wrench icon.
99 SkBitmap GenerateWrenchIcon(int base_id) const;
101 // Returns the tint for buttons that contrasts with the normal window
102 // background color.
103 void GetNormalButtonTintHSL(color_utils::HSL* tint) const;
105 // Returns a tint that's the color of the current normal text in an entry.
106 void GetNormalEntryForegroundHSL(color_utils::HSL* tint) const;
108 // Returns a tint that's the color of the current highlighted text in an
109 // entry.
110 void GetSelectedEntryForegroundHSL(color_utils::HSL* tint) const;
112 // Draws the GTK button border for state |gtk_state| onto a bitmap.
113 SkBitmap DrawGtkButtonBorder(int gtk_state, int width, int height) const;
115 // Frees all calculated images and color data.
116 void ClearAllThemeData();
118 GtkWidget* fake_window_;
119 GtkWidget* fake_frame_;
120 OwnedWidgetGtk fake_label_;
121 OwnedWidgetGtk fake_entry_;
123 // Tints and colors calculated by LoadGtkValues() that are given to the
124 // caller while |use_gtk_| is true.
125 ColorMap colors_;
126 TintMap tints_;
128 // Colors used to tint certain icons.
129 color_utils::HSL button_tint_;
130 color_utils::HSL entry_tint_;
131 color_utils::HSL selected_entry_tint_;
133 // Colors that we pass to WebKit. These are generated each time the theme
134 // changes.
135 SkColor focus_ring_color_;
136 SkColor thumb_active_color_;
137 SkColor thumb_inactive_color_;
138 SkColor track_color_;
139 SkColor active_selection_bg_color_;
140 SkColor active_selection_fg_color_;
141 SkColor inactive_selection_bg_color_;
142 SkColor inactive_selection_fg_color_;
144 // Image cache of lazily created images.
145 mutable ImageCache gtk_images_;
147 DISALLOW_COPY_AND_ASSIGN(Gtk2UI);
150 } // namespace libgtk2ui
152 // Access point to the GTK2 desktop system. This should be the only symbol that
153 // is exported in the library; everything else should be used through the
154 // interface, because eventually this .so will be loaded through dlopen at
155 // runtime so our main binary can conditionally load GTK2 or GTK3 or EFL or
156 // QT or whatever.
157 LIBGTK2UI_EXPORT ui::LinuxUI* BuildGtk2UI();
159 #endif // CHROME_BROWSER_UI_LIBGTK2UI_GTK2_UI_H_