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/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 Loading... |
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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 default: | 215 default: |
222 NOTREACHED(); | 216 NOTREACHED(); |
223 break; | 217 break; |
224 } | 218 } |
225 } | 219 } |
226 | 220 |
227 // ImageLoadingTracker::Observer implementation. | 221 // ImageLoadingTracker::Observer implementation. |
228 void OnImageLoaded(const gfx::Image& image, | 222 void OnImageLoaded(const gfx::Image& image, |
229 const std::string& extension_id, | 223 const std::string& extension_id, |
230 int index) OVERRIDE { | 224 int index) OVERRIDE { |
231 if (!image.IsEmpty()) { | 225 extension_->browser_action()->CacheIcon( |
232 default_skbitmap_ = *image.ToSkBitmap(); | 226 extension_->browser_action()->default_icon_path(), image); |
233 default_icon_ = | |
234 static_cast<GdkPixbuf*>(g_object_ref(image.ToGdkPixbuf())); | |
235 } | |
236 UpdateState(); | 227 UpdateState(); |
237 } | 228 } |
238 | 229 |
239 // Updates the button based on the latest state from the associated | 230 // Updates the button based on the latest state from the associated |
240 // browser action. | 231 // browser action. |
241 void UpdateState() { | 232 void UpdateState() { |
242 int tab_id = toolbar_->GetCurrentTabId(); | 233 int tab_id = toolbar_->GetCurrentTabId(); |
243 if (tab_id < 0) | 234 if (tab_id < 0) |
244 return; | 235 return; |
245 | 236 |
246 std::string tooltip = extension_->browser_action()->GetTitle(tab_id); | 237 std::string tooltip = extension_->browser_action()->GetTitle(tab_id); |
247 if (tooltip.empty()) | 238 if (tooltip.empty()) |
248 gtk_widget_set_has_tooltip(button(), FALSE); | 239 gtk_widget_set_has_tooltip(button(), FALSE); |
249 else | 240 else |
250 gtk_widget_set_tooltip_text(button(), tooltip.c_str()); | 241 gtk_widget_set_tooltip_text(button(), tooltip.c_str()); |
251 | 242 |
252 SkBitmap image = extension_->browser_action()->GetIcon(tab_id); | 243 gfx::Image image = extension_->browser_action()->GetIcon(tab_id); |
253 if (!image.isNull()) { | 244 if (!image.IsEmpty()) |
254 GdkPixbuf* previous_gdk_icon = tab_specific_icon_; | 245 SetImage(image.ToGdkPixbuf()); |
255 tab_specific_icon_ = gfx::GdkPixbufFromSkBitmap(image); | |
256 SetImage(tab_specific_icon_); | |
257 if (previous_gdk_icon) | |
258 g_object_unref(previous_gdk_icon); | |
259 } else if (default_icon_) { | |
260 SetImage(default_icon_); | |
261 } | |
262 bool enabled = extension_->browser_action()->GetIsVisible(tab_id); | 246 bool enabled = extension_->browser_action()->GetIsVisible(tab_id); |
263 gtk_widget_set_sensitive(button(), enabled); | 247 gtk_widget_set_sensitive(button(), enabled); |
264 | 248 |
265 gtk_widget_queue_draw(button()); | 249 gtk_widget_queue_draw(button()); |
266 } | 250 } |
267 | 251 |
268 SkBitmap GetIcon() { | 252 SkBitmap GetIcon() { |
269 const SkBitmap& image = extension_->browser_action()->GetIcon( | 253 return *extension_->browser_action()->GetIcon( |
270 toolbar_->GetCurrentTabId()); | 254 toolbar_->GetCurrentTabId()).ToSkBitmap(); |
271 if (!image.isNull()) { | |
272 return image; | |
273 } else { | |
274 return default_skbitmap_; | |
275 } | |
276 } | 255 } |
277 | 256 |
278 MenuGtk* GetContextMenu() { | 257 MenuGtk* GetContextMenu() { |
279 if (!extension_->ShowConfigureContextMenus()) | 258 if (!extension_->ShowConfigureContextMenus()) |
280 return NULL; | 259 return NULL; |
281 | 260 |
282 context_menu_model_ = | 261 context_menu_model_ = |
283 new ExtensionContextMenuModel(extension_, toolbar_->browser(), this); | 262 new ExtensionContextMenuModel(extension_, toolbar_->browser(), this); |
284 context_menu_.reset( | 263 context_menu_.reset( |
285 new MenuGtk(this, context_menu_model_.get())); | 264 new MenuGtk(this, context_menu_model_.get())); |
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 | 1093 |
1115 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), | 1094 menu->PopupAsContext(gfx::Point(event->x_root, event->y_root), |
1116 event->time); | 1095 event->time); |
1117 return TRUE; | 1096 return TRUE; |
1118 } | 1097 } |
1119 | 1098 |
1120 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { | 1099 void BrowserActionsToolbarGtk::OnButtonShowOrHide(GtkWidget* sender) { |
1121 if (!resize_animation_.is_animating()) | 1100 if (!resize_animation_.is_animating()) |
1122 UpdateChevronVisibility(); | 1101 UpdateChevronVisibility(); |
1123 } | 1102 } |
OLD | NEW |