Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/ui/platform_dispatcher.dart
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ class PlatformDispatcher {

// Called from the engine, via hooks.dart
void _updateAccessibilityFeatures(int values) {
final AccessibilityFeatures newFeatures = AccessibilityFeatures._(values);
final AccessibilityFeatures newFeatures = AccessibilityFeatures.fromValue(values)!;
final _PlatformConfiguration previousConfiguration = _configuration;
if (newFeatures == previousConfiguration.accessibilityFeatures) {
return;
Expand Down Expand Up @@ -1244,7 +1244,7 @@ class PlatformDispatcher {
/// Immutable class (but can't use @immutable in dart:ui)
class _PlatformConfiguration {
const _PlatformConfiguration({
this.accessibilityFeatures = const AccessibilityFeatures._(0),
this.accessibilityFeatures = AccessibilityFeatures.none,
this.alwaysUse24HourFormat = false,
this.semanticsEnabled = false,
this.platformBrightness = Brightness.light,
Expand Down
91 changes: 34 additions & 57 deletions lib/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -803,91 +803,68 @@ class SingletonFlutterWindow extends FlutterView {
//
// When changes are made to this class, the equivalent APIs in each of the
// embedders *must* be updated.
class AccessibilityFeatures {
const AccessibilityFeatures._(this._index);

static const int _kAccessibleNavigationIndex = 1 << 0;
static const int _kInvertColorsIndex = 1 << 1;
static const int _kDisableAnimationsIndex = 1 << 2;
static const int _kBoldTextIndex = 1 << 3;
static const int _kReduceMotionIndex = 1 << 4;
static const int _kHighContrastIndex = 1 << 5;
static const int _kOnOffSwitchLabelsIndex = 1 << 6;

// A bitfield which represents each enabled feature.
final int _index;

enum AccessibilityFeatures {
/// No accessibility features are enabled.
none(0),
/// Whether there is a running accessibility service which is changing the
/// interaction model of the device.
///
/// For example, TalkBack on Android and VoiceOver on iOS enable this flag.
bool get accessibleNavigation => _kAccessibleNavigationIndex & _index != 0;
accessibleNavigation(_kAccessibleNavigationIndex),

/// The platform is inverting the colors of the application.
bool get invertColors => _kInvertColorsIndex & _index != 0;
invertColors(_kInvertColorsIndex),

/// The platform is requesting that animations be disabled or simplified.
bool get disableAnimations => _kDisableAnimationsIndex & _index != 0;
disableAnimations(_kDisableAnimationsIndex),

/// The platform is requesting that text be rendered at a bold font weight.
///
/// Only supported on iOS and Android API 31+.
bool get boldText => _kBoldTextIndex & _index != 0;
boldText(_kBoldTextIndex),

/// The platform is requesting that certain animations be simplified and
/// parallax effects removed.
///
/// Only supported on iOS.
bool get reduceMotion => _kReduceMotionIndex & _index != 0;
reduceMotion(_kReduceMotionIndex),

/// The platform is requesting that UI be rendered with darker colors.
///
/// Only supported on iOS.
bool get highContrast => _kHighContrastIndex & _index != 0;
highContrast(_kHighContrastIndex),

/// The platform is requesting to show on/off labels inside switches.
///
/// Only supported on iOS.
bool get onOffSwitchLabels => _kOnOffSwitchLabelsIndex & _index != 0;
onOffSwitchLabels(_kOnOffSwitchLabelsIndex);

const AccessibilityFeatures(this.value);

@override
String toString() {
final List<String> features = <String>[];
if (accessibleNavigation) {
features.add('accessibleNavigation');
}
if (invertColors) {
features.add('invertColors');
}
if (disableAnimations) {
features.add('disableAnimations');
}
if (boldText) {
features.add('boldText');
}
if (reduceMotion) {
features.add('reduceMotion');
}
if (highContrast) {
features.add('highContrast');
}
if (onOffSwitchLabels) {
features.add('onOffSwitchLabels');
}
return 'AccessibilityFeatures$features';
}
/// The numerical value for this flag.
///
/// Each flag has one bit set in this bit field.
final int value;

@override
bool operator ==(Object other) {
if (other.runtimeType != runtimeType) {
return false;
}
return other is AccessibilityFeatures
&& other._index == _index;
}
static const Map<int, AccessibilityFeatures> _kFeatureById = <int, AccessibilityFeatures>{
_kAccessibleNavigationIndex: accessibleNavigation,
_kInvertColorsIndex: invertColors,
_kDisableAnimationsIndex: disableAnimations,
_kBoldTextIndex: boldText,
_kReduceMotionIndex: reduceMotion,
_kHighContrastIndex: highContrast,
_kOnOffSwitchLabelsIndex: onOffSwitchLabels,
};

@override
int get hashCode => _index.hashCode;
static AccessibilityFeatures? fromValue(int value) => _kFeatureById[value];

static const int _kAccessibleNavigationIndex = 1 << 0;
static const int _kInvertColorsIndex = 1 << 1;
static const int _kDisableAnimationsIndex = 1 << 2;
static const int _kBoldTextIndex = 1 << 3;
static const int _kReduceMotionIndex = 1 << 4;
static const int _kHighContrastIndex = 1 << 5;
static const int _kOnOffSwitchLabelsIndex = 1 << 6;
}

/// Describes the contrast of a theme or color palette.
Expand Down
4 changes: 2 additions & 2 deletions shell/platform/embedder/fixtures/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ void a11y_main() async {

// Return initial state of accessibility features.
notifyAccessibilityFeatures(
PlatformDispatcher.instance.accessibilityFeatures.reduceMotion);
PlatformDispatcher.instance.accessibilityFeatures == AccessibilityFeatures.reduceMotion);

// Await accessibility features changed from embedder.
await accessibilityFeaturesChanged;
notifyAccessibilityFeatures(
PlatformDispatcher.instance.accessibilityFeatures.reduceMotion);
PlatformDispatcher.instance.accessibilityFeatures == AccessibilityFeatures.reduceMotion);

// Fire semantics update.
final SemanticsUpdateBuilder builder = SemanticsUpdateBuilder()
Expand Down