55import 'dart:html' as html;
66
77import 'browser_detection.dart' ;
8+ import 'dom.dart' ;
89import 'embedder.dart' ;
910import 'text_editing/text_editing.dart' ;
1011
1112/// The interface required to host a flutter app in the DOM, and its tests.
1213///
13- /// Consider this as the intersection in functionality between [html.ShadowRoot ]
14- /// (preferred Flutter rendering method) and [html.Document ] (fallback).
14+ /// Consider this as the intersection in functionality between [DomShadowRoot ]
15+ /// (preferred Flutter rendering method) and [DomDocument ] (fallback).
1516///
16- /// Not to be confused with [html.DocumentOrShadowRoot ] .
17+ /// Not to be confused with [DomDocumentOrShadowRoot ] .
1718abstract class HostNode {
18- /// Retrieves the [html.Element ] that currently has focus.
19+ /// Retrieves the [DomElement ] that currently has focus.
1920 ///
2021 /// See:
2122 /// * [Document.activeElement] (https://developer.mozilla.org/en-US/docs/Web/API/Document/activeElement)
22- html. Element ? get activeElement;
23+ DomElement ? get activeElement;
2324
2425 /// Adds a node to the end of the child [nodes] list of this node.
2526 ///
@@ -31,18 +32,18 @@ abstract class HostNode {
3132 ///
3233 /// See:
3334 /// * [Node.appendChild] (https://developer.mozilla.org/en-US/docs/Web/API/Node/appendChild)
34- html.Node append (html.Node node);
35+ DomNode append (DomNode node);
36+
37+ /// Appends all of an [Iterable<DomNode>] to this [HostNode] .
38+ void appendAll (Iterable <DomNode > nodes);
3539
3640 /// Returns true if this node contains the specified node.
3741 /// See:
3842 /// * [Node.contains] (https://developer.mozilla.org/en-US/docs/Web/API/Node.contains)
39- bool contains (html.Node ? other);
40-
41- /// Returns the currently wrapped [html.Node] .
42- html.Node get node;
43+ bool contains (DomNode ? other);
4344
44- /// A modifiable list of this node's children .
45- List <html. Node > get nodes ;
45+ /// Returns the currently wrapped [DomNode] .
46+ DomNode get node ;
4647
4748 /// Finds the first descendant element of this document that matches the
4849 /// specified group of selectors.
@@ -59,7 +60,7 @@ abstract class HostNode {
5960 ///
6061 /// See:
6162 /// * [Document.querySelector] (https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector)
62- html. Element ? querySelector (String selectors);
63+ DomElement ? querySelector (String selectors);
6364
6465 /// Finds all descendant elements of this document that match the specified
6566 /// group of selectors.
@@ -75,10 +76,10 @@ abstract class HostNode {
7576 ///
7677 /// See:
7778 /// * [Document.querySelectorAll] (https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll)
78- List <html. Element > querySelectorAll (String selectors);
79+ List <DomElement > querySelectorAll (String selectors);
7980}
8081
81- /// A [HostNode] implementation, backed by a [html.ShadowRoot ] .
82+ /// A [HostNode] implementation, backed by a [DomShadowRoot ] .
8283///
8384/// This is the preferred flutter implementation, but it might not be supported
8485/// by all browsers yet.
@@ -87,12 +88,12 @@ abstract class HostNode {
8788/// supported in the current environment. In this case, a fallback [ElementHostNode]
8889/// should be created instead.
8990class ShadowDomHostNode implements HostNode {
90- late html. ShadowRoot _shadow;
91+ late DomShadowRoot _shadow;
9192
92- /// Build a HostNode by attaching a [html.ShadowRoot ] to the `root` element.
93+ /// Build a HostNode by attaching a [DomShadowRoot ] to the `root` element.
9394 ///
9495 /// This also calls [applyGlobalCssRulesToSheet] , defined in dom_renderer.
95- ShadowDomHostNode (html. Element root) :
96+ ShadowDomHostNode (DomElement root) :
9697 assert (
9798 root.isConnected ?? true ,
9899 'The `root` of a ShadowDomHostNode must be connected to the Document object or a ShadowRoot.' ,
@@ -104,9 +105,9 @@ class ShadowDomHostNode implements HostNode {
104105 'delegatesFocus' : false ,
105106 });
106107
107- final html. StyleElement shadowRootStyleElement = html. StyleElement ();
108+ final DomHTMLStyleElement shadowRootStyleElement = createDomHTMLStyleElement ();
108109 // The shadowRootStyleElement must be appended to the DOM, or its `sheet` will be null later.
109- _shadow.append (shadowRootStyleElement);
110+ _shadow.appendChild (shadowRootStyleElement);
110111
111112 // TODO(dit): Apply only rules for the shadow root
112113 applyGlobalCssRulesToSheet (
@@ -117,74 +118,74 @@ class ShadowDomHostNode implements HostNode {
117118 }
118119
119120 @override
120- html. Element ? get activeElement => _shadow.activeElement;
121+ DomElement ? get activeElement => _shadow.activeElement;
121122
122123 @override
123- html. Element ? querySelector (String selectors) {
124+ DomElement ? querySelector (String selectors) {
124125 return _shadow.querySelector (selectors);
125126 }
126127
127128 @override
128- List <html. Element > querySelectorAll (String selectors) {
129- return _shadow.querySelectorAll (selectors);
129+ List <DomElement > querySelectorAll (String selectors) {
130+ return _shadow.querySelectorAll (selectors) as List < DomElement > ;
130131 }
131132
132133 @override
133- html. Node append (html. Node node) {
134- return _shadow.append (node);
134+ DomNode append (DomNode node) {
135+ return _shadow.appendChild (node);
135136 }
136137
137138 @override
138- bool contains (html. Node ? other) {
139+ bool contains (DomNode ? other) {
139140 return _shadow.contains (other);
140141 }
141142
142143 @override
143- html. Node get node => _shadow;
144+ DomNode get node => _shadow;
144145
145146 @override
146- List <html. Node > get nodes => _shadow. nodes;
147+ void appendAll ( Iterable < DomNode > nodes) => nodes. forEach (append) ;
147148}
148149
149- /// A [HostNode] implementation, backed by a [html.Element ] .
150+ /// A [HostNode] implementation, backed by a [DomElement ] .
150151///
151152/// This is a fallback implementation, in case [ShadowDomHostNode] fails when
152153/// being constructed.
153154class ElementHostNode implements HostNode {
154- late html. Element _element;
155+ late DomElement _element;
155156
156- /// Build a HostNode by attaching a child [html.Element ] to the `root` element.
157- ElementHostNode (html. Element root) {
158- _element = html.document .createElement ('flt-element-host-node' );
159- root.append (_element);
157+ /// Build a HostNode by attaching a child [DomElement ] to the `root` element.
158+ ElementHostNode (DomElement root) {
159+ _element = domDocument .createElement ('flt-element-host-node' );
160+ root.appendChild (_element);
160161 }
161162
162163 @override
163- html. Element ? get activeElement => _element.ownerDocument? .activeElement;
164+ DomElement ? get activeElement => _element.ownerDocument? .activeElement;
164165
165166 @override
166- html. Element ? querySelector (String selectors) {
167+ DomElement ? querySelector (String selectors) {
167168 return _element.querySelector (selectors);
168169 }
169170
170171 @override
171- List <html. Element > querySelectorAll (String selectors) {
172+ List <DomElement > querySelectorAll (String selectors) {
172173 return _element.querySelectorAll (selectors);
173174 }
174175
175176 @override
176- html. Node append (html. Node node) {
177- return _element.append (node);
177+ DomNode append (DomNode node) {
178+ return _element.appendChild (node);
178179 }
179180
180181 @override
181- bool contains (html. Node ? other) {
182+ bool contains (DomNode ? other) {
182183 return _element.contains (other);
183184 }
184185
185186 @override
186- html. Node get node => _element;
187+ DomNode get node => _element;
187188
188189 @override
189- List <html. Node > get nodes => _element. nodes;
190+ void appendAll ( Iterable < DomNode > nodes) => nodes. forEach (append) ;
190191}
0 commit comments