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

Unified Diff: services/ui/ws/window_tree.cc

Issue 2183163002: mus: Change PointerWatcher to observe all pointer events, with moves optional. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: pointer enter/exit; has_pointer_watcher etc Created 4 years, 4 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: services/ui/ws/window_tree.cc
diff --git a/services/ui/ws/window_tree.cc b/services/ui/ws/window_tree.cc
index fb500d96ed2be8e87e0f6c59522419159fa153dc..46393414e59b10aa29497e64ff82bbe027833198 100644
--- a/services/ui/ws/window_tree.cc
+++ b/services/ui/ws/window_tree.cc
@@ -700,6 +700,12 @@ void WindowTree::ProcessTransientWindowRemoved(
transient_client_window_id.id);
}
+void WindowTree::SendToPointerWatcher(const ui::Event& event) {
+ if (EventMatchesPointerWatcher(event))
+ client()->OnPointerEventObserved(ui::Event::Clone(event),
+ pointer_watcher_id_);
+}
+
bool WindowTree::ShouldRouteToWindowManager(const ServerWindow* window) const {
if (window_manager_state_)
return false; // We are the window manager, don't route to ourself.
@@ -987,16 +993,22 @@ void WindowTree::DispatchInputEventImpl(ServerWindow* target,
event_source_wms_ = display_root->window_manager_state();
// Should only get events from windows attached to a host.
DCHECK(event_source_wms_);
- bool matched_observer =
- event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event);
+ bool matched_pointer_watcher = EventMatchesPointerWatcher(event);
client()->OnWindowInputEvent(
event_ack_id_, ClientWindowIdForWindow(target).id,
- ui::Event::Clone(event), matched_observer ? event_observer_id_ : 0);
+ ui::Event::Clone(event),
+ matched_pointer_watcher ? pointer_watcher_id_ : 0);
}
-void WindowTree::SendToEventObserver(const ui::Event& event) {
- if (event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event))
- client()->OnEventObserved(ui::Event::Clone(event), event_observer_id_);
+bool WindowTree::EventMatchesPointerWatcher(const ui::Event& event) const {
+ if (pointer_watcher_id_ == 0)
+ return false;
+ if (!event.IsPointerEvent())
+ return false;
+ if (pointer_watcher_want_moves_ && event.type() == ui::ET_POINTER_MOVED)
+ return true;
+ return !pointer_watcher_want_moves_ && (event.type() == ui::ET_POINTER_DOWN ||
sky 2016/08/05 18:06:51 Why do you have the !pointer_watcher_wants_moves_
riajiang 2016/08/05 19:23:59 Oh right! Removed.
+ event.type() == ui::ET_POINTER_UP);
}
void WindowTree::NewWindow(
@@ -1162,50 +1174,19 @@ void WindowTree::ReleaseCapture(uint32_t change_id, Id window_id) {
client()->OnChangeCompleted(change_id, success);
}
-void WindowTree::SetEventObserver(mojom::EventMatcherPtr matcher,
- uint32_t observer_id) {
- if (matcher.is_null() || observer_id == 0) {
- // Clear any existing event observer.
- event_observer_matcher_.reset();
- event_observer_id_ = 0;
- return;
- }
-
- // Do not allow key events to be observed, as a compromised app could register
- // itself as an event observer and spy on keystrokes to another app.
- if (!matcher->type_matcher && !matcher->pointer_kind_matcher) {
- DVLOG(1) << "SetEventObserver must specify an event type.";
+void WindowTree::StartPointerWatcher(bool want_moves,
+ uint32_t pointer_watcher_id) {
+ if (pointer_watcher_id == 0) {
+ StopPointerWatcher();
sky 2016/08/05 18:06:51 Please also log here as the client shouldn't reall
riajiang 2016/08/05 19:23:59 Done.
return;
}
+ pointer_watcher_want_moves_ = want_moves;
+ pointer_watcher_id_ = pointer_watcher_id;
+}
- const ui::mojom::EventType event_type_whitelist[] = {
- ui::mojom::EventType::POINTER_CANCEL, ui::mojom::EventType::POINTER_DOWN,
- ui::mojom::EventType::POINTER_MOVE, ui::mojom::EventType::POINTER_UP,
- ui::mojom::EventType::MOUSE_EXIT, ui::mojom::EventType::WHEEL,
- };
-
- if (matcher->type_matcher) {
- auto* iter =
- std::find(std::begin(event_type_whitelist),
- std::end(event_type_whitelist), matcher->type_matcher->type);
- if (iter == std::end(event_type_whitelist)) {
- DVLOG(1) << "SetEventObserver event type not allowed";
- return;
- }
- }
- if (matcher->pointer_kind_matcher) {
- ui::mojom::PointerKind pointer_kind =
- matcher->pointer_kind_matcher->pointer_kind;
- if (pointer_kind != ui::mojom::PointerKind::MOUSE &&
- pointer_kind != ui::mojom::PointerKind::TOUCH &&
- pointer_kind != ui::mojom::PointerKind::PEN) {
- DVLOG(1) << "SetEventObserver pointer kind not allowed";
- return;
- }
- }
-
- event_observer_matcher_.reset(new EventMatcher(*matcher));
- event_observer_id_ = observer_id;
+void WindowTree::StopPointerWatcher() {
+ pointer_watcher_want_moves_ = false;
+ pointer_watcher_id_ = 0;
}
void WindowTree::SetWindowBounds(uint32_t change_id,

Powered by Google App Engine
This is Rietveld 408576698