Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
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
8 changes: 8 additions & 0 deletions lib/ui/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ class AccessibilityFeatures {
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;
Expand Down Expand Up @@ -803,6 +804,11 @@ class AccessibilityFeatures {
/// Only supported on iOS.
bool get highContrast => _kHighContrastIndex & _index != 0;

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

@override
String toString() {
final List<String> features = <String>[];
Expand All @@ -818,6 +824,8 @@ class AccessibilityFeatures {
features.add('reduceMotion');
if (highContrast)
features.add('highContrast');
if (onOffSwitchLabels)
features.add('onOffSwitchLabels');
return 'AccessibilityFeatures$features';
}

Expand Down
1 change: 1 addition & 0 deletions lib/ui/window/platform_configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ enum class AccessibilityFeatureFlag : int32_t {
kBoldText = 1 << 3,
kReduceMotion = 1 << 4,
kHighContrast = 1 << 5,
kOnOffSwitchLabels = 1 << 6,
};

//--------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions lib/web_ui/lib/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class AccessibilityFeatures {
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;
Expand All @@ -158,6 +159,7 @@ class AccessibilityFeatures {
bool get boldText => _kBoldTextIndex & _index != 0;
bool get reduceMotion => _kReduceMotionIndex & _index != 0;
bool get highContrast => _kHighContrastIndex & _index != 0;
bool get onOffSwitchLabels => _kOnOffSwitchLabelsIndex & _index != 0;

@override
String toString() {
Expand All @@ -180,6 +182,9 @@ class AccessibilityFeatures {
if (highContrast) {
features.add('highContrast');
}
if (onOffSwitchLabels) {
features.add('onOffSwitchLabels');
}
return 'AccessibilityFeatures$features';
}

Expand Down
50 changes: 37 additions & 13 deletions shell/platform/darwin/ios/framework/Source/FlutterViewController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,13 @@ - (void)setupNotificationCenterObservers {
name:UIAccessibilityDarkerSystemColorsStatusDidChangeNotification
object:nil];

if (@available(iOS 13.0, *)) {
[center addObserver:self
selector:@selector(onAccessibilityStatusChanged:)
name:UIAccessibilityOnOffSwitchLabelsDidChangeNotification
object:nil];
}

[center addObserver:self
selector:@selector(onUserSettingsChanged:)
name:UIContentSizeCategoryDidChangeNotification
Expand Down Expand Up @@ -1417,19 +1424,7 @@ - (void)onAccessibilityStatusChanged:(NSNotification*)notification {
return;
}
auto platformView = [_engine.get() platformView];
int32_t flags = 0;
if (UIAccessibilityIsInvertColorsEnabled()) {
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kInvertColors);
}
if (UIAccessibilityIsReduceMotionEnabled()) {
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kReduceMotion);
}
if (UIAccessibilityIsBoldTextEnabled()) {
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kBoldText);
}
if (UIAccessibilityDarkerSystemColorsEnabled()) {
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kHighContrast);
}
int32_t flags = [self accessibilityFlags];
#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
Expand All @@ -1447,6 +1442,35 @@ - (void)onAccessibilityStatusChanged:(NSNotification*)notification {
#endif
}

- (int32_t)accessibilityFlags {
int32_t flags = 0;
if (UIAccessibilityIsInvertColorsEnabled()) {
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kInvertColors);
}
if (UIAccessibilityIsReduceMotionEnabled()) {
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kReduceMotion);
}
if (UIAccessibilityIsBoldTextEnabled()) {
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kBoldText);
}
if (UIAccessibilityDarkerSystemColorsEnabled()) {
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kHighContrast);
}
if ([FlutterViewController accessibilityIsOnOffSwitchLabelsEnabled]) {
flags |= static_cast<int32_t>(flutter::AccessibilityFeatureFlag::kOnOffSwitchLabels);
}

return flags;
}

+ (BOOL)accessibilityIsOnOffSwitchLabelsEnabled {
if (@available(iOS 13, *)) {
return UIAccessibilityIsOnOffSwitchLabelsEnabled();
} else {
return NO;
}
}

#pragma mark - Set user settings

- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#import <XCTest/XCTest.h>

