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

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

Issue 2391253004: Use mojo Shelf interfaces for both mash and classic ash. (Closed)
Patch Set: Sync and rebase. Created 4 years, 2 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/browser_shortcut_launcher_item_controll er.h" 5 #include "chrome/browser/ui/ash/launcher/browser_shortcut_launcher_item_controll er.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "ash/aura/wm_window_aura.h" 9 #include "ash/aura/wm_window_aura.h"
10 #include "ash/common/shelf/shelf_delegate.h" 10 #include "ash/common/shelf/shelf_delegate.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 for (BrowserList::const_iterator it = browser_list->begin(); 135 for (BrowserList::const_iterator it = browser_list->begin();
136 it != browser_list->end(); ++it) { 136 it != browser_list->end(); ++it) {
137 if (IsBrowserFromActiveUser(*it)) 137 if (IsBrowserFromActiveUser(*it))
138 return true; 138 return true;
139 } 139 }
140 return false; 140 return false;
141 } 141 }
142 142
143 bool BrowserShortcutLauncherItemController::IsVisible() const { 143 bool BrowserShortcutLauncherItemController::IsVisible() const {
144 Browser* last_browser = 144 Browser* last_browser =
145 chrome::FindTabbedBrowser(launcher_controller()->GetProfile(), true); 145 chrome::FindTabbedBrowser(launcher_controller()->profile(), true);
146 146
147 if (!last_browser) { 147 if (!last_browser) {
148 return false; 148 return false;
149 } 149 }
150 150
151 aura::Window* window = last_browser->window()->GetNativeWindow(); 151 aura::Window* window = last_browser->window()->GetNativeWindow();
152 return ash::wm::IsActiveWindow(window); 152 return ash::wm::IsActiveWindow(window);
153 } 153 }
154 154
155 void BrowserShortcutLauncherItemController::Launch(ash::LaunchSource source, 155 void BrowserShortcutLauncherItemController::Launch(ash::LaunchSource source,
156 int event_flags) { 156 int event_flags) {
157 } 157 }
158 158
159 ash::ShelfItemDelegate::PerformedAction 159 ash::ShelfItemDelegate::PerformedAction
160 BrowserShortcutLauncherItemController::Activate(ash::LaunchSource source) { 160 BrowserShortcutLauncherItemController::Activate(ash::LaunchSource source) {
161 Browser* last_browser = 161 Browser* last_browser =
162 chrome::FindTabbedBrowser(launcher_controller()->GetProfile(), true); 162 chrome::FindTabbedBrowser(launcher_controller()->profile(), true);
163 163
164 if (!last_browser) { 164 if (!last_browser) {
165 chrome::NewEmptyWindow(launcher_controller()->GetProfile()); 165 chrome::NewEmptyWindow(launcher_controller()->profile());
166 return kNewWindowCreated; 166 return kNewWindowCreated;
167 } 167 }
168 168
169 return launcher_controller()->ActivateWindowOrMinimizeIfActive( 169 return launcher_controller()->ActivateWindowOrMinimizeIfActive(
170 last_browser->window(), GetApplicationList(0).size() == 2); 170 last_browser->window(), GetApplicationList(0).size() == 2);
171 } 171 }
172 172
173 void BrowserShortcutLauncherItemController::Close() { 173 void BrowserShortcutLauncherItemController::Close() {
174 for (auto* browser : GetListOfActiveBrowsers()) 174 for (auto* browser : GetListOfActiveBrowsers())
175 browser->window()->Close(); 175 browser->window()->Close();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 // If only windowed applications are open, we return an empty list to 212 // If only windowed applications are open, we return an empty list to
213 // enforce the creation of a new browser. 213 // enforce the creation of a new browser.
214 if (!found_tabbed_browser) 214 if (!found_tabbed_browser)
215 items.clear(); 215 items.clear();
216 return items; 216 return items;
217 } 217 }
218 218
219 ash::ShelfItemDelegate::PerformedAction 219 ash::ShelfItemDelegate::PerformedAction
220 BrowserShortcutLauncherItemController::ItemSelected(const ui::Event& event) { 220 BrowserShortcutLauncherItemController::ItemSelected(const ui::Event& event) {
221 if (event.flags() & ui::EF_CONTROL_DOWN) { 221 if (event.flags() & ui::EF_CONTROL_DOWN) {
222 chrome::NewEmptyWindow(launcher_controller()->GetProfile()); 222 chrome::NewEmptyWindow(launcher_controller()->profile());
223 return kNewWindowCreated; 223 return kNewWindowCreated;
224 } 224 }
225 225
226 // In case of a keyboard event, we were called by a hotkey. In that case we 226 // In case of a keyboard event, we were called by a hotkey. In that case we
227 // activate the next item in line if an item of our list is already active. 227 // activate the next item in line if an item of our list is already active.
228 if (event.type() == ui::ET_KEY_RELEASED) { 228 if (event.type() == ui::ET_KEY_RELEASED) {
229 return ActivateOrAdvanceToNextBrowser(); 229 return ActivateOrAdvanceToNextBrowser();
230 } 230 }
231 231
232 return Activate(ash::LAUNCH_FROM_UNKNOWN); 232 return Activate(ash::LAUNCH_FROM_UNKNOWN);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // We use the list in the order of how the browsers got created - not the LRU 287 // We use the list in the order of how the browsers got created - not the LRU
288 // order. 288 // order.
289 const BrowserList* browser_list = BrowserList::GetInstance(); 289 const BrowserList* browser_list = BrowserList::GetInstance();
290 for (BrowserList::const_iterator it = browser_list->begin(); 290 for (BrowserList::const_iterator it = browser_list->begin();
291 it != browser_list->end(); ++it) { 291 it != browser_list->end(); ++it) {
292 if (IsBrowserRepresentedInBrowserList(*it)) 292 if (IsBrowserRepresentedInBrowserList(*it))
293 items.push_back(*it); 293 items.push_back(*it);
294 } 294 }
295 // If there are no suitable browsers we create a new one. 295 // If there are no suitable browsers we create a new one.
296 if (items.empty()) { 296 if (items.empty()) {
297 chrome::NewEmptyWindow(launcher_controller()->GetProfile()); 297 chrome::NewEmptyWindow(launcher_controller()->profile());
298 return kNewWindowCreated; 298 return kNewWindowCreated;
299 } 299 }
300 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); 300 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow());
301 if (items.size() == 1) { 301 if (items.size() == 1) {
302 // If there is only one suitable browser, we can either activate it, or 302 // If there is only one suitable browser, we can either activate it, or
303 // bounce it (if it is already active). 303 // bounce it (if it is already active).
304 if (browser == items[0]) { 304 if (browser == items[0]) {
305 AnimateWindow(browser->window()->GetNativeWindow(), 305 AnimateWindow(browser->window()->GetNativeWindow(),
306 wm::WINDOW_ANIMATION_TYPE_BOUNCE); 306 wm::WINDOW_ANIMATION_TYPE_BOUNCE);
307 return kNoAction; 307 return kNoAction;
308 } 308 }
309 browser = items[0]; 309 browser = items[0];
310 } else { 310 } else {
311 // If there is more than one suitable browser, we advance to the next if 311 // If there is more than one suitable browser, we advance to the next if
312 // |browser| is already active - or - check the last used browser if it can 312 // |browser| is already active - or - check the last used browser if it can
313 // be used. 313 // be used.
314 std::vector<Browser*>::iterator i = 314 std::vector<Browser*>::iterator i =
315 std::find(items.begin(), items.end(), browser); 315 std::find(items.begin(), items.end(), browser);
316 if (i != items.end()) { 316 if (i != items.end()) {
317 browser = (++i == items.end()) ? items[0] : *i; 317 browser = (++i == items.end()) ? items[0] : *i;
318 } else { 318 } else {
319 browser = 319 browser =
320 chrome::FindTabbedBrowser(launcher_controller()->GetProfile(), true); 320 chrome::FindTabbedBrowser(launcher_controller()->profile(), true);
321 if (!browser || 321 if (!browser || !IsBrowserRepresentedInBrowserList(browser))
322 !IsBrowserRepresentedInBrowserList(browser))
323 browser = items[0]; 322 browser = items[0];
324 } 323 }
325 } 324 }
326 DCHECK(browser); 325 DCHECK(browser);
327 browser->window()->Show(); 326 browser->window()->Show();
328 browser->window()->Activate(); 327 browser->window()->Activate();
329 return kExistingWindowActivated; 328 return kExistingWindowActivated;
330 } 329 }
331 330
332 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( 331 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList(
(...skipping 28 matching lines...) Expand all
361 !browser->window()->IsMinimized()) { 360 !browser->window()->IsMinimized()) {
362 continue; 361 continue;
363 } 362 }
364 if (!IsBrowserRepresentedInBrowserList(browser) && 363 if (!IsBrowserRepresentedInBrowserList(browser) &&
365 !browser->is_type_tabbed()) 364 !browser->is_type_tabbed())
366 continue; 365 continue;
367 active_browsers.push_back(browser); 366 active_browsers.push_back(browser);
368 } 367 }
369 return active_browsers; 368 return active_browsers;
370 } 369 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698