Index: ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.mm |
diff --git a/ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.mm b/ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.mm |
index 9618ce4a96d401f211462b6e9ee889f491b4cff3..b488546cf267024fce3f1af47b04206769bea237 100644 |
--- a/ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.mm |
+++ b/ios/chrome/browser/ui/reading_list/reading_list_collection_view_item.mm |
@@ -7,6 +7,7 @@ |
#include "base/strings/sys_string_conversions.h" |
#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" |
#import "ios/chrome/browser/ui/favicon_view.h" |
+#import "ios/chrome/browser/ui/reading_list/reading_list_collection_view_item_accessibility_delegate.h" |
#import "ios/chrome/browser/ui/uikit_ui_util.h" |
#include "ios/chrome/grit/ios_strings.h" |
#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h" |
@@ -59,6 +60,10 @@ const CGFloat kMargin = 16; |
// The cell that is displaying this item, if any. Used to reload favicon when |
// the cell is on screen. Backed by WeakNSObject. |
@property(nonatomic, weak) ReadingListCell* displayedCell; |
+ |
+// Returns the accessibility custom actions associated with this item. |
+- (NSArray<UIAccessibilityCustomAction*>*)customActions; |
+ |
@end |
@implementation ReadingListCollectionViewItem |
@@ -70,6 +75,7 @@ const CGFloat kMargin = 16; |
@synthesize faviconPageURL = _faviconPageURL; |
@synthesize displayedCell = _displayedCell; |
@synthesize distillationState = _distillationState; |
+@synthesize accessibilityDelegate = _accessibilityDelegate; |
- (instancetype)initWithType:(NSInteger)type |
attributesProvider:(FaviconAttributesProvider*)provider |
@@ -111,6 +117,7 @@ const CGFloat kMargin = 16; |
(ReadingListEntry::DistillationState)distillationState { |
self.displayedCell.distillationState = distillationState; |
self.displayedCell.accessibilityLabel = [self accessibilityLabel]; |
+ self.displayedCell.accessibilityCustomActions = [self customActions]; |
_distillationState = distillationState; |
} |
@@ -128,6 +135,7 @@ const CGFloat kMargin = 16; |
cell.distillationState = _distillationState; |
cell.isAccessibilityElement = YES; |
cell.accessibilityLabel = [self accessibilityLabel]; |
+ cell.accessibilityCustomActions = [self customActions]; |
} |
#pragma mark - ReadingListCellDelegate |
@@ -154,6 +162,102 @@ const CGFloat kMargin = 16; |
base::SysNSStringToUTF16(self.detailText)); |
} |
+#pragma mark - AccessibilityCustomAction |
+ |
+- (NSArray<UIAccessibilityCustomAction*>*)customActions { |
+ UIAccessibilityCustomAction* deleteAction = [ |
+ [UIAccessibilityCustomAction alloc] |
+ initWithName:l10n_util::GetNSString(IDS_IOS_READING_LIST_DELETE_BUTTON) |
+ target:self |
+ selector:@selector(deleteEntry)]; |
+ UIAccessibilityCustomAction* toogleReadStatus = nil; |
+ if ([self.accessibilityDelegate isEntryRead:self]) { |
+ toogleReadStatus = [[UIAccessibilityCustomAction alloc] |
+ initWithName:l10n_util::GetNSString( |
+ IDS_IOS_READING_LIST_MARK_UNREAD_BUTTON) |
+ target:self |
+ selector:@selector(markUnread)]; |
+ } else { |
+ toogleReadStatus = [[UIAccessibilityCustomAction alloc] |
+ initWithName:l10n_util::GetNSString( |
+ IDS_IOS_READING_LIST_MARK_READ_BUTTON) |
+ target:self |
+ selector:@selector(markRead)]; |
+ } |
+ |
+ UIAccessibilityCustomAction* openInNewTabAction = |
+ [[UIAccessibilityCustomAction alloc] |
+ initWithName:l10n_util::GetNSString( |
+ IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB) |
+ target:self |
+ selector:@selector(openInNewTab)]; |
+ UIAccessibilityCustomAction* openInNewIncognitoTabAction = |
+ [[UIAccessibilityCustomAction alloc] |
+ initWithName:l10n_util::GetNSString( |
+ IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB) |
+ target:self |
+ selector:@selector(openInNewIncognitoTab)]; |
+ UIAccessibilityCustomAction* copyURLAction = |
+ [[UIAccessibilityCustomAction alloc] |
+ initWithName:l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_COPY) |
+ target:self |
+ selector:@selector(copyURL)]; |
+ |
+ NSMutableArray* customActions = [NSMutableArray |
+ arrayWithObjects:deleteAction, toogleReadStatus, openInNewTabAction, |
+ openInNewIncognitoTabAction, copyURLAction, nil]; |
+ |
+ if (self.distillationState == ReadingListEntry::PROCESSED) { |
+ // Add the possibility to open offline version only if the entry is |
+ // distilled. |
+ UIAccessibilityCustomAction* openOfflineAction = |
+ [[UIAccessibilityCustomAction alloc] |
+ initWithName:l10n_util::GetNSString( |
+ IDS_IOS_READING_LIST_CONTENT_CONTEXT_OFFLINE) |
+ target:self |
+ selector:@selector(openOffline)]; |
+ |
+ [customActions addObject:openOfflineAction]; |
+ } |
+ |
+ return customActions; |
+} |
+ |
+- (BOOL)deleteEntry { |
+ [self.accessibilityDelegate deleteEntry:self]; |
+ return YES; |
+} |
+ |
+- (BOOL)markRead { |
+ [self.accessibilityDelegate markEntryRead:self]; |
+ return YES; |
+} |
+ |
+- (BOOL)markUnread { |
+ [self.accessibilityDelegate markEntryUnread:self]; |
+ return YES; |
+} |
+ |
+- (BOOL)openInNewTab { |
+ [self.accessibilityDelegate openEntryInNewTab:self]; |
+ return YES; |
+} |
+ |
+- (BOOL)openInNewIncognitoTab { |
+ [self.accessibilityDelegate openEntryInNewIncognitoTab:self]; |
+ return YES; |
+} |
+ |
+- (BOOL)copyURL { |
+ [self.accessibilityDelegate copyEntryURL:self]; |
+ return YES; |
+} |
+ |
+- (BOOL)openOffline { |
+ [self.accessibilityDelegate openEntryOffline:self]; |
+ return YES; |
+} |
+ |
#pragma mark - NSObject |
- (NSString*)description { |
@@ -281,6 +385,7 @@ const CGFloat kMargin = 16; |
self.textLabel.text = nil; |
self.detailTextLabel.text = nil; |
self.distillationState = ReadingListEntry::WAITING; |
+ self.accessibilityCustomActions = nil; |
[super prepareForReuse]; |
} |