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 "athena/wm/public/window_manager.h" | 5 #include "athena/wm/public/window_manager.h" |
6 | 6 |
7 #include "athena/common/container_priorities.h" | 7 #include "athena/common/container_priorities.h" |
8 #include "athena/input/public/accelerator_manager.h" | 8 #include "athena/input/public/accelerator_manager.h" |
9 #include "athena/screen/public/screen_manager.h" | 9 #include "athena/screen/public/screen_manager.h" |
10 #include "athena/wm/bezel_controller.h" | 10 #include "athena/wm/bezel_controller.h" |
| 11 #include "athena/wm/mru_window_tracker.h" |
11 #include "athena/wm/public/window_manager_observer.h" | 12 #include "athena/wm/public/window_manager_observer.h" |
12 #include "athena/wm/split_view_controller.h" | 13 #include "athena/wm/split_view_controller.h" |
| 14 #include "athena/wm/window_list_provider.h" |
13 #include "athena/wm/window_overview_mode.h" | 15 #include "athena/wm/window_overview_mode.h" |
14 #include "base/logging.h" | 16 #include "base/logging.h" |
15 #include "base/observer_list.h" | 17 #include "base/observer_list.h" |
16 #include "ui/aura/layout_manager.h" | 18 #include "ui/aura/layout_manager.h" |
17 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
18 #include "ui/wm/core/window_util.h" | 20 #include "ui/wm/core/window_util.h" |
19 #include "ui/wm/public/window_types.h" | 21 #include "ui/wm/public/window_types.h" |
20 | 22 |
21 namespace athena { | 23 namespace athena { |
22 namespace { | 24 namespace { |
23 | 25 |
24 class WindowManagerImpl : public WindowManager, | 26 class WindowManagerImpl : public WindowManager, |
25 public WindowOverviewModeDelegate, | 27 public WindowOverviewModeDelegate, |
26 public aura::WindowObserver, | 28 public aura::WindowObserver, |
27 public AcceleratorHandler { | 29 public AcceleratorHandler { |
28 public: | 30 public: |
29 WindowManagerImpl(); | 31 WindowManagerImpl(); |
30 virtual ~WindowManagerImpl(); | 32 virtual ~WindowManagerImpl(); |
31 | 33 |
32 void Layout(); | 34 void Layout(); |
33 | 35 |
34 // WindowManager: | 36 // WindowManager: |
35 virtual void ToggleOverview() OVERRIDE; | 37 virtual void ToggleOverview() OVERRIDE; |
36 | 38 |
| 39 virtual bool IsOverviewModeActive() OVERRIDE { |
| 40 return overview_; |
| 41 } |
| 42 |
37 private: | 43 private: |
38 enum Command { | 44 enum Command { |
39 COMMAND_TOGGLE_OVERVIEW, | 45 COMMAND_TOGGLE_OVERVIEW, |
40 }; | 46 }; |
41 | 47 |
42 // Sets whether overview mode is active. | 48 // Sets whether overview mode is active. |
43 void SetInOverview(bool active); | 49 void SetInOverview(bool active); |
44 | 50 |
45 void InstallAccelerators(); | 51 void InstallAccelerators(); |
46 | 52 |
47 // WindowManager: | 53 // WindowManager: |
48 virtual void AddObserver(WindowManagerObserver* observer) OVERRIDE; | 54 virtual void AddObserver(WindowManagerObserver* observer) OVERRIDE; |
49 virtual void RemoveObserver(WindowManagerObserver* observer) OVERRIDE; | 55 virtual void RemoveObserver(WindowManagerObserver* observer) OVERRIDE; |
50 | 56 |
51 // WindowOverviewModeDelegate: | 57 // WindowOverviewModeDelegate: |
52 virtual void OnSelectWindow(aura::Window* window) OVERRIDE; | 58 virtual void OnSelectWindow(aura::Window* window) OVERRIDE; |
53 | 59 |
54 // aura::WindowObserver | 60 // aura::WindowObserver |
55 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; | 61 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE; |
56 | 62 |
57 // AcceleratorHandler: | 63 // AcceleratorHandler: |
58 virtual bool IsCommandEnabled(int command_id) const OVERRIDE; | 64 virtual bool IsCommandEnabled(int command_id) const OVERRIDE; |
59 virtual bool OnAcceleratorFired(int command_id, | 65 virtual bool OnAcceleratorFired(int command_id, |
60 const ui::Accelerator& accelerator) OVERRIDE; | 66 const ui::Accelerator& accelerator) OVERRIDE; |
61 | 67 |
62 scoped_ptr<aura::Window> container_; | 68 scoped_ptr<aura::Window> container_; |
| 69 scoped_ptr<MruWindowTracker> mru_window_tracker_; |
63 scoped_ptr<WindowOverviewMode> overview_; | 70 scoped_ptr<WindowOverviewMode> overview_; |
64 scoped_ptr<BezelController> bezel_controller_; | 71 scoped_ptr<BezelController> bezel_controller_; |
65 scoped_ptr<SplitViewController> split_view_controller_; | 72 scoped_ptr<SplitViewController> split_view_controller_; |
66 ObserverList<WindowManagerObserver> observers_; | 73 ObserverList<WindowManagerObserver> observers_; |
67 | 74 |
68 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); | 75 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); |
69 }; | 76 }; |
70 | 77 |
71 class AthenaContainerLayoutManager : public aura::LayoutManager { | 78 class AthenaContainerLayoutManager : public aura::LayoutManager { |
72 public: | 79 public: |
(...skipping 15 matching lines...) Expand all Loading... |
88 }; | 95 }; |
89 | 96 |
90 class WindowManagerImpl* instance = NULL; | 97 class WindowManagerImpl* instance = NULL; |
91 | 98 |
92 WindowManagerImpl::WindowManagerImpl() { | 99 WindowManagerImpl::WindowManagerImpl() { |
93 ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); | 100 ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); |
94 params.can_activate_children = true; | 101 params.can_activate_children = true; |
95 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); | 102 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); |
96 container_->SetLayoutManager(new AthenaContainerLayoutManager); | 103 container_->SetLayoutManager(new AthenaContainerLayoutManager); |
97 container_->AddObserver(this); | 104 container_->AddObserver(this); |
| 105 mru_window_tracker_.reset(new MruWindowTracker(container_.get())); |
98 bezel_controller_.reset(new BezelController(container_.get())); | 106 bezel_controller_.reset(new BezelController(container_.get())); |
99 split_view_controller_.reset(new SplitViewController()); | 107 split_view_controller_.reset(new SplitViewController( |
| 108 container_.get(), mru_window_tracker_.get(), this)); |
100 bezel_controller_->set_left_right_delegate(split_view_controller_.get()); | 109 bezel_controller_->set_left_right_delegate(split_view_controller_.get()); |
101 container_->AddPreTargetHandler(bezel_controller_.get()); | 110 container_->AddPreTargetHandler(bezel_controller_.get()); |
102 instance = this; | 111 instance = this; |
103 InstallAccelerators(); | 112 InstallAccelerators(); |
104 } | 113 } |
105 | 114 |
106 WindowManagerImpl::~WindowManagerImpl() { | 115 WindowManagerImpl::~WindowManagerImpl() { |
107 overview_.reset(); | 116 overview_.reset(); |
108 if (container_) { | 117 if (container_) { |
109 container_->RemoveObserver(this); | 118 container_->RemoveObserver(this); |
(...skipping 21 matching lines...) Expand all Loading... |
131 void WindowManagerImpl::ToggleOverview() { | 140 void WindowManagerImpl::ToggleOverview() { |
132 SetInOverview(overview_.get() == NULL); | 141 SetInOverview(overview_.get() == NULL); |
133 } | 142 } |
134 | 143 |
135 void WindowManagerImpl::SetInOverview(bool active) { | 144 void WindowManagerImpl::SetInOverview(bool active) { |
136 bool in_overview = !!overview_; | 145 bool in_overview = !!overview_; |
137 if (active == in_overview) | 146 if (active == in_overview) |
138 return; | 147 return; |
139 | 148 |
140 if (active) { | 149 if (active) { |
141 overview_ = WindowOverviewMode::Create(container_.get(), this); | |
142 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 150 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
143 OnOverviewModeEnter()); | 151 OnOverviewModeEnter()); |
| 152 // Re-stack all windows in the order defined by mru_window_tracker_. |
| 153 aura::Window::Windows window_list = mru_window_tracker_->GetWindowList(); |
| 154 aura::Window::Windows::iterator it; |
| 155 for (it = window_list.begin(); it != window_list.end(); ++it) { |
| 156 container_->StackChildAtTop(*it); |
| 157 } |
| 158 overview_ = |
| 159 WindowOverviewMode::Create(container_.get(), |
| 160 mru_window_tracker_->GetWindowList(), |
| 161 this); |
144 } else { | 162 } else { |
145 overview_.reset(); | 163 overview_.reset(); |
146 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 164 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
147 OnOverviewModeExit()); | 165 OnOverviewModeExit()); |
148 } | 166 } |
149 } | 167 } |
150 | 168 |
151 void WindowManagerImpl::InstallAccelerators() { | 169 void WindowManagerImpl::InstallAccelerators() { |
152 const AcceleratorData accelerator_data[] = { | 170 const AcceleratorData accelerator_data[] = { |
153 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, COMMAND_TOGGLE_OVERVIEW, | 171 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, COMMAND_TOGGLE_OVERVIEW, |
154 AF_NONE}, | 172 AF_NONE}, |
155 }; | 173 }; |
156 AcceleratorManager::Get()->RegisterAccelerators( | 174 AcceleratorManager::Get()->RegisterAccelerators( |
157 accelerator_data, arraysize(accelerator_data), this); | 175 accelerator_data, arraysize(accelerator_data), this); |
158 } | 176 } |
159 | 177 |
160 void WindowManagerImpl::AddObserver(WindowManagerObserver* observer) { | 178 void WindowManagerImpl::AddObserver(WindowManagerObserver* observer) { |
161 observers_.AddObserver(observer); | 179 observers_.AddObserver(observer); |
162 } | 180 } |
163 | 181 |
164 void WindowManagerImpl::RemoveObserver(WindowManagerObserver* observer) { | 182 void WindowManagerImpl::RemoveObserver(WindowManagerObserver* observer) { |
165 observers_.RemoveObserver(observer); | 183 observers_.RemoveObserver(observer); |
166 } | 184 } |
167 | 185 |
168 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { | 186 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { |
169 CHECK_EQ(container_.get(), window->parent()); | 187 mru_window_tracker_->MoveToFront(window); |
170 container_->StackChildAtTop(window); | |
171 wm::ActivateWindow(window); | 188 wm::ActivateWindow(window); |
172 SetInOverview(false); | 189 SetInOverview(false); |
173 } | 190 } |
174 | 191 |
175 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { | 192 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { |
176 if (window == container_) | 193 if (window == container_) |
177 container_.reset(); | 194 container_.reset(); |
178 } | 195 } |
179 | 196 |
180 bool WindowManagerImpl::IsCommandEnabled(int command_id) const { | 197 bool WindowManagerImpl::IsCommandEnabled(int command_id) const { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 DCHECK(!instance); | 261 DCHECK(!instance); |
245 } | 262 } |
246 | 263 |
247 // static | 264 // static |
248 WindowManager* WindowManager::GetInstance() { | 265 WindowManager* WindowManager::GetInstance() { |
249 DCHECK(instance); | 266 DCHECK(instance); |
250 return instance; | 267 return instance; |
251 } | 268 } |
252 | 269 |
253 } // namespace athena | 270 } // namespace athena |
OLD | NEW |