33// found in the LICENSE file.
44
55import 'dart:async' ;
6- import 'dart:html' as html;
76
87import 'package:meta/meta.dart' ;
98
109import '../browser_detection.dart' ;
10+ import '../dom.dart' ;
11+ import '../safe_browser_api.dart' ;
1112import 'semantics.dart' ;
1213
1314/// The maximum [semanticsActivationAttempts] before we give up waiting for
@@ -50,11 +51,11 @@ class SemanticsHelper {
5051 _semanticsEnabler = semanticsEnabler;
5152 }
5253
53- bool shouldEnableSemantics (html. Event event) {
54+ bool shouldEnableSemantics (DomEvent event) {
5455 return _semanticsEnabler.shouldEnableSemantics (event);
5556 }
5657
57- html. Element prepareAccessibilityPlaceholder () {
58+ DomElement prepareAccessibilityPlaceholder () {
5859 return _semanticsEnabler.prepareAccessibilityPlaceholder ();
5960 }
6061
@@ -75,9 +76,9 @@ abstract class SemanticsEnabler {
7576 /// Semantics should be enabled if the web engine is no longer waiting for
7677 /// extra signals from the user events. See [isWaitingToEnableSemantics] .
7778 ///
78- /// Or if the received [html.Event ] is suitable/enough for enabling the
79+ /// Or if the received [DomEvent ] is suitable/enough for enabling the
7980 /// semantics. See [tryEnableSemantics] .
80- bool shouldEnableSemantics (html. Event event) {
81+ bool shouldEnableSemantics (DomEvent event) {
8182 if (! isWaitingToEnableSemantics) {
8283 // Forward to framework as normal.
8384 return true ;
@@ -90,15 +91,15 @@ abstract class SemanticsEnabler {
9091 ///
9192 /// Returns true if the `event` is not related to semantics activation and
9293 /// should be forwarded to the framework.
93- bool tryEnableSemantics (html. Event event);
94+ bool tryEnableSemantics (DomEvent event);
9495
9596 /// Creates the placeholder for accessibility.
9697 ///
9798 /// Puts it inside the glasspane.
9899 ///
99100 /// On focus the element announces that accessibility can be enabled by
100101 /// tapping/clicking. (Announcement depends on the assistive technology)
101- html. Element prepareAccessibilityPlaceholder ();
102+ DomElement prepareAccessibilityPlaceholder ();
102103
103104 /// Whether platform is still considering enabling semantics.
104105 ///
@@ -123,14 +124,14 @@ abstract class SemanticsEnabler {
123124@visibleForTesting
124125class DesktopSemanticsEnabler extends SemanticsEnabler {
125126 /// A temporary placeholder used to capture a request to activate semantics.
126- html. Element ? _semanticsPlaceholder;
127+ DomElement ? _semanticsPlaceholder;
127128
128129 /// Whether we are waiting for the user to enable semantics.
129130 @override
130131 bool get isWaitingToEnableSemantics => _semanticsPlaceholder != null ;
131132
132133 @override
133- bool tryEnableSemantics (html. Event event) {
134+ bool tryEnableSemantics (DomEvent event) {
134135 // Semantics may be enabled programmatically. If there's a race between that
135136 // and the DOM event, we may end up here while there's no longer a placeholder
136137 // to work with.
@@ -173,15 +174,15 @@ class DesktopSemanticsEnabler extends SemanticsEnabler {
173174 }
174175
175176 @override
176- html. Element prepareAccessibilityPlaceholder () {
177- final html. Element placeholder =
178- _semanticsPlaceholder = html. Element . tag ('flt-semantics-placeholder' );
177+ DomElement prepareAccessibilityPlaceholder () {
178+ final DomElement placeholder =
179+ _semanticsPlaceholder = createDomElement ('flt-semantics-placeholder' );
179180
180181 // Only listen to "click" because other kinds of events are reported via
181182 // PointerBinding.
182- placeholder.addEventListener ('click' , (html. Event event) {
183+ placeholder.addEventListener ('click' , allowInterop (( DomEvent event) {
183184 tryEnableSemantics (event);
184- }, true );
185+ }) , true );
185186
186187 // Adding roles to semantics placeholder. 'aria-live' will make sure that
187188 // the content is announced to the assistive technology user as soon as the
@@ -226,7 +227,7 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
226227 Timer ? semanticsActivationTimer;
227228
228229 /// A temporary placeholder used to capture a request to activate semantics.
229- html. Element ? _semanticsPlaceholder;
230+ DomElement ? _semanticsPlaceholder;
230231
231232 /// The number of events we processed that could potentially activate
232233 /// semantics.
@@ -247,7 +248,7 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
247248 bool get isWaitingToEnableSemantics => _semanticsPlaceholder != null ;
248249
249250 @override
250- bool tryEnableSemantics (html. Event event) {
251+ bool tryEnableSemantics (DomEvent event) {
251252 // Semantics may be enabled programmatically. If there's a race between that
252253 // and the DOM event, we may end up here while there's no longer a placeholder
253254 // to work with.
@@ -320,29 +321,29 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
320321 // semantics tree is designed to not interfere with Flutter's gesture
321322 // detection.
322323 bool enableConditionPassed = false ;
323- html. Point < num > activationPoint;
324+ late final DomPoint activationPoint;
324325
325326 switch (event.type) {
326327 case 'click' :
327- final html. MouseEvent click = event as html. MouseEvent ;
328+ final DomMouseEvent click = event as DomMouseEvent ;
328329 activationPoint = click.offset;
329330 break ;
330331 case 'touchstart' :
331332 case 'touchend' :
332- final html. TouchEvent touch = event as html. TouchEvent ;
333- activationPoint = touch .changedTouches! .first.client;
333+ final DomTouchEvent touchEvent = event as DomTouchEvent ;
334+ activationPoint = touchEvent .changedTouches! .first.client;
334335 break ;
335336 case 'pointerdown' :
336337 case 'pointerup' :
337- final html. PointerEvent touch = event as html. PointerEvent ;
338- activationPoint = html. Point < num >( touch.client.x, touch.client.y) ;
338+ final DomPointerEvent touch = event as DomPointerEvent ;
339+ activationPoint = touch.client;
339340 break ;
340341 default :
341342 // The event is not relevant, forward to framework as normal.
342343 return true ;
343344 }
344345
345- final html. Rectangle < num > activatingElementRect =
346+ final DomRect activatingElementRect =
346347 _semanticsPlaceholder! .getBoundingClientRect ();
347348 final double midX = (activatingElementRect.left +
348349 (activatingElementRect.right - activatingElementRect.left) / 2 )
@@ -372,15 +373,15 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
372373 }
373374
374375 @override
375- html. Element prepareAccessibilityPlaceholder () {
376- final html. Element placeholder =
377- _semanticsPlaceholder = html. Element . tag ('flt-semantics-placeholder' );
376+ DomElement prepareAccessibilityPlaceholder () {
377+ final DomElement placeholder =
378+ _semanticsPlaceholder = createDomElement ('flt-semantics-placeholder' );
378379
379380 // Only listen to "click" because other kinds of events are reported via
380381 // PointerBinding.
381- placeholder.addEventListener ('click' , (html. Event event) {
382+ placeholder.addEventListener ('click' , allowInterop (( DomEvent event) {
382383 tryEnableSemantics (event);
383- }, true );
384+ }) , true );
384385
385386 placeholder
386387 ..setAttribute ('role' , 'button' )
0 commit comments