| 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" | |
| 20 #include "ui/views/mus/clipboard_mus.h" | 19 #include "ui/views/mus/clipboard_mus.h" |
| 21 #include "ui/views/mus/native_widget_mus.h" | 20 #include "ui/views/mus/native_widget_mus.h" |
| 22 #include "ui/views/mus/screen_mus.h" | 21 #include "ui/views/mus/screen_mus.h" |
| 23 #include "ui/views/pointer_watcher.h" | 22 #include "ui/views/pointer_watcher.h" |
| 24 #include "ui/views/views_delegate.h" | 23 #include "ui/views/views_delegate.h" |
| 25 | 24 |
| 26 namespace views { | 25 namespace views { |
| 27 namespace { | 26 namespace { |
| 28 | 27 |
| 29 using WindowManagerConnectionPtr = | 28 using WindowManagerConnectionPtr = |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 pointer_watchers_.RemoveObserver(watcher); | 96 pointer_watchers_.RemoveObserver(watcher); |
| 98 if (!HasPointerWatcher()) { | 97 if (!HasPointerWatcher()) { |
| 99 // Last PointerWatcher removed, stop the event observer. | 98 // Last PointerWatcher removed, stop the event observer. |
| 100 client_->SetEventObserver(nullptr); | 99 client_->SetEventObserver(nullptr); |
| 101 } | 100 } |
| 102 } | 101 } |
| 103 | 102 |
| 104 WindowManagerConnection::WindowManagerConnection( | 103 WindowManagerConnection::WindowManagerConnection( |
| 105 shell::Connector* connector, | 104 shell::Connector* connector, |
| 106 const shell::Identity& identity) | 105 const shell::Identity& identity) |
| 107 : connector_(connector), | 106 : connector_(connector), identity_(identity) { |
| 108 identity_(identity), | |
| 109 created_device_data_manager_(false) { | |
| 110 lazy_tls_ptr.Pointer()->Set(this); | 107 lazy_tls_ptr.Pointer()->Set(this); |
| 111 client_.reset(new mus::WindowTreeClient(this, nullptr, nullptr)); | 108 client_.reset(new mus::WindowTreeClient(this, nullptr, nullptr)); |
| 112 client_->ConnectViaWindowTreeFactory(connector_); | 109 client_->ConnectViaWindowTreeFactory(connector_); |
| 113 | 110 |
| 114 screen_.reset(new ScreenMus(this)); | 111 screen_.reset(new ScreenMus(this)); |
| 115 screen_->Init(connector); | 112 screen_->Init(connector); |
| 116 | 113 |
| 117 std::unique_ptr<ClipboardMus> clipboard(new ClipboardMus); | 114 std::unique_ptr<ClipboardMus> clipboard(new ClipboardMus); |
| 118 clipboard->Init(connector); | 115 clipboard->Init(connector); |
| 119 ui::Clipboard::SetClipboardForCurrentThread(std::move(clipboard)); | 116 ui::Clipboard::SetClipboardForCurrentThread(std::move(clipboard)); |
| 120 | 117 |
| 121 if (!ui::DeviceDataManager::HasInstance()) { | |
| 122 // TODO(sad): We should have a DeviceDataManager implementation that talks | |
| 123 // to a mojo service to learn about the input-devices on the system. | |
| 124 // http://crbug.com/601981 | |
| 125 ui::DeviceDataManager::CreateInstance(); | |
| 126 created_device_data_manager_ = true; | |
| 127 } | |
| 128 | |
| 129 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( | 118 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( |
| 130 &WindowManagerConnection::CreateNativeWidgetMus, | 119 &WindowManagerConnection::CreateNativeWidgetMus, |
| 131 base::Unretained(this), | 120 base::Unretained(this), |
| 132 std::map<std::string, std::vector<uint8_t>>())); | 121 std::map<std::string, std::vector<uint8_t>>())); |
| 133 } | 122 } |
| 134 | 123 |
| 135 WindowManagerConnection::~WindowManagerConnection() { | 124 WindowManagerConnection::~WindowManagerConnection() { |
| 136 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while | 125 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while |
| 137 // we are still valid. | 126 // we are still valid. |
| 138 client_.reset(); | 127 client_.reset(); |
| 139 ui::Clipboard::DestroyClipboardForCurrentThread(); | 128 ui::Clipboard::DestroyClipboardForCurrentThread(); |
| 140 if (created_device_data_manager_) | |
| 141 ui::DeviceDataManager::DeleteInstance(); | |
| 142 lazy_tls_ptr.Pointer()->Set(nullptr); | 129 lazy_tls_ptr.Pointer()->Set(nullptr); |
| 143 | 130 |
| 144 if (ViewsDelegate::GetInstance()) { | 131 if (ViewsDelegate::GetInstance()) { |
| 145 ViewsDelegate::GetInstance()->set_native_widget_factory( | 132 ViewsDelegate::GetInstance()->set_native_widget_factory( |
| 146 ViewsDelegate::NativeWidgetFactory()); | 133 ViewsDelegate::NativeWidgetFactory()); |
| 147 } | 134 } |
| 148 } | 135 } |
| 149 | 136 |
| 150 bool WindowManagerConnection::HasPointerWatcher() { | 137 bool WindowManagerConnection::HasPointerWatcher() { |
| 151 // Check to see if we really have any observers left. This doesn't use | 138 // Check to see if we really have any observers left. This doesn't use |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { | 175 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { |
| 189 if (client_) | 176 if (client_) |
| 190 NativeWidgetMus::NotifyFrameChanged(client_.get()); | 177 NativeWidgetMus::NotifyFrameChanged(client_.get()); |
| 191 } | 178 } |
| 192 | 179 |
| 193 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { | 180 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { |
| 194 return client_->GetCursorScreenPoint(); | 181 return client_->GetCursorScreenPoint(); |
| 195 } | 182 } |
| 196 | 183 |
| 197 } // namespace views | 184 } // namespace views |
| OLD | NEW |