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