| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/app_window_launcher_item_controller.h" | 5 #include "chrome/browser/ui/ash/launcher/app_window_launcher_item_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/wm/window_util.h" | 9 #include "ash/wm/window_util.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 11 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 12 #include "chrome/browser/ui/ash/launcher/launcher_application_menu_item_model.h" | |
| 13 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" | 12 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" |
| 14 #include "ui/aura/client/aura_constants.h" | 13 #include "ui/aura/client/aura_constants.h" |
| 15 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 16 #include "ui/base/base_window.h" | 15 #include "ui/base/base_window.h" |
| 17 #include "ui/wm/core/window_animations.h" | 16 #include "ui/wm/core/window_animations.h" |
| 18 | 17 |
| 19 AppWindowLauncherItemController::AppWindowLauncherItemController( | 18 AppWindowLauncherItemController::AppWindowLauncherItemController( |
| 20 const std::string& app_id, | 19 const std::string& app_id, |
| 21 const std::string& launch_id, | 20 const std::string& launch_id, |
| 22 ChromeLauncherController* controller) | 21 ChromeLauncherController* controller) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 76 |
| 78 ash::ShelfItemDelegate::PerformedAction | 77 ash::ShelfItemDelegate::PerformedAction |
| 79 AppWindowLauncherItemController::Activate(ash::LaunchSource source) { | 78 AppWindowLauncherItemController::Activate(ash::LaunchSource source) { |
| 80 DCHECK(!windows_.empty()); | 79 DCHECK(!windows_.empty()); |
| 81 ui::BaseWindow* window_to_activate = | 80 ui::BaseWindow* window_to_activate = |
| 82 last_active_window_ ? last_active_window_ : windows_.back(); | 81 last_active_window_ ? last_active_window_ : windows_.back(); |
| 83 window_to_activate->Activate(); | 82 window_to_activate->Activate(); |
| 84 return kExistingWindowActivated; | 83 return kExistingWindowActivated; |
| 85 } | 84 } |
| 86 | 85 |
| 87 ui::SimpleMenuModel* AppWindowLauncherItemController::CreateApplicationMenu( | |
| 88 int event_flags) { | |
| 89 return new LauncherApplicationMenuItemModel(GetApplicationList(event_flags)); | |
| 90 } | |
| 91 | |
| 92 void AppWindowLauncherItemController::Close() { | |
| 93 // Note: Closing windows may affect the contents of app_windows_. | |
| 94 WindowList windows_to_close = windows_; | |
| 95 for (auto* window : windows_) | |
| 96 window->Close(); | |
| 97 } | |
| 98 | |
| 99 void AppWindowLauncherItemController::ActivateIndexedApp(size_t index) { | |
| 100 if (index >= windows_.size()) | |
| 101 return; | |
| 102 auto it = windows_.begin(); | |
| 103 std::advance(it, index); | |
| 104 ShowAndActivateOrMinimize(*it); | |
| 105 } | |
| 106 | |
| 107 ChromeLauncherAppMenuItems AppWindowLauncherItemController::GetApplicationList( | |
| 108 int event_flags) { | |
| 109 ChromeLauncherAppMenuItems items; | |
| 110 // Add the application name to the menu. | |
| 111 base::string16 app_title = LauncherControllerHelper::GetAppTitle( | |
| 112 launcher_controller()->profile(), app_id()); | |
| 113 items.push_back( | |
| 114 base::MakeUnique<ChromeLauncherAppMenuItem>(app_title, nullptr, false)); | |
| 115 return items; | |
| 116 } | |
| 117 | |
| 118 AppWindowLauncherItemController* | 86 AppWindowLauncherItemController* |
| 119 AppWindowLauncherItemController::AsAppWindowLauncherItemController() { | 87 AppWindowLauncherItemController::AsAppWindowLauncherItemController() { |
| 120 return this; | 88 return this; |
| 121 } | 89 } |
| 122 | 90 |
| 123 ash::ShelfItemDelegate::PerformedAction | 91 ash::ShelfItemDelegate::PerformedAction |
| 124 AppWindowLauncherItemController::ItemSelected(const ui::Event& event) { | 92 AppWindowLauncherItemController::ItemSelected(const ui::Event& event) { |
| 125 if (windows_.empty()) | 93 if (windows_.empty()) |
| 126 return kNoAction; | 94 return kNoAction; |
| 127 | 95 |
| 128 ui::BaseWindow* window_to_show = | 96 ui::BaseWindow* window_to_show = |
| 129 last_active_window_ ? last_active_window_ : windows_.front(); | 97 last_active_window_ ? last_active_window_ : windows_.front(); |
| 130 // If the event was triggered by a keystroke, we try to advance to the next | 98 // If the event was triggered by a keystroke, we try to advance to the next |
| 131 // item if the window we are trying to activate is already active. | 99 // item if the window we are trying to activate is already active. |
| 132 if (windows_.size() >= 1 && window_to_show->IsActive() && | 100 if (windows_.size() >= 1 && window_to_show->IsActive() && |
| 133 event.type() == ui::ET_KEY_RELEASED) { | 101 event.type() == ui::ET_KEY_RELEASED) { |
| 134 return ActivateOrAdvanceToNextAppWindow(window_to_show); | 102 return ActivateOrAdvanceToNextAppWindow(window_to_show); |
| 135 } else { | |
| 136 return ShowAndActivateOrMinimize(window_to_show); | |
| 137 } | 103 } |
| 104 |
| 105 return ShowAndActivateOrMinimize(window_to_show); |
| 106 } |
| 107 |
| 108 ash::ShelfAppMenuItemList AppWindowLauncherItemController::GetAppMenuItems( |
| 109 int event_flags) { |
| 110 return ash::ShelfAppMenuItemList(); |
| 111 } |
| 112 |
| 113 void AppWindowLauncherItemController::Close() { |
| 114 // Note: Closing windows may affect the contents of app_windows_. |
| 115 WindowList windows_to_close = windows_; |
| 116 for (auto* window : windows_) |
| 117 window->Close(); |
| 118 } |
| 119 |
| 120 void AppWindowLauncherItemController::ActivateIndexedApp(size_t index) { |
| 121 if (index >= windows_.size()) |
| 122 return; |
| 123 auto it = windows_.begin(); |
| 124 std::advance(it, index); |
| 125 ShowAndActivateOrMinimize(*it); |
| 138 } | 126 } |
| 139 | 127 |
| 140 void AppWindowLauncherItemController::OnWindowPropertyChanged( | 128 void AppWindowLauncherItemController::OnWindowPropertyChanged( |
| 141 aura::Window* window, | 129 aura::Window* window, |
| 142 const void* key, | 130 const void* key, |
| 143 intptr_t old) { | 131 intptr_t old) { |
| 144 if (key == aura::client::kDrawAttentionKey) { | 132 if (key == aura::client::kDrawAttentionKey) { |
| 145 ash::ShelfItemStatus status; | 133 ash::ShelfItemStatus status; |
| 146 if (ash::wm::IsActiveWindow(window)) { | 134 if (ash::wm::IsActiveWindow(window)) { |
| 147 status = ash::STATUS_ACTIVE; | 135 status = ash::STATUS_ACTIVE; |
| 148 } else if (window->GetProperty(aura::client::kDrawAttentionKey)) { | 136 } else if (window->GetProperty(aura::client::kDrawAttentionKey)) { |
| 149 status = ash::STATUS_ATTENTION; | 137 status = ash::STATUS_ATTENTION; |
| 150 } else { | 138 } else { |
| 151 status = ash::STATUS_RUNNING; | 139 status = ash::STATUS_RUNNING; |
| 152 } | 140 } |
| 153 launcher_controller()->SetItemStatus(shelf_id(), status); | 141 launcher_controller()->SetItemStatus(shelf_id(), status); |
| 154 } | 142 } |
| 155 } | 143 } |
| 156 | 144 |
| 157 ash::ShelfItemDelegate::PerformedAction | 145 ash::ShelfItemDelegate::PerformedAction |
| 158 AppWindowLauncherItemController::ShowAndActivateOrMinimize( | 146 AppWindowLauncherItemController::ShowAndActivateOrMinimize( |
| 159 ui::BaseWindow* app_window) { | 147 ui::BaseWindow* app_window) { |
| 160 // Either show or minimize windows when shown from the launcher. | 148 // Either show or minimize windows when shown from the launcher. |
| 161 return launcher_controller()->ActivateWindowOrMinimizeIfActive( | 149 return launcher_controller()->ActivateWindowOrMinimizeIfActive( |
| 162 app_window, GetApplicationList(0).size() == 2); | 150 app_window, GetAppMenuItems(0).size() == 1); |
| 163 } | 151 } |
| 164 | 152 |
| 165 ash::ShelfItemDelegate::PerformedAction | 153 ash::ShelfItemDelegate::PerformedAction |
| 166 AppWindowLauncherItemController::ActivateOrAdvanceToNextAppWindow( | 154 AppWindowLauncherItemController::ActivateOrAdvanceToNextAppWindow( |
| 167 ui::BaseWindow* window_to_show) { | 155 ui::BaseWindow* window_to_show) { |
| 168 WindowList::iterator i( | 156 WindowList::iterator i( |
| 169 std::find(windows_.begin(), windows_.end(), window_to_show)); | 157 std::find(windows_.begin(), windows_.end(), window_to_show)); |
| 170 if (i != windows_.end()) { | 158 if (i != windows_.end()) { |
| 171 if (++i != windows_.end()) | 159 if (++i != windows_.end()) |
| 172 window_to_show = *i; | 160 window_to_show = *i; |
| 173 else | 161 else |
| 174 window_to_show = windows_.front(); | 162 window_to_show = windows_.front(); |
| 175 } | 163 } |
| 176 if (window_to_show->IsActive()) { | 164 if (window_to_show->IsActive()) { |
| 177 // Coming here, only a single window is active. For keyboard activations | 165 // Coming here, only a single window is active. For keyboard activations |
| 178 // the window gets animated. | 166 // the window gets animated. |
| 179 AnimateWindow(window_to_show->GetNativeWindow(), | 167 AnimateWindow(window_to_show->GetNativeWindow(), |
| 180 wm::WINDOW_ANIMATION_TYPE_BOUNCE); | 168 wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
| 181 } else { | 169 } else { |
| 182 return ShowAndActivateOrMinimize(window_to_show); | 170 return ShowAndActivateOrMinimize(window_to_show); |
| 183 } | 171 } |
| 184 return kNoAction; | 172 return kNoAction; |
| 185 } | 173 } |
| OLD | NEW |