| 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_delegate.h" | 9 #include "ash/common/shelf/shelf_delegate.h" |
| 10 #include "ash/common/shelf/shelf_model.h" | 10 #include "ash/common/shelf/shelf_model.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 if (!browser || !IsBrowserFromActiveUser(browser) || | 121 if (!browser || !IsBrowserFromActiveUser(browser) || |
| 122 IsSettingsBrowser(browser)) | 122 IsSettingsBrowser(browser)) |
| 123 return; | 123 return; |
| 124 | 124 |
| 125 ash::WmWindow::Get(browser->window()->GetNativeWindow()) | 125 ash::WmWindow::Get(browser->window()->GetNativeWindow()) |
| 126 ->SetIntProperty( | 126 ->SetIntProperty( |
| 127 ash::WmWindowProperty::SHELF_ID, | 127 ash::WmWindowProperty::SHELF_ID, |
| 128 launcher_controller()->GetShelfIDForWebContents(web_contents)); | 128 launcher_controller()->GetShelfIDForWebContents(web_contents)); |
| 129 } | 129 } |
| 130 | 130 |
| 131 ash::ShelfItemDelegate::PerformedAction | 131 ash::ShelfAction BrowserShortcutLauncherItemController::ItemSelected( |
| 132 BrowserShortcutLauncherItemController::Activate(ash::LaunchSource source) { | 132 ui::EventType event_type, |
| 133 int event_flags, |
| 134 int64_t display_id, |
| 135 ash::ShelfLaunchSource source) { |
| 136 if (event_flags & ui::EF_CONTROL_DOWN) { |
| 137 chrome::NewEmptyWindow(launcher_controller()->profile()); |
| 138 return ash::kNewWindowCreated; |
| 139 } |
| 140 |
| 141 // In case of a keyboard event, we were called by a hotkey. In that case we |
| 142 // activate the next item in line if an item of our list is already active. |
| 143 if (event_type == ui::ET_KEY_RELEASED) |
| 144 return ActivateOrAdvanceToNextBrowser(); |
| 145 |
| 133 Browser* last_browser = | 146 Browser* last_browser = |
| 134 chrome::FindTabbedBrowser(launcher_controller()->profile(), true); | 147 chrome::FindTabbedBrowser(launcher_controller()->profile(), true); |
| 135 | 148 |
| 136 if (!last_browser) { | 149 if (!last_browser) { |
| 137 chrome::NewEmptyWindow(launcher_controller()->profile()); | 150 chrome::NewEmptyWindow(launcher_controller()->profile()); |
| 138 return kNewWindowCreated; | 151 return ash::kNewWindowCreated; |
| 139 } | 152 } |
| 140 | 153 |
| 141 return launcher_controller()->ActivateWindowOrMinimizeIfActive( | 154 return launcher_controller()->ActivateWindowOrMinimizeIfActive( |
| 142 last_browser->window(), GetAppMenuItems(0).size() == 1); | 155 last_browser->window(), GetAppMenuItems(0).size() == 1); |
| 143 } | 156 } |
| 144 | 157 |
| 145 ash::ShelfItemDelegate::PerformedAction | |
| 146 BrowserShortcutLauncherItemController::ItemSelected(const ui::Event& event) { | |
| 147 if (event.flags() & ui::EF_CONTROL_DOWN) { | |
| 148 chrome::NewEmptyWindow(launcher_controller()->profile()); | |
| 149 return kNewWindowCreated; | |
| 150 } | |
| 151 | |
| 152 // In case of a keyboard event, we were called by a hotkey. In that case we | |
| 153 // activate the next item in line if an item of our list is already active. | |
| 154 if (event.type() == ui::ET_KEY_RELEASED) | |
| 155 return ActivateOrAdvanceToNextBrowser(); | |
| 156 | |
| 157 return Activate(ash::LAUNCH_FROM_UNKNOWN); | |
| 158 } | |
| 159 | |
| 160 ash::ShelfAppMenuItemList | 158 ash::ShelfAppMenuItemList |
| 161 BrowserShortcutLauncherItemController::GetAppMenuItems(int event_flags) { | 159 BrowserShortcutLauncherItemController::GetAppMenuItems(int event_flags) { |
| 162 ash::ShelfAppMenuItemList items; | 160 ash::ShelfAppMenuItemList items; |
| 163 bool found_tabbed_browser = false; | 161 bool found_tabbed_browser = false; |
| 164 for (auto* browser : GetListOfActiveBrowsers()) { | 162 for (auto* browser : GetListOfActiveBrowsers()) { |
| 165 TabStripModel* tab_strip = browser->tab_strip_model(); | 163 TabStripModel* tab_strip = browser->tab_strip_model(); |
| 166 if (tab_strip->active_index() == -1) | 164 if (tab_strip->active_index() == -1) |
| 167 continue; | 165 continue; |
| 168 if (browser->is_type_tabbed()) | 166 if (browser->is_type_tabbed()) |
| 169 found_tabbed_browser = true; | 167 found_tabbed_browser = true; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); | 217 return l10n_util::GetStringUTF16(IDS_NEW_TAB_TITLE); |
| 220 } | 218 } |
| 221 | 219 |
| 222 bool BrowserShortcutLauncherItemController::IsIncognito( | 220 bool BrowserShortcutLauncherItemController::IsIncognito( |
| 223 content::WebContents* web_contents) const { | 221 content::WebContents* web_contents) const { |
| 224 const Profile* profile = | 222 const Profile* profile = |
| 225 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 223 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 226 return profile->IsOffTheRecord() && !profile->IsGuestSession(); | 224 return profile->IsOffTheRecord() && !profile->IsGuestSession(); |
| 227 } | 225 } |
| 228 | 226 |
| 229 ash::ShelfItemDelegate::PerformedAction | 227 ash::ShelfAction |
| 230 BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() { | 228 BrowserShortcutLauncherItemController::ActivateOrAdvanceToNextBrowser() { |
| 231 // Create a list of all suitable running browsers. | 229 // Create a list of all suitable running browsers. |
| 232 std::vector<Browser*> items; | 230 std::vector<Browser*> items; |
| 233 // We use the list in the order of how the browsers got created - not the LRU | 231 // We use the list in the order of how the browsers got created - not the LRU |
| 234 // order. | 232 // order. |
| 235 const BrowserList* browser_list = BrowserList::GetInstance(); | 233 const BrowserList* browser_list = BrowserList::GetInstance(); |
| 236 for (BrowserList::const_iterator it = browser_list->begin(); | 234 for (BrowserList::const_iterator it = browser_list->begin(); |
| 237 it != browser_list->end(); ++it) { | 235 it != browser_list->end(); ++it) { |
| 238 if (IsBrowserRepresentedInBrowserList(*it)) | 236 if (IsBrowserRepresentedInBrowserList(*it)) |
| 239 items.push_back(*it); | 237 items.push_back(*it); |
| 240 } | 238 } |
| 241 // If there are no suitable browsers we create a new one. | 239 // If there are no suitable browsers we create a new one. |
| 242 if (items.empty()) { | 240 if (items.empty()) { |
| 243 chrome::NewEmptyWindow(launcher_controller()->profile()); | 241 chrome::NewEmptyWindow(launcher_controller()->profile()); |
| 244 return kNewWindowCreated; | 242 return ash::kNewWindowCreated; |
| 245 } | 243 } |
| 246 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); | 244 Browser* browser = chrome::FindBrowserWithWindow(ash::wm::GetActiveWindow()); |
| 247 if (items.size() == 1) { | 245 if (items.size() == 1) { |
| 248 // If there is only one suitable browser, we can either activate it, or | 246 // If there is only one suitable browser, we can either activate it, or |
| 249 // bounce it (if it is already active). | 247 // bounce it (if it is already active). |
| 250 if (browser == items[0]) { | 248 if (browser == items[0]) { |
| 251 AnimateWindow(browser->window()->GetNativeWindow(), | 249 AnimateWindow(browser->window()->GetNativeWindow(), |
| 252 wm::WINDOW_ANIMATION_TYPE_BOUNCE); | 250 wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
| 253 return kNoAction; | 251 return ash::kNoAction; |
| 254 } | 252 } |
| 255 browser = items[0]; | 253 browser = items[0]; |
| 256 } else { | 254 } else { |
| 257 // If there is more than one suitable browser, we advance to the next if | 255 // If there is more than one suitable browser, we advance to the next if |
| 258 // |browser| is already active - or - check the last used browser if it can | 256 // |browser| is already active - or - check the last used browser if it can |
| 259 // be used. | 257 // be used. |
| 260 std::vector<Browser*>::iterator i = | 258 std::vector<Browser*>::iterator i = |
| 261 std::find(items.begin(), items.end(), browser); | 259 std::find(items.begin(), items.end(), browser); |
| 262 if (i != items.end()) { | 260 if (i != items.end()) { |
| 263 browser = (++i == items.end()) ? items[0] : *i; | 261 browser = (++i == items.end()) ? items[0] : *i; |
| 264 } else { | 262 } else { |
| 265 browser = | 263 browser = |
| 266 chrome::FindTabbedBrowser(launcher_controller()->profile(), true); | 264 chrome::FindTabbedBrowser(launcher_controller()->profile(), true); |
| 267 if (!browser || !IsBrowserRepresentedInBrowserList(browser)) | 265 if (!browser || !IsBrowserRepresentedInBrowserList(browser)) |
| 268 browser = items[0]; | 266 browser = items[0]; |
| 269 } | 267 } |
| 270 } | 268 } |
| 271 DCHECK(browser); | 269 DCHECK(browser); |
| 272 browser->window()->Show(); | 270 browser->window()->Show(); |
| 273 browser->window()->Activate(); | 271 browser->window()->Activate(); |
| 274 return kExistingWindowActivated; | 272 return ash::kExistingWindowActivated; |
| 275 } | 273 } |
| 276 | 274 |
| 277 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( | 275 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( |
| 278 Browser* browser) { | 276 Browser* browser) { |
| 279 // Only Ash desktop browser windows for the active user are represented. | 277 // Only Ash desktop browser windows for the active user are represented. |
| 280 if (!browser || !IsBrowserFromActiveUser(browser)) | 278 if (!browser || !IsBrowserFromActiveUser(browser)) |
| 281 return false; | 279 return false; |
| 282 | 280 |
| 283 // v1 App popup windows with a valid app id have their own icon. | 281 // v1 App popup windows with a valid app id have their own icon. |
| 284 if (browser->is_app() && browser->is_type_popup() && | 282 if (browser->is_app() && browser->is_type_popup() && |
| (...skipping 21 matching lines...) Expand all Loading... |
| 306 !browser->window()->IsMinimized()) { | 304 !browser->window()->IsMinimized()) { |
| 307 continue; | 305 continue; |
| 308 } | 306 } |
| 309 if (!IsBrowserRepresentedInBrowserList(browser) && | 307 if (!IsBrowserRepresentedInBrowserList(browser) && |
| 310 !browser->is_type_tabbed()) | 308 !browser->is_type_tabbed()) |
| 311 continue; | 309 continue; |
| 312 active_browsers.push_back(browser); | 310 active_browsers.push_back(browser); |
| 313 } | 311 } |
| 314 return active_browsers; | 312 return active_browsers; |
| 315 } | 313 } |
| OLD | NEW |