| OLD | NEW |
| 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/common/shelf/shelf_model.h" | 9 #include "ash/common/shelf/shelf_model.h" |
| 10 #include "ash/shelf/shelf_delegate.h" |
| 10 #include "ash/shelf/shelf_util.h" | 11 #include "ash/shelf/shelf_util.h" |
| 11 #include "ash/shell.h" | 12 #include "ash/shell.h" |
| 12 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
| 13 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
| 15 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h
" | 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h
" |
| 16 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" | 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" |
| 17 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 18 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" | 19 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" |
| 19 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" | 20 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 for (BrowserList::const_iterator it = browser_list->begin(); | 136 for (BrowserList::const_iterator it = browser_list->begin(); |
| 136 it != browser_list->end(); ++it) { | 137 it != browser_list->end(); ++it) { |
| 137 if (launcher_controller()->IsBrowserFromActiveUser(*it)) | 138 if (launcher_controller()->IsBrowserFromActiveUser(*it)) |
| 138 return true; | 139 return true; |
| 139 } | 140 } |
| 140 return false; | 141 return false; |
| 141 } | 142 } |
| 142 | 143 |
| 143 bool BrowserShortcutLauncherItemController::IsVisible() const { | 144 bool BrowserShortcutLauncherItemController::IsVisible() const { |
| 144 Browser* last_browser = | 145 Browser* last_browser = |
| 145 chrome::FindTabbedBrowser(launcher_controller()->profile(), true); | 146 chrome::FindTabbedBrowser(launcher_controller()->GetProfile(), true); |
| 146 | 147 |
| 147 if (!last_browser) { | 148 if (!last_browser) { |
| 148 return false; | 149 return false; |
| 149 } | 150 } |
| 150 | 151 |
| 151 aura::Window* window = last_browser->window()->GetNativeWindow(); | 152 aura::Window* window = last_browser->window()->GetNativeWindow(); |
| 152 return ash::wm::IsActiveWindow(window); | 153 return ash::wm::IsActiveWindow(window); |
| 153 } | 154 } |
| 154 | 155 |
| 155 void BrowserShortcutLauncherItemController::Launch(ash::LaunchSource source, | 156 void BrowserShortcutLauncherItemController::Launch(ash::LaunchSource source, |
| 156 int event_flags) { | 157 int event_flags) { |
| 157 } | 158 } |
| 158 | 159 |
| 159 ash::ShelfItemDelegate::PerformedAction | 160 ash::ShelfItemDelegate::PerformedAction |
| 160 BrowserShortcutLauncherItemController::Activate(ash::LaunchSource source) { | 161 BrowserShortcutLauncherItemController::Activate(ash::LaunchSource source) { |
| 161 Browser* last_browser = | 162 Browser* last_browser = |
| 162 chrome::FindTabbedBrowser(launcher_controller()->profile(), true); | 163 chrome::FindTabbedBrowser(launcher_controller()->GetProfile(), true); |
| 163 | 164 |
| 164 if (!last_browser) { | 165 if (!last_browser) { |
| 165 chrome::NewEmptyWindow(launcher_controller()->profile()); | 166 chrome::NewEmptyWindow(launcher_controller()->GetProfile()); |
| 166 return kNewWindowCreated; | 167 return kNewWindowCreated; |
| 167 } | 168 } |
| 168 | 169 |
| 169 return launcher_controller()->ActivateWindowOrMinimizeIfActive( | 170 return launcher_controller()->ActivateWindowOrMinimizeIfActive( |
| 170 last_browser->window(), GetApplicationList(0).size() == 2); | 171 last_browser->window(), GetApplicationList(0).size() == 2); |
| 171 } | 172 } |
| 172 | 173 |
| 173 void BrowserShortcutLauncherItemController::Close() { | 174 void BrowserShortcutLauncherItemController::Close() { |
| 174 for (auto* browser : GetListOfActiveBrowsers()) | 175 for (auto* browser : GetListOfActiveBrowsers()) |
| 175 browser->window()->Close(); | 176 browser->window()->Close(); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 // If only windowed applications are open, we return an empty list to | 213 // If only windowed applications are open, we return an empty list to |
| 213 // enforce the creation of a new browser. | 214 // enforce the creation of a new browser. |
| 214 if (!found_tabbed_browser) | 215 if (!found_tabbed_browser) |
| 215 items.clear(); | 216 items.clear(); |
| 216 return items; | 217 return items; |
| 217 } | 218 } |
| 218 | 219 |
| 219 ash::ShelfItemDelegate::PerformedAction | 220 ash::ShelfItemDelegate::PerformedAction |
| 220 BrowserShortcutLauncherItemController::ItemSelected(const ui::Event& event) { | 221 BrowserShortcutLauncherItemController::ItemSelected(const ui::Event& event) { |
| 221 if (event.flags() & ui::EF_CONTROL_DOWN) { | 222 if (event.flags() & ui::EF_CONTROL_DOWN) { |
| 222 chrome::NewEmptyWindow(launcher_controller()->profile()); | 223 chrome::NewEmptyWindow(launcher_controller()->GetProfile()); |
| 223 return kNewWindowCreated; | 224 return kNewWindowCreated; |
| 224 } | 225 } |
| 225 | 226 |
| 226 // In case of a keyboard event, we were called by a hotkey. In that case we | 227 // 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. | 228 // activate the next item in line if an item of our list is already active. |
| 228 if (event.type() & ui::ET_KEY_RELEASED) { | 229 if (event.type() & ui::ET_KEY_RELEASED) { |
| 229 return ActivateOrAdvanceToNextBrowser(); | 230 return ActivateOrAdvanceToNextBrowser(); |
| 230 } | 231 } |
| 231 | 232 |
| 232 return Activate(ash::LAUNCH_FROM_UNKNOWN); | 233 return Activate(ash::LAUNCH_FROM_UNKNOWN); |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 // We use the list in the order of how the browsers got created - not the LRU | 288 // We use the list in the order of how the browsers got created - not the LRU |
| 288 // order. | 289 // order. |
| 289 const BrowserList* browser_list = BrowserList::GetInstance(); | 290 const BrowserList* browser_list = BrowserList::GetInstance(); |
| 290 for (BrowserList::const_iterator it = browser_list->begin(); | 291 for (BrowserList::const_iterator it = browser_list->begin(); |
| 291 it != browser_list->end(); ++it) { | 292 it != browser_list->end(); ++it) { |
| 292 if (IsBrowserRepresentedInBrowserList(*it)) | 293 if (IsBrowserRepresentedInBrowserList(*it)) |
| 293 items.push_back(*it); | 294 items.push_back(*it); |
| 294 } | 295 } |
| 295 // If there are no suitable browsers we create a new one. | 296 // If there are no suitable browsers we create a new one. |
| 296 if (items.empty()) { | 297 if (items.empty()) { |
| 297 chrome::NewEmptyWindow(launcher_controller()->profile()); | 298 chrome::NewEmptyWindow(launcher_controller()->GetProfile()); |
| 298 return kNewWindowCreated; | 299 return kNewWindowCreated; |
| 299 } | 300 } |
| 300 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); | 301 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); |
| 301 if (items.size() == 1) { | 302 if (items.size() == 1) { |
| 302 // If there is only one suitable browser, we can either activate it, or | 303 // If there is only one suitable browser, we can either activate it, or |
| 303 // bounce it (if it is already active). | 304 // bounce it (if it is already active). |
| 304 if (browser == items[0]) { | 305 if (browser == items[0]) { |
| 305 AnimateWindow(browser->window()->GetNativeWindow(), | 306 AnimateWindow(browser->window()->GetNativeWindow(), |
| 306 wm::WINDOW_ANIMATION_TYPE_BOUNCE); | 307 wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
| 307 return kNoAction; | 308 return kNoAction; |
| 308 } | 309 } |
| 309 browser = items[0]; | 310 browser = items[0]; |
| 310 } else { | 311 } else { |
| 311 // If there is more then one suitable browser, we advance to the next if | 312 // If there is more then one suitable browser, we advance to the next if |
| 312 // |browser| is already active - or - check the last used browser if it can | 313 // |browser| is already active - or - check the last used browser if it can |
| 313 // be used. | 314 // be used. |
| 314 std::vector<Browser*>::iterator i = | 315 std::vector<Browser*>::iterator i = |
| 315 std::find(items.begin(), items.end(), browser); | 316 std::find(items.begin(), items.end(), browser); |
| 316 if (i != items.end()) { | 317 if (i != items.end()) { |
| 317 browser = (++i == items.end()) ? items[0] : *i; | 318 browser = (++i == items.end()) ? items[0] : *i; |
| 318 } else { | 319 } else { |
| 319 browser = | 320 browser = |
| 320 chrome::FindTabbedBrowser(launcher_controller()->profile(), true); | 321 chrome::FindTabbedBrowser(launcher_controller()->GetProfile(), true); |
| 321 if (!browser || | 322 if (!browser || |
| 322 !IsBrowserRepresentedInBrowserList(browser)) | 323 !IsBrowserRepresentedInBrowserList(browser)) |
| 323 browser = items[0]; | 324 browser = items[0]; |
| 324 } | 325 } |
| 325 } | 326 } |
| 326 DCHECK(browser); | 327 DCHECK(browser); |
| 327 browser->window()->Show(); | 328 browser->window()->Show(); |
| 328 browser->window()->Activate(); | 329 browser->window()->Activate(); |
| 329 return kExistingWindowActivated; | 330 return kExistingWindowActivated; |
| 330 } | 331 } |
| 331 | 332 |
| 332 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( | 333 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( |
| 333 Browser* browser) { | 334 Browser* browser) { |
| 334 // Only Ash desktop browser windows for the active user are represented. | 335 // Only Ash desktop browser windows for the active user are represented. |
| 335 if (!browser || !launcher_controller()->IsBrowserFromActiveUser(browser)) | 336 if (!browser || !launcher_controller()->IsBrowserFromActiveUser(browser)) |
| 336 return false; | 337 return false; |
| 337 | 338 |
| 338 // v1 App popup windows with a valid app id have their own icon. | 339 // v1 App popup windows with a valid app id have their own icon. |
| 339 if (browser->is_app() && | 340 if (browser->is_app() && |
| 340 browser->is_type_popup() && | 341 browser->is_type_popup() && |
| 341 launcher_controller()->GetShelfIDForAppID( | 342 ash::Shell::GetInstance()->GetShelfDelegate()->GetShelfIDForAppID( |
| 342 web_app::GetExtensionIdFromApplicationName(browser->app_name())) > 0) | 343 web_app::GetExtensionIdFromApplicationName(browser->app_name())) > 0) |
| 343 return false; | 344 return false; |
| 344 | 345 |
| 345 // Settings browsers have their own icon. | 346 // Settings browsers have their own icon. |
| 346 if (IsSettingsBrowser(browser)) | 347 if (IsSettingsBrowser(browser)) |
| 347 return false; | 348 return false; |
| 348 | 349 |
| 349 // Tabbed browser and other popup windows are all represented. | 350 // Tabbed browser and other popup windows are all represented. |
| 350 return true; | 351 return true; |
| 351 } | 352 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 362 !browser->window()->IsMinimized()) { | 363 !browser->window()->IsMinimized()) { |
| 363 continue; | 364 continue; |
| 364 } | 365 } |
| 365 if (!IsBrowserRepresentedInBrowserList(browser) && | 366 if (!IsBrowserRepresentedInBrowserList(browser) && |
| 366 !browser->is_type_tabbed()) | 367 !browser->is_type_tabbed()) |
| 367 continue; | 368 continue; |
| 368 active_browsers.push_back(browser); | 369 active_browsers.push_back(browser); |
| 369 } | 370 } |
| 370 return active_browsers; | 371 return active_browsers; |
| 371 } | 372 } |
| OLD | NEW |