| 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 <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "athena/common/container_priorities.h" | 9 #include "athena/common/container_priorities.h" |
| 10 #include "athena/input/public/accelerator_manager.h" | 10 #include "athena/input/public/accelerator_manager.h" |
| 11 #include "athena/screen/public/screen_manager.h" | 11 #include "athena/screen/public/screen_manager.h" |
| 12 #include "athena/wm/bezel_controller.h" | 12 #include "athena/wm/bezel_controller.h" |
| 13 #include "athena/wm/mru_window_tracker.h" | |
| 14 #include "athena/wm/public/window_manager_observer.h" | 13 #include "athena/wm/public/window_manager_observer.h" |
| 15 #include "athena/wm/split_view_controller.h" | 14 #include "athena/wm/split_view_controller.h" |
| 16 #include "athena/wm/title_drag_controller.h" | 15 #include "athena/wm/title_drag_controller.h" |
| 17 #include "athena/wm/window_overview_mode.h" | 16 #include "athena/wm/window_overview_mode.h" |
| 18 #include "base/logging.h" | 17 #include "base/logging.h" |
| 19 #include "base/observer_list.h" | 18 #include "base/observer_list.h" |
| 20 #include "ui/aura/layout_manager.h" | 19 #include "ui/aura/layout_manager.h" |
| 21 #include "ui/aura/window.h" | 20 #include "ui/aura/window.h" |
| 22 #include "ui/wm/core/shadow_controller.h" | 21 #include "ui/wm/core/shadow_controller.h" |
| 23 #include "ui/wm/core/window_util.h" | 22 #include "ui/wm/core/window_util.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 35 public TitleDragControllerDelegate { | 34 public TitleDragControllerDelegate { |
| 36 public: | 35 public: |
| 37 WindowManagerImpl(); | 36 WindowManagerImpl(); |
| 38 virtual ~WindowManagerImpl(); | 37 virtual ~WindowManagerImpl(); |
| 39 | 38 |
| 40 void Layout(); | 39 void Layout(); |
| 41 | 40 |
| 42 // WindowManager: | 41 // WindowManager: |
| 43 virtual void ToggleOverview() OVERRIDE; | 42 virtual void ToggleOverview() OVERRIDE; |
| 44 | 43 |
| 45 virtual bool IsOverviewModeActive() OVERRIDE; | |
| 46 | |
| 47 private: | 44 private: |
| 48 enum Command { | 45 enum Command { |
| 49 CMD_TOGGLE_OVERVIEW, | 46 CMD_TOGGLE_OVERVIEW, |
| 50 }; | 47 }; |
| 51 | 48 |
| 52 // Sets whether overview mode is active. | 49 // Sets whether overview mode is active. |
| 53 void SetInOverview(bool active); | 50 void SetInOverview(bool active); |
| 54 | 51 |
| 55 void InstallAccelerators(); | 52 void InstallAccelerators(); |
| 56 | 53 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 69 virtual bool IsCommandEnabled(int command_id) const OVERRIDE; | 66 virtual bool IsCommandEnabled(int command_id) const OVERRIDE; |
| 70 virtual bool OnAcceleratorFired(int command_id, | 67 virtual bool OnAcceleratorFired(int command_id, |
| 71 const ui::Accelerator& accelerator) OVERRIDE; | 68 const ui::Accelerator& accelerator) OVERRIDE; |
| 72 | 69 |
| 73 // TitleDragControllerDelegate: | 70 // TitleDragControllerDelegate: |
| 74 virtual aura::Window* GetWindowBehind(aura::Window* window) OVERRIDE; | 71 virtual aura::Window* GetWindowBehind(aura::Window* window) OVERRIDE; |
| 75 virtual void OnTitleDragStarted(aura::Window* window) OVERRIDE; | 72 virtual void OnTitleDragStarted(aura::Window* window) OVERRIDE; |
| 76 virtual void OnTitleDragCompleted(aura::Window* window) OVERRIDE; | 73 virtual void OnTitleDragCompleted(aura::Window* window) OVERRIDE; |
| 77 virtual void OnTitleDragCanceled(aura::Window* window) OVERRIDE; | 74 virtual void OnTitleDragCanceled(aura::Window* window) OVERRIDE; |
| 78 | 75 |
| 79 // Should be declared first so that it is destoyed last. | |
| 80 ObserverList<WindowManagerObserver> observers_; | |
| 81 | |
| 82 scoped_ptr<aura::Window> container_; | 76 scoped_ptr<aura::Window> container_; |
| 83 scoped_ptr<MruWindowTracker> mru_window_tracker_; | |
| 84 scoped_ptr<WindowOverviewMode> overview_; | 77 scoped_ptr<WindowOverviewMode> overview_; |
| 85 scoped_ptr<BezelController> bezel_controller_; | 78 scoped_ptr<BezelController> bezel_controller_; |
| 86 scoped_ptr<SplitViewController> split_view_controller_; | 79 scoped_ptr<SplitViewController> split_view_controller_; |
| 87 scoped_ptr<wm::WMState> wm_state_; | 80 scoped_ptr<wm::WMState> wm_state_; |
| 88 scoped_ptr<TitleDragController> title_drag_controller_; | 81 scoped_ptr<TitleDragController> title_drag_controller_; |
| 89 scoped_ptr<wm::ShadowController> shadow_controller_; | 82 scoped_ptr<wm::ShadowController> shadow_controller_; |
| 83 ObserverList<WindowManagerObserver> observers_; |
| 90 | 84 |
| 91 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); | 85 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); |
| 92 }; | 86 }; |
| 93 | 87 |
| 94 class AthenaContainerLayoutManager : public aura::LayoutManager { | 88 class AthenaContainerLayoutManager : public aura::LayoutManager { |
| 95 public: | 89 public: |
| 96 AthenaContainerLayoutManager(); | 90 AthenaContainerLayoutManager(); |
| 97 virtual ~AthenaContainerLayoutManager(); | 91 virtual ~AthenaContainerLayoutManager(); |
| 98 | 92 |
| 99 private: | 93 private: |
| (...skipping 11 matching lines...) Expand all Loading... |
| 111 }; | 105 }; |
| 112 | 106 |
| 113 class WindowManagerImpl* instance = NULL; | 107 class WindowManagerImpl* instance = NULL; |
| 114 | 108 |
| 115 WindowManagerImpl::WindowManagerImpl() { | 109 WindowManagerImpl::WindowManagerImpl() { |
| 116 ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); | 110 ScreenManager::ContainerParams params("DefaultContainer", CP_DEFAULT); |
| 117 params.can_activate_children = true; | 111 params.can_activate_children = true; |
| 118 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); | 112 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); |
| 119 container_->SetLayoutManager(new AthenaContainerLayoutManager); | 113 container_->SetLayoutManager(new AthenaContainerLayoutManager); |
| 120 container_->AddObserver(this); | 114 container_->AddObserver(this); |
| 121 mru_window_tracker_.reset(new MruWindowTracker(container_.get())); | |
| 122 bezel_controller_.reset(new BezelController(container_.get())); | 115 bezel_controller_.reset(new BezelController(container_.get())); |
| 123 split_view_controller_.reset(new SplitViewController( | 116 split_view_controller_.reset(new SplitViewController()); |
| 124 container_.get(), mru_window_tracker_.get(), this)); | |
| 125 bezel_controller_->set_left_right_delegate(split_view_controller_.get()); | 117 bezel_controller_->set_left_right_delegate(split_view_controller_.get()); |
| 126 container_->AddPreTargetHandler(bezel_controller_.get()); | 118 container_->AddPreTargetHandler(bezel_controller_.get()); |
| 127 title_drag_controller_.reset(new TitleDragController(container_.get(), this)); | 119 title_drag_controller_.reset(new TitleDragController(container_.get(), this)); |
| 128 wm_state_.reset(new wm::WMState()); | 120 wm_state_.reset(new wm::WMState()); |
| 129 aura::client::ActivationClient* activation_client = | 121 aura::client::ActivationClient* activation_client = |
| 130 aura::client::GetActivationClient(container_->GetRootWindow()); | 122 aura::client::GetActivationClient(container_->GetRootWindow()); |
| 131 shadow_controller_.reset(new wm::ShadowController(activation_client)); | 123 shadow_controller_.reset(new wm::ShadowController(activation_client)); |
| 132 instance = this; | 124 instance = this; |
| 133 InstallAccelerators(); | 125 InstallAccelerators(); |
| 134 } | 126 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 155 ++iter) { | 147 ++iter) { |
| 156 if ((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL) | 148 if ((*iter)->type() == ui::wm::WINDOW_TYPE_NORMAL) |
| 157 (*iter)->SetBounds(bounds); | 149 (*iter)->SetBounds(bounds); |
| 158 } | 150 } |
| 159 } | 151 } |
| 160 | 152 |
| 161 void WindowManagerImpl::ToggleOverview() { | 153 void WindowManagerImpl::ToggleOverview() { |
| 162 SetInOverview(overview_.get() == NULL); | 154 SetInOverview(overview_.get() == NULL); |
| 163 } | 155 } |
| 164 | 156 |
| 165 bool WindowManagerImpl::IsOverviewModeActive() { | |
| 166 return overview_; | |
| 167 } | |
| 168 | |
| 169 void WindowManagerImpl::SetInOverview(bool active) { | 157 void WindowManagerImpl::SetInOverview(bool active) { |
| 170 bool in_overview = !!overview_; | 158 bool in_overview = !!overview_; |
| 171 if (active == in_overview) | 159 if (active == in_overview) |
| 172 return; | 160 return; |
| 173 | 161 |
| 174 if (active) { | 162 if (active) { |
| 163 overview_ = WindowOverviewMode::Create(container_.get(), this); |
| 175 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 164 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 176 OnOverviewModeEnter()); | 165 OnOverviewModeEnter()); |
| 177 // Re-stack all windows in the order defined by mru_window_tracker_. | |
| 178 aura::Window::Windows window_list = mru_window_tracker_->GetWindowList(); | |
| 179 aura::Window::Windows::iterator it; | |
| 180 for (it = window_list.begin(); it != window_list.end(); ++it) | |
| 181 container_->StackChildAtTop(*it); | |
| 182 overview_ = WindowOverviewMode::Create(container_.get(), | |
| 183 mru_window_tracker_.get(), | |
| 184 this); | |
| 185 } else { | 166 } else { |
| 186 overview_.reset(); | 167 overview_.reset(); |
| 187 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 168 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
| 188 OnOverviewModeExit()); | 169 OnOverviewModeExit()); |
| 189 } | 170 } |
| 190 } | 171 } |
| 191 | 172 |
| 192 void WindowManagerImpl::InstallAccelerators() { | 173 void WindowManagerImpl::InstallAccelerators() { |
| 193 const AcceleratorData accelerator_data[] = { | 174 const AcceleratorData accelerator_data[] = { |
| 194 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, CMD_TOGGLE_OVERVIEW, | 175 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, CMD_TOGGLE_OVERVIEW, |
| 195 AF_NONE}, | 176 AF_NONE}, |
| 196 }; | 177 }; |
| 197 AcceleratorManager::Get()->RegisterAccelerators( | 178 AcceleratorManager::Get()->RegisterAccelerators( |
| 198 accelerator_data, arraysize(accelerator_data), this); | 179 accelerator_data, arraysize(accelerator_data), this); |
| 199 } | 180 } |
| 200 | 181 |
| 201 void WindowManagerImpl::AddObserver(WindowManagerObserver* observer) { | 182 void WindowManagerImpl::AddObserver(WindowManagerObserver* observer) { |
| 202 observers_.AddObserver(observer); | 183 observers_.AddObserver(observer); |
| 203 } | 184 } |
| 204 | 185 |
| 205 void WindowManagerImpl::RemoveObserver(WindowManagerObserver* observer) { | 186 void WindowManagerImpl::RemoveObserver(WindowManagerObserver* observer) { |
| 206 observers_.RemoveObserver(observer); | 187 observers_.RemoveObserver(observer); |
| 207 } | 188 } |
| 208 | 189 |
| 209 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { | 190 void WindowManagerImpl::OnSelectWindow(aura::Window* window) { |
| 210 mru_window_tracker_->MoveToFront(window); | 191 CHECK_EQ(container_.get(), window->parent()); |
| 192 container_->StackChildAtTop(window); |
| 211 wm::ActivateWindow(window); | 193 wm::ActivateWindow(window); |
| 212 SetInOverview(false); | 194 SetInOverview(false); |
| 213 } | 195 } |
| 214 | 196 |
| 215 void WindowManagerImpl::OnWindowAdded(aura::Window* new_window) { | 197 void WindowManagerImpl::OnWindowAdded(aura::Window* new_window) { |
| 216 if (new_window->type() == ui::wm::WINDOW_TYPE_NORMAL) | 198 if (new_window->type() == ui::wm::WINDOW_TYPE_NORMAL) |
| 217 SetInOverview(false); | 199 SetInOverview(false); |
| 218 } | 200 } |
| 219 | 201 |
| 220 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { | 202 void WindowManagerImpl::OnWindowDestroying(aura::Window* window) { |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 DCHECK(!instance); | 291 DCHECK(!instance); |
| 310 } | 292 } |
| 311 | 293 |
| 312 // static | 294 // static |
| 313 WindowManager* WindowManager::GetInstance() { | 295 WindowManager* WindowManager::GetInstance() { |
| 314 DCHECK(instance); | 296 DCHECK(instance); |
| 315 return instance; | 297 return instance; |
| 316 } | 298 } |
| 317 | 299 |
| 318 } // namespace athena | 300 } // namespace athena |
| OLD | NEW |