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

Side by Side Diff: chrome/browser/ui/views/location_bar/page_action_image_view.cc

Issue 10827191: Convert extension action icons code to use ImageSkia instead of SkBitmap (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: some nits 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/location_bar/page_action_image_view.h" 5 #include "chrome/browser/ui/views/location_bar/page_action_image_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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 // We loaded icons()->size() icons, plus one extra if the page action had 201 // We loaded icons()->size() icons, plus one extra if the page action had
202 // a default icon. 202 // a default icon.
203 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); 203 int total_icons = static_cast<int>(page_action_->icon_paths()->size());
204 if (!page_action_->default_icon_path().empty()) 204 if (!page_action_->default_icon_path().empty())
205 total_icons++; 205 total_icons++;
206 DCHECK(index < total_icons); 206 DCHECK(index < total_icons);
207 207
208 // Map the index of the loaded image back to its name. If we ever get an 208 // Map the index of the loaded image back to its name. If we ever get an
209 // index greater than the number of icons, it must be the default icon. 209 // index greater than the number of icons, it must be the default icon.
210 if (index < static_cast<int>(page_action_->icon_paths()->size())) 210 if (index < static_cast<int>(page_action_->icon_paths()->size()))
211 page_action_->CacheIcon(page_action_->icon_paths()->at(index), image); 211 page_action_->CacheIcon(page_action_->icon_paths()->at(index),
212 *image.ToImageSkia());
212 else 213 else
213 page_action_->CacheIcon(page_action_->default_icon_path(), image); 214 page_action_->CacheIcon(page_action_->default_icon_path(),
215 *image.ToImageSkia());
214 216
215 // During object construction owner_ will be NULL. 217 // During object construction owner_ will be NULL.
216 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL; 218 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL;
217 if (tab_contents) 219 if (tab_contents)
218 UpdateVisibility(tab_contents->web_contents(), current_url_); 220 UpdateVisibility(tab_contents->web_contents(), current_url_);
219 } 221 }
220 222
221 void PageActionImageView::ShowContextMenuForView(View* source, 223 void PageActionImageView::ShowContextMenuForView(View* source,
222 const gfx::Point& point) { 224 const gfx::Point& point) {
223 const Extension* extension = owner_->profile()->GetExtensionService()-> 225 const Extension* extension = owner_->profile()->GetExtensionService()->
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 (!preview_enabled_ && !page_action_->GetIsVisible(current_tab_id_))) { 264 (!preview_enabled_ && !page_action_->GetIsVisible(current_tab_id_))) {
263 SetVisible(false); 265 SetVisible(false);
264 return; 266 return;
265 } 267 }
266 268
267 // Set the tooltip. 269 // Set the tooltip.
268 tooltip_ = page_action_->GetTitle(current_tab_id_); 270 tooltip_ = page_action_->GetTitle(current_tab_id_);
269 SetTooltipText(UTF8ToUTF16(tooltip_)); 271 SetTooltipText(UTF8ToUTF16(tooltip_));
270 272
271 // Set the image. 273 // Set the image.
272 gfx::Image icon = page_action_->GetIcon(current_tab_id_); 274 gfx::ImageSkia icon = page_action_->GetIcon(current_tab_id_);
273 if (!icon.IsEmpty()) { 275 if (!icon.empty())
274 SetImage(*icon.ToImageSkia()); 276 SetImage(icon);
275 }
276 277
277 SetVisible(true); 278 SetVisible(true);
278 } 279 }
279 280
280 void PageActionImageView::OnWidgetClosing(views::Widget* widget) { 281 void PageActionImageView::OnWidgetClosing(views::Widget* widget) {
281 DCHECK_EQ(popup_->GetWidget(), widget); 282 DCHECK_EQ(popup_->GetWidget(), widget);
282 popup_->GetWidget()->RemoveObserver(this); 283 popup_->GetWidget()->RemoveObserver(this);
283 popup_ = NULL; 284 popup_ = NULL;
284 } 285 }
285 286
(...skipping 28 matching lines...) Expand all
314 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; 315 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT;
315 316
316 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location); 317 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location);
317 popup_->GetWidget()->AddObserver(this); 318 popup_->GetWidget()->AddObserver(this);
318 } 319 }
319 320
320 void PageActionImageView::HidePopup() { 321 void PageActionImageView::HidePopup() {
321 if (popup_) 322 if (popup_)
322 popup_->GetWidget()->Close(); 323 popup_->GetWidget()->Close();
323 } 324 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698