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

Side by Side Diff: components/mus/ws/window_tree.cc

Issue 1909733002: mus: Add EventObserver to allow passively listening to UI events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/mus/ws/window_tree.h" 5 #include "components/mus/ws/window_tree.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "components/mus/ws/default_access_policy.h" 15 #include "components/mus/ws/default_access_policy.h"
16 #include "components/mus/ws/display.h" 16 #include "components/mus/ws/display.h"
17 #include "components/mus/ws/display_manager.h" 17 #include "components/mus/ws/display_manager.h"
18 #include "components/mus/ws/event_matcher.h"
18 #include "components/mus/ws/focus_controller.h" 19 #include "components/mus/ws/focus_controller.h"
19 #include "components/mus/ws/operation.h" 20 #include "components/mus/ws/operation.h"
20 #include "components/mus/ws/platform_display.h" 21 #include "components/mus/ws/platform_display.h"
21 #include "components/mus/ws/server_window.h" 22 #include "components/mus/ws/server_window.h"
22 #include "components/mus/ws/server_window_observer.h" 23 #include "components/mus/ws/server_window_observer.h"
23 #include "components/mus/ws/window_manager_state.h" 24 #include "components/mus/ws/window_manager_state.h"
24 #include "components/mus/ws/window_server.h" 25 #include "components/mus/ws/window_server.h"
25 #include "components/mus/ws/window_tree_binding.h" 26 #include "components/mus/ws/window_tree_binding.h"
26 #include "mojo/converters/geometry/geometry_type_converters.h" 27 #include "mojo/converters/geometry/geometry_type_converters.h"
27 #include "mojo/converters/ime/ime_type_converters.h" 28 #include "mojo/converters/ime/ime_type_converters.h"
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 const ui::Event& event) { 948 const ui::Event& event) {
948 DCHECK(!event_ack_id_); 949 DCHECK(!event_ack_id_);
949 // We do not want to create a sequential id for each event, because that can 950 // We do not want to create a sequential id for each event, because that can
950 // leak some information to the client. So instead, manufacture the id 951 // leak some information to the client. So instead, manufacture the id
951 // randomly. 952 // randomly.
952 // TODO(moshayedi): Find a faster way to generate ids. 953 // TODO(moshayedi): Find a faster way to generate ids.
953 event_ack_id_ = 0x1000000 | (rand() & 0xffffff); 954 event_ack_id_ = 0x1000000 | (rand() & 0xffffff);
954 event_source_wms_ = GetWindowManagerState(target); 955 event_source_wms_ = GetWindowManagerState(target);
955 // Should only get events from windows attached to a host. 956 // Should only get events from windows attached to a host.
956 DCHECK(event_source_wms_); 957 DCHECK(event_source_wms_);
957 client()->OnWindowInputEvent(event_ack_id_, 958 bool matched_observer =
958 ClientWindowIdForWindow(target).id, 959 event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event);
959 mojom::Event::From(event)); 960 client()->OnWindowInputEvent(
961 event_ack_id_, ClientWindowIdForWindow(target).id,
962 mojom::Event::From(event), matched_observer ? event_observer_id_ : 0);
963 }
964
965 void WindowTree::SendToEventObserver(const ui::Event& event) {
966 if (event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event))
967 client()->OnEventObserved(mojom::Event::From(event), event_observer_id_);
960 } 968 }
961 969
962 void WindowTree::NewWindow( 970 void WindowTree::NewWindow(
963 uint32_t change_id, 971 uint32_t change_id,
964 Id transport_window_id, 972 Id transport_window_id,
965 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { 973 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) {
966 std::map<std::string, std::vector<uint8_t>> properties; 974 std::map<std::string, std::vector<uint8_t>> properties;
967 if (!transport_properties.is_null()) { 975 if (!transport_properties.is_null()) {
968 properties = 976 properties =
969 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); 977 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
1105 (!current_capture_window || 1113 (!current_capture_window ||
1106 access_policy_->CanSetCapture(current_capture_window)) && 1114 access_policy_->CanSetCapture(current_capture_window)) &&
1107 window == current_capture_window; 1115 window == current_capture_window;
1108 if (success) { 1116 if (success) {
1109 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE); 1117 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE);
1110 success = wms->SetCapture(nullptr, false); 1118 success = wms->SetCapture(nullptr, false);
1111 } 1119 }
1112 client()->OnChangeCompleted(change_id, success); 1120 client()->OnChangeCompleted(change_id, success);
1113 } 1121 }
1114 1122
1123 void WindowTree::SetEventObserver(mojom::EventMatcherPtr matcher,
1124 uint32_t observer_id) {
1125 if (!matcher.is_null() && observer_id != 0) {
1126 event_observer_matcher_.reset(new EventMatcher(*matcher));
1127 event_observer_id_ = observer_id;
1128 } else {
1129 event_observer_matcher_.reset();
1130 event_observer_id_ = 0;
1131 }
1132 }
1133
1115 void WindowTree::SetWindowBounds(uint32_t change_id, 1134 void WindowTree::SetWindowBounds(uint32_t change_id,
1116 Id window_id, 1135 Id window_id,
1117 mojo::RectPtr bounds) { 1136 mojo::RectPtr bounds) {
1118 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1137 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1119 if (window && ShouldRouteToWindowManager(window)) { 1138 if (window && ShouldRouteToWindowManager(window)) {
1120 const uint32_t wm_change_id = 1139 const uint32_t wm_change_id =
1121 window_server_->GenerateWindowManagerChangeId(this, change_id); 1140 window_server_->GenerateWindowManagerChangeId(this, change_id);
1122 // |window_id| may be a client id, use the id from the window to ensure 1141 // |window_id| may be a client id, use the id from the window to ensure
1123 // the windowmanager doesn't get an id it doesn't know about. 1142 // the windowmanager doesn't get an id it doesn't know about.
1124 WindowManagerState* wms = display_manager() 1143 WindowManagerState* wms = display_manager()
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1412 } 1431 }
1413 1432
1414 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( 1433 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy(
1415 const ServerWindow* window) const { 1434 const ServerWindow* window) const {
1416 WindowTree* tree = window_server_->GetTreeWithRoot(window); 1435 WindowTree* tree = window_server_->GetTreeWithRoot(window);
1417 return tree && tree != this; 1436 return tree && tree != this;
1418 } 1437 }
1419 1438
1420 } // namespace ws 1439 } // namespace ws
1421 } // namespace mus 1440 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698