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 "services/shell/public/cpp/connection.h" | 11 #include "services/shell/public/cpp/connection.h" |
12 #include "services/shell/public/cpp/connector.h" | 12 #include "services/shell/public/cpp/connector.h" |
13 #include "services/ui/public/cpp/property_type_converters.h" | 13 #include "services/ui/public/cpp/property_type_converters.h" |
14 #include "services/ui/public/cpp/window.h" | 14 #include "services/ui/public/cpp/window.h" |
15 #include "services/ui/public/cpp/window_property.h" | 15 #include "services/ui/public/cpp/window_property.h" |
16 #include "services/ui/public/cpp/window_tree_client.h" | 16 #include "services/ui/public/cpp/window_tree_client.h" |
17 #include "services/ui/public/interfaces/event_matcher.mojom.h" | 17 #include "services/ui/public/interfaces/event_matcher.mojom.h" |
18 #include "services/ui/public/interfaces/window_tree.mojom.h" | 18 #include "services/ui/public/interfaces/window_tree.mojom.h" |
19 #include "ui/views/mus/clipboard_mus.h" | 19 #include "ui/views/mus/clipboard_mus.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/touch_event_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>; |
30 | 31 |
31 // Env is thread local so that aura may be used on multiple threads. | 32 // Env is thread local so that aura may be used on multiple threads. |
32 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr = | 33 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr = |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 94 } |
94 | 95 |
95 void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) { | 96 void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) { |
96 pointer_watchers_.RemoveObserver(watcher); | 97 pointer_watchers_.RemoveObserver(watcher); |
97 if (!HasPointerWatcher()) { | 98 if (!HasPointerWatcher()) { |
98 // Last PointerWatcher removed, stop the event observer. | 99 // Last PointerWatcher removed, stop the event observer. |
99 client_->SetEventObserver(nullptr); | 100 client_->SetEventObserver(nullptr); |
100 } | 101 } |
101 } | 102 } |
102 | 103 |
| 104 void WindowManagerConnection::AddTouchEventWatcher(TouchEventWatcher* watcher) { |
| 105 bool had_watcher = HasTouchEventWatcher(); |
| 106 touch_event_watchers_.AddObserver(watcher); |
| 107 if (!had_watcher) { |
| 108 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New(); |
| 109 matcher->pointer_kind_matcher = ui::mojom::PointerKindMatcher::New(); |
| 110 matcher->pointer_kind_matcher->pointer_kind = ui::mojom::PointerKind::TOUCH; |
| 111 client_->SetEventObserver(std::move(matcher)); |
| 112 } |
| 113 } |
| 114 |
| 115 void WindowManagerConnection::RemoveTouchEventWatcher( |
| 116 TouchEventWatcher* watcher) { |
| 117 touch_event_watchers_.RemoveObserver(watcher); |
| 118 if (!HasTouchEventWatcher()) { |
| 119 // Last PointerWatcher removed, stop the event observer. |
| 120 client_->SetEventObserver(nullptr); |
| 121 } |
| 122 } |
| 123 |
103 WindowManagerConnection::WindowManagerConnection( | 124 WindowManagerConnection::WindowManagerConnection( |
104 shell::Connector* connector, | 125 shell::Connector* connector, |
105 const shell::Identity& identity) | 126 const shell::Identity& identity) |
106 : connector_(connector), identity_(identity) { | 127 : connector_(connector), identity_(identity) { |
107 lazy_tls_ptr.Pointer()->Set(this); | 128 lazy_tls_ptr.Pointer()->Set(this); |
108 client_.reset(new ui::WindowTreeClient(this, nullptr, nullptr)); | 129 client_.reset(new ui::WindowTreeClient(this, nullptr, nullptr)); |
109 client_->ConnectViaWindowTreeFactory(connector_); | 130 client_->ConnectViaWindowTreeFactory(connector_); |
110 | 131 |
111 screen_.reset(new ScreenMus(this)); | 132 screen_.reset(new ScreenMus(this)); |
112 screen_->Init(connector); | 133 screen_->Init(connector); |
(...skipping 22 matching lines...) Expand all Loading... |
135 } | 156 } |
136 | 157 |
137 bool WindowManagerConnection::HasPointerWatcher() { | 158 bool WindowManagerConnection::HasPointerWatcher() { |
138 // Check to see if we really have any observers left. This doesn't use | 159 // Check to see if we really have any observers left. This doesn't use |
139 // base::ObserverList<>::might_have_observers() because that returns true | 160 // base::ObserverList<>::might_have_observers() because that returns true |
140 // during iteration over the list even when the last observer is removed. | 161 // during iteration over the list even when the last observer is removed. |
141 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); | 162 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); |
142 return !!iterator.GetNext(); | 163 return !!iterator.GetNext(); |
143 } | 164 } |
144 | 165 |
| 166 bool WindowManagerConnection::HasTouchEventWatcher() { |
| 167 // Check to see if we really have any observers left. This doesn't use |
| 168 // base::ObserverList<>::might_have_observers() because that returns true |
| 169 // during iteration over the list even when the last observer is removed. |
| 170 base::ObserverList<TouchEventWatcher>::Iterator iterator( |
| 171 &touch_event_watchers_); |
| 172 return !!iterator.GetNext(); |
| 173 } |
| 174 |
145 void WindowManagerConnection::OnEmbed(ui::Window* root) {} | 175 void WindowManagerConnection::OnEmbed(ui::Window* root) {} |
146 | 176 |
147 void WindowManagerConnection::OnDidDestroyClient(ui::WindowTreeClient* client) { | 177 void WindowManagerConnection::OnDidDestroyClient(ui::WindowTreeClient* client) { |
148 if (client_.get() == client) { | 178 if (client_.get() == client) { |
149 client_.release(); | 179 client_.release(); |
150 } else { | 180 } else { |
151 DCHECK(!client_); | 181 DCHECK(!client_); |
152 } | 182 } |
153 } | 183 } |
154 | 184 |
(...skipping 12 matching lines...) Expand all Loading... |
167 // separately. See http://crbug.com/608547 | 197 // separately. See http://crbug.com/608547 |
168 gfx::Point location_in_screen = event.AsLocatedEvent()->root_location(); | 198 gfx::Point location_in_screen = event.AsLocatedEvent()->root_location(); |
169 if (event.type() == ui::ET_MOUSE_PRESSED) { | 199 if (event.type() == ui::ET_MOUSE_PRESSED) { |
170 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, | 200 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, |
171 OnMousePressed(*event.AsMouseEvent(), location_in_screen, | 201 OnMousePressed(*event.AsMouseEvent(), location_in_screen, |
172 target_widget)); | 202 target_widget)); |
173 } else if (event.type() == ui::ET_TOUCH_PRESSED) { | 203 } else if (event.type() == ui::ET_TOUCH_PRESSED) { |
174 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, | 204 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, |
175 OnTouchPressed(*event.AsTouchEvent(), location_in_screen, | 205 OnTouchPressed(*event.AsTouchEvent(), location_in_screen, |
176 target_widget)); | 206 target_widget)); |
| 207 } else if (event.IsTouchPointerEvent()) { |
| 208 FOR_EACH_OBSERVER(TouchEventWatcher, touch_event_watchers_, |
| 209 OnTouchEventObserved(*event.AsLocatedEvent(), |
| 210 location_in_screen, |
| 211 target_widget)); |
177 } | 212 } |
178 } | 213 } |
179 | 214 |
180 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { | 215 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { |
181 if (client_) | 216 if (client_) |
182 NativeWidgetMus::NotifyFrameChanged(client_.get()); | 217 NativeWidgetMus::NotifyFrameChanged(client_.get()); |
183 } | 218 } |
184 | 219 |
185 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { | 220 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { |
186 return client_->GetCursorScreenPoint(); | 221 return client_->GetCursorScreenPoint(); |
187 } | 222 } |
188 | 223 |
189 } // namespace views | 224 } // namespace views |
OLD | NEW |