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

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: DCHECK 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 3936c25b2b88f41ee837aab2f68ccb27e4de57dd..088224b1ab6c5af820ed0945684af69d2c6170dd 100644
--- a/ui/views/mus/window_manager_connection.cc
+++ b/ui/views/mus/window_manager_connection.cc
@@ -21,6 +21,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 {
@@ -81,6 +82,8 @@ NativeWidget* WindowManagerConnection::CreateNativeWidgetMus(
}
void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher) {
+ // TODO(riajiang): Support multiple event matchers (crbug.com/627146).
+ DCHECK(!HasTouchEventWatcher());
bool had_watcher = HasPointerWatcher();
pointer_watchers_.AddObserver(watcher);
if (!had_watcher) {
@@ -101,6 +104,28 @@ void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) {
}
}
+void WindowManagerConnection::AddTouchEventWatcher(TouchEventWatcher* watcher) {
+ // TODO(riajiang): Support multiple event matchers (crbug.com/627146).
+ DCHECK(!HasPointerWatcher());
+ 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));
+ }
+}
+
+void WindowManagerConnection::RemoveTouchEventWatcher(
+ TouchEventWatcher* watcher) {
+ touch_event_watchers_.RemoveObserver(watcher);
+ if (!HasTouchEventWatcher()) {
+ // Last PointerWatcher removed, stop the event observer.
+ client_->SetEventObserver(nullptr);
+ }
+}
+
const std::set<ui::Window*>& WindowManagerConnection::GetRoots() const {
return client_->GetRoots();
}
@@ -151,6 +176,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) {
@@ -175,14 +209,23 @@ void WindowManagerConnection::OnEventObserved(const ui::Event& event,
// to store screen coordinates. Screen coordinates really should be returned
// separately. See http://crbug.com/608547
gfx::Point location_in_screen = event.AsLocatedEvent()->root_location();
- if (event.type() == ui::ET_MOUSE_PRESSED) {
- FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
- OnMousePressed(*event.AsMouseEvent(), location_in_screen,
- target_widget));
- } else if (event.type() == ui::ET_TOUCH_PRESSED) {
- FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
- OnTouchPressed(*event.AsTouchEvent(), location_in_screen,
- target_widget));
+ if (HasPointerWatcher()) {
+ if (event.type() == ui::ET_MOUSE_PRESSED) {
+ FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
+ OnMousePressed(*event.AsMouseEvent(),
+ location_in_screen, target_widget));
+ } else if (event.type() == ui::ET_TOUCH_PRESSED) {
+ FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
+ OnTouchPressed(*event.AsTouchEvent(),
+ location_in_screen, target_widget));
+ }
+ } else {
+ DCHECK(HasTouchEventWatcher());
+ // Receives TouchEvent and TouchPointerEvent
msw 2016/07/12 22:23:11 nit: add a trailing period; optionally expand or r
riajiang 2016/07/13 15:40:21 Removed. The DCHECK after this comment should be e
+ DCHECK(event.IsTouchEvent() || event.IsTouchPointerEvent());
+ FOR_EACH_OBSERVER(
+ TouchEventWatcher, touch_event_watchers_,
+ OnTouchEventObserved(*event.AsLocatedEvent(), target_widget));
}
}

Powered by Google App Engine
This is Rietveld 408576698