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/window_manager_connection.h" | 5 #include "ui/views/mus/window_manager_connection.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
| 11 #include "components/mus/public/cpp/property_type_converters.h" | 11 #include "components/mus/public/cpp/property_type_converters.h" |
| 12 #include "components/mus/public/cpp/window.h" | 12 #include "components/mus/public/cpp/window.h" |
| 13 #include "components/mus/public/cpp/window_property.h" | 13 #include "components/mus/public/cpp/window_property.h" |
| 14 #include "components/mus/public/cpp/window_tree_client.h" | 14 #include "components/mus/public/cpp/window_tree_client.h" |
| 15 #include "components/mus/public/interfaces/event_matcher.mojom.h" | 15 #include "components/mus/public/interfaces/event_matcher.mojom.h" |
| 16 #include "components/mus/public/interfaces/window_tree.mojom.h" | 16 #include "components/mus/public/interfaces/window_tree.mojom.h" |
| 17 #include "services/shell/public/cpp/connection.h" | 17 #include "services/shell/public/cpp/connection.h" |
| 18 #include "services/shell/public/cpp/connector.h" | 18 #include "services/shell/public/cpp/connector.h" |
| 19 #include "ui/events/devices/device_data_manager.h" | 19 #include "ui/events/devices/device_data_manager.h" |
| 20 #include "ui/views/mus/clipboard_mus.h" | |
| 20 #include "ui/views/mus/native_widget_mus.h" | 21 #include "ui/views/mus/native_widget_mus.h" |
| 21 #include "ui/views/mus/screen_mus.h" | 22 #include "ui/views/mus/screen_mus.h" |
| 22 #include "ui/views/pointer_watcher.h" | 23 #include "ui/views/pointer_watcher.h" |
| 23 #include "ui/views/views_delegate.h" | 24 #include "ui/views/views_delegate.h" |
| 24 | 25 |
| 25 namespace views { | 26 namespace views { |
| 26 namespace { | 27 namespace { |
| 27 | 28 |
| 28 using WindowManagerConnectionPtr = | 29 using WindowManagerConnectionPtr = |
| 29 base::ThreadLocalPointer<views::WindowManagerConnection>; | 30 base::ThreadLocalPointer<views::WindowManagerConnection>; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 102 const shell::Identity& identity) | 103 const shell::Identity& identity) |
| 103 : connector_(connector), | 104 : connector_(connector), |
| 104 identity_(identity), | 105 identity_(identity), |
| 105 created_device_data_manager_(false) { | 106 created_device_data_manager_(false) { |
| 106 client_.reset(new mus::WindowTreeClient(this, nullptr, nullptr)); | 107 client_.reset(new mus::WindowTreeClient(this, nullptr, nullptr)); |
| 107 client_->ConnectViaWindowTreeFactory(connector_); | 108 client_->ConnectViaWindowTreeFactory(connector_); |
| 108 | 109 |
| 109 screen_.reset(new ScreenMus(this)); | 110 screen_.reset(new ScreenMus(this)); |
| 110 screen_->Init(connector); | 111 screen_->Init(connector); |
| 111 | 112 |
| 113 // We keep a weak ptr to clipboard_ | |
|
dcheng
2016/06/04 06:14:01
Stale comment? I don't see |clipboard_|
| |
| 114 std::unique_ptr<ClipboardMus> clipboard(new ClipboardMus); | |
| 115 clipboard->Init(connector); | |
| 116 ui::Clipboard::SetClipboardForCurrentThread(std::move(clipboard)); | |
| 117 | |
| 112 if (!ui::DeviceDataManager::HasInstance()) { | 118 if (!ui::DeviceDataManager::HasInstance()) { |
| 113 // TODO(sad): We should have a DeviceDataManager implementation that talks | 119 // TODO(sad): We should have a DeviceDataManager implementation that talks |
| 114 // to a mojo service to learn about the input-devices on the system. | 120 // to a mojo service to learn about the input-devices on the system. |
| 115 // http://crbug.com/601981 | 121 // http://crbug.com/601981 |
| 116 ui::DeviceDataManager::CreateInstance(); | 122 ui::DeviceDataManager::CreateInstance(); |
| 117 created_device_data_manager_ = true; | 123 created_device_data_manager_ = true; |
| 118 } | 124 } |
| 119 | 125 |
| 120 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( | 126 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( |
| 121 &WindowManagerConnection::CreateNativeWidgetMus, | 127 &WindowManagerConnection::CreateNativeWidgetMus, |
| 122 base::Unretained(this), | 128 base::Unretained(this), |
| 123 std::map<std::string, std::vector<uint8_t>>())); | 129 std::map<std::string, std::vector<uint8_t>>())); |
| 124 } | 130 } |
| 125 | 131 |
| 126 WindowManagerConnection::~WindowManagerConnection() { | 132 WindowManagerConnection::~WindowManagerConnection() { |
| 127 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while | 133 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while |
| 128 // we are still valid. | 134 // we are still valid. |
| 129 client_.reset(); | 135 client_.reset(); |
| 136 ui::Clipboard::DestroyClipboardForCurrentThread(); | |
| 130 if (created_device_data_manager_) | 137 if (created_device_data_manager_) |
| 131 ui::DeviceDataManager::DeleteInstance(); | 138 ui::DeviceDataManager::DeleteInstance(); |
| 132 } | 139 } |
| 133 | 140 |
| 134 bool WindowManagerConnection::HasPointerWatcher() { | 141 bool WindowManagerConnection::HasPointerWatcher() { |
| 135 // Check to see if we really have any observers left. This doesn't use | 142 // Check to see if we really have any observers left. This doesn't use |
| 136 // base::ObserverList<>::might_have_observers() because that returns true | 143 // base::ObserverList<>::might_have_observers() because that returns true |
| 137 // during iteration over the list even when the last observer is removed. | 144 // during iteration over the list even when the last observer is removed. |
| 138 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); | 145 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); |
| 139 return !!iterator.GetNext(); | 146 return !!iterator.GetNext(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 172 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { | 179 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { |
| 173 if (client_) | 180 if (client_) |
| 174 NativeWidgetMus::NotifyFrameChanged(client_.get()); | 181 NativeWidgetMus::NotifyFrameChanged(client_.get()); |
| 175 } | 182 } |
| 176 | 183 |
| 177 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { | 184 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { |
| 178 return client_->GetCursorScreenPoint(); | 185 return client_->GetCursorScreenPoint(); |
| 179 } | 186 } |
| 180 | 187 |
| 181 } // namespace views | 188 } // namespace views |
| OLD | NEW |