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 1 commit
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
Next Next commit
Inject contents of a platform view in the FlutterView of the current …
…renderer, right before injecting its slot.
  • Loading branch information
ditman committed Dec 15, 2023
commit 0ecf2ff057d9aecd2bf59a35768466550ad408e0
4 changes: 4 additions & 0 deletions lib/web_ui/lib/src/engine/canvaskit/embedded_views.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ class HtmlViewEmbedder {
}

void _compositeWithParams(int viewId, EmbeddedViewParams params) {
// Ensure platform view with `viewId` is injected into the `rasterizer.view`
// before rendering its shadow DOM `slot`.
rasterizer.view.platformViewMessageHandler.injectPlatformView(viewId);

// If we haven't seen this viewId yet, cache it for clips/transforms.
final ViewClipChain clipChain = _viewClipChains.putIfAbsent(viewId, () {
return ViewClipChain(view: createPlatformViewSlot(viewId));
Expand Down
7 changes: 7 additions & 0 deletions lib/web_ui/lib/src/engine/html/platform_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
// found in the LICENSE file.

import '../dom.dart';
import '../platform_dispatcher.dart';
import '../platform_views/slots.dart';
import '../window.dart';
import 'surface.dart';

/// A surface containing a platform view, which is an HTML element.
Expand All @@ -18,6 +20,11 @@ class PersistedPlatformView extends PersistedLeafSurface {

@override
DomElement createElement() {
// Ensure platform view with `viewId` is injected into the `implicitView`
// before rendering its shadow DOM `slot`.
final EngineFlutterView implicitView = EnginePlatformDispatcher.instance.implicitView!;
implicitView.platformViewMessageHandler.injectPlatformView(viewId);

return createPlatformViewSlot(viewId);
}

Expand Down
5 changes: 5 additions & 0 deletions lib/web_ui/lib/src/engine/platform_views/content_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ class PlatformViewManager {
return _contents.containsKey(viewId);
}

/// Returns the pre-rendered contents of [viewId], to inject them into the DOM.
DomElement getContents(int viewId) {
return _contents[viewId]!;
}

/// Returns the HTML element created by a registered factory for [viewId].
///
/// Throws an [AssertionError] if [viewId] hasn't been rendered before.
Expand Down
17 changes: 14 additions & 3 deletions lib/web_ui/lib/src/engine/platform_views/message_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,27 @@ class PlatformViewMessageHandler {
return;
}

final DomElement content = _contentManager.renderContent(
// Ensure the DomElement of the view is *created*, so programmers can
// access it through `_contentManager.getViewById` (maybe not the DOM!).
_contentManager.renderContent(
platformViewType,
platformViewId,
params,
);

callback(_codec.encodeSuccessEnvelope(null));
}

/// Injects a platform view with [viewId] into this handler's `platformViewsContainer`.
void injectPlatformView(int viewId) {
// For now, we don't need anything fancier. If needed, this can be converted
// to a PlatformViewStrategy class for each web-renderer backend?
_platformViewsContainer.append(content);
callback(_codec.encodeSuccessEnvelope(null));
final DomElement pv = _contentManager.getContents(viewId);
// If pv is a descendant of _platformViewsContainer -> noop
if (_platformViewsContainer.contains(pv)) {
return;
}
_platformViewsContainer.append(pv);
}

/// Handle a `dispose` Platform View message.
Expand Down