Chromium Code Reviews| 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 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "ash/wm/window_util.h" | 10 #include "ash/wm/window_util.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" | 12 #include "chrome/browser/ui/ash/launcher/chrome_launcher_controller.h" |
| 13 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" | 13 #include "chrome/browser/ui/ash/launcher/launcher_controller_helper.h" |
| 14 #include "ui/aura/client/aura_constants.h" | 14 #include "ui/aura/client/aura_constants.h" |
| 15 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 16 #include "ui/base/base_window.h" | 16 #include "ui/base/base_window.h" |
| 17 #include "ui/wm/core/window_animations.h" | 17 #include "ui/wm/core/window_animations.h" |
| 18 | 18 |
| 19 AppWindowLauncherItemController::AppWindowLauncherItemController( | 19 AppWindowLauncherItemController::AppWindowLauncherItemController( |
| 20 const ash::ShelfID& shelf_id) | 20 const ash::ShelfID& shelf_id) |
| 21 : ash::ShelfItemDelegate(shelf_id), observed_windows_(this) {} | 21 : ash::ShelfItemDelegate(shelf_id), observed_windows_(this) {} |
| 22 | 22 |
| 23 AppWindowLauncherItemController::~AppWindowLauncherItemController() {} | 23 AppWindowLauncherItemController::~AppWindowLauncherItemController() {} |
| 24 | 24 |
| 25 void AppWindowLauncherItemController::AddWindow(ui::BaseWindow* app_window) { | 25 void AppWindowLauncherItemController::AddWindow(ui::BaseWindow* app_window) { |
| 26 windows_.push_front(app_window); | 26 windows_.push_front(app_window); |
| 27 aura::Window* window = app_window->GetNativeWindow(); | 27 aura::Window* window = app_window->GetNativeWindow(); |
| 28 if (window) | 28 if (window) |
| 29 observed_windows_.Add(window); | 29 observed_windows_.Add(window); |
| 30 UpdateLauncherItem(); | |
| 30 } | 31 } |
| 31 | 32 |
| 32 AppWindowLauncherItemController::WindowList::iterator | 33 AppWindowLauncherItemController::WindowList::iterator |
| 33 AppWindowLauncherItemController::GetFromNativeWindow(aura::Window* window) { | 34 AppWindowLauncherItemController::GetFromNativeWindow(aura::Window* window) { |
| 34 return std::find_if(windows_.begin(), windows_.end(), | 35 return std::find_if(windows_.begin(), windows_.end(), |
| 35 [window](ui::BaseWindow* base_window) { | 36 [window](ui::BaseWindow* base_window) { |
| 36 return base_window->GetNativeWindow() == window; | 37 return base_window->GetNativeWindow() == window; |
| 37 }); | 38 }); |
| 38 } | 39 } |
| 39 | 40 |
| 40 void AppWindowLauncherItemController::RemoveWindow(ui::BaseWindow* app_window) { | 41 void AppWindowLauncherItemController::RemoveWindow(ui::BaseWindow* app_window) { |
| 41 DCHECK(app_window); | 42 DCHECK(app_window); |
| 42 aura::Window* window = app_window->GetNativeWindow(); | 43 aura::Window* window = app_window->GetNativeWindow(); |
| 43 if (window) | 44 if (window) |
| 44 observed_windows_.Remove(window); | 45 observed_windows_.Remove(window); |
| 45 if (app_window == last_active_window_) | 46 if (app_window == last_active_window_) |
| 46 last_active_window_ = nullptr; | 47 last_active_window_ = nullptr; |
| 47 auto iter = std::find(windows_.begin(), windows_.end(), app_window); | 48 auto iter = std::find(windows_.begin(), windows_.end(), app_window); |
| 48 if (iter == windows_.end()) { | 49 if (iter == windows_.end()) { |
| 49 NOTREACHED(); | 50 NOTREACHED(); |
| 50 return; | 51 return; |
| 51 } | 52 } |
| 52 OnWindowRemoved(app_window); | |
| 53 windows_.erase(iter); | 53 windows_.erase(iter); |
| 54 UpdateLauncherItem(); | |
| 54 } | 55 } |
| 55 | 56 |
| 56 ui::BaseWindow* AppWindowLauncherItemController::GetAppWindow( | 57 ui::BaseWindow* AppWindowLauncherItemController::GetAppWindow( |
| 57 aura::Window* window) { | 58 aura::Window* window) { |
| 58 const auto iter = GetFromNativeWindow(window); | 59 const auto iter = GetFromNativeWindow(window); |
| 59 if (iter != windows_.end()) | 60 if (iter != windows_.end()) |
| 60 return *iter; | 61 return *iter; |
| 61 return nullptr; | 62 return nullptr; |
| 62 } | 63 } |
| 63 | 64 |
| 64 void AppWindowLauncherItemController::SetActiveWindow(aura::Window* window) { | 65 void AppWindowLauncherItemController::SetActiveWindow(aura::Window* window) { |
| 65 ui::BaseWindow* app_window = GetAppWindow(window); | 66 ui::BaseWindow* app_window = GetAppWindow(window); |
| 66 if (app_window) | 67 if (app_window) |
| 67 last_active_window_ = app_window; | 68 last_active_window_ = app_window; |
| 69 UpdateLauncherItem(); | |
| 68 } | 70 } |
| 69 | 71 |
| 70 AppWindowLauncherItemController* | 72 AppWindowLauncherItemController* |
| 71 AppWindowLauncherItemController::AsAppWindowLauncherItemController() { | 73 AppWindowLauncherItemController::AsAppWindowLauncherItemController() { |
| 72 return this; | 74 return this; |
| 73 } | 75 } |
| 74 | 76 |
| 75 void AppWindowLauncherItemController::ItemSelected( | 77 void AppWindowLauncherItemController::ItemSelected( |
| 76 std::unique_ptr<ui::Event> event, | 78 std::unique_ptr<ui::Event> event, |
| 77 int64_t display_id, | 79 int64_t display_id, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 } | 114 } |
| 113 | 115 |
| 114 void AppWindowLauncherItemController::ActivateIndexedApp(size_t index) { | 116 void AppWindowLauncherItemController::ActivateIndexedApp(size_t index) { |
| 115 if (index >= windows_.size()) | 117 if (index >= windows_.size()) |
| 116 return; | 118 return; |
| 117 auto it = windows_.begin(); | 119 auto it = windows_.begin(); |
| 118 std::advance(it, index); | 120 std::advance(it, index); |
| 119 ShowAndActivateOrMinimize(*it); | 121 ShowAndActivateOrMinimize(*it); |
| 120 } | 122 } |
| 121 | 123 |
| 124 ui::BaseWindow* AppWindowLauncherItemController::GetLastActiveWindow() { | |
| 125 if (last_active_window_) | |
| 126 return last_active_window_; | |
| 127 return windows_.empty() ? nullptr : windows_.front(); | |
|
Luis Héctor Chávez
2017/05/18 18:09:40
nit:
if (windows_.empty())
return nullptr
retur
khmel
2017/05/18 20:27:52
Done.
msw
2017/05/18 22:03:39
fwiw, I prefer ternary statements, but style prefe
khmel
2017/05/18 22:40:02
Acknowledged.
| |
| 128 } | |
| 129 | |
| 122 void AppWindowLauncherItemController::OnWindowPropertyChanged( | 130 void AppWindowLauncherItemController::OnWindowPropertyChanged( |
| 123 aura::Window* window, | 131 aura::Window* window, |
| 124 const void* key, | 132 const void* key, |
| 125 intptr_t old) { | 133 intptr_t old) { |
| 126 if (key == aura::client::kDrawAttentionKey) { | 134 if (key == aura::client::kDrawAttentionKey) { |
| 127 ash::ShelfItemStatus status; | 135 ash::ShelfItemStatus status; |
| 128 if (ash::wm::IsActiveWindow(window)) { | 136 if (ash::wm::IsActiveWindow(window)) { |
| 129 status = ash::STATUS_ACTIVE; | 137 status = ash::STATUS_ACTIVE; |
| 130 } else if (window->GetProperty(aura::client::kDrawAttentionKey)) { | 138 } else if (window->GetProperty(aura::client::kDrawAttentionKey)) { |
| 131 status = ash::STATUS_ATTENTION; | 139 status = ash::STATUS_ATTENTION; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 157 if (window_to_show->IsActive()) { | 165 if (window_to_show->IsActive()) { |
| 158 // Coming here, only a single window is active. For keyboard activations | 166 // Coming here, only a single window is active. For keyboard activations |
| 159 // the window gets animated. | 167 // the window gets animated. |
| 160 AnimateWindow(window_to_show->GetNativeWindow(), | 168 AnimateWindow(window_to_show->GetNativeWindow(), |
| 161 wm::WINDOW_ANIMATION_TYPE_BOUNCE); | 169 wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
| 162 } else { | 170 } else { |
| 163 return ShowAndActivateOrMinimize(window_to_show); | 171 return ShowAndActivateOrMinimize(window_to_show); |
| 164 } | 172 } |
| 165 return ash::SHELF_ACTION_NONE; | 173 return ash::SHELF_ACTION_NONE; |
| 166 } | 174 } |
| OLD | NEW |