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

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

Issue 14327008: Add InitWidgets() phase for GTK infobars. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 8 months 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_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 17 matching lines...) Expand all
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 ExtensionInfoBarGtk::ExtensionInfoBarGtk(InfoBarService* owner, 31 ExtensionInfoBarGtk::ExtensionInfoBarGtk(InfoBarService* owner,
32 ExtensionInfoBarDelegate* delegate) 32 ExtensionInfoBarDelegate* delegate)
33 : InfoBarGtk(owner, delegate), 33 : InfoBarGtk(owner, delegate),
34 delegate_(delegate), 34 delegate_(delegate),
35 view_(NULL), 35 view_(NULL),
36 button_(NULL), 36 button_(NULL),
37 icon_(NULL), 37 icon_(NULL),
38 alignment_(NULL),
38 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 39 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
39 delegate->set_observer(this); 40 delegate->set_observer(this);
40 41
41 // Always render the close button as if we were doing chrome style widget
42 // rendering. For extension infobars, we force chrome style rendering because
43 // extension authors are going to expect to match the declared gradient in
44 // extensions_infobar.css, and the close button provided by some GTK+ themes
45 // won't look good on this background.
46 close_button_->ForceChromeTheme();
47
48 int height = delegate->height(); 42 int height = delegate->height();
49 SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0); 43 SetBarTargetHeight((height > 0) ? (height + kSeparatorLineHeight) : 0);
50
51 BuildWidgets();
52 } 44 }
53 45
54 ExtensionInfoBarGtk::~ExtensionInfoBarGtk() { 46 ExtensionInfoBarGtk::~ExtensionInfoBarGtk() {
55 if (delegate_) 47 if (delegate_)
56 delegate_->set_observer(NULL); 48 delegate_->set_observer(NULL);
57 } 49 }
58 50
59 void ExtensionInfoBarGtk::PlatformSpecificHide(bool animate) { 51 void ExtensionInfoBarGtk::PlatformSpecificHide(bool animate) {
60 // This view is not owned by us; we can't unparent it because we aren't the 52 DCHECK(alignment_);
61 // owning container.
62 gtk_util::RemoveAllChildren(alignment_); 53 gtk_util::RemoveAllChildren(alignment_);
63 } 54 }
64 55
65 void ExtensionInfoBarGtk::GetTopColor(InfoBarDelegate::Type type, 56 void ExtensionInfoBarGtk::GetTopColor(InfoBarDelegate::Type type,
66 double* r, double* g, double* b) { 57 double* r, double* g, double* b) {
67 // Extension infobars are always drawn with chrome-theme colors. 58 // Extension infobars are always drawn with chrome-theme colors.
68 *r = *g = *b = 233.0 / 255.0; 59 *r = *g = *b = 233.0 / 255.0;
69 } 60 }
70 61
71 void ExtensionInfoBarGtk::GetBottomColor(InfoBarDelegate::Type type, 62 void ExtensionInfoBarGtk::GetBottomColor(InfoBarDelegate::Type type,
72 double* r, double* g, double* b) { 63 double* r, double* g, double* b) {
73 *r = *g = *b = 218.0 / 255.0; 64 *r = *g = *b = 218.0 / 255.0;
74 } 65 }
75 66
76 void ExtensionInfoBarGtk::OnImageLoaded(const gfx::Image& image) { 67 void ExtensionInfoBarGtk::OnImageLoaded(const gfx::Image& image) {
77 if (!delegate_) 68 if (!delegate_)
78 return; // The delegate can go away while we asynchronously load images. 69 return; // The delegate can go away while we asynchronously load images.
79 70
71 DCHECK(icon_);
80 // TODO(erg): IDR_EXTENSIONS_SECTION should have an IDR_INFOBAR_EXTENSIONS 72 // TODO(erg): IDR_EXTENSIONS_SECTION should have an IDR_INFOBAR_EXTENSIONS
81 // icon of the correct size with real subpixel shading and such. 73 // icon of the correct size with real subpixel shading and such.
82 const gfx::ImageSkia* icon = NULL; 74 const gfx::ImageSkia* icon = NULL;
83 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 75 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
84 if (image.IsEmpty()) 76 if (image.IsEmpty())
85 icon = rb.GetImageSkiaNamed(IDR_EXTENSIONS_SECTION); 77 icon = rb.GetImageSkiaNamed(IDR_EXTENSIONS_SECTION);
86 else 78 else
87 icon = image.ToImageSkia(); 79 icon = image.ToImageSkia();
88 80
89 SkBitmap bitmap; 81 SkBitmap bitmap;
(...skipping 13 matching lines...) Expand all
103 bitmap = canvas->ExtractImageRep().sk_bitmap(); 95 bitmap = canvas->ExtractImageRep().sk_bitmap();
104 } else { 96 } else {
105 bitmap = *icon->bitmap(); 97 bitmap = *icon->bitmap();
106 } 98 }
107 99
108 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(bitmap); 100 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(bitmap);
109 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf); 101 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), pixbuf);
110 g_object_unref(pixbuf); 102 g_object_unref(pixbuf);
111 } 103 }
112 104
113 void ExtensionInfoBarGtk::BuildWidgets() { 105 void ExtensionInfoBarGtk::InitWidgets() {
106 InfoBarGtk::InitWidgets();
107
108 // Always render the close button as if we were doing chrome style widget
109 // rendering. For extension infobars, we force chrome style rendering because
110 // extension authors are going to expect to match the declared gradient in
111 // extensions_infobar.css, and the close button provided by some GTK+ themes
112 // won't look good on this background.
113 close_button_->ForceChromeTheme();
114
114 icon_ = gtk_image_new(); 115 icon_ = gtk_image_new();
115 gtk_misc_set_alignment(GTK_MISC(icon_), 0.5, 0.5); 116 gtk_misc_set_alignment(GTK_MISC(icon_), 0.5, 0.5);
116 117
117 const extensions::Extension* extension = 118 const extensions::Extension* extension =
118 delegate_->extension_host()->extension(); 119 delegate_->extension_host()->extension();
119 120
120 if (extension->ShowConfigureContextMenus()) { 121 if (extension->ShowConfigureContextMenus()) {
121 button_ = gtk_chrome_button_new(); 122 button_ = gtk_chrome_button_new();
122 gtk_chrome_button_set_use_gtk_rendering(GTK_CHROME_BUTTON(button_), FALSE); 123 gtk_chrome_button_set_use_gtk_rendering(GTK_CHROME_BUTTON(button_), FALSE);
123 g_object_set_data(G_OBJECT(button_), "left-align-popup", 124 g_object_set_data(G_OBJECT(button_), "left-align-popup",
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
171 void ExtensionInfoBarGtk::StoppedShowing() { 172 void ExtensionInfoBarGtk::StoppedShowing() {
172 if (button_) 173 if (button_)
173 gtk_chrome_button_unset_paint_state(GTK_CHROME_BUTTON(button_)); 174 gtk_chrome_button_unset_paint_state(GTK_CHROME_BUTTON(button_));
174 } 175 }
175 176
176 void ExtensionInfoBarGtk::OnDelegateDeleted() { 177 void ExtensionInfoBarGtk::OnDelegateDeleted() {
177 delegate_ = NULL; 178 delegate_ = NULL;
178 } 179 }
179 180
180 Browser* ExtensionInfoBarGtk::GetBrowser() { 181 Browser* ExtensionInfoBarGtk::GetBrowser() {
182 DCHECK(icon_);
181 // Get the Browser object this infobar is attached to. 183 // Get the Browser object this infobar is attached to.
182 GtkWindow* parent = platform_util::GetTopLevel(icon_); 184 GtkWindow* parent = platform_util::GetTopLevel(icon_);
183 if (!parent) 185 if (!parent)
184 return NULL; 186 return NULL;
185 187
186 return BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent)->browser(); 188 return BrowserWindowGtk::GetBrowserWindowForNativeWindow(parent)->browser();
187 } 189 }
188 190
189 ExtensionContextMenuModel* ExtensionInfoBarGtk::BuildMenuModel() { 191 ExtensionContextMenuModel* ExtensionInfoBarGtk::BuildMenuModel() {
190 const extensions::Extension* extension = delegate_->extension(); 192 const extensions::Extension* extension = delegate_->extension();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 // We also need to draw our infobar arrows over the renderer. 233 // We also need to draw our infobar arrows over the renderer.
232 static_cast<InfoBarContainerGtk*>(container())-> 234 static_cast<InfoBarContainerGtk*>(container())->
233 PaintInfobarBitsOn(sender, event, this); 235 PaintInfobarBitsOn(sender, event, this);
234 236
235 return FALSE; 237 return FALSE;
236 } 238 }
237 239
238 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarService* owner) { 240 InfoBar* ExtensionInfoBarDelegate::CreateInfoBar(InfoBarService* owner) {
239 return new ExtensionInfoBarGtk(owner, this); 241 return new ExtensionInfoBarGtk(owner, this);
240 } 242 }
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