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

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

Issue 23606016: Refactor LauncherItemController and LauncherItemDelegate (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix for LauncherTest and observing LauncherModel in DelegateManager Created 7 years, 3 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/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/launcher/launcher_util.h" 11 #include "ash/launcher/launcher_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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 browser_status = ash::STATUS_RUNNING; 93 browser_status = ash::STATUS_RUNNING;
92 } 94 }
93 } 95 }
94 96
95 if (browser_status != browser_item.status) { 97 if (browser_status != browser_item.status) {
96 browser_item.status = browser_status; 98 browser_item.status = browser_status;
97 model->Set(browser_index, browser_item); 99 model->Set(browser_index, browser_item);
98 } 100 }
99 } 101 }
100 102
101 string16 BrowserShortcutLauncherItemController::GetTitle() {
102 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
103 }
104
105 bool BrowserShortcutLauncherItemController::IsCurrentlyShownInWindow( 103 bool BrowserShortcutLauncherItemController::IsCurrentlyShownInWindow(
106 aura::Window* window) const { 104 aura::Window* window) const {
107 const BrowserList* ash_browser_list = 105 const BrowserList* ash_browser_list =
108 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH); 106 BrowserList::GetInstance(chrome::HOST_DESKTOP_TYPE_ASH);
109 for (BrowserList::const_iterator it = ash_browser_list->begin(); 107 for (BrowserList::const_iterator it = ash_browser_list->begin();
110 it != ash_browser_list->end(); ++it) { 108 it != ash_browser_list->end(); ++it) {
111 // During browser creation it is possible that this function is called 109 // During browser creation it is possible that this function is called
112 // before a browser got a window (see crbug.com/263563). 110 // before a browser got a window (see crbug.com/263563).
113 if ((*it)->window() && 111 if ((*it)->window() &&
114 (*it)->window()->GetNativeWindow() == window) 112 (*it)->window()->GetNativeWindow() == window)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 return; 149 return;
152 } 150 }
153 151
154 launcher_controller()->ActivateWindowOrMinimizeIfActive( 152 launcher_controller()->ActivateWindowOrMinimizeIfActive(
155 last_browser->window(), GetApplicationList(0).size() == 2); 153 last_browser->window(), GetApplicationList(0).size() == 2);
156 } 154 }
157 155
158 void BrowserShortcutLauncherItemController::Close() { 156 void BrowserShortcutLauncherItemController::Close() {
159 } 157 }
160 158
161 void BrowserShortcutLauncherItemController::Clicked(const ui::Event& event) {
162 #if defined(OS_CHROMEOS)
163 chromeos::default_pinned_apps_field_trial::RecordShelfClick(
164 chromeos::default_pinned_apps_field_trial::CHROME);
165 #endif
166
167 if (event.flags() & ui::EF_CONTROL_DOWN) {
168 launcher_controller()->CreateNewWindow();
169 return;
170 }
171
172 // In case of a keyboard event, we were called by a hotkey. In that case we
173 // activate the next item in line if an item of our list is already active.
174 if (event.type() & ui::ET_KEY_RELEASED) {
175 ActivateOrAdvanceToNextBrowser();
176 return;
177 }
178
179 Activate();
180 }
181
182 void BrowserShortcutLauncherItemController::OnRemoved() { 159 void BrowserShortcutLauncherItemController::OnRemoved() {
183 // BrowserShortcutLauncherItemController is owned by ChromeLauncherController. 160 // BrowserShortcutLauncherItemController is owned by ChromeLauncherController.
184 } 161 }
185 162
186 ChromeLauncherAppMenuItems 163 ChromeLauncherAppMenuItems
187 BrowserShortcutLauncherItemController::GetApplicationList(int event_flags) { 164 BrowserShortcutLauncherItemController::GetApplicationList(int event_flags) {
188 ChromeLauncherAppMenuItems items; 165 ChromeLauncherAppMenuItems items;
189 bool found_tabbed_browser = false; 166 bool found_tabbed_browser = false;
190 // Add the application name to the menu. 167 // Add the application name to the menu.
191 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); 168 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 } 205 }
229 } 206 }
230 } 207 }
231 // If only windowed applications are open, we return an empty list to 208 // If only windowed applications are open, we return an empty list to
232 // enforce the creation of a new browser. 209 // enforce the creation of a new browser.
233 if (!found_tabbed_browser) 210 if (!found_tabbed_browser)
234 items.clear(); 211 items.clear();
235 return items.Pass(); 212 return items.Pass();
236 } 213 }
237 214
215 void BrowserShortcutLauncherItemController::ItemSelected(
216 const ui::Event& event) {
217 #if defined(OS_CHROMEOS)
218 chromeos::default_pinned_apps_field_trial::RecordShelfClick(
219 chromeos::default_pinned_apps_field_trial::CHROME);
220 #endif
221
222 if (event.flags() & ui::EF_CONTROL_DOWN) {
223 launcher_controller()->CreateNewWindow();
224 return;
225 }
226
227 // In case of a keyboard event, we were called by a hotkey. In that case we
228 // activate the next item in line if an item of our list is already active.
229 if (event.type() & ui::ET_KEY_RELEASED) {
230 ActivateOrAdvanceToNextBrowser();
231 return;
232 }
233
234 Activate();
235 }
236
237 string16 BrowserShortcutLauncherItemController::GetTitle() {
238 return l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
239 }
240
241 ui::MenuModel* BrowserShortcutLauncherItemController::CreateContextMenu(
242 aura::RootWindow* root_window) {
243 ash::LauncherItem item =
244 *(launcher_controller()->model()->ItemByID(launcher_id()));
245 return new LauncherContextMenu(launcher_controller(), &item, root_window);
246 }
247
248 ash::LauncherMenuModel*
249 BrowserShortcutLauncherItemController::CreateApplicationMenu(int event_flags) {
250 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags));
251 }
252
253 bool BrowserShortcutLauncherItemController::IsDraggable() {
254 return launcher_controller()->CanPin() ? true : false;
255 }
256
257 bool BrowserShortcutLauncherItemController::ShouldShowTooltip() {
258 return true;
259 }
260
238 gfx::Image BrowserShortcutLauncherItemController::GetBrowserListIcon( 261 gfx::Image BrowserShortcutLauncherItemController::GetBrowserListIcon(
239 content::WebContents* web_contents) const { 262 content::WebContents* web_contents) const {
240 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 263 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
241 return rb.GetImageNamed(IsIncognito(web_contents) ? 264 return rb.GetImageNamed(IsIncognito(web_contents) ?
242 IDR_AURA_LAUNCHER_LIST_INCOGNITO_BROWSER : 265 IDR_AURA_LAUNCHER_LIST_INCOGNITO_BROWSER :
243 IDR_AURA_LAUNCHER_LIST_BROWSER); 266 IDR_AURA_LAUNCHER_LIST_BROWSER);
244 } 267 }
245 268
246 string16 BrowserShortcutLauncherItemController::GetBrowserListTitle( 269 string16 BrowserShortcutLauncherItemController::GetBrowserListTitle(
247 content::WebContents* web_contents) const { 270 content::WebContents* web_contents) const {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList( 334 bool BrowserShortcutLauncherItemController::IsBrowserRepresentedInBrowserList(
312 Browser* browser) { 335 Browser* browser) {
313 return (browser && 336 return (browser &&
314 (browser->is_type_tabbed() || 337 (browser->is_type_tabbed() ||
315 !browser->is_app() || 338 !browser->is_app() ||
316 !browser->is_type_popup() || 339 !browser->is_type_popup() ||
317 launcher_controller()-> 340 launcher_controller()->
318 GetLauncherIDForAppID(web_app::GetExtensionIdFromApplicationName( 341 GetLauncherIDForAppID(web_app::GetExtensionIdFromApplicationName(
319 browser->app_name())) <= 0)); 342 browser->app_name())) <= 0));
320 } 343 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698