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

Side by Side Diff: chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc

Issue 10806058: Move icon fallbacks into ExtensionAction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Windows support Created 8 years, 5 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/browser_actions_toolbar_gtk.h" 5 #include "chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <vector> 10 #include <vector>
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 DCHECK(extension_->browser_action()); 120 DCHECK(extension_->browser_action());
121 121
122 // The Browser Action API does not allow the default icon path to be 122 // The Browser Action API does not allow the default icon path to be
123 // changed at runtime, so we can load this now and cache it. 123 // changed at runtime, so we can load this now and cache it.
124 std::string path = extension_->browser_action()->default_icon_path(); 124 std::string path = extension_->browser_action()->default_icon_path();
125 if (!path.empty()) { 125 if (!path.empty()) {
126 tracker_.LoadImage(extension_, extension_->GetResource(path), 126 tracker_.LoadImage(extension_, extension_->GetResource(path),
127 gfx::Size(Extension::kBrowserActionIconMaxSize, 127 gfx::Size(Extension::kBrowserActionIconMaxSize,
128 Extension::kBrowserActionIconMaxSize), 128 Extension::kBrowserActionIconMaxSize),
129 ImageLoadingTracker::DONT_CACHE); 129 ImageLoadingTracker::DONT_CACHE);
130 } else {
131 const SkBitmap* bm =
132 ui::ResourceBundle::GetSharedInstance().GetImageNamed(
133 IDR_EXTENSIONS_FAVICON).ToSkBitmap();
134 default_skbitmap_ = *bm;
135 default_icon_ = gfx::GdkPixbufFromSkBitmap(*bm);
136 } 130 }
137 131
138 UpdateState(); 132 UpdateState();
139 133
140 signals_.Connect(button(), "button-press-event", 134 signals_.Connect(button(), "button-press-event",
141 G_CALLBACK(OnButtonPress), this); 135 G_CALLBACK(OnButtonPress), this);
142 signals_.Connect(button(), "clicked", 136 signals_.Connect(button(), "clicked",
143 G_CALLBACK(OnClicked), this); 137 G_CALLBACK(OnClicked), this);
144 signals_.Connect(button(), "drag-begin", 138 signals_.Connect(button(), "drag-begin",
145 G_CALLBACK(&OnDragBegin), this); 139 G_CALLBACK(&OnDragBegin), this);
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 NOTREACHED(); 193 NOTREACHED();
200 break; 194 break;
201 } 195 }
202 } 196 }
203 197
204 // ImageLoadingTracker::Observer implementation. 198 // ImageLoadingTracker::Observer implementation.
205 void OnImageLoaded(const gfx::Image& image, 199 void OnImageLoaded(const gfx::Image& image,
206 const std::string& extension_id, 200 const std::string& extension_id,
207 int index) OVERRIDE { 201 int index) OVERRIDE {
208 if (!image.IsEmpty()) { 202 if (!image.IsEmpty()) {
209 default_skbitmap_ = *image.ToSkBitmap(); 203 loaded_icons_[extension_->browser_action()->default_icon_path()] = image;
210 default_icon_ =
211 static_cast<GdkPixbuf*>(g_object_ref(image.ToGdkPixbuf()));
212 } 204 }
not at google - send to devlin 2012/07/26 02:29:44 nit: remove surrounding {}
Jeffrey Yasskin 2012/07/26 21:11:47 Done.
213 UpdateState(); 205 UpdateState();
214 } 206 }
215 207
216 // Updates the button based on the latest state from the associated 208 // Updates the button based on the latest state from the associated
217 // browser action. 209 // browser action.
218 void UpdateState() { 210 void UpdateState() {
219 int tab_id = toolbar_->GetCurrentTabId(); 211 int tab_id = toolbar_->GetCurrentTabId();
220 if (tab_id < 0) 212 if (tab_id < 0)
221 return; 213 return;
222 214
223 std::string tooltip = extension_->browser_action()->GetTitle(tab_id); 215 std::string tooltip = extension_->browser_action()->GetTitle(tab_id);
224 if (tooltip.empty()) 216 if (tooltip.empty())
225 gtk_widget_set_has_tooltip(button(), FALSE); 217 gtk_widget_set_has_tooltip(button(), FALSE);
226 else 218 else
227 gtk_widget_set_tooltip_text(button(), tooltip.c_str()); 219 gtk_widget_set_tooltip_text(button(), tooltip.c_str());
228 220
229 SkBitmap image = extension_->browser_action()->GetIcon(tab_id); 221 gfx::Image image = extension_->browser_action()->GetIcon(
230 if (!image.isNull()) { 222 tab_id, loaded_icons_);
231 GdkPixbuf* previous_gdk_icon = tab_specific_icon_; 223 if (!image.IsEmpty()) {
232 tab_specific_icon_ = gfx::GdkPixbufFromSkBitmap(image); 224 SetImage(image.ToGdkPixbuf());
233 SetImage(tab_specific_icon_);
234 if (previous_gdk_icon)
235 g_object_unref(previous_gdk_icon);
236 } else if (default_icon_) {
237 SetImage(default_icon_);
238 } 225 }
not at google - send to devlin 2012/07/26 02:29:44 same nit
Jeffrey Yasskin 2012/07/26 21:11:47 Ah the perils of removing code. :)
239 bool enabled = extension_->browser_action()->GetIsVisible(tab_id); 226 bool enabled = extension_->browser_action()->GetIsVisible(tab_id);
240 gtk_widget_set_sensitive(button(), enabled); 227 gtk_widget_set_sensitive(button(), enabled);
241 228
242 gtk_widget_queue_draw(button()); 229 gtk_widget_queue_draw(button());
243 } 230 }
244 231
245 SkBitmap GetIcon() { 232 SkBitmap GetIcon() {
246 const SkBitmap& image = extension_->browser_action()->GetIcon( 233 return *extension_->browser_action()->GetIcon(
247 toolbar_->GetCurrentTabId()); 234 toolbar_->GetCurrentTabId(), loaded_icons_).ToSkBitmap();
248 if (!image.isNull()) {
249 return image;
250 } else {
251 return default_skbitmap_;
252 }
253 } 235 }
254 236
255 MenuGtk* GetContextMenu() { 237 MenuGtk* GetContextMenu() {
256 if (!extension_->ShowConfigureContextMenus()) 238 if (!extension_->ShowConfigureContextMenus())
257 return NULL; 239 return NULL;
258 240
259 context_menu_model_ = 241 context_menu_model_ =
260 new ExtensionContextMenuModel(extension_, toolbar_->browser(), this); 242 new ExtensionContextMenuModel(extension_, toolbar_->browser(), this);
261 context_menu_.reset( 243 context_menu_.reset(
262 new MenuGtk(this, context_menu_model_.get())); 244 new MenuGtk(this, context_menu_model_.get()));
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 // GTK widget hierarchy invalidates all tooltips and several popular 436 // GTK widget hierarchy invalidates all tooltips and several popular
455 // extensions change browser action icon in a loop. 437 // extensions change browser action icon in a loop.
456 GtkWidget* image_; 438 GtkWidget* image_;
457 439
458 // Loads the button's icons for us on the file thread. 440 // Loads the button's icons for us on the file thread.
459 ImageLoadingTracker tracker_; 441 ImageLoadingTracker tracker_;
460 442
461 // If we are displaying a tab-specific icon, it will be here. 443 // If we are displaying a tab-specific icon, it will be here.
462 GdkPixbuf* tab_specific_icon_; 444 GdkPixbuf* tab_specific_icon_;
463 445
446 // Icons loaded from paths. Currently just the browser action's default icon.
447 ExtensionAction::PathToIconCache loaded_icons_;
448
464 // If the browser action has a default icon, it will be here. 449 // If the browser action has a default icon, it will be here.
465 GdkPixbuf* default_icon_; 450 GdkPixbuf* default_icon_;
466 451
467 // Same as |default_icon_|, but stored as SkBitmap. 452 // Same as |default_icon_|, but stored as SkBitmap.
468 SkBitmap default_skbitmap_; 453 SkBitmap default_skbitmap_;
469 454
470 ui::GtkSignalRegistrar signals_; 455 ui::GtkSignalRegistrar signals_;
471 content::NotificationRegistrar registrar_; 456 content::NotificationRegistrar registrar_;
472 457
473 // The accelerator group used to handle accelerators, owned by this object. 458 // The accelerator group used to handle accelerators, owned by this object.
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 1071
1087 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), 1072 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root),
1088 event->time); 1073 event->time);
1089 return TRUE; 1074 return TRUE;
1090 } 1075 }
1091 1076
1092 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { 1077 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) {
1093 if (!resize_animation_.is_animating()) 1078 if (!resize_animation_.is_animating())
1094 UpdateChevronVisibility(); 1079 UpdateChevronVisibility();
1095 } 1080 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698