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