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

Side by Side Diff: chrome/browser/ui/views/location_bar/page_action_image_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/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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 // We loaded icons()->size() icons, plus one extra if the page action had 175 // We loaded icons()->size() icons, plus one extra if the page action had
176 // a default icon. 176 // a default icon.
177 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); 177 int total_icons = static_cast<int>(page_action_->icon_paths()->size());
178 if (!page_action_->default_icon_path().empty()) 178 if (!page_action_->default_icon_path().empty())
179 total_icons++; 179 total_icons++;
180 DCHECK(index < total_icons); 180 DCHECK(index < total_icons);
181 181
182 // Map the index of the loaded image back to its name. If we ever get an 182 // Map the index of the loaded image back to its name. If we ever get an
183 // index greater than the number of icons, it must be the default icon. 183 // index greater than the number of icons, it must be the default icon.
184 if (!image.IsEmpty()) { 184 if (!image.IsEmpty()) {
185 const SkBitmap* bitmap = image.ToSkBitmap();
186 if (index < static_cast<int>(page_action_->icon_paths()->size())) 185 if (index < static_cast<int>(page_action_->icon_paths()->size()))
187 page_action_icons_[page_action_->icon_paths()->at(index)] = *bitmap; 186 page_action_icons_[page_action_->icon_paths()->at(index)] = image;
188 else 187 else
189 page_action_icons_[page_action_->default_icon_path()] = *bitmap; 188 page_action_icons_[page_action_->default_icon_path()] = image;
190 } 189 }
191 190
192 // During object construction owner_ will be NULL. 191 // During object construction owner_ will be NULL.
193 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL; 192 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL;
194 if (tab_contents) 193 if (tab_contents)
195 UpdateVisibility(tab_contents->web_contents(), current_url_); 194 UpdateVisibility(tab_contents->web_contents(), current_url_);
196 } 195 }
197 196
198 void PageActionImageView::ShowContextMenuForView(View* source, 197 void PageActionImageView::ShowContextMenuForView(View* source,
199 const gfx::Point& point) { 198 const gfx::Point& point) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 (!preview_enabled_ && !page_action_->GetIsVisible(current_tab_id_))) { 238 (!preview_enabled_ && !page_action_->GetIsVisible(current_tab_id_))) {
240 SetVisible(false); 239 SetVisible(false);
241 return; 240 return;
242 } 241 }
243 242
244 // Set the tooltip. 243 // Set the tooltip.
245 tooltip_ = page_action_->GetTitle(current_tab_id_); 244 tooltip_ = page_action_->GetTitle(current_tab_id_);
246 SetTooltipText(UTF8ToUTF16(tooltip_)); 245 SetTooltipText(UTF8ToUTF16(tooltip_));
247 246
248 // Set the image. 247 // Set the image.
249 // It can come from three places. In descending order of priority: 248 gfx::Image icon = page_action_->GetIcon(current_tab_id_, page_action_icons_);
250 // - The developer can set it dynamically by path or bitmap. It will be in 249 if (!icon.IsEmpty()) {
251 // page_action_->GetIcon(). 250 SetImage(*icon.ToImageSkia());
252 // - The developer can set it dynamically by index. It will be in
253 // page_action_->GetIconIndex().
254 // - It can be set in the manifest by path. It will be in
255 // page_action_->default_icon_path().
256
257 // First look for a dynamically set bitmap.
258 SkBitmap icon = page_action_->GetIcon(current_tab_id_);
259 if (icon.isNull()) {
260 int icon_index = page_action_->GetIconIndex(current_tab_id_);
261 std::string icon_path = (icon_index < 0) ?
262 page_action_->default_icon_path() :
263 page_action_->icon_paths()->at(icon_index);
264 if (!icon_path.empty()) {
265 PageActionMap::iterator iter = page_action_icons_.find(icon_path);
266 if (iter != page_action_icons_.end())
267 icon = iter->second;
268 }
269 }
270
271 if (!icon.isNull()) {
272 const ExtensionAction::IconAnimation* icon_animation =
273 scoped_icon_animation_observer_.icon_animation();
274 if (icon_animation)
275 icon = icon_animation->Apply(icon);
276 SetImage(icon);
277 } 251 }
278 252
279 SetVisible(true); 253 SetVisible(true);
280 } 254 }
281 255
282 void PageActionImageView::OnWidgetClosing(views::Widget* widget) { 256 void PageActionImageView::OnWidgetClosing(views::Widget* widget) {
283 DCHECK_EQ(popup_->GetWidget(), widget); 257 DCHECK_EQ(popup_->GetWidget(), widget);
284 popup_->GetWidget()->RemoveObserver(this); 258 popup_->GetWidget()->RemoveObserver(this);
285 popup_ = NULL; 259 popup_ = NULL;
286 } 260 }
(...skipping 29 matching lines...) Expand all
316 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; 290 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT;
317 291
318 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location); 292 popup_ = ExtensionPopup::ShowPopup(popup_url, browser_, this, arrow_location);
319 popup_->GetWidget()->AddObserver(this); 293 popup_->GetWidget()->AddObserver(this);
320 } 294 }
321 295
322 void PageActionImageView::HidePopup() { 296 void PageActionImageView::HidePopup() {
323 if (popup_) 297 if (popup_)
324 popup_->GetWidget()->Close(); 298 popup_->GetWidget()->Close();
325 } 299 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698