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/launcher/launcher.h" | 9 #include "ash/launcher/launcher.h" |
10 #include "ash/launcher/launcher_model.h" | 10 #include "ash/launcher/launcher_model.h" |
11 #include "ash/shelf/shelf_util.h" | 11 #include "ash/shelf/shelf_util.h" |
12 #include "ash/shell.h" | 12 #include "ash/shell.h" |
13 #include "ash/wm/window_util.h" | 13 #include "ash/wm/window_util.h" |
14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.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.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_browser.h
" |
17 #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" |
18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.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/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
20 #include "chrome/browser/ui/browser_finder.h" | 22 #include "chrome/browser/ui/browser_finder.h" |
21 #include "chrome/browser/ui/browser_list.h" | 23 #include "chrome/browser/ui/browser_list.h" |
22 #include "chrome/browser/ui/browser_window.h" | 24 #include "chrome/browser/ui/browser_window.h" |
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
24 #include "chrome/browser/web_applications/web_app.h" | 26 #include "chrome/browser/web_applications/web_app.h" |
25 #include "chrome/common/extensions/extension_constants.h" | 27 #include "chrome/common/extensions/extension_constants.h" |
26 #include "content/public/browser/web_contents.h" | 28 #include "content/public/browser/web_contents.h" |
27 #include "grit/ash_resources.h" | 29 #include "grit/ash_resources.h" |
28 #include "grit/chromium_strings.h" | 30 #include "grit/chromium_strings.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 browser_status = ash::STATUS_RUNNING; | 91 browser_status = ash::STATUS_RUNNING; |
90 } | 92 } |
91 } | 93 } |
92 | 94 |
93 if (browser_status != browser_item.status) { | 95 if (browser_status != browser_item.status) { |
94 browser_item.status = browser_status; | 96 browser_item.status = browser_status; |
95 model->Set(browser_index, browser_item); | 97 model->Set(browser_index, browser_item); |
96 } | 98 } |
97 } | 99 } |
98 | 100 |
99 string16 BrowserShortcutLauncherItemController::GetTitle() { | |
100 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); | |
101 } | |
102 | |
103 bool BrowserShortcutLauncherItemController::IsCurrentlyShownInWindow( | 101 bool BrowserShortcutLauncherItemController::IsCurrentlyShownInWindow( |
104 aura::Window* window) const { | 102 aura::Window* window) const { |
105 const BrowserList* ash_browser_list = | 103 const BrowserList* ash_browser_list = |
106 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 104 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
107 for (BrowserList::const_iterator it = ash_browser_list->begin(); | 105 for (BrowserList::const_iterator it = ash_browser_list->begin(); |
108 it != ash_browser_list->end(); ++it) { | 106 it != ash_browser_list->end(); ++it) { |
109 // During browser creation it is possible that this function is called | 107 // During browser creation it is possible that this function is called |
110 // before a browser got a window (see crbug.com/263563). | 108 // before a browser got a window (see crbug.com/263563). |
111 if ((*it)->window() && | 109 if ((*it)->window() && |
112 (*it)->window()->GetNativeWindow() == window) | 110 (*it)->window()->GetNativeWindow() == window) |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 return; | 148 return; |
151 } | 149 } |
152 | 150 |
153 launcher_controller()->ActivateWindowOrMinimizeIfActive( | 151 launcher_controller()->ActivateWindowOrMinimizeIfActive( |
154 last_browser->window(), GetApplicationList(0).size() == 2); | 152 last_browser->window(), GetApplicationList(0).size() == 2); |
155 } | 153 } |
156 | 154 |
157 void BrowserShortcutLauncherItemController::Close() { | 155 void BrowserShortcutLauncherItemController::Close() { |
158 } | 156 } |
159 | 157 |
160 void BrowserShortcutLauncherItemController::Clicked(const ui::Event& event) { | |
161 #if defined(OS_CHROMEOS) | |
162 chromeos::default_pinned_apps_field_trial::RecordShelfClick( | |
163 chromeos::default_pinned_apps_field_trial::CHROME); | |
164 #endif | |
165 | |
166 if (event.flags() & ui::EF_CONTROL_DOWN) { | |
167 launcher_controller()->CreateNewWindow(); | |
168 return; | |
169 } | |
170 | |
171 // In case of a keyboard event, we were called by a hotkey. In that case we | |
172 // activate the next item in line if an item of our list is already active. | |
173 if (event.type() & ui::ET_KEY_RELEASED) { | |
174 ActivateOrAdvanceToNextBrowser(); | |
175 return; | |
176 } | |
177 | |
178 Activate(ash::LAUNCH_FROM_UNKNOWN); | |
179 } | |
180 | |
181 void BrowserShortcutLauncherItemController::OnRemoved() { | |
182 // BrowserShortcutLauncherItemController is owned by ChromeLauncherController. | |
183 } | |
184 | |
185 ChromeLauncherAppMenuItems | 158 ChromeLauncherAppMenuItems |
186 BrowserShortcutLauncherItemController::GetApplicationList(int event_flags) { | 159 BrowserShortcutLauncherItemController::GetApplicationList(int event_flags) { |
187 ChromeLauncherAppMenuItems items; | 160 ChromeLauncherAppMenuItems items; |
188 bool found_tabbed_browser = false; | 161 bool found_tabbed_browser = false; |
189 // Add the application name to the menu. | 162 // Add the application name to the menu. |
190 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); | 163 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); |
191 const BrowserList* ash_browser_list = | 164 const BrowserList* ash_browser_list = |
192 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); | 165 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); |
193 for (BrowserList::const_iterator it = ash_browser_list->begin(); | 166 for (BrowserList::const_iterator it = ash_browser_list->begin(); |
194 it != ash_browser_list->end(); ++it) { | 167 it != ash_browser_list->end(); ++it) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 } | 200 } |
228 } | 201 } |
229 } | 202 } |
230 // If only windowed applications are open, we return an empty list to | 203 // If only windowed applications are open, we return an empty list to |
231 // enforce the creation of a new browser. | 204 // enforce the creation of a new browser. |
232 if (!found_tabbed_browser) | 205 if (!found_tabbed_browser) |
233 items.clear(); | 206 items.clear(); |
234 return items.Pass(); | 207 return items.Pass(); |
235 } | 208 } |
236 | 209 |
| 210 void BrowserShortcutLauncherItemController::ItemSelected( |
| 211 const ui::Event& event) { |
| 212 #if defined(OS_CHROMEOS) |
| 213 chromeos::default_pinned_apps_field_trial::RecordShelfClick( |
| 214 chromeos::default_pinned_apps_field_trial::CHROME); |
| 215 #endif |
| 216 |
| 217 if (event.flags() & ui::EF_CONTROL_DOWN) { |
| 218 launcher_controller()->CreateNewWindow(); |
| 219 return; |
| 220 } |
| 221 |
| 222 // In case of a keyboard event, we were called by a hotkey. In that case we |
| 223 // activate the next item in line if an item of our list is already active. |
| 224 if (event.type() & ui::ET_KEY_RELEASED) { |
| 225 ActivateOrAdvanceToNextBrowser(); |
| 226 return; |
| 227 } |
| 228 |
| 229 Activate(ash::LAUNCH_FROM_UNKNOWN); |
| 230 } |
| 231 |
| 232 string16 BrowserShortcutLauncherItemController::GetTitle() { |
| 233 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME); |
| 234 } |
| 235 |
| 236 ui::MenuModel* BrowserShortcutLauncherItemController::CreateContextMenu( |
| 237 aura::RootWindow* root_window) { |
| 238 ash::LauncherItem item = |
| 239 *(launcher_controller()->model()->ItemByID(launcher_id())); |
| 240 return new LauncherContextMenu(launcher_controller(), &item, root_window); |
| 241 } |
| 242 |
| 243 ash::LauncherMenuModel* |
| 244 BrowserShortcutLauncherItemController::CreateApplicationMenu(int event_flags) { |
| 245 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags)); |
| 246 } |
| 247 |
| 248 bool BrowserShortcutLauncherItemController::IsDraggable() { |
| 249 return launcher_controller()->CanPin() ? true : false; |
| 250 } |
| 251 |
| 252 bool BrowserShortcutLauncherItemController::ShouldShowTooltip() { |
| 253 return true; |
| 254 } |
| 255 |
237 gfx::Image BrowserShortcutLauncherItemController::GetBrowserListIcon( | 256 gfx::Image BrowserShortcutLauncherItemController::GetBrowserListIcon( |
238 content::WebContents* web_contents) const { | 257 content::WebContents* web_contents) const { |
239 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 258 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
240 return rb.GetImageNamed(IsIncognito(web_contents) ? | 259 return rb.GetImageNamed(IsIncognito(web_contents) ? |
241 IDR_AURA_LAUNCHER_LIST_INCOGNITO_BROWSER : | 260 IDR_AURA_LAUNCHER_LIST_INCOGNITO_BROWSER : |
242 IDR_AURA_LAUNCHER_LIST_BROWSER); | 261 IDR_AURA_LAUNCHER_LIST_BROWSER); |
243 } | 262 } |
244 | 263 |
245 string16 BrowserShortcutLauncherItemController::GetBrowserListTitle( | 264 string16 BrowserShortcutLauncherItemController::GetBrowserListTitle( |
246 content::WebContents* web_contents) const { | 265 content::WebContents* web_contents) const { |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 Browser* browser) { | 330 Browser* browser) { |
312 return (browser && | 331 return (browser && |
313 browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH && | 332 browser->host_desktop_type() == chrome::HOST_DESKTOP_TYPE_ASH && |
314 (browser->is_type_tabbed() || | 333 (browser->is_type_tabbed() || |
315 !browser->is_app() || | 334 !browser->is_app() || |
316 !browser->is_type_popup() || | 335 !browser->is_type_popup() || |
317 launcher_controller()-> | 336 launcher_controller()-> |
318 GetLauncherIDForAppID(web_app::GetExtensionIdFromApplicationName( | 337 GetLauncherIDForAppID(web_app::GetExtensionIdFromApplicationName( |
319 browser->app_name())) <= 0)); | 338 browser->app_name())) <= 0)); |
320 } | 339 } |
OLD | NEW |