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 "components/mus/public/cpp/lib/window_tree_client_impl.h" | 5 #include "components/mus/public/cpp/lib/window_tree_client_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
544 return focused_window_; | 544 return focused_window_; |
545 } | 545 } |
546 | 546 |
547 void WindowTreeClientImpl::ClearFocus() { | 547 void WindowTreeClientImpl::ClearFocus() { |
548 if (!focused_window_) | 548 if (!focused_window_) |
549 return; | 549 return; |
550 | 550 |
551 SetFocus(nullptr); | 551 SetFocus(nullptr); |
552 } | 552 } |
553 | 553 |
| 554 void WindowTreeClientImpl::SetEventObserver(mojom::EventMatcherPtr matcher) { |
| 555 if (matcher.is_null()) { |
| 556 has_event_observer_ = false; |
| 557 tree_->SetEventObserver(nullptr, 0u); |
| 558 } else { |
| 559 has_event_observer_ = true; |
| 560 event_observer_id_++; |
| 561 tree_->SetEventObserver(std::move(matcher), event_observer_id_); |
| 562 } |
| 563 } |
| 564 |
554 Window* WindowTreeClientImpl::NewWindow( | 565 Window* WindowTreeClientImpl::NewWindow( |
555 const Window::SharedProperties* properties) { | 566 const Window::SharedProperties* properties) { |
556 return NewWindowImpl(NewWindowType::CHILD, properties); | 567 return NewWindowImpl(NewWindowType::CHILD, properties); |
557 } | 568 } |
558 | 569 |
559 Window* WindowTreeClientImpl::NewTopLevelWindow( | 570 Window* WindowTreeClientImpl::NewTopLevelWindow( |
560 const Window::SharedProperties* properties) { | 571 const Window::SharedProperties* properties) { |
561 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); | 572 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); |
562 // Assume newly created top level windows are drawn by default, otherwise | 573 // Assume newly created top level windows are drawn by default, otherwise |
563 // requests to focus will fail. We will get the real value in | 574 // requests to focus will fail. We will get the real value in |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
860 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 871 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
861 return; | 872 return; |
862 | 873 |
863 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); | 874 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); |
864 } | 875 } |
865 | 876 |
866 void WindowTreeClientImpl::OnWindowInputEvent(uint32_t event_id, | 877 void WindowTreeClientImpl::OnWindowInputEvent(uint32_t event_id, |
867 Id window_id, | 878 Id window_id, |
868 mojom::EventPtr event, | 879 mojom::EventPtr event, |
869 uint32_t event_observer_id) { | 880 uint32_t event_observer_id) { |
870 // TODO(jamescook): If event_observer_id is non-zero, also route the event to | 881 std::unique_ptr<ui::Event> ui_event = event.To<std::unique_ptr<ui::Event>>(); |
871 // PointerWatchers. | 882 |
| 883 // Non-zero event_observer_id means it matched an event observer on the |
| 884 // server. |
| 885 if (event_observer_id != 0 && has_event_observer_ && |
| 886 event_observer_id == event_observer_id_) |
| 887 delegate_->OnEventObserved(*ui_event); |
872 | 888 |
873 Window* window = GetWindowByServerId(window_id); | 889 Window* window = GetWindowByServerId(window_id); |
874 if (!window || !window->input_event_handler_) { | 890 if (!window || !window->input_event_handler_) { |
875 tree_->OnWindowInputEventAck(event_id, mojom::EventResult::UNHANDLED); | 891 tree_->OnWindowInputEventAck(event_id, mojom::EventResult::UNHANDLED); |
876 return; | 892 return; |
877 } | 893 } |
878 | 894 |
879 std::unique_ptr<base::Callback<void(mojom::EventResult)>> ack_callback( | 895 std::unique_ptr<base::Callback<void(mojom::EventResult)>> ack_callback( |
880 new base::Callback<void(mojom::EventResult)>( | 896 new base::Callback<void(mojom::EventResult)>( |
881 base::Bind(&mojom::WindowTree::OnWindowInputEventAck, | 897 base::Bind(&mojom::WindowTree::OnWindowInputEventAck, |
882 base::Unretained(tree_), event_id))); | 898 base::Unretained(tree_), event_id))); |
883 window->input_event_handler_->OnWindowInputEvent( | 899 window->input_event_handler_->OnWindowInputEvent( |
884 window, *event.To<std::unique_ptr<ui::Event>>().get(), &ack_callback); | 900 window, *event.To<std::unique_ptr<ui::Event>>().get(), &ack_callback); |
885 | 901 |
886 // The handler did not take ownership of the callback, so we send the ack, | 902 // The handler did not take ownership of the callback, so we send the ack, |
887 // marking the event as not consumed. | 903 // marking the event as not consumed. |
888 if (ack_callback) | 904 if (ack_callback) |
889 ack_callback->Run(mojom::EventResult::UNHANDLED); | 905 ack_callback->Run(mojom::EventResult::UNHANDLED); |
890 } | 906 } |
891 | 907 |
892 void WindowTreeClientImpl::OnEventObserved(mojom::EventPtr event_in, | 908 void WindowTreeClientImpl::OnEventObserved(mojom::EventPtr event, |
893 uint32_t event_observer_id) { | 909 uint32_t event_observer_id) { |
894 // TODO(jamescook): Route the observed event to PointerWatchers. | 910 if (has_event_observer_ && event_observer_id == event_observer_id_) { |
| 911 std::unique_ptr<ui::Event> ui_event = |
| 912 event.To<std::unique_ptr<ui::Event>>(); |
| 913 delegate_->OnEventObserved(*ui_event); |
| 914 } |
895 } | 915 } |
896 | 916 |
897 void WindowTreeClientImpl::OnWindowFocused(Id focused_window_id) { | 917 void WindowTreeClientImpl::OnWindowFocused(Id focused_window_id) { |
898 Window* focused_window = GetWindowByServerId(focused_window_id); | 918 Window* focused_window = GetWindowByServerId(focused_window_id); |
899 InFlightFocusChange new_change(this, focused_window); | 919 InFlightFocusChange new_change(this, focused_window); |
900 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 920 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
901 return; | 921 return; |
902 | 922 |
903 LocalSetFocus(focused_window); | 923 LocalSetFocus(focused_window); |
904 } | 924 } |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 | 1061 |
1042 void WindowTreeClientImpl::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1062 void WindowTreeClientImpl::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
1043 Window* window, | 1063 Window* window, |
1044 const gfx::Vector2d& offset, | 1064 const gfx::Vector2d& offset, |
1045 const gfx::Insets& hit_area) { | 1065 const gfx::Insets& hit_area) { |
1046 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1066 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
1047 server_id(window), offset.x(), offset.y(), mojo::Insets::From(hit_area)); | 1067 server_id(window), offset.x(), offset.y(), mojo::Insets::From(hit_area)); |
1048 } | 1068 } |
1049 | 1069 |
1050 } // namespace mus | 1070 } // namespace mus |
OLD | NEW |