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

Side by Side Diff: chrome/browser/ui/ash/launcher/shell_window_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 unittest.. Created 7 years, 2 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
« no previous file with comments | « chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/shell_window_launcher_item_controller.h " 5 #include "chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h "
6 6
7 #include "apps/native_app_window.h" 7 #include "apps/native_app_window.h"
8 #include "apps/shell_window.h" 8 #include "apps/shell_window.h"
9 #include "ash/launcher/launcher_model.h"
9 #include "ash/wm/window_state.h" 10 #include "ash/wm/window_state.h"
10 #include "ash/wm/window_util.h" 11 #include "ash/wm/window_util.h"
11 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" 12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h"
12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h" 13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h"
13 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" 14 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h"
15 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h"
16 #include "chrome/browser/ui/ash/launcher/launcher_context_menu.h"
14 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h" 17 #include "chrome/browser/ui/ash/launcher/launcher_item_controller.h"
15 #include "content/public/browser/web_contents.h" 18 #include "content/public/browser/web_contents.h"
16 #include "ui/aura/client/aura_constants.h" 19 #include "ui/aura/client/aura_constants.h"
17 #include "ui/aura/window.h" 20 #include "ui/aura/window.h"
18 #include "ui/events/event.h" 21 #include "ui/events/event.h"
19 #include "ui/views/corewm/window_animations.h" 22 #include "ui/views/corewm/window_animations.h"
20 23
21 using apps::ShellWindow; 24 using apps::ShellWindow;
22 25
23 namespace { 26 namespace {
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 } 77 }
75 78
76 void ShellWindowLauncherItemController::SetActiveWindow(aura::Window* window) { 79 void ShellWindowLauncherItemController::SetActiveWindow(aura::Window* window) {
77 ShellWindowList::iterator iter = 80 ShellWindowList::iterator iter =
78 std::find_if(shell_windows_.begin(), shell_windows_.end(), 81 std::find_if(shell_windows_.begin(), shell_windows_.end(),
79 ShellWindowHasWindow(window)); 82 ShellWindowHasWindow(window));
80 if (iter != shell_windows_.end()) 83 if (iter != shell_windows_.end())
81 last_active_shell_window_ = *iter; 84 last_active_shell_window_ = *iter;
82 } 85 }
83 86
84 string16 ShellWindowLauncherItemController::GetTitle() {
85 // For panels return the title of the contents if set.
86 // Otherwise return the title of the app.
87 if (type() == TYPE_APP_PANEL && !shell_windows_.empty()) {
88 ShellWindow* shell_window = shell_windows_.front();
89 if (shell_window->web_contents()) {
90 string16 title = shell_window->web_contents()->GetTitle();
91 if (!title.empty())
92 return title;
93 }
94 }
95 return GetAppTitle();
96 }
97
98 bool ShellWindowLauncherItemController::IsCurrentlyShownInWindow( 87 bool ShellWindowLauncherItemController::IsCurrentlyShownInWindow(
99 aura::Window* window) const { 88 aura::Window* window) const {
100 ShellWindowList::const_iterator iter = 89 ShellWindowList::const_iterator iter =
101 std::find_if(shell_windows_.begin(), shell_windows_.end(), 90 std::find_if(shell_windows_.begin(), shell_windows_.end(),
102 ShellWindowHasWindow(window)); 91 ShellWindowHasWindow(window));
103 return iter != shell_windows_.end(); 92 return iter != shell_windows_.end();
104 } 93 }
105 94
106 bool ShellWindowLauncherItemController::IsOpen() const { 95 bool ShellWindowLauncherItemController::IsOpen() const {
107 return !shell_windows_.empty(); 96 return !shell_windows_.empty();
(...skipping 25 matching lines...) Expand all
133 122
134 void ShellWindowLauncherItemController::Close() { 123 void ShellWindowLauncherItemController::Close() {
135 // Note: Closing windows may affect the contents of shell_windows_. 124 // Note: Closing windows may affect the contents of shell_windows_.
136 ShellWindowList windows_to_close = shell_windows_; 125 ShellWindowList windows_to_close = shell_windows_;
137 for (ShellWindowList::iterator iter = windows_to_close.begin(); 126 for (ShellWindowList::iterator iter = windows_to_close.begin();
138 iter != windows_to_close.end(); ++iter) { 127 iter != windows_to_close.end(); ++iter) {
139 (*iter)->GetBaseWindow()->Close(); 128 (*iter)->GetBaseWindow()->Close();
140 } 129 }
141 } 130 }
142 131
143 void ShellWindowLauncherItemController::Clicked(const ui::Event& event) { 132 void ShellWindowLauncherItemController::ActivateIndexedApp(size_t index) {
133 if (index >= shell_windows_.size())
134 return;
135 ShellWindowList::iterator it = shell_windows_.begin();
136 std::advance(it, index);
137 ShowAndActivateOrMinimize(*it);
138 }
139
140 ChromeLauncherAppMenuItems
141 ShellWindowLauncherItemController::GetApplicationList(int event_flags) {
142 ChromeLauncherAppMenuItems items;
143 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false));
144 int index = 0;
145 for (ShellWindowList::iterator iter = shell_windows_.begin();
146 iter != shell_windows_.end(); ++iter) {
147 ShellWindow* shell_window = *iter;
148 scoped_ptr<gfx::Image> image(shell_window->GetAppListIcon());
149 items.push_back(new ChromeLauncherAppMenuItemV2App(
150 shell_window->GetTitle(),
151 image.get(), // Will be copied
152 app_id(),
153 launcher_controller(),
154 index,
155 index == 0 /* has_leading_separator */));
156 ++index;
157 }
158 return items.Pass();
159 }
160
161 void ShellWindowLauncherItemController::ItemSelected(const ui::Event& event) {
144 if (shell_windows_.empty()) 162 if (shell_windows_.empty())
145 return; 163 return;
146 if (type() == TYPE_APP_PANEL) { 164 if (type() == TYPE_APP_PANEL) {
147 DCHECK(shell_windows_.size() == 1); 165 DCHECK(shell_windows_.size() == 1);
148 ShellWindow* panel = shell_windows_.front(); 166 ShellWindow* panel = shell_windows_.front();
149 aura::Window* panel_window = panel->GetNativeWindow(); 167 aura::Window* panel_window = panel->GetNativeWindow();
150 // If the panel is attached on another display, move it to the current 168 // If the panel is attached on another display, move it to the current
151 // display and activate it. 169 // display and activate it.
152 if (ash::wm::GetWindowState(panel_window)->panel_attached() && 170 if (ash::wm::GetWindowState(panel_window)->panel_attached() &&
153 ash::wm::MoveWindowToEventRoot(panel_window, event)) { 171 ash::wm::MoveWindowToEventRoot(panel_window, event)) {
(...skipping 10 matching lines...) Expand all
164 if (shell_windows_.size() >= 1 && 182 if (shell_windows_.size() >= 1 &&
165 window_to_show->GetBaseWindow()->IsActive() && 183 window_to_show->GetBaseWindow()->IsActive() &&
166 event.type() == ui::ET_KEY_RELEASED) { 184 event.type() == ui::ET_KEY_RELEASED) {
167 ActivateOrAdvanceToNextShellWindow(window_to_show); 185 ActivateOrAdvanceToNextShellWindow(window_to_show);
168 } else { 186 } else {
169 ShowAndActivateOrMinimize(window_to_show); 187 ShowAndActivateOrMinimize(window_to_show);
170 } 188 }
171 } 189 }
172 } 190 }
173 191
174 void ShellWindowLauncherItemController::ActivateIndexedApp(size_t index) { 192 base::string16 ShellWindowLauncherItemController::GetTitle() {
175 if (index >= shell_windows_.size()) 193 // For panels return the title of the contents if set.
176 return; 194 // Otherwise return the title of the app.
177 ShellWindowList::iterator it = shell_windows_.begin(); 195 if (type() == TYPE_APP_PANEL && !shell_windows_.empty()) {
178 std::advance(it, index); 196 ShellWindow* shell_window = shell_windows_.front();
179 ShowAndActivateOrMinimize(*it); 197 if (shell_window->web_contents()) {
198 string16 title = shell_window->web_contents()->GetTitle();
199 if (!title.empty())
200 return title;
201 }
202 }
203 return GetAppTitle();
180 } 204 }
181 205
182 ChromeLauncherAppMenuItems 206 ui::MenuModel* ShellWindowLauncherItemController::CreateContextMenu(
183 ShellWindowLauncherItemController::GetApplicationList(int event_flags) { 207 aura::RootWindow* root_window) {
184 ChromeLauncherAppMenuItems items; 208 ash::LauncherItem item =
185 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); 209 *(launcher_controller()->model()->ItemByID(launcher_id()));
186 int index = 0; 210 return new LauncherContextMenu(launcher_controller(), &item, root_window);
187 for (ShellWindowList::iterator iter = shell_windows_.begin(); 211 }
188 iter != shell_windows_.end(); ++iter) { 212
189 ShellWindow* shell_window = *iter; 213 ash::LauncherMenuModel*
190 scoped_ptr<gfx::Image> image(shell_window->GetAppListIcon()); 214 ShellWindowLauncherItemController::CreateApplicationMenu(int event_flags) {
191 items.push_back(new ChromeLauncherAppMenuItemV2App( 215 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags));
192 shell_window->GetTitle(), 216 }
193 image.get(), // Will be copied 217
194 app_id(), 218 bool ShellWindowLauncherItemController::IsDraggable() {
195 launcher_controller(), 219 if (type() == TYPE_APP_PANEL)
196 index, 220 return true;
197 index == 0 /* has_leading_separator */)); 221 return launcher_controller()->CanPin() ? true : false;
198 ++index; 222 }
199 } 223
200 return items.Pass(); 224 bool ShellWindowLauncherItemController::ShouldShowTooltip() {
225 if (type() == TYPE_APP_PANEL && IsVisible())
226 return false;
227 return true;
201 } 228 }
202 229
203 void ShellWindowLauncherItemController::OnWindowPropertyChanged( 230 void ShellWindowLauncherItemController::OnWindowPropertyChanged(
204 aura::Window* window, 231 aura::Window* window,
205 const void* key, 232 const void* key,
206 intptr_t old) { 233 intptr_t old) {
207 if (key == aura::client::kDrawAttentionKey) { 234 if (key == aura::client::kDrawAttentionKey) {
208 ash::LauncherItemStatus status; 235 ash::LauncherItemStatus status;
209 if (ash::wm::IsActiveWindow(window)) { 236 if (ash::wm::IsActiveWindow(window)) {
210 status = ash::STATUS_ACTIVE; 237 status = ash::STATUS_ACTIVE;
(...skipping 28 matching lines...) Expand all
239 } 266 }
240 if (window_to_show->GetBaseWindow()->IsActive()) { 267 if (window_to_show->GetBaseWindow()->IsActive()) {
241 // Coming here, only a single window is active. For keyboard activations 268 // Coming here, only a single window is active. For keyboard activations
242 // the window gets animated. 269 // the window gets animated.
243 AnimateWindow(window_to_show->GetNativeWindow(), 270 AnimateWindow(window_to_show->GetNativeWindow(),
244 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE); 271 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE);
245 } else { 272 } else {
246 ShowAndActivateOrMinimize(window_to_show); 273 ShowAndActivateOrMinimize(window_to_show);
247 } 274 }
248 } 275 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/launcher/shell_window_launcher_item_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698