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

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

Issue 1823923002: arc: Support running Arc app in shelf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase, tests, cleanup Created 4 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/ash/launcher/extension_app_window_launcher_item_cont roller.h"
6
7 #include "ash/wm/window_state.h"
8 #include "ash/wm/window_util.h"
9 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
10 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h"
11 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
12 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
13 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
14 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
15 #include "components/favicon/content/content_favicon_driver.h"
16 #include "content/public/browser/web_contents.h"
17 #include "extensions/browser/app_window/app_window.h"
18 #include "extensions/browser/app_window/native_app_window.h"
19 #include "skia/ext/image_operations.h"
20 #include "ui/aura/client/aura_constants.h"
21 #include "ui/aura/window.h"
22 #include "ui/events/event.h"
23 #include "ui/gfx/image/image_skia.h"
24 #include "ui/wm/core/window_animations.h"
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::
51 ExtensionAppWindowLauncherItemController(
52 Type type,
53 const std::string& app_shelf_id,
54 const std::string& app_id,
55 ChromeLauncherController* controller)
56 : AppWindowLauncherItemController(type, app_shelf_id, app_id, controller) {}
57
58 ExtensionAppWindowLauncherItemController::
59 ~ExtensionAppWindowLauncherItemController() {}
60
61 void ExtensionAppWindowLauncherItemController::AddAppWindow(
62 extensions::AppWindow* app_window) {
63 if (app_window->window_type_is_panel() && type() != TYPE_APP_PANEL)
64 LOG(ERROR) << "AppWindow of type Panel added to non-panel launcher item";
65 DCHECK(window_to_app_window_.find(app_window->GetBaseWindow()) ==
66 window_to_app_window_.end());
67 AddWindow(app_window->GetBaseWindow());
68 window_to_app_window_[app_window->GetBaseWindow()] = app_window;
69 }
70
71 void ExtensionAppWindowLauncherItemController::OnWindowRemoved(
72 ui::BaseWindow* window) {
73 WindowToAppWindow::iterator it = window_to_app_window_.find(window);
74 if (it == window_to_app_window_.end()) {
75 NOTREACHED();
76 return;
77 }
78
79 window_to_app_window_.erase(it);
80 }
81
82 ChromeLauncherAppMenuItems
83 ExtensionAppWindowLauncherItemController::GetApplicationList(int event_flags) {
84 ChromeLauncherAppMenuItems items =
85 AppWindowLauncherItemController::GetApplicationList(event_flags);
86 int index = 0;
87 for (WindowList::const_iterator iter = windows().begin();
88 iter != windows().end(); ++iter) {
xiyuan 2016/03/23 23:22:53 nit: range loop
khmel 2016/03/24 16:30:38 Done.
89 extensions::AppWindow* app_window = window_to_app_window_[*iter];
90 DCHECK(app_window);
91
92 // If the app's web contents provides a favicon, use it. Otherwise, use a
93 // scaled down app icon.
94 favicon::FaviconDriver* favicon_driver =
95 favicon::ContentFaviconDriver::FromWebContents(
96 app_window->web_contents());
97 gfx::Image result = favicon_driver->GetFavicon();
98 if (result.IsEmpty())
99 result = GetAppListIcon(app_window);
100
101 items.push_back(new ChromeLauncherAppMenuItemV2App(
102 app_window->GetTitle(),
103 &result, // Will be copied
104 app_id(), launcher_controller(), index,
105 index == 0 /* has_leading_separator */));
106 ++index;
107 }
108 return items;
109 }
110
111 ash::ShelfItemDelegate::PerformedAction
112 ExtensionAppWindowLauncherItemController::ItemSelected(const ui::Event& event) {
113 if (windows().empty())
114 return kNoAction;
115
116 if (type() == TYPE_APP_PANEL) {
117 DCHECK_EQ(windows().size(), 1u);
118 ui::BaseWindow* panel = windows().front();
119 aura::Window* panel_window = panel->GetNativeWindow();
120 // If the panel is attached on another display, move it to the current
121 // display and activate it.
122 if (ash::wm::GetWindowState(panel_window)->panel_attached() &&
123 ash::wm::MoveWindowToEventRoot(panel_window, event)) {
124 if (!panel->IsActive())
125 return ShowAndActivateOrMinimize(panel);
126 } else {
127 return ShowAndActivateOrMinimize(panel);
128 }
129 } else {
130 return AppWindowLauncherItemController::ItemSelected(event);
131 }
132 return kNoAction;
133 }
134
135 base::string16 ExtensionAppWindowLauncherItemController::GetTitle() {
136 // For panels return the title of the contents if set.
137 // Otherwise return the title of the app.
138 if (type() == TYPE_APP_PANEL && !windows().empty()) {
139 extensions::AppWindow* app_window =
140 window_to_app_window_[windows().front()];
141 DCHECK(app_window);
142 if (app_window->web_contents()) {
143 base::string16 title = app_window->web_contents()->GetTitle();
144 if (!title.empty())
145 return title;
146 }
147 }
148 return AppWindowLauncherItemController::GetTitle();
149 }
150
151 ash::ShelfMenuModel*
152 ExtensionAppWindowLauncherItemController::CreateApplicationMenu(
153 int event_flags) {
154 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags));
155 }
156
157 bool ExtensionAppWindowLauncherItemController::IsDraggable() {
158 if (type() == TYPE_APP_PANEL)
159 return true;
160 return AppWindowLauncherItemController::IsDraggable();
161 }
162
163 bool ExtensionAppWindowLauncherItemController::ShouldShowTooltip() {
164 if (type() == TYPE_APP_PANEL && IsVisible())
165 return false;
166 return AppWindowLauncherItemController::ShouldShowTooltip();
167 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698