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