Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ash/launcher/extension_app_window_launcher_item_cont roller.h" | 5 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont roller.h" |
| 6 | 6 |
| 7 #include "ash/common/wm/window_state.h" | 7 #include "ash/common/wm/window_state.h" |
| 8 #include "ash/wm/window_state_aura.h" | 8 #include "ash/wm/window_state_aura.h" |
| 9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 13 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | 13 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
| 14 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" | 14 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" |
| 15 #include "components/favicon/content/content_favicon_driver.h" | 15 #include "components/favicon/content/content_favicon_driver.h" |
| 16 #include "content/public/browser/web_contents.h" | 16 #include "content/public/browser/web_contents.h" |
| 17 #include "extensions/browser/app_window/app_window.h" | 17 #include "extensions/browser/app_window/app_window.h" |
| 18 #include "extensions/browser/app_window/app_window_registry.h" | |
| 18 #include "extensions/browser/app_window/native_app_window.h" | 19 #include "extensions/browser/app_window/native_app_window.h" |
| 19 #include "skia/ext/image_operations.h" | |
| 20 #include "ui/aura/client/aura_constants.h" | 20 #include "ui/aura/client/aura_constants.h" |
| 21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 22 #include "ui/events/event.h" | 22 #include "ui/events/event.h" |
| 23 #include "ui/gfx/image/image_skia.h" | 23 #include "ui/gfx/image/image.h" |
| 24 #include "ui/wm/core/window_animations.h" | 24 #include "ui/wm/core/window_animations.h" |
| 25 | 25 |
| 26 namespace { | |
| 27 | |
| 28 // Size of the icon in the shelf launcher in display-independent pixels. | |
| 29 const int kAppListIconSize = 24; | |
| 30 | |
| 31 // This will return a slightly smaller icon than the app icon to be used in | |
| 32 // the application list menu. | |
| 33 gfx::Image GetAppListIcon(extensions::AppWindow* app_window) { | |
| 34 // TODO(skuhne): We instead might want to use LoadImages in | |
| 35 // AppWindow::UpdateExtensionAppIcon() to let the extension give us | |
| 36 // pre-defined icons in the launcher and the launcher list sizes. Since there | |
| 37 // is no mock yet, doing this now seems a bit premature and we scale for the | |
| 38 // time being. | |
| 39 if (app_window->app_icon().IsEmpty()) | |
| 40 return gfx::Image(); | |
| 41 | |
| 42 SkBitmap bmp = skia::ImageOperations::Resize( | |
|
James Cook
2017/03/01 19:50:48
So this stuff isn't necessary any more? Are there
msw
2017/03/02 02:59:20
AFAICT, MenuItemView correctly clamps the icon's p
| |
| 43 *app_window->app_icon().ToSkBitmap(), skia::ImageOperations::RESIZE_BEST, | |
| 44 kAppListIconSize, kAppListIconSize); | |
| 45 return gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(bmp)); | |
| 46 } | |
| 47 | |
| 48 } // namespace | |
| 49 | |
| 50 ExtensionAppWindowLauncherItemController:: | 26 ExtensionAppWindowLauncherItemController:: |
| 51 ExtensionAppWindowLauncherItemController( | 27 ExtensionAppWindowLauncherItemController( |
| 52 const std::string& app_id, | 28 const std::string& app_id, |
| 53 const std::string& launch_id, | 29 const std::string& launch_id, |
| 54 ChromeLauncherController* controller) | 30 ChromeLauncherController* controller) |
| 55 : AppWindowLauncherItemController(app_id, launch_id, controller) {} | 31 : AppWindowLauncherItemController(app_id, launch_id, controller) {} |
| 56 | 32 |
| 57 ExtensionAppWindowLauncherItemController:: | 33 ExtensionAppWindowLauncherItemController:: |
| 58 ~ExtensionAppWindowLauncherItemController() {} | 34 ~ExtensionAppWindowLauncherItemController() {} |
| 59 | 35 |
| 60 void ExtensionAppWindowLauncherItemController::AddAppWindow( | 36 void ExtensionAppWindowLauncherItemController::AddAppWindow( |
| 61 extensions::AppWindow* app_window) { | 37 extensions::AppWindow* app_window) { |
| 62 DCHECK(!app_window->window_type_is_panel()); | 38 DCHECK(!app_window->window_type_is_panel()); |
| 63 DCHECK(window_to_app_window_.find(app_window->GetBaseWindow()) == | |
| 64 window_to_app_window_.end()); | |
| 65 AddWindow(app_window->GetBaseWindow()); | 39 AddWindow(app_window->GetBaseWindow()); |
| 66 window_to_app_window_[app_window->GetBaseWindow()] = app_window; | |
| 67 } | 40 } |
| 68 | 41 |
| 69 ash::ShelfAppMenuItemList | 42 ash::ShelfAppMenuItemList |
| 70 ExtensionAppWindowLauncherItemController::GetAppMenuItems(int event_flags) { | 43 ExtensionAppWindowLauncherItemController::GetAppMenuItems(int event_flags) { |
| 71 ash::ShelfAppMenuItemList items; | 44 ash::ShelfAppMenuItemList items; |
| 72 int index = 0; | 45 CHECK_LT(windows().size(), std::numeric_limits<uint32_t>::max()); |
| 73 for (const auto* window : windows()) { | 46 extensions::AppWindowRegistry* app_window_registry = |
| 74 extensions::AppWindow* app_window = window_to_app_window_[window]; | 47 extensions::AppWindowRegistry::Get(launcher_controller()->profile()); |
| 48 | |
| 49 uint32_t window_index = 0; | |
| 50 for (const ui::BaseWindow* window : windows()) { | |
| 51 extensions::AppWindow* app_window = | |
| 52 app_window_registry->GetAppWindowForNativeWindow( | |
| 53 window->GetNativeWindow()); | |
| 75 DCHECK(app_window); | 54 DCHECK(app_window); |
| 76 | 55 |
| 77 // If the app's web contents provides a favicon, use it. Otherwise, use a | 56 // Use the app's web contents favicon, or the app window's icon. |
| 78 // scaled down app icon. | |
| 79 favicon::FaviconDriver* favicon_driver = | 57 favicon::FaviconDriver* favicon_driver = |
| 80 favicon::ContentFaviconDriver::FromWebContents( | 58 favicon::ContentFaviconDriver::FromWebContents( |
| 81 app_window->web_contents()); | 59 app_window->web_contents()); |
| 82 gfx::Image result = favicon_driver->GetFavicon(); | 60 gfx::Image icon = favicon_driver->GetFavicon(); |
| 83 if (result.IsEmpty()) | 61 if (icon.IsEmpty()) |
| 84 result = GetAppListIcon(app_window); | 62 icon = app_window->app_icon(); |
| 85 | 63 |
| 86 items.push_back(base::MakeUnique<ChromeLauncherAppMenuItemV2App>( | 64 items.push_back(base::MakeUnique<ash::ShelfApplicationMenuItem>( |
| 87 app_window->GetTitle(), | 65 window_index, app_window->GetTitle(), &icon)); |
| 88 &result, // Will be copied | 66 ++window_index; |
| 89 app_id(), launcher_controller(), index)); | |
| 90 ++index; | |
| 91 } | 67 } |
| 92 return items; | 68 return items; |
| 93 } | 69 } |
| 94 | 70 |
| 95 void ExtensionAppWindowLauncherItemController::OnWindowRemoved( | 71 void ExtensionAppWindowLauncherItemController::ExecuteCommand( |
| 96 ui::BaseWindow* window) { | 72 uint32_t command_id, |
| 97 WindowToAppWindow::iterator it = window_to_app_window_.find(window); | 73 int32_t event_flags) { |
| 98 if (it == window_to_app_window_.end()) { | 74 launcher_controller()->ActivateShellApp(app_id(), command_id); |
| 99 NOTREACHED(); | |
| 100 return; | |
| 101 } | |
| 102 | |
| 103 window_to_app_window_.erase(it); | |
| 104 } | 75 } |
| OLD | NEW |