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

Side by Side Diff: components/mus/public/cpp/lib/window_tree_client.cc

Issue 1939133002: StructTraits to map mus::mojom::Event to unique_ptr<ui::Event> (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: todo comments + reorganize files Created 4 years, 6 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/public/cpp/window_tree_client.h" 5 #include "components/mus/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 855 matching lines...) Expand 10 before | Expand all | Expand 10 after
866 if (!window) 866 if (!window)
867 return; 867 return;
868 868
869 InFlightPropertyChange new_change(window, name, new_data); 869 InFlightPropertyChange new_change(window, name, new_data);
870 if (ApplyServerChangeToExistingInFlightChange(new_change)) 870 if (ApplyServerChangeToExistingInFlightChange(new_change))
871 return; 871 return;
872 872
873 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); 873 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data));
874 } 874 }
875 875
876 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, 876 void WindowTreeClient::OnWindowInputEvent(
877 Id window_id, 877 uint32_t event_id,
878 mojom::EventPtr event, 878 Id window_id,
879 uint32_t event_observer_id) { 879 const std::unique_ptr<ui::Event>& event,
880 std::unique_ptr<ui::Event> ui_event = event.To<std::unique_ptr<ui::Event>>(); 880 uint32_t event_observer_id) {
881 DCHECK(event);
881 Window* window = GetWindowByServerId(window_id); // May be null. 882 Window* window = GetWindowByServerId(window_id); // May be null.
882 883
883 // Non-zero event_observer_id means it matched an event observer on the 884 // Non-zero event_observer_id means it matched an event observer on the
884 // server. 885 // server.
885 if (event_observer_id != 0 && has_event_observer_ && 886 if (event_observer_id != 0 && has_event_observer_ &&
886 event_observer_id == event_observer_id_) 887 event_observer_id == event_observer_id_)
887 delegate_->OnEventObserved(*ui_event, window); 888 delegate_->OnEventObserved(*event.get(), window);
888 889
889 if (!window || !window->input_event_handler_) { 890 if (!window || !window->input_event_handler_) {
890 tree_->OnWindowInputEventAck(event_id, mojom::EventResult::UNHANDLED); 891 tree_->OnWindowInputEventAck(event_id, mojom::EventResult::UNHANDLED);
891 return; 892 return;
892 } 893 }
893 894
894 std::unique_ptr<base::Callback<void(mojom::EventResult)>> ack_callback( 895 std::unique_ptr<base::Callback<void(mojom::EventResult)>> ack_callback(
895 new base::Callback<void(mojom::EventResult)>( 896 new base::Callback<void(mojom::EventResult)>(
896 base::Bind(&mojom::WindowTree::OnWindowInputEventAck, 897 base::Bind(&mojom::WindowTree::OnWindowInputEventAck,
897 base::Unretained(tree_), event_id))); 898 base::Unretained(tree_), event_id)));
898 window->input_event_handler_->OnWindowInputEvent( 899
899 window, *event.To<std::unique_ptr<ui::Event>>().get(), &ack_callback); 900 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or
901 // ui::TouchEvent once we have proper support for pointer events.
902 if (event->IsMousePointerEvent()) {
903 window->input_event_handler_->OnWindowInputEvent(
904 window, ui::MouseEvent(*event->AsPointerEvent()), &ack_callback);
905 } else if (event->IsTouchPointerEvent()) {
906 window->input_event_handler_->OnWindowInputEvent(
907 window, ui::TouchEvent(*event->AsPointerEvent()), &ack_callback);
908 } else {
909 window->input_event_handler_->OnWindowInputEvent(window, *event.get(),
910 &ack_callback);
911 }
900 912
901 // The handler did not take ownership of the callback, so we send the ack, 913 // The handler did not take ownership of the callback, so we send the ack,
902 // marking the event as not consumed. 914 // marking the event as not consumed.
903 if (ack_callback) 915 if (ack_callback)
904 ack_callback->Run(mojom::EventResult::UNHANDLED); 916 ack_callback->Run(mojom::EventResult::UNHANDLED);
905 } 917 }
906 918
907 void WindowTreeClient::OnEventObserved(mojom::EventPtr event, 919 void WindowTreeClient::OnEventObserved(const std::unique_ptr<ui::Event>& event,
908 uint32_t event_observer_id) { 920 uint32_t event_observer_id) {
909 if (has_event_observer_ && event_observer_id == event_observer_id_) { 921 DCHECK(event);
910 std::unique_ptr<ui::Event> ui_event = 922 if (has_event_observer_ && event_observer_id == event_observer_id_)
911 event.To<std::unique_ptr<ui::Event>>(); 923 delegate_->OnEventObserved(*event.get(), nullptr /* target */);
912 delegate_->OnEventObserved(*ui_event, nullptr /* target */);
913 }
914 } 924 }
915 925
916 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { 926 void WindowTreeClient::OnWindowFocused(Id focused_window_id) {
917 Window* focused_window = GetWindowByServerId(focused_window_id); 927 Window* focused_window = GetWindowByServerId(focused_window_id);
918 InFlightFocusChange new_change(this, focused_window); 928 InFlightFocusChange new_change(this, focused_window);
919 if (ApplyServerChangeToExistingInFlightChange(new_change)) 929 if (ApplyServerChangeToExistingInFlightChange(new_change))
920 return; 930 return;
921 931
922 LocalSetFocus(focused_window); 932 LocalSetFocus(focused_window);
923 } 933 }
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, 1042 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id,
1033 bool janky) { 1043 bool janky) {
1034 if (window_manager_delegate_) { 1044 if (window_manager_delegate_) {
1035 auto it = embedded_windows_.find(client_id); 1045 auto it = embedded_windows_.find(client_id);
1036 CHECK(it != embedded_windows_.end()); 1046 CHECK(it != embedded_windows_.end());
1037 window_manager_delegate_->OnWmClientJankinessChanged( 1047 window_manager_delegate_->OnWmClientJankinessChanged(
1038 embedded_windows_[client_id], janky); 1048 embedded_windows_[client_id], janky);
1039 } 1049 }
1040 } 1050 }
1041 1051
1042 void WindowTreeClient::OnAccelerator(uint32_t id, mojom::EventPtr event) { 1052 void WindowTreeClient::OnAccelerator(uint32_t id,
1043 window_manager_delegate_->OnAccelerator( 1053 const std::unique_ptr<ui::Event>& event) {
1044 id, *event.To<std::unique_ptr<ui::Event>>().get()); 1054 DCHECK(event);
1055 window_manager_delegate_->OnAccelerator(id, *event.get());
1045 } 1056 }
1046 1057
1047 void WindowTreeClient::SetFrameDecorationValues( 1058 void WindowTreeClient::SetFrameDecorationValues(
1048 mojom::FrameDecorationValuesPtr values) { 1059 mojom::FrameDecorationValuesPtr values) {
1049 if (window_manager_internal_client_) { 1060 if (window_manager_internal_client_) {
1050 window_manager_internal_client_->WmSetFrameDecorationValues( 1061 window_manager_internal_client_->WmSetFrameDecorationValues(
1051 std::move(values)); 1062 std::move(values));
1052 } 1063 }
1053 } 1064 }
1054 1065
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 Window* window, 1104 Window* window,
1094 const gfx::Vector2d& offset, 1105 const gfx::Vector2d& offset,
1095 const gfx::Insets& hit_area) { 1106 const gfx::Insets& hit_area) {
1096 if (window_manager_internal_client_) { 1107 if (window_manager_internal_client_) {
1097 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1108 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1098 server_id(window), offset.x(), offset.y(), hit_area); 1109 server_id(window), offset.x(), offset.y(), hit_area);
1099 } 1110 }
1100 } 1111 }
1101 1112
1102 } // namespace mus 1113 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698