From 893a777a2f1c6188107952cc57b1d09e128a1bf2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Sun, 10 May 2015 01:23:00 -0700 Subject: [PATCH] [ios] Made compass and user dot accessible MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Made the compass behave like a button when visible. Added accessibility values and hints. The compass’s accessibility value uses the compass direction formatter. Turned off direct interaction with the map because it obscures the ornaments. The user dot now reports the current coordinates. Its accessibility label now reflects its annotation’s title instead of the hardcoded label “User location”. (It’d be weird to address the VoiceOver user as “user”.) --- .../resources/Base.lproj/Localizable.strings | 11 +++-- platform/ios/src/MGLMapView.mm | 42 +++++++++---------- .../ios/src/MGLUserLocationAnnotationView.m | 39 ++++++++++++++++- 3 files changed, 66 insertions(+), 26 deletions(-) diff --git a/platform/ios/resources/Base.lproj/Localizable.strings b/platform/ios/resources/Base.lproj/Localizable.strings index cf6de337c..04cc66799 100644 --- a/platform/ios/resources/Base.lproj/Localizable.strings +++ b/platform/ios/resources/Base.lproj/Localizable.strings @@ -7,6 +7,9 @@ /* No comment provided by engineer. */ "CANCEL" = "Cancel"; +/* Accessibility hint */ +"COMPASS_A11Y_HINT" = "Rotates the map to face due north"; + /* Accessibility label */ "COMPASS_A11Y_LABEL" = "Compass"; @@ -25,8 +28,11 @@ /* Setup documentation URL display string; keep as short as possible */ "FIRST_STEPS_URL" = "mapbox.com/help/first-steps-ios-sdk"; +/* Accessibility hint */ +"INFO_A11Y_HINT" = "Access credits, a feedback form, and more"; + /* Accessibility label */ -"INFO_A11Y_LABEL" = "Attribution info"; +"INFO_A11Y_LABEL" = "About this map"; /* Accessibility label */ "LOGO_A11Y_LABEL" = "Mapbox logo"; @@ -67,9 +73,6 @@ /* Telemetry prompt title */ "TELEMETRY_TITLE" = "Make Mapbox Maps Better"; -/* Accessibility label */ -"USER_DOT_A11Y_LABEL" = "User location"; - /* Default user location annotation title */ "USER_DOT_TITLE" = "You Are Here"; diff --git a/platform/ios/src/MGLMapView.mm b/platform/ios/src/MGLMapView.mm index 34078430f..5b429d9d4 100644 --- a/platform/ios/src/MGLMapView.mm +++ b/platform/ios/src/MGLMapView.mm @@ -218,7 +218,7 @@ public: BOOL _delegateHasFillColorsForShapeAnnotations; BOOL _delegateHasLineWidthsForShapeAnnotations; - MGLCoordinateFormatter *_accessibilityCoordinateFormatter; + MGLCompassDirectionFormatter *_accessibilityCompassFormatter; } #pragma mark - Setup & Teardown - @@ -307,11 +307,11 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) // setup accessibility // - self.isAccessibilityElement = YES; +// self.isAccessibilityElement = YES; self.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"MAP_A11Y_LABEL", nil, nil, @"Map", @"Accessibility label"); self.accessibilityTraits = UIAccessibilityTraitAllowsDirectInteraction; - _accessibilityCoordinateFormatter = [[MGLCoordinateFormatter alloc] init]; - _accessibilityCoordinateFormatter.unitStyle = NSFormattingUnitStyleLong; + _accessibilityCompassFormatter = [[MGLCompassDirectionFormatter alloc] init]; + _accessibilityCompassFormatter.unitStyle = NSFormattingUnitStyleLong; self.backgroundColor = [UIColor clearColor]; self.clipsToBounds = YES; @@ -365,7 +365,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) // setup attribution // _attributionButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; - _attributionButton.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"INFO_A11Y_LABEL", nil, nil, @"Attribution info", @"Accessibility label"); + _attributionButton.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"INFO_A11Y_LABEL", nil, nil, @"About this map", @"Accessibility label"); + _attributionButton.accessibilityHint = NSLocalizedStringWithDefaultValue(@"INFO_A11Y_HINT", nil, nil, @"Access credits, a feedback form, and more", @"Accessibility hint"); [_attributionButton addTarget:self action:@selector(showAttribution) forControlEvents:UIControlEventTouchUpInside]; _attributionButton.translatesAutoresizingMaskIntoConstraints = NO; [self addSubview:_attributionButton]; @@ -375,11 +376,14 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) // setup compass // _compassView = [[UIImageView alloc] initWithImage:self.compassImage]; - _compassView.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"COMPASS_A11Y_LABEL", nil, nil, @"Compass", @"Accessibility label"); - _compassView.frame = CGRectMake(0, 0, _compassView.image.size.width, _compassView.image.size.height); + _compassView.frame = { CGPointZero, _compassView.image.size }; _compassView.alpha = 0; _compassView.userInteractionEnabled = YES; [_compassView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleCompassTapGesture:)]]; + _compassView.isAccessibilityElement = YES; + _compassView.accessibilityTraits = UIAccessibilityTraitButton; + _compassView.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"COMPASS_A11Y_LABEL", nil, nil, @"Compass", @"Accessibility label"); + _compassView.accessibilityHint = NSLocalizedStringWithDefaultValue(@"COMPASS_A11Y_HINT", nil, nil, @"Rotates the map to face due north", @"Accessibility hint"); UIView *container = [[UIView alloc] initWithFrame:CGRectZero]; [container addSubview:_compassView]; container.translatesAutoresizingMaskIntoConstraints = NO; @@ -663,6 +667,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) multiplier:1 constant:5]]; + UIImage *compassImage = self.compassView.image; [compassContainerConstraints addObject: [NSLayoutConstraint constraintWithItem:compassContainer attribute:NSLayoutAttributeWidth @@ -670,7 +675,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 - constant:self.compassView.image.size.width]]; + constant:compassImage.size.width]]; [compassContainerConstraints addObject: [NSLayoutConstraint constraintWithItem:compassContainer @@ -679,7 +684,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 - constant:self.compassView.image.size.height]]; + constant:compassImage.size.height]]; [constraintParentView addConstraints:compassContainerConstraints]; // logo bug @@ -1784,17 +1789,6 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) return frame; } -- (NSString *)accessibilityValue -{ - // Each arcminute of longitude is at most about 1 nmi, too small for low zoom levels. - // Each arcsecond of longitude is at most about 30 m, too small for all but the very highest of zoom levels. - _accessibilityCoordinateFormatter.allowsMinutes = self.zoomLevel > 8; - _accessibilityCoordinateFormatter.allowsSeconds = self.zoomLevel > 20; - - return [NSString stringWithFormat:@"Centered on %@", - [_accessibilityCoordinateFormatter stringFromCoordinate:self.centerCoordinate]]; -} - #pragma mark - Geography - + (NS_SET_OF(NSString *) *)keyPathsForValuesAffectingCenterCoordinate @@ -3004,6 +2998,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) inView:self.glView constrainedToView:self.glView animated:animated]; + UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil); } // notify delegate @@ -3085,6 +3080,8 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) self.calloutViewForSelectedAnnotation = nil; self.selectedAnnotation = nil; + UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil); + // notify delegate if ([self.delegate respondsToSelector:@selector(mapView:didDeselectAnnotation:)]) { @@ -3274,6 +3271,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) self.userLocationAnnotationView = [[MGLUserLocationAnnotationView alloc] initInMapView:self]; self.userLocationAnnotationView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin); + self.userLocationAnnotationView.isAccessibilityElement = YES; [self validateLocationServices]; } @@ -3855,6 +3853,7 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) if ( ! [self isSuppressingChangeDelimiters] && [self.delegate respondsToSelector:@selector(mapView:regionDidChangeAnimated:)]) { + UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil); BOOL animated = change == mbgl::MapChangeRegionDidChangeAnimated; [self.delegate mapView:self regionDidChangeAnimated:animated]; } @@ -4034,8 +4033,9 @@ mbgl::Duration MGLDurationInSeconds(NSTimeInterval duration) - (void)updateCompass { CLLocationDirection degrees = mbgl::util::wrap(-self.direction, 0., 360.); - self.compassView.transform = CGAffineTransformMakeRotation(MGLRadiansFromDegrees(degrees)); + + self.compassView.accessibilityValue = [_accessibilityCompassFormatter stringFromDirection:self.direction]; if (_mbglMap->getBearing() && self.compassView.alpha < 1) { diff --git a/platform/ios/src/MGLUserLocationAnnotationView.m b/platform/ios/src/MGLUserLocationAnnotationView.m index be93b7884..74908ec4e 100644 --- a/platform/ios/src/MGLUserLocationAnnotationView.m +++ b/platform/ios/src/MGLUserLocationAnnotationView.m @@ -4,6 +4,7 @@ #import "MGLUserLocation_Private.h" #import "MGLAnnotation.h" #import "MGLMapView.h" +#import "MGLCoordinateFormatter.h" #import "NSBundle+MGLAdditions.h" const CGFloat MGLUserLocationAnnotationDotSize = 22.0; @@ -37,6 +38,8 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck CLLocationAccuracy _oldHorizontalAccuracy; double _oldZoom; double _oldPitch; + + MGLCoordinateFormatter *_accessibilityCoordinateFormatter; } - (instancetype)initWithFrame:(CGRect)frame @@ -54,7 +57,10 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck self.annotation = [[MGLUserLocation alloc] initWithMapView:mapView]; _mapView = mapView; [self setupLayers]; - self.accessibilityLabel = NSLocalizedStringWithDefaultValue(@"USER_DOT_A11Y_LABEL", nil, nil, @"User location", @"Accessibility label"); + self.accessibilityTraits = UIAccessibilityTraitButton; + + _accessibilityCoordinateFormatter = [[MGLCoordinateFormatter alloc] init]; + _accessibilityCoordinateFormatter.unitStyle = NSFormattingUnitStyleLong; } return self; } @@ -65,6 +71,37 @@ const CGFloat MGLUserLocationAnnotationArrowSize = MGLUserLocationAnnotationPuck return [self initInMapView:mapView]; } +- (BOOL)isAccessibilityElement +{ + return !self.hidden; +} + +- (NSString *)accessibilityLabel +{ + return self.annotation.title; +} + +- (NSString *)accessibilityValue +{ + if (self.annotation.subtitle) + { + return self.annotation.subtitle; + } + + // Each arcminute of longitude is at most about 1 nmi, too small for low zoom levels. + // Each arcsecond of longitude is at most about 30 m, too small for all but the very highest of zoom levels. + double zoomLevel = self.mapView.zoomLevel; + _accessibilityCoordinateFormatter.allowsMinutes = zoomLevel > 8; + _accessibilityCoordinateFormatter.allowsSeconds = zoomLevel > 20; + + return [_accessibilityCoordinateFormatter stringFromCoordinate:self.mapView.centerCoordinate]; +} + +- (UIBezierPath *)accessibilityPath +{ + return [UIBezierPath bezierPathWithOvalInRect:self.frame]; +} + - (void)setTintColor:(UIColor *)tintColor { if (_puckModeActivated)