| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/mus_client.h" | 5 #include "ui/views/mus/mus_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "services/service_manager/public/cpp/connection.h" | 9 #include "services/service_manager/public/cpp/connection.h" |
| 10 #include "services/service_manager/public/cpp/connector.h" | 10 #include "services/service_manager/public/cpp/connector.h" |
| 11 #include "services/ui/public/cpp/gpu_service.h" | 11 #include "services/ui/public/cpp/gpu_service.h" |
| 12 #include "services/ui/public/interfaces/event_matcher.mojom.h" | 12 #include "services/ui/public/interfaces/event_matcher.mojom.h" |
| 13 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
| 14 #include "ui/aura/mus/os_exchange_data_provider_mus.h" | 14 #include "ui/aura/mus/os_exchange_data_provider_mus.h" |
| 15 #include "ui/aura/mus/property_converter.h" | 15 #include "ui/aura/mus/property_converter.h" |
| 16 #include "ui/aura/mus/window_port_mus.h" | |
| 17 #include "ui/aura/mus/window_tree_client.h" | 16 #include "ui/aura/mus/window_tree_client.h" |
| 18 #include "ui/aura/mus/window_tree_host_mus.h" | 17 #include "ui/aura/mus/window_tree_host_mus.h" |
| 19 #include "ui/aura/window.h" | 18 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_tree_host.h" | 19 #include "ui/aura/window_tree_host.h" |
| 21 #include "ui/views/mus/aura_init.h" | 20 #include "ui/views/mus/aura_init.h" |
| 22 #include "ui/views/mus/clipboard_mus.h" | 21 #include "ui/views/mus/clipboard_mus.h" |
| 22 #include "ui/views/mus/desktop_window_tree_host_mus.h" |
| 23 #include "ui/views/mus/screen_mus.h" | 23 #include "ui/views/mus/screen_mus.h" |
| 24 #include "ui/views/mus/surface_context_factory.h" | 24 #include "ui/views/mus/surface_context_factory.h" |
| 25 #include "ui/views/views_delegate.h" | 25 #include "ui/views/views_delegate.h" |
| 26 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 26 #include "ui/wm/core/base_focus_rules.h" | 27 #include "ui/wm/core/base_focus_rules.h" |
| 27 #include "ui/wm/core/capture_controller.h" | 28 #include "ui/wm/core/capture_controller.h" |
| 28 #include "ui/wm/core/focus_controller.h" | 29 #include "ui/wm/core/focus_controller.h" |
| 29 #include "ui/wm/core/wm_state.h" | 30 #include "ui/wm/core/wm_state.h" |
| 30 | 31 |
| 31 namespace views { | 32 namespace views { |
| 32 namespace { | 33 namespace { |
| 33 | 34 |
| 34 // TODO: this is temporary, figure out what the real one should be like. | 35 // TODO: this is temporary, figure out what the real one should be like. |
| 35 class FocusRulesMus : public wm::BaseFocusRules { | 36 class FocusRulesMus : public wm::BaseFocusRules { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 aura::Window* window, | 68 aura::Window* window, |
| 68 const std::string& transport_name, | 69 const std::string& transport_name, |
| 69 const std::vector<uint8_t>* transport_data) override {} | 70 const std::vector<uint8_t>* transport_data) override {} |
| 70 | 71 |
| 71 private: | 72 private: |
| 72 DISALLOW_COPY_AND_ASSIGN(PropertyConverterImpl); | 73 DISALLOW_COPY_AND_ASSIGN(PropertyConverterImpl); |
| 73 }; | 74 }; |
| 74 | 75 |
| 75 } // namespace | 76 } // namespace |
| 76 | 77 |
| 78 // static |
| 79 MusClient* MusClient::instance_ = nullptr; |
| 80 |
| 81 MusClient::~MusClient() { |
| 82 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while |
| 83 // we are still valid. |
| 84 window_tree_client_.reset(); |
| 85 ui::OSExchangeDataProviderFactory::SetFactory(nullptr); |
| 86 ui::Clipboard::DestroyClipboardForCurrentThread(); |
| 87 gpu_service_.reset(); |
| 88 |
| 89 if (ViewsDelegate::GetInstance()) { |
| 90 ViewsDelegate::GetInstance()->set_native_widget_factory( |
| 91 ViewsDelegate::NativeWidgetFactory()); |
| 92 } |
| 93 |
| 94 DCHECK_EQ(instance_, this); |
| 95 instance_ = nullptr; |
| 96 } |
| 97 |
| 98 NativeWidget* MusClient::CreateNativeWidget( |
| 99 const Widget::InitParams& init_params, |
| 100 internal::NativeWidgetDelegate* delegate) { |
| 101 // TYPE_CONTROL widgets require a NativeWidgetAura. So we let this fall |
| 102 // through, so that the default NativeWidgetPrivate::CreateNativeWidget() is |
| 103 // used instead. |
| 104 if (init_params.type == Widget::InitParams::TYPE_CONTROL) |
| 105 return nullptr; |
| 106 |
| 107 DesktopNativeWidgetAura* native_widget = |
| 108 new DesktopNativeWidgetAura(delegate); |
| 109 if (init_params.desktop_window_tree_host) { |
| 110 native_widget->SetDesktopWindowTreeHost( |
| 111 base::WrapUnique(init_params.desktop_window_tree_host)); |
| 112 } else { |
| 113 native_widget->SetDesktopWindowTreeHost( |
| 114 base::MakeUnique<DesktopWindowTreeHostMus>(delegate, native_widget)); |
| 115 } |
| 116 return native_widget; |
| 117 } |
| 118 |
| 77 MusClient::MusClient(service_manager::Connector* connector, | 119 MusClient::MusClient(service_manager::Connector* connector, |
| 78 const service_manager::Identity& identity, | 120 const service_manager::Identity& identity, |
| 79 const std::string& resource_file, | |
| 80 const std::string& resource_file_200, | |
| 81 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) | 121 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| 82 : connector_(connector), identity_(identity) { | 122 : connector_(connector), identity_(identity) { |
| 83 aura_init_ = base::MakeUnique<AuraInit>( | 123 DCHECK(!instance_); |
| 84 connector, resource_file, resource_file_200, | 124 instance_ = this; |
| 85 base::Bind(&MusClient::CreateWindowPort, base::Unretained(this))); | |
| 86 | |
| 87 property_converter_ = base::MakeUnique<PropertyConverterImpl>(); | 125 property_converter_ = base::MakeUnique<PropertyConverterImpl>(); |
| 88 | 126 |
| 89 wm_state_ = base::MakeUnique<wm::WMState>(); | 127 wm_state_ = base::MakeUnique<wm::WMState>(); |
| 90 | 128 |
| 91 gpu_service_ = ui::GpuService::Create(connector, std::move(io_task_runner)); | 129 gpu_service_ = ui::GpuService::Create(connector, std::move(io_task_runner)); |
| 92 compositor_context_factory_ = | 130 compositor_context_factory_ = |
| 93 base::MakeUnique<views::SurfaceContextFactory>(gpu_service_.get()); | 131 base::MakeUnique<views::SurfaceContextFactory>(gpu_service_.get()); |
| 94 aura::Env::GetInstance()->set_context_factory( | 132 aura::Env::GetInstance()->set_context_factory( |
| 95 compositor_context_factory_.get()); | 133 compositor_context_factory_.get()); |
| 96 // TODO(sky): need a class similar to DesktopFocusRules. | 134 // TODO(sky): need a class similar to DesktopFocusRules. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 107 std::unique_ptr<ClipboardMus> clipboard = base::MakeUnique<ClipboardMus>(); | 145 std::unique_ptr<ClipboardMus> clipboard = base::MakeUnique<ClipboardMus>(); |
| 108 clipboard->Init(connector); | 146 clipboard->Init(connector); |
| 109 ui::Clipboard::SetClipboardForCurrentThread(std::move(clipboard)); | 147 ui::Clipboard::SetClipboardForCurrentThread(std::move(clipboard)); |
| 110 | 148 |
| 111 ui::OSExchangeDataProviderFactory::SetFactory(this); | 149 ui::OSExchangeDataProviderFactory::SetFactory(this); |
| 112 | 150 |
| 113 ViewsDelegate::GetInstance()->set_native_widget_factory( | 151 ViewsDelegate::GetInstance()->set_native_widget_factory( |
| 114 base::Bind(&MusClient::CreateNativeWidget, base::Unretained(this))); | 152 base::Bind(&MusClient::CreateNativeWidget, base::Unretained(this))); |
| 115 } | 153 } |
| 116 | 154 |
| 117 MusClient::~MusClient() { | 155 void MusClient::OnEmbed( |
| 118 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while | 156 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
| 119 // we are still valid. | 157 NOTREACHED(); |
| 120 window_tree_client_.reset(); | |
| 121 ui::OSExchangeDataProviderFactory::SetFactory(nullptr); | |
| 122 ui::Clipboard::DestroyClipboardForCurrentThread(); | |
| 123 gpu_service_.reset(); | |
| 124 | |
| 125 if (ViewsDelegate::GetInstance()) { | |
| 126 ViewsDelegate::GetInstance()->set_native_widget_factory( | |
| 127 ViewsDelegate::NativeWidgetFactory()); | |
| 128 } | |
| 129 } | 158 } |
| 130 | 159 |
| 131 NativeWidget* MusClient::CreateNativeWidget( | |
| 132 const Widget::InitParams& init_params, | |
| 133 internal::NativeWidgetDelegate* delegate) { | |
| 134 // TYPE_CONTROL widgets require a NativeWidgetAura. So we let this fall | |
| 135 // through, so that the default NativeWidgetPrivate::CreateNativeWidget() is | |
| 136 // used instead. | |
| 137 if (init_params.type == Widget::InitParams::TYPE_CONTROL) | |
| 138 return nullptr; | |
| 139 return nullptr; | |
| 140 } | |
| 141 | |
| 142 std::unique_ptr<aura::WindowPort> MusClient::CreateWindowPort( | |
| 143 aura::Window* window) { | |
| 144 return base::MakeUnique<aura::WindowPortMus>(window_tree_client_.get(), | |
| 145 aura::WindowMusType::LOCAL); | |
| 146 } | |
| 147 | |
| 148 void MusClient::OnEmbed( | |
| 149 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {} | |
| 150 | |
| 151 void MusClient::OnLostConnection(aura::WindowTreeClient* client) {} | 160 void MusClient::OnLostConnection(aura::WindowTreeClient* client) {} |
| 152 | 161 |
| 153 void MusClient::OnEmbedRootDestroyed(aura::Window* root) { | 162 void MusClient::OnEmbedRootDestroyed(aura::Window* root) { |
| 154 // Not called for MusClient as WindowTreeClient isn't created by | 163 // Not called for MusClient as WindowTreeClient isn't created by |
| 155 // way of an Embed(). | 164 // way of an Embed(). |
| 156 NOTREACHED(); | 165 NOTREACHED(); |
| 157 } | 166 } |
| 158 | 167 |
| 159 void MusClient::OnPointerEventObserved(const ui::PointerEvent& event, | 168 void MusClient::OnPointerEventObserved(const ui::PointerEvent& event, |
| 160 aura::Window* target) { | 169 aura::Window* target) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 return root->GetTopWindowContainingPoint(relative_point); | 204 return root->GetTopWindowContainingPoint(relative_point); |
| 196 } | 205 } |
| 197 return nullptr; | 206 return nullptr; |
| 198 } | 207 } |
| 199 | 208 |
| 200 std::unique_ptr<OSExchangeData::Provider> MusClient::BuildProvider() { | 209 std::unique_ptr<OSExchangeData::Provider> MusClient::BuildProvider() { |
| 201 return base::MakeUnique<aura::OSExchangeDataProviderMus>(); | 210 return base::MakeUnique<aura::OSExchangeDataProviderMus>(); |
| 202 } | 211 } |
| 203 | 212 |
| 204 } // namespace views | 213 } // namespace views |
| OLD | NEW |