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

Unified Diff: ui/views/mus/window_manager_connection.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: views_exports.cc, observer list iteration 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
« no previous file with comments | « ui/views/mus/window_manager_connection.h ('k') | ui/views/mus/window_manager_connection_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 cfa0a2b2322f11e0a66845b681384155f7232661..0fd84a60d89edc63775be533801a47497c0678f6 100644
--- a/ui/views/mus/window_manager_connection.cc
+++ b/ui/views/mus/window_manager_connection.cc
@@ -12,6 +12,7 @@
#include "components/mus/public/cpp/window.h"
#include "components/mus/public/cpp/window_property.h"
#include "components/mus/public/cpp/window_tree_connection.h"
+#include "components/mus/public/interfaces/input_event_matcher.mojom.h"
#include "components/mus/public/interfaces/window_tree.mojom.h"
#include "mojo/converters/geometry/geometry_type_converters.h"
#include "services/shell/public/cpp/connection.h"
@@ -19,6 +20,7 @@
#include "ui/events/devices/device_data_manager.h"
#include "ui/views/mus/native_widget_mus.h"
#include "ui/views/mus/screen_mus.h"
+#include "ui/views/pointer_watcher.h"
#include "ui/views/views_delegate.h"
namespace views {
@@ -75,6 +77,27 @@ NativeWidget* WindowManagerConnection::CreateNativeWidgetMus(
mus::mojom::SurfaceType::DEFAULT);
}
+void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher) {
+ bool had_watcher = HasPointerWatcher();
James Cook 2016/04/26 23:19:05 I believe you have to use iterator.GetNext() in bo
+ pointer_watchers_.AddObserver(watcher);
+ if (!had_watcher) {
+ // Start a watcher for pointer down.
+ // TODO(jamescook): Extend event observers to handle multiple event types.
+ mus::mojom::EventMatcherPtr matcher = mus::mojom::EventMatcher::New();
+ matcher->type_matcher = mus::mojom::EventTypeMatcher::New();
+ matcher->type_matcher->type = mus::mojom::EventType::POINTER_DOWN;
+ window_tree_connection_->SetEventObserver(std::move(matcher));
+ }
+}
+
+void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) {
+ pointer_watchers_.RemoveObserver(watcher);
+ if (!HasPointerWatcher()) {
+ // Last PointerWatcher removed, stop the event observer.
+ window_tree_connection_->SetEventObserver(nullptr);
+ }
+}
+
WindowManagerConnection::WindowManagerConnection(
shell::Connector* connector,
const shell::Identity& identity)
@@ -106,11 +129,29 @@ WindowManagerConnection::~WindowManagerConnection() {
ui::DeviceDataManager::DeleteInstance();
}
+bool WindowManagerConnection::HasPointerWatcher() {
+ // 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<PointerWatcher>::Iterator iterator(&pointer_watchers_);
+ return iterator.GetNext();
+}
+
void WindowManagerConnection::OnEmbed(mus::Window* root) {}
void WindowManagerConnection::OnConnectionLost(
mus::WindowTreeConnection* connection) {}
+void WindowManagerConnection::OnEventObserved(const ui::Event& event) {
+ if (event.type() == ui::ET_MOUSE_PRESSED) {
+ FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
+ OnMousePressed(*event.AsMouseEvent()));
+ } else if (event.type() == ui::ET_TOUCH_PRESSED) {
+ FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
+ OnTouchPressed(*event.AsTouchEvent()));
+ }
+}
+
void WindowManagerConnection::OnWindowManagerFrameValuesChanged() {
if (window_tree_connection_)
NativeWidgetMus::NotifyFrameChanged(window_tree_connection_.get());
« no previous file with comments | « ui/views/mus/window_manager_connection.h ('k') | ui/views/mus/window_manager_connection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698