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/fill_layout_manager.h" | 7 #include "athena/common/fill_layout_manager.h" |
8 #include "athena/input/public/accelerator_manager.h" | 8 #include "athena/input/public/accelerator_manager.h" |
9 #include "athena/screen/background_controller.h" | 9 #include "athena/screen/background_controller.h" |
10 #include "athena/screen/screen_accelerator_handler.h" | 10 #include "athena/screen/screen_accelerator_handler.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "ui/aura/client/screen_position_client.h" | 13 #include "ui/aura/client/screen_position_client.h" |
14 #include "ui/aura/client/window_tree_client.h" | 14 #include "ui/aura/client/window_tree_client.h" |
15 #include "ui/aura/layout_manager.h" | 15 #include "ui/aura/layout_manager.h" |
16 #include "ui/aura/window.h" | 16 #include "ui/aura/window.h" |
| 17 #include "ui/aura/window_property.h" |
17 #include "ui/aura/window_tree_host.h" | 18 #include "ui/aura/window_tree_host.h" |
| 19 #include "ui/wm/core/base_focus_rules.h" |
18 #include "ui/wm/core/capture_controller.h" | 20 #include "ui/wm/core/capture_controller.h" |
19 | 21 |
20 namespace athena { | 22 namespace athena { |
21 namespace { | 23 namespace { |
22 | 24 |
| 25 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ScreenManager::ContainerParams, |
| 26 kContainerParamsKey, |
| 27 NULL); |
| 28 |
23 ScreenManager* instance = NULL; | 29 ScreenManager* instance = NULL; |
24 | 30 |
| 31 class AthenaFocusRules : public wm::BaseFocusRules { |
| 32 public: |
| 33 AthenaFocusRules() {} |
| 34 virtual ~AthenaFocusRules() {} |
| 35 |
| 36 // wm::BaseFocusRules: |
| 37 virtual bool SupportsChildActivation(aura::Window* window) const OVERRIDE { |
| 38 ScreenManager::ContainerParams* params = |
| 39 window->GetProperty(kContainerParamsKey); |
| 40 return params && params->can_activate_children; |
| 41 } |
| 42 |
| 43 private: |
| 44 DISALLOW_COPY_AND_ASSIGN(AthenaFocusRules); |
| 45 }; |
| 46 |
25 class AthenaWindowTreeClient : public aura::client::WindowTreeClient { | 47 class AthenaWindowTreeClient : public aura::client::WindowTreeClient { |
26 public: | 48 public: |
27 explicit AthenaWindowTreeClient(aura::Window* container) | 49 explicit AthenaWindowTreeClient(aura::Window* container) |
28 : container_(container) {} | 50 : container_(container) {} |
29 | 51 |
30 private: | 52 private: |
31 virtual ~AthenaWindowTreeClient() {} | 53 virtual ~AthenaWindowTreeClient() {} |
32 | 54 |
33 // aura::client::WindowTreeClient: | 55 // aura::client::WindowTreeClient: |
34 virtual aura::Window* GetDefaultParent(aura::Window* context, | 56 virtual aura::Window* GetDefaultParent(aura::Window* context, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 93 |
72 virtual void SetBounds(aura::Window* window, | 94 virtual void SetBounds(aura::Window* window, |
73 const gfx::Rect& bounds, | 95 const gfx::Rect& bounds, |
74 const gfx::Display& display) OVERRIDE { | 96 const gfx::Display& display) OVERRIDE { |
75 window->SetBounds(bounds); | 97 window->SetBounds(bounds); |
76 } | 98 } |
77 | 99 |
78 DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient); | 100 DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient); |
79 }; | 101 }; |
80 | 102 |
81 aura::Window* CreateContainerInternal(aura::Window* parent, | |
82 const std::string& name) { | |
83 aura::Window* container = new aura::Window(NULL); | |
84 container->Init(aura::WINDOW_LAYER_NOT_DRAWN); | |
85 container->SetName(name); | |
86 parent->AddChild(container); | |
87 container->Show(); | |
88 return container; | |
89 } | |
90 | |
91 class ScreenManagerImpl : public ScreenManager { | 103 class ScreenManagerImpl : public ScreenManager { |
92 public: | 104 public: |
93 explicit ScreenManagerImpl(aura::Window* root_window); | 105 explicit ScreenManagerImpl(aura::Window* root_window); |
94 virtual ~ScreenManagerImpl(); | 106 virtual ~ScreenManagerImpl(); |
95 | 107 |
96 void Init(); | 108 void Init(); |
97 | 109 |
98 private: | 110 private: |
99 // ScreenManager: | 111 // ScreenManager: |
100 virtual aura::Window* CreateDefaultContainer( | 112 virtual aura::Window* CreateDefaultContainer( |
101 const std::string& name) OVERRIDE; | 113 const ContainerParams& params) OVERRIDE; |
102 virtual aura::Window* CreateContainer(const std::string& name) OVERRIDE; | 114 virtual aura::Window* CreateContainer(const ContainerParams& params) OVERRIDE; |
103 virtual aura::Window* GetContext() OVERRIDE { return root_window_; } | 115 virtual aura::Window* GetContext() OVERRIDE { return root_window_; } |
104 virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE; | 116 virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE; |
105 | 117 |
106 aura::Window* root_window_; | 118 aura::Window* root_window_; |
107 aura::Window* background_window_; | 119 aura::Window* background_window_; |
108 | 120 |
109 scoped_ptr<BackgroundController> background_controller_; | 121 scoped_ptr<BackgroundController> background_controller_; |
110 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_; | 122 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_; |
111 scoped_ptr<AcceleratorHandler> accelerator_handler_; | 123 scoped_ptr<AcceleratorHandler> accelerator_handler_; |
112 scoped_ptr< ::wm::ScopedCaptureClient> capture_client_; | 124 scoped_ptr< ::wm::ScopedCaptureClient> capture_client_; |
113 scoped_ptr<aura::client::ScreenPositionClient> screen_position_client_; | 125 scoped_ptr<aura::client::ScreenPositionClient> screen_position_client_; |
114 | 126 |
115 DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl); | 127 DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl); |
116 }; | 128 }; |
117 | 129 |
118 void ScreenManagerImpl::Init() { | 130 void ScreenManagerImpl::Init() { |
| 131 // TODO(oshima): Move the background out from ScreenManager. |
119 root_window_->SetLayoutManager(new FillLayoutManager(root_window_)); | 132 root_window_->SetLayoutManager(new FillLayoutManager(root_window_)); |
120 background_window_ = | 133 background_window_ = CreateContainer(ContainerParams("AthenaBackground")); |
121 CreateContainerInternal(root_window_, "AthenaBackground"); | 134 |
122 background_window_->SetLayoutManager( | 135 background_window_->SetLayoutManager( |
123 new FillLayoutManager(background_window_)); | 136 new FillLayoutManager(background_window_)); |
124 background_controller_.reset(new BackgroundController(background_window_)); | 137 background_controller_.reset(new BackgroundController(background_window_)); |
125 | 138 |
126 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window_)); | 139 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window_)); |
127 accelerator_handler_.reset(new ScreenAcceleratorHandler(root_window_)); | 140 accelerator_handler_.reset(new ScreenAcceleratorHandler(root_window_)); |
128 } | 141 } |
129 | 142 |
130 aura::Window* ScreenManagerImpl::CreateDefaultContainer( | 143 aura::Window* ScreenManagerImpl::CreateDefaultContainer( |
131 const std::string& name) { | 144 const ContainerParams& params) { |
132 aura::Window* container = CreateContainerInternal(root_window_, name); | 145 aura::Window* container = CreateContainer(params); |
133 window_tree_client_.reset(new AthenaWindowTreeClient(container)); | 146 window_tree_client_.reset(new AthenaWindowTreeClient(container)); |
134 aura::client::SetWindowTreeClient(root_window_, window_tree_client_.get()); | 147 aura::client::SetWindowTreeClient(root_window_, window_tree_client_.get()); |
135 | 148 |
136 screen_position_client_.reset(new AthenaScreenPositionClient()); | 149 screen_position_client_.reset(new AthenaScreenPositionClient()); |
137 aura::client::SetScreenPositionClient(root_window_, | 150 aura::client::SetScreenPositionClient(root_window_, |
138 screen_position_client_.get()); | 151 screen_position_client_.get()); |
139 | 152 |
140 return container; | 153 return container; |
141 } | 154 } |
142 | 155 |
143 aura::Window* ScreenManagerImpl::CreateContainer(const std::string& name) { | 156 aura::Window* ScreenManagerImpl::CreateContainer( |
144 return CreateContainerInternal(root_window_, name); | 157 const ContainerParams& params) { |
| 158 aura::Window* container = new aura::Window(NULL); |
| 159 container->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
| 160 container->SetName(params.name); |
| 161 root_window_->AddChild(container); |
| 162 container->Show(); |
| 163 container->SetProperty(kContainerParamsKey, new ContainerParams(params)); |
| 164 return container; |
145 } | 165 } |
146 | 166 |
147 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { | 167 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { |
148 background_controller_->SetImage(image); | 168 background_controller_->SetImage(image); |
149 } | 169 } |
150 | 170 |
151 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window) | 171 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window) |
152 : root_window_(root_window) { | 172 : root_window_(root_window) { |
153 DCHECK(root_window_); | 173 DCHECK(root_window_); |
154 DCHECK(!instance); | 174 DCHECK(!instance); |
155 instance = this; | 175 instance = this; |
156 } | 176 } |
157 | 177 |
158 ScreenManagerImpl::~ScreenManagerImpl() { | 178 ScreenManagerImpl::~ScreenManagerImpl() { |
159 aura::client::SetScreenPositionClient(root_window_, NULL); | 179 aura::client::SetScreenPositionClient(root_window_, NULL); |
160 aura::client::SetWindowTreeClient(root_window_, NULL); | 180 aura::client::SetWindowTreeClient(root_window_, NULL); |
161 instance = NULL; | 181 instance = NULL; |
162 } | 182 } |
163 | 183 |
164 } // namespace | 184 } // namespace |
165 | 185 |
| 186 ScreenManager::ContainerParams::ContainerParams(const std::string& n) |
| 187 : name(n), |
| 188 can_activate_children(false) { |
| 189 } |
| 190 |
166 // static | 191 // static |
167 ScreenManager* ScreenManager::Create(aura::Window* root_window) { | 192 ScreenManager* ScreenManager::Create(aura::Window* root_window) { |
168 (new ScreenManagerImpl(root_window))->Init(); | 193 (new ScreenManagerImpl(root_window))->Init(); |
169 DCHECK(instance); | 194 DCHECK(instance); |
170 return instance; | 195 return instance; |
171 } | 196 } |
172 | 197 |
173 // static | 198 // static |
174 ScreenManager* ScreenManager::Get() { | 199 ScreenManager* ScreenManager::Get() { |
175 DCHECK(instance); | 200 DCHECK(instance); |
176 return instance; | 201 return instance; |
177 } | 202 } |
178 | 203 |
179 // static | 204 // static |
180 void ScreenManager::Shutdown() { | 205 void ScreenManager::Shutdown() { |
181 DCHECK(instance); | 206 DCHECK(instance); |
182 delete instance; | 207 delete instance; |
183 DCHECK(!instance); | 208 DCHECK(!instance); |
184 } | 209 } |
185 | 210 |
| 211 // static |
| 212 wm::FocusRules* ScreenManager::CreateFocusRules() { |
| 213 return new AthenaFocusRules(); |
| 214 } |
| 215 |
186 } // namespace athena | 216 } // namespace athena |
OLD | NEW |