Commit 5b2ab789 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Add accessibility for IdentityPicker

This CL adds dynamic for the IdentityPicker, making sure that the name
and email can spread on multiple lines and respond nicely when the font
is increased.

Bug: 872277
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: Iea05b977c7a6f6fe199c0e8d4e6325ac05936ef0
Reviewed-on: https://chromium-review.googlesource.com/1172423Reviewed-by: default avatarJérôme Lebel <jlebel@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#582588}
parent 335bd11f
...@@ -12,7 +12,7 @@ const CGFloat kAuthenticationHeaderImageHeight = 88.; ...@@ -12,7 +12,7 @@ const CGFloat kAuthenticationHeaderImageHeight = 88.;
const CGFloat kAuthenticationHeaderImageWidth = 360.; const CGFloat kAuthenticationHeaderImageWidth = 360.;
const UIFontTextStyle kAuthenticationTitleFontStyle = UIFontTextStyleTitle2; const UIFontTextStyle kAuthenticationTitleFontStyle = UIFontTextStyleTitle2;
const UIFontTextStyle kAuthenticationTextFontStyle = UIFontTextStyleCaption1; const UIFontTextStyle kAuthenticationTextFontStyle = UIFontTextStyleFootnote;
const int kAuthenticationHeaderBackgroundColor = 0xf8f9fa; const int kAuthenticationHeaderBackgroundColor = 0xf8f9fa;
const CGFloat kAuthenticationHorizontalMargin = 16.; const CGFloat kAuthenticationHorizontalMargin = 16.;
......
...@@ -14,11 +14,10 @@ ...@@ -14,11 +14,10 @@
namespace { namespace {
// Top margin for the label. // Top margin for the label.
CGFloat kTopMargin = 24.; CGFloat kTopMargin = 20.;
CGFloat kBottomMargin = 15;
// Leading margin for the label. // Leading margin for the label.
CGFloat kLeadingMargin = 24.; CGFloat kLeadingMargin = 24.;
// Label font size.
CGFloat kTitleFontSize = 14.;
// Label font color alpha. // Label font color alpha.
CGFloat kFontAlpha = .87; CGFloat kFontAlpha = .87;
} // namespace } // namespace
...@@ -35,7 +34,7 @@ CGFloat kFontAlpha = .87; ...@@ -35,7 +34,7 @@ CGFloat kFontAlpha = .87;
label.translatesAutoresizingMaskIntoConstraints = NO; label.translatesAutoresizingMaskIntoConstraints = NO;
label.text = label.text =
l10n_util::GetNSString(IDS_IOS_ACCOUNT_IDENTITY_CHOOSER_CHOOSE_ACCOUNT); l10n_util::GetNSString(IDS_IOS_ACCOUNT_IDENTITY_CHOOSER_CHOOSE_ACCOUNT);
label.font = [UIFont boldSystemFontOfSize:kTitleFontSize]; label.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
label.textColor = [UIColor colorWithWhite:0. alpha:kFontAlpha]; label.textColor = [UIColor colorWithWhite:0. alpha:kFontAlpha];
[self.contentView addSubview:label]; [self.contentView addSubview:label];
NSDictionary* views = @{ NSDictionary* views = @{
...@@ -44,12 +43,13 @@ CGFloat kFontAlpha = .87; ...@@ -44,12 +43,13 @@ CGFloat kFontAlpha = .87;
NSDictionary* metrics = @{ NSDictionary* metrics = @{
@"LeadingMargin" : @(kLeadingMargin), @"LeadingMargin" : @(kLeadingMargin),
@"TopMargin" : @(kTopMargin), @"TopMargin" : @(kTopMargin),
@"BottomMargin" : @(kBottomMargin),
}; };
NSArray* constraints = @[ NSArray* constraints = @[
// Horitizontal constraints. // Horitizontal constraints.
@"H:|-(LeadingMargin)-[label]-(>=0)-|", @"H:|-(LeadingMargin)-[label]-(>=0)-|",
// Vertical constraints. // Vertical constraints.
@"V:|-(TopMargin)-[label]", @"V:|-(TopMargin)-[label]-(BottomMargin)-|",
]; ];
ApplyVisualConstraintsWithMetrics(constraints, views, metrics); ApplyVisualConstraintsWithMetrics(constraints, views, metrics);
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_header_item.h" #import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_header_item.h"
#import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_item.h" #import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_item.h"
#import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_view_controller.h" #import "ios/chrome/browser/ui/authentication/unified_consent/identity_chooser/identity_chooser_view_controller.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_header_footer_item.h"
#import "ios/chrome/browser/ui/table_view/table_view_model.h" #import "ios/chrome/browser/ui/table_view/table_view_model.h"
#import "ios/public/provider/chrome/browser/signin/chrome_identity.h" #import "ios/public/provider/chrome/browser/signin/chrome_identity.h"
#include "ios/public/provider/chrome/browser/signin/chrome_identity_service.h" #include "ios/public/provider/chrome/browser/signin/chrome_identity_service.h"
......
...@@ -38,7 +38,7 @@ const CGFloat kFooterHeight = 17.; ...@@ -38,7 +38,7 @@ const CGFloat kFooterHeight = 17.;
self.tableView.sectionFooterHeight = 0; self.tableView.sectionFooterHeight = 0;
// Setting -UITableView.rowHeight is required for iOS 10. On iOS 11, the row // Setting -UITableView.rowHeight is required for iOS 10. On iOS 11, the row
// height is automatically set. // height is automatically set.
self.tableView.rowHeight = kRowHeight; self.tableView.estimatedRowHeight = kRowHeight;
} }
- (void)viewDidDisappear:(BOOL)animated { - (void)viewDidDisappear:(BOOL)animated {
......
...@@ -16,10 +16,8 @@ namespace { ...@@ -16,10 +16,8 @@ namespace {
// Sizes. // Sizes.
const CGFloat kAvatarSize = 40.; const CGFloat kAvatarSize = 40.;
const CGFloat kTitleFontSize = 14.;
const CGFloat kSubtitleFontSize = 12.;
// Distances/margins. // Distances/margins.
const CGFloat kTitleOffset = 2; const CGFloat kTitleOffset = 4;
const CGFloat kHorizontalAvatarMargin = 16.; const CGFloat kHorizontalAvatarMargin = 16.;
const CGFloat kVerticalMargin = 12.; const CGFloat kVerticalMargin = 12.;
// Colors // Colors
...@@ -66,22 +64,28 @@ const CGFloat kSubtitleTextColorAlpha = .54; ...@@ -66,22 +64,28 @@ const CGFloat kSubtitleTextColorAlpha = .54;
// Title. // Title.
_title = [[UILabel alloc] init]; _title = [[UILabel alloc] init];
_title.translatesAutoresizingMaskIntoConstraints = NO; _title.translatesAutoresizingMaskIntoConstraints = NO;
_title.numberOfLines = 0;
_title.textColor = [UIColor colorWithWhite:0 alpha:kTitleTextColorAlpha]; _title.textColor = [UIColor colorWithWhite:0 alpha:kTitleTextColorAlpha];
_title.font = [UIFont systemFontOfSize:kTitleFontSize]; _title.font = [UIFont preferredFontForTextStyle:UIFontTextStyleSubheadline];
[self addSubview:_title]; [self addSubview:_title];
// Subtitle. // Subtitle.
_subtitle = [[UILabel alloc] init]; _subtitle = [[UILabel alloc] init];
_subtitle.translatesAutoresizingMaskIntoConstraints = NO; _subtitle.translatesAutoresizingMaskIntoConstraints = NO;
_subtitle.numberOfLines = 0;
_subtitle.textColor = _subtitle.textColor =
[UIColor colorWithWhite:0 alpha:kSubtitleTextColorAlpha]; [UIColor colorWithWhite:0 alpha:kSubtitleTextColorAlpha];
_subtitle.font = [UIFont systemFontOfSize:kSubtitleFontSize]; _subtitle.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
[self addSubview:_subtitle]; [self addSubview:_subtitle];
// Text container.
UILayoutGuide* textContainerGuide = [[UILayoutGuide alloc] init];
[self addLayoutGuide:textContainerGuide];
// Layout constraints. // Layout constraints.
NSDictionary* views = @{ NSDictionary* views = @{
@"avatar" : _avatarView, @"avatar" : _avatarView,
@"title" : _title, @"container" : textContainerGuide,
@"subtitle" : _subtitle, @"subtitle" : _subtitle,
}; };
NSDictionary* metrics = @{ NSDictionary* metrics = @{
...@@ -91,7 +95,7 @@ const CGFloat kSubtitleTextColorAlpha = .54; ...@@ -91,7 +95,7 @@ const CGFloat kSubtitleTextColorAlpha = .54;
}; };
NSArray* constraints = @[ NSArray* constraints = @[
// Horizontal constraints. // Horizontal constraints.
@"H:|-(HAvatarMargin)-[avatar]-(HAvatarMargin)-[title]|", @"H:|-(HAvatarMargin)-[avatar]-(HAvatarMargin)-[container]|",
// Vertical constraints. // Vertical constraints.
// Size constraints. // Size constraints.
@"H:[avatar(AvatarSize)]", @"H:[avatar(AvatarSize)]",
...@@ -102,22 +106,39 @@ const CGFloat kSubtitleTextColorAlpha = .54; ...@@ -102,22 +106,39 @@ const CGFloat kSubtitleTextColorAlpha = .54;
AddSameConstraintsToSides(_title, _subtitle, AddSameConstraintsToSides(_title, _subtitle,
LayoutSides::kLeading | LayoutSides::kTrailing); LayoutSides::kLeading | LayoutSides::kTrailing);
_titleConstraintForNameAndEmail = _titleConstraintForNameAndEmail =
[self.centerYAnchor constraintEqualToAnchor:_title.bottomAnchor [_subtitle.topAnchor constraintEqualToAnchor:_title.bottomAnchor
constant:kTitleOffset]; constant:kTitleOffset];
_titleConstraintForEmailOnly = _titleConstraintForEmailOnly = [textContainerGuide.bottomAnchor
[self.centerYAnchor constraintEqualToAnchor:_title.centerYAnchor]; constraintEqualToAnchor:_title.bottomAnchor];
[self.centerYAnchor constraintEqualToAnchor:_subtitle.topAnchor
constant:-kTitleOffset] [NSLayoutConstraint activateConstraints:@[
.active = YES; [self.centerYAnchor
constraintEqualToAnchor:textContainerGuide.centerYAnchor],
[textContainerGuide.leadingAnchor
constraintEqualToAnchor:_title.leadingAnchor],
[textContainerGuide.leadingAnchor
constraintEqualToAnchor:_subtitle.leadingAnchor],
[textContainerGuide.trailingAnchor
constraintEqualToAnchor:_title.trailingAnchor],
[textContainerGuide.trailingAnchor
constraintEqualToAnchor:_subtitle.trailingAnchor],
[textContainerGuide.topAnchor constraintEqualToAnchor:_title.topAnchor],
[textContainerGuide.bottomAnchor
constraintEqualToAnchor:_subtitle.bottomAnchor],
]];
_verticalConstraints = @[ _verticalConstraints = @[
[_avatarView.topAnchor constraintEqualToAnchor:self.topAnchor [_avatarView.topAnchor
constant:kVerticalMargin], constraintGreaterThanOrEqualToAnchor:self.topAnchor
[self.bottomAnchor constraintEqualToAnchor:_avatarView.bottomAnchor constant:kVerticalMargin],
constant:kVerticalMargin], [self.bottomAnchor
[_title.topAnchor constraintGreaterThanOrEqualToAnchor:self.topAnchor constraintGreaterThanOrEqualToAnchor:_avatarView.bottomAnchor
constant:kVerticalMargin], constant:kVerticalMargin],
[textContainerGuide.topAnchor
constraintGreaterThanOrEqualToAnchor:self.topAnchor
constant:kVerticalMargin],
[self.bottomAnchor [self.bottomAnchor
constraintGreaterThanOrEqualToAnchor:_subtitle.bottomAnchor constraintGreaterThanOrEqualToAnchor:textContainerGuide.bottomAnchor
constant:kVerticalMargin], constant:kVerticalMargin],
]; ];
[NSLayoutConstraint activateConstraints:_verticalConstraints]; [NSLayoutConstraint activateConstraints:_verticalConstraints];
......
...@@ -125,10 +125,12 @@ NSString* const kSyncCompleteIconName = @"ic_sync_complete"; ...@@ -125,10 +125,12 @@ NSString* const kSyncCompleteIconName = @"ic_sync_complete";
} }
- (void)scrollToBottom { - (void)scrollToBottom {
// Add one point to make sure that it is actually scrolled to the bottom (as
// there are some issues when the fonts are increased).
CGPoint bottomOffset = CGPoint bottomOffset =
CGPointMake(0, self.scrollView.contentSize.height - CGPointMake(0, self.scrollView.contentSize.height -
self.scrollView.bounds.size.height + self.scrollView.bounds.size.height +
self.scrollView.contentInset.bottom); self.scrollView.contentInset.bottom + 1);
[self.scrollView setContentOffset:bottomOffset animated:YES]; [self.scrollView setContentOffset:bottomOffset animated:YES];
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment