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

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

Issue 2671923002: mash: Cleanup ash shelf application menu code. (Closed)
Patch Set: Add comments Created 3 years, 10 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/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"
11 #include "ash/common/wm_shell.h" 11 #include "ash/common/wm_shell.h"
12 #include "ash/common/wm_window.h" 12 #include "ash/common/wm_window.h"
13 #include "ash/common/wm_window_property.h" 13 #include "ash/common/wm_window_property.h"
14 #include "ash/public/cpp/shelf_application_menu_item.h"
14 #include "ash/resources/grit/ash_resources.h" 15 #include "ash/resources/grit/ash_resources.h"
15 #include "ash/wm/window_util.h" 16 #include "ash/wm/window_util.h"
16 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
17 #include "chrome/browser/profiles/profile.h" 18 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
19 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h " 19 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_browser.h "
20 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h" 20 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_tab.h"
21 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 21 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
22 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h" 22 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller_util.h"
23 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
24 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h" 23 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
25 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
26 #include "chrome/browser/ui/browser_commands.h" 25 #include "chrome/browser/ui/browser_commands.h"
27 #include "chrome/browser/ui/browser_finder.h" 26 #include "chrome/browser/ui/browser_finder.h"
28 #include "chrome/browser/ui/browser_window.h" 27 #include "chrome/browser/ui/browser_window.h"
29 #include "chrome/browser/ui/chrome_pages.h" 28 #include "chrome/browser/ui/chrome_pages.h"
30 #include "chrome/browser/ui/settings_window_manager.h" 29 #include "chrome/browser/ui/settings_window_manager.h"
31 #include "chrome/browser/ui/tabs/tab_strip_model.h" 30 #include "chrome/browser/ui/tabs/tab_strip_model.h"
32 #include "chrome/browser/web_applications/web_app.h" 31 #include "chrome/browser/web_applications/web_app.h"
33 #include "chrome/common/extensions/extension_constants.h" 32 #include "chrome/common/extensions/extension_constants.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 BrowserShortcutLauncherItemController::Activate(ash::LaunchSource source) { 137 BrowserShortcutLauncherItemController::Activate(ash::LaunchSource source) {
139 Browser* last_browser = 138 Browser* last_browser =
140 chrome::FindTabbedBrowser(launcher_controller()->profile(), true); 139 chrome::FindTabbedBrowser(launcher_controller()->profile(), true);
141 140
142 if (!last_browser) { 141 if (!last_browser) {
143 chrome::NewEmptyWindow(launcher_controller()->profile()); 142 chrome::NewEmptyWindow(launcher_controller()->profile());
144 return kNewWindowCreated; 143 return kNewWindowCreated;
145 } 144 }
146 145
147 return launcher_controller()->ActivateWindowOrMinimizeIfActive( 146 return launcher_controller()->ActivateWindowOrMinimizeIfActive(
148 last_browser->window(), GetApplicationList(0).size() == 2); 147 last_browser->window(), GetAppMenuItems(0).size() == 1);
149 } 148 }
150 149
151 void BrowserShortcutLauncherItemController::Close() { 150 ash::ShelfItemDelegate::PerformedAction
152 for (auto* browser : GetListOfActiveBrowsers()) 151 BrowserShortcutLauncherItemController::ItemSelected(const ui::Event& event) {
153 browser->window()->Close(); 152 if (event.flags() & ui::EF_CONTROL_DOWN) {
153 chrome::NewEmptyWindow(launcher_controller()->profile());
154 return kNewWindowCreated;
155 }
156
157 // In case of a keyboard event, we were called by a hotkey. In that case we
158 // activate the next item in line if an item of our list is already active.
159 if (event.type() == ui::ET_KEY_RELEASED)
160 return ActivateOrAdvanceToNextBrowser();
161
162 return Activate(ash::LAUNCH_FROM_UNKNOWN);
154 } 163 }
155 164
156 ChromeLauncherAppMenuItems 165 ash::ShelfAppMenuItemList
157 BrowserShortcutLauncherItemController::GetApplicationList(int event_flags) { 166 BrowserShortcutLauncherItemController::GetAppMenuItems(int event_flags) {
158 ChromeLauncherAppMenuItems items; 167 ash::ShelfAppMenuItemList items;
159 bool found_tabbed_browser = false; 168 bool found_tabbed_browser = false;
160 // Add the application name to the menu.
161 base::string16 app_title = l10n_util::GetStringUTF16(IDS_PRODUCT_NAME);
162 items.push_back(
163 base::MakeUnique<ChromeLauncherAppMenuItem>(app_title, nullptr, false));
164 for (auto* browser : GetListOfActiveBrowsers()) { 169 for (auto* browser : GetListOfActiveBrowsers()) {
165 TabStripModel* tab_strip = browser->tab_strip_model(); 170 TabStripModel* tab_strip = browser->tab_strip_model();
166 if (tab_strip->active_index() == -1) 171 if (tab_strip->active_index() == -1)
167 continue; 172 continue;
168 if (browser->is_type_tabbed()) 173 if (browser->is_type_tabbed())
169 found_tabbed_browser = true; 174 found_tabbed_browser = true;
170 if (!(event_flags & ui::EF_SHIFT_DOWN)) { 175 if (!(event_flags & ui::EF_SHIFT_DOWN)) {
171 content::WebContents* web_contents = 176 content::WebContents* web_contents =
172 tab_strip->GetWebContentsAt(tab_strip->active_index()); 177 tab_strip->GetWebContentsAt(tab_strip->active_index());
173 gfx::Image app_icon = GetBrowserListIcon(web_contents); 178 gfx::Image app_icon = GetBrowserListIcon(web_contents);
174 base::string16 title = GetBrowserListTitle(web_contents); 179 base::string16 title = GetBrowserListTitle(web_contents);
175 items.push_back(base::MakeUnique<ChromeLauncherAppMenuItemBrowser>( 180 items.push_back(base::MakeUnique<ChromeLauncherAppMenuItemBrowser>(
176 title, &app_icon, browser, items.size() == 1)); 181 title, &app_icon, browser));
177 } else { 182 } else {
178 for (int index = 0; index < tab_strip->count(); ++index) { 183 for (int index = 0; index < tab_strip->count(); ++index) {
179 content::WebContents* web_contents = 184 content::WebContents* web_contents =
180 tab_strip->GetWebContentsAt(index); 185 tab_strip->GetWebContentsAt(index);
181 gfx::Image app_icon = 186 gfx::Image app_icon =
182 launcher_controller()->GetAppListIcon(web_contents); 187 launcher_controller()->GetAppListIcon(web_contents);
183 base::string16 title = 188 base::string16 title =
184 launcher_controller()->GetAppListTitle(web_contents); 189 launcher_controller()->GetAppListTitle(web_contents);
185 // Check if we need to insert a separator in front.
186 bool leading_separator = !index;
187 items.push_back(base::MakeUnique<ChromeLauncherAppMenuItemTab>( 190 items.push_back(base::MakeUnique<ChromeLauncherAppMenuItemTab>(
188 title, &app_icon, web_contents, leading_separator)); 191 title, &app_icon, web_contents));
189 } 192 }
190 } 193 }
191 } 194 }
192 // If only windowed applications are open, we return an empty list to 195 // If only windowed applications are open, we return an empty list to
193 // enforce the creation of a new browser. 196 // enforce the creation of a new browser.
194 if (!found_tabbed_browser) 197 if (!found_tabbed_browser)
195 items.clear(); 198 items.clear();
196 return items; 199 return items;
197 } 200 }
198 201
199 ash::ShelfItemDelegate::PerformedAction 202 void BrowserShortcutLauncherItemController::Close() {
200 BrowserShortcutLauncherItemController::ItemSelected(const ui::Event& event) { 203 for (auto* browser : GetListOfActiveBrowsers())
201 if (event.flags() & ui::EF_CONTROL_DOWN) { 204 browser->window()->Close();
202 chrome::NewEmptyWindow(launcher_controller()->profile());
203 return kNewWindowCreated;
204 }
205
206 // In case of a keyboard event, we were called by a hotkey. In that case we
207 // activate the next item in line if an item of our list is already active.
208 if (event.type() == ui::ET_KEY_RELEASED) {
209 return ActivateOrAdvanceToNextBrowser();
210 }
211
212 return Activate(ash::LAUNCH_FROM_UNKNOWN);
213 }
214
215 ui::SimpleMenuModel*
216 BrowserShortcutLauncherItemController::CreateApplicationMenu(int event_flags) {
217 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags));
218 } 205 }
219 206
220 bool BrowserShortcutLauncherItemController::IsListOfActiveBrowserEmpty() { 207 bool BrowserShortcutLauncherItemController::IsListOfActiveBrowserEmpty() {
221 return GetListOfActiveBrowsers().empty(); 208 return GetListOfActiveBrowsers().empty();
222 } 209 }
223 210
224 gfx::Image BrowserShortcutLauncherItemController::GetBrowserListIcon( 211 gfx::Image BrowserShortcutLauncherItemController::GetBrowserListIcon(
225 content::WebContents* web_contents) const { 212 content::WebContents* web_contents) const {
226 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 213 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
227 return rb.GetImageNamed(IsIncognito(web_contents) ? 214 return rb.GetImageNamed(IsIncognito(web_contents) ?
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 !browser->window()->IsMinimized()) { 311 !browser->window()->IsMinimized()) {
325 continue; 312 continue;
326 } 313 }
327 if (!IsBrowserRepresentedInBrowserList(browser) && 314 if (!IsBrowserRepresentedInBrowserList(browser) &&
328 !browser->is_type_tabbed()) 315 !browser->is_type_tabbed())
329 continue; 316 continue;
330 active_browsers.push_back(browser); 317 active_browsers.push_back(browser);
331 } 318 }
332 return active_browsers; 319 return active_browsers;
333 } 320 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698