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/input/public/accelerator_manager.h" | 7 #include "athena/input/public/accelerator_manager.h" |
8 #include "athena/screen/background_controller.h" | 8 #include "athena/screen/background_controller.h" |
9 #include "athena/screen/screen_accelerator_handler.h" | 9 #include "athena/screen/screen_accelerator_handler.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
12 #include "ui/aura/client/screen_position_client.h" | |
12 #include "ui/aura/client/window_tree_client.h" | 13 #include "ui/aura/client/window_tree_client.h" |
13 #include "ui/aura/layout_manager.h" | 14 #include "ui/aura/layout_manager.h" |
14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
16 #include "ui/aura/window_tree_host.h" | |
15 #include "ui/wm/core/capture_controller.h" | 17 #include "ui/wm/core/capture_controller.h" |
16 | 18 |
17 namespace athena { | 19 namespace athena { |
18 namespace { | 20 namespace { |
19 | 21 |
20 ScreenManager* instance = NULL; | 22 ScreenManager* instance = NULL; |
21 | 23 |
22 // TODO(oshima): There seems to be a couple of private implementation which does | 24 // TODO(oshima): There seems to be a couple of private implementation which does |
23 // the same. | 25 // the same. |
24 // Consider consolidating and reuse it. | 26 // Consider consolidating and reuse it. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 aura::Window* window, | 71 aura::Window* window, |
70 const gfx::Rect& bounds) OVERRIDE { | 72 const gfx::Rect& bounds) OVERRIDE { |
71 return container_; | 73 return container_; |
72 } | 74 } |
73 | 75 |
74 aura::Window* container_; | 76 aura::Window* container_; |
75 | 77 |
76 DISALLOW_COPY_AND_ASSIGN(AthenaWindowTreeClient); | 78 DISALLOW_COPY_AND_ASSIGN(AthenaWindowTreeClient); |
77 }; | 79 }; |
78 | 80 |
81 class AthenaScreenPositionClient : public aura::client::ScreenPositionClient { | |
82 public: | |
83 AthenaScreenPositionClient() { | |
84 } | |
85 virtual ~AthenaScreenPositionClient() { | |
86 } | |
87 | |
88 private: | |
89 // aura::client::ScreenPositionClient: | |
90 virtual void ConvertPointToScreen(const aura::Window* window, | |
91 gfx::Point* point) OVERRIDE { | |
92 const aura::Window* root = window->GetRootWindow(); | |
93 aura::Window::ConvertPointToTarget(window, root, point); | |
94 gfx::Point origin = root->GetHost()->GetBounds().origin(); | |
95 point->Offset(origin.x(), origin.y()); | |
oshima
2014/06/19 17:37:27
Looks like this convert to the native coords, inst
sadrul
2014/06/19 17:59:00
The doc for this is a bit lacking; but the current
sadrul
2014/06/19 18:17:44
Done.
| |
96 } | |
97 | |
98 virtual void ConvertPointFromScreen(const aura::Window* window, | |
99 gfx::Point* point) OVERRIDE { | |
100 const aura::Window* root = window->GetRootWindow(); | |
101 gfx::Point origin = root->GetHost()->GetBounds().origin(); | |
102 point->Offset(-origin.x(), -origin.y()); | |
103 aura::Window::ConvertPointToTarget(root, window, point); | |
104 } | |
105 | |
106 virtual void ConvertHostPointToScreen(aura::Window* window, | |
107 gfx::Point* point) OVERRIDE { | |
108 aura::Window* root = window->GetRootWindow(); | |
109 ConvertPointToScreen(root, point); | |
110 } | |
111 | |
112 virtual void SetBounds(aura::Window* window, | |
113 const gfx::Rect& bounds, | |
114 const gfx::Display& display) OVERRIDE { | |
115 window->SetBounds(bounds); | |
116 } | |
117 | |
118 DISALLOW_COPY_AND_ASSIGN(AthenaScreenPositionClient); | |
119 }; | |
120 | |
79 aura::Window* CreateContainerInternal(aura::Window* parent, | 121 aura::Window* CreateContainerInternal(aura::Window* parent, |
80 const std::string& name) { | 122 const std::string& name) { |
81 aura::Window* container = new aura::Window(NULL); | 123 aura::Window* container = new aura::Window(NULL); |
82 container->Init(aura::WINDOW_LAYER_NOT_DRAWN); | 124 container->Init(aura::WINDOW_LAYER_NOT_DRAWN); |
83 container->SetName(name); | 125 container->SetName(name); |
84 parent->AddChild(container); | 126 parent->AddChild(container); |
85 container->Show(); | 127 container->Show(); |
86 return container; | 128 return container; |
87 } | 129 } |
88 | 130 |
(...skipping 12 matching lines...) Expand all Loading... | |
101 virtual aura::Window* GetContext() OVERRIDE { return root_window_; } | 143 virtual aura::Window* GetContext() OVERRIDE { return root_window_; } |
102 virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE; | 144 virtual void SetBackgroundImage(const gfx::ImageSkia& image) OVERRIDE; |
103 | 145 |
104 aura::Window* root_window_; | 146 aura::Window* root_window_; |
105 aura::Window* background_window_; | 147 aura::Window* background_window_; |
106 | 148 |
107 scoped_ptr<BackgroundController> background_controller_; | 149 scoped_ptr<BackgroundController> background_controller_; |
108 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_; | 150 scoped_ptr<aura::client::WindowTreeClient> window_tree_client_; |
109 scoped_ptr<AcceleratorHandler> accelerator_handler_; | 151 scoped_ptr<AcceleratorHandler> accelerator_handler_; |
110 scoped_ptr< ::wm::ScopedCaptureClient> capture_client_; | 152 scoped_ptr< ::wm::ScopedCaptureClient> capture_client_; |
153 scoped_ptr<aura::client::ScreenPositionClient> screen_position_client_; | |
111 | 154 |
112 DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl); | 155 DISALLOW_COPY_AND_ASSIGN(ScreenManagerImpl); |
113 }; | 156 }; |
114 | 157 |
115 void ScreenManagerImpl::Init() { | 158 void ScreenManagerImpl::Init() { |
116 root_window_->SetLayoutManager(new FillLayoutManager(root_window_)); | 159 root_window_->SetLayoutManager(new FillLayoutManager(root_window_)); |
117 background_window_ = | 160 background_window_ = |
118 CreateContainerInternal(root_window_, "AthenaBackground"); | 161 CreateContainerInternal(root_window_, "AthenaBackground"); |
119 background_window_->SetLayoutManager( | 162 background_window_->SetLayoutManager( |
120 new FillLayoutManager(background_window_)); | 163 new FillLayoutManager(background_window_)); |
121 background_controller_.reset(new BackgroundController(background_window_)); | 164 background_controller_.reset(new BackgroundController(background_window_)); |
122 | 165 |
123 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window_)); | 166 capture_client_.reset(new ::wm::ScopedCaptureClient(root_window_)); |
124 accelerator_handler_.reset(new ScreenAcceleratorHandler(root_window_)); | 167 accelerator_handler_.reset(new ScreenAcceleratorHandler(root_window_)); |
125 } | 168 } |
126 | 169 |
127 aura::Window* ScreenManagerImpl::CreateDefaultContainer( | 170 aura::Window* ScreenManagerImpl::CreateDefaultContainer( |
128 const std::string& name) { | 171 const std::string& name) { |
129 aura::Window* container = CreateContainerInternal(root_window_, name); | 172 aura::Window* container = CreateContainerInternal(root_window_, name); |
130 window_tree_client_.reset(new AthenaWindowTreeClient(container)); | 173 window_tree_client_.reset(new AthenaWindowTreeClient(container)); |
131 aura::client::SetWindowTreeClient(root_window_, window_tree_client_.get()); | 174 aura::client::SetWindowTreeClient(root_window_, window_tree_client_.get()); |
175 | |
176 screen_position_client_.reset(new AthenaScreenPositionClient()); | |
177 aura::client::SetScreenPositionClient(root_window_, | |
178 screen_position_client_.get()); | |
179 | |
132 return container; | 180 return container; |
133 } | 181 } |
134 | 182 |
135 aura::Window* ScreenManagerImpl::CreateContainer(const std::string& name) { | 183 aura::Window* ScreenManagerImpl::CreateContainer(const std::string& name) { |
136 return CreateContainerInternal(root_window_, name); | 184 return CreateContainerInternal(root_window_, name); |
137 } | 185 } |
138 | 186 |
139 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { | 187 void ScreenManagerImpl::SetBackgroundImage(const gfx::ImageSkia& image) { |
140 background_controller_->SetImage(image); | 188 background_controller_->SetImage(image); |
141 } | 189 } |
142 | 190 |
143 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window) | 191 ScreenManagerImpl::ScreenManagerImpl(aura::Window* root_window) |
144 : root_window_(root_window) { | 192 : root_window_(root_window) { |
145 DCHECK(root_window_); | 193 DCHECK(root_window_); |
146 DCHECK(!instance); | 194 DCHECK(!instance); |
147 instance = this; | 195 instance = this; |
148 } | 196 } |
149 | 197 |
150 ScreenManagerImpl::~ScreenManagerImpl() { | 198 ScreenManagerImpl::~ScreenManagerImpl() { |
199 aura::client::SetScreenPositionClient(root_window_, NULL); | |
151 aura::client::SetWindowTreeClient(root_window_, NULL); | 200 aura::client::SetWindowTreeClient(root_window_, NULL); |
152 instance = NULL; | 201 instance = NULL; |
153 } | 202 } |
154 | 203 |
155 } // namespace | 204 } // namespace |
156 | 205 |
157 // static | 206 // static |
158 ScreenManager* ScreenManager::Create(aura::Window* root_window) { | 207 ScreenManager* ScreenManager::Create(aura::Window* root_window) { |
159 (new ScreenManagerImpl(root_window))->Init(); | 208 (new ScreenManagerImpl(root_window))->Init(); |
160 DCHECK(instance); | 209 DCHECK(instance); |
161 return instance; | 210 return instance; |
162 } | 211 } |
163 | 212 |
164 // static | 213 // static |
165 ScreenManager* ScreenManager::Get() { | 214 ScreenManager* ScreenManager::Get() { |
166 DCHECK(instance); | 215 DCHECK(instance); |
167 return instance; | 216 return instance; |
168 } | 217 } |
169 | 218 |
170 // static | 219 // static |
171 void ScreenManager::Shutdown() { | 220 void ScreenManager::Shutdown() { |
172 DCHECK(instance); | 221 DCHECK(instance); |
173 delete instance; | 222 delete instance; |
174 DCHECK(!instance); | 223 DCHECK(!instance); |
175 } | 224 } |
176 | 225 |
177 } // namespace athena | 226 } // namespace athena |
OLD | NEW |