Chromium Code Reviews| 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 DCHECK(std::find_if(children.begin(), | |
| 202 children.end(), | |
| 203 PriorityMatcher(params.z_order_priority)) | |
| 204 == children.end()) | |
| 205 << "The container with the priority " | |
| 206 << params.z_order_priority << " already exists."; | |
|
sadrul
2014/07/23 18:37:24
nice
| |
| 207 | |
| 208 container->SetProperty(kContainerParamsKey, new ContainerParams(params)); | |
| 161 root_window_->AddChild(container); | 209 root_window_->AddChild(container); |
| 210 | |
| 211 aura::Window::Windows::const_iterator iter = | |
| 212 std::find_if(children.begin(), | |
| 213 children.end(), | |
| 214 HigherPriorityFinder(params.z_order_priority)); | |
| 215 if (iter != children.end()) | |
| 216 root_window_->StackChildBelow(container, *iter); | |
| 217 | |
| 162 container->Show(); | 218 container->Show(); |
| 163 container->SetProperty(kContainerParamsKey, new ContainerParams(params)); | |
| 164 return container; | 219 return container; |
| 165 } | 220 } |
| 166 | 221 |
| 167 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { | 222 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { |
| 168 background_controller_->SetImage(image); | 223 background_controller_->SetImage(image); |
| 169 } | 224 } |
| 170 | 225 |
| 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 | 226 } // namespace |
| 185 | 227 |
| 186 ScreenManager::ContainerParams::ContainerParams(const std::string& n) | 228 ScreenManager::ContainerParams::ContainerParams(const std::string& n, |
| 187 : name(n), | 229 int priority) |
| 188 can_activate_children(false) { | 230 : name(n), can_activate_children(false), z_order_priority(priority) { |
| 189 } | 231 } |
| 190 | 232 |
| 191 // static | 233 // static |
| 192 ScreenManager* ScreenManager::Create(aura::Window* root_window) { | 234 ScreenManager* ScreenManager::Create(aura::Window* root_window) { |
| 193 (new ScreenManagerImpl(root_window))->Init(); | 235 (new ScreenManagerImpl(root_window))->Init(); |
| 194 DCHECK(instance); | 236 DCHECK(instance); |
| 195 return instance; | 237 return instance; |
| 196 } | 238 } |
| 197 | 239 |
| 198 // static | 240 // static |
| 199 ScreenManager* ScreenManager::Get() { | 241 ScreenManager* ScreenManager::Get() { |
| 200 DCHECK(instance); | 242 DCHECK(instance); |
| 201 return instance; | 243 return instance; |
| 202 } | 244 } |
| 203 | 245 |
| 204 // static | 246 // static |
| 205 void ScreenManager::Shutdown() { | 247 void ScreenManager::Shutdown() { |
| 206 DCHECK(instance); | 248 DCHECK(instance); |
| 207 delete instance; | 249 delete instance; |
| 208 DCHECK(!instance); | 250 DCHECK(!instance); |
| 209 } | 251 } |
| 210 | 252 |
| 211 // static | 253 // static |
| 212 wm::FocusRules* ScreenManager::CreateFocusRules() { | 254 wm::FocusRules* ScreenManager::CreateFocusRules() { |
| 213 return new AthenaFocusRules(); | 255 return new AthenaFocusRules(); |
| 214 } | 256 } |
| 215 | 257 |
| 216 } // namespace athena | 258 } // namespace athena |
| OLD | NEW |