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/input/public/accelerator_manager.h" | 7 #include "athena/input/public/accelerator_manager.h" |
8 #include "athena/screen/public/screen_manager.h" | 8 #include "athena/screen/public/screen_manager.h" |
9 #include "athena/wm/bezel_controller.h" | 9 #include "athena/wm/bezel_controller.h" |
10 #include "athena/wm/public/window_manager_observer.h" | 10 #include "athena/wm/public/window_manager_observer.h" |
11 #include "athena/wm/split_view_controller.h" | 11 #include "athena/wm/split_view_controller.h" |
12 #include "athena/wm/window_overview_mode.h" | 12 #include "athena/wm/window_overview_mode.h" |
13 #include "athena/wm/window_stack_provider.h" | |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/observer_list.h" | 15 #include "base/observer_list.h" |
15 #include "ui/aura/layout_manager.h" | 16 #include "ui/aura/layout_manager.h" |
16 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
17 #include "ui/wm/public/window_types.h" | 18 #include "ui/wm/public/window_types.h" |
18 | 19 |
19 namespace athena { | 20 namespace athena { |
20 namespace { | 21 namespace { |
21 | 22 |
22 class WindowManagerImpl : public WindowManager, | 23 class WindowManagerImpl : public WindowManager, |
24 public WindowStackProvider, | |
23 public WindowOverviewModeDelegate, | 25 public WindowOverviewModeDelegate, |
24 public aura::WindowObserver, | 26 public aura::WindowObserver, |
25 public AcceleratorHandler { | 27 public AcceleratorHandler { |
26 public: | 28 public: |
27 WindowManagerImpl(); | 29 WindowManagerImpl(); |
28 virtual ~WindowManagerImpl(); | 30 virtual ~WindowManagerImpl(); |
29 | 31 |
30 void Layout(); | 32 void Layout(); |
31 | 33 |
32 // WindowManager: | 34 // WindowManager: |
33 virtual void ToggleOverview() OVERRIDE { | 35 virtual void ToggleOverview() OVERRIDE { |
36 LOG(ERROR) << "ToggleOverview"; | |
34 if (overview_) { | 37 if (overview_) { |
Jun Mukai
2014/07/25 20:21:30
Keep in mind that pkotwicz is changing the code ar
| |
35 overview_.reset(); | |
36 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 38 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
37 OnOverviewModeExit()); | 39 OnOverviewModeExit()); |
40 overview_.reset(); | |
38 } else { | 41 } else { |
39 overview_ = WindowOverviewMode::Create(container_.get(), this); | 42 // Re-stack all windows in the order defined by ordered_windows_. |
43 aura::Window::Windows::iterator it; | |
44 for (it = ordered_windows_.begin(); it != ordered_windows_.end(); ++it) { | |
45 container_->StackChildAtTop(*it); | |
46 } | |
40 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 47 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
41 OnOverviewModeEnter()); | 48 OnOverviewModeEnter()); |
49 overview_ = | |
50 WindowOverviewMode::Create(container_.get(), GetWindowStack(), this); | |
42 } | 51 } |
43 } | 52 } |
44 | 53 |
54 virtual bool IsOverviewModeActive() OVERRIDE { | |
55 return overview_; | |
56 } | |
57 | |
45 private: | 58 private: |
46 enum Command { | 59 enum Command { |
47 COMMAND_TOGGLE_OVERVIEW, | 60 COMMAND_TOGGLE_OVERVIEW, |
48 }; | 61 }; |
49 | 62 |
50 void InstallAccelerators() { | 63 void InstallAccelerators() { |
51 const AcceleratorData accelerator_data[] = { | 64 const AcceleratorData accelerator_data[] = { |
52 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, COMMAND_TOGGLE_OVERVIEW, | 65 {TRIGGER_ON_PRESS, ui::VKEY_F6, ui::EF_NONE, COMMAND_TOGGLE_OVERVIEW, |
53 AF_NONE}, | 66 AF_NONE}, |
54 }; | 67 }; |
55 AcceleratorManager::Get()->RegisterAccelerators( | 68 AcceleratorManager::Get()->RegisterAccelerators( |
56 accelerator_data, arraysize(accelerator_data), this); | 69 accelerator_data, arraysize(accelerator_data), this); |
57 } | 70 } |
58 | 71 |
59 // WindowManager: | 72 // WindowManager: |
60 virtual void AddObserver(WindowManagerObserver* observer) OVERRIDE { | 73 virtual void AddObserver(WindowManagerObserver* observer) OVERRIDE { |
61 observers_.AddObserver(observer); | 74 observers_.AddObserver(observer); |
62 } | 75 } |
63 | 76 |
64 virtual void RemoveObserver(WindowManagerObserver* observer) OVERRIDE { | 77 virtual void RemoveObserver(WindowManagerObserver* observer) OVERRIDE { |
65 observers_.RemoveObserver(observer); | 78 observers_.RemoveObserver(observer); |
66 } | 79 } |
67 | 80 |
81 // WindowStackProvider: | |
82 virtual void MoveWindowToFront(aura::Window* window) OVERRIDE{ | |
83 CHECK_EQ(container_.get(), window->parent()); | |
84 aura::Window::Windows::iterator it = std::find( | |
85 ordered_windows_.begin(), ordered_windows_.end(), window); | |
86 DCHECK(it != ordered_windows_.end()); | |
87 ordered_windows_.erase(it); | |
88 ordered_windows_.push_back(window); | |
89 container_->StackChildAtTop(window); | |
90 } | |
91 | |
92 virtual const aura::Window::Windows& GetWindowStack() OVERRIDE { | |
93 return ordered_windows_; | |
94 } | |
95 | |
68 // WindowOverviewModeDelegate: | 96 // WindowOverviewModeDelegate: |
69 virtual void OnSelectWindow(aura::Window* window) OVERRIDE { | 97 virtual void OnSelectWindow(aura::Window* window) OVERRIDE { |
70 CHECK_EQ(container_.get(), window->parent()); | 98 MoveWindowToFront(window); |
71 container_->StackChildAtTop(window); | |
oshima
2014/07/28 17:58:43
This should have called wm::ActivateWindow instead
mfomitchev
2014/08/05 19:56:57
Done.
| |
72 overview_.reset(); | 99 overview_.reset(); |
73 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, | 100 FOR_EACH_OBSERVER(WindowManagerObserver, observers_, |
74 OnOverviewModeExit()); | 101 OnOverviewModeExit()); |
75 } | 102 } |
76 | 103 |
77 // aura::WindowObserver | 104 // aura::WindowObserver |
78 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { | 105 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE { |
79 if (window == container_) | 106 if (window == container_) |
80 container_.reset(); | 107 container_.reset(); |
81 } | 108 } |
82 | 109 |
110 virtual void OnWillRemoveWindow(aura::Window* window) OVERRIDE { | |
111 aura::Window::Windows::iterator it = std::find( | |
112 ordered_windows_.begin(), ordered_windows_.end(), window); | |
113 ordered_windows_.erase(it); | |
114 } | |
115 | |
116 virtual void OnWindowAdded(aura::Window* new_window) OVERRIDE { | |
117 ordered_windows_.push_back(new_window); | |
118 } | |
119 | |
83 // AcceleratorHandler: | 120 // AcceleratorHandler: |
84 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } | 121 virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; } |
85 virtual bool OnAcceleratorFired(int command_id, | 122 virtual bool OnAcceleratorFired(int command_id, |
86 const ui::Accelerator& accelerator) OVERRIDE { | 123 const ui::Accelerator& accelerator) OVERRIDE { |
87 switch (command_id) { | 124 switch (command_id) { |
88 case COMMAND_TOGGLE_OVERVIEW: | 125 case COMMAND_TOGGLE_OVERVIEW: |
89 ToggleOverview(); | 126 ToggleOverview(); |
90 break; | 127 break; |
91 } | 128 } |
92 return true; | 129 return true; |
93 } | 130 } |
94 | 131 |
95 scoped_ptr<aura::Window> container_; | 132 scoped_ptr<aura::Window> container_; |
133 aura::Window::Windows ordered_windows_; | |
oshima
2014/07/25 21:41:10
what's the reason to keep its own list?
mfomitchev
2014/07/25 23:27:38
The order within the container changes when you in
oshima
2014/07/28 17:58:42
StackChildAtTop does change the order within the c
mfomitchev
2014/07/28 18:15:00
I can't rely on the container's window order for t
oshima
2014/07/28 18:35:20
I know that container's window order isn't enough
mfomitchev
2014/07/28 18:57:42
SplitViewController implements window switching -
mfomitchev
2014/08/05 19:56:57
I have implemented a very basic, stripped down Mru
| |
96 scoped_ptr<WindowOverviewMode> overview_; | 134 scoped_ptr<WindowOverviewMode> overview_; |
97 scoped_ptr<BezelController> bezel_controller_; | 135 scoped_ptr<BezelController> bezel_controller_; |
98 scoped_ptr<SplitViewController> split_view_controller_; | 136 scoped_ptr<SplitViewController> split_view_controller_; |
99 ObserverList<WindowManagerObserver> observers_; | 137 ObserverList<WindowManagerObserver> observers_; |
100 | 138 |
101 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); | 139 DISALLOW_COPY_AND_ASSIGN(WindowManagerImpl); |
102 }; | 140 }; |
103 | 141 |
104 class WindowManagerImpl* instance = NULL; | 142 class WindowManagerImpl* instance = NULL; |
105 | 143 |
(...skipping 25 matching lines...) Expand all Loading... | |
131 DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager); | 169 DISALLOW_COPY_AND_ASSIGN(AthenaContainerLayoutManager); |
132 }; | 170 }; |
133 | 171 |
134 WindowManagerImpl::WindowManagerImpl() { | 172 WindowManagerImpl::WindowManagerImpl() { |
135 ScreenManager::ContainerParams params("DefaultContainer"); | 173 ScreenManager::ContainerParams params("DefaultContainer"); |
136 params.can_activate_children = true; | 174 params.can_activate_children = true; |
137 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); | 175 container_.reset(ScreenManager::Get()->CreateDefaultContainer(params)); |
138 container_->SetLayoutManager(new AthenaContainerLayoutManager); | 176 container_->SetLayoutManager(new AthenaContainerLayoutManager); |
139 container_->AddObserver(this); | 177 container_->AddObserver(this); |
140 bezel_controller_.reset(new BezelController(container_.get())); | 178 bezel_controller_.reset(new BezelController(container_.get())); |
141 split_view_controller_.reset(new SplitViewController()); | 179 split_view_controller_.reset(new SplitViewController( |
180 container_.get(), this, this)); | |
142 bezel_controller_->set_left_right_delegate(split_view_controller_.get()); | 181 bezel_controller_->set_left_right_delegate(split_view_controller_.get()); |
143 container_->AddPreTargetHandler(bezel_controller_.get()); | 182 container_->AddPreTargetHandler(bezel_controller_.get()); |
144 instance = this; | 183 instance = this; |
145 InstallAccelerators(); | 184 InstallAccelerators(); |
146 } | 185 } |
147 | 186 |
148 WindowManagerImpl::~WindowManagerImpl() { | 187 WindowManagerImpl::~WindowManagerImpl() { |
149 if (container_) { | 188 if (container_) { |
150 container_->RemoveObserver(this); | 189 container_->RemoveObserver(this); |
151 container_->RemovePreTargetHandler(bezel_controller_.get()); | 190 container_->RemovePreTargetHandler(bezel_controller_.get()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
185 DCHECK(!instance); | 224 DCHECK(!instance); |
186 } | 225 } |
187 | 226 |
188 // static | 227 // static |
189 WindowManager* WindowManager::GetInstance() { | 228 WindowManager* WindowManager::GetInstance() { |
190 DCHECK(instance); | 229 DCHECK(instance); |
191 return instance; | 230 return instance; |
192 } | 231 } |
193 | 232 |
194 } // namespace athena | 233 } // namespace athena |
OLD | NEW |