@@ -23,10 +23,6 @@ import 'window.dart';
2323
2424class DomRenderer {
2525 DomRenderer () {
26- if (assertionsEnabled) {
27- _debugFrameStatistics = DebugDomRendererFrameStatistics ();
28- }
29-
3026 reset ();
3127
3228 assert (() {
@@ -35,12 +31,6 @@ class DomRenderer {
3531 }());
3632 }
3733
38- static const int vibrateLongPress = 50 ;
39- static const int vibrateLightImpact = 10 ;
40- static const int vibrateMediumImpact = 20 ;
41- static const int vibrateHeavyImpact = 30 ;
42- static const int vibrateSelectionClick = 10 ;
43-
4434 // The tag name for the root view of the flutter app (glass-pane)
4535 static const String _glassPaneTagName = 'flt-glass-pane' ;
4636
@@ -175,52 +165,6 @@ class DomRenderer {
175165
176166 final html.Element rootElement = html.document.body! ;
177167
178- html.Element createElement (String tagName, {html.Element ? parent}) {
179- final html.Element element = html.document.createElement (tagName);
180- parent? .append (element);
181- return element;
182- }
183-
184- void appendText (html.Element parent, String text) {
185- parent.appendText (text);
186- }
187-
188- static void setElementStyle (
189- html.Element element, String name, String ? value) {
190- if (value == null ) {
191- element.style.removeProperty (name);
192- } else {
193- element.style.setProperty (name, value);
194- }
195- }
196-
197- static void setClipPath (html.Element element, String ? value) {
198- if (browserEngine == BrowserEngine .webkit) {
199- if (value == null ) {
200- element.style.removeProperty ('-webkit-clip-path' );
201- } else {
202- element.style.setProperty ('-webkit-clip-path' , value);
203- }
204- }
205- if (value == null ) {
206- element.style.removeProperty ('clip-path' );
207- } else {
208- element.style.setProperty ('clip-path' , value);
209- }
210- }
211-
212- void setThemeColor (ui.Color color) {
213- html.MetaElement ? theme =
214- html.document.querySelector ('#flutterweb-theme' ) as html.MetaElement ? ;
215- if (theme == null ) {
216- theme = html.MetaElement ()
217- ..id = 'flutterweb-theme'
218- ..name = 'theme-color' ;
219- html.document.head! .append (theme);
220- }
221- theme.content = colorToCssString (color)! ;
222- }
223-
224168 static const String defaultFontStyle = 'normal' ;
225169 static const String defaultFontWeight = 'normal' ;
226170 static const double defaultFontSize = 14 ;
@@ -313,7 +257,7 @@ class DomRenderer {
313257 // IMPORTANT: the glass pane element must come after the scene element in the DOM node list so
314258 // it can intercept input events.
315259 _glassPaneElement? .remove ();
316- final html.Element glassPaneElement = createElement (_glassPaneTagName);
260+ final html.Element glassPaneElement = html.document. createElement (_glassPaneTagName);
317261 _glassPaneElement = glassPaneElement;
318262 glassPaneElement.style
319263 ..position = 'absolute'
@@ -331,11 +275,11 @@ class DomRenderer {
331275 _glassPaneShadow = glassPaneElementHostNode;
332276
333277 // Don't allow the scene to receive pointer events.
334- _sceneHostElement = createElement ('flt-scene-host' )
278+ _sceneHostElement = html.document. createElement ('flt-scene-host' )
335279 ..style.pointerEvents = 'none' ;
336280
337281 final html.Element semanticsHostElement =
338- createElement ('flt-semantics-host' );
282+ html.document. createElement ('flt-semantics-host' );
339283 semanticsHostElement.style
340284 ..position = 'absolute'
341285 ..transformOrigin = '0 0 0' ;
@@ -463,34 +407,6 @@ class DomRenderer {
463407 }
464408 }
465409
466- static bool ? _ellipseFeatureDetected;
467-
468- /// Draws CanvasElement ellipse with fallback.
469- static void ellipse (
470- html.CanvasRenderingContext2D context,
471- double centerX,
472- double centerY,
473- double radiusX,
474- double radiusY,
475- double rotation,
476- double startAngle,
477- double endAngle,
478- bool antiClockwise) {
479- // ignore: implicit_dynamic_function
480- _ellipseFeatureDetected ?? = js_util.getProperty (context, 'ellipse' ) != null ;
481- if (_ellipseFeatureDetected! ) {
482- context.ellipse (centerX, centerY, radiusX, radiusY, rotation, startAngle,
483- endAngle, antiClockwise);
484- } else {
485- context.save ();
486- context.translate (centerX, centerY);
487- context.rotate (rotation);
488- context.scale (radiusX, radiusY);
489- context.arc (0 , 0 , 1 , startAngle, endAngle, antiClockwise);
490- context.restore ();
491- }
492- }
493-
494410 static const String orientationLockTypeAny = 'any' ;
495411 static const String orientationLockTypeNatural = 'natural' ;
496412 static const String orientationLockTypeLandscape = 'landscape' ;
@@ -596,36 +512,14 @@ class DomRenderer {
596512
597513 /// Removes a global resource element.
598514 void removeResource (html.Element ? element) {
599- element? .remove ();
600- }
601-
602- /// Provides haptic feedback.
603- void vibrate (int durationMs) {
604- final html.Navigator navigator = html.window.navigator;
605- if (js_util.hasProperty (navigator, 'vibrate' )) {
606- // ignore: implicit_dynamic_function
607- js_util.callMethod (navigator, 'vibrate' , < num > [durationMs]);
515+ if (element == null ) {
516+ return ;
608517 }
518+ assert (element.parent == _resourcesHost);
519+ element.remove ();
609520 }
610521
611522 String get currentHtml => _rootApplicationElement? .outerHtml ?? '' ;
612-
613- DebugDomRendererFrameStatistics ? _debugFrameStatistics;
614-
615- DebugDomRendererFrameStatistics ? debugFlushFrameStatistics () {
616- if (! assertionsEnabled) {
617- throw Exception ('This code should not be reachable in production.' );
618- }
619- final DebugDomRendererFrameStatistics ? current = _debugFrameStatistics;
620- _debugFrameStatistics = DebugDomRendererFrameStatistics ();
621- return current;
622- }
623-
624- void debugRulerCacheHit () => _debugFrameStatistics! .paragraphRulerCacheHits++ ;
625- void debugRulerCacheMiss () =>
626- _debugFrameStatistics! .paragraphRulerCacheMisses++ ;
627- void debugRichTextLayout () => _debugFrameStatistics! .richTextLayouts++ ;
628- void debugPlainTextLayout () => _debugFrameStatistics! .plainTextLayouts++ ;
629523}
630524
631525// Applies the required global CSS to an incoming [html.CssStyleSheet] `sheet`.
@@ -752,45 +646,6 @@ void applyGlobalCssRulesToSheet(
752646 }
753647}
754648
755- /// Miscellaneous statistics collecting during a single frame's execution.
756- ///
757- /// This is useful when profiling the app. This class should only be used when
758- /// assertions are enabled and therefore is not suitable for collecting any
759- /// time measurements. It is mostly useful for counting certain events.
760- class DebugDomRendererFrameStatistics {
761- /// The number of times we reused a previously initialized paragraph ruler to
762- /// measure a paragraph of text.
763- int paragraphRulerCacheHits = 0 ;
764-
765- /// The number of times we had to create a new paragraph ruler to measure a
766- /// paragraph of text.
767- int paragraphRulerCacheMisses = 0 ;
768-
769- /// The number of times we used a paragraph ruler to measure a paragraph of
770- /// text.
771- int get totalParagraphRulerAccesses =>
772- paragraphRulerCacheHits + paragraphRulerCacheMisses;
773-
774- /// The number of times a paragraph of rich text was laid out this frame.
775- int richTextLayouts = 0 ;
776-
777- /// The number of times a paragraph of plain text was laid out this frame.
778- int plainTextLayouts = 0 ;
779-
780- @override
781- String toString () {
782- return '''
783- Frame statistics:
784- Paragraph ruler cache hits: $paragraphRulerCacheHits
785- Paragraph ruler cache misses: $paragraphRulerCacheMisses
786- Paragraph ruler accesses: $totalParagraphRulerAccesses
787- Rich text layouts: $richTextLayouts
788- Plain text layouts: $plainTextLayouts
789- '''
790- .trim ();
791- }
792- }
793-
794649/// Singleton DOM renderer.
795650DomRenderer get domRenderer => ensureDomRendererInitialized ();
796651
0 commit comments