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 if (GetLastActiveWindow() == app_window) |
| 31 OnActiveWindowChanged(app_window); |
30 } | 32 } |
31 | 33 |
32 AppWindowLauncherItemController::WindowList::iterator | 34 AppWindowLauncherItemController::WindowList::iterator |
33 AppWindowLauncherItemController::GetFromNativeWindow(aura::Window* window) { | 35 AppWindowLauncherItemController::GetFromNativeWindow(aura::Window* window) { |
34 return std::find_if(windows_.begin(), windows_.end(), | 36 return std::find_if(windows_.begin(), windows_.end(), |
35 [window](ui::BaseWindow* base_window) { | 37 [window](ui::BaseWindow* base_window) { |
36 return base_window->GetNativeWindow() == window; | 38 return base_window->GetNativeWindow() == window; |
37 }); | 39 }); |
38 } | 40 } |
39 | 41 |
40 void AppWindowLauncherItemController::RemoveWindow(ui::BaseWindow* app_window) { | 42 void AppWindowLauncherItemController::RemoveWindow(ui::BaseWindow* app_window) { |
41 DCHECK(app_window); | 43 DCHECK(app_window); |
42 aura::Window* window = app_window->GetNativeWindow(); | 44 aura::Window* window = app_window->GetNativeWindow(); |
43 if (window) | 45 if (window) |
44 observed_windows_.Remove(window); | 46 observed_windows_.Remove(window); |
45 if (app_window == last_active_window_) | 47 if (app_window == last_active_window_) |
46 last_active_window_ = nullptr; | 48 last_active_window_ = nullptr; |
47 auto iter = std::find(windows_.begin(), windows_.end(), app_window); | 49 auto iter = std::find(windows_.begin(), windows_.end(), app_window); |
48 if (iter == windows_.end()) { | 50 if (iter == windows_.end()) { |
49 NOTREACHED(); | 51 NOTREACHED(); |
50 return; | 52 return; |
51 } | 53 } |
52 OnWindowRemoved(app_window); | |
53 windows_.erase(iter); | 54 windows_.erase(iter); |
| 55 OnActiveWindowChanged(GetLastActiveWindow()); |
54 } | 56 } |
55 | 57 |
56 ui::BaseWindow* AppWindowLauncherItemController::GetAppWindow( | 58 ui::BaseWindow* AppWindowLauncherItemController::GetAppWindow( |
57 aura::Window* window) { | 59 aura::Window* window) { |
58 const auto iter = GetFromNativeWindow(window); | 60 const auto iter = GetFromNativeWindow(window); |
59 if (iter != windows_.end()) | 61 if (iter != windows_.end()) |
60 return *iter; | 62 return *iter; |
61 return nullptr; | 63 return nullptr; |
62 } | 64 } |
63 | 65 |
64 void AppWindowLauncherItemController::SetActiveWindow(aura::Window* window) { | 66 void AppWindowLauncherItemController::SetActiveWindow(aura::Window* window) { |
65 ui::BaseWindow* app_window = GetAppWindow(window); | 67 ui::BaseWindow* app_window = GetAppWindow(window); |
66 if (app_window) | 68 if (app_window) |
67 last_active_window_ = app_window; | 69 last_active_window_ = app_window; |
| 70 OnActiveWindowChanged(GetLastActiveWindow()); |
68 } | 71 } |
69 | 72 |
70 AppWindowLauncherItemController* | 73 AppWindowLauncherItemController* |
71 AppWindowLauncherItemController::AsAppWindowLauncherItemController() { | 74 AppWindowLauncherItemController::AsAppWindowLauncherItemController() { |
72 return this; | 75 return this; |
73 } | 76 } |
74 | 77 |
75 void AppWindowLauncherItemController::ItemSelected( | 78 void AppWindowLauncherItemController::ItemSelected( |
76 std::unique_ptr<ui::Event> event, | 79 std::unique_ptr<ui::Event> event, |
77 int64_t display_id, | 80 int64_t display_id, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 } | 115 } |
113 | 116 |
114 void AppWindowLauncherItemController::ActivateIndexedApp(size_t index) { | 117 void AppWindowLauncherItemController::ActivateIndexedApp(size_t index) { |
115 if (index >= windows_.size()) | 118 if (index >= windows_.size()) |
116 return; | 119 return; |
117 auto it = windows_.begin(); | 120 auto it = windows_.begin(); |
118 std::advance(it, index); | 121 std::advance(it, index); |
119 ShowAndActivateOrMinimize(*it); | 122 ShowAndActivateOrMinimize(*it); |
120 } | 123 } |
121 | 124 |
| 125 ui::BaseWindow* AppWindowLauncherItemController::GetLastActiveWindow() { |
| 126 if (last_active_window_) |
| 127 return last_active_window_; |
| 128 return windows_.empty() ? nullptr : windows_.front(); |
| 129 } |
| 130 |
122 void AppWindowLauncherItemController::OnWindowPropertyChanged( | 131 void AppWindowLauncherItemController::OnWindowPropertyChanged( |
123 aura::Window* window, | 132 aura::Window* window, |
124 const void* key, | 133 const void* key, |
125 intptr_t old) { | 134 intptr_t old) { |
126 if (key == aura::client::kDrawAttentionKey) { | 135 if (key == aura::client::kDrawAttentionKey) { |
127 ash::ShelfItemStatus status; | 136 ash::ShelfItemStatus status; |
128 if (ash::wm::IsActiveWindow(window)) { | 137 if (ash::wm::IsActiveWindow(window)) { |
129 status = ash::STATUS_ACTIVE; | 138 status = ash::STATUS_ACTIVE; |
130 } else if (window->GetProperty(aura::client::kDrawAttentionKey)) { | 139 } else if (window->GetProperty(aura::client::kDrawAttentionKey)) { |
131 status = ash::STATUS_ATTENTION; | 140 status = ash::STATUS_ATTENTION; |
(...skipping 25 matching lines...) Expand all Loading... |
157 if (window_to_show->IsActive()) { | 166 if (window_to_show->IsActive()) { |
158 // Coming here, only a single window is active. For keyboard activations | 167 // Coming here, only a single window is active. For keyboard activations |
159 // the window gets animated. | 168 // the window gets animated. |
160 AnimateWindow(window_to_show->GetNativeWindow(), | 169 AnimateWindow(window_to_show->GetNativeWindow(), |
161 wm::WINDOW_ANIMATION_TYPE_BOUNCE); | 170 wm::WINDOW_ANIMATION_TYPE_BOUNCE); |
162 } else { | 171 } else { |
163 return ShowAndActivateOrMinimize(window_to_show); | 172 return ShowAndActivateOrMinimize(window_to_show); |
164 } | 173 } |
165 return ash::SHELF_ACTION_NONE; | 174 return ash::SHELF_ACTION_NONE; |
166 } | 175 } |
OLD | NEW |