Chromium Code Reviews| 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 "ash/launcher/launcher_util.h" | 7 #include "ash/launcher/launcher_util.h" |
| 8 #include "ash/wm/window_util.h" | 8 #include "ash/wm/window_util.h" |
| 9 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" | 9 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item.h" |
| 10 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h" | 10 #include "chrome/browser/ui/ash/launcher/chrome_launcher_app_menu_item_v2app.h" |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 }; | 32 }; |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 ShellWindowLauncherItemController::ShellWindowLauncherItemController( | 36 ShellWindowLauncherItemController::ShellWindowLauncherItemController( |
| 37 Type type, | 37 Type type, |
| 38 const std::string& app_launcher_id, | 38 const std::string& app_launcher_id, |
| 39 const std::string& app_id, | 39 const std::string& app_id, |
| 40 ChromeLauncherController* controller) | 40 ChromeLauncherController* controller) |
| 41 : LauncherItemController(type, app_id, controller), | 41 : LauncherItemController(type, app_id, controller), |
| 42 last_active_shell_window_(NULL), | |
| 42 app_launcher_id_(app_launcher_id), | 43 app_launcher_id_(app_launcher_id), |
| 43 ALLOW_THIS_IN_INITIALIZER_LIST(observed_windows_(this)) { | 44 ALLOW_THIS_IN_INITIALIZER_LIST(observed_windows_(this)) { |
| 44 } | 45 } |
| 45 | 46 |
| 46 ShellWindowLauncherItemController::~ShellWindowLauncherItemController() { | 47 ShellWindowLauncherItemController::~ShellWindowLauncherItemController() { |
| 47 } | 48 } |
| 48 | 49 |
| 49 void ShellWindowLauncherItemController::AddShellWindow( | 50 void ShellWindowLauncherItemController::AddShellWindow( |
| 50 ShellWindow* shell_window, | 51 ShellWindow* shell_window, |
| 51 ash::LauncherItemStatus status) { | 52 ash::LauncherItemStatus status) { |
| 52 if (shell_window->window_type_is_panel() && type() != TYPE_APP_PANEL) { | 53 if (shell_window->window_type_is_panel() && type() != TYPE_APP_PANEL) |
| 53 LOG(ERROR) << "ShellWindow of type Panel added to non-panel launcher item"; | 54 LOG(ERROR) << "ShellWindow of type Panel added to non-panel launcher item"; |
| 54 } | 55 shell_windows_.push_front(shell_window); |
| 55 if (status == ash::STATUS_ACTIVE) | |
| 56 shell_windows_.push_front(shell_window); | |
| 57 else | |
| 58 shell_windows_.push_back(shell_window); | |
| 59 observed_windows_.Add(shell_window->GetNativeWindow()); | 56 observed_windows_.Add(shell_window->GetNativeWindow()); |
| 60 } | 57 } |
| 61 | 58 |
| 62 void ShellWindowLauncherItemController::RemoveShellWindowForWindow( | 59 void ShellWindowLauncherItemController::RemoveShellWindowForWindow( |
| 63 aura::Window* window) { | 60 aura::Window* window) { |
| 64 ShellWindowList::iterator iter = | 61 ShellWindowList::iterator iter = |
| 65 std::find_if(shell_windows_.begin(), shell_windows_.end(), | 62 std::find_if(shell_windows_.begin(), shell_windows_.end(), |
| 66 ShellWindowHasWindow(window)); | 63 ShellWindowHasWindow(window)); |
| 67 if (iter != shell_windows_.end()) | 64 if (iter != shell_windows_.end()) |
| 68 shell_windows_.erase(iter); | 65 shell_windows_.erase(iter); |
| 69 observed_windows_.Remove(window); | 66 observed_windows_.Remove(window); |
|
Mr4D (OOO till 08-26)
2013/03/22 00:45:31
You should possibly check if the removed window is
stevenjb
2013/03/22 19:18:33
Good catch, thanks. NULL should be fine.
| |
| 70 } | 67 } |
| 71 | 68 |
| 72 void ShellWindowLauncherItemController::SetActiveWindow( | 69 void ShellWindowLauncherItemController::SetActiveWindow(aura::Window* window) { |
| 73 aura::Window* window) { | |
| 74 ShellWindowList::iterator iter = | 70 ShellWindowList::iterator iter = |
| 75 std::find_if(shell_windows_.begin(), shell_windows_.end(), | 71 std::find_if(shell_windows_.begin(), shell_windows_.end(), |
| 76 ShellWindowHasWindow(window)); | 72 ShellWindowHasWindow(window)); |
| 77 if (iter != shell_windows_.end()) { | 73 if (iter != shell_windows_.end()) |
| 78 ShellWindow* shell_window = *iter; | 74 last_active_shell_window_ = *iter; |
| 79 shell_windows_.erase(iter); | |
| 80 shell_windows_.push_front(shell_window); | |
| 81 } | |
| 82 } | 75 } |
| 83 | 76 |
| 84 string16 ShellWindowLauncherItemController::GetTitle() { | 77 string16 ShellWindowLauncherItemController::GetTitle() { |
| 85 return GetAppTitle(); | 78 return GetAppTitle(); |
| 86 } | 79 } |
| 87 | 80 |
| 88 bool ShellWindowLauncherItemController::HasWindow( | 81 bool ShellWindowLauncherItemController::HasWindow( |
| 89 aura::Window* window) const { | 82 aura::Window* window) const { |
| 90 ShellWindowList::const_iterator iter = | 83 ShellWindowList::const_iterator iter = |
| 91 std::find_if(shell_windows_.begin(), shell_windows_.end(), | 84 std::find_if(shell_windows_.begin(), shell_windows_.end(), |
| 92 ShellWindowHasWindow(window)); | 85 ShellWindowHasWindow(window)); |
| 93 return iter != shell_windows_.end(); | 86 return iter != shell_windows_.end(); |
| 94 } | 87 } |
| 95 | 88 |
| 96 bool ShellWindowLauncherItemController::IsOpen() const { | 89 bool ShellWindowLauncherItemController::IsOpen() const { |
| 97 return !shell_windows_.empty(); | 90 return !shell_windows_.empty(); |
| 98 } | 91 } |
| 99 | 92 |
| 100 void ShellWindowLauncherItemController::Launch( | 93 void ShellWindowLauncherItemController::Launch( |
| 101 int event_flags) { | 94 int event_flags) { |
| 102 launcher_controller()->LaunchApp(app_id(), ui::EF_NONE); | 95 launcher_controller()->LaunchApp(app_id(), ui::EF_NONE); |
| 103 } | 96 } |
| 104 | 97 |
| 105 void ShellWindowLauncherItemController::Activate() { | 98 void ShellWindowLauncherItemController::Activate() { |
| 106 DCHECK(!shell_windows_.empty()); | 99 DCHECK(!shell_windows_.empty()); |
| 107 shell_windows_.front()->GetBaseWindow()->Activate(); | 100 ShellWindow* window_to_activate = last_active_shell_window_ ? |
| 101 last_active_shell_window_ : shell_windows_.back(); | |
| 102 window_to_activate->GetBaseWindow()->Activate(); | |
| 108 } | 103 } |
| 109 | 104 |
| 110 void ShellWindowLauncherItemController::Close() { | 105 void ShellWindowLauncherItemController::Close() { |
| 111 // Note: Closing windows may affect the contents of shell_windows_. | 106 // Note: Closing windows may affect the contents of shell_windows_. |
| 112 ShellWindowList windows_to_close = shell_windows_; | 107 ShellWindowList windows_to_close = shell_windows_; |
| 113 for (ShellWindowList::iterator iter = windows_to_close.begin(); | 108 for (ShellWindowList::iterator iter = windows_to_close.begin(); |
| 114 iter != windows_to_close.end(); ++iter) { | 109 iter != windows_to_close.end(); ++iter) { |
| 115 (*iter)->GetBaseWindow()->Close(); | 110 (*iter)->GetBaseWindow()->Close(); |
| 116 } | 111 } |
| 117 } | 112 } |
| 118 | 113 |
| 119 // Behavior for app windows: | |
| 120 // * One window: Toggle minimization when clicked. | |
| 121 // * Multiple windows: | |
| 122 // ** If the first window is not active, activate it. | |
| 123 // ** Otherwise activate the next window. | |
| 124 void ShellWindowLauncherItemController::Clicked(const ui::Event& event) { | 114 void ShellWindowLauncherItemController::Clicked(const ui::Event& event) { |
| 125 if (shell_windows_.empty()) | 115 if (shell_windows_.empty()) |
| 126 return; | 116 return; |
| 127 ShellWindow* first_window = shell_windows_.front(); | 117 if (launcher_controller()->GetPerAppInterface() || |
| 128 if (shell_windows_.size() == 1) { | 118 shell_windows_.size() == 1) { |
| 129 ash::launcher::MoveToEventRootIfPanel(first_window->GetNativeWindow(), | 119 ShellWindow* window_to_show = last_active_shell_window_ ? |
| 130 event); | 120 last_active_shell_window_ : shell_windows_.front(); |
| 131 // If the window moves, it becomes inactive first then | 121 RestoreOrShow(window_to_show); |
| 132 // gets activated in |RestoreOrShow| below. | |
| 133 if (first_window->GetBaseWindow()->IsActive()) | |
| 134 first_window->GetBaseWindow()->Minimize(); | |
| 135 else | |
| 136 RestoreOrShow(first_window); | |
| 137 } else { | 122 } else { |
| 138 if (!first_window->GetBaseWindow()->IsActive()) { | 123 // TODO(stevenjb): Deprecate |
| 139 RestoreOrShow(first_window); | 124 if (!last_active_shell_window_ || |
| 140 } else { | 125 last_active_shell_window_->GetBaseWindow()->IsActive()) { |
| 141 shell_windows_.pop_front(); | 126 // Restore all windows since there is no other way to restore them. |
| 142 shell_windows_.push_back(first_window); | 127 for (ShellWindowList::iterator iter = shell_windows_.begin(); |
| 143 RestoreOrShow(shell_windows_.front()); | 128 iter != shell_windows_.end(); ++iter) { |
| 129 ShellWindow* shell_window = *iter; | |
| 130 if (shell_window->GetBaseWindow()->IsMinimized()) | |
| 131 shell_window->GetBaseWindow()->Restore(); | |
| 132 } | |
| 144 } | 133 } |
| 134 if (last_active_shell_window_) | |
| 135 RestoreOrShow(last_active_shell_window_); | |
| 145 } | 136 } |
| 146 } | 137 } |
| 147 | 138 |
| 148 void ShellWindowLauncherItemController::ActivateIndexedApp( | 139 void ShellWindowLauncherItemController::ActivateIndexedApp(size_t index) { |
| 149 size_t index) { | 140 if (index >= shell_windows_.size()) |
| 150 if (index < shell_windows_.size()) { | 141 return; |
| 151 ShellWindowList::iterator it = shell_windows_.begin(); | 142 ShellWindowList::iterator it = shell_windows_.begin(); |
| 152 std::advance(it, index); | 143 std::advance(it, index); |
| 153 RestoreOrShow(*it); | 144 RestoreOrShow(*it); |
| 154 } | |
| 155 } | |
| 156 | |
| 157 string16 ShellWindowLauncherItemController::GetTitleOfIndexedApp( | |
| 158 size_t index) { | |
| 159 if (index < shell_windows_.size()) { | |
| 160 ShellWindowList::iterator it = shell_windows_.begin(); | |
| 161 std::advance(it, index); | |
| 162 return (*it)->GetTitle(); | |
| 163 } | |
| 164 return string16(); | |
| 165 } | |
| 166 | |
| 167 gfx::Image* | |
| 168 ShellWindowLauncherItemController::GetIconOfIndexedApp(size_t index) { | |
| 169 if (index < shell_windows_.size()) { | |
| 170 ShellWindowList::iterator it = shell_windows_.begin(); | |
| 171 std::advance(it, index); | |
| 172 return (*it)->GetAppListIcon(); | |
| 173 } | |
| 174 return new gfx::Image(); | |
| 175 } | 145 } |
| 176 | 146 |
| 177 ChromeLauncherAppMenuItems | 147 ChromeLauncherAppMenuItems |
| 178 ShellWindowLauncherItemController::GetApplicationList() { | 148 ShellWindowLauncherItemController::GetApplicationList() { |
| 179 ChromeLauncherAppMenuItems items; | 149 ChromeLauncherAppMenuItems items; |
| 180 if (!launcher_controller()->GetPerAppInterface()) { | 150 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); |
| 181 items.push_back(new ChromeLauncherAppMenuItem(GetTitle(), NULL, false)); | 151 int index = 0; |
| 182 for (size_t i = 0; i < shell_window_count(); i++) { | 152 for (ShellWindowList::iterator iter = shell_windows_.begin(); |
| 183 gfx::Image* image = GetIconOfIndexedApp(i); | 153 iter != shell_windows_.end(); ++iter) { |
| 184 items.push_back(new ChromeLauncherAppMenuItemV2App( | 154 ShellWindow* shell_window = *iter; |
| 185 GetTitleOfIndexedApp(i), | 155 scoped_ptr<gfx::Image> image(shell_window->GetAppListIcon()); |
| 186 image, | 156 items.push_back(new ChromeLauncherAppMenuItemV2App( |
| 187 app_id(), | 157 shell_window->GetTitle(), |
| 188 launcher_controller()->GetPerAppInterface(), | 158 image.get(), // Will be copied |
| 189 i, | 159 app_id(), |
| 190 i == 0)); | 160 launcher_controller()->GetPerAppInterface(), |
| 191 delete image; | 161 index, |
| 192 } | 162 index == 0 /* has_leading_separator */)); |
|
Mr4D (OOO till 08-26)
2013/03/22 00:45:31
You can ignore this - but shouldn't the comments b
stevenjb
2013/03/22 19:18:33
Different types of comments. /* */ is a format tha
| |
| 163 ++index; | |
| 193 } | 164 } |
| 194 return items.Pass(); | 165 return items.Pass(); |
| 195 } | 166 } |
| 196 | 167 |
| 197 void ShellWindowLauncherItemController::OnWindowPropertyChanged( | 168 void ShellWindowLauncherItemController::OnWindowPropertyChanged( |
| 198 aura::Window* window, | 169 aura::Window* window, |
| 199 const void* key, | 170 const void* key, |
| 200 intptr_t old) { | 171 intptr_t old) { |
| 201 if (key == aura::client::kDrawAttentionKey) { | 172 if (key == aura::client::kDrawAttentionKey) { |
| 202 ash::LauncherItemStatus status; | 173 ash::LauncherItemStatus status; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 213 | 184 |
| 214 void ShellWindowLauncherItemController::RestoreOrShow( | 185 void ShellWindowLauncherItemController::RestoreOrShow( |
| 215 ShellWindow* shell_window) { | 186 ShellWindow* shell_window) { |
| 216 if (shell_window->GetBaseWindow()->IsMinimized()) | 187 if (shell_window->GetBaseWindow()->IsMinimized()) |
| 217 shell_window->GetBaseWindow()->Restore(); | 188 shell_window->GetBaseWindow()->Restore(); |
| 218 else | 189 else |
| 219 shell_window->GetBaseWindow()->Show(); | 190 shell_window->GetBaseWindow()->Show(); |
| 220 // Always activate windows when shown from the launcher. | 191 // Always activate windows when shown from the launcher. |
| 221 shell_window->GetBaseWindow()->Activate(); | 192 shell_window->GetBaseWindow()->Activate(); |
| 222 } | 193 } |
| OLD | NEW |