| 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/container_priorities.h" |
| 8 #include "athena/common/fill_layout_manager.h" | 8 #include "athena/common/fill_layout_manager.h" |
| 9 #include "athena/input/public/accelerator_manager.h" | 9 #include "athena/input/public/accelerator_manager.h" |
| 10 #include "athena/screen/background_controller.h" | 10 #include "athena/screen/background_controller.h" |
| 11 #include "athena/screen/public/screen_manager_delegate.h" | |
| 12 #include "athena/screen/screen_accelerator_handler.h" | 11 #include "athena/screen/screen_accelerator_handler.h" |
| 13 #include "base/logging.h" | 12 #include "base/logging.h" |
| 14 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 15 #include "ui/aura/client/screen_position_client.h" | 14 #include "ui/aura/client/screen_position_client.h" |
| 16 #include "ui/aura/client/window_tree_client.h" | 15 #include "ui/aura/client/window_tree_client.h" |
| 17 #include "ui/aura/layout_manager.h" | 16 #include "ui/aura/layout_manager.h" |
| 18 #include "ui/aura/test/test_screen.h" | 17 #include "ui/aura/test/test_screen.h" |
| 19 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_property.h" | 19 #include "ui/aura/window_property.h" |
| 21 #include "ui/aura/window_targeter.h" | 20 #include "ui/aura/window_targeter.h" |
| 22 #include "ui/aura/window_tree_host.h" | 21 #include "ui/aura/window_tree_host.h" |
| 23 #include "ui/compositor/layer.h" | 22 #include "ui/compositor/layer.h" |
| 24 #include "ui/gfx/display.h" | 23 #include "ui/gfx/display.h" |
| 25 #include "ui/gfx/screen.h" | 24 #include "ui/gfx/screen.h" |
| 26 #include "ui/wm/core/base_focus_rules.h" | 25 #include "ui/wm/core/base_focus_rules.h" |
| 27 #include "ui/wm/core/capture_controller.h" | 26 #include "ui/wm/core/capture_controller.h" |
| 27 #include "ui/wm/core/focus_controller.h" |
| 28 | 28 |
| 29 namespace athena { | 29 namespace athena { |
| 30 namespace { | 30 namespace { |
| 31 | 31 |
| 32 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ScreenManager::ContainerParams, | 32 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ScreenManager::ContainerParams, |
| 33 kContainerParamsKey, | 33 kContainerParamsKey, |
| 34 NULL); | 34 NULL); |
| 35 | 35 |
| 36 ScreenManager* instance = NULL; | 36 ScreenManager* instance = NULL; |
| 37 | 37 |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 root_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>()); | 185 root_window->SetEventTargeter(scoped_ptr<ui::EventTargeter>()); |
| 186 } | 186 } |
| 187 | 187 |
| 188 aura::Window* container_; | 188 aura::Window* container_; |
| 189 | 189 |
| 190 DISALLOW_COPY_AND_ASSIGN(AthenaEventTargeter); | 190 DISALLOW_COPY_AND_ASSIGN(AthenaEventTargeter); |
| 191 }; | 191 }; |
| 192 | 192 |
| 193 class ScreenManagerImpl : public ScreenManager { | 193 class ScreenManagerImpl : public ScreenManager { |
| 194 public: | 194 public: |
| 195 ScreenManagerImpl(ScreenManagerDelegate* delegate, aura::Window* root_window); | 195 ScreenManagerImpl(aura::Window* root_window); |
| 196 virtual ~ScreenManagerImpl(); | 196 virtual ~ScreenManagerImpl(); |
| 197 | 197 |
| 198 void Init(); | 198 void Init(); |
| 199 | 199 |
| 200 private: | 200 private: |
| 201 // ScreenManager: | 201 // ScreenManager: |
| 202 virtual void SetWorkAreaInsets(const gfx::Insets& insets) OVERRIDE; | |
| 203 virtual aura::Window* CreateDefaultContainer( | 202 virtual aura::Window* CreateDefaultContainer( |
| 204 const ContainerParams& params) OVERRIDE; | 203 const ContainerParams& params) OVERRIDE; |
| 205 virtual aura::Window* CreateContainer(const ContainerParams& params) OVERRIDE; | 204 virtual aura::Window* CreateContainer(const ContainerParams& params) OVERRIDE; |
| 206 virtual aura::Window* GetContext() OVERRIDE { return root_window_; } | 205 virtual aura::Window* GetContext() OVERRIDE { return root_window_; } |
| 207 virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE; | 206 virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE; |
| 208 virtual void SetRotation(gfx::Display::Rotation rotation) OVERRIDE; | 207 virtual void SetRotation(gfx::Display::Rotation rotation) OVERRIDE; |
| 209 virtual ui::LayerAnimator* GetScreenAnimator() OVERRIDE; | 208 virtual ui::LayerAnimator* GetScreenAnimator() OVERRIDE; |
| 210 | 209 |
| 211 // Not owned. | 210 // Not owned. |
| 212 ScreenManagerDelegate* delegate_; | |
| 213 aura::Window* root_window_; | 211 aura::Window* root_window_; |
| 214 aura::Window* background_window_; | 212 aura::Window* background_window_; |
| 215 | 213 |
| 214 scoped_ptr<aura::client::FocusClient> focus_client_; |
| 216 scoped_ptr<BackgroundController> background_controller_; | 215 scoped_ptr<BackgroundController> background_controller_; |
| 217 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_; | 216 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_; |
| 218 scoped_ptr<AcceleratorHandler> accelerator_handler_; | 217 scoped_ptr<AcceleratorHandler> accelerator_handler_; |
| 219 scoped_ptr< ::wm::ScopedCaptureClient> capture_client_; | 218 scoped_ptr< ::wm::ScopedCaptureClient> capture_client_; |
| 220 scoped_ptr<aura::client::ScreenPositionClient> screen_position_client_; | 219 scoped_ptr<aura::client::ScreenPositionClient> screen_position_client_; |
| 221 | 220 |
| 222 DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl); | 221 DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl); |
| 223 }; | 222 }; |
| 224 | 223 |
| 225 ScreenManagerImpl::ScreenManagerImpl(ScreenManagerDelegate* delegate, | 224 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window) |
| 226 aura::Window* root_window) | 225 : root_window_(root_window) { |
| 227 : delegate_(delegate), | |
| 228 root_window_(root_window) { | |
| 229 DCHECK(root_window_); | 226 DCHECK(root_window_); |
| 230 DCHECK(!instance); | 227 DCHECK(!instance); |
| 231 instance = this; | 228 instance = this; |
| 232 } | 229 } |
| 233 | 230 |
| 234 ScreenManagerImpl::~ScreenManagerImpl() { | 231 ScreenManagerImpl::~ScreenManagerImpl() { |
| 235 aura::client::SetScreenPositionClient(root_window_, NULL); | 232 aura::client::SetScreenPositionClient(root_window_, NULL); |
| 236 aura::client::SetWindowTreeClient(root_window_, NULL); | 233 aura::client::SetWindowTreeClient(root_window_, NULL); |
| 234 wm::FocusController* focus_controller = |
| 235 static_cast<wm::FocusController*>(focus_client_.get()); |
| 236 root_window_->RemovePreTargetHandler(focus_controller); |
| 237 aura::client::SetActivationClient(root_window_, NULL); |
| 238 aura::client::SetFocusClient(root_window_, NULL); |
| 237 instance = NULL; | 239 instance = NULL; |
| 238 } | 240 } |
| 239 | 241 |
| 240 void ScreenManagerImpl::Init() { | 242 void ScreenManagerImpl::Init() { |
| 243 wm::FocusController* focus_controller = |
| 244 new wm::FocusController(new AthenaFocusRules()); |
| 245 |
| 246 aura::client::SetFocusClient(root_window_, focus_controller); |
| 247 root_window_->AddPreTargetHandler(focus_controller); |
| 248 aura::client::SetActivationClient(root_window_, focus_controller); |
| 249 focus_client_.reset(focus_controller); |
| 250 |
| 241 // TODO(oshima): Move the background out from ScreenManager. | 251 // TODO(oshima): Move the background out from ScreenManager. |
| 242 root_window_->SetLayoutManager(new FillLayoutManager(root_window_)); | 252 root_window_->SetLayoutManager(new FillLayoutManager(root_window_)); |
| 243 background_window_ = | 253 background_window_ = |
| 244 CreateContainer(ContainerParams("AthenaBackground", CP_BACKGROUND)); | 254 CreateContainer(ContainerParams("AthenaBackground", CP_BACKGROUND)); |
| 245 | 255 |
| 246 background_window_->SetLayoutManager( | 256 background_window_->SetLayoutManager( |
| 247 new FillLayoutManager(background_window_)); | 257 new FillLayoutManager(background_window_)); |
| 248 background_controller_.reset(new BackgroundController(background_window_)); | 258 background_controller_.reset(new BackgroundController(background_window_)); |
| 249 | 259 |
| 250 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window_)); | 260 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window_)); |
| 251 accelerator_handler_.reset(new ScreenAcceleratorHandler(root_window_)); | 261 accelerator_handler_.reset(new ScreenAcceleratorHandler(root_window_)); |
| 252 } | 262 } |
| 253 | 263 |
| 254 void ScreenManagerImpl::SetWorkAreaInsets(const gfx::Insets& insets) { | |
| 255 delegate_->SetWorkAreaInsets(insets); | |
| 256 } | |
| 257 | |
| 258 aura::Window* ScreenManagerImpl::CreateDefaultContainer( | 264 aura::Window* ScreenManagerImpl::CreateDefaultContainer( |
| 259 const ContainerParams& params) { | 265 const ContainerParams& params) { |
| 260 aura::Window* container = CreateContainer(params); | 266 aura::Window* container = CreateContainer(params); |
| 261 window_tree_client_.reset(new AthenaWindowTreeClient(container)); | 267 window_tree_client_.reset(new AthenaWindowTreeClient(container)); |
| 262 aura::client::SetWindowTreeClient(root_window_, window_tree_client_.get()); | 268 aura::client::SetWindowTreeClient(root_window_, window_tree_client_.get()); |
| 263 | 269 |
| 264 screen_position_client_.reset(new AthenaScreenPositionClient()); | 270 screen_position_client_.reset(new AthenaScreenPositionClient()); |
| 265 aura::client::SetScreenPositionClient(root_window_, | 271 aura::client::SetScreenPositionClient(root_window_, |
| 266 screen_position_client_.get()); | 272 screen_position_client_.get()); |
| 267 | 273 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 | 364 |
| 359 ScreenManager::ContainerParams::ContainerParams(const std::string& n, | 365 ScreenManager::ContainerParams::ContainerParams(const std::string& n, |
| 360 int priority) | 366 int priority) |
| 361 : name(n), | 367 : name(n), |
| 362 can_activate_children(false), | 368 can_activate_children(false), |
| 363 grab_inputs(false), | 369 grab_inputs(false), |
| 364 z_order_priority(priority) { | 370 z_order_priority(priority) { |
| 365 } | 371 } |
| 366 | 372 |
| 367 // static | 373 // static |
| 368 ScreenManager* ScreenManager::Create(ScreenManagerDelegate* delegate, | 374 ScreenManager* ScreenManager::Create(aura::Window* root_window) { |
| 369 aura::Window* root_window) { | 375 (new ScreenManagerImpl(root_window))->Init(); |
| 370 (new ScreenManagerImpl(delegate, root_window))->Init(); | |
| 371 DCHECK(instance); | 376 DCHECK(instance); |
| 372 return instance; | 377 return instance; |
| 373 } | 378 } |
| 374 | 379 |
| 375 // static | 380 // static |
| 376 ScreenManager* ScreenManager::Get() { | 381 ScreenManager* ScreenManager::Get() { |
| 377 DCHECK(instance); | 382 DCHECK(instance); |
| 378 return instance; | 383 return instance; |
| 379 } | 384 } |
| 380 | 385 |
| 381 // static | 386 // static |
| 382 void ScreenManager::Shutdown() { | 387 void ScreenManager::Shutdown() { |
| 383 DCHECK(instance); | 388 DCHECK(instance); |
| 384 delete instance; | 389 delete instance; |
| 385 DCHECK(!instance); | 390 DCHECK(!instance); |
| 386 } | 391 } |
| 387 | 392 |
| 388 // static | |
| 389 wm::FocusRules* ScreenManager::CreateFocusRules() { | |
| 390 return new AthenaFocusRules(); | |
| 391 } | |
| 392 | |
| 393 } // namespace athena | 393 } // namespace athena |
| OLD | NEW |