@@ -8,7 +8,9 @@ import 'package:ui/ui.dart' as ui;
88
99import '../browser_detection.dart' ;
1010import '../configuration.dart' ;
11+ import '../dom.dart' ;
1112import '../platform_dispatcher.dart' ;
13+ import '../safe_browser_api.dart' ;
1214import '../util.dart' ;
1315import '../window.dart' ;
1416import 'canvas.dart' ;
@@ -70,15 +72,15 @@ class Surface {
7072 /// We must cache this function because each time we access the tear-off it
7173 /// creates a new object, meaning we won't be able to remove this listener
7274 /// later.
73- void Function (html. Event )? _cachedContextLostListener;
75+ void Function (DomEvent )? _cachedContextLostListener;
7476
7577 /// A cached copy of the most recently created `webglcontextrestored`
7678 /// listener.
7779 ///
7880 /// We must cache this function because each time we access the tear-off it
7981 /// creates a new object, meaning we won't be able to remove this listener
8082 /// later.
81- void Function (html. Event )? _cachedContextRestoredListener;
83+ void Function (DomEvent )? _cachedContextRestoredListener;
8284
8385 SkGrContext ? _grContext;
8486 int ? _glContext;
@@ -93,10 +95,10 @@ class Surface {
9395 /// Conversely, the canvas that lives inside this element can be swapped, for
9496 /// example, when the screen size changes, or when the WebGL context is lost
9597 /// due to the browser tab becoming dormant.
96- final html. Element htmlElement = html. Element . tag ('flt-canvas-container' );
98+ final DomElement htmlElement = createDomElement ('flt-canvas-container' );
9799
98100 /// The underlying `<canvas>` element used for this surface.
99- html. CanvasElement ? htmlCanvas;
101+ DomCanvasElement ? htmlCanvas;
100102 int _pixelWidth = - 1 ;
101103 int _pixelHeight = - 1 ;
102104
@@ -131,7 +133,7 @@ class Surface {
131133
132134 void addToScene () {
133135 if (! _addedToScene) {
134- skiaSceneHost! .children.insert (0 , htmlElement);
136+ skiaSceneHost! .children.insert (0 , htmlElement as html. Element );
135137 }
136138 _addedToScene = true ;
137139 }
@@ -207,9 +209,9 @@ class Surface {
207209 void _updateLogicalHtmlCanvasSize () {
208210 final double logicalWidth = _pixelWidth / window.devicePixelRatio;
209211 final double logicalHeight = _pixelHeight / window.devicePixelRatio;
210- htmlCanvas! .style
211- .. width = '${logicalWidth }px'
212- .. height = '${logicalHeight }px' ;
212+ final DomCSSStyleDeclaration style = htmlCanvas! .style;
213+ style. setProperty ( ' width' , '${logicalWidth }px' );
214+ style. setProperty ( ' height' , '${logicalHeight }px' ) ;
213215 }
214216
215217 /// Translate the canvas so the surface covers the visible portion of the
@@ -224,10 +226,10 @@ class Surface {
224226 final int surfaceHeight = _currentSurfaceSize! .height.ceil ();
225227 final double offset =
226228 (_pixelHeight - surfaceHeight) / window.devicePixelRatio;
227- htmlCanvas! .style.transform = 'translate(0, -${offset }px)' ;
229+ htmlCanvas! .style.setProperty ( ' transform' , 'translate(0, -${offset }px)' ) ;
228230 }
229231
230- void _contextRestoredListener (html. Event event) {
232+ void _contextRestoredListener (DomEvent event) {
231233 assert (
232234 _contextLost,
233235 'Received "webglcontextrestored" event but never received '
@@ -239,7 +241,7 @@ class Surface {
239241 event.preventDefault ();
240242 }
241243
242- void _contextLostListener (html. Event event) {
244+ void _contextLostListener (DomEvent event) {
243245 assert (event.target == htmlCanvas,
244246 'Received a context lost event for a disposed canvas' );
245247 final SurfaceFactory factory = SurfaceFactory .instance;
@@ -277,7 +279,7 @@ class Surface {
277279 // we ensure that the rendred picture covers the entire browser window.
278280 _pixelWidth = physicalSize.width.ceil ();
279281 _pixelHeight = physicalSize.height.ceil ();
280- final html. CanvasElement htmlCanvas = html. CanvasElement (
282+ final DomCanvasElement htmlCanvas = createDomCanvasElement (
281283 width: _pixelWidth,
282284 height: _pixelHeight,
283285 );
@@ -294,7 +296,7 @@ class Surface {
294296 // accessible.
295297 htmlCanvas.setAttribute ('aria-hidden' , 'true' );
296298
297- htmlCanvas.style.position = 'absolute' ;
299+ htmlCanvas.style.setProperty ( ' position' , 'absolute' ) ;
298300 _updateLogicalHtmlCanvasSize ();
299301
300302 // When the browser tab using WebGL goes dormant the browser and/or OS may
@@ -303,8 +305,8 @@ class Surface {
303305 // notification. When we receive this notification we force a new context.
304306 //
305307 // See also: https://www.khronos.org/webgl/wiki/HandlingContextLost
306- _cachedContextRestoredListener = _contextRestoredListener;
307- _cachedContextLostListener = _contextLostListener;
308+ _cachedContextRestoredListener = allowInterop ( _contextRestoredListener) ;
309+ _cachedContextLostListener = allowInterop ( _contextLostListener) ;
308310 htmlCanvas.addEventListener (
309311 'webglcontextlost' ,
310312 _cachedContextLostListener,
@@ -377,7 +379,7 @@ class Surface {
377379 static bool _didWarnAboutWebGlInitializationFailure = false ;
378380
379381 CkSurface _makeSoftwareCanvasSurface (
380- html. CanvasElement htmlCanvas, String reason) {
382+ DomCanvasElement htmlCanvas, String reason) {
381383 if (! _didWarnAboutWebGlInitializationFailure) {
382384 printWarning ('WARNING: Falling back to CPU-only rendering. $reason .' );
383385 _didWarnAboutWebGlInitializationFailure = true ;
0 commit comments