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/screen/public/screen_manager.h" | 5 #include "athena/screen/public/screen_manager.h" |
6 | 6 |
| 7 #include "athena/common/container_priorities.h" |
7 #include "athena/common/fill_layout_manager.h" | 8 #include "athena/common/fill_layout_manager.h" |
8 #include "athena/input/public/accelerator_manager.h" | 9 #include "athena/input/public/accelerator_manager.h" |
9 #include "athena/screen/background_controller.h" | 10 #include "athena/screen/background_controller.h" |
10 #include "athena/screen/screen_accelerator_handler.h" | 11 #include "athena/screen/screen_accelerator_handler.h" |
11 #include "base/logging.h" | 12 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
13 #include "ui/aura/client/screen_position_client.h" | 14 #include "ui/aura/client/screen_position_client.h" |
14 #include "ui/aura/client/window_tree_client.h" | 15 #include "ui/aura/client/window_tree_client.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" |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 | 121 |
121 scoped_ptr<BackgroundController> background_controller_; | 122 scoped_ptr<BackgroundController> background_controller_; |
122 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_; | 123 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_; |
123 scoped_ptr<AcceleratorHandler> accelerator_handler_; | 124 scoped_ptr<AcceleratorHandler> accelerator_handler_; |
124 scoped_ptr< ::wm::ScopedCaptureClient> capture_client_; | 125 scoped_ptr< ::wm::ScopedCaptureClient> capture_client_; |
125 scoped_ptr<aura::client::ScreenPositionClient> screen_position_client_; | 126 scoped_ptr<aura::client::ScreenPositionClient> screen_position_client_; |
126 | 127 |
127 DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl); | 128 DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl); |
128 }; | 129 }; |
129 | 130 |
| 131 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window) |
| 132 : root_window_(root_window) { |
| 133 DCHECK(root_window_); |
| 134 DCHECK(!instance); |
| 135 instance = this; |
| 136 } |
| 137 |
| 138 ScreenManagerImpl::~ScreenManagerImpl() { |
| 139 aura::client::SetScreenPositionClient(root_window_, NULL); |
| 140 aura::client::SetWindowTreeClient(root_window_, NULL); |
| 141 instance = NULL; |
| 142 } |
| 143 |
130 void ScreenManagerImpl::Init() { | 144 void ScreenManagerImpl::Init() { |
131 // TODO(oshima): Move the background out from ScreenManager. | 145 // TODO(oshima): Move the background out from ScreenManager. |
132 root_window_->SetLayoutManager(new FillLayoutManager(root_window_)); | 146 root_window_->SetLayoutManager(new FillLayoutManager(root_window_)); |
133 background_window_ = CreateContainer(ContainerParams("AthenaBackground")); | 147 background_window_ = |
| 148 CreateContainer(ContainerParams("AthenaBackground", CP_BACKGROUND)); |
134 | 149 |
135 background_window_->SetLayoutManager( | 150 background_window_->SetLayoutManager( |
136 new FillLayoutManager(background_window_)); | 151 new FillLayoutManager(background_window_)); |
137 background_controller_.reset(new BackgroundController(background_window_)); | 152 background_controller_.reset(new BackgroundController(background_window_)); |
138 | 153 |
139 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window_)); | 154 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window_)); |
140 accelerator_handler_.reset(new ScreenAcceleratorHandler(root_window_)); | 155 accelerator_handler_.reset(new ScreenAcceleratorHandler(root_window_)); |
141 } | 156 } |
142 | 157 |
143 aura::Window* ScreenManagerImpl::CreateDefaultContainer( | 158 aura::Window* ScreenManagerImpl::CreateDefaultContainer( |
144 const ContainerParams& params) { | 159 const ContainerParams& params) { |
145 aura::Window* container = CreateContainer(params); | 160 aura::Window* container = CreateContainer(params); |
146 window_tree_client_.reset(new AthenaWindowTreeClient(container)); | 161 window_tree_client_.reset(new AthenaWindowTreeClient(container)); |
147 aura::client::SetWindowTreeClient(root_window_, window_tree_client_.get()); | 162 aura::client::SetWindowTreeClient(root_window_, window_tree_client_.get()); |
148 | 163 |
149 screen_position_client_.reset(new AthenaScreenPositionClient()); | 164 screen_position_client_.reset(new AthenaScreenPositionClient()); |
150 aura::client::SetScreenPositionClient(root_window_, | 165 aura::client::SetScreenPositionClient(root_window_, |
151 screen_position_client_.get()); | 166 screen_position_client_.get()); |
152 | 167 |
153 return container; | 168 return container; |
154 } | 169 } |
155 | 170 |
| 171 // A functor to find a container that has the higher priority. |
| 172 struct HigherPriorityFinder { |
| 173 HigherPriorityFinder(int p) : priority(p) {} |
| 174 bool operator()(aura::Window* window) { |
| 175 return window->GetProperty(kContainerParamsKey)->z_order_priority > |
| 176 priority; |
| 177 } |
| 178 int priority; |
| 179 }; |
| 180 |
| 181 #if !defined(NDEBUG) |
| 182 struct PriorityMatcher { |
| 183 PriorityMatcher(int p) : priority(p) {} |
| 184 bool operator()(aura::Window* window) { |
| 185 return window->GetProperty(kContainerParamsKey)->z_order_priority == |
| 186 priority; |
| 187 } |
| 188 int priority; |
| 189 }; |
| 190 #endif |
| 191 |
156 aura::Window* ScreenManagerImpl::CreateContainer( | 192 aura::Window* ScreenManagerImpl::CreateContainer( |
157 const ContainerParams& params) { | 193 const ContainerParams& params) { |
158 aura::Window* container = new aura::Window(NULL); | 194 aura::Window* container = new aura::Window(NULL); |
| 195 CHECK_GE(params.z_order_priority, 0); |
159 container->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 196 container->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
160 container->SetName(params.name); | 197 container->SetName(params.name); |
| 198 |
| 199 const aura::Window::Windows& children = root_window_->children(); |
| 200 |
| 201 #if !defined(NDEBUG) |
| 202 DCHECK(std::find_if(children.begin(), |
| 203 children.end(), |
| 204 PriorityMatcher(params.z_order_priority)) |
| 205 == children.end()) |
| 206 << "The container with the priority " |
| 207 << params.z_order_priority << " already exists."; |
| 208 #endif |
| 209 |
| 210 container->SetProperty(kContainerParamsKey, new ContainerParams(params)); |
161 root_window_->AddChild(container); | 211 root_window_->AddChild(container); |
| 212 |
| 213 aura::Window::Windows::const_iterator iter = |
| 214 std::find_if(children.begin(), |
| 215 children.end(), |
| 216 HigherPriorityFinder(params.z_order_priority)); |
| 217 if (iter != children.end()) |
| 218 root_window_->StackChildBelow(container, *iter); |
| 219 |
162 container->Show(); | 220 container->Show(); |
163 container->SetProperty(kContainerParamsKey, new ContainerParams(params)); | |
164 return container; | 221 return container; |
165 } | 222 } |
166 | 223 |
167 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { | 224 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { |
168 background_controller_->SetImage(image); | 225 background_controller_->SetImage(image); |
169 } | 226 } |
170 | 227 |
171 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window) | |
172 : root_window_(root_window) { | |
173 DCHECK(root_window_); | |
174 DCHECK(!instance); | |
175 instance = this; | |
176 } | |
177 | |
178 ScreenManagerImpl::~ScreenManagerImpl() { | |
179 aura::client::SetScreenPositionClient(root_window_, NULL); | |
180 aura::client::SetWindowTreeClient(root_window_, NULL); | |
181 instance = NULL; | |
182 } | |
183 | |
184 } // namespace | 228 } // namespace |
185 | 229 |
186 ScreenManager::ContainerParams::ContainerParams(const std::string& n) | 230 ScreenManager::ContainerParams::ContainerParams(const std::string& n, |
187 : name(n), | 231 int priority) |
188 can_activate_children(false) { | 232 : name(n), can_activate_children(false), z_order_priority(priority) { |
189 } | 233 } |
190 | 234 |
191 // static | 235 // static |
192 ScreenManager* ScreenManager::Create(aura::Window* root_window) { | 236 ScreenManager* ScreenManager::Create(aura::Window* root_window) { |
193 (new ScreenManagerImpl(root_window))->Init(); | 237 (new ScreenManagerImpl(root_window))->Init(); |
194 DCHECK(instance); | 238 DCHECK(instance); |
195 return instance; | 239 return instance; |
196 } | 240 } |
197 | 241 |
198 // static | 242 // static |
199 ScreenManager* ScreenManager::Get() { | 243 ScreenManager* ScreenManager::Get() { |
200 DCHECK(instance); | 244 DCHECK(instance); |
201 return instance; | 245 return instance; |
202 } | 246 } |
203 | 247 |
204 // static | 248 // static |
205 void ScreenManager::Shutdown() { | 249 void ScreenManager::Shutdown() { |
206 DCHECK(instance); | 250 DCHECK(instance); |
207 delete instance; | 251 delete instance; |
208 DCHECK(!instance); | 252 DCHECK(!instance); |
209 } | 253 } |
210 | 254 |
211 // static | 255 // static |
212 wm::FocusRules* ScreenManager::CreateFocusRules() { | 256 wm::FocusRules* ScreenManager::CreateFocusRules() { |
213 return new AthenaFocusRules(); | 257 return new AthenaFocusRules(); |
214 } | 258 } |
215 | 259 |
216 } // namespace athena | 260 } // namespace athena |
OLD | NEW |