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

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: Change back to support only one event matcher with TODOs and DCHECKs. 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/common/gpu_service.h" 13 #include "services/ui/common/gpu_service.h"
14 #include "services/ui/public/cpp/property_type_converters.h" 14 #include "services/ui/public/cpp/property_type_converters.h"
15 #include "services/ui/public/cpp/window.h" 15 #include "services/ui/public/cpp/window.h"
16 #include "services/ui/public/cpp/window_property.h" 16 #include "services/ui/public/cpp/window_property.h"
17 #include "services/ui/public/cpp/window_tree_client.h" 17 #include "services/ui/public/cpp/window_tree_client.h"
18 #include "services/ui/public/interfaces/event_matcher.mojom.h" 18 #include "services/ui/public/interfaces/event_matcher.mojom.h"
19 #include "services/ui/public/interfaces/window_tree.mojom.h" 19 #include "services/ui/public/interfaces/window_tree.mojom.h"
20 #include "ui/views/mus/clipboard_mus.h" 20 #include "ui/views/mus/clipboard_mus.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/touch_event_watcher.h"
24 #include "ui/views/views_delegate.h" 25 #include "ui/views/views_delegate.h"
25 26
26 namespace views { 27 namespace views {
27 namespace { 28 namespace {
28 29
29 using WindowManagerConnectionPtr = 30 using WindowManagerConnectionPtr =
30 base::ThreadLocalPointer<views::WindowManagerConnection>; 31 base::ThreadLocalPointer<views::WindowManagerConnection>;
31 32
32 // Env is thread local so that aura may be used on multiple threads. 33 // Env is thread local so that aura may be used on multiple threads.
33 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr = 34 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr =
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 return nullptr; 75 return nullptr;
75 std::map<std::string, std::vector<uint8_t>> properties = props; 76 std::map<std::string, std::vector<uint8_t>> properties = props;
76 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties); 77 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties);
77 properties[ui::mojom::WindowManager::kAppID_Property] = 78 properties[ui::mojom::WindowManager::kAppID_Property] =
78 mojo::ConvertTo<std::vector<uint8_t>>(identity_.name()); 79 mojo::ConvertTo<std::vector<uint8_t>>(identity_.name());
79 return new NativeWidgetMus(delegate, connector_, NewWindow(properties), 80 return new NativeWidgetMus(delegate, connector_, NewWindow(properties),
80 ui::mojom::SurfaceType::DEFAULT); 81 ui::mojom::SurfaceType::DEFAULT);
81 } 82 }
82 83
83 void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher) { 84 void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher) {
85 // TODO(riajiang): Support multiple event matchers (issue 627146).
sadrul 2016/07/11 20:47:52 s#issue 627146#crbug.com/627146#
riajiang 2016/07/11 21:51:40 Done.
86 DCHECK(!HasTouchEventWatcher());
84 bool had_watcher = HasPointerWatcher(); 87 bool had_watcher = HasPointerWatcher();
85 pointer_watchers_.AddObserver(watcher); 88 pointer_watchers_.AddObserver(watcher);
86 if (!had_watcher) { 89 if (!had_watcher) {
87 // Start a watcher for pointer down. 90 // Start a watcher for pointer down.
88 // TODO(jamescook): Extend event observers to handle multiple event types. 91 // TODO(jamescook): Extend event observers to handle multiple event types.
89 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New(); 92 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New();
90 matcher->type_matcher = ui::mojom::EventTypeMatcher::New(); 93 matcher->type_matcher = ui::mojom::EventTypeMatcher::New();
91 matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN; 94 matcher->type_matcher->type = ui::mojom::EventType::POINTER_DOWN;
92 client_->SetEventObserver(std::move(matcher)); 95 client_->SetEventObserver(std::move(matcher));
93 } 96 }
94 } 97 }
95 98
96 void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) { 99 void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) {
97 pointer_watchers_.RemoveObserver(watcher); 100 pointer_watchers_.RemoveObserver(watcher);
98 if (!HasPointerWatcher()) { 101 if (!HasPointerWatcher()) {
99 // Last PointerWatcher removed, stop the event observer. 102 // Last PointerWatcher removed, stop the event observer.
100 client_->SetEventObserver(nullptr); 103 client_->SetEventObserver(nullptr);
101 } 104 }
102 } 105 }
103 106
107 void WindowManagerConnection::AddTouchEventWatcher(TouchEventWatcher* watcher) {
108 // TODO(riajiang): Support multiple event matchers (issue 627146).
109 DCHECK(!HasPointerWatcher());
110 bool had_watcher = HasTouchEventWatcher();
111 touch_event_watchers_.AddObserver(watcher);
112 if (!had_watcher) {
113 ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New();
114 matcher->pointer_kind_matcher = ui::mojom::PointerKindMatcher::New();
115 matcher->pointer_kind_matcher->pointer_kind = ui::mojom::PointerKind::TOUCH;
116 client_->SetEventObserver(std::move(matcher));
117 }
118 }
119
120 void WindowManagerConnection::RemoveTouchEventWatcher(
121 TouchEventWatcher* watcher) {
122 touch_event_watchers_.RemoveObserver(watcher);
123 if (!HasTouchEventWatcher()) {
124 // Last PointerWatcher removed, stop the event observer.
125 client_->SetEventObserver(nullptr);
126 }
127 }
128
104 const std::set<ui::Window*>& WindowManagerConnection::GetRoots() const { 129 const std::set<ui::Window*>& WindowManagerConnection::GetRoots() const {
105 return client_->GetRoots(); 130 return client_->GetRoots();
106 } 131 }
107 132
108 WindowManagerConnection::WindowManagerConnection( 133 WindowManagerConnection::WindowManagerConnection(
109 shell::Connector* connector, 134 shell::Connector* connector,
110 const shell::Identity& identity) 135 const shell::Identity& identity)
111 : connector_(connector), identity_(identity) { 136 : connector_(connector), identity_(identity) {
112 lazy_tls_ptr.Pointer()->Set(this); 137 lazy_tls_ptr.Pointer()->Set(this);
113 138
(...skipping 30 matching lines...) Expand all
144 } 169 }
145 170
146 bool WindowManagerConnection::HasPointerWatcher() { 171 bool WindowManagerConnection::HasPointerWatcher() {
147 // Check to see if we really have any observers left. This doesn't use 172 // Check to see if we really have any observers left. This doesn't use
148 // base::ObserverList<>::might_have_observers() because that returns true 173 // base::ObserverList<>::might_have_observers() because that returns true
149 // during iteration over the list even when the last observer is removed. 174 // during iteration over the list even when the last observer is removed.
150 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); 175 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_);
151 return !!iterator.GetNext(); 176 return !!iterator.GetNext();
152 } 177 }
153 178
179 bool WindowManagerConnection::HasTouchEventWatcher() {
180 // Check to see if we really have any observers left. This doesn't use
181 // base::ObserverList<>::might_have_observers() because that returns true
182 // during iteration over the list even when the last observer is removed.
183 base::ObserverList<TouchEventWatcher>::Iterator iterator(
184 &touch_event_watchers_);
185 return !!iterator.GetNext();
186 }
187
154 void WindowManagerConnection::OnEmbed(ui::Window* root) {} 188 void WindowManagerConnection::OnEmbed(ui::Window* root) {}
155 189
156 void WindowManagerConnection::OnDidDestroyClient(ui::WindowTreeClient* client) { 190 void WindowManagerConnection::OnDidDestroyClient(ui::WindowTreeClient* client) {
157 if (client_.get() == client) { 191 if (client_.get() == client) {
158 client_.release(); 192 client_.release();
159 } else { 193 } else {
160 DCHECK(!client_); 194 DCHECK(!client_);
161 } 195 }
162 } 196 }
163 197
(...skipping 13 matching lines...) Expand all
177 gfx::Point location_in_screen = event.AsLocatedEvent()->root_location(); 211 gfx::Point location_in_screen = event.AsLocatedEvent()->root_location();
178 if (event.type() == ui::ET_MOUSE_PRESSED) { 212 if (event.type() == ui::ET_MOUSE_PRESSED) {
179 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, 213 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
180 OnMousePressed(*event.AsMouseEvent(), location_in_screen, 214 OnMousePressed(*event.AsMouseEvent(), location_in_screen,
181 target_widget)); 215 target_widget));
182 } else if (event.type() == ui::ET_TOUCH_PRESSED) { 216 } else if (event.type() == ui::ET_TOUCH_PRESSED) {
183 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, 217 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
184 OnTouchPressed(*event.AsTouchEvent(), location_in_screen, 218 OnTouchPressed(*event.AsTouchEvent(), location_in_screen,
185 target_widget)); 219 target_widget));
186 } 220 }
221
222 // Receives TouchEvent and TouchPointerEvent
223 if (event.IsTouchEvent() || event.IsTouchPointerEvent()) {
224 FOR_EACH_OBSERVER(TouchEventWatcher, touch_event_watchers_,
225 OnTouchEventObserved(*event.AsLocatedEvent(),
226 location_in_screen, target_widget));
227 }
sadrul 2016/07/11 20:47:52 Change to: if (HasPointerWatcher()) { ... tr
riajiang 2016/07/11 21:51:40 Done.
187 } 228 }
188 229
189 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { 230 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() {
190 if (client_) 231 if (client_)
191 NativeWidgetMus::NotifyFrameChanged(client_.get()); 232 NativeWidgetMus::NotifyFrameChanged(client_.get());
192 } 233 }
193 234
194 gfx::Point WindowManagerConnection::GetCursorScreenPoint() { 235 gfx::Point WindowManagerConnection::GetCursorScreenPoint() {
195 return client_->GetCursorScreenPoint(); 236 return client_->GetCursorScreenPoint();
196 } 237 }
197 238
198 } // namespace views 239 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698