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

Side by Side Diff: chrome/browser/ui/toolbar/back_forward_menu_model.cc

Issue 10824402: Convert ui::MenuModel to use gfx::Image instead of ImageSkia. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Another day, another rebase 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 "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h" 7 #include "chrome/browser/ui/toolbar/back_forward_menu_model.h"
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 } 126 }
127 127
128 bool BackForwardMenuModel::IsItemCheckedAt(int index) const { 128 bool BackForwardMenuModel::IsItemCheckedAt(int index) const {
129 return false; 129 return false;
130 } 130 }
131 131
132 int BackForwardMenuModel::GetGroupIdAt(int index) const { 132 int BackForwardMenuModel::GetGroupIdAt(int index) const {
133 return false; 133 return false;
134 } 134 }
135 135
136 bool BackForwardMenuModel::GetIconAt(int index, gfx::ImageSkia* icon) { 136 bool BackForwardMenuModel::GetIconAt(int index, gfx::Image* icon) {
137 if (!ItemHasIcon(index)) 137 if (!ItemHasIcon(index))
138 return false; 138 return false;
139 139
140 if (index == GetItemCount() - 1) { 140 if (index == GetItemCount() - 1) {
141 *icon = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 141 *icon = ResourceBundle::GetSharedInstance().GetNativeImageNamed(
142 IDR_HISTORY_FAVICON); 142 IDR_HISTORY_FAVICON);
143 } else { 143 } else {
144 NavigationEntry* entry = GetNavigationEntry(index); 144 NavigationEntry* entry = GetNavigationEntry(index);
145 *icon = *entry->GetFavicon().image.ToImageSkia(); 145 *icon = entry->GetFavicon().image;
146 if (!entry->GetFavicon().valid && menu_model_delegate()) { 146 if (!entry->GetFavicon().valid && menu_model_delegate()) {
147 FetchFavicon(entry); 147 FetchFavicon(entry);
148 } 148 }
149 } 149 }
150 150
151 return true; 151 return true;
152 } 152 }
153 153
154 ui::ButtonMenuItemModel* BackForwardMenuModel::GetButtonMenuItemAt( 154 ui::ButtonMenuItemModel* BackForwardMenuModel::GetButtonMenuItemAt(
155 int index) const { 155 int index) const {
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 } 270 }
271 271
272 if (!entry) 272 if (!entry)
273 // The NavigationEntry wasn't found, this can happen if the user 273 // The NavigationEntry wasn't found, this can happen if the user
274 // navigates to another page and a NavigatationEntry falls out of the 274 // navigates to another page and a NavigatationEntry falls out of the
275 // range of kMaxHistoryItems. 275 // range of kMaxHistoryItems.
276 return; 276 return;
277 277
278 // Now that we have a valid NavigationEntry, decode the favicon and assign 278 // Now that we have a valid NavigationEntry, decode the favicon and assign
279 // it to the NavigationEntry. 279 // it to the NavigationEntry.
280 SkBitmap fav_icon; 280 gfx::Image icon(favicon.image_data->front(), favicon.image_data->size());
281 if (gfx::PNGCodec::Decode(favicon.image_data->front(), 281 if (!icon.IsEmpty()) {
282 favicon.image_data->size(),
283 &fav_icon)) {
284 entry->GetFavicon().valid = true; 282 entry->GetFavicon().valid = true;
285 entry->GetFavicon().url = favicon.icon_url; 283 entry->GetFavicon().url = favicon.icon_url;
286 if (fav_icon.empty())
287 return;
288 // TODO: Once the history service returns more representations, 284 // TODO: Once the history service returns more representations,
289 // use them all instead of having just the lodpi favicon. 285 // use them all instead of having just the lodpi favicon.
290 entry->GetFavicon().image = gfx::Image(fav_icon); 286 entry->GetFavicon().image = icon;
291 if (menu_model_delegate()) { 287 if (menu_model_delegate()) {
292 menu_model_delegate()->OnIconChanged(model_index); 288 menu_model_delegate()->OnIconChanged(model_index);
293 } 289 }
294 } 290 }
295 } 291 }
296 } 292 }
297 293
298 int BackForwardMenuModel::GetHistoryItemCount() const { 294 int BackForwardMenuModel::GetHistoryItemCount() const {
299 WebContents* contents = GetWebContents(); 295 WebContents* contents = GetWebContents();
300 int items = 0; 296 int items = 0;
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 metric_string += "ForwardMenu_"; 466 metric_string += "ForwardMenu_";
471 else 467 else
472 metric_string += "BackMenu_"; 468 metric_string += "BackMenu_";
473 metric_string += action; 469 metric_string += action;
474 if (index != -1) { 470 if (index != -1) {
475 // +1 is for historical reasons (indices used to start at 1). 471 // +1 is for historical reasons (indices used to start at 1).
476 metric_string += base::IntToString(index + 1); 472 metric_string += base::IntToString(index + 1);
477 } 473 }
478 return metric_string; 474 return metric_string;
479 } 475 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/toolbar/back_forward_menu_model.h ('k') | chrome/browser/ui/toolbar/back_forward_menu_model_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698