OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ui/views/mus/native_widget_mus.h" | 5 #include "ui/views/mus/native_widget_mus.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/thread_task_runner_handle.h" | 8 #include "base/thread_task_runner_handle.h" |
9 #include "components/mus/public/cpp/property_type_converters.h" | 9 #include "components/mus/public/cpp/property_type_converters.h" |
10 #include "components/mus/public/cpp/window.h" | 10 #include "components/mus/public/cpp/window.h" |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "ui/native_theme/native_theme_aura.h" | 23 #include "ui/native_theme/native_theme_aura.h" |
24 #include "ui/views/mus/platform_window_mus.h" | 24 #include "ui/views/mus/platform_window_mus.h" |
25 #include "ui/views/mus/surface_context_factory.h" | 25 #include "ui/views/mus/surface_context_factory.h" |
26 #include "ui/views/mus/window_manager_constants_converters.h" | 26 #include "ui/views/mus/window_manager_constants_converters.h" |
27 #include "ui/views/mus/window_manager_frame_values.h" | 27 #include "ui/views/mus/window_manager_frame_values.h" |
28 #include "ui/views/mus/window_tree_host_mus.h" | 28 #include "ui/views/mus/window_tree_host_mus.h" |
29 #include "ui/views/widget/widget_delegate.h" | 29 #include "ui/views/widget/widget_delegate.h" |
30 #include "ui/views/window/custom_frame_view.h" | 30 #include "ui/views/window/custom_frame_view.h" |
31 #include "ui/wm/core/base_focus_rules.h" | 31 #include "ui/wm/core/base_focus_rules.h" |
32 #include "ui/wm/core/capture_controller.h" | 32 #include "ui/wm/core/capture_controller.h" |
33 #include "ui/wm/core/default_screen_position_client.h" | |
34 #include "ui/wm/core/focus_controller.h" | 33 #include "ui/wm/core/focus_controller.h" |
35 | 34 |
36 DECLARE_WINDOW_PROPERTY_TYPE(mus::Window*); | 35 DECLARE_WINDOW_PROPERTY_TYPE(mus::Window*); |
37 | 36 |
38 namespace views { | 37 namespace views { |
39 namespace { | 38 namespace { |
40 | 39 |
41 DEFINE_WINDOW_PROPERTY_KEY(mus::Window*, kMusWindow, nullptr); | 40 DEFINE_WINDOW_PROPERTY_KEY(mus::Window*, kMusWindow, nullptr); |
42 | 41 |
43 MUS_DEFINE_WINDOW_PROPERTY_KEY(NativeWidgetMus*, kNativeWidgetMusKey, nullptr); | 42 MUS_DEFINE_WINDOW_PROPERTY_KEY(NativeWidgetMus*, kNativeWidgetMusKey, nullptr); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } // namespace | 172 } // namespace |
174 | 173 |
175 //////////////////////////////////////////////////////////////////////////////// | 174 //////////////////////////////////////////////////////////////////////////////// |
176 // NativeWidgetMus, public: | 175 // NativeWidgetMus, public: |
177 | 176 |
178 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate, | 177 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate, |
179 mojo::Shell* shell, | 178 mojo::Shell* shell, |
180 mus::Window* window, | 179 mus::Window* window, |
181 mus::mojom::SurfaceType surface_type) | 180 mus::mojom::SurfaceType surface_type) |
182 : window_(window), | 181 : window_(window), |
| 182 shell_(shell), |
183 native_widget_delegate_(delegate), | 183 native_widget_delegate_(delegate), |
184 surface_type_(surface_type), | 184 surface_type_(surface_type), |
185 show_state_before_fullscreen_(ui::PLATFORM_WINDOW_STATE_UNKNOWN), | 185 show_state_before_fullscreen_(ui::PLATFORM_WINDOW_STATE_UNKNOWN), |
186 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), | 186 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET), |
187 content_(new aura::Window(this)), | 187 content_(new aura::Window(this)), |
188 close_widget_factory_(this) { | 188 close_widget_factory_(this) { |
189 // TODO(fsamuel): Figure out lifetime of |window_|. | 189 // TODO(fsamuel): Figure out lifetime of |window_|. |
190 aura::SetMusWindow(content_, window_); | 190 aura::SetMusWindow(content_, window_); |
191 | 191 |
192 window->SetLocalProperty(kNativeWidgetMusKey, this); | 192 window->SetLocalProperty(kNativeWidgetMusKey, this); |
193 // WindowTreeHost creates the compositor using the ContextFactory from | |
194 // aura::Env. Install |context_factory_| there so that |context_factory_| is | |
195 // picked up. | |
196 ui::ContextFactory* default_context_factory = | |
197 aura::Env::GetInstance()->context_factory(); | |
198 // For Chrome, we need the GpuProcessTransportFactory so that renderer and | |
199 // browser pixels are composited into a single backing | |
200 // SoftwareOutputDeviceMus. | |
201 if (!default_context_factory) { | |
202 context_factory_.reset( | |
203 new SurfaceContextFactory(shell, window_, surface_type_)); | |
204 aura::Env::GetInstance()->set_context_factory(context_factory_.get()); | |
205 } | |
206 window_tree_host_.reset(new WindowTreeHostMus(shell, this, window_)); | |
207 aura::Env::GetInstance()->set_context_factory(default_context_factory); | |
208 } | 193 } |
209 | 194 |
210 NativeWidgetMus::~NativeWidgetMus() { | 195 NativeWidgetMus::~NativeWidgetMus() { |
211 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 196 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
212 delete native_widget_delegate_; | 197 delete native_widget_delegate_; |
213 else | 198 else |
214 CloseNow(); | 199 CloseNow(); |
215 } | 200 } |
216 | 201 |
217 // static | 202 // static |
218 void NativeWidgetMus::NotifyFrameChanged( | 203 void NativeWidgetMus::NotifyFrameChanged( |
219 mus::WindowTreeConnection* connection) { | 204 mus::WindowTreeConnection* connection) { |
220 for (mus::Window* window : connection->GetRoots()) { | 205 for (mus::Window* window : connection->GetRoots()) { |
221 NativeWidgetMus* native_widget = | 206 NativeWidgetMus* native_widget = |
222 window->GetLocalProperty(kNativeWidgetMusKey); | 207 window->GetLocalProperty(kNativeWidgetMusKey); |
223 if (native_widget && native_widget->GetWidget()->non_client_view()) { | 208 if (native_widget && native_widget->GetWidget()->non_client_view()) { |
224 native_widget->GetWidget()->non_client_view()->Layout(); | 209 native_widget->GetWidget()->non_client_view()->Layout(); |
225 native_widget->GetWidget()->non_client_view()->SchedulePaint(); | 210 native_widget->GetWidget()->non_client_view()->SchedulePaint(); |
226 native_widget->UpdateClientArea(); | 211 native_widget->UpdateClientArea(); |
227 } | 212 } |
228 } | 213 } |
229 } | 214 } |
230 | 215 |
231 aura::Window* NativeWidgetMus::GetRootWindow() { | |
232 return window_tree_host_->window(); | |
233 } | |
234 | |
235 void NativeWidgetMus::OnPlatformWindowClosed() { | 216 void NativeWidgetMus::OnPlatformWindowClosed() { |
236 native_widget_delegate_->OnNativeWidgetDestroying(); | 217 native_widget_delegate_->OnNativeWidgetDestroying(); |
237 | 218 |
238 window_tree_client_.reset(); // Uses |content_|. | 219 window_tree_client_.reset(); // Uses |content_|. |
239 capture_client_.reset(); // Uses |content_|. | 220 capture_client_.reset(); // Uses |content_|. |
240 | 221 |
241 window_tree_host_->RemoveObserver(this); | 222 window_tree_host_->RemoveObserver(this); |
242 window_tree_host_.reset(); | 223 window_tree_host_.reset(); |
243 | 224 |
244 window_ = nullptr; | 225 window_ = nullptr; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
304 | 285 |
305 NonClientFrameView* NativeWidgetMus::CreateNonClientFrameView() { | 286 NonClientFrameView* NativeWidgetMus::CreateNonClientFrameView() { |
306 return new ClientSideNonClientFrameView(GetWidget()); | 287 return new ClientSideNonClientFrameView(GetWidget()); |
307 } | 288 } |
308 | 289 |
309 void NativeWidgetMus::InitNativeWidget(const Widget::InitParams& params) { | 290 void NativeWidgetMus::InitNativeWidget(const Widget::InitParams& params) { |
310 ownership_ = params.ownership; | 291 ownership_ = params.ownership; |
311 window_->SetCanFocus(params.activatable == | 292 window_->SetCanFocus(params.activatable == |
312 Widget::InitParams::ACTIVATABLE_YES); | 293 Widget::InitParams::ACTIVATABLE_YES); |
313 | 294 |
| 295 // WindowTreeHost creates the compositor using the ContextFactory from |
| 296 // aura::Env. Install |context_factory_| there so that |context_factory_| is |
| 297 // picked up. |
| 298 ui::ContextFactory* default_context_factory = |
| 299 aura::Env::GetInstance()->context_factory(); |
| 300 // For Chrome, we need the GpuProcessTransportFactory so that renderer and |
| 301 // browser pixels are composited into a single backing |
| 302 // SoftwareOutputDeviceMus. |
| 303 if (!default_context_factory) { |
| 304 if (!context_factory_) { |
| 305 context_factory_.reset(new SurfaceContextFactory(shell_, window_, |
| 306 surface_type_)); |
| 307 } |
| 308 aura::Env::GetInstance()->set_context_factory(context_factory_.get()); |
| 309 } |
| 310 window_tree_host_.reset(new WindowTreeHostMus(shell_, this, window_)); |
314 window_tree_host_->AddObserver(this); | 311 window_tree_host_->AddObserver(this); |
315 window_tree_host_->InitHost(); | 312 window_tree_host_->InitHost(); |
| 313 aura::Env::GetInstance()->set_context_factory(default_context_factory); |
316 window_tree_host_->window()->SetProperty(kMusWindow, window_); | 314 window_tree_host_->window()->SetProperty(kMusWindow, window_); |
317 | 315 |
318 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); | 316 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); |
319 | 317 |
320 aura::client::SetFocusClient(window_tree_host_->window(), | 318 aura::client::SetFocusClient(window_tree_host_->window(), |
321 focus_client_.get()); | 319 focus_client_.get()); |
322 aura::client::SetActivationClient(window_tree_host_->window(), | 320 aura::client::SetActivationClient(window_tree_host_->window(), |
323 focus_client_.get()); | 321 focus_client_.get()); |
324 screen_position_client_.reset(new wm::DefaultScreenPositionClient()); | |
325 aura::client::SetScreenPositionClient(window_tree_host_->window(), | |
326 screen_position_client_.get()); | |
327 | |
328 window_tree_client_.reset( | 322 window_tree_client_.reset( |
329 new NativeWidgetMusWindowTreeClient(window_tree_host_->window())); | 323 new NativeWidgetMusWindowTreeClient(window_tree_host_->window())); |
330 window_tree_host_->window()->AddPreTargetHandler(focus_client_.get()); | 324 window_tree_host_->window()->AddPreTargetHandler(focus_client_.get()); |
331 window_tree_host_->window()->SetLayoutManager( | 325 window_tree_host_->window()->SetLayoutManager( |
332 new ContentWindowLayoutManager(window_tree_host_->window(), content_)); | 326 new ContentWindowLayoutManager(window_tree_host_->window(), content_)); |
333 capture_client_.reset( | 327 capture_client_.reset( |
334 new aura::client::DefaultCaptureClient(window_tree_host_->window())); | 328 new aura::client::DefaultCaptureClient(window_tree_host_->window())); |
335 | 329 |
336 content_->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 330 content_->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
337 content_->Init(ui::LAYER_TEXTURED); | 331 content_->Init(ui::LAYER_TEXTURED); |
(...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 | 848 |
855 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { | 849 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { |
856 native_widget_delegate_->OnGestureEvent(event); | 850 native_widget_delegate_->OnGestureEvent(event); |
857 } | 851 } |
858 | 852 |
859 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { | 853 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { |
860 GetWidget()->Close(); | 854 GetWidget()->Close(); |
861 } | 855 } |
862 | 856 |
863 } // namespace views | 857 } // namespace views |
OLD | NEW |