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

Side by Side Diff: chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_controller.cc

Issue 2716403005: mash: Remove shelf app menu item objects. (Closed)
Patch Set: Address comments. Created 3 years, 9 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
« no previous file with comments | « chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(
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 extensions::AppWindowRegistry* app_window_registry =
73 for (const auto* window : windows()) { 46 extensions::AppWindowRegistry::Get(launcher_controller()->profile());
74 extensions::AppWindow* app_window = window_to_app_window_[window]; 47
48 uint32_t window_index = 0;
49 for (const ui::BaseWindow* window : windows()) {
50 extensions::AppWindow* app_window =
51 app_window_registry->GetAppWindowForNativeWindow(
52 window->GetNativeWindow());
75 DCHECK(app_window); 53 DCHECK(app_window);
76 54
77 // If the app's web contents provides a favicon, use it. Otherwise, use a 55 // Use the app's web contents favicon, or the app window's icon.
78 // scaled down app icon.
79 favicon::FaviconDriver* favicon_driver = 56 favicon::FaviconDriver* favicon_driver =
80 favicon::ContentFaviconDriver::FromWebContents( 57 favicon::ContentFaviconDriver::FromWebContents(
81 app_window->web_contents()); 58 app_window->web_contents());
82 gfx::Image result = favicon_driver->GetFavicon(); 59 gfx::Image icon = favicon_driver->GetFavicon();
83 if (result.IsEmpty()) 60 if (icon.IsEmpty())
84 result = GetAppListIcon(app_window); 61 icon = app_window->app_icon();
85 62
86 items.push_back(base::MakeUnique<ChromeLauncherAppMenuItemV2App>( 63 items.push_back(base::MakeUnique<ash::ShelfApplicationMenuItem>(
87 app_window->GetTitle(), 64 window_index, app_window->GetTitle(), &icon));
88 &result, // Will be copied 65 ++window_index;
89 app_id(), launcher_controller(), index));
90 ++index;
91 } 66 }
92 return items; 67 return items;
93 } 68 }
94 69
95 void ExtensionAppWindowLauncherItemController::OnWindowRemoved( 70 void ExtensionAppWindowLauncherItemController::ExecuteCommand(
96 ui::BaseWindow* window) { 71 uint32_t command_id,
97 WindowToAppWindow::iterator it = window_to_app_window_.find(window); 72 int event_flags) {
98 if (it == window_to_app_window_.end()) { 73 launcher_controller()->ActivateShellApp(app_id(), command_id);
99 NOTREACHED();
100 return;
101 }
102
103 window_to_app_window_.erase(it);
104 } 74 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698