Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,9 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/pointer_delegate.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/pointer_delegate.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/pointer_delegate_unittests.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/pointer_injector_delegate_unittest.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/program_metadata.h
FILE: ../../../flutter/shell/platform/fuchsia/flutter/runner.cc
FILE: ../../../flutter/shell/platform/fuchsia/flutter/runner.h
Expand Down
4 changes: 4 additions & 0 deletions shell/platform/fuchsia/flutter/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ template("runner_sources") {
"platform_view.h",
"pointer_delegate.cc",
"pointer_delegate.h",
"pointer_injector_delegate.cc",
"pointer_injector_delegate.h",
"program_metadata.h",
"runner.cc",
"runner.h",
Expand Down Expand Up @@ -158,6 +160,7 @@ template("runner_sources") {
"$fuchsia_sdk_root/fidl:fuchsia.ui.pointer",
"$fuchsia_sdk_root/fidl:fuchsia.ui.views",
"$fuchsia_sdk_root/fidl:fuchsia.ui.scenic",
"$fuchsia_sdk_root/fidl:fuchsia.ui.pointerinjector",
"$fuchsia_sdk_root/pkg:async-cpp",
"$fuchsia_sdk_root/pkg:async-default",
"$fuchsia_sdk_root/pkg:async-loop",
Expand Down Expand Up @@ -472,6 +475,7 @@ if (enable_unittests) {
"keyboard_unittest.cc",
"platform_view_unittest.cc",
"pointer_delegate_unittests.cc",
"pointer_injector_delegate_unittest.cc",
"tests/engine_unittests.cc",
"tests/fake_flatland_unittests.cc",
"tests/fake_session_unittests.cc",
Expand Down
14 changes: 14 additions & 0 deletions shell/platform/fuchsia/flutter/engine.cc
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ void Engine::Initialize(
<< "fuchsia::ui::input3::Keyboard connection failed: "
<< zx_status_get_string(keyboard_status);

// Connect to Pointerinjector service.
fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry;
zx_status_t pointerinjector_registry_status =
runner_services->Connect<fuchsia::ui::pointerinjector::Registry>(
pointerinjector_registry.NewRequest());
if (pointerinjector_registry_status != ZX_OK) {
FML_LOG(WARNING)
<< "fuchsia::ui::pointerinjector::Registry connection failed: "
<< zx_status_get_string(pointerinjector_registry_status);
}

// Make clones of the `ViewRef` before sending it to various places.
fuchsia::ui::views::ViewRef platform_view_ref;
view_ref_pair.view_ref.Clone(&platform_view_ref);
Expand Down Expand Up @@ -401,6 +412,7 @@ void Engine::Initialize(
view_ref_focused = std::move(view_ref_focused),
touch_source = std::move(touch_source),
mouse_source = std::move(mouse_source),
pointerinjector_registry = std::move(pointerinjector_registry),
on_session_listener_error_callback =
std::move(on_session_listener_error_callback),
on_enable_wireframe_callback =
Expand Down Expand Up @@ -479,6 +491,7 @@ void Engine::Initialize(
std::move(mouse_source), std::move(focuser),
std::move(view_ref_focused),
std::move(parent_viewport_watcher),
std::move(pointerinjector_registry),
std::move(on_enable_wireframe_callback),
std::move(on_create_flatland_view_callback),
std::move(on_update_view_callback),
Expand All @@ -496,6 +509,7 @@ void Engine::Initialize(
std::move(keyboard), std::move(touch_source),
std::move(mouse_source), std::move(focuser),
std::move(view_ref_focused),
std::move(pointerinjector_registry),
std::move(session_listener_request),
std::move(on_session_listener_error_callback),
std::move(on_enable_wireframe_callback),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ void FlatlandExternalViewEmbedder::CreateView(
FlatlandView new_view = {.transform_id = transform_id,
.viewport_id = viewport_id};
flatland_->flatland()->CreateTransform(new_view.transform_id);
fuchsia::ui::composition::ChildViewWatcherPtr child_view_watcher;
fuchsia::ui::composition::ChildViewWatcherHandle child_view_watcher;
new_view.pending_create_viewport_callback =
[this, transform_id, viewport_id, view_id,
child_view_watcher_request =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace flutter_runner {
using ViewCallback = std::function<void()>;
using FlatlandViewCreatedCallback = std::function<void(
fuchsia::ui::composition::ContentId,
fuchsia::ui::composition::ChildViewWatcherPtr child_view_watcher)>;
fuchsia::ui::composition::ChildViewWatcherHandle child_view_watcher)>;
using FlatlandViewIdCallback =
std::function<void(fuchsia::ui::composition::ContentId)>;

Expand Down
35 changes: 29 additions & 6 deletions shell/platform/fuchsia/flutter/flatland_platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ FlatlandPlatformView::FlatlandPlatformView(
fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused,
fuchsia::ui::composition::ParentViewportWatcherHandle
parent_viewport_watcher,
fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry,
OnEnableWireframe wireframe_enabled_callback,
OnCreateFlatlandView on_create_view_callback,
OnUpdateView on_update_view_callback,
Expand All @@ -43,6 +44,7 @@ FlatlandPlatformView::FlatlandPlatformView(
std::move(mouse_source),
std::move(focuser),
std::move(view_ref_focused),
std::move(pointerinjector_registry),
std::move(wireframe_enabled_callback),
std::move(on_update_view_callback),
std::move(on_create_surface_callback),
Expand Down Expand Up @@ -148,6 +150,10 @@ void FlatlandPlatformView::OnChildViewViewRef(

focus_delegate_->OnChildViewViewRef(view_id, std::move(view_ref));

fuchsia::ui::views::ViewRef view_ref_clone;
fidl::Clone(view_ref, &view_ref_clone);
pointer_injector_delegate_->OnCreateView(view_id, std::move(view_ref_clone));

child_view_info_.at(content_id)
.child_view_watcher->GetViewRef(
[this, content_id, view_id](fuchsia::ui::views::ViewRef view_ref) {
Expand All @@ -164,16 +170,32 @@ void FlatlandPlatformView::OnCreateView(ViewCallback on_view_created,
task_runners_.GetPlatformTaskRunner(),
view_id = view_id_raw](
fuchsia::ui::composition::ContentId content_id,
fuchsia::ui::composition::ChildViewWatcherPtr
child_view_watcher) {
fuchsia::ui::composition::ChildViewWatcherHandle
child_view_watcher_handle) {
FML_CHECK(weak);
FML_CHECK(weak->child_view_info_.count(content_id.value) == 0);

// Bind the child view watcher to the platform thread so that the FIDL calls
// are handled on the platform thread.
fuchsia::ui::composition::ChildViewWatcherPtr child_view_watcher =
child_view_watcher_handle.Bind();
FML_CHECK(child_view_watcher);

child_view_watcher.set_error_handler([](zx_status_t status) {
FML_LOG(ERROR) << "Interface error on: ChildViewWatcher status: "
<< status;
});
child_view_watcher.set_error_handler(
[weak, view_id](zx_status_t status) {
FML_LOG(ERROR) << "Interface error on: ChildViewWatcher status: "
<< status;

if (!weak) {
FML_LOG(WARNING)
<< "Flatland View bound to PlatformView after PlatformView was "
"destroyed; ignoring.";
return;
}

// Disconnected views cannot listen to pointer events.
weak->pointer_injector_delegate_->OnDestroyView(view_id);
});

platform_task_runner->PostTask(
fml::MakeCopyable([weak, view_id, content_id,
Expand Down Expand Up @@ -226,6 +248,7 @@ void FlatlandPlatformView::OnDisposeView(int64_t view_id_raw) {
FML_DCHECK(weak->child_view_info_.count(content_id.value) == 1);
weak->child_view_info_.erase(content_id.value);
weak->focus_delegate_->OnDisposeChildView(view_id_raw);
weak->pointer_injector_delegate_->OnDestroyView(view_id_raw);
});
};
on_destroy_view_callback_(view_id_raw, std::move(on_view_unbound));
Expand Down
1 change: 1 addition & 0 deletions shell/platform/fuchsia/flutter/flatland_platform_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class FlatlandPlatformView final : public flutter_runner::PlatformView {
fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused,
fuchsia::ui::composition::ParentViewportWatcherHandle
parent_viewport_watcher,
fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry,
OnEnableWireframe wireframe_enabled_callback,
OnCreateFlatlandView on_create_view_callback,
OnUpdateView on_update_view_callback,
Expand Down
11 changes: 9 additions & 2 deletions shell/platform/fuchsia/flutter/gfx_platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ GfxPlatformView::GfxPlatformView(
fuchsia::ui::pointer::MouseSourceHandle mouse_source,
fuchsia::ui::views::FocuserHandle focuser,
fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused,
fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry,
fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener>
session_listener_request,
fit::closure on_session_listener_error_callback,
Expand All @@ -44,6 +45,7 @@ GfxPlatformView::GfxPlatformView(
std::move(mouse_source),
std::move(focuser),
std::move(view_ref_focused),
std::move(pointerinjector_registry),
std::move(wireframe_enabled_callback),
std::move(on_update_view_callback),
std::move(on_create_surface_callback),
Expand Down Expand Up @@ -295,6 +297,9 @@ bool GfxPlatformView::OnChildViewDisconnected(
<< "}";
auto call = out.str();

// A disconnected view cannot listen to pointer events.
pointer_injector_delegate_->OnDestroyView(view_id_mapping->second);

std::unique_ptr<flutter::PlatformMessage> message =
std::make_unique<flutter::PlatformMessage>(
"flutter/platform_views",
Expand Down Expand Up @@ -350,6 +355,7 @@ void GfxPlatformView::OnCreateView(ViewCallback on_view_created,

FML_DCHECK(weak->child_view_ids_.count(resource_id) == 0);
weak->child_view_ids_[resource_id] = view_id;
weak->pointer_injector_delegate_->OnCreateView(view_id);
});
};
on_create_view_callback_(view_id_raw, std::move(on_view_created),
Expand All @@ -358,10 +364,10 @@ void GfxPlatformView::OnCreateView(ViewCallback on_view_created,

void GfxPlatformView::OnDisposeView(int64_t view_id_raw) {
auto on_view_unbound =
[weak = weak_factory_.GetWeakPtr(),
[weak = weak_factory_.GetWeakPtr(), view_id = view_id_raw,
platform_task_runner = task_runners_.GetPlatformTaskRunner()](
scenic::ResourceId resource_id) {
platform_task_runner->PostTask([weak, resource_id]() {
platform_task_runner->PostTask([weak, resource_id, view_id]() {
if (!weak) {
FML_LOG(WARNING)
<< "ViewHolder unbound from PlatformView after PlatformView"
Expand All @@ -371,6 +377,7 @@ void GfxPlatformView::OnDisposeView(int64_t view_id_raw) {

FML_DCHECK(weak->child_view_ids_.count(resource_id) == 1);
weak->child_view_ids_.erase(resource_id);
weak->pointer_injector_delegate_->OnDestroyView(view_id);
});
};
on_destroy_view_callback_(view_id_raw, std::move(on_view_unbound));
Expand Down
1 change: 1 addition & 0 deletions shell/platform/fuchsia/flutter/gfx_platform_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class GfxPlatformView final : public flutter_runner::PlatformView,
fuchsia::ui::pointer::MouseSourceHandle mouse_source,
fuchsia::ui::views::FocuserHandle focuser,
fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused,
fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry,
fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener>
session_listener_request,
fit::closure on_session_listener_error_callback,
Expand Down
1 change: 1 addition & 0 deletions shell/platform/fuchsia/flutter/meta/common.shard.cml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"fuchsia.ui.input.ImeService",
"fuchsia.ui.input3.Keyboard",
"fuchsia.ui.scenic.Scenic",
"fuchsia.ui.pointerinjector.Registry",
"fuchsia.vulkan.loader.Loader" // Copied from vulkan/client.shard.cml.
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"fuchsia.ui.input.ImeService",
"fuchsia.ui.input3.Keyboard",
"fuchsia.ui.scenic.Scenic",
"fuchsia.ui.pointerinjector.Registry",
"fuchsia.vulkan.loader.Loader"
]
}
Expand Down
1 change: 1 addition & 0 deletions shell/platform/fuchsia/flutter/meta/flutter_aot_runner.cmx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"fuchsia.ui.input.ImeService",
"fuchsia.ui.input3.Keyboard",
"fuchsia.ui.scenic.Scenic",
"fuchsia.ui.pointerinjector.Registry",
"fuchsia.vulkan.loader.Loader"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"fuchsia.ui.input.ImeService",
"fuchsia.ui.input3.Keyboard",
"fuchsia.ui.scenic.Scenic",
"fuchsia.ui.pointerinjector.Registry",
"fuchsia.vulkan.loader.Loader"
]
}
Expand Down
1 change: 1 addition & 0 deletions shell/platform/fuchsia/flutter/meta/flutter_jit_runner.cmx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"fuchsia.ui.input.ImeService",
"fuchsia.ui.input3.Keyboard",
"fuchsia.ui.scenic.Scenic",
"fuchsia.ui.pointerinjector.Registry",
"fuchsia.vulkan.loader.Loader"
]
}
Expand Down
14 changes: 14 additions & 0 deletions shell/platform/fuchsia/flutter/platform_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// found in the LICENSE file.

#include "flow/embedded_views.h"
#include "pointer_injector_delegate.h"
#define RAPIDJSON_HAS_STDSTRING 1

#include "platform_view.h"
Expand Down Expand Up @@ -62,6 +63,7 @@ PlatformView::PlatformView(
fuchsia::ui::pointer::MouseSourceHandle mouse_source,
fuchsia::ui::views::FocuserHandle focuser,
fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused,
fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry,
OnEnableWireframe wireframe_enabled_callback,
OnUpdateView on_update_view_callback,
OnCreateSurface on_create_surface_callback,
Expand Down Expand Up @@ -101,6 +103,9 @@ PlatformView::PlatformView(
SetInterfaceErrorHandler(keyboard_listener_binding_, "Keyboard Listener");
SetInterfaceErrorHandler(keyboard_, "Keyboard");

fuchsia::ui::views::ViewRef view_ref_clone;
fidl::Clone(view_ref, &view_ref_clone);

// Configure keyboard listener.
keyboard_->AddListener(std::move(view_ref),
keyboard_listener_binding_.NewBinding(), [] {});
Expand Down Expand Up @@ -150,6 +155,11 @@ PlatformView::PlatformView(
});
}

// Configure the pointer injector delegate.
pointer_injector_delegate_ = std::make_unique<PointerInjectorDelegate>(
std::move(pointerinjector_registry), std::move(view_ref_clone),
is_flatland);

// Finally! Register the native platform message handlers.
RegisterPlatformMessageHandlers();
}
Expand Down Expand Up @@ -845,6 +855,10 @@ bool PlatformView::HandleFlutterPlatformViewsChannelPlatformMessage(
}
} else if (method.rfind("View.focus", 0) == 0) {
return focus_delegate_->HandlePlatformMessage(root, message->response());
} else if (method.rfind(PointerInjectorDelegate::kPointerInjectorMethodPrefix,
0) == 0) {
return pointer_injector_delegate_->HandlePlatformMessage(
root, message->response());
} else {
FML_LOG(ERROR) << "Unknown " << message->channel() << " method " << method;
}
Expand Down
3 changes: 3 additions & 0 deletions shell/platform/fuchsia/flutter/platform_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "flutter/shell/platform/fuchsia/flutter/vsync_waiter.h"
#include "focus_delegate.h"
#include "pointer_delegate.h"
#include "pointer_injector_delegate.h"

namespace flutter_runner {

Expand Down Expand Up @@ -75,6 +76,7 @@ class PlatformView : public flutter::PlatformView,
fuchsia::ui::pointer::MouseSourceHandle mouse_source,
fuchsia::ui::views::FocuserHandle focuser,
fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused,
fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry,
OnEnableWireframe wireframe_enabled_callback,
OnUpdateView on_update_view_callback,
OnCreateSurface on_create_surface_callback,
Expand Down Expand Up @@ -187,6 +189,7 @@ class PlatformView : public flutter::PlatformView,

std::shared_ptr<FocusDelegate> focus_delegate_;
std::shared_ptr<PointerDelegate> pointer_delegate_;
std::unique_ptr<PointerInjectorDelegate> pointer_injector_delegate_;

fidl::Binding<fuchsia::ui::input::InputMethodEditorClient> ime_client_;
fuchsia::ui::input::InputMethodEditorPtr ime_;
Expand Down
10 changes: 9 additions & 1 deletion shell/platform/fuchsia/flutter/platform_view_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ class PlatformViewBuilder {
return *this;
}

PlatformViewBuilder& SetPointerinjectorRegistry(
fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry) {
pointerinjector_registry_ = std::move(pointerinjector_registry);
return *this;
}

PlatformViewBuilder& SetSessionListenerRequest(
fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener> request) {
session_listener_request_ = std::move(request);
Expand Down Expand Up @@ -316,7 +322,8 @@ class PlatformViewBuilder {
external_external_view_embedder_, std::move(ime_service_),
std::move(keyboard_), std::move(touch_source_),
std::move(mouse_source_), std::move(focuser_),
std::move(view_ref_focused_), std::move(session_listener_request_),
std::move(view_ref_focused_), std::move(pointerinjector_registry_),
std::move(session_listener_request_),
std::move(on_session_listener_error_callback_),
std::move(wireframe_enabled_callback_),
std::move(on_create_view_callback_),
Expand All @@ -343,6 +350,7 @@ class PlatformViewBuilder {
fuchsia::ui::pointer::MouseSourceHandle mouse_source_;
fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused_;
fuchsia::ui::views::FocuserHandle focuser_;
fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry_;
fidl::InterfaceRequest<fuchsia::ui::scenic::SessionListener>
session_listener_request_;
fit::closure on_session_listener_error_callback_;
Expand Down
Loading