Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
platform_view.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_PLATFORM_VIEW_H_
6#define FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_PLATFORM_VIEW_H_
7
8#include <fuchsia/ui/composition/cpp/fidl.h>
9#include <fuchsia/ui/input/cpp/fidl.h>
10#include <fuchsia/ui/input3/cpp/fidl.h>
11#include <fuchsia/ui/pointer/cpp/fidl.h>
12#include <fuchsia/ui/test/input/cpp/fidl.h>
13#include <lib/fidl/cpp/binding.h>
14#include <lib/fit/function.h>
15#include <lib/sys/cpp/service_directory.h>
16
17#include <array>
18#include <functional>
19#include <map>
20#include <memory>
21#include <set>
22#include <string>
23#include <unordered_map>
24#include <vector>
27
28#include "flow/embedded_views.h"
29#include "flutter/fml/macros.h"
35#include "focus_delegate.h"
36#include "pointer_delegate.h"
38#include "text_delegate.h"
39
40namespace flutter_runner {
41
42using OnEnableWireframeCallback = fit::function<void(bool)>;
43using ViewCallback = std::function<void()>;
44using OnUpdateViewCallback = fit::function<void(int64_t, SkRect, bool, bool)>;
46 fit::function<std::unique_ptr<flutter::Surface>()>;
48 fit::function<void(flutter::SemanticsNodeUpdates, float)>;
49using OnRequestAnnounceCallback = fit::function<void(std::string)>;
51 fit::function<void(int64_t, ViewCallback, ViewCreatedCallback, bool, bool)>;
52using OnDestroyViewCallback = fit::function<void(int64_t, ViewIdCallback)>;
53
54// we use an std::function here because the fit::funtion causes problems with
55// std:bind since HandleFuchsiaShaderWarmupChannelPlatformMessage takes one of
56// these as its first argument.
58 std::function<void(const std::vector<std::string>&,
59 std::function<void(uint32_t)>,
60 uint64_t,
61 uint64_t)>;
62
63// PlatformView is the per-engine component residing on the platform thread that
64// is responsible for all platform specific integrations -- particularly
65// integration with the platform's accessibility, input, and windowing features.
66//
67// PlatformView communicates with the Dart code via "platform messages" handled
68// in HandlePlatformMessage. This communication is bidirectional. Platform
69// messages are notably responsible for communication related to input and
70// external views / windowing.
72 public:
75 flutter::TaskRunners task_runners,
76 fuchsia::ui::views::ViewRef view_ref,
77 std::shared_ptr<flutter::ExternalViewEmbedder> external_view_embedder,
78 fuchsia::ui::input::ImeServiceHandle ime_service,
79 fuchsia::ui::input3::KeyboardHandle keyboard,
80 fuchsia::ui::pointer::TouchSourceHandle touch_source,
81 fuchsia::ui::pointer::MouseSourceHandle mouse_source,
82 fuchsia::ui::views::FocuserHandle focuser,
83 fuchsia::ui::views::ViewRefFocusedHandle view_ref_focused,
84 fuchsia::ui::composition::ParentViewportWatcherHandle
85 parent_viewport_watcher,
86 fuchsia::ui::pointerinjector::RegistryHandle pointerinjector_registry,
87 OnEnableWireframeCallback wireframe_enabled_callback,
88 OnCreateViewCallback on_create_view_callback,
89 OnUpdateViewCallback on_update_view_callback,
90 OnDestroyViewCallback on_destroy_view_callback,
91 OnCreateSurfaceCallback on_create_surface_callback,
92 OnSemanticsNodeUpdateCallback on_semantics_node_update_callback,
93 OnRequestAnnounceCallback on_request_announce_callback,
94 OnShaderWarmupCallback on_shader_warmup_callback,
95 AwaitVsyncCallback await_vsync_callback,
97 await_vsync_for_secondary_callback_callback,
98 std::shared_ptr<sys::ServiceDirectory> dart_application_svc);
99
100 ~PlatformView() override;
101
102 void OnGetLayout(fuchsia::ui::composition::LayoutInfo info);
104 fuchsia::ui::composition::ParentViewportStatus status);
105 void OnChildViewStatus(uint64_t content_id,
106 fuchsia::ui::composition::ChildViewStatus status);
107 void OnChildViewViewRef(uint64_t content_id,
108 uint64_t view_id,
109 fuchsia::ui::views::ViewRef view_ref);
110
111 // |flutter::PlatformView|
112 void SetSemanticsEnabled(bool enabled) override;
113
114 // |flutter::PlatformView|
115 std::shared_ptr<flutter::ExternalViewEmbedder> CreateExternalViewEmbedder()
116 override;
117
118 private:
119 void RegisterPlatformMessageHandlers();
120
121 bool OnHandlePointerEvent(const fuchsia::ui::input::PointerEvent& pointer);
122
123 bool OnHandleFocusEvent(const fuchsia::ui::input::FocusEvent& focus);
124
125 // |flutter::PlatformView|
126 std::unique_ptr<flutter::VsyncWaiter> CreateVSyncWaiter() override;
127
128 // |flutter::PlatformView|
129 std::unique_ptr<flutter::Surface> CreateRenderingSurface() override;
130
131 // |flutter::PlatformView|
132 void HandlePlatformMessage(
133 std::unique_ptr<flutter::PlatformMessage> message) override;
134
135 // |flutter::PlatformView|
136 void UpdateSemantics(
137 int64_t view_id,
140
141 // Channel handler for kAccessibilityChannel. This is currently not
142 // being used, but it is necessary to handle accessibility messages
143 // that are sent by Flutter when semantics is enabled.
144 bool HandleAccessibilityChannelPlatformMessage(
145 std::unique_ptr<flutter::PlatformMessage> message);
146
147 // Channel handler for kFlutterPlatformChannel
148 bool HandleFlutterPlatformChannelPlatformMessage(
149 std::unique_ptr<flutter::PlatformMessage> message);
150
151 // Channel handler for kPlatformViewsChannel.
152 bool HandleFlutterPlatformViewsChannelPlatformMessage(
153 std::unique_ptr<flutter::PlatformMessage> message);
154
155 // Channel handler for kFuchsiaShaderWarmupChannel.
156 static bool HandleFuchsiaShaderWarmupChannelPlatformMessage(
157 OnShaderWarmupCallback on_shader_warmup_callback,
158 std::unique_ptr<flutter::PlatformMessage> message);
159
160 // Channel handler for kFuchsiaInputTestChannel.
161 bool HandleFuchsiaInputTestChannelPlatformMessage(
162 std::unique_ptr<flutter::PlatformMessage> message);
163
164 // Channel handler for kFuchsiaChildViewChannel.
165 bool HandleFuchsiaChildViewChannelPlatformMessage(
166 std::unique_ptr<flutter::PlatformMessage> message);
167
168 void OnCreateView(ViewCallback on_view_created,
169 int64_t view_id_raw,
170 bool hit_testable,
171 bool focusable);
172 void OnDisposeView(int64_t view_id_raw);
173
174 // Sends a 'View.viewConnected' platform message over 'flutter/platform_views'
175 // channel when a view gets created.
176 void OnChildViewConnected(uint64_t content_id);
177
178 // Sends a 'View.viewDisconnected' platform message over
179 // 'flutter/platform_views' channel when a view gets destroyed or the child
180 // view watcher channel of a view closes.
181 void OnChildViewDisconnected(uint64_t content_id);
182
183 // Utility function for coordinate massaging.
184 std::array<float, 2> ClampToViewSpace(const float x, const float y) const;
185
186 // Logical size and origin, and logical->physical ratio. These are optional
187 // to provide an "unset" state during program startup, before Scenic has sent
188 // any metrics-related events to provide initial values for these.
189 //
190 // The engine internally uses a default size of (0.f 0.f) with a default 1.f
191 // ratio, so there is no need to emit events until Scenic has actually sent a
192 // valid size and ratio.
193 std::optional<std::array<float, 2>> view_logical_size_;
194 std::optional<std::array<float, 2>> view_logical_origin_;
195 std::optional<float> view_pixel_ratio_;
196
197 std::shared_ptr<flutter::ExternalViewEmbedder> external_view_embedder_;
198
199 std::shared_ptr<FocusDelegate> focus_delegate_;
200 std::shared_ptr<PointerDelegate> pointer_delegate_;
201 std::unique_ptr<PointerInjectorDelegate> pointer_injector_delegate_;
202
203 // Text delegate is responsible for handling keyboard input and text editing.
204 std::unique_ptr<TextDelegate> text_delegate_;
205
206 std::set<int> down_pointers_;
207 std::map<std::string /* channel */,
208 std::function<bool /* response_handled */ (
209 std::unique_ptr<
210 flutter::PlatformMessage> /* message */)> /* handler */>
211 platform_message_handlers_;
212 // These are the channels that aren't registered and have been notified as
213 // such. Notifying via logs multiple times results in log-spam. See:
214 // https://github.com/flutter/flutter/issues/55966
215 std::set<std::string /* channel */> unregistered_channels_;
216
217 OnEnableWireframeCallback wireframe_enabled_callback_;
218 OnUpdateViewCallback on_update_view_callback_;
219 OnCreateSurfaceCallback on_create_surface_callback_;
220 OnSemanticsNodeUpdateCallback on_semantics_node_update_callback_;
221 OnRequestAnnounceCallback on_request_announce_callback_;
222 OnCreateViewCallback on_create_view_callback_;
223 OnDestroyViewCallback on_destroy_view_callback_;
224 OnShaderWarmupCallback on_shader_warmup_callback_;
225 AwaitVsyncCallback await_vsync_callback_;
227 await_vsync_for_secondary_callback_callback_;
228
229 // Proxies for input tests.
230 fuchsia::ui::test::input::TouchInputListenerPtr touch_input_listener_;
231 fuchsia::ui::test::input::KeyboardInputListenerPtr keyboard_input_listener_;
232 fuchsia::ui::test::input::MouseInputListenerPtr mouse_input_listener_;
233
234 // Component's service directory.
235 std::shared_ptr<sys::ServiceDirectory> dart_application_svc_;
236
237 // child_view_ids_ maintains a persistent mapping from Flatland ContentId's to
238 // flutter view ids, which are really zx_handle_t of ViewCreationToken.
239 struct ChildViewInfo {
240 ChildViewInfo(zx_handle_t token,
241 fuchsia::ui::composition::ChildViewWatcherPtr watcher)
242 : view_id(token), child_view_watcher(std::move(watcher)) {}
243 zx_handle_t view_id;
244 fuchsia::ui::composition::ChildViewWatcherPtr child_view_watcher;
245 };
246 std::unordered_map<uint64_t /*fuchsia::ui::composition::ContentId*/,
247 ChildViewInfo>
248 child_view_info_;
249
250 fuchsia::ui::composition::ParentViewportWatcherPtr parent_viewport_watcher_;
251 fuchsia::ui::composition::ParentViewportStatus parent_viewport_status_;
252
253 fml::WeakPtrFactory<PlatformView> weak_factory_; // Must be the last member.
254
255 FML_DISALLOW_COPY_AND_ASSIGN(PlatformView);
256};
257
258} // namespace flutter_runner
259
260#endif // FLUTTER_SHELL_PLATFORM_FUCHSIA_FLUTTER_PLATFORM_VIEW_H_
Used to forward events from the platform view to interested subsystems. This forwarding is done by th...
Platform views are created by the shell on the platform task runner. Unless explicitly specified,...
void OnParentViewportStatus(fuchsia::ui::composition::ParentViewportStatus status)
void SetSemanticsEnabled(bool enabled) override
Used by embedder to notify the running isolate hosted by the engine on the UI thread that the accessi...
void OnGetLayout(fuchsia::ui::composition::LayoutInfo info)
std::shared_ptr< flutter::ExternalViewEmbedder > CreateExternalViewEmbedder() override
void OnChildViewStatus(uint64_t content_id, fuchsia::ui::composition::ChildViewStatus status)
void OnChildViewViewRef(uint64_t content_id, uint64_t view_id, fuchsia::ui::views::ViewRef view_ref)
~PlatformView() override
Destroys the platform view. The platform view is owned by the shell and will be destroyed by the same...
int32_t x
G_BEGIN_DECLS GBytes * message
G_BEGIN_DECLS FlutterViewId view_id
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
double y
std::function< void(const std::vector< std::string > &, std::function< void(uint32_t)>, uint64_t, uint64_t)> OnShaderWarmupCallback
fit::function< void(int64_t, ViewCallback, ViewCreatedCallback, bool, bool)> OnCreateViewCallback
fit::function< void(int64_t, ViewIdCallback)> OnDestroyViewCallback
fit::function< void(int64_t, SkRect, bool, bool)> OnUpdateViewCallback
fit::function< std::unique_ptr< flutter::Surface >()> OnCreateSurfaceCallback
std::function< void()> ViewCallback
std::function< void(FireCallbackCallback)> AwaitVsyncForSecondaryCallbackCallback
fit::function< void(flutter::SemanticsNodeUpdates, float)> OnSemanticsNodeUpdateCallback
std::function< void(fuchsia::ui::composition::ContentId)> ViewIdCallback
std::function< void(FireCallbackCallback)> AwaitVsyncCallback
fit::function< void(std::string)> OnRequestAnnounceCallback
std::function< void(fuchsia::ui::composition::ContentId, fuchsia::ui::composition::ChildViewWatcherHandle child_view_watcher)> ViewCreatedCallback
fit::function< void(bool)> OnEnableWireframeCallback
std::unordered_map< int32_t, SemanticsNode > SemanticsNodeUpdates
std::unordered_map< int32_t, CustomAccessibilityAction > CustomAccessibilityActionUpdates
Definition ref_ptr.h:261