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

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

Issue 332021: Move page actions over to ExtensionAction2 (Closed)
Patch Set: Review feedback Created 11 years, 1 month 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
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/gtk/browser_actions_toolbar_gtk.h" 5 #include "chrome/browser/gtk/browser_actions_toolbar_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 #include <vector> 8 #include <vector>
9 9
10 #include "app/gfx/canvas_paint.h" 10 #include "app/gfx/canvas_paint.h"
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 tab_specific_icon_(NULL), 46 tab_specific_icon_(NULL),
47 default_icon_(NULL) { 47 default_icon_(NULL) {
48 DCHECK(extension_->browser_action()); 48 DCHECK(extension_->browser_action());
49 49
50 gtk_widget_set_size_request(button_.get(), kButtonSize, kButtonSize); 50 gtk_widget_set_size_request(button_.get(), kButtonSize, kButtonSize);
51 51
52 UpdateState(); 52 UpdateState();
53 53
54 // The Browser Action API does not allow the default icon path to be 54 // The Browser Action API does not allow the default icon path to be
55 // changed at runtime, so we can load this now and cache it. 55 // changed at runtime, so we can load this now and cache it.
56 std::string path = extension_->browser_action()->GetDefaultIconPath(); 56 std::string path = extension_->browser_action()->default_icon_path();
57 if (!path.empty()) { 57 if (!path.empty()) {
58 tracker_ = new ImageLoadingTracker(this, 1); 58 tracker_ = new ImageLoadingTracker(this, 1);
59 tracker_->PostLoadImageTask(extension_->GetResource(path), 59 tracker_->PostLoadImageTask(extension_->GetResource(path),
60 gfx::Size(Extension::kBrowserActionIconMaxSize, 60 gfx::Size(Extension::kBrowserActionIconMaxSize,
61 Extension::kBrowserActionIconMaxSize)); 61 Extension::kBrowserActionIconMaxSize));
62 } 62 }
63 63
64 // We need to hook up extension popups here. http://crbug.com/23897 64 // We need to hook up extension popups here. http://crbug.com/23897
65 g_signal_connect(button_.get(), "clicked", 65 g_signal_connect(button_.get(), "clicked",
66 G_CALLBACK(OnButtonClicked), this); 66 G_CALLBACK(OnButtonClicked), this);
(...skipping 29 matching lines...) Expand all
96 if (type == NotificationType::EXTENSION_BROWSER_ACTION_UPDATED) 96 if (type == NotificationType::EXTENSION_BROWSER_ACTION_UPDATED)
97 UpdateState(); 97 UpdateState();
98 else if (type == NotificationType::BROWSER_THEME_CHANGED) 98 else if (type == NotificationType::BROWSER_THEME_CHANGED)
99 OnThemeChanged(); 99 OnThemeChanged();
100 else 100 else
101 NOTREACHED(); 101 NOTREACHED();
102 } 102 }
103 103
104 // ImageLoadingTracker::Observer implementation. 104 // ImageLoadingTracker::Observer implementation.
105 void OnImageLoaded(SkBitmap* image, size_t index) { 105 void OnImageLoaded(SkBitmap* image, size_t index) {
106 default_icon_ = gfx::GdkPixbufFromSkBitmap(image); 106 if (image)
107 default_icon_ = gfx::GdkPixbufFromSkBitmap(image);
107 UpdateState(); 108 UpdateState();
108 } 109 }
109 110
110 // Updates the button based on the latest state from the associated 111 // Updates the button based on the latest state from the associated
111 // browser action. 112 // browser action.
112 void UpdateState() { 113 void UpdateState() {
113 int tab_id = toolbar_->GetCurrentTabId(); 114 int tab_id = toolbar_->GetCurrentTabId();
114 if (tab_id < 0) 115 if (tab_id < 0)
115 return; 116 return;
116 117
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 int tab_id = button->toolbar_->GetCurrentTabId(); 161 int tab_id = button->toolbar_->GetCurrentTabId();
161 if (tab_id < 0) 162 if (tab_id < 0)
162 return FALSE; 163 return FALSE;
163 164
164 ExtensionAction2* action = button->extension_->browser_action(); 165 ExtensionAction2* action = button->extension_->browser_action();
165 if (action->GetBadgeText(tab_id).empty()) 166 if (action->GetBadgeText(tab_id).empty())
166 return FALSE; 167 return FALSE;
167 168
168 gfx::CanvasPaint canvas(event, false); 169 gfx::CanvasPaint canvas(event, false);
169 gfx::Rect bounding_rect(widget->allocation); 170 gfx::Rect bounding_rect(widget->allocation);
170 ExtensionActionState::PaintBadge(&canvas, bounding_rect, 171 action->PaintBadge(&canvas, bounding_rect, tab_id);
171 action->GetBadgeText(tab_id),
172 action->GetBadgeTextColor(tab_id),
173 action->GetBadgeBackgroundColor(tab_id));
174 return FALSE; 172 return FALSE;
175 } 173 }
176 174
177 // The toolbar containing this button. 175 // The toolbar containing this button.
178 BrowserActionsToolbarGtk* toolbar_; 176 BrowserActionsToolbarGtk* toolbar_;
179 177
180 // The extension that contains this browser action. 178 // The extension that contains this browser action.
181 Extension* extension_; 179 Extension* extension_;
182 180
183 // The gtk widget for this browser action. 181 // The gtk widget for this browser action.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 if (extension_button_map_.erase(extension->id())) 273 if (extension_button_map_.erase(extension->id()))
276 UpdateVisibility(); 274 UpdateVisibility();
277 } 275 }
278 276
279 void BrowserActionsToolbarGtk::UpdateVisibility() { 277 void BrowserActionsToolbarGtk::UpdateVisibility() {
280 if (button_count() == 0) 278 if (button_count() == 0)
281 gtk_widget_hide(widget()); 279 gtk_widget_hide(widget());
282 else 280 else
283 gtk_widget_show(widget()); 281 gtk_widget_show(widget());
284 } 282 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698