OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h" | 5 #include "chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h" |
6 | 6 |
7 #include "base/debug/trace_event.h" | 7 #include "base/debug/trace_event.h" |
8 #include "chrome/browser/extensions/extension_context_menu_model.h" | 8 #include "chrome/browser/extensions/extension_context_menu_model.h" |
9 #include "chrome/browser/extensions/extension_host.h" | 9 #include "chrome/browser/extensions/extension_host.h" |
10 #include "chrome/browser/extensions/image_loader.h" | 10 #include "chrome/browser/extensions/image_loader.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "grit/theme_resources.h" | 24 #include "grit/theme_resources.h" |
25 #include "ui/base/gtk/gtk_signal_registrar.h" | 25 #include "ui/base/gtk/gtk_signal_registrar.h" |
26 #include "ui/base/resource/resource_bundle.h" | 26 #include "ui/base/resource/resource_bundle.h" |
27 #include "ui/gfx/canvas.h" | 27 #include "ui/gfx/canvas.h" |
28 #include "ui/gfx/gtk_util.h" | 28 #include "ui/gfx/gtk_util.h" |
29 #include "ui/gfx/image/image.h" | 29 #include "ui/gfx/image/image.h" |
30 | 30 |
31 | 31 |
32 // ExtensionInfoBarDelegate --------------------------------------------------- | 32 // ExtensionInfoBarDelegate --------------------------------------------------- |
33 | 33 |
34 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { | 34 // static |
35 return new ExtensionInfoBarGtk(owner, this); | 35 scoped_ptr<InfoBar> ExtensionInfoBarDelegate::CreateInfoBar( |
| 36 scoped_ptr<ExtensionInfoBarDelegate> delegate) { |
| 37 return scoped_ptr<InfoBar>(new ExtensionInfoBarGtk(delegate.Pass())); |
36 } | 38 } |
37 | 39 |
38 | 40 |
39 // ExtensionInfoBarGtk -------------------------------------------------------- | 41 // ExtensionInfoBarGtk -------------------------------------------------------- |
40 | 42 |
41 ExtensionInfoBarGtk::ExtensionInfoBarGtk(InfoBarService* owner, | 43 ExtensionInfoBarGtk::ExtensionInfoBarGtk( |
42 ExtensionInfoBarDelegate* delegate) | 44 scoped_ptr<ExtensionInfoBarDelegate> delegate) |
43 : InfoBarGtk(owner, delegate), | 45 : InfoBarGtk(delegate.PassAs<InfoBarDelegate>()), |
44 delegate_(delegate), | |
45 view_(NULL), | 46 view_(NULL), |
46 button_(NULL), | 47 button_(NULL), |
47 icon_(NULL), | 48 icon_(NULL), |
48 alignment_(NULL), | 49 alignment_(NULL), |
49 weak_ptr_factory_(this) { | 50 weak_ptr_factory_(this) { |
50 GetDelegate()->set_observer(this); | |
51 | |
52 int height = GetDelegate()->height(); | 51 int height = GetDelegate()->height(); |
53 SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0); | 52 SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0); |
54 } | 53 } |
55 | 54 |
56 ExtensionInfoBarGtk::~ExtensionInfoBarGtk() { | 55 ExtensionInfoBarGtk::~ExtensionInfoBarGtk() { |
57 if (GetDelegate()) | |
58 GetDelegate()->set_observer(NULL); | |
59 } | 56 } |
60 | 57 |
61 void ExtensionInfoBarGtk::PlatformSpecificHide(bool animate) { | 58 void ExtensionInfoBarGtk::PlatformSpecificSetOwner() { |
62 DCHECK(view_); | 59 InfoBarGtk::PlatformSpecificSetOwner(); |
63 DCHECK(alignment_); | |
64 gtk_util::RemoveAllChildren(alignment_); | |
65 } | |
66 | |
67 void ExtensionInfoBarGtk::GetTopColor(InfoBarDelegate::Type type, | |
68 double* r, double* g, double* b) { | |
69 // Extension infobars are always drawn with chrome-theme colors. | |
70 *r = *g = *b = 233.0 / 255.0; | |
71 } | |
72 | |
73 void ExtensionInfoBarGtk::GetBottomColor(InfoBarDelegate::Type type, | |
74 double* r, double* g, double* b) { | |
75 *r = *g = *b = 218.0 / 255.0; | |
76 } | |
77 | |
78 void ExtensionInfoBarGtk::InitWidgets() { | |
79 InfoBarGtk::InitWidgets(); | |
80 | 60 |
81 // Always render the close button as if we were doing chrome style widget | 61 // Always render the close button as if we were doing chrome style widget |
82 // rendering. For extension infobars, we force chrome style rendering because | 62 // rendering. For extension infobars, we force chrome style rendering because |
83 // extension authors are going to expect to match the declared gradient in | 63 // extension authors are going to expect to match the declared gradient in |
84 // extensions_infobar.css, and the close button provided by some GTK+ themes | 64 // extensions_infobar.css, and the close button provided by some GTK+ themes |
85 // won't look good on this background. | 65 // won't look good on this background. |
86 ForceCloseButtonToUseChromeTheme(); | 66 ForceCloseButtonToUseChromeTheme(); |
87 | 67 |
88 icon_ = gtk_image_new(); | 68 icon_ = gtk_image_new(); |
89 gtk_misc_set_alignment(GTK_MISC(icon_), 0.5, 0.5); | 69 gtk_misc_set_alignment(GTK_MISC(icon_), 0.5, 0.5); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 if (button_) { | 114 if (button_) { |
135 signals()->Connect(button_, "button-press-event", | 115 signals()->Connect(button_, "button-press-event", |
136 G_CALLBACK(&OnButtonPressThunk), this); | 116 G_CALLBACK(&OnButtonPressThunk), this); |
137 } | 117 } |
138 signals()->Connect(view_->native_view(), "expose-event", | 118 signals()->Connect(view_->native_view(), "expose-event", |
139 G_CALLBACK(&OnExposeThunk), this); | 119 G_CALLBACK(&OnExposeThunk), this); |
140 signals()->Connect(view_->native_view(), "size_allocate", | 120 signals()->Connect(view_->native_view(), "size_allocate", |
141 G_CALLBACK(&OnSizeAllocateThunk), this); | 121 G_CALLBACK(&OnSizeAllocateThunk), this); |
142 } | 122 } |
143 | 123 |
| 124 void ExtensionInfoBarGtk::PlatformSpecificHide(bool animate) { |
| 125 DCHECK(view_); |
| 126 DCHECK(alignment_); |
| 127 gtk_util::RemoveAllChildren(alignment_); |
| 128 } |
| 129 |
| 130 void ExtensionInfoBarGtk::GetTopColor(InfoBarDelegate::Type type, |
| 131 double* r, double* g, double* b) { |
| 132 // Extension infobars are always drawn with chrome-theme colors. |
| 133 *r = *g = *b = 233.0 / 255.0; |
| 134 } |
| 135 |
| 136 void ExtensionInfoBarGtk::GetBottomColor(InfoBarDelegate::Type type, |
| 137 double* r, double* g, double* b) { |
| 138 *r = *g = *b = 218.0 / 255.0; |
| 139 } |
| 140 |
144 void ExtensionInfoBarGtk::StoppedShowing() { | 141 void ExtensionInfoBarGtk::StoppedShowing() { |
145 if (button_) | 142 if (button_) |
146 gtk_chrome_button_unset_paint_state(GTK_CHROME_BUTTON(button_)); | 143 gtk_chrome_button_unset_paint_state(GTK_CHROME_BUTTON(button_)); |
147 } | 144 } |
148 | 145 |
149 void ExtensionInfoBarGtk::OnDelegateDeleted() { | |
150 delegate_ = NULL; | |
151 } | |
152 | |
153 void ExtensionInfoBarGtk::OnImageLoaded(const gfx::Image& image) { | 146 void ExtensionInfoBarGtk::OnImageLoaded(const gfx::Image& image) { |
154 | 147 |
155 DCHECK(icon_); | 148 DCHECK(icon_); |
156 // TODO(erg): IDR_EXTENSIONS_SECTION should have an IDR_INFOBAR_EXTENSIONS | 149 // TODO(erg): IDR_EXTENSIONS_SECTION should have an IDR_INFOBAR_EXTENSIONS |
157 // icon of the correct size with real subpixel shading and such. | 150 // icon of the correct size with real subpixel shading and such. |
158 const gfx::ImageSkia* icon = NULL; | 151 const gfx::ImageSkia* icon = NULL; |
159 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 152 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
160 if (image.IsEmpty()) | 153 if (image.IsEmpty()) |
161 icon = rb.GetImageSkiaNamed(IDR_EXTENSIONS_SECTION); | 154 icon = rb.GetImageSkiaNamed(IDR_EXTENSIONS_SECTION); |
162 else | 155 else |
(...skipping 17 matching lines...) Expand all Loading... |
180 } else { | 173 } else { |
181 bitmap = *icon->bitmap(); | 174 bitmap = *icon->bitmap(); |
182 } | 175 } |
183 | 176 |
184 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(bitmap); | 177 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(bitmap); |
185 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf); | 178 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf); |
186 g_object_unref(pixbuf); | 179 g_object_unref(pixbuf); |
187 } | 180 } |
188 | 181 |
189 ExtensionInfoBarDelegate* ExtensionInfoBarGtk::GetDelegate() { | 182 ExtensionInfoBarDelegate* ExtensionInfoBarGtk::GetDelegate() { |
190 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; | 183 return delegate()->AsExtensionInfoBarDelegate(); |
191 } | 184 } |
192 | 185 |
193 Browser* ExtensionInfoBarGtk::GetBrowser() { | 186 Browser* ExtensionInfoBarGtk::GetBrowser() { |
194 DCHECK(icon_); | 187 DCHECK(icon_); |
195 // Get the Browser object this infobar is attached to. | 188 // Get the Browser object this infobar is attached to. |
196 GtkWindow* parent = platform_util::GetTopLevel(icon_); | 189 GtkWindow* parent = platform_util::GetTopLevel(icon_); |
197 return parent ? | 190 return parent ? |
198 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent)->browser() : | 191 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent)->browser() : |
199 NULL; | 192 NULL; |
200 } | 193 } |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 gboolean ExtensionInfoBarGtk::OnExpose(GtkWidget* sender, | 233 gboolean ExtensionInfoBarGtk::OnExpose(GtkWidget* sender, |
241 GdkEventExpose* event) { | 234 GdkEventExpose* event) { |
242 TRACE_EVENT0("ui::gtk", "ExtensionInfoBarGtk::OnExpose"); | 235 TRACE_EVENT0("ui::gtk", "ExtensionInfoBarGtk::OnExpose"); |
243 | 236 |
244 // We also need to draw our infobar arrows over the renderer. | 237 // We also need to draw our infobar arrows over the renderer. |
245 static_cast<InfoBarContainerGtk*>(container())-> | 238 static_cast<InfoBarContainerGtk*>(container())-> |
246 PaintInfobarBitsOn(sender, event, this); | 239 PaintInfobarBitsOn(sender, event, this); |
247 | 240 |
248 return FALSE; | 241 return FALSE; |
249 } | 242 } |
OLD | NEW |