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

Unified 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: 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 side-by-side diff with in-line comments
Download patch
Index: ui/views/mus/window_manager_connection.cc
diff --git a/ui/views/mus/window_manager_connection.cc b/ui/views/mus/window_manager_connection.cc
index d5f3670520cdf5f3aef280027b0d4184d1b8cbd6..1cbbc1d925b801aa53da0f21cc2b640c3b8022d4 100644
--- a/ui/views/mus/window_manager_connection.cc
+++ b/ui/views/mus/window_manager_connection.cc
@@ -20,6 +20,7 @@
#include "ui/views/mus/native_widget_mus.h"
#include "ui/views/mus/screen_mus.h"
#include "ui/views/pointer_watcher.h"
+#include "ui/views/touch_event_watcher.h"
#include "ui/views/views_delegate.h"
namespace views {
@@ -100,6 +101,26 @@ void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) {
}
}
+void WindowManagerConnection::AddTouchEventWatcher(TouchEventWatcher* watcher) {
+ bool had_watcher = HasTouchEventWatcher();
+ touch_event_watchers_.AddObserver(watcher);
+ if (!had_watcher) {
+ ui::mojom::EventMatcherPtr matcher = ui::mojom::EventMatcher::New();
+ matcher->pointer_kind_matcher = ui::mojom::PointerKindMatcher::New();
+ matcher->pointer_kind_matcher->pointer_kind = ui::mojom::PointerKind::TOUCH;
+ client_->SetEventObserver(std::move(matcher));
sky 2016/07/06 20:22:02 Notice how this now conflicts with 92. In an effor
riajiang 2016/07/08 02:51:40 Done.
+ }
+}
+
+void WindowManagerConnection::RemoveTouchEventWatcher(
+ TouchEventWatcher* watcher) {
+ touch_event_watchers_.RemoveObserver(watcher);
+ if (!HasTouchEventWatcher()) {
+ // Last PointerWatcher removed, stop the event observer.
+ client_->SetEventObserver(nullptr);
+ }
+}
+
WindowManagerConnection::WindowManagerConnection(
shell::Connector* connector,
const shell::Identity& identity)
@@ -142,6 +163,15 @@ bool WindowManagerConnection::HasPointerWatcher() {
return !!iterator.GetNext();
}
+bool WindowManagerConnection::HasTouchEventWatcher() {
+ // Check to see if we really have any observers left. This doesn't use
+ // base::ObserverList<>::might_have_observers() because that returns true
+ // during iteration over the list even when the last observer is removed.
+ base::ObserverList<TouchEventWatcher>::Iterator iterator(
+ &touch_event_watchers_);
+ return !!iterator.GetNext();
+}
+
void WindowManagerConnection::OnEmbed(ui::Window* root) {}
void WindowManagerConnection::OnDidDestroyClient(ui::WindowTreeClient* client) {
@@ -174,6 +204,11 @@ void WindowManagerConnection::OnEventObserved(const ui::Event& event,
FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
OnTouchPressed(*event.AsTouchEvent(), location_in_screen,
target_widget));
+ } else if (event.IsTouchPointerEvent()) {
+ FOR_EACH_OBSERVER(TouchEventWatcher, touch_event_watchers_,
+ OnTouchEventObserved(*event.AsLocatedEvent(),
+ location_in_screen,
+ target_widget));
}
}

Powered by Google App Engine
This is Rietveld 408576698