From 8e2ee829da51eb7088c25c50cde74b647b21cdba Mon Sep 17 00:00:00 2001 From: Miquel Beltran Date: Thu, 9 Jan 2020 11:29:16 +0100 Subject: [PATCH 1/2] Add support for Increase Contrast on iOS Reference ticket: https://github.com/flutter/flutter/issues/48418 According to the Apple documentation, the method UIAccessibilityDarkerSystemColorsEnabled exposes the value of the Increase Contrast setting in the Accessibility settings. The value is passed as a flag together with the rest of accessibility settings. Add HighContrast index to web_ui Add observer for the high contrast a11y setting change --- lib/ui/window.dart | 8 ++++++++ lib/ui/window/window.h | 1 + lib/web_ui/lib/src/ui/window.dart | 9 +++++++++ .../darwin/ios/framework/Source/FlutterViewController.mm | 7 +++++++ 4 files changed, 25 insertions(+) diff --git a/lib/ui/window.dart b/lib/ui/window.dart index 96b48e2aefbbe..92a7910e22926 100644 --- a/lib/ui/window.dart +++ b/lib/ui/window.dart @@ -1211,6 +1211,7 @@ class AccessibilityFeatures { static const int _kDisableAnimationsIndex = 1 << 2; static const int _kBoldTextIndex = 1 << 3; static const int _kReduceMotionIndex = 1 << 4; + static const int _kHighContrastIndex = 1 << 5; // A bitfield which represents each enabled feature. final int _index; @@ -1238,6 +1239,11 @@ class AccessibilityFeatures { /// Only supported on iOS. bool get reduceMotion => _kReduceMotionIndex & _index != 0; + /// The platform is requesting that UI be rendered with darker colors. + /// + /// Only supported on iOS. + bool get highContrast => _kHighContrastIndex & _index != 0; + @override String toString() { final List features = []; @@ -1251,6 +1257,8 @@ class AccessibilityFeatures { features.add('boldText'); if (reduceMotion) features.add('reduceMotion'); + if (highContrast) + features.add('highContrast'); return 'AccessibilityFeatures$features'; } diff --git a/lib/ui/window/window.h b/lib/ui/window/window.h index bddcb70f3150f..fac2861a43e40 100644 --- a/lib/ui/window/window.h +++ b/lib/ui/window/window.h @@ -44,6 +44,7 @@ enum class AccessibilityFeatureFlag : int32_t { kDisableAnimations = 1 << 2, kBoldText = 1 << 3, kReduceMotion = 1 << 4, + kHighContrast = 1 << 5, }; class WindowClient { diff --git a/lib/web_ui/lib/src/ui/window.dart b/lib/web_ui/lib/src/ui/window.dart index d81159b37e950..0a36cc3da8f73 100644 --- a/lib/web_ui/lib/src/ui/window.dart +++ b/lib/web_ui/lib/src/ui/window.dart @@ -995,6 +995,7 @@ class AccessibilityFeatures { static const int _kDisableAnimationsIndex = 1 << 2; static const int _kBoldTextIndex = 1 << 3; static const int _kReduceMotionIndex = 1 << 4; + static const int _kHighContrastIndex = 1 << 5; // A bitfield which represents each enabled feature. final int _index; @@ -1022,6 +1023,11 @@ class AccessibilityFeatures { /// Only supported on iOS. bool get reduceMotion => _kReduceMotionIndex & _index != 0; + /// The platform is requesting that UI be rendered with darker colors. + /// + /// Only supported on iOS. + bool get highContrast => _kHighContrastIndex & _index != 0; + @override String toString() { final List features = []; @@ -1040,6 +1046,9 @@ class AccessibilityFeatures { if (reduceMotion) { features.add('reduceMotion'); } + if (highContrast) { + features.add('highContrast'); + } return 'AccessibilityFeatures$features'; } diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index a94f6b657fa38..842f615324d1c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -297,6 +297,11 @@ - (void)setupNotificationCenterObservers { selector:@selector(onAccessibilityStatusChanged:) name:UIAccessibilityBoldTextStatusDidChangeNotification object:nil]; + + [center addObserver:self + selector:@selector(onAccessibilityStatusChanged:) + name:UIAccessibilityDarkerSystemColorsStatusDidChangeNotification + object:nil]; [center addObserver:self selector:@selector(onUserSettingsChanged:) @@ -962,6 +967,8 @@ - (void)onAccessibilityStatusChanged:(NSNotification*)notification { flags |= static_cast(flutter::AccessibilityFeatureFlag::kReduceMotion); if (UIAccessibilityIsBoldTextEnabled()) flags |= static_cast(flutter::AccessibilityFeatureFlag::kBoldText); + if (UIAccessibilityDarkerSystemColorsEnabled()) + flags |= static_cast(flutter::AccessibilityFeatureFlag::kHighContrast); #if TARGET_OS_SIMULATOR // There doesn't appear to be any way to determine whether the accessibility // inspector is enabled on the simulator. We conservatively always turn on the From c6d3797b6afa20eb49f2d22d0d605ec189f4f78b Mon Sep 17 00:00:00 2001 From: Miquel Beltran Date: Thu, 20 Feb 2020 11:17:00 +0100 Subject: [PATCH 2/2] Flutter format as requested --- .../darwin/ios/framework/Source/FlutterViewController.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm index 842f615324d1c..5b04408ec9d2c 100644 --- a/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm +++ b/shell/platform/darwin/ios/framework/Source/FlutterViewController.mm @@ -297,7 +297,7 @@ - (void)setupNotificationCenterObservers { selector:@selector(onAccessibilityStatusChanged:) name:UIAccessibilityBoldTextStatusDidChangeNotification object:nil]; - + [center addObserver:self selector:@selector(onAccessibilityStatusChanged:) name:UIAccessibilityDarkerSystemColorsStatusDidChangeNotification