OLD | NEW |
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 "services/ui/public/cpp/window_tree_client.h" | 5 #include "services/ui/public/cpp/window_tree_client.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 // We raced initialization. Return (0, 0). | 620 // We raced initialization. Return (0, 0). |
621 if (!cursor_location_memory()) | 621 if (!cursor_location_memory()) |
622 return gfx::Point(); | 622 return gfx::Point(); |
623 | 623 |
624 base::subtle::Atomic32 location = | 624 base::subtle::Atomic32 location = |
625 base::subtle::NoBarrier_Load(cursor_location_memory()); | 625 base::subtle::NoBarrier_Load(cursor_location_memory()); |
626 return gfx::Point(static_cast<int16_t>(location >> 16), | 626 return gfx::Point(static_cast<int16_t>(location >> 16), |
627 static_cast<int16_t>(location & 0xFFFF)); | 627 static_cast<int16_t>(location & 0xFFFF)); |
628 } | 628 } |
629 | 629 |
630 void WindowTreeClient::SetEventObserver(mojom::EventMatcherPtr matcher) { | 630 uint32_t WindowTreeClient::AddEventObserver(mojom::EventMatcherPtr matcher) { |
631 if (matcher.is_null()) { | 631 if (!matcher.is_null()) { |
632 has_event_observer_ = false; | |
633 tree_->SetEventObserver(nullptr, 0u); | |
634 } else { | |
635 has_event_observer_ = true; | |
636 event_observer_id_++; | 632 event_observer_id_++; |
637 tree_->SetEventObserver(std::move(matcher), event_observer_id_); | 633 tree_->AddEventObserver(std::move(matcher), event_observer_id_); |
| 634 event_observer_ids_.push_back(event_observer_id_); |
| 635 return event_observer_id_; |
| 636 } |
| 637 return 0u; |
| 638 } |
| 639 |
| 640 void WindowTreeClient::RemoveEventObserver(uint32_t event_observer_id) { |
| 641 std::vector<uint32_t>::iterator it; |
| 642 it = find(event_observer_ids_.begin(), event_observer_ids_.end(), |
| 643 event_observer_id); |
| 644 if (it != event_observer_ids_.end()) { |
| 645 event_observer_ids_.erase(it); |
| 646 tree_->RemoveEventObserver(event_observer_id); |
638 } | 647 } |
639 } | 648 } |
640 | 649 |
641 void WindowTreeClient::PerformWindowMove( | 650 void WindowTreeClient::PerformWindowMove( |
642 Window* window, | 651 Window* window, |
643 ui::mojom::MoveLoopSource source, | 652 ui::mojom::MoveLoopSource source, |
644 const gfx::Point& cursor_location, | 653 const gfx::Point& cursor_location, |
645 const base::Callback<void(bool)>& callback) { | 654 const base::Callback<void(bool)>& callback) { |
646 DCHECK(on_current_move_finished_.is_null()); | 655 DCHECK(on_current_move_finished_.is_null()); |
647 on_current_move_finished_ = callback; | 656 on_current_move_finished_ = callback; |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
957 if (!window) | 966 if (!window) |
958 return; | 967 return; |
959 | 968 |
960 InFlightPropertyChange new_change(window, name, new_data); | 969 InFlightPropertyChange new_change(window, name, new_data); |
961 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 970 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
962 return; | 971 return; |
963 | 972 |
964 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); | 973 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); |
965 } | 974 } |
966 | 975 |
967 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, | 976 void WindowTreeClient::OnWindowInputEvent( |
968 Id window_id, | 977 uint32_t event_id, Id window_id, std::unique_ptr<ui::Event> event, |
969 std::unique_ptr<ui::Event> event, | 978 mojo::Array<uint32_t> event_observer_ids) { |
970 uint32_t event_observer_id) { | |
971 DCHECK(event); | 979 DCHECK(event); |
972 Window* window = GetWindowByServerId(window_id); // May be null. | 980 Window* window = GetWindowByServerId(window_id); // May be null. |
973 | 981 |
974 // Non-zero event_observer_id means it matched an event observer on the | 982 // Non-zero event_observer_id means it matched an event observer on the |
975 // server. | 983 // server. |
976 if (event_observer_id != 0 && has_event_observer_ && | 984 for (uint32_t id : event_observer_ids) { |
977 event_observer_id == event_observer_id_) | 985 if (id != 0 && MatchEventObserverId(id)) { |
978 delegate_->OnEventObserved(*event.get(), window); | 986 delegate_->OnEventObserved(*event.get(), window); |
| 987 break; |
| 988 } |
| 989 } |
979 | 990 |
980 if (!window || !window->input_event_handler_) { | 991 if (!window || !window->input_event_handler_) { |
981 tree_->OnWindowInputEventAck(event_id, mojom::EventResult::UNHANDLED); | 992 tree_->OnWindowInputEventAck(event_id, mojom::EventResult::UNHANDLED); |
982 return; | 993 return; |
983 } | 994 } |
984 | 995 |
985 std::unique_ptr<base::Callback<void(mojom::EventResult)>> ack_callback( | 996 std::unique_ptr<base::Callback<void(mojom::EventResult)>> ack_callback( |
986 new base::Callback<void(mojom::EventResult)>( | 997 new base::Callback<void(mojom::EventResult)>( |
987 base::Bind(&mojom::WindowTree::OnWindowInputEventAck, | 998 base::Bind(&mojom::WindowTree::OnWindowInputEventAck, |
988 base::Unretained(tree_), event_id))); | 999 base::Unretained(tree_), event_id))); |
(...skipping 10 matching lines...) Expand all Loading... |
999 window->input_event_handler_->OnWindowInputEvent(window, *event.get(), | 1010 window->input_event_handler_->OnWindowInputEvent(window, *event.get(), |
1000 &ack_callback); | 1011 &ack_callback); |
1001 } | 1012 } |
1002 | 1013 |
1003 // The handler did not take ownership of the callback, so we send the ack, | 1014 // The handler did not take ownership of the callback, so we send the ack, |
1004 // marking the event as not consumed. | 1015 // marking the event as not consumed. |
1005 if (ack_callback) | 1016 if (ack_callback) |
1006 ack_callback->Run(mojom::EventResult::UNHANDLED); | 1017 ack_callback->Run(mojom::EventResult::UNHANDLED); |
1007 } | 1018 } |
1008 | 1019 |
1009 void WindowTreeClient::OnEventObserved(std::unique_ptr<ui::Event> event, | 1020 void WindowTreeClient::OnEventObserved( |
1010 uint32_t event_observer_id) { | 1021 std::unique_ptr<ui::Event> event, mojo::Array<uint32_t> event_observer_ids) { |
1011 DCHECK(event); | 1022 DCHECK(event); |
1012 if (has_event_observer_ && event_observer_id == event_observer_id_) | 1023 for (uint32_t id : event_observer_ids) { |
1013 delegate_->OnEventObserved(*event.get(), nullptr /* target */); | 1024 if (MatchEventObserverId(id)) { |
| 1025 delegate_->OnEventObserved(*event.get(), nullptr /* target */); |
| 1026 break; |
| 1027 } |
| 1028 } |
1014 } | 1029 } |
1015 | 1030 |
1016 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { | 1031 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { |
1017 Window* focused_window = GetWindowByServerId(focused_window_id); | 1032 Window* focused_window = GetWindowByServerId(focused_window_id); |
1018 InFlightFocusChange new_change(this, focused_window); | 1033 InFlightFocusChange new_change(this, focused_window); |
1019 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1034 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
1020 return; | 1035 return; |
1021 | 1036 |
1022 LocalSetFocus(focused_window); | 1037 LocalSetFocus(focused_window); |
1023 } | 1038 } |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1256 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
1242 Window* window, | 1257 Window* window, |
1243 const gfx::Vector2d& offset, | 1258 const gfx::Vector2d& offset, |
1244 const gfx::Insets& hit_area) { | 1259 const gfx::Insets& hit_area) { |
1245 if (window_manager_internal_client_) { | 1260 if (window_manager_internal_client_) { |
1246 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1261 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
1247 server_id(window), offset.x(), offset.y(), hit_area); | 1262 server_id(window), offset.x(), offset.y(), hit_area); |
1248 } | 1263 } |
1249 } | 1264 } |
1250 | 1265 |
| 1266 bool WindowTreeClient::MatchEventObserverId(uint32_t event_observer_id) { |
| 1267 std::vector<uint32_t>::iterator it; |
| 1268 it = find(event_observer_ids_.begin(), event_observer_ids_.end(), |
| 1269 event_observer_id); |
| 1270 if (it != event_observer_ids_.end()) { |
| 1271 return true; |
| 1272 } |
| 1273 return false; |
| 1274 } |
| 1275 |
1251 } // namespace ui | 1276 } // namespace ui |
OLD | NEW |