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

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

Issue 2671923002: mash: Cleanup ash shelf application menu code. (Closed)
Patch Set: Fix tests; cleanup. Created 3 years, 10 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 (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/ash/launcher/app_shortcut_launcher_item_controller.h " 5 #include "chrome/browser/ui/ash/launcher/app_shortcut_launcher_item_controller.h "
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "ash/public/cpp/shelf_application_menu_item.h"
9 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
10 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
11 #include "chrome/browser/chromeos/arc/arc_support_host.h" 12 #include "chrome/browser/chromeos/arc/arc_support_host.h"
12 #include "chrome/browser/extensions/launch_util.h" 13 #include "chrome/browser/extensions/launch_util.h"
13 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" 14 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h"
14 #include "chrome/browser/ui/ash/launcher/arc_playstore_shortcut_launcher_item_co ntroller.h" 15 #include "chrome/browser/ui/ash/launcher/arc_playstore_shortcut_launcher_item_co ntroller.h"
15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h"
17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" 18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
19 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
20 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" 19 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
21 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" 20 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h"
22 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 21 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
23 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" 22 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
24 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" 23 #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
25 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_finder.h" 25 #include "chrome/browser/ui/browser_finder.h"
27 #include "chrome/browser/ui/browser_list.h" 26 #include "chrome/browser/ui/browser_list.h"
28 #include "chrome/browser/ui/browser_window.h" 27 #include "chrome/browser/ui/browser_window.h"
29 #include "chrome/browser/ui/tabs/tab_strip_model.h" 28 #include "chrome/browser/ui/tabs/tab_strip_model.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
118 // special time out. 117 // special time out.
119 if (!AllowNextLaunchAttempt()) 118 if (!AllowNextLaunchAttempt())
120 return kNoAction; 119 return kNoAction;
121 } 120 }
122 Launch(source, ui::EF_NONE); 121 Launch(source, ui::EF_NONE);
123 return kNewWindowCreated; 122 return kNewWindowCreated;
124 } 123 }
125 return ActivateContent(content); 124 return ActivateContent(content);
126 } 125 }
127 126
127 ash::ShelfItemDelegate::PerformedAction
128 AppShortcutLauncherItemController::ItemSelected(const ui::Event& event) {
129 // In case of a keyboard event, we were called by a hotkey. In that case we
130 // activate the next item in line if an item of our list is already active.
131 if (event.type() == ui::ET_KEY_RELEASED && AdvanceToNextApp())
132 return kExistingWindowActivated;
133 return Activate(ash::LAUNCH_FROM_UNKNOWN);
134 }
135
136 ash::ShelfApplicationMenuItems
137 AppShortcutLauncherItemController::GetAppMenuItems(int event_flags) {
138 ash::ShelfApplicationMenuItems items;
139 std::vector<content::WebContents*> content_list = GetRunningApplications();
140 for (size_t i = 0; i < content_list.size(); i++) {
141 content::WebContents* web_contents = content_list[i];
142 gfx::Image app_icon = launcher_controller()->GetAppListIcon(web_contents);
143 base::string16 title = launcher_controller()->GetAppListTitle(web_contents);
144 items.push_back(base::MakeUnique<ChromeLauncherAppMenuItemTab>(
145 title, &app_icon, web_contents));
146 }
147 return items;
148 }
149
128 void AppShortcutLauncherItemController::Close() { 150 void AppShortcutLauncherItemController::Close() {
129 // Close all running 'programs' of this type. 151 // Close all running 'programs' of this type.
130 std::vector<content::WebContents*> content = 152 std::vector<content::WebContents*> content =
131 launcher_controller()->GetV1ApplicationsFromAppId(app_id()); 153 launcher_controller()->GetV1ApplicationsFromAppId(app_id());
132 for (size_t i = 0; i < content.size(); i++) { 154 for (size_t i = 0; i < content.size(); i++) {
133 Browser* browser = chrome::FindBrowserWithWebContents(content[i]); 155 Browser* browser = chrome::FindBrowserWithWebContents(content[i]);
134 if (!browser || !IsBrowserFromActiveUser(browser)) 156 if (!browser || !IsBrowserFromActiveUser(browser))
135 continue; 157 continue;
136 TabStripModel* tab_strip = browser->tab_strip_model(); 158 TabStripModel* tab_strip = browser->tab_strip_model();
137 int index = tab_strip->GetIndexOfWebContents(content[i]); 159 int index = tab_strip->GetIndexOfWebContents(content[i]);
138 DCHECK(index != TabStripModel::kNoTab); 160 DCHECK(index != TabStripModel::kNoTab);
139 tab_strip->CloseWebContentsAt(index, TabStripModel::CLOSE_NONE); 161 tab_strip->CloseWebContentsAt(index, TabStripModel::CLOSE_NONE);
140 } 162 }
141 } 163 }
142 164
143 ChromeLauncherAppMenuItems
144 AppShortcutLauncherItemController::GetApplicationList(int event_flags) {
145 ChromeLauncherAppMenuItems items;
146 // Add the application name to the menu.
147 base::string16 app_title = LauncherControllerHelper::GetAppTitle(
148 launcher_controller()->profile(), app_id());
149 items.push_back(
150 base::MakeUnique<ChromeLauncherAppMenuItem>(app_title, nullptr, false));
151
152 std::vector<content::WebContents*> content_list = GetRunningApplications();
153
154 for (size_t i = 0; i < content_list.size(); i++) {
155 content::WebContents* web_contents = content_list[i];
156 // Get the icon.
157 gfx::Image app_icon = launcher_controller()->GetAppListIcon(web_contents);
158 base::string16 title = launcher_controller()->GetAppListTitle(web_contents);
159 items.push_back(base::MakeUnique<ChromeLauncherAppMenuItemTab>(
160 title, &app_icon, web_contents, i == 0));
161 }
162 return items;
163 }
164
165 std::vector<content::WebContents*> 165 std::vector<content::WebContents*>
166 AppShortcutLauncherItemController::GetRunningApplications() { 166 AppShortcutLauncherItemController::GetRunningApplications() {
167 std::vector<content::WebContents*> items; 167 std::vector<content::WebContents*> items;
168 168
169 URLPattern refocus_pattern(URLPattern::SCHEME_ALL); 169 URLPattern refocus_pattern(URLPattern::SCHEME_ALL);
170 refocus_pattern.SetMatchAllURLs(true); 170 refocus_pattern.SetMatchAllURLs(true);
171 171
172 if (!refocus_url_.is_empty()) { 172 if (!refocus_url_.is_empty()) {
173 refocus_pattern.SetMatchAllURLs(false); 173 refocus_pattern.SetMatchAllURLs(false);
174 refocus_pattern.Parse(refocus_url_.spec()); 174 refocus_pattern.Parse(refocus_url_.spec());
(...skipping 13 matching lines...) Expand all
188 for (int index = 0; index < tab_strip->count(); index++) { 188 for (int index = 0; index < tab_strip->count(); index++) {
189 content::WebContents* web_contents = tab_strip->GetWebContentsAt(index); 189 content::WebContents* web_contents = tab_strip->GetWebContentsAt(index);
190 if (WebContentMatchesApp( 190 if (WebContentMatchesApp(
191 extension, refocus_pattern, web_contents, browser)) 191 extension, refocus_pattern, web_contents, browser))
192 items.push_back(web_contents); 192 items.push_back(web_contents);
193 } 193 }
194 } 194 }
195 return items; 195 return items;
196 } 196 }
197 197
198 ash::ShelfItemDelegate::PerformedAction
199 AppShortcutLauncherItemController::ItemSelected(const ui::Event& event) {
200 // In case of a keyboard event, we were called by a hotkey. In that case we
201 // activate the next item in line if an item of our list is already active.
202 if (event.type() == ui::ET_KEY_RELEASED) {
203 if (AdvanceToNextApp())
204 return kExistingWindowActivated;
205 }
206 return Activate(ash::LAUNCH_FROM_UNKNOWN);
207 }
208
209 ui::SimpleMenuModel* AppShortcutLauncherItemController::CreateApplicationMenu(
210 int event_flags) {
211 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags));
212 }
213
214 content::WebContents* AppShortcutLauncherItemController::GetLRUApplication() { 198 content::WebContents* AppShortcutLauncherItemController::GetLRUApplication() {
215 URLPattern refocus_pattern(URLPattern::SCHEME_ALL); 199 URLPattern refocus_pattern(URLPattern::SCHEME_ALL);
216 refocus_pattern.SetMatchAllURLs(true); 200 refocus_pattern.SetMatchAllURLs(true);
217 201
218 if (!refocus_url_.is_empty()) { 202 if (!refocus_url_.is_empty()) {
219 refocus_pattern.SetMatchAllURLs(false); 203 refocus_pattern.SetMatchAllURLs(false);
220 refocus_pattern.Parse(refocus_url_.spec()); 204 refocus_pattern.Parse(refocus_url_.spec());
221 } 205 }
222 206
223 const Extension* extension = 207 const Extension* extension =
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
350 334
351 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { 335 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() {
352 if (last_launch_attempt_.is_null() || 336 if (last_launch_attempt_.is_null() ||
353 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( 337 last_launch_attempt_ + base::TimeDelta::FromMilliseconds(
354 kClickSuppressionInMS) < base::Time::Now()) { 338 kClickSuppressionInMS) < base::Time::Now()) {
355 last_launch_attempt_ = base::Time::Now(); 339 last_launch_attempt_ = base::Time::Now();
356 return true; 340 return true;
357 } 341 }
358 return false; 342 return false;
359 } 343 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698