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

Unified Diff: ash/pointer_watcher_delegate_aura.cc

Issue 1921673005: mus: Add PointerWatcher for passively observing mouse and touch events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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: ash/pointer_watcher_delegate_aura.cc
diff --git a/ash/pointer_watcher_delegate_aura.cc b/ash/pointer_watcher_delegate_aura.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c00ff1c0263904ebb6b54ab16378b22010c1581b
--- /dev/null
+++ b/ash/pointer_watcher_delegate_aura.cc
@@ -0,0 +1,48 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ash/pointer_watcher_delegate_aura.h"
+
+#include "ash/shell.h"
+#include "ui/events/event.h"
+#include "ui/events/event_constants.h"
+#include "ui/views/pointer_watcher.h"
+
+namespace ash {
+
+PointerWatcherDelegateAura::PointerWatcherDelegateAura() {}
+
+PointerWatcherDelegateAura::~PointerWatcherDelegateAura() {}
sky 2016/04/26 16:55:48 Remove pretargethandler if have observers?
James Cook 2016/04/26 17:42:45 I went with ObserverList check_empty. I think that
+
+void PointerWatcherDelegateAura::AddPointerWatcher(
+ views::PointerWatcher* watcher) {
+ bool had_observers = pointer_watchers_.might_have_observers();
+ pointer_watchers_.AddObserver(watcher);
+ if (!had_observers) {
+ Shell::GetInstance()->AddPreTargetHandler(this);
+ }
+}
+
+void PointerWatcherDelegateAura::RemovePointerWatcher(
+ views::PointerWatcher* watcher) {
+ pointer_watchers_.RemoveObserver(watcher);
+ if (!pointer_watchers_.might_have_observers()) {
+ // We removed the last PointerWatcher, so no need to monitor events.
+ Shell::GetInstance()->RemovePreTargetHandler(this);
+ }
+}
+
+void PointerWatcherDelegateAura::OnMouseEvent(ui::MouseEvent* event) {
+ if (event->type() == ui::ET_MOUSE_PRESSED)
+ FOR_EACH_OBSERVER(views::PointerWatcher, pointer_watchers_,
+ OnMousePressed(*event));
+}
+
+void PointerWatcherDelegateAura::OnTouchEvent(ui::TouchEvent* event) {
+ if (event->type() == ui::ET_TOUCH_PRESSED)
+ FOR_EACH_OBSERVER(views::PointerWatcher, pointer_watchers_,
+ OnTouchPressed(*event));
+}
+
+} // namespace ash
« no previous file with comments | « ash/pointer_watcher_delegate_aura.h ('k') | ash/shell.h » ('j') | ash/shell_delegate.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698