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 608 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
619 // We raced initialization. Return (0, 0). | 619 // We raced initialization. Return (0, 0). |
620 if (!cursor_location_memory()) | 620 if (!cursor_location_memory()) |
621 return gfx::Point(); | 621 return gfx::Point(); |
622 | 622 |
623 base::subtle::Atomic32 location = | 623 base::subtle::Atomic32 location = |
624 base::subtle::NoBarrier_Load(cursor_location_memory()); | 624 base::subtle::NoBarrier_Load(cursor_location_memory()); |
625 return gfx::Point(static_cast<int16_t>(location >> 16), | 625 return gfx::Point(static_cast<int16_t>(location >> 16), |
626 static_cast<int16_t>(location & 0xFFFF)); | 626 static_cast<int16_t>(location & 0xFFFF)); |
627 } | 627 } |
628 | 628 |
629 void WindowTreeClient::SetEventObserver(mojom::EventMatcherPtr matcher) { | 629 void WindowTreeClient::StartPointerWatcher(bool want_moves) { |
630 if (matcher.is_null()) { | 630 if (has_pointer_watcher_) |
631 has_event_observer_ = false; | 631 StopPointerWatcher(); |
632 tree_->SetEventObserver(nullptr, 0u); | 632 has_pointer_watcher_ = true; |
sky
2016/08/05 18:06:50
Sorry, missed this earlier. Isn't pointer_watcher_
riajiang
2016/08/05 19:23:59
As discussed, we'll keep has_pointer_watcher since
| |
633 } else { | 633 pointer_watcher_id_++; |
sky
2016/08/05 18:06:50
Make sure to skip over 0 if you wrap.
riajiang
2016/08/05 19:23:59
Done.
| |
634 has_event_observer_ = true; | 634 tree_->StartPointerWatcher(want_moves, pointer_watcher_id_); |
635 event_observer_id_++; | 635 } |
636 tree_->SetEventObserver(std::move(matcher), event_observer_id_); | 636 |
637 } | 637 void WindowTreeClient::StopPointerWatcher() { |
638 DCHECK(has_pointer_watcher_); | |
639 tree_->StopPointerWatcher(); | |
640 has_pointer_watcher_ = false; | |
638 } | 641 } |
639 | 642 |
640 void WindowTreeClient::PerformWindowMove( | 643 void WindowTreeClient::PerformWindowMove( |
641 Window* window, | 644 Window* window, |
642 ui::mojom::MoveLoopSource source, | 645 ui::mojom::MoveLoopSource source, |
643 const gfx::Point& cursor_location, | 646 const gfx::Point& cursor_location, |
644 const base::Callback<void(bool)>& callback) { | 647 const base::Callback<void(bool)>& callback) { |
645 DCHECK(on_current_move_finished_.is_null()); | 648 DCHECK(on_current_move_finished_.is_null()); |
646 on_current_move_finished_ = callback; | 649 on_current_move_finished_ = callback; |
647 | 650 |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
965 InFlightPropertyChange new_change(window, name, new_data); | 968 InFlightPropertyChange new_change(window, name, new_data); |
966 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 969 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
967 return; | 970 return; |
968 | 971 |
969 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); | 972 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); |
970 } | 973 } |
971 | 974 |
972 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, | 975 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, |
973 Id window_id, | 976 Id window_id, |
974 std::unique_ptr<ui::Event> event, | 977 std::unique_ptr<ui::Event> event, |
975 uint32_t event_observer_id) { | 978 uint32_t pointer_watcher_id) { |
976 DCHECK(event); | 979 DCHECK(event); |
977 Window* window = GetWindowByServerId(window_id); // May be null. | 980 Window* window = GetWindowByServerId(window_id); // May be null. |
978 | 981 |
979 // Non-zero event_observer_id means it matched an event observer on the | 982 // Non-zero pointer_watcher_id means it matched a pointer watcher on the |
980 // server. | 983 // server. |
981 if (event_observer_id != 0 && has_event_observer_ && | 984 if (pointer_watcher_id_ != 0 && has_pointer_watcher_ && |
982 event_observer_id == event_observer_id_) | 985 pointer_watcher_id == pointer_watcher_id_) { |
983 delegate_->OnEventObserved(*event.get(), window); | 986 DCHECK(event->IsPointerEvent()); |
987 delegate_->OnPointerEventObserved(*event->AsPointerEvent(), window); | |
988 } | |
984 | 989 |
985 if (!window || !window->input_event_handler_) { | 990 if (!window || !window->input_event_handler_) { |
986 tree_->OnWindowInputEventAck(event_id, mojom::EventResult::UNHANDLED); | 991 tree_->OnWindowInputEventAck(event_id, mojom::EventResult::UNHANDLED); |
987 return; | 992 return; |
988 } | 993 } |
989 | 994 |
990 std::unique_ptr<base::Callback<void(mojom::EventResult)>> ack_callback( | 995 std::unique_ptr<base::Callback<void(mojom::EventResult)>> ack_callback( |
991 new base::Callback<void(mojom::EventResult)>( | 996 new base::Callback<void(mojom::EventResult)>( |
992 base::Bind(&mojom::WindowTree::OnWindowInputEventAck, | 997 base::Bind(&mojom::WindowTree::OnWindowInputEventAck, |
993 base::Unretained(tree_), event_id))); | 998 base::Unretained(tree_), event_id))); |
(...skipping 10 matching lines...) Expand all Loading... | |
1004 window->input_event_handler_->OnWindowInputEvent(window, *event.get(), | 1009 window->input_event_handler_->OnWindowInputEvent(window, *event.get(), |
1005 &ack_callback); | 1010 &ack_callback); |
1006 } | 1011 } |
1007 | 1012 |
1008 // The handler did not take ownership of the callback, so we send the ack, | 1013 // The handler did not take ownership of the callback, so we send the ack, |
1009 // marking the event as not consumed. | 1014 // marking the event as not consumed. |
1010 if (ack_callback) | 1015 if (ack_callback) |
1011 ack_callback->Run(mojom::EventResult::UNHANDLED); | 1016 ack_callback->Run(mojom::EventResult::UNHANDLED); |
1012 } | 1017 } |
1013 | 1018 |
1014 void WindowTreeClient::OnEventObserved(std::unique_ptr<ui::Event> event, | 1019 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event, |
1015 uint32_t event_observer_id) { | 1020 uint32_t pointer_watcher_id) { |
1016 DCHECK(event); | 1021 DCHECK(event); |
1017 if (has_event_observer_ && event_observer_id == event_observer_id_) | 1022 DCHECK(event->IsPointerEvent()); |
1018 delegate_->OnEventObserved(*event.get(), nullptr /* target */); | 1023 if (has_pointer_watcher_ && pointer_watcher_id == pointer_watcher_id_) |
1024 delegate_->OnPointerEventObserved(*event->AsPointerEvent(), | |
1025 nullptr /* target */); | |
1019 } | 1026 } |
1020 | 1027 |
1021 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { | 1028 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { |
1022 Window* focused_window = GetWindowByServerId(focused_window_id); | 1029 Window* focused_window = GetWindowByServerId(focused_window_id); |
1023 InFlightFocusChange new_change(this, focused_window); | 1030 InFlightFocusChange new_change(this, focused_window); |
1024 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1031 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
1025 return; | 1032 return; |
1026 | 1033 |
1027 LocalSetFocus(focused_window); | 1034 LocalSetFocus(focused_window); |
1028 } | 1035 } |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1250 Window* window, | 1257 Window* window, |
1251 const gfx::Vector2d& offset, | 1258 const gfx::Vector2d& offset, |
1252 const gfx::Insets& hit_area) { | 1259 const gfx::Insets& hit_area) { |
1253 if (window_manager_internal_client_) { | 1260 if (window_manager_internal_client_) { |
1254 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1261 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
1255 server_id(window), offset.x(), offset.y(), hit_area); | 1262 server_id(window), offset.x(), offset.y(), hit_area); |
1256 } | 1263 } |
1257 } | 1264 } |
1258 | 1265 |
1259 } // namespace ui | 1266 } // namespace ui |
OLD | NEW |