@@ -24,13 +24,6 @@ const int kMaxSemanticsActivationAttempts = 20;
2424/// Otherwise these events can cause unintended gestures on the framework side.
2525const Duration _periodToConsumeEvents = Duration (milliseconds: 300 );
2626
27- /// The message in the label for the placeholder element used to enable
28- /// accessibility.
29- ///
30- /// This uses US English as the default message. Set this value prior to
31- /// calling `runApp` to translate to another language.
32- String placeholderMessage = 'Enable accessibility' ;
33-
3427/// A helper for [EngineSemanticsOwner] .
3528///
3629/// [SemanticsHelper] prepares and placeholder to enable semantics.
@@ -56,8 +49,10 @@ class SemanticsHelper {
5649 return _semanticsEnabler.shouldEnableSemantics (event);
5750 }
5851
59- DomElement prepareAccessibilityPlaceholder () {
60- return _semanticsEnabler.prepareAccessibilityPlaceholder ();
52+ DomElement get accessibilityPlaceholder => _semanticsEnabler.accessibilityPlaceholder;
53+
54+ void updatePlaceholderLabel (String message) {
55+ _semanticsEnabler.updatePlaceholderLabel (message);
6156 }
6257
6358 /// Stops waiting for the user to enable semantics and removes the
@@ -103,13 +98,16 @@ abstract class SemanticsEnabler {
10398 /// should be forwarded to the framework.
10499 bool tryEnableSemantics (DomEvent event);
105100
106- /// Creates the placeholder for accessibility.
107- ///
108- /// Puts it inside the glasspane.
101+ /// The placeholder element for enabling accessibility.
109102 ///
110103 /// On focus the element announces that accessibility can be enabled by
111104 /// tapping/clicking. (Announcement depends on the assistive technology)
112- DomElement prepareAccessibilityPlaceholder ();
105+ late final DomElement accessibilityPlaceholder = _prepareAccessibilityPlaceholder ();
106+
107+ DomElement _prepareAccessibilityPlaceholder ();
108+
109+ /// Updates the placeholder's label to the given [message] .
110+ void updatePlaceholderLabel (String message);
113111
114112 /// Whether platform is still considering enabling semantics.
115113 ///
@@ -184,7 +182,7 @@ class DesktopSemanticsEnabler extends SemanticsEnabler {
184182 }
185183
186184 @override
187- DomElement prepareAccessibilityPlaceholder () {
185+ DomElement _prepareAccessibilityPlaceholder () {
188186 final DomElement placeholder = _semanticsPlaceholder = createDomElement (
189187 'flt-semantics-placeholder' ,
190188 );
@@ -207,8 +205,9 @@ class DesktopSemanticsEnabler extends SemanticsEnabler {
207205 placeholder
208206 ..setAttribute ('role' , 'button' )
209207 ..setAttribute ('aria-live' , 'polite' )
210- ..setAttribute ('tabindex' , '0' )
211- ..setAttribute ('aria-label' , placeholderMessage);
208+ ..setAttribute ('tabindex' , '0' );
209+
210+ updatePlaceholderLabel (ui_web.accessibilityPlaceholderMessage);
212211
213212 // The placeholder sits just outside the window so only AT can reach it.
214213 placeholder.style
@@ -220,6 +219,11 @@ class DesktopSemanticsEnabler extends SemanticsEnabler {
220219 return placeholder;
221220 }
222221
222+ @override
223+ void updatePlaceholderLabel (String message) {
224+ _semanticsPlaceholder? .setAttribute ('aria-label' , message);
225+ }
226+
223227 @override
224228 void dispose () {
225229 _semanticsPlaceholder? .remove ();
@@ -383,7 +387,7 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
383387 }
384388
385389 @override
386- DomElement prepareAccessibilityPlaceholder () {
390+ DomElement _prepareAccessibilityPlaceholder () {
387391 final DomElement placeholder = _semanticsPlaceholder = createDomElement (
388392 'flt-semantics-placeholder' ,
389393 );
@@ -398,9 +402,8 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
398402 true .toJS,
399403 );
400404
401- placeholder
402- ..setAttribute ('role' , 'button' )
403- ..setAttribute ('aria-label' , placeholderMessage);
405+ placeholder.setAttribute ('role' , 'button' );
406+ updatePlaceholderLabel (ui_web.accessibilityPlaceholderMessage);
404407 placeholder.style
405408 ..position = 'absolute'
406409 ..left = '0'
@@ -411,6 +414,11 @@ class MobileSemanticsEnabler extends SemanticsEnabler {
411414 return placeholder;
412415 }
413416
417+ @override
418+ void updatePlaceholderLabel (String message) {
419+ _semanticsPlaceholder? .setAttribute ('aria-label' , message);
420+ }
421+
414422 @override
415423 void dispose () {
416424 _semanticsPlaceholder? .remove ();
0 commit comments