Chromium Code Reviews| 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" | |
| 33 #include "ui/wm/core/focus_controller.h" | 34 #include "ui/wm/core/focus_controller.h" |
| 34 | 35 |
| 35 DECLARE_WINDOW_PROPERTY_TYPE(mus::Window*); | 36 DECLARE_WINDOW_PROPERTY_TYPE(mus::Window*); |
| 36 | 37 |
| 37 namespace views { | 38 namespace views { |
| 38 namespace { | 39 namespace { |
| 39 | 40 |
| 40 DEFINE_WINDOW_PROPERTY_KEY(mus::Window*, kMusWindow, nullptr); | 41 DEFINE_WINDOW_PROPERTY_KEY(mus::Window*, kMusWindow, nullptr); |
| 41 | 42 |
| 42 MUS_DEFINE_WINDOW_PROPERTY_KEY(NativeWidgetMus*, kNativeWidgetMusKey, nullptr); | 43 MUS_DEFINE_WINDOW_PROPERTY_KEY(NativeWidgetMus*, kNativeWidgetMusKey, nullptr); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 } // namespace | 173 } // namespace |
| 173 | 174 |
| 174 //////////////////////////////////////////////////////////////////////////////// | 175 //////////////////////////////////////////////////////////////////////////////// |
| 175 // NativeWidgetMus, public: | 176 // NativeWidgetMus, public: |
| 176 | 177 |
| 177 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate, | 178 NativeWidgetMus::NativeWidgetMus(internal::NativeWidgetDelegate* delegate, |
| 178 mojo::Shell* shell, | 179 mojo::Shell* shell, |
| 179 mus::Window* window, | 180 mus::Window* window, |
| 180 mus::mojom::SurfaceType surface_type) | 181 mus::mojom::SurfaceType surface_type) |
| 181 : window_(window), | 182 : 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 | |
|
sky
2016/02/08 17:42:15
Seems better to do initialization in InitNativeWid
sadrul
2016/02/08 18:33:24
We need to install the RootWindowSettings for the
| |
| 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); | |
| 193 } | 208 } |
| 194 | 209 |
| 195 NativeWidgetMus::~NativeWidgetMus() { | 210 NativeWidgetMus::~NativeWidgetMus() { |
| 196 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) | 211 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) |
| 197 delete native_widget_delegate_; | 212 delete native_widget_delegate_; |
| 198 else | 213 else |
| 199 CloseNow(); | 214 CloseNow(); |
| 200 } | 215 } |
| 201 | 216 |
| 202 // static | 217 // static |
| 203 void NativeWidgetMus::NotifyFrameChanged( | 218 void NativeWidgetMus::NotifyFrameChanged( |
| 204 mus::WindowTreeConnection* connection) { | 219 mus::WindowTreeConnection* connection) { |
| 205 for (mus::Window* window : connection->GetRoots()) { | 220 for (mus::Window* window : connection->GetRoots()) { |
| 206 NativeWidgetMus* native_widget = | 221 NativeWidgetMus* native_widget = |
| 207 window->GetLocalProperty(kNativeWidgetMusKey); | 222 window->GetLocalProperty(kNativeWidgetMusKey); |
| 208 if (native_widget && native_widget->GetWidget()->non_client_view()) { | 223 if (native_widget && native_widget->GetWidget()->non_client_view()) { |
| 209 native_widget->GetWidget()->non_client_view()->Layout(); | 224 native_widget->GetWidget()->non_client_view()->Layout(); |
| 210 native_widget->GetWidget()->non_client_view()->SchedulePaint(); | 225 native_widget->GetWidget()->non_client_view()->SchedulePaint(); |
| 211 native_widget->UpdateClientArea(); | 226 native_widget->UpdateClientArea(); |
| 212 } | 227 } |
| 213 } | 228 } |
| 214 } | 229 } |
| 215 | 230 |
| 231 aura::Window* NativeWidgetMus::GetRootWindow() { | |
| 232 return window_tree_host_->window(); | |
| 233 } | |
| 234 | |
| 216 void NativeWidgetMus::OnPlatformWindowClosed() { | 235 void NativeWidgetMus::OnPlatformWindowClosed() { |
| 217 native_widget_delegate_->OnNativeWidgetDestroying(); | 236 native_widget_delegate_->OnNativeWidgetDestroying(); |
| 218 | 237 |
| 219 window_tree_client_.reset(); // Uses |content_|. | 238 window_tree_client_.reset(); // Uses |content_|. |
| 220 capture_client_.reset(); // Uses |content_|. | 239 capture_client_.reset(); // Uses |content_|. |
| 221 | 240 |
| 222 window_tree_host_->RemoveObserver(this); | 241 window_tree_host_->RemoveObserver(this); |
| 223 window_tree_host_.reset(); | 242 window_tree_host_.reset(); |
| 224 | 243 |
| 225 window_ = nullptr; | 244 window_ = nullptr; |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 | 304 |
| 286 NonClientFrameView* NativeWidgetMus::CreateNonClientFrameView() { | 305 NonClientFrameView* NativeWidgetMus::CreateNonClientFrameView() { |
| 287 return new ClientSideNonClientFrameView(GetWidget()); | 306 return new ClientSideNonClientFrameView(GetWidget()); |
| 288 } | 307 } |
| 289 | 308 |
| 290 void NativeWidgetMus::InitNativeWidget(const Widget::InitParams& params) { | 309 void NativeWidgetMus::InitNativeWidget(const Widget::InitParams& params) { |
| 291 ownership_ = params.ownership; | 310 ownership_ = params.ownership; |
| 292 window_->SetCanFocus(params.activatable == | 311 window_->SetCanFocus(params.activatable == |
| 293 Widget::InitParams::ACTIVATABLE_YES); | 312 Widget::InitParams::ACTIVATABLE_YES); |
| 294 | 313 |
| 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_)); | |
| 311 window_tree_host_->AddObserver(this); | 314 window_tree_host_->AddObserver(this); |
| 312 window_tree_host_->InitHost(); | 315 window_tree_host_->InitHost(); |
| 313 aura::Env::GetInstance()->set_context_factory(default_context_factory); | |
| 314 window_tree_host_->window()->SetProperty(kMusWindow, window_); | 316 window_tree_host_->window()->SetProperty(kMusWindow, window_); |
| 315 | 317 |
| 316 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); | 318 focus_client_.reset(new wm::FocusController(new FocusRulesImpl)); |
| 317 | 319 |
| 318 aura::client::SetFocusClient(window_tree_host_->window(), | 320 aura::client::SetFocusClient(window_tree_host_->window(), |
| 319 focus_client_.get()); | 321 focus_client_.get()); |
| 320 aura::client::SetActivationClient(window_tree_host_->window(), | 322 aura::client::SetActivationClient(window_tree_host_->window(), |
| 321 focus_client_.get()); | 323 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 | |
| 322 window_tree_client_.reset( | 328 window_tree_client_.reset( |
| 323 new NativeWidgetMusWindowTreeClient(window_tree_host_->window())); | 329 new NativeWidgetMusWindowTreeClient(window_tree_host_->window())); |
| 324 window_tree_host_->window()->AddPreTargetHandler(focus_client_.get()); | 330 window_tree_host_->window()->AddPreTargetHandler(focus_client_.get()); |
| 325 window_tree_host_->window()->SetLayoutManager( | 331 window_tree_host_->window()->SetLayoutManager( |
| 326 new ContentWindowLayoutManager(window_tree_host_->window(), content_)); | 332 new ContentWindowLayoutManager(window_tree_host_->window(), content_)); |
| 327 capture_client_.reset( | 333 capture_client_.reset( |
| 328 new aura::client::DefaultCaptureClient(window_tree_host_->window())); | 334 new aura::client::DefaultCaptureClient(window_tree_host_->window())); |
| 329 | 335 |
| 330 content_->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 336 content_->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
| 331 content_->Init(ui::LAYER_TEXTURED); | 337 content_->Init(ui::LAYER_TEXTURED); |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 848 | 854 |
| 849 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { | 855 void NativeWidgetMus::OnGestureEvent(ui::GestureEvent* event) { |
| 850 native_widget_delegate_->OnGestureEvent(event); | 856 native_widget_delegate_->OnGestureEvent(event); |
| 851 } | 857 } |
| 852 | 858 |
| 853 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { | 859 void NativeWidgetMus::OnHostCloseRequested(const aura::WindowTreeHost* host) { |
| 854 GetWidget()->Close(); | 860 GetWidget()->Close(); |
| 855 } | 861 } |
| 856 | 862 |
| 857 } // namespace views | 863 } // namespace views |
| OLD | NEW |