@@ -21,6 +21,7 @@ FlatlandPlatformView::FlatlandPlatformView(
2121 fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused,
2222 fuchsia::ui::composition::ParentViewportWatcherHandle
2323 parent_viewport_watcher,
24+ fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry,
2425 OnEnableWireframe wireframe_enabled_callback,
2526 OnCreateFlatlandView on_create_view_callback,
2627 OnUpdateView on_update_view_callback,
@@ -43,6 +44,7 @@ FlatlandPlatformView::FlatlandPlatformView(
4344 std::move(mouse_source),
4445 std::move(focuser),
4546 std::move(view_ref_focused),
47+ std::move(pointerinjector_registry),
4648 std::move(wireframe_enabled_callback),
4749 std::move(on_update_view_callback),
4850 std::move(on_create_surface_callback),
@@ -148,6 +150,10 @@ void FlatlandPlatformView::OnChildViewViewRef(
148150
149151 focus_delegate_->OnChildViewViewRef (view_id, std::move (view_ref));
150152
153+ fuchsia::ui::views::ViewRef view_ref_clone;
154+ fidl::Clone (view_ref, &view_ref_clone);
155+ pointer_injector_delegate_->OnCreateView (view_id, std::move (view_ref_clone));
156+
151157 child_view_info_.at (content_id)
152158 .child_view_watcher ->GetViewRef (
153159 [this , content_id, view_id](fuchsia::ui::views::ViewRef view_ref) {
@@ -164,16 +170,32 @@ void FlatlandPlatformView::OnCreateView(ViewCallback on_view_created,
164170 task_runners_.GetPlatformTaskRunner (),
165171 view_id = view_id_raw](
166172 fuchsia::ui::composition::ContentId content_id,
167- fuchsia::ui::composition::ChildViewWatcherPtr
168- child_view_watcher ) {
173+ fuchsia::ui::composition::ChildViewWatcherHandle
174+ child_view_watcher_handle ) {
169175 FML_CHECK (weak);
170176 FML_CHECK (weak->child_view_info_ .count (content_id.value ) == 0 );
177+
178+ // Bind the child view watcher to the platform thread so that the FIDL calls
179+ // are handled on the platform thread.
180+ fuchsia::ui::composition::ChildViewWatcherPtr child_view_watcher =
181+ child_view_watcher_handle.Bind ();
171182 FML_CHECK (child_view_watcher);
172183
173- child_view_watcher.set_error_handler ([](zx_status_t status) {
174- FML_LOG (ERROR) << " Interface error on: ChildViewWatcher status: "
175- << status;
176- });
184+ child_view_watcher.set_error_handler (
185+ [weak, view_id](zx_status_t status) {
186+ FML_LOG (ERROR) << " Interface error on: ChildViewWatcher status: "
187+ << status;
188+
189+ if (!weak) {
190+ FML_LOG (WARNING)
191+ << " Flatland View bound to PlatformView after PlatformView was "
192+ " destroyed; ignoring." ;
193+ return ;
194+ }
195+
196+ // Disconnected views cannot listen to pointer events.
197+ weak->pointer_injector_delegate_ ->OnDestroyView (view_id);
198+ });
177199
178200 platform_task_runner->PostTask (
179201 fml::MakeCopyable ([weak, view_id, content_id,
@@ -226,6 +248,7 @@ void FlatlandPlatformView::OnDisposeView(int64_t view_id_raw) {
226248 FML_DCHECK (weak->child_view_info_ .count (content_id.value ) == 1 );
227249 weak->child_view_info_ .erase (content_id.value );
228250 weak->focus_delegate_ ->OnDisposeChildView (view_id_raw);
251+ weak->pointer_injector_delegate_ ->OnDestroyView (view_id_raw);
229252 });
230253 };
231254 on_destroy_view_callback_ (view_id_raw, std::move (on_view_unbound));
0 commit comments