OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "athena/screen/public/screen_manager.h" |
| 6 |
| 7 #include "athena/screen/background_controller.h" |
| 8 #include "base/logging.h" |
| 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "ui/aura/layout_manager.h" |
| 11 #include "ui/aura/window.h" |
| 12 |
| 13 namespace athena { |
| 14 namespace { |
| 15 |
| 16 class FillLayoutManager : public aura::LayoutManager { |
| 17 public: |
| 18 FillLayoutManager(aura::Window* container) : container_(container) { |
| 19 DCHECK(container_); |
| 20 } |
| 21 |
| 22 // aura::LayoutManager: |
| 23 virtual void OnWindowResized() OVERRIDE { |
| 24 gfx::Rect full_bounds = gfx::Rect(container_->bounds().size()); |
| 25 |
| 26 for (aura::Window::Windows::const_iterator iter = |
| 27 container_->children().begin(); |
| 28 iter != container_->children().end(); |
| 29 ++iter) { |
| 30 SetChildBoundsDirect(*iter, full_bounds); |
| 31 } |
| 32 } |
| 33 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { |
| 34 SetChildBoundsDirect(child, (gfx::Rect(container_->bounds().size()))); |
| 35 } |
| 36 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
| 37 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} |
| 38 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 39 bool visible) OVERRIDE {} |
| 40 virtual void SetChildBounds(aura::Window* child, |
| 41 const gfx::Rect& requested_bounds) OVERRIDE { |
| 42 // Ignore SetBounds request. |
| 43 } |
| 44 |
| 45 private: |
| 46 aura::Window* container_; |
| 47 }; |
| 48 |
| 49 aura::Window* CreateContainer(aura::Window* parent, const std::string& name) { |
| 50 aura::Window* container = new aura::Window(NULL); |
| 51 container->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
| 52 container->SetName(name); |
| 53 parent->AddChild(container); |
| 54 container->Show(); |
| 55 return container; |
| 56 } |
| 57 |
| 58 class ScreenManagerImpl : public ScreenManager { |
| 59 public: |
| 60 explicit ScreenManagerImpl(aura::Window* root); |
| 61 virtual ~ScreenManagerImpl(); |
| 62 |
| 63 virtual aura::Window* GetContainerWindow() OVERRIDE { return container_; } |
| 64 virtual aura::Window* GetContext() OVERRIDE { return root_window_; } |
| 65 virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE; |
| 66 |
| 67 void Init(); |
| 68 |
| 69 private: |
| 70 aura::Window* root_window_; |
| 71 aura::Window* container_; |
| 72 aura::Window* background_window_; |
| 73 |
| 74 scoped_ptr<BackgroundController> background_controller_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl); |
| 77 }; |
| 78 |
| 79 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { |
| 80 background_controller_->SetImage(image); |
| 81 } |
| 82 |
| 83 void ScreenManagerImpl::Init() { |
| 84 root_window_->SetLayoutManager(new FillLayoutManager(root_window_)); |
| 85 background_window_ = CreateContainer(root_window_, "background"); |
| 86 background_window_->SetLayoutManager( |
| 87 new FillLayoutManager(background_window_)); |
| 88 background_controller_.reset(new BackgroundController(background_window_)); |
| 89 container_ = CreateContainer(root_window_, "container"); |
| 90 } |
| 91 |
| 92 ScreenManagerImpl* instance = NULL; |
| 93 |
| 94 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root) |
| 95 : root_window_(root) { |
| 96 DCHECK(root_window_); |
| 97 DCHECK(!instance); |
| 98 instance = this; |
| 99 } |
| 100 |
| 101 ScreenManagerImpl::~ScreenManagerImpl() { |
| 102 instance = NULL; |
| 103 } |
| 104 |
| 105 } // namespace |
| 106 |
| 107 // static |
| 108 ScreenManager* ScreenManager::Get() { |
| 109 DCHECK(instance); |
| 110 return instance; |
| 111 } |
| 112 |
| 113 // static |
| 114 ScreenManager* ScreenManager::Create(aura::Window* root) { |
| 115 new ScreenManagerImpl(root); |
| 116 instance->Init(); |
| 117 return instance; |
| 118 } |
| 119 |
| 120 // static |
| 121 void ScreenManager::Shutdown() { |
| 122 DCHECK(instance); |
| 123 delete instance; |
| 124 DCHECK(!instance); |
| 125 } |
| 126 |
| 127 } // namespace athena |
OLD | NEW |