Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/app_list/extension_app_item.h" | 5 #include "chrome/browser/ui/app_list/extension_app_item.h" |
| 6 | 6 |
| 7 #include "chrome/app/chrome_command_ids.h" | 7 #include "chrome/app/chrome_command_ids.h" |
| 8 #include "chrome/browser/extensions/context_menu_matcher.h" | 8 #include "chrome/browser/extensions/context_menu_matcher.h" |
| 9 #include "chrome/browser/extensions/extension_prefs.h" | 9 #include "chrome/browser/extensions/extension_prefs.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/extension_sorting.h" | 11 #include "chrome/browser/extensions/extension_sorting.h" |
| 12 #include "chrome/browser/extensions/extension_system.h" | 12 #include "chrome/browser/extensions/extension_system.h" |
| 13 #include "chrome/browser/extensions/extension_uninstall_dialog.h" | 13 #include "chrome/browser/extensions/extension_uninstall_dialog.h" |
| 14 #include "chrome/browser/extensions/management_policy.h" | 14 #include "chrome/browser/extensions/management_policy.h" |
| 15 #include "chrome/browser/prefs/incognito_mode_prefs.h" | 15 #include "chrome/browser/prefs/incognito_mode_prefs.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/ui/app_list/app_list_controller.h" | 17 #include "chrome/browser/ui/app_list/app_list_controller.h" |
| 18 #include "chrome/browser/ui/browser.h" | 18 #include "chrome/browser/ui/browser.h" |
| 19 #include "chrome/browser/ui/browser_navigator.h" | 19 #include "chrome/browser/ui/browser_navigator.h" |
| 20 #include "chrome/browser/ui/browser_tabstrip.h" | 20 #include "chrome/browser/ui/browser_tabstrip.h" |
| 21 #include "chrome/browser/ui/browser_window.h" | 21 #include "chrome/browser/ui/browser_window.h" |
| 22 #include "chrome/common/extensions/extension.h" | 22 #include "chrome/common/extensions/extension.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | 23 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "chrome/common/extensions/extension_icon_set.h" | 24 #include "chrome/common/extensions/extension_icon_set.h" |
| 25 #include "content/public/common/context_menu_params.h" | 25 #include "content/public/common/context_menu_params.h" |
| 26 #include "grit/chromium_strings.h" | 26 #include "grit/chromium_strings.h" |
| 27 #include "grit/generated_resources.h" | 27 #include "grit/generated_resources.h" |
| 28 #include "grit/theme_resources.h" | |
| 28 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | |
| 31 #include "ui/gfx/canvas.h" | |
| 29 #include "ui/gfx/image/image.h" | 32 #include "ui/gfx/image/image.h" |
| 30 | 33 |
| 31 using extensions::Extension; | 34 using extensions::Extension; |
| 32 | 35 |
| 33 namespace { | 36 namespace { |
| 34 | 37 |
| 35 enum CommandId { | 38 enum CommandId { |
| 36 LAUNCH_NEW = 100, | 39 LAUNCH_NEW = 100, |
| 37 TOGGLE_PIN, | 40 TOGGLE_PIN, |
| 38 CREATE_SHORTCUTS, | 41 CREATE_SHORTCUTS, |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 // Otherwise, go with |next|. This is okay because app list does not split | 208 // Otherwise, go with |next|. This is okay because app list does not split |
| 206 // page based ntp page ordinal. | 209 // page based ntp page ordinal. |
| 207 // TODO(xiyuan): Revisit this when implementing paging support. | 210 // TODO(xiyuan): Revisit this when implementing paging support. |
| 208 GetExtensionSorting(profile_)->SetPageOrdinal(extension_id_, prev_page); | 211 GetExtensionSorting(profile_)->SetPageOrdinal(extension_id_, prev_page); |
| 209 service->OnExtensionMoved(extension_id_, | 212 service->OnExtensionMoved(extension_id_, |
| 210 prev->extension_id(), | 213 prev->extension_id(), |
| 211 std::string()); | 214 std::string()); |
| 212 } | 215 } |
| 213 | 216 |
| 214 void ExtensionAppItem::LoadImage(const Extension* extension) { | 217 void ExtensionAppItem::LoadImage(const Extension* extension) { |
| 218 int icon_size = extension_misc::EXTENSION_ICON_MEDIUM; | |
| 219 if (HasOverlay()) | |
| 220 icon_size = extension_misc::EXTENSION_ICON_SMALL; | |
| 221 | |
| 215 icon_.reset(new extensions::IconImage( | 222 icon_.reset(new extensions::IconImage( |
| 216 extension, | 223 extension, |
| 217 extension->icons(), | 224 extension->icons(), |
| 218 extension_misc::EXTENSION_ICON_MEDIUM, | 225 icon_size, |
| 219 Extension::GetDefaultIcon(true), | 226 Extension::GetDefaultIcon(true), |
| 220 this)); | 227 this)); |
| 221 SetIcon(icon_->image_skia()); | 228 SetIconWithOverlay(icon_->image_skia()); |
| 229 } | |
| 230 | |
| 231 bool ExtensionAppItem::HasOverlay() { | |
| 232 return !GetExtension()->is_platform_app(); | |
| 233 } | |
| 234 | |
| 235 void ExtensionAppItem::SetIconWithOverlay(const gfx::ImageSkia& icon) { | |
| 236 using extension_misc::EXTENSION_ICON_SMALL; | |
| 237 using extension_misc::EXTENSION_ICON_MEDIUM; | |
| 238 | |
| 239 if (!HasOverlay()) { | |
| 240 SetIcon(icon); | |
| 241 return; | |
| 242 } | |
| 243 | |
| 244 const int kIconOffset = (EXTENSION_ICON_MEDIUM - EXTENSION_ICON_SMALL) / 2; | |
| 245 | |
| 246 // The tab overlay is not vertically symmetric, to position the app in the | |
| 247 // middle of the overlay we need a slight adjustment. | |
| 248 const int kVerticalAdjust = 2; | |
| 249 gfx::Canvas icon_canvas(gfx::Size(EXTENSION_ICON_MEDIUM, | |
| 250 EXTENSION_ICON_MEDIUM), | |
| 251 ui::SCALE_FACTOR_100P, false); | |
|
xiyuan
2012/12/12 17:12:43
This does not work properly on HiDPI. I think you
benwells
2012/12/13 06:38:27
Yep, thanks for that. For now I'm just going to ha
xiyuan
2012/12/13 17:26:54
CanvasImageSource is cross platform and we should
| |
| 252 icon_canvas.DrawImageInt(icon, kIconOffset, kIconOffset + kVerticalAdjust); | |
| 253 icon_canvas.DrawImageInt( | |
| 254 *ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 255 IDR_APP_LIST_TAB_OVERLAY), | |
| 256 0, 0); | |
|
xiyuan
2012/12/12 17:12:43
Should we draw the tab first since it is bigger an
benwells
2012/12/13 06:38:27
I've switched it around. It does make a slight dif
| |
| 257 SetIcon(gfx::ImageSkia(icon_canvas.ExtractImageRep())); | |
| 222 } | 258 } |
| 223 | 259 |
| 224 void ExtensionAppItem::ShowExtensionOptions() { | 260 void ExtensionAppItem::ShowExtensionOptions() { |
| 225 const Extension* extension = GetExtension(); | 261 const Extension* extension = GetExtension(); |
| 226 if (!extension) | 262 if (!extension) |
| 227 return; | 263 return; |
| 228 | 264 |
| 229 chrome::NavigateParams params(profile_, | 265 chrome::NavigateParams params(profile_, |
| 230 extension->options_url(), | 266 extension->options_url(), |
| 231 content::PAGE_TRANSITION_LINK); | 267 content::PAGE_TRANSITION_LINK); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 247 // ExtensionUninstall deletes itself when done or aborted. | 283 // ExtensionUninstall deletes itself when done or aborted. |
| 248 ExtensionUninstaller* uninstaller = new ExtensionUninstaller(profile_, | 284 ExtensionUninstaller* uninstaller = new ExtensionUninstaller(profile_, |
| 249 extension_id_, | 285 extension_id_, |
| 250 controller_); | 286 controller_); |
| 251 uninstaller->Run(); | 287 uninstaller->Run(); |
| 252 } | 288 } |
| 253 | 289 |
| 254 void ExtensionAppItem::OnExtensionIconImageChanged( | 290 void ExtensionAppItem::OnExtensionIconImageChanged( |
| 255 extensions::IconImage* image) { | 291 extensions::IconImage* image) { |
| 256 DCHECK(icon_.get() == image); | 292 DCHECK(icon_.get() == image); |
| 257 SetIcon(icon_->image_skia()); | 293 SetIconWithOverlay(icon_->image_skia()); |
| 258 } | 294 } |
| 259 | 295 |
| 260 bool ExtensionAppItem::IsItemForCommandIdDynamic(int command_id) const { | 296 bool ExtensionAppItem::IsItemForCommandIdDynamic(int command_id) const { |
| 261 return command_id == TOGGLE_PIN || command_id == LAUNCH_NEW; | 297 return command_id == TOGGLE_PIN || command_id == LAUNCH_NEW; |
| 262 } | 298 } |
| 263 | 299 |
| 264 string16 ExtensionAppItem::GetLabelForCommandId(int command_id) const { | 300 string16 ExtensionAppItem::GetLabelForCommandId(int command_id) const { |
| 265 if (command_id == TOGGLE_PIN) { | 301 if (command_id == TOGGLE_PIN) { |
| 266 return controller_->IsAppPinned(extension_id_) ? | 302 return controller_->IsAppPinned(extension_id_) ? |
| 267 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_UNPIN) : | 303 l10n_util::GetStringUTF16(IDS_APP_LIST_CONTEXT_MENU_UNPIN) : |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 455 } | 491 } |
| 456 | 492 |
| 457 context_menu_model_->AddItemWithStringId(UNINSTALL, | 493 context_menu_model_->AddItemWithStringId(UNINSTALL, |
| 458 extension->is_platform_app() ? | 494 extension->is_platform_app() ? |
| 459 IDS_APP_LIST_UNINSTALL_ITEM : | 495 IDS_APP_LIST_UNINSTALL_ITEM : |
| 460 IDS_EXTENSIONS_UNINSTALL); | 496 IDS_EXTENSIONS_UNINSTALL); |
| 461 } | 497 } |
| 462 | 498 |
| 463 return context_menu_model_.get(); | 499 return context_menu_model_.get(); |
| 464 } | 500 } |
| OLD | NEW |