#include "flutter/fml/platform/darwin/message_loop_darwin.h"
#import "flutter/lib/ui/window/platform_configuration.h"
#import "flutter/lib/ui/window/viewport_metrics.h"
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h"
#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
Expand All @@ -25,10 +26,6 @@ - (void)sendKeyEvent:(const FlutterKeyEvent&)event
userData:(nullable void*)userData;
@end

namespace flutter {
class PointerDataPacket {};
}
Comment on lines -28 to -30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean to change this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if I didn't it wouldn't compile.

I had to import

#import "flutter/lib/ui/window/platform_configuration.h"

to get access to the AccessibilityFeatureFlag enum.

platform_configuration imports the implementation of the PointerDataPacket class. Making the one in the tests obsolete.

#include "flutter/lib/ui/window/pointer_data_packet.h"


/// Sometimes we have to use a custom mock to avoid retain cycles in OCMock.
/// Used for testing low memory notification.
@interface FlutterEnginePartialMock : FlutterEngine
Expand Down Expand Up @@ -617,6 +614,46 @@ - (void)testItReportsHighContrastWhenTraitCollectionRequestsIt {
[mockTraitCollection stopMocking];
}

- (void)testItReportsAccessibilityOnOffSwitchLabelsFlagNotSet {
if (@available(iOS 13, *)) {
// noop
} else {
return;
}

// Setup test.
FlutterViewController* viewController =
[[FlutterViewController alloc] initWithEngine:self.mockEngine nibName:nil bundle:nil];
id partialMockViewController = OCMPartialMock(viewController);
OCMStub([partialMockViewController accessibilityIsOnOffSwitchLabelsEnabled]).andReturn(NO);

// Exercise behavior under test.
int32_t flags = [partialMockViewController accessibilityFlags];

// Verify behavior.
XCTAssert((flags & (int32_t)flutter::AccessibilityFeatureFlag::kOnOffSwitchLabels) == 0);
}

- (void)testItReportsAccessibilityOnOffSwitchLabelsFlagSet {
if (@available(iOS 13, *)) {
// noop
} else {
return;
}

// Setup test.
FlutterViewController* viewController =
[[FlutterViewController alloc] initWithEngine:self.mockEngine nibName:nil bundle:nil];
id partialMockViewController = OCMPartialMock(viewController);
OCMStub([partialMockViewController accessibilityIsOnOffSwitchLabelsEnabled]).andReturn(YES);

// Exercise behavior under test.
int32_t flags = [partialMockViewController accessibilityFlags];

// Verify behavior.
XCTAssert((flags & (int32_t)flutter::AccessibilityFeatureFlag::kOnOffSwitchLabels) != 0);
}

- (void)testPerformOrientationUpdateForcesOrientationChange {
[self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortrait
currentOrientation:UIInterfaceOrientationLandscapeLeft
Expand Down Expand Up @@ -1052,7 +1089,7 @@ - (void)testMouseSupport API_AVAILABLE(ios(13.4)) {
[vc scrollEvent:mockPanGestureRecognizer];

[[[self.mockEngine verify] ignoringNonObjectArgs]
dispatchPointerDataPacket:std::make_unique<flutter::PointerDataPacket>()];
dispatchPointerDataPacket:std::make_unique<flutter::PointerDataPacket>(0)];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or this?

}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern NSNotificationName const FlutterViewControllerShowHomeIndicator;

@interface FlutterViewController () <FlutterViewResponder>

@property(class, nonatomic, readonly) BOOL accessibilityIsOnOffSwitchLabelsEnabled;
@property(nonatomic, readonly) BOOL isPresentingViewController;
@property(nonatomic, readonly) BOOL isVoiceOverRunning;
@property(nonatomic, retain) FlutterKeyboardManager* keyboardManager;
Expand All @@ -45,6 +46,7 @@ extern NSNotificationName const FlutterViewControllerShowHomeIndicator;
nextAction:(void (^)())nextAction API_AVAILABLE(ios(13.4));
- (void)addInternalPlugins;
- (void)deregisterNotifications;
- (int32_t)accessibilityFlags;
@end

#endif // FLUTTER_SHELL_PLATFORM_DARWIN_IOS_FRAMEWORK_SOURCE_FLUTTERVIEWCONTROLLER_INTERNAL_H_