Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Public Member Functions | Static Public Attributes | List of all members
flutter_runner::PointerInjectorDelegate Class Reference

#include <pointer_injector_delegate.h>

Public Member Functions

 PointerInjectorDelegate (fuchsia::ui::pointerinjector::RegistryHandle registry, fuchsia::ui::views::ViewRef host_view_ref)
 
bool HandlePlatformMessage (rapidjson::Value request, fml::RefPtr< flutter::PlatformMessageResponse > response)
 
void OnCreateView (uint64_t view_id, std::optional< fuchsia::ui::views::ViewRef > view_ref=std::nullopt)
 
void OnDestroyView (uint64_t view_id)
 

Static Public Attributes

static constexpr auto kPointerInjectorMethodPrefix
 

Detailed Description

Definition at line 25 of file pointer_injector_delegate.h.

Constructor & Destructor Documentation

◆ PointerInjectorDelegate()

flutter_runner::PointerInjectorDelegate::PointerInjectorDelegate ( fuchsia::ui::pointerinjector::RegistryHandle  registry,
fuchsia::ui::views::ViewRef  host_view_ref 
)
inline

Definition at line 30 of file pointer_injector_delegate.h.

32 : registry_(std::make_shared<fuchsia::ui::pointerinjector::RegistryPtr>(
33 registry.Bind())),
34 host_view_ref_(std::make_shared<fuchsia::ui::views::ViewRef>(
35 std::move(host_view_ref))) {}

Member Function Documentation

◆ HandlePlatformMessage()

bool flutter_runner::PointerInjectorDelegate::HandlePlatformMessage ( rapidjson::Value  request,
fml::RefPtr< flutter::PlatformMessageResponse response 
)

Definition at line 35 of file pointer_injector_delegate.cc.

37 {
38 if (!registry_->is_bound()) {
39 FML_LOG(WARNING)
40 << "Lost connection to fuchsia.ui.pointerinjector.Registry";
41 return false;
42 }
43
44 auto method = request.FindMember("method");
45 if (method == request.MemberEnd() || !method->value.IsString()) {
46 FML_LOG(ERROR) << "No method found in platform message.";
47 return false;
48 }
49
50 if (method->value != kPointerInjectorMethodPrefix) {
51 FML_LOG(ERROR) << "Unexpected platform message method, expected "
52 "View.pointerinjector.inject.";
53 return false;
54 }
55
56 auto args_it = request.FindMember("args");
57 if (args_it == request.MemberEnd() || !args_it->value.IsObject()) {
58 FML_LOG(ERROR) << "No arguments found in platform message's method";
59 return false;
60 }
61
62 const auto& args = args_it->value;
63
64 auto view_id = args.FindMember("viewId");
65 if (!view_id->value.IsUint64()) {
66 FML_LOG(ERROR) << "Argument 'viewId' is not a uint64";
67 return false;
68 }
69
70 auto id = view_id->value.GetUint64();
71 if (valid_views_.count(id) == 0) {
72 // A child view can get destroyed bottom-up, so the parent view may continue
73 // injecting until all view state processing "catches up". Until then, it's
74 // okay to accept a request to inject into a view that no longer exists.
75 // Doing so avoids log pollution regarding "MissingPluginException".
76 Complete(std::move(response), "[0]");
77 return true;
78 }
79
80 auto phase = args.FindMember("phase");
81 if (!phase->value.IsInt()) {
82 FML_LOG(ERROR) << "Argument 'phase' is not a int";
83 return false;
84 }
85
86 auto pointer_x = args.FindMember("x");
87 if (!pointer_x->value.IsFloat() && !pointer_x->value.IsInt()) {
88 FML_LOG(ERROR) << "Argument 'Pointer.X' is not a float";
89 return false;
90 }
91
92 auto pointer_y = args.FindMember("y");
93 if (!pointer_y->value.IsFloat() && !pointer_y->value.IsInt()) {
94 FML_LOG(ERROR) << "Argument 'Pointer.Y' is not a float";
95 return false;
96 }
97
98 auto pointer_id = args.FindMember("pointerId");
99 if (!pointer_id->value.IsUint()) {
100 FML_LOG(ERROR) << "Argument 'pointerId' is not a uint32";
101 return false;
102 }
103
104 auto trace_flow_id = args.FindMember("traceFlowId");
105 if (!trace_flow_id->value.IsInt()) {
106 FML_LOG(ERROR) << "Argument 'traceFlowId' is not a int";
107 return false;
108 }
109
110 auto width = args.FindMember("logicalWidth");
111 if (!width->value.IsFloat() && !width->value.IsInt()) {
112 FML_LOG(ERROR) << "Argument 'logicalWidth' is not a float";
113 return false;
114 }
115
116 auto height = args.FindMember("logicalHeight");
117 if (!height->value.IsFloat() && !height->value.IsInt()) {
118 FML_LOG(ERROR) << "Argument 'logicalHeight' is not a float";
119 return false;
120 }
121
122 auto timestamp = args.FindMember("timestamp");
123 if (!timestamp->value.IsInt() && !timestamp->value.IsUint64()) {
124 FML_LOG(ERROR) << "Argument 'timestamp' is not a int";
125 return false;
126 }
127
128 PointerInjectorRequest event = {
129 .x = pointer_x->value.GetFloat(),
130 .y = pointer_y->value.GetFloat(),
131 .pointer_id = pointer_id->value.GetUint(),
132 .phase = static_cast<fup_EventPhase>(phase->value.GetInt()),
133 .trace_flow_id = trace_flow_id->value.GetUint64(),
134 .logical_size = {width->value.GetFloat(), height->value.GetFloat()},
135 .timestamp = timestamp->value.GetInt()};
136
137 // Inject the pointer event if the view has been created.
138 valid_views_.at(id).InjectEvent(std::move(event));
139 Complete(std::move(response), "[0]");
140 return true;
141}
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent * event
#define FML_LOG(severity)
Definition logging.h:82
fuchsia::ui::pointer::EventPhase fup_EventPhase
int32_t height
int32_t width
#define ERROR(message)

◆ OnCreateView()

void flutter_runner::PointerInjectorDelegate::OnCreateView ( uint64_t  view_id,
std::optional< fuchsia::ui::views::ViewRef >  view_ref = std::nullopt 
)

Definition at line 143 of file pointer_injector_delegate.cc.

145 {
146 FML_CHECK(valid_views_.count(view_id) == 0);
147
148 auto [_, success] = valid_views_.try_emplace(
149 view_id, registry_, host_view_ref_, std::move(view_ref));
150
151 FML_CHECK(success);
152}
#define FML_CHECK(condition)
Definition logging.h:85

◆ OnDestroyView()

void flutter_runner::PointerInjectorDelegate::OnDestroyView ( uint64_t  view_id)
inline

Definition at line 53 of file pointer_injector_delegate.h.

53{ valid_views_.erase(view_id); }

Member Data Documentation

◆ kPointerInjectorMethodPrefix

constexpr auto flutter_runner::PointerInjectorDelegate::kPointerInjectorMethodPrefix
staticconstexpr
Initial value:
=
"View.pointerinjector.inject"

Definition at line 27 of file pointer_injector_delegate.h.


The documentation for this class was generated from the following files: