• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
5part of engine;
6
7/// A surface containing a platform view, which is an HTML element.
8class PersistedPlatformView extends PersistedLeafSurface {
9  final int viewId;
10  final double dx;
11  final double dy;
12  final double width;
13  final double height;
14
15  html.HtmlElement _hostElement;
16  html.ShadowRoot _shadowRoot;
17
18  PersistedPlatformView(this.viewId, this.dx, this.dy, this.width, this.height);
19
20  @override
21  html.Element createElement() {
22    _hostElement = defaultCreateElement('flt-platform-view');
23
24    // Allow the platform view host element to receive pointer events.
25    //
26    // This is to allow platform view HTML elements to be interactive.
27    //
28    // ACCESSIBILITY NOTE: The way we enable accessibility on Flutter for web
29    // is to have a full-page button which waits for a double tap. Placing this
30    // full-page button in front of the scene would cause platform views not
31    // to receive pointer events. The tradeoff is that by placing the scene in
32    // front of the semantics placeholder will cause platform views to block
33    // pointer events from reaching the placeholder. This means that in order
34    // to enable accessibility, you must double tap the app *outside of a
35    // platform view*. As a consequence, a full-screen platform view will make
36    // it impossible to enable accessibility.
37    _hostElement.style.pointerEvents = 'auto';
38
39    _shadowRoot = _hostElement.attachShadow(<String, String>{'mode': 'open'});
40    final html.StyleElement _styleReset = html.StyleElement();
41    _styleReset.innerHtml = '''
42      :host {
43        all: initial;
44      }''';
45    _shadowRoot.append(_styleReset);
46    final html.Element platformView =
47        platformViewRegistry.getCreatedView(viewId);
48    if (platformView != null) {
49      _shadowRoot.append(platformView);
50    } else {
51      html.window.console.warn('No platform view created for id $viewId');
52    }
53    return _hostElement;
54  }
55
56  @override
57  void apply() {
58    _hostElement.style
59      ..transform = 'translate(${dx}px, ${dy}px)'
60      ..width = '${width}px'
61      ..height = '${height}px';
62  }
63
64  @override
65  double matchForUpdate(PersistedPlatformView existingSurface) {
66    return existingSurface.viewId == viewId ? 0.0 : 1.0;
67  }
68}
69