OLD | NEW |
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_properties.h" | 10 #include "ash/wm/window_properties.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/base/events/event.h" | 21 #include "ui/base/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 Loading... |
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 23 matching lines...) Expand all Loading... |
131 | 120 |
132 void ShellWindowLauncherItemController::Close() { | 121 void ShellWindowLauncherItemController::Close() { |
133 // Note: Closing windows may affect the contents of shell_windows_. | 122 // Note: Closing windows may affect the contents of shell_windows_. |
134 ShellWindowList windows_to_close = shell_windows_; | 123 ShellWindowList windows_to_close = shell_windows_; |
135 for (ShellWindowList::iterator iter = windows_to_close.begin(); | 124 for (ShellWindowList::iterator iter = windows_to_close.begin(); |
136 iter != windows_to_close.end(); ++iter) { | 125 iter != windows_to_close.end(); ++iter) { |
137 (*iter)->GetBaseWindow()->Close(); | 126 (*iter)->GetBaseWindow()->Close(); |
138 } | 127 } |
139 } | 128 } |
140 | 129 |
141 void ShellWindowLauncherItemController::Clicked(const ui::Event& event) { | 130 void ShellWindowLauncherItemController::ActivateIndexedApp(size_t index) { |
| 131 if (index >= shell_windows_.size()) |
| 132 return; |
| 133 ShellWindowList::iterator it = shell_windows_.begin(); |
| 134 std::advance(it, index); |
| 135 ShowAndActivateOrMinimize(*it); |
| 136 } |
| 137 |
| 138 ChromeLauncherAppMenuItems |
| 139 ShellWindowLauncherItemController::GetApplicationList(int event_flags) { |
| 140 ChromeLauncherAppMenuItems items; |
| 141 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); |
| 142 int index = 0; |
| 143 for (ShellWindowList::iterator iter = shell_windows_.begin(); |
| 144 iter != shell_windows_.end(); ++iter) { |
| 145 ShellWindow* shell_window = *iter; |
| 146 scoped_ptr<gfx::Image> image(shell_window->GetAppListIcon()); |
| 147 items.push_back(new ChromeLauncherAppMenuItemV2App( |
| 148 shell_window->GetTitle(), |
| 149 image.get(), // Will be copied |
| 150 app_id(), |
| 151 launcher_controller(), |
| 152 index, |
| 153 index == 0 /* has_leading_separator */)); |
| 154 ++index; |
| 155 } |
| 156 return items.Pass(); |
| 157 } |
| 158 |
| 159 void ShellWindowLauncherItemController::ItemSelected(const ui::Event& event) { |
142 if (shell_windows_.empty()) | 160 if (shell_windows_.empty()) |
143 return; | 161 return; |
144 if (type() == TYPE_APP_PANEL) { | 162 if (type() == TYPE_APP_PANEL) { |
145 DCHECK(shell_windows_.size() == 1); | 163 DCHECK(shell_windows_.size() == 1); |
146 ShellWindow* panel = shell_windows_.front(); | 164 ShellWindow* panel = shell_windows_.front(); |
147 aura::Window* panel_window = panel->GetNativeWindow(); | 165 aura::Window* panel_window = panel->GetNativeWindow(); |
148 // If the panel is attached on another display, move it to the current | 166 // If the panel is attached on another display, move it to the current |
149 // display and activate it. | 167 // display and activate it. |
150 if (panel_window->GetProperty(ash::internal::kPanelAttachedKey) && | 168 if (panel_window->GetProperty(ash::internal::kPanelAttachedKey) && |
151 ash::wm::MoveWindowToEventRoot(panel_window, event)) { | 169 ash::wm::MoveWindowToEventRoot(panel_window, event)) { |
(...skipping 10 matching lines...) Expand all Loading... |
162 if (shell_windows_.size() >= 1 && | 180 if (shell_windows_.size() >= 1 && |
163 window_to_show->GetBaseWindow()->IsActive() && | 181 window_to_show->GetBaseWindow()->IsActive() && |
164 event.type() == ui::ET_KEY_RELEASED) { | 182 event.type() == ui::ET_KEY_RELEASED) { |
165 ActivateOrAdvanceToNextShellWindow(window_to_show); | 183 ActivateOrAdvanceToNextShellWindow(window_to_show); |
166 } else { | 184 } else { |
167 ShowAndActivateOrMinimize(window_to_show); | 185 ShowAndActivateOrMinimize(window_to_show); |
168 } | 186 } |
169 } | 187 } |
170 } | 188 } |
171 | 189 |
172 void ShellWindowLauncherItemController::ActivateIndexedApp(size_t index) { | 190 base::string16 ShellWindowLauncherItemController::GetTitle() { |
173 if (index >= shell_windows_.size()) | 191 // For panels return the title of the contents if set. |
174 return; | 192 // Otherwise return the title of the app. |
175 ShellWindowList::iterator it = shell_windows_.begin(); | 193 if (type() == TYPE_APP_PANEL && !shell_windows_.empty()) { |
176 std::advance(it, index); | 194 ShellWindow* shell_window = shell_windows_.front(); |
177 ShowAndActivateOrMinimize(*it); | 195 if (shell_window->web_contents()) { |
| 196 string16 title = shell_window->web_contents()->GetTitle(); |
| 197 if (!title.empty()) |
| 198 return title; |
| 199 } |
| 200 } |
| 201 return GetAppTitle(); |
178 } | 202 } |
179 | 203 |
180 ChromeLauncherAppMenuItems | 204 ui::MenuModel* ShellWindowLauncherItemController::CreateContextMenu( |
181 ShellWindowLauncherItemController::GetApplicationList(int event_flags) { | 205 aura::RootWindow* root_window) { |
182 ChromeLauncherAppMenuItems items; | 206 ash::LauncherItem item = |
183 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); | 207 *(launcher_controller()->model()->ItemByID(launcher_id())); |
184 int index = 0; | 208 return new LauncherContextMenu(launcher_controller(), &item, root_window); |
185 for (ShellWindowList::iterator iter = shell_windows_.begin(); | 209 } |
186 iter != shell_windows_.end(); ++iter) { | 210 |
187 ShellWindow* shell_window = *iter; | 211 ash::LauncherMenuModel* |
188 scoped_ptr<gfx::Image> image(shell_window->GetAppListIcon()); | 212 ShellWindowLauncherItemController::CreateApplicationMenu(int event_flags) { |
189 items.push_back(new ChromeLauncherAppMenuItemV2App( | 213 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags)); |
190 shell_window->GetTitle(), | 214 } |
191 image.get(), // Will be copied | 215 |
192 app_id(), | 216 bool ShellWindowLauncherItemController::IsDraggable() { |
193 launcher_controller(), | 217 if (type() == TYPE_APP_PANEL) |
194 index, | 218 return true; |
195 index == 0 /* has_leading_separator */)); | 219 else |
196 ++index; | 220 return launcher_controller()->CanPin() ? true : false; |
197 } | 221 } |
198 return items.Pass(); | 222 |
| 223 bool ShellWindowLauncherItemController::ShouldShowTooltip() { |
| 224 if (type() == TYPE_APP_PANEL && IsVisible()) |
| 225 return false; |
| 226 return true; |
199 } | 227 } |
200 | 228 |
201 void ShellWindowLauncherItemController::OnWindowPropertyChanged( | 229 void ShellWindowLauncherItemController::OnWindowPropertyChanged( |
202 aura::Window* window, | 230 aura::Window* window, |
203 const void* key, | 231 const void* key, |
204 intptr_t old) { | 232 intptr_t old) { |
205 if (key == aura::client::kDrawAttentionKey) { | 233 if (key == aura::client::kDrawAttentionKey) { |
206 ash::LauncherItemStatus status; | 234 ash::LauncherItemStatus status; |
207 if (ash::wm::IsActiveWindow(window)) { | 235 if (ash::wm::IsActiveWindow(window)) { |
208 status = ash::STATUS_ACTIVE; | 236 status = ash::STATUS_ACTIVE; |
(...skipping 28 matching lines...) Expand all Loading... |
237 } | 265 } |
238 if (window_to_show->GetBaseWindow()->IsActive()) { | 266 if (window_to_show->GetBaseWindow()->IsActive()) { |
239 // Coming here, only a single window is active. For keyboard activations | 267 // Coming here, only a single window is active. For keyboard activations |
240 // the window gets animated. | 268 // the window gets animated. |
241 AnimateWindow(window_to_show->GetNativeWindow(), | 269 AnimateWindow(window_to_show->GetNativeWindow(), |
242 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE); | 270 views::corewm::WINDOW_ANIMATION_TYPE_BOUNCE); |
243 } else { | 271 } else { |
244 ShowAndActivateOrMinimize(window_to_show); | 272 ShowAndActivateOrMinimize(window_to_show); |
245 } | 273 } |
246 } | 274 } |
OLD | NEW |