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" |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 WINDOW_TYPES_MATCH(BUBBLE); | 48 WINDOW_TYPES_MATCH(BUBBLE); |
49 WINDOW_TYPES_MATCH(DRAG); | 49 WINDOW_TYPES_MATCH(DRAG); |
50 // ui::mojom::WindowType::UNKNOWN does not correspond to a value in | 50 // ui::mojom::WindowType::UNKNOWN does not correspond to a value in |
51 // Widget::InitParams::Type. | 51 // Widget::InitParams::Type. |
52 | 52 |
53 namespace views { | 53 namespace views { |
54 | 54 |
55 // static | 55 // static |
56 MusClient* MusClient::instance_ = nullptr; | 56 MusClient* MusClient::instance_ = nullptr; |
57 | 57 |
58 MusClient::MusClient(service_manager::Connector* connector, | |
59 const service_manager::Identity& identity, | |
60 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, | |
61 bool create_wm_state) | |
62 : identity_(identity) { | |
63 DCHECK(!instance_); | |
64 instance_ = this; | |
65 // TODO(msw): Avoid this... use some default value? Allow clients to extend? | |
66 property_converter_ = base::MakeUnique<aura::PropertyConverter>(); | |
67 | |
68 if (create_wm_state) | |
69 wm_state_ = base::MakeUnique<wm::WMState>(); | |
70 | |
71 gpu_ = ui::Gpu::Create(connector, std::move(io_task_runner)); | |
72 compositor_context_factory_ = | |
73 base::MakeUnique<aura::MusContextFactory>(gpu_.get()); | |
74 aura::Env::GetInstance()->set_context_factory( | |
75 compositor_context_factory_.get()); | |
76 window_tree_client_ = | |
77 base::MakeUnique<aura::WindowTreeClient>(connector, this); | |
78 aura::Env::GetInstance()->SetWindowTreeClient(window_tree_client_.get()); | |
79 window_tree_client_->ConnectViaWindowTreeFactory(); | |
80 | |
81 pointer_watcher_event_router_ = | |
82 base::MakeUnique<PointerWatcherEventRouter2>(window_tree_client_.get()); | |
83 | |
84 screen_ = base::MakeUnique<ScreenMus>(this); | |
85 screen_->Init(connector); | |
86 | |
87 std::unique_ptr<ClipboardMus> clipboard = base::MakeUnique<ClipboardMus>(); | |
88 clipboard->Init(connector); | |
89 ui::Clipboard::SetClipboardForCurrentThread(std::move(clipboard)); | |
90 | |
91 ui::OSExchangeDataProviderFactory::SetFactory(this); | |
92 | |
93 ViewsDelegate::GetInstance()->set_native_widget_factory( | |
94 base::Bind(&MusClient::CreateNativeWidget, base::Unretained(this))); | |
95 } | |
96 | |
97 MusClient::~MusClient() { | 58 MusClient::~MusClient() { |
98 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while | 59 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while |
99 // we are still valid. | 60 // we are still valid. |
100 window_tree_client_.reset(); | 61 window_tree_client_.reset(); |
101 ui::OSExchangeDataProviderFactory::SetFactory(nullptr); | 62 ui::OSExchangeDataProviderFactory::SetFactory(nullptr); |
102 ui::Clipboard::DestroyClipboardForCurrentThread(); | 63 ui::Clipboard::DestroyClipboardForCurrentThread(); |
103 gpu_.reset(); | 64 gpu_.reset(); |
104 | 65 |
105 if (ViewsDelegate::GetInstance()) { | 66 if (ViewsDelegate::GetInstance()) { |
106 ViewsDelegate::GetInstance()->set_native_widget_factory( | 67 ViewsDelegate::GetInstance()->set_native_widget_factory( |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
200 } | 161 } |
201 | 162 |
202 void MusClient::AddObserver(MusClientObserver* observer) { | 163 void MusClient::AddObserver(MusClientObserver* observer) { |
203 observer_list_.AddObserver(observer); | 164 observer_list_.AddObserver(observer); |
204 } | 165 } |
205 | 166 |
206 void MusClient::RemoveObserver(MusClientObserver* observer) { | 167 void MusClient::RemoveObserver(MusClientObserver* observer) { |
207 observer_list_.RemoveObserver(observer); | 168 observer_list_.RemoveObserver(observer); |
208 } | 169 } |
209 | 170 |
| 171 MusClient::MusClient(service_manager::Connector* connector, |
| 172 const service_manager::Identity& identity, |
| 173 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| 174 : identity_(identity) { |
| 175 DCHECK(!instance_); |
| 176 instance_ = this; |
| 177 // TODO(msw): Avoid this... use some default value? Allow clients to extend? |
| 178 property_converter_ = base::MakeUnique<aura::PropertyConverter>(); |
| 179 |
| 180 wm_state_ = base::MakeUnique<wm::WMState>(); |
| 181 |
| 182 gpu_ = ui::Gpu::Create(connector, std::move(io_task_runner)); |
| 183 compositor_context_factory_ = |
| 184 base::MakeUnique<aura::MusContextFactory>(gpu_.get()); |
| 185 aura::Env::GetInstance()->set_context_factory( |
| 186 compositor_context_factory_.get()); |
| 187 window_tree_client_ = |
| 188 base::MakeUnique<aura::WindowTreeClient>(connector, this); |
| 189 aura::Env::GetInstance()->SetWindowTreeClient(window_tree_client_.get()); |
| 190 window_tree_client_->ConnectViaWindowTreeFactory(); |
| 191 |
| 192 pointer_watcher_event_router_ = |
| 193 base::MakeUnique<PointerWatcherEventRouter2>(window_tree_client_.get()); |
| 194 |
| 195 screen_ = base::MakeUnique<ScreenMus>(this); |
| 196 screen_->Init(connector); |
| 197 |
| 198 std::unique_ptr<ClipboardMus> clipboard = base::MakeUnique<ClipboardMus>(); |
| 199 clipboard->Init(connector); |
| 200 ui::Clipboard::SetClipboardForCurrentThread(std::move(clipboard)); |
| 201 |
| 202 ui::OSExchangeDataProviderFactory::SetFactory(this); |
| 203 |
| 204 ViewsDelegate::GetInstance()->set_native_widget_factory( |
| 205 base::Bind(&MusClient::CreateNativeWidget, base::Unretained(this))); |
| 206 } |
| 207 |
210 void MusClient::OnEmbed( | 208 void MusClient::OnEmbed( |
211 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { | 209 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
212 NOTREACHED(); | 210 NOTREACHED(); |
213 } | 211 } |
214 | 212 |
215 void MusClient::OnLostConnection(aura::WindowTreeClient* client) {} | 213 void MusClient::OnLostConnection(aura::WindowTreeClient* client) {} |
216 | 214 |
217 void MusClient::OnEmbedRootDestroyed( | 215 void MusClient::OnEmbedRootDestroyed( |
218 aura::WindowTreeHostMus* window_tree_host) { | 216 aura::WindowTreeHostMus* window_tree_host) { |
219 static_cast<DesktopWindowTreeHostMus*>(window_tree_host) | 217 static_cast<DesktopWindowTreeHostMus*>(window_tree_host) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 return root->GetTopWindowContainingPoint(relative_point); | 252 return root->GetTopWindowContainingPoint(relative_point); |
255 } | 253 } |
256 return nullptr; | 254 return nullptr; |
257 } | 255 } |
258 | 256 |
259 std::unique_ptr<OSExchangeData::Provider> MusClient::BuildProvider() { | 257 std::unique_ptr<OSExchangeData::Provider> MusClient::BuildProvider() { |
260 return base::MakeUnique<aura::OSExchangeDataProviderMus>(); | 258 return base::MakeUnique<aura::OSExchangeDataProviderMus>(); |
261 } | 259 } |
262 | 260 |
263 } // namespace views | 261 } // namespace views |
OLD | NEW |