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

Side by Side Diff: chrome/browser/ui/views/browser_action_view.cc

Issue 10806058: Move icon fallbacks into ExtensionAction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Move the icon cache inside ExtensionAction. Created 8 years, 4 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/views/browser_action_view.h" 5 #include "chrome/browser/ui/views/browser_action_view.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/extensions/api/commands/command_service.h" 8 #include "chrome/browser/extensions/api/commands/command_service.h"
9 #include "chrome/browser/extensions/api/commands/command_service_factory.h" 9 #include "chrome/browser/extensions/api/commands/command_service_factory.h"
10 #include "chrome/browser/extensions/extension_context_menu_model.h" 10 #include "chrome/browser/extensions/extension_context_menu_model.h"
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 std::string relative_path = browser_action_->default_icon_path(); 88 std::string relative_path = browser_action_->default_icon_path();
89 if (!relative_path.empty()) { 89 if (!relative_path.empty()) {
90 // LoadImage is not guaranteed to be synchronous, so we might see the 90 // LoadImage is not guaranteed to be synchronous, so we might see the
91 // callback OnImageLoaded execute immediately. It (through UpdateState) 91 // callback OnImageLoaded execute immediately. It (through UpdateState)
92 // expects parent() to return the owner for this button, so this 92 // expects parent() to return the owner for this button, so this
93 // function is as early as we can start this request. 93 // function is as early as we can start this request.
94 tracker_.LoadImage(extension_, extension_->GetResource(relative_path), 94 tracker_.LoadImage(extension_, extension_->GetResource(relative_path),
95 gfx::Size(Extension::kBrowserActionIconMaxSize, 95 gfx::Size(Extension::kBrowserActionIconMaxSize,
96 Extension::kBrowserActionIconMaxSize), 96 Extension::kBrowserActionIconMaxSize),
97 ImageLoadingTracker::DONT_CACHE); 97 ImageLoadingTracker::DONT_CACHE);
98 } else {
99 // Set the icon to be the default extensions icon.
100 default_icon_ = *ui::ResourceBundle::GetSharedInstance().GetImageNamed(
101 IDR_EXTENSIONS_FAVICON).ToSkBitmap();
102 UpdateState();
sky 2012/07/31 16:25:19 Are you sure you don't still need the call to Upda
Jeffrey Yasskin 2012/07/31 19:53:20 Pretty sure, but not 100%. I believe the only time
103 } 98 }
104 99
105 MaybeRegisterExtensionCommand(); 100 MaybeRegisterExtensionCommand();
106 } 101 }
107 102
108 MenuButton::ViewHierarchyChanged(is_add, parent, child); 103 MenuButton::ViewHierarchyChanged(is_add, parent, child);
109 } 104 }
110 105
111 bool BrowserActionButton::CanHandleAccelerators() const { 106 bool BrowserActionButton::CanHandleAccelerators() const {
112 // View::CanHandleAccelerators() checks to see if the view is visible before 107 // View::CanHandleAccelerators() checks to see if the view is visible before
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 views::MenuRunner::MENU_DELETED) 141 views::MenuRunner::MENU_DELETED)
147 return; 142 return;
148 143
149 SetButtonNotPushed(); 144 SetButtonNotPushed();
150 context_menu_ = NULL; 145 context_menu_ = NULL;
151 } 146 }
152 147
153 void BrowserActionButton::OnImageLoaded(const gfx::Image& image, 148 void BrowserActionButton::OnImageLoaded(const gfx::Image& image,
154 const std::string& extension_id, 149 const std::string& extension_id,
155 int index) { 150 int index) {
156 if (!image.IsEmpty()) 151 browser_action_->CacheIcon(browser_action_->default_icon_path(), image);
157 default_icon_ = *image.ToSkBitmap();
158 152
159 // Call back to UpdateState() because a more specific icon might have been set 153 // Call back to UpdateState() because a more specific icon might have been set
160 // while the load was outstanding. 154 // while the load was outstanding.
161 UpdateState(); 155 UpdateState();
162 } 156 }
163 157
164 void BrowserActionButton::UpdateState() { 158 void BrowserActionButton::UpdateState() {
165 int tab_id = panel_->GetCurrentTabId(); 159 int tab_id = panel_->GetCurrentTabId();
166 if (tab_id < 0) 160 if (tab_id < 0)
167 return; 161 return;
168 162
169 if (!IsEnabled(tab_id)) { 163 if (!IsEnabled(tab_id)) {
170 SetState(views::CustomButton::BS_DISABLED); 164 SetState(views::CustomButton::BS_DISABLED);
171 } else { 165 } else {
172 SetState(menu_visible_ ? 166 SetState(menu_visible_ ?
173 views::CustomButton::BS_PUSHED : 167 views::CustomButton::BS_PUSHED :
174 views::CustomButton::BS_NORMAL); 168 views::CustomButton::BS_NORMAL);
175 } 169 }
176 170
177 SkBitmap icon(browser_action()->GetIcon(tab_id)); 171 SkBitmap icon(*browser_action()->GetIcon(tab_id).ToSkBitmap());
sky 2012/07/31 16:25:19 I believe all this code should be using ImageSkia.
Jeffrey Yasskin 2012/07/31 19:53:20 I believe you're right. However, I don't think thi
178 if (icon.isNull())
179 icon = default_icon_;
180 if (!icon.isNull()) { 172 if (!icon.isNull()) {
181 if (!browser_action()->GetIsVisible(tab_id)) 173 if (!browser_action()->GetIsVisible(tab_id))
182 icon = MakeTransparent(icon); 174 icon = MakeTransparent(icon);
183 SkPaint paint; 175 SkPaint paint;
184 paint.setXfermode(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); 176 paint.setXfermode(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
185 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 177 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
186 178
187 SkBitmap bg; 179 SkBitmap bg;
188 rb.GetBitmapNamed(IDR_BROWSER_ACTION)->copyTo(&bg, 180 rb.GetBitmapNamed(IDR_BROWSER_ACTION)->copyTo(&bg,
189 SkBitmap::kARGB_8888_Config); 181 SkBitmap::kARGB_8888_Config);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 377 }
386 378
387 BrowserActionView::~BrowserActionView() { 379 BrowserActionView::~BrowserActionView() {
388 RemoveChildView(button_); 380 RemoveChildView(button_);
389 button_->Destroy(); 381 button_->Destroy();
390 } 382 }
391 383
392 gfx::Canvas* BrowserActionView::GetIconWithBadge() { 384 gfx::Canvas* BrowserActionView::GetIconWithBadge() {
393 int tab_id = panel_->GetCurrentTabId(); 385 int tab_id = panel_->GetCurrentTabId();
394 386
395 SkBitmap icon = button_->extension()->browser_action()->GetIcon(tab_id); 387 SkBitmap icon = *button_->extension()->browser_action()->GetIcon(
396 if (icon.isNull()) 388 tab_id).ToSkBitmap();
397 icon = button_->default_icon();
398 389
399 // Dim the icon if our button is disabled. 390 // Dim the icon if our button is disabled.
400 if (!button_->IsEnabled(tab_id)) 391 if (!button_->IsEnabled(tab_id))
401 icon = MakeTransparent(icon); 392 icon = MakeTransparent(icon);
402 393
403 gfx::Canvas* canvas = 394 gfx::Canvas* canvas =
404 new gfx::Canvas(gfx::ImageSkiaRep(icon, ui::SCALE_FACTOR_100P), false); 395 new gfx::Canvas(gfx::ImageSkiaRep(icon, ui::SCALE_FACTOR_100P), false);
405 396
406 if (tab_id >= 0) { 397 if (tab_id >= 0) {
407 gfx::Rect bounds(icon.width(), icon.height() + ToolbarView::kVertSpacing); 398 gfx::Rect bounds(icon.width(), icon.height() + ToolbarView::kVertSpacing);
(...skipping 21 matching lines...) Expand all
429 state->role = ui::AccessibilityTypes::ROLE_GROUPING; 420 state->role = ui::AccessibilityTypes::ROLE_GROUPING;
430 } 421 }
431 422
432 void BrowserActionView::PaintChildren(gfx::Canvas* canvas) { 423 void BrowserActionView::PaintChildren(gfx::Canvas* canvas) {
433 View::PaintChildren(canvas); 424 View::PaintChildren(canvas);
434 ExtensionAction* action = button()->browser_action(); 425 ExtensionAction* action = button()->browser_action();
435 int tab_id = panel_->GetCurrentTabId(); 426 int tab_id = panel_->GetCurrentTabId();
436 if (tab_id >= 0) 427 if (tab_id >= 0)
437 action->PaintBadge(canvas, gfx::Rect(width(), height()), tab_id); 428 action->PaintBadge(canvas, gfx::Rect(width(), height()), tab_id);
438 } 429 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/browser_action_view.h ('k') | chrome/browser/ui/views/location_bar/page_action_image_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698