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

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

Issue 2696073002: Merge ShelfItemDelegate::ItemSelected & LauncherItemDelegate::Activate. (Closed)
Patch Set: 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/public/cpp/shelf_application_menu_item.h"
10 #include "ash/wm/window_util.h" 10 #include "ash/wm/window_util.h"
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 GetExtensionForAppID(app_id, controller->profile()); 87 GetExtensionForAppID(app_id, controller->profile());
88 // Some unit tests have no real extension. 88 // Some unit tests have no real extension.
89 if (extension) { 89 if (extension) {
90 set_refocus_url(GURL( 90 set_refocus_url(GURL(
91 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*")); 91 extensions::AppLaunchInfo::GetLaunchWebURL(extension).spec() + "*"));
92 } 92 }
93 } 93 }
94 94
95 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() {} 95 AppShortcutLauncherItemController::~AppShortcutLauncherItemController() {}
96 96
97 ash::ShelfItemDelegate::PerformedAction 97 ash::ShelfAction AppShortcutLauncherItemController::ItemSelected(
98 AppShortcutLauncherItemController::Activate(ash::LaunchSource source) { 98 ui::EventType event_type,
99 int event_flags,
100 int64_t display_id,
101 ash::ShelfLaunchSource source) {
102 // In case of a keyboard event, we were called by a hotkey. In that case we
103 // activate the next item in line if an item of our list is already active.
104 if (event_type == ui::ET_KEY_RELEASED && AdvanceToNextApp())
105 return ash::kExistingWindowActivated;
106
99 content::WebContents* content = GetLRUApplication(); 107 content::WebContents* content = GetLRUApplication();
100 if (!content) { 108 if (!content) {
101 // Ideally we come here only once. After that ShellLauncherItemController 109 // Ideally we come here only once. After that ShellLauncherItemController
102 // will take over when the shell window gets opened. However there are apps 110 // will take over when the shell window gets opened. However there are apps
103 // which take a lot of time for pre-processing (like the files app) before 111 // which take a lot of time for pre-processing (like the files app) before
104 // they open a window. Since there is currently no other way to detect if an 112 // they open a window. Since there is currently no other way to detect if an
105 // app was started we suppress any further clicks within a special time out. 113 // app was started we suppress any further clicks within a special time out.
106 if (IsV2App() && !AllowNextLaunchAttempt()) 114 if (IsV2App() && !AllowNextLaunchAttempt())
107 return kNoAction; 115 return ash::kNoAction;
108 116
109 // Launching some items replaces this item controller instance, which 117 // Launching some items replaces this item controller instance, which
110 // destroys the app and launch id strings; making copies avoid crashes. 118 // destroys the app and launch id strings; making copies avoid crashes.
111 launcher_controller()->LaunchApp(ash::AppLauncherId(app_id(), launch_id()), 119 launcher_controller()->LaunchApp(ash::AppLauncherId(app_id(), launch_id()),
112 source, ui::EF_NONE); 120 source, event_flags);
James Cook 2017/02/15 00:44:40 Is this change needed?
msw 2017/02/15 19:59:18 Reverted; no, afaict, this would have no behaviora
113 return kNewWindowCreated; 121 return ash::kNewWindowCreated;
114 } 122 }
115 return ActivateContent(content); 123 return ActivateContent(content);
116 } 124 }
117 125
118 ash::ShelfItemDelegate::PerformedAction
119 AppShortcutLauncherItemController::ItemSelected(const ui::Event& event) {
120 // In case of a keyboard event, we were called by a hotkey. In that case we
121 // activate the next item in line if an item of our list is already active.
122 if (event.type() == ui::ET_KEY_RELEASED && AdvanceToNextApp())
123 return kExistingWindowActivated;
124 return Activate(ash::LAUNCH_FROM_UNKNOWN);
125 }
126
127 ash::ShelfAppMenuItemList AppShortcutLauncherItemController::GetAppMenuItems( 126 ash::ShelfAppMenuItemList AppShortcutLauncherItemController::GetAppMenuItems(
128 int event_flags) { 127 int event_flags) {
129 ash::ShelfAppMenuItemList items; 128 ash::ShelfAppMenuItemList items;
130 std::vector<content::WebContents*> content_list = GetRunningApplications(); 129 std::vector<content::WebContents*> content_list = GetRunningApplications();
131 for (size_t i = 0; i < content_list.size(); i++) { 130 for (size_t i = 0; i < content_list.size(); i++) {
132 content::WebContents* web_contents = content_list[i]; 131 content::WebContents* web_contents = content_list[i];
133 gfx::Image app_icon = launcher_controller()->GetAppListIcon(web_contents); 132 gfx::Image app_icon = launcher_controller()->GetAppListIcon(web_contents);
134 base::string16 title = launcher_controller()->GetAppListTitle(web_contents); 133 base::string16 title = launcher_controller()->GetAppListTitle(web_contents);
135 items.push_back(base::MakeUnique<ChromeLauncherAppMenuItemTab>( 134 items.push_back(base::MakeUnique<ChromeLauncherAppMenuItemTab>(
136 title, &app_icon, web_contents)); 135 title, &app_icon, web_contents));
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 // - The launcher controller knows that the tab got created for this app. 265 // - The launcher controller knows that the tab got created for this app.
267 const GURL tab_url = web_contents->GetURL(); 266 const GURL tab_url = web_contents->GetURL();
268 return ((!refocus_pattern.match_all_urls() && 267 return ((!refocus_pattern.match_all_urls() &&
269 refocus_pattern.MatchesURL(tab_url)) || 268 refocus_pattern.MatchesURL(tab_url)) ||
270 (extension->OverlapsWithOrigin(tab_url) && 269 (extension->OverlapsWithOrigin(tab_url) &&
271 extension->web_extent().MatchesURL(tab_url)) || 270 extension->web_extent().MatchesURL(tab_url)) ||
272 launcher_controller()->IsWebContentHandledByApplication(web_contents, 271 launcher_controller()->IsWebContentHandledByApplication(web_contents,
273 app_id())); 272 app_id()));
274 } 273 }
275 274
276 ash::ShelfItemDelegate::PerformedAction 275 ash::ShelfAction AppShortcutLauncherItemController::ActivateContent(
277 AppShortcutLauncherItemController::ActivateContent(
278 content::WebContents* content) { 276 content::WebContents* content) {
279 Browser* browser = chrome::FindBrowserWithWebContents(content); 277 Browser* browser = chrome::FindBrowserWithWebContents(content);
280 TabStripModel* tab_strip = browser->tab_strip_model(); 278 TabStripModel* tab_strip = browser->tab_strip_model();
281 int index = tab_strip->GetIndexOfWebContents(content); 279 int index = tab_strip->GetIndexOfWebContents(content);
282 DCHECK_NE(TabStripModel::kNoTab, index); 280 DCHECK_NE(TabStripModel::kNoTab, index);
283 281
284 int old_index = tab_strip->active_index(); 282 int old_index = tab_strip->active_index();
285 if (index != old_index) 283 if (index != old_index)
286 tab_strip->ActivateTabAt(index, false); 284 tab_strip->ActivateTabAt(index, false);
287 return launcher_controller()->ActivateWindowOrMinimizeIfActive( 285 return launcher_controller()->ActivateWindowOrMinimizeIfActive(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 323
326 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() { 324 bool AppShortcutLauncherItemController::AllowNextLaunchAttempt() {
327 if (last_launch_attempt_.is_null() || 325 if (last_launch_attempt_.is_null() ||
328 last_launch_attempt_ + base::TimeDelta::FromMilliseconds( 326 last_launch_attempt_ + base::TimeDelta::FromMilliseconds(
329 kClickSuppressionInMS) < base::Time::Now()) { 327 kClickSuppressionInMS) < base::Time::Now()) {
330 last_launch_attempt_ = base::Time::Now(); 328 last_launch_attempt_ = base::Time::Now();
331 return true; 329 return true;
332 } 330 }
333 return false; 331 return false;
334 } 332 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698