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

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: Fix kalman's comments. 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/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();
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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 if (!image.IsEmpty())
157 default_icon_ = *image.ToSkBitmap(); 152 loaded_icons_[browser_action_->default_icon_path()] = image;
158 153
159 // Call back to UpdateState() because a more specific icon might have been set 154 // Call back to UpdateState() because a more specific icon might have been set
160 // while the load was outstanding. 155 // while the load was outstanding.
161 UpdateState(); 156 UpdateState();
162 } 157 }
163 158
164 void BrowserActionButton::UpdateState() { 159 void BrowserActionButton::UpdateState() {
165 int tab_id = panel_->GetCurrentTabId(); 160 int tab_id = panel_->GetCurrentTabId();
166 if (tab_id < 0) 161 if (tab_id < 0)
167 return; 162 return;
168 163
169 if (!IsEnabled(tab_id)) { 164 if (!IsEnabled(tab_id)) {
170 SetState(views::CustomButton::BS_DISABLED); 165 SetState(views::CustomButton::BS_DISABLED);
171 } else { 166 } else {
172 SetState(menu_visible_ ? 167 SetState(menu_visible_ ?
173 views::CustomButton::BS_PUSHED : 168 views::CustomButton::BS_PUSHED :
174 views::CustomButton::BS_NORMAL); 169 views::CustomButton::BS_NORMAL);
175 } 170 }
176 171
177 SkBitmap icon(browser_action()->GetIcon(tab_id)); 172 SkBitmap icon(*browser_action()->GetIcon(tab_id, loaded_icons_).ToSkBitmap());
178 if (icon.isNull())
179 icon = default_icon_;
180 if (!icon.isNull()) { 173 if (!icon.isNull()) {
181 if (!browser_action()->GetIsVisible(tab_id)) 174 if (!browser_action()->GetIsVisible(tab_id))
182 icon = MakeTransparent(icon); 175 icon = MakeTransparent(icon);
183 SkPaint paint; 176 SkPaint paint;
184 paint.setXfermode(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); 177 paint.setXfermode(SkXfermode::Create(SkXfermode::kSrcOver_Mode));
185 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 178 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
186 179
187 SkBitmap bg; 180 SkBitmap bg;
188 rb.GetBitmapNamed(IDR_BROWSER_ACTION)->copyTo(&bg, 181 rb.GetBitmapNamed(IDR_BROWSER_ACTION)->copyTo(&bg,
189 SkBitmap::kARGB_8888_Config); 182 SkBitmap::kARGB_8888_Config);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 378 }
386 379
387 BrowserActionView::~BrowserActionView() { 380 BrowserActionView::~BrowserActionView() {
388 RemoveChildView(button_); 381 RemoveChildView(button_);
389 button_->Destroy(); 382 button_->Destroy();
390 } 383 }
391 384
392 gfx::Canvas* BrowserActionView::GetIconWithBadge() { 385 gfx::Canvas* BrowserActionView::GetIconWithBadge() {
393 int tab_id = panel_->GetCurrentTabId(); 386 int tab_id = panel_->GetCurrentTabId();
394 387
395 SkBitmap icon = button_->extension()->browser_action()->GetIcon(tab_id); 388 SkBitmap icon = *button_->extension()->browser_action()->GetIcon(
396 if (icon.isNull()) 389 tab_id, button_->loaded_icons()).ToSkBitmap();
397 icon = button_->default_icon();
398 390
399 // Dim the icon if our button is disabled. 391 // Dim the icon if our button is disabled.
400 if (!button_->IsEnabled(tab_id)) 392 if (!button_->IsEnabled(tab_id))
401 icon = MakeTransparent(icon); 393 icon = MakeTransparent(icon);
402 394
403 gfx::Canvas* canvas = 395 gfx::Canvas* canvas =
404 new gfx::Canvas(gfx::ImageSkiaRep(icon, ui::SCALE_FACTOR_100P), false); 396 new gfx::Canvas(gfx::ImageSkiaRep(icon, ui::SCALE_FACTOR_100P), false);
405 397
406 if (tab_id >= 0) { 398 if (tab_id >= 0) {
407 gfx::Rect bounds(icon.width(), icon.height() + ToolbarView::kVertSpacing); 399 gfx::Rect bounds(icon.width(), icon.height() + ToolbarView::kVertSpacing);
(...skipping 21 matching lines...) Expand all
429 state->role = ui::AccessibilityTypes::ROLE_GROUPING; 421 state->role = ui::AccessibilityTypes::ROLE_GROUPING;
430 } 422 }
431 423
432 void BrowserActionView::PaintChildren(gfx::Canvas* canvas) { 424 void BrowserActionView::PaintChildren(gfx::Canvas* canvas) {
433 View::PaintChildren(canvas); 425 View::PaintChildren(canvas);
434 ExtensionAction* action = button()->browser_action(); 426 ExtensionAction* action = button()->browser_action();
435 int tab_id = panel_->GetCurrentTabId(); 427 int tab_id = panel_->GetCurrentTabId();
436 if (tab_id >= 0) 428 if (tab_id >= 0)
437 action->PaintBadge(canvas, gfx::Rect(width(), height()), tab_id); 429 action->PaintBadge(canvas, gfx::Rect(width(), height()), tab_id);
438 } 430 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698