Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/ui/gtk/infobars/extension_infobar_gtk.cc

Issue 22694006: Infobar system refactor. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 if (button_) { 115 if (button_) {
136 signals()->Connect(button_, "button-press-event", 116 signals()->Connect(button_, "button-press-event",
137 G_CALLBACK(&OnButtonPressThunk), this); 117 G_CALLBACK(&OnButtonPressThunk), this);
138 } 118 }
139 signals()->Connect(view_->native_view(), "expose-event", 119 signals()->Connect(view_->native_view(), "expose-event",
140 G_CALLBACK(&OnExposeThunk), this); 120 G_CALLBACK(&OnExposeThunk), this);
141 signals()->Connect(view_->native_view(), "size_allocate", 121 signals()->Connect(view_->native_view(), "size_allocate",
142 G_CALLBACK(&OnSizeAllocateThunk), this); 122 G_CALLBACK(&OnSizeAllocateThunk), this);
143 } 123 }
144 124
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
145 void ExtensionInfoBarGtk::StoppedShowing() { 142 void ExtensionInfoBarGtk::StoppedShowing() {
146 if (button_) 143 if (button_)
147 gtk_chrome_button_unset_paint_state(GTK_CHROME_BUTTON(button_)); 144 gtk_chrome_button_unset_paint_state(GTK_CHROME_BUTTON(button_));
148 } 145 }
149 146
150 void ExtensionInfoBarGtk::OnDelegateDeleted() {
151 delegate_ = NULL;
152 }
153
154 void ExtensionInfoBarGtk::OnImageLoaded(const gfx::Image& image) { 147 void ExtensionInfoBarGtk::OnImageLoaded(const gfx::Image& image) {
155 148
156 DCHECK(icon_); 149 DCHECK(icon_);
157 // TODO(erg): IDR_EXTENSIONS_SECTION should have an IDR_INFOBAR_EXTENSIONS 150 // TODO(erg): IDR_EXTENSIONS_SECTION should have an IDR_INFOBAR_EXTENSIONS
158 // icon of the correct size with real subpixel shading and such. 151 // icon of the correct size with real subpixel shading and such.
159 const gfx::ImageSkia* icon = NULL; 152 const gfx::ImageSkia* icon = NULL;
160 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 153 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
161 if (image.IsEmpty()) 154 if (image.IsEmpty())
162 icon = rb.GetImageSkiaNamed(IDR_EXTENSIONS_SECTION); 155 icon = rb.GetImageSkiaNamed(IDR_EXTENSIONS_SECTION);
163 else 156 else
(...skipping 17 matching lines...) Expand all
181 } else { 174 } else {
182 bitmap = *icon->bitmap(); 175 bitmap = *icon->bitmap();
183 } 176 }
184 177
185 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(bitmap); 178 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(bitmap);
186 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf); 179 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf);
187 g_object_unref(pixbuf); 180 g_object_unref(pixbuf);
188 } 181 }
189 182
190 ExtensionInfoBarDelegate* ExtensionInfoBarGtk::GetDelegate() { 183 ExtensionInfoBarDelegate* ExtensionInfoBarGtk::GetDelegate() {
191 return delegate_ ? delegate_->AsExtensionInfoBarDelegate() : NULL; 184 return delegate()->AsExtensionInfoBarDelegate();
192 } 185 }
193 186
194 Browser* ExtensionInfoBarGtk::GetBrowser() { 187 Browser* ExtensionInfoBarGtk::GetBrowser() {
195 DCHECK(icon_); 188 DCHECK(icon_);
196 // Get the Browser object this infobar is attached to. 189 // Get the Browser object this infobar is attached to.
197 GtkWindow* parent = platform_util::GetTopLevel(icon_); 190 GtkWindow* parent = platform_util::GetTopLevel(icon_);
198 return parent ? 191 return parent ?
199 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent)->browser() : 192 BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent)->browser() :
200 NULL; 193 NULL;
201 } 194 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 gboolean ExtensionInfoBarGtk::OnExpose(GtkWidget* sender, 234 gboolean ExtensionInfoBarGtk::OnExpose(GtkWidget* sender,
242 GdkEventExpose* event) { 235 GdkEventExpose* event) {
243 TRACE_EVENT0("ui::gtk", "ExtensionInfoBarGtk::OnExpose"); 236 TRACE_EVENT0("ui::gtk", "ExtensionInfoBarGtk::OnExpose");
244 237
245 // We also need to draw our infobar arrows over the renderer. 238 // We also need to draw our infobar arrows over the renderer.
246 static_cast<InfoBarContainerGtk*>(container())-> 239 static_cast<InfoBarContainerGtk*>(container())->
247 PaintInfobarBitsOn(sender, event, this); 240 PaintInfobarBitsOn(sender, event, this);
248 241
249 return FALSE; 242 return FALSE;
250 } 243 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/infobars/extension_infobar_gtk.h ('k') | chrome/browser/ui/gtk/infobars/infobar_container_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698