OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CHROME_BROWSER_UI_GTK_INFOBARS_INFOBAR_GTK_H_ | |
6 #define CHROME_BROWSER_UI_GTK_INFOBARS_INFOBAR_GTK_H_ | |
7 | |
8 #include <gtk/gtk.h> | |
9 | |
10 #include "base/basictypes.h" | |
11 #include "base/memory/scoped_ptr.h" | |
12 #include "chrome/browser/infobars/infobar.h" | |
13 #include "chrome/browser/infobars/infobar_delegate.h" | |
14 #include "chrome/browser/ui/gtk/menu_gtk.h" | |
15 #include "content/public/browser/notification_observer.h" | |
16 #include "content/public/browser/notification_registrar.h" | |
17 #include "third_party/skia/include/core/SkColor.h" | |
18 #include "ui/base/gtk/gtk_signal.h" | |
19 #include "ui/base/gtk/owned_widget_gtk.h" | |
20 | |
21 class CustomDrawButton; | |
22 class GtkThemeService; | |
23 | |
24 namespace ui { | |
25 class GtkSignalRegistrar; | |
26 class MenuModel; | |
27 } | |
28 | |
29 class InfoBarGtk : public InfoBar, | |
30 public content::NotificationObserver { | |
31 public: | |
32 // Conversion from cairo colors to SkColor. | |
33 typedef void (InfoBarGtk::*ColorGetter)(InfoBarDelegate::Type, | |
34 double* r, double* g, double* b); | |
35 | |
36 explicit InfoBarGtk(scoped_ptr<InfoBarDelegate> delegate); | |
37 virtual ~InfoBarGtk(); | |
38 | |
39 // Get the top level native GTK widget for this infobar. | |
40 GtkWidget* widget() { return widget_.get(); } | |
41 | |
42 GdkColor GetBorderColor() const; | |
43 | |
44 // Returns the target height of the infobar if the bar is animating, | |
45 // otherwise 0. We care about this number since we want to prevent | |
46 // unnecessary renderer repaints while animating. | |
47 int AnimatingHeight() const; | |
48 | |
49 SkColor ConvertGetColor(ColorGetter getter); | |
50 | |
51 // Retrieves the component colors for the infobar's background | |
52 // gradient. (This varies by infobars and can be animated to change). | |
53 virtual void GetTopColor(InfoBarDelegate::Type type, | |
54 double* r, double* g, double* b); | |
55 virtual void GetBottomColor(InfoBarDelegate::Type type, | |
56 double* r, double* g, double* b); | |
57 | |
58 protected: | |
59 // Spacing after message (and before buttons). | |
60 static const int kEndOfLabelSpacing; | |
61 | |
62 // InfoBar: | |
63 | |
64 // Inits any widgets and related objects necessary. | |
65 // | |
66 // NOTE: Subclasses who need to init widgets should override this function and | |
67 // explicitly call their parent's implementation first, then continue with | |
68 // further work they need to do. Failing to call the parent implementation | |
69 // first (or at all), or setting up widgets in the constructor instead of | |
70 // here, will lead to bad side effects like crashing. | |
71 virtual void PlatformSpecificSetOwner() OVERRIDE; | |
72 | |
73 virtual void PlatformSpecificShow(bool animate) OVERRIDE; | |
74 virtual void PlatformSpecificOnCloseSoon() OVERRIDE; | |
75 virtual void PlatformSpecificOnHeightsRecalculated() OVERRIDE; | |
76 | |
77 // content::NotificationObserver: | |
78 virtual void Observe(int type, | |
79 const content::NotificationSource& source, | |
80 const content::NotificationDetails& details) OVERRIDE; | |
81 | |
82 // Styles the close button as if we're doing Chrome-stlye widget rendering. | |
83 void ForceCloseButtonToUseChromeTheme(); | |
84 | |
85 GtkWidget* hbox() { return hbox_; } | |
86 | |
87 // Returns the signal registrar for this infobar. All signals representing | |
88 // user actions on visible widgets must go through this registrar! | |
89 ui::GtkSignalRegistrar* signals() { return signals_.get(); } | |
90 | |
91 // Creates a label with the appropriate font and color for the current | |
92 // gtk-theme state. It is InfoBarGtk's responsibility to observe browser | |
93 // theme changes and update the label's state. | |
94 GtkWidget* CreateLabel(const std::string& text); | |
95 | |
96 // Creates a link button with the appropriate current gtk-theme state. | |
97 GtkWidget* CreateLinkButton(const std::string& text); | |
98 | |
99 // Builds a button with an arrow in it to emulate the menu-button style from | |
100 // the windows version. | |
101 static GtkWidget* CreateMenuButton(const std::string& text); | |
102 | |
103 // Adds |display_text| to the infobar. If |link_text| is not empty, it is | |
104 // rendered as a hyperlink and inserted into |display_text| at |link_offset|, | |
105 // or right aligned in the infobar if |link_offset| is |npos|. If a link is | |
106 // supplied, |link_callback| must not be null. It will be invoked on click. | |
107 void AddLabelWithInlineLink(const base::string16& display_text, | |
108 const base::string16& link_text, | |
109 size_t link_offset, | |
110 GCallback callback); | |
111 | |
112 // Shows the menu with |model| with the context of |sender|. | |
113 void ShowMenuWithModel(GtkWidget* sender, | |
114 MenuGtk::Delegate* delegate, | |
115 ui::MenuModel* model); | |
116 | |
117 private: | |
118 void GetBackgroundColor(SkColor color, double* r, double* g, double* b); | |
119 void UpdateBorderColor(); | |
120 | |
121 CHROMEGTK_CALLBACK_0(InfoBarGtk, void, OnCloseButton); | |
122 CHROMEGTK_CALLBACK_1(InfoBarGtk, gboolean, OnBackgroundExpose, | |
123 GdkEventExpose*); | |
124 CHROMEGTK_CALLBACK_2(InfoBarGtk, void, OnChildSizeRequest, GtkWidget*, | |
125 GtkRequisition*); | |
126 | |
127 // A GtkExpandedContainer that contains |bg_box_| so we can vary the height of | |
128 // the infobar. | |
129 ui::OwnedWidgetGtk widget_; | |
130 | |
131 // The second highest widget in the hierarchy (after the |widget_|). | |
132 GtkWidget* bg_box_; | |
133 | |
134 // The hbox that holds infobar elements (button, text, icon, etc.). | |
135 GtkWidget* hbox_; | |
136 | |
137 // The x that closes the bar. | |
138 scoped_ptr<CustomDrawButton> close_button_; | |
139 | |
140 // The theme provider, used for getting border colors. | |
141 GtkThemeService* theme_service_; | |
142 | |
143 content::NotificationRegistrar registrar_; | |
144 | |
145 // A list of signals which we clear out once we're closing. | |
146 scoped_ptr<ui::GtkSignalRegistrar> signals_; | |
147 | |
148 // The current menu displayed. Can be null. We own this on the base class so | |
149 // we can cancel the menu while we're closing. | |
150 scoped_ptr<MenuGtk> menu_; | |
151 | |
152 DISALLOW_COPY_AND_ASSIGN(InfoBarGtk); | |
153 }; | |
154 | |
155 #endif // CHROME_BROWSER_UI_GTK_INFOBARS_INFOBAR_GTK_H_ | |
OLD | NEW |