Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: ui/views/mus/window_manager_connection.cc

Issue 2125663002: mus: Add watcher for all touch events. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Overload copy assignment operator for Change struct. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 82
82 void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher) { 83 void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher) {
83 bool had_watcher = HasPointerWatcher(); 84 bool had_watcher = HasPointerWatcher();
84 pointer_watchers_.AddObserver(watcher); 85 pointer_watchers_.AddObserver(watcher);
85 if (!had_watcher) { 86 if (!had_watcher) {
86 // Start a watcher for pointer down. 87 // Start a watcher for pointer down.
87 // TODO(jamescook): Extend event observers to handle multiple event types. 88 // TODO(jamescook): Extend event observers to handle multiple event types.
88 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New(); 89 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New();
89 matcher->type_matcher = ui::mojom::EventTypeMatcher::New(); 90 matcher->type_matcher = ui::mojom::EventTypeMatcher::New();
90 matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN; 91 matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN;
91 client_->SetEventObserver(std::move(matcher)); 92 uint32_t id = client_->AddEventObserver(std::move(matcher));
93 if (id > 0u) {
94 pointer_watcher_observer_id_ = id;
95 }
92 } 96 }
93 } 97 }
94 98
95 void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) { 99 void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) {
96 pointer_watchers_.RemoveObserver(watcher); 100 pointer_watchers_.RemoveObserver(watcher);
97 if (!HasPointerWatcher()) { 101 if (!HasPointerWatcher()) {
98 // Last PointerWatcher removed, stop the event observer. 102 // Last PointerWatcher removed, stop the event observer.
99 client_->SetEventObserver(nullptr); 103 client_->RemoveEventObserver(pointer_watcher_observer_id_);
100 } 104 }
101 } 105 }
102 106
107 void WindowManagerConnection::AddTouchEventWatcher(TouchEventWatcher* watcher) {
108 bool had_watcher = HasTouchEventWatcher();
109 touch_event_watchers_.AddObserver(watcher);
110 if (!had_watcher) {
111 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New();
112 matcher->pointer_kind_matcher = ui::mojom::PointerKindMatcher::New();
113 matcher->pointer_kind_matcher->pointer_kind = ui::mojom::PointerKind::TOUCH;
114 uint32_t id = client_->AddEventObserver(std::move(matcher));
115 if (id > 0u) {
116 touch_event_watcher_observer_id_ = id;
117 }
118 }
119 }
120
121 void WindowManagerConnection::RemoveTouchEventWatcher(
122 TouchEventWatcher* watcher) {
123 touch_event_watchers_.RemoveObserver(watcher);
124 if (!HasTouchEventWatcher()) {
125 // Last PointerWatcher removed, stop the event observer.
126 client_->RemoveEventObserver(touch_event_watcher_observer_id_);
127 }
128 }
129
103 WindowManagerConnection::WindowManagerConnection( 130 WindowManagerConnection::WindowManagerConnection(
104 shell::Connector* connector, 131 shell::Connector* connector,
105 const shell::Identity& identity) 132 const shell::Identity& identity)
106 : connector_(connector), identity_(identity) { 133 : connector_(connector), identity_(identity) {
107 lazy_tls_ptr.Pointer()->Set(this); 134 lazy_tls_ptr.Pointer()->Set(this);
108 client_.reset(new ui::WindowTreeClient(this, nullptr, nullptr)); 135 client_.reset(new ui::WindowTreeClient(this, nullptr, nullptr));
109 client_->ConnectViaWindowTreeFactory(connector_); 136 client_->ConnectViaWindowTreeFactory(connector_);
110 137
111 screen_.reset(new ScreenMus(this)); 138 screen_.reset(new ScreenMus(this));
112 screen_->Init(connector); 139 screen_->Init(connector);
(...skipping 22 matching lines...) Expand all
135 } 162 }
136 163
137 bool WindowManagerConnection::HasPointerWatcher() { 164 bool WindowManagerConnection::HasPointerWatcher() {
138 // Check to see if we really have any observers left. This doesn't use 165 // Check to see if we really have any observers left. This doesn't use
139 // base::ObserverList<>::might_have_observers() because that returns true 166 // base::ObserverList<>::might_have_observers() because that returns true
140 // during iteration over the list even when the last observer is removed. 167 // during iteration over the list even when the last observer is removed.
141 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); 168 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_);
142 return !!iterator.GetNext(); 169 return !!iterator.GetNext();
143 } 170 }
144 171
172 bool WindowManagerConnection::HasTouchEventWatcher() {
173 // Check to see if we really have any observers left. This doesn't use
174 // base::ObserverList<>::might_have_observers() because that returns true
175 // during iteration over the list even when the last observer is removed.
176 base::ObserverList<TouchEventWatcher>::Iterator iterator(
177 &touch_event_watchers_);
178 return !!iterator.GetNext();
179 }
180
145 void WindowManagerConnection::OnEmbed(ui::Window* root) {} 181 void WindowManagerConnection::OnEmbed(ui::Window* root) {}
146 182
147 void WindowManagerConnection::OnDidDestroyClient(ui::WindowTreeClient* client) { 183 void WindowManagerConnection::OnDidDestroyClient(ui::WindowTreeClient* client) {
148 if (client_.get() == client) { 184 if (client_.get() == client) {
149 client_.release(); 185 client_.release();
150 } else { 186 } else {
151 DCHECK(!client_); 187 DCHECK(!client_);
152 } 188 }
153 } 189 }
154 190
(...skipping 13 matching lines...) Expand all
168 gfx::Point location_in_screen = event.AsLocatedEvent()->root_location(); 204 gfx::Point location_in_screen = event.AsLocatedEvent()->root_location();
169 if (event.type() == ui::ET_MOUSE_PRESSED) { 205 if (event.type() == ui::ET_MOUSE_PRESSED) {
170 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, 206 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
171 OnMousePressed(*event.AsMouseEvent(), location_in_screen, 207 OnMousePressed(*event.AsMouseEvent(), location_in_screen,
172 target_widget)); 208 target_widget));
173 } else if (event.type() == ui::ET_TOUCH_PRESSED) { 209 } else if (event.type() == ui::ET_TOUCH_PRESSED) {
174 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, 210 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
175 OnTouchPressed(*event.AsTouchEvent(), location_in_screen, 211 OnTouchPressed(*event.AsTouchEvent(), location_in_screen,
176 target_widget)); 212 target_widget));
177 } 213 }
214
215 // Receives TouchEvent and TouchPointerEvent
216 if (event.IsTouchEvent() || event.IsTouchPointerEvent()) {
217 FOR_EACH_OBSERVER(TouchEventWatcher, touch_event_watchers_,
218 OnTouchEventObserved(*event.AsLocatedEvent(),
219 location_in_screen,
220 target_widget));
221 }
178 } 222 }
179 223
180 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { 224 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() {
181 if (client_) 225 if (client_)
182 NativeWidgetMus::NotifyFrameChanged(client_.get()); 226 NativeWidgetMus::NotifyFrameChanged(client_.get());
183 } 227 }
184 228
185 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { 229 gfx::Point WindowManagerConnection::GetCursorScreenPoint() {
186 return client_->GetCursorScreenPoint(); 230 return client_->GetCursorScreenPoint();
187 } 231 }
188 232
189 } // namespace views 233 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698