3
3
// found in the LICENSE file.
4
4
5
5
import 'dart:async' ;
6
- import 'dart:html' as html;
7
6
8
7
import 'package:meta/meta.dart' ;
9
8
10
9
import '../browser_detection.dart' ;
10
+ import '../dom.dart' ;
11
+ import '../safe_browser_api.dart' ;
11
12
import 'semantics.dart' ;
12
13
13
14
/// The maximum [semanticsActivationAttempts] before we give up waiting for
@@ -50,11 +51,11 @@ class SemanticsHelper {
50
51
_semanticsEnabler = semanticsEnabler;
51
52
}
52
53
53
- bool shouldEnableSemantics (html. Event event) {
54
+ bool shouldEnableSemantics (DomEvent event) {
54
55
return _semanticsEnabler.shouldEnableSemantics (event);
55
56
}
56
57
57
- html. Element prepareAccessibilityPlaceholder () {
58
+ DomElement prepareAccessibilityPlaceholder () {
58
59
return _semanticsEnabler.prepareAccessibilityPlaceholder ();
59
60
}
60
61
@@ -75,9 +76,9 @@ abstract class SemanticsEnabler {
75
76
/// Semantics should be enabled if the web engine is no longer waiting for
76
77
/// extra signals from the user events. See [isWaitingToEnableSemantics] .
77
78
///
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
79
80
/// semantics. See [tryEnableSemantics] .
80
- bool shouldEnableSemantics (html. Event event) {
81
+ bool shouldEnableSemantics (DomEvent event) {
81
82
if (! isWaitingToEnableSemantics) {
82
83
// Forward to framework as normal.
83
84
return true ;
@@ -90,15 +91,15 @@ abstract class SemanticsEnabler {
90
91
///
91
92
/// Returns true if the `event` is not related to semantics activation and
92
93
/// should be forwarded to the framework.
93
- bool tryEnableSemantics (html. Event event);
94
+ bool tryEnableSemantics (DomEvent event);
94
95
95
96
/// Creates the placeholder for accessibility.
96
97
///
97
98
/// Puts it inside the glasspane.
98
99
///
99
100
/// On focus the element announces that accessibility can be enabled by
100
101
/// tapping/clicking. (Announcement depends on the assistive technology)
101
- html. Element prepareAccessibilityPlaceholder ();
102
+ DomElement prepareAccessibilityPlaceholder ();
102
103
103
104
/// Whether platform is still considering enabling semantics.
104
105
///
@@ -123,14 +124,14 @@ abstract class SemanticsEnabler {
123
124
@visibleForTesting
124
125
class DesktopSemanticsEnabler extends SemanticsEnabler {
125
126
/// A temporary placeholder used to capture a request to activate semantics.
126
- html. Element ? _semanticsPlaceholder;
127
+ DomElement ? _semanticsPlaceholder;
127
128
128
129
/// Whether we are waiting for the user to enable semantics.
129
130
@override
130
131
bool get isWaitingToEnableSemantics => _semanticsPlaceholder != null ;
131
132
132
133
@override
133
- bool tryEnableSemantics (html. Event event) {
134
+ bool tryEnableSemantics (DomEvent event) {
134
135
// Semantics may be enabled programmatically. If there's a race between that
135
136
// and the DOM event, we may end up here while there's no longer a placeholder
136
137
// to work with.
@@ -173,15 +174,15 @@ class DesktopSemanticsEnabler extends SemanticsEnabler {
173
174
}
174
175
175
176
@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' );
179
180
180
181
// Only listen to "click" because other kinds of events are reported via
181
182
// PointerBinding.
182
- placeholder.addEventListener ('click' , (html. Event event) {
183
+ placeholder.addEventListener ('click' , allowInterop (( DomEvent event) {
183
184
tryEnableSemantics (event);
184
- }, true );
185
+ }) , true );
185
186
186
187
// Adding roles to semantics placeholder. 'aria-live' will make sure that
187
188
// the content is announced to the assistive technology user as soon as the
@@ -226,7 +227,7 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
226
227
Timer ? semanticsActivationTimer;
227
228
228
229
/// A temporary placeholder used to capture a request to activate semantics.
229
- html. Element ? _semanticsPlaceholder;
230
+ DomElement ? _semanticsPlaceholder;
230
231
231
232
/// The number of events we processed that could potentially activate
232
233
/// semantics.
@@ -247,7 +248,7 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
247
248
bool get isWaitingToEnableSemantics => _semanticsPlaceholder != null ;
248
249
249
250
@override
250
- bool tryEnableSemantics (html. Event event) {
251
+ bool tryEnableSemantics (DomEvent event) {
251
252
// Semantics may be enabled programmatically. If there's a race between that
252
253
// and the DOM event, we may end up here while there's no longer a placeholder
253
254
// to work with.
@@ -320,29 +321,29 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
320
321
// semantics tree is designed to not interfere with Flutter's gesture
321
322
// detection.
322
323
bool enableConditionPassed = false ;
323
- html. Point < num > activationPoint;
324
+ late final DomPoint activationPoint;
324
325
325
326
switch (event.type) {
326
327
case 'click' :
327
- final html. MouseEvent click = event as html. MouseEvent ;
328
+ final DomMouseEvent click = event as DomMouseEvent ;
328
329
activationPoint = click.offset;
329
330
break ;
330
331
case 'touchstart' :
331
332
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;
334
335
break ;
335
336
case 'pointerdown' :
336
337
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;
339
340
break ;
340
341
default :
341
342
// The event is not relevant, forward to framework as normal.
342
343
return true ;
343
344
}
344
345
345
- final html. Rectangle < num > activatingElementRect =
346
+ final DomRect activatingElementRect =
346
347
_semanticsPlaceholder! .getBoundingClientRect ();
347
348
final double midX = (activatingElementRect.left +
348
349
(activatingElementRect.right - activatingElementRect.left) / 2 )
@@ -372,15 +373,15 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
372
373
}
373
374
374
375
@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' );
378
379
379
380
// Only listen to "click" because other kinds of events are reported via
380
381
// PointerBinding.
381
- placeholder.addEventListener ('click' , (html. Event event) {
382
+ placeholder.addEventListener ('click' , allowInterop (( DomEvent event) {
382
383
tryEnableSemantics (event);
383
- }, true );
384
+ }) , true );
384
385
385
386
placeholder
386
387
..setAttribute ('role' , 'button' )
0 commit comments