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/client/window_tree_client.h" |
| 11 #include "ui/aura/layout_manager.h" |
| 12 #include "ui/aura/window.h" |
| 13 |
| 14 namespace athena { |
| 15 namespace { |
| 16 |
| 17 ScreenManager* instance = NULL; |
| 18 |
| 19 // TODO(oshima): There seems to be a couple of private implementation which does |
| 20 // the same. |
| 21 // Consider consolidating and reuse it. |
| 22 class FillLayoutManager : public aura::LayoutManager { |
| 23 public: |
| 24 explicit FillLayoutManager(aura::Window* container) : container_(container) { |
| 25 DCHECK(container_); |
| 26 } |
| 27 |
| 28 // aura::LayoutManager: |
| 29 virtual void OnWindowResized() OVERRIDE { |
| 30 gfx::Rect full_bounds = gfx::Rect(container_->bounds().size()); |
| 31 for (aura::Window::Windows::const_iterator iter = |
| 32 container_->children().begin(); |
| 33 iter != container_->children().end(); |
| 34 ++iter) { |
| 35 SetChildBoundsDirect(*iter, full_bounds); |
| 36 } |
| 37 } |
| 38 virtual void OnWindowAddedToLayout(aura::Window* child) OVERRIDE { |
| 39 SetChildBoundsDirect(child, (gfx::Rect(container_->bounds().size()))); |
| 40 } |
| 41 virtual void OnWillRemoveWindowFromLayout(aura::Window* child) OVERRIDE {} |
| 42 virtual void OnWindowRemovedFromLayout(aura::Window* child) OVERRIDE {} |
| 43 virtual void OnChildWindowVisibilityChanged(aura::Window* child, |
| 44 bool visible) OVERRIDE {} |
| 45 virtual void SetChildBounds(aura::Window* child, |
| 46 const gfx::Rect& requested_bounds) OVERRIDE { |
| 47 // Ignore SetBounds request. |
| 48 } |
| 49 |
| 50 private: |
| 51 aura::Window* container_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(FillLayoutManager); |
| 54 }; |
| 55 |
| 56 class AthenaWindowTreeClient : public aura::client::WindowTreeClient { |
| 57 public: |
| 58 explicit AthenaWindowTreeClient(aura::Window* container) |
| 59 : container_(container) {} |
| 60 |
| 61 private: |
| 62 virtual ~AthenaWindowTreeClient() {} |
| 63 |
| 64 // aura::client::WindowTreeClient: |
| 65 virtual aura::Window* GetDefaultParent(aura::Window* context, |
| 66 aura::Window* window, |
| 67 const gfx::Rect& bounds) OVERRIDE { |
| 68 return container_; |
| 69 } |
| 70 |
| 71 aura::Window* container_; |
| 72 |
| 73 DISALLOW_COPY_AND_ASSIGN(AthenaWindowTreeClient); |
| 74 }; |
| 75 |
| 76 aura::Window* CreateContainer(aura::Window* parent, const std::string& name) { |
| 77 aura::Window* container = new aura::Window(NULL); |
| 78 container->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
| 79 container->SetName(name); |
| 80 parent->AddChild(container); |
| 81 container->Show(); |
| 82 return container; |
| 83 } |
| 84 |
| 85 class ScreenManagerImpl : public ScreenManager { |
| 86 public: |
| 87 explicit ScreenManagerImpl(aura::Window* root_window); |
| 88 virtual ~ScreenManagerImpl(); |
| 89 |
| 90 void Init(); |
| 91 |
| 92 private: |
| 93 // Screenmanager: |
| 94 virtual aura::Window* GetContainerWindow() OVERRIDE { return container_; } |
| 95 virtual aura::Window* GetContext() OVERRIDE { return root_window_; } |
| 96 virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE; |
| 97 |
| 98 aura::Window* root_window_; |
| 99 // A container used for apps/web windows. |
| 100 aura::Window* container_; |
| 101 aura::Window* background_window_; |
| 102 scoped_ptr<BackgroundController> background_controller_; |
| 103 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_; |
| 104 |
| 105 DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl); |
| 106 }; |
| 107 |
| 108 void ScreenManagerImpl::Init() { |
| 109 root_window_->SetLayoutManager(new FillLayoutManager(root_window_)); |
| 110 background_window_ = CreateContainer(root_window_, "AthenaBackground"); |
| 111 background_window_->SetLayoutManager( |
| 112 new FillLayoutManager(background_window_)); |
| 113 background_controller_.reset(new BackgroundController(background_window_)); |
| 114 container_ = CreateContainer(root_window_, "AthenaContainer"); |
| 115 |
| 116 window_tree_client_.reset(new AthenaWindowTreeClient(container_)); |
| 117 aura::client::SetWindowTreeClient(root_window_, window_tree_client_.get()); |
| 118 } |
| 119 |
| 120 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { |
| 121 background_controller_->SetImage(image); |
| 122 } |
| 123 |
| 124 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window) |
| 125 : root_window_(root_window) { |
| 126 DCHECK(root_window_); |
| 127 DCHECK(!instance); |
| 128 instance = this; |
| 129 } |
| 130 |
| 131 ScreenManagerImpl::~ScreenManagerImpl() { |
| 132 aura::client::SetWindowTreeClient(root_window_, NULL); |
| 133 instance = NULL; |
| 134 } |
| 135 |
| 136 } // namespace |
| 137 |
| 138 // static |
| 139 ScreenManager* ScreenManager::Create(aura::Window* root_window) { |
| 140 (new ScreenManagerImpl(root_window))->Init(); |
| 141 DCHECK(instance); |
| 142 return instance; |
| 143 } |
| 144 |
| 145 // static |
| 146 ScreenManager* ScreenManager::Get() { |
| 147 DCHECK(instance); |
| 148 return instance; |
| 149 } |
| 150 |
| 151 // static |
| 152 void ScreenManager::Shutdown() { |
| 153 DCHECK(instance); |
| 154 delete instance; |
| 155 DCHECK(!instance); |
| 156 } |
| 157 |
| 158 } // namespace athena |
OLD | NEW |