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

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

Issue 298303002: Add option to install an ephemeral app to ChromeOS shelf context menu (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed asargent's review comments Created 6 years, 6 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/app_window_launcher_item_controller.h" 5 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h"
6 6
7 #include "apps/app_window.h" 7 #include "apps/app_window.h"
8 #include "apps/ui/native_app_window.h" 8 #include "apps/ui/native_app_window.h"
9 #include "ash/shelf/shelf_model.h" 9 #include "ash/shelf/shelf_model.h"
10 #include "ash/wm/window_state.h" 10 #include "ash/wm/window_state.h"
11 #include "ash/wm/window_util.h" 11 #include "ash/wm/window_util.h"
12 #include "chrome/browser/extensions/webstore_install_with_prompt.h"
12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" 13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h" 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h"
14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
15 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" 16 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
16 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" 17 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
17 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 18 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
18 #include "content/public/browser/web_contents.h" 19 #include "content/public/browser/web_contents.h"
19 #include "skia/ext/image_operations.h" 20 #include "skia/ext/image_operations.h"
20 #include "ui/aura/client/aura_constants.h" 21 #include "ui/aura/client/aura_constants.h"
21 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
(...skipping 21 matching lines...) Expand all
43 44
44 SkBitmap bmp = 45 SkBitmap bmp =
45 skia::ImageOperations::Resize(*app_window->app_icon().ToSkBitmap(), 46 skia::ImageOperations::Resize(*app_window->app_icon().ToSkBitmap(),
46 skia::ImageOperations::RESIZE_BEST, 47 skia::ImageOperations::RESIZE_BEST,
47 kAppListIconSize, 48 kAppListIconSize,
48 kAppListIconSize); 49 kAppListIconSize);
49 return make_scoped_ptr( 50 return make_scoped_ptr(
50 new gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(bmp))); 51 new gfx::Image(gfx::ImageSkia::CreateFrom1xBitmap(bmp)));
51 } 52 }
52 53
54 // Returns true if the app window is visible on screen, i.e. not hidden or
55 // minimized.
56 bool IsAppWindowVisible(AppWindow* app_window) {
57 return app_window &&
58 !app_window->is_hidden() &&
59 !app_window->GetBaseWindow()->IsMinimized();
60 }
61
53 // Functor for std::find_if used in AppLauncherItemController. 62 // Functor for std::find_if used in AppLauncherItemController.
54 class AppWindowHasWindow { 63 class AppWindowHasWindow {
55 public: 64 public:
56 explicit AppWindowHasWindow(aura::Window* window) : window_(window) {} 65 explicit AppWindowHasWindow(aura::Window* window) : window_(window) {}
57 66
58 bool operator()(AppWindow* app_window) const { 67 bool operator()(AppWindow* app_window) const {
59 return app_window->GetNativeWindow() == window_; 68 return app_window->GetNativeWindow() == window_;
60 } 69 }
61 70
62 private: 71 private:
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 } 153 }
145 154
146 void AppWindowLauncherItemController::ActivateIndexedApp(size_t index) { 155 void AppWindowLauncherItemController::ActivateIndexedApp(size_t index) {
147 if (index >= app_windows_.size()) 156 if (index >= app_windows_.size())
148 return; 157 return;
149 AppWindowList::iterator it = app_windows_.begin(); 158 AppWindowList::iterator it = app_windows_.begin();
150 std::advance(it, index); 159 std::advance(it, index);
151 ShowAndActivateOrMinimize(*it); 160 ShowAndActivateOrMinimize(*it);
152 } 161 }
153 162
163 void AppWindowLauncherItemController::InstallApp() {
164 // Find a visible window in order to position the install dialog. If there is
165 // no visible window, the dialog will be centered on the screen.
166 AppWindow* parent_window = NULL;
167 if (IsAppWindowVisible(last_active_app_window_)) {
168 parent_window = last_active_app_window_;
169 } else {
170 for (AppWindowList::iterator iter = app_windows_.begin();
171 iter != app_windows_.end(); ++iter) {
172 if (IsAppWindowVisible(*iter)) {
173 parent_window = *iter;
174 break;
175 }
176 }
177 }
178
179 scoped_refptr<extensions::WebstoreInstallWithPrompt> installer;
180 if (parent_window) {
181 installer = new extensions::WebstoreInstallWithPrompt(
182 app_id(),
183 launcher_controller()->profile(),
184 parent_window->GetNativeWindow(),
185 extensions::WebstoreInstallWithPrompt::Callback());
186 } else {
187 installer = new extensions::WebstoreInstallWithPrompt(
188 app_id(),
189 launcher_controller()->profile(),
190 extensions::WebstoreInstallWithPrompt::Callback());
191 }
192 installer->BeginInstall();
193 }
194
154 ChromeLauncherAppMenuItems AppWindowLauncherItemController::GetApplicationList( 195 ChromeLauncherAppMenuItems AppWindowLauncherItemController::GetApplicationList(
155 int event_flags) { 196 int event_flags) {
156 ChromeLauncherAppMenuItems items; 197 ChromeLauncherAppMenuItems items;
157 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); 198 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false));
158 int index = 0; 199 int index = 0;
159 for (AppWindowList::iterator iter = app_windows_.begin(); 200 for (AppWindowList::iterator iter = app_windows_.begin();
160 iter != app_windows_.end(); 201 iter != app_windows_.end();
161 ++iter) { 202 ++iter) {
162 AppWindow* app_window = *iter; 203 AppWindow* app_window = *iter;
163 scoped_ptr<gfx::Image> image(GetAppListIcon(app_window)); 204 scoped_ptr<gfx::Image> image(GetAppListIcon(app_window));
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 } 320 }
280 if (window_to_show->GetBaseWindow()->IsActive()) { 321 if (window_to_show->GetBaseWindow()->IsActive()) {
281 // Coming here, only a single window is active. For keyboard activations 322 // Coming here, only a single window is active. For keyboard activations
282 // the window gets animated. 323 // the window gets animated.
283 AnimateWindow(window_to_show->GetNativeWindow(), 324 AnimateWindow(window_to_show->GetNativeWindow(),
284 wm::WINDOW_ANIMATION_TYPE_BOUNCE); 325 wm::WINDOW_ANIMATION_TYPE_BOUNCE);
285 } else { 326 } else {
286 ShowAndActivateOrMinimize(window_to_show); 327 ShowAndActivateOrMinimize(window_to_show);
287 } 328 }
288 } 329 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698