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_connection.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/gfx/geometry/mojo/geometry_type_converters.h" | 20 #include "ui/gfx/geometry/mojo/geometry_type_converters.h" |
21 #include "ui/views/mus/native_widget_mus.h" | 21 #include "ui/views/mus/native_widget_mus.h" |
22 #include "ui/views/mus/screen_mus.h" | 22 #include "ui/views/mus/screen_mus.h" |
23 #include "ui/views/pointer_watcher.h" | 23 #include "ui/views/pointer_watcher.h" |
24 #include "ui/views/views_delegate.h" | 24 #include "ui/views/views_delegate.h" |
(...skipping 30 matching lines...) Expand all Loading... |
55 } | 55 } |
56 | 56 |
57 // static | 57 // static |
58 void WindowManagerConnection::Reset() { | 58 void WindowManagerConnection::Reset() { |
59 delete Get(); | 59 delete Get(); |
60 lazy_tls_ptr.Pointer()->Set(nullptr); | 60 lazy_tls_ptr.Pointer()->Set(nullptr); |
61 } | 61 } |
62 | 62 |
63 mus::Window* WindowManagerConnection::NewWindow( | 63 mus::Window* WindowManagerConnection::NewWindow( |
64 const std::map<std::string, std::vector<uint8_t>>& properties) { | 64 const std::map<std::string, std::vector<uint8_t>>& properties) { |
65 return window_tree_connection_->NewTopLevelWindow(&properties); | 65 return client_->NewTopLevelWindow(&properties); |
66 } | 66 } |
67 | 67 |
68 NativeWidget* WindowManagerConnection::CreateNativeWidgetMus( | 68 NativeWidget* WindowManagerConnection::CreateNativeWidgetMus( |
69 const std::map<std::string, std::vector<uint8_t>>& props, | 69 const std::map<std::string, std::vector<uint8_t>>& props, |
70 const Widget::InitParams& init_params, | 70 const Widget::InitParams& init_params, |
71 internal::NativeWidgetDelegate* delegate) { | 71 internal::NativeWidgetDelegate* delegate) { |
72 std::map<std::string, std::vector<uint8_t>> properties = props; | 72 std::map<std::string, std::vector<uint8_t>> properties = props; |
73 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties); | 73 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties); |
74 properties[mus::mojom::WindowManager::kAppID_Property] = | 74 properties[mus::mojom::WindowManager::kAppID_Property] = |
75 mojo::ConvertTo<std::vector<uint8_t>>(identity_.name()); | 75 mojo::ConvertTo<std::vector<uint8_t>>(identity_.name()); |
76 return new NativeWidgetMus(delegate, connector_, NewWindow(properties), | 76 return new NativeWidgetMus(delegate, connector_, NewWindow(properties), |
77 mus::mojom::SurfaceType::DEFAULT); | 77 mus::mojom::SurfaceType::DEFAULT); |
78 } | 78 } |
79 | 79 |
80 void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher) { | 80 void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher) { |
81 bool had_watcher = HasPointerWatcher(); | 81 bool had_watcher = HasPointerWatcher(); |
82 pointer_watchers_.AddObserver(watcher); | 82 pointer_watchers_.AddObserver(watcher); |
83 if (!had_watcher) { | 83 if (!had_watcher) { |
84 // Start a watcher for pointer down. | 84 // Start a watcher for pointer down. |
85 // TODO(jamescook): Extend event observers to handle multiple event types. | 85 // TODO(jamescook): Extend event observers to handle multiple event types. |
86 mus::mojom::EventMatcherPtr matcher = mus::mojom::EventMatcher::New(); | 86 mus::mojom::EventMatcherPtr matcher = mus::mojom::EventMatcher::New(); |
87 matcher->type_matcher = mus::mojom::EventTypeMatcher::New(); | 87 matcher->type_matcher = mus::mojom::EventTypeMatcher::New(); |
88 matcher->type_matcher->type = mus::mojom::EventType::POINTER_DOWN; | 88 matcher->type_matcher->type = mus::mojom::EventType::POINTER_DOWN; |
89 window_tree_connection_->SetEventObserver(std::move(matcher)); | 89 client_->SetEventObserver(std::move(matcher)); |
90 } | 90 } |
91 } | 91 } |
92 | 92 |
93 void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) { | 93 void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) { |
94 pointer_watchers_.RemoveObserver(watcher); | 94 pointer_watchers_.RemoveObserver(watcher); |
95 if (!HasPointerWatcher()) { | 95 if (!HasPointerWatcher()) { |
96 // Last PointerWatcher removed, stop the event observer. | 96 // Last PointerWatcher removed, stop the event observer. |
97 window_tree_connection_->SetEventObserver(nullptr); | 97 client_->SetEventObserver(nullptr); |
98 } | 98 } |
99 } | 99 } |
100 | 100 |
101 WindowManagerConnection::WindowManagerConnection( | 101 WindowManagerConnection::WindowManagerConnection( |
102 shell::Connector* connector, | 102 shell::Connector* connector, |
103 const shell::Identity& identity) | 103 const shell::Identity& identity) |
104 : connector_(connector), | 104 : connector_(connector), |
105 identity_(identity), | 105 identity_(identity), |
106 window_tree_connection_(nullptr) { | 106 client_(nullptr) { |
107 window_tree_connection_.reset( | 107 client_.reset(new mus::WindowTreeClient(this, nullptr, nullptr)); |
108 mus::WindowTreeConnection::Create(this, connector_)); | 108 client_->ConnectViaWindowTreeFactory(connector_); |
109 | 109 |
110 screen_.reset(new ScreenMus(this)); | 110 screen_.reset(new ScreenMus(this)); |
111 screen_->Init(connector); | 111 screen_->Init(connector); |
112 | 112 |
113 // TODO(sad): We should have a DeviceDataManager implementation that talks to | 113 // TODO(sad): We should have a DeviceDataManager implementation that talks to |
114 // a mojo service to learn about the input-devices on the system. | 114 // a mojo service to learn about the input-devices on the system. |
115 // http://crbug.com/601981 | 115 // http://crbug.com/601981 |
116 ui::DeviceDataManager::CreateInstance(); | 116 ui::DeviceDataManager::CreateInstance(); |
117 | 117 |
118 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( | 118 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( |
119 &WindowManagerConnection::CreateNativeWidgetMus, | 119 &WindowManagerConnection::CreateNativeWidgetMus, |
120 base::Unretained(this), | 120 base::Unretained(this), |
121 std::map<std::string, std::vector<uint8_t>>())); | 121 std::map<std::string, std::vector<uint8_t>>())); |
122 } | 122 } |
123 | 123 |
124 WindowManagerConnection::~WindowManagerConnection() { | 124 WindowManagerConnection::~WindowManagerConnection() { |
125 // ~WindowTreeConnection calls back to us (we're the WindowTreeDelegate), | 125 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while |
126 // destroy it while we are still valid. | 126 // we are still valid. |
127 window_tree_connection_.reset(); | 127 client_.reset(); |
128 | 128 |
129 ui::DeviceDataManager::DeleteInstance(); | 129 ui::DeviceDataManager::DeleteInstance(); |
130 } | 130 } |
131 | 131 |
132 bool WindowManagerConnection::HasPointerWatcher() { | 132 bool WindowManagerConnection::HasPointerWatcher() { |
133 // Check to see if we really have any observers left. This doesn't use | 133 // Check to see if we really have any observers left. This doesn't use |
134 // base::ObserverList<>::might_have_observers() because that returns true | 134 // base::ObserverList<>::might_have_observers() because that returns true |
135 // during iteration over the list even when the last observer is removed. | 135 // during iteration over the list even when the last observer is removed. |
136 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); | 136 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); |
137 return !!iterator.GetNext(); | 137 return !!iterator.GetNext(); |
138 } | 138 } |
139 | 139 |
140 void WindowManagerConnection::OnEmbed(mus::Window* root) {} | 140 void WindowManagerConnection::OnEmbed(mus::Window* root) {} |
141 | 141 |
142 void WindowManagerConnection::OnConnectionLost( | 142 void WindowManagerConnection::OnWindowTreeClientDestroyed( |
143 mus::WindowTreeConnection* connection) {} | 143 mus::WindowTreeClient* client) {} |
144 | 144 |
145 void WindowManagerConnection::OnEventObserved(const ui::Event& event, | 145 void WindowManagerConnection::OnEventObserved(const ui::Event& event, |
146 mus::Window* target) { | 146 mus::Window* target) { |
147 if (!event.IsLocatedEvent()) | 147 if (!event.IsLocatedEvent()) |
148 return; | 148 return; |
149 Widget* target_widget = nullptr; | 149 Widget* target_widget = nullptr; |
150 if (target) { | 150 if (target) { |
151 mus::Window* root = target->GetRoot(); | 151 mus::Window* root = target->GetRoot(); |
152 target_widget = NativeWidgetMus::GetWidgetForWindow(root); | 152 target_widget = NativeWidgetMus::GetWidgetForWindow(root); |
153 } | 153 } |
154 | 154 |
155 // The mojo input events type converter uses the event root_location field | 155 // The mojo input events type converter uses the event root_location field |
156 // to store screen coordinates. Screen coordinates really should be returned | 156 // to store screen coordinates. Screen coordinates really should be returned |
157 // separately. See http://crbug.com/608547 | 157 // separately. See http://crbug.com/608547 |
158 gfx::Point location_in_screen = event.AsLocatedEvent()->root_location(); | 158 gfx::Point location_in_screen = event.AsLocatedEvent()->root_location(); |
159 if (event.type() == ui::ET_MOUSE_PRESSED) { | 159 if (event.type() == ui::ET_MOUSE_PRESSED) { |
160 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, | 160 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, |
161 OnMousePressed(*event.AsMouseEvent(), location_in_screen, | 161 OnMousePressed(*event.AsMouseEvent(), location_in_screen, |
162 target_widget)); | 162 target_widget)); |
163 } else if (event.type() == ui::ET_TOUCH_PRESSED) { | 163 } else if (event.type() == ui::ET_TOUCH_PRESSED) { |
164 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, | 164 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, |
165 OnTouchPressed(*event.AsTouchEvent(), location_in_screen, | 165 OnTouchPressed(*event.AsTouchEvent(), location_in_screen, |
166 target_widget)); | 166 target_widget)); |
167 } | 167 } |
168 } | 168 } |
169 | 169 |
170 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { | 170 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { |
171 if (window_tree_connection_) | 171 if (client_) |
172 NativeWidgetMus::NotifyFrameChanged(window_tree_connection_.get()); | 172 NativeWidgetMus::NotifyFrameChanged(client_.get()); |
173 } | 173 } |
174 | 174 |
175 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { | 175 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { |
176 return window_tree_connection_->GetCursorScreenPoint(); | 176 return client_->GetCursorScreenPoint(); |
177 } | 177 } |
178 | 178 |
179 } // namespace views | 179 } // namespace views |
OLD | NEW |