Commit ee1229d3 authored by Kurt Horimoto's avatar Kurt Horimoto Committed by Commit Bot

[iOS] Update NTP Reading List a11y label to include unread article count

This CL updates ContentSuggestionsMostVisitedActionItem to support
custom a11y labels that differ from their titles, and adds a custom
label for the Reading List cell that states the number of unread
articles.

Bug: 862299
Cq-Include-Trybots: luci.chromium.try:ios-simulator-full-configs;master.tryserver.chromium.mac:ios-simulator-cronet
Change-Id: I972b5996fb3398154f656b8ea056b9028d468af0
Reviewed-on: https://chromium-review.googlesource.com/1137027
Commit-Queue: Kurt Horimoto <kkhorimoto@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#575860}
parent ff6d76db
...@@ -573,6 +573,12 @@ locale. The strings in this file are specific to iOS. ...@@ -573,6 +573,12 @@ locale. The strings in this file are specific to iOS.
<message name="IDS_IOS_CONTENT_SUGGESTIONS_READING_LIST" desc="The Reading List title on the new tab page [Length: 10em]"> <message name="IDS_IOS_CONTENT_SUGGESTIONS_READING_LIST" desc="The Reading List title on the new tab page [Length: 10em]">
Reading List Reading List
</message> </message>
<message name="IDS_IOS_CONTENT_SUGGESTIONS_READING_LIST_ACCESSIBILITY_LABEL_ONE_UNREAD" desc="The accessibility label to use for the reading list content suggestion cell when there is only a single unread article [Length: unlimited]">
1 unread Reading List article.
</message>
<message name="IDS_IOS_CONTENT_SUGGESTIONS_READING_LIST_ACCESSIBILITY_LABEL" desc="The accessibility label to use for the reading list content suggestion cell when there are multiple unread articles [Length: unlimited]">
<ph name="UNREAD_COUNT">$1<ex>4</ex></ph> unread Reading List articles.
</message>
<message name="IDS_IOS_CONTENT_SUGGESTIONS_RECENT_TABS" desc="The Recent Tabs title on the new tab page [Length: 10em]"> <message name="IDS_IOS_CONTENT_SUGGESTIONS_RECENT_TABS" desc="The Recent Tabs title on the new tab page [Length: 10em]">
Recent Tabs Recent Tabs
</message> </message>
......
...@@ -27,9 +27,13 @@ typedef NS_ENUM(NSInteger, ContentSuggestionsMostVisitedAction) { ...@@ -27,9 +27,13 @@ typedef NS_ENUM(NSInteger, ContentSuggestionsMostVisitedAction) {
- (nonnull instancetype)initWithAction: - (nonnull instancetype)initWithAction:
(ContentSuggestionsMostVisitedAction)action; (ContentSuggestionsMostVisitedAction)action;
// Text for the title and the accessibility label of the cell. // Text for the title of the cell.
@property(nonatomic, copy, nonnull) NSString* title; @property(nonatomic, copy, nonnull) NSString* title;
// The accessibility label of the cell. If none is provided, self.title is used
// as the label.
@property(nonatomic, copy, nullable) NSString* accessibilityLabel;
// The action type for this button. // The action type for this button.
@property(nonatomic, assign) ContentSuggestionsMostVisitedAction action; @property(nonatomic, assign) ContentSuggestionsMostVisitedAction action;
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_action_item.h" #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_action_item.h"
#include "base/logging.h"
#include "base/strings/sys_string_conversions.h"
#include "base/strings/utf_string_conversions.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_action_cell.h" #import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_action_cell.h"
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
...@@ -19,6 +22,7 @@ ...@@ -19,6 +22,7 @@
@synthesize metricsRecorded = _metricsRecorded; @synthesize metricsRecorded = _metricsRecorded;
@synthesize suggestionIdentifier = _suggestionIdentifier; @synthesize suggestionIdentifier = _suggestionIdentifier;
@synthesize title = _title; @synthesize title = _title;
@synthesize accessibilityLabel = _accessibilityLabel;
- (instancetype)initWithAction:(ContentSuggestionsMostVisitedAction)action { - (instancetype)initWithAction:(ContentSuggestionsMostVisitedAction)action {
self = [super initWithType:0]; self = [super initWithType:0];
...@@ -30,13 +34,30 @@ ...@@ -30,13 +34,30 @@
return self; return self;
} }
#pragma mark - Accessors
- (void)setTitle:(NSString*)title {
if ([_title isEqualToString:title])
return;
_title = title;
[self updateAccessibilityLabel];
}
- (void)setCount:(NSInteger)count {
if (_count == count)
return;
_count = count;
[self updateAccessibilityLabel];
}
#pragma mark - AccessibilityCustomAction #pragma mark - AccessibilityCustomAction
- (void)configureCell:(ContentSuggestionsMostVisitedActionCell*)cell { - (void)configureCell:(ContentSuggestionsMostVisitedActionCell*)cell {
[super configureCell:cell]; [super configureCell:cell];
cell.accessibilityCustomActions = nil; cell.accessibilityCustomActions = nil;
cell.titleLabel.text = self.title; cell.titleLabel.text = self.title;
cell.accessibilityLabel = self.title; cell.accessibilityLabel =
self.accessibilityLabel.length ? self.accessibilityLabel : self.title;
cell.iconView.image = [self imageForAction:_action]; cell.iconView.image = [self imageForAction:_action];
if (self.count != 0) { if (self.count != 0) {
cell.countLabel.text = [@(self.count) stringValue]; cell.countLabel.text = [@(self.count) stringValue];
...@@ -54,6 +75,7 @@ ...@@ -54,6 +75,7 @@
#pragma mark - Private #pragma mark - Private
// Returns the title to use for a cell with |action|.
- (NSString*)titleForAction:(ContentSuggestionsMostVisitedAction)action { - (NSString*)titleForAction:(ContentSuggestionsMostVisitedAction)action {
switch (action) { switch (action) {
case ContentSuggestionsMostVisitedActionBookmark: case ContentSuggestionsMostVisitedActionBookmark:
...@@ -67,6 +89,7 @@ ...@@ -67,6 +89,7 @@
} }
} }
// Returns the image to use for a cell with |action|.
- (UIImage*)imageForAction:(ContentSuggestionsMostVisitedAction)action { - (UIImage*)imageForAction:(ContentSuggestionsMostVisitedAction)action {
switch (action) { switch (action) {
case ContentSuggestionsMostVisitedActionBookmark: case ContentSuggestionsMostVisitedActionBookmark:
...@@ -80,4 +103,30 @@ ...@@ -80,4 +103,30 @@
} }
} }
// Updates self.accessibilityLabel based on the current property values.
- (void)updateAccessibilityLabel {
// Resetting self.accessibilityLabel to nil will prompt self.title to be used
// as the default label. This default value should be used if:
// - the cell is not for Reading List,
// - there are no unread articles in the reading list.
if (self.action != ContentSuggestionsMostVisitedActionReadingList ||
self.count <= 0) {
self.accessibilityLabel = nil;
return;
}
BOOL hasMultipleArticles = self.count > 1;
int messageID =
hasMultipleArticles
? IDS_IOS_CONTENT_SUGGESTIONS_READING_LIST_ACCESSIBILITY_LABEL
: IDS_IOS_CONTENT_SUGGESTIONS_READING_LIST_ACCESSIBILITY_LABEL_ONE_UNREAD;
if (hasMultipleArticles) {
self.accessibilityLabel = l10n_util::GetNSStringF(
messageID, base::SysNSStringToUTF16([@(self.count) stringValue]));
} else {
self.accessibilityLabel = l10n_util::GetNSString(messageID);
}
DCHECK(self.accessibilityLabel.length);
}
@end @end
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