Commit 28cefc4b authored by Menglu Huang's avatar Menglu Huang Committed by Commit Bot

Revert "Add AccessibilityCustomAction to ContentSuggestions"

This reverts commit 7405f12a.

Reason for revert: <INSERT REASONING HERE>
This CL breaks ios_showcase_tests.
https://build.chromium.org/p/chromium.fyi/builders/EarlGreyiOS/builds/30194

Original change's description:
> Add AccessibilityCustomAction to ContentSuggestions
> 
> In order to have the feature accessible, all the actions using gestures
> (long press, swipe to dismiss) must have custom accessibility actions.
> Also adds action sheet to Read Later cells.
> 
> Bug: 749131
> Change-Id: I2c81f6443a49bdf0cdccc3ec747b0ffd42513ef1
> Reviewed-on: https://chromium-review.googlesource.com/593652
> Commit-Queue: Gauthier Ambard <gambard@chromium.org>
> Reviewed-by: Jean-François Geyelin <jif@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#490930}

TBR=jif@chromium.org,gambard@chromium.org

Change-Id: I805e907403106623dc9c67cc89ccbbc5546d0ee1
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 749131
Reviewed-on: https://chromium-review.googlesource.com/596591Reviewed-by: default avatarYuke Liao <liaoyuke@chromium.org>
Commit-Queue: Menglu Huang <huangml@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491088}
parent dba6bbe4
......@@ -5,6 +5,7 @@
source_set("content_suggestions") {
configs += [ "//build/config/compiler:enable_arc" ]
sources = [
"content_suggestions_alert_commands.h",
"content_suggestions_alert_factory.h",
"content_suggestions_alert_factory.mm",
"content_suggestions_category_wrapper.h",
......@@ -93,7 +94,6 @@ source_set("eg_tests") {
"//ios/chrome/browser/ui/alert_coordinator",
"//ios/chrome/browser/ui/alert_coordinator",
"//ios/chrome/browser/ui/collection_view/cells",
"//ios/chrome/browser/ui/content_suggestions/cells",
"//ios/chrome/browser/ui/util",
"//ios/chrome/test/earl_grey:test_support",
"//ui/strings",
......
......@@ -2,49 +2,38 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_CELLS_CONTENT_SUGGESTIONS_GESTURE_COMMANDS_H_
#define IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_CELLS_CONTENT_SUGGESTIONS_GESTURE_COMMANDS_H_
#ifndef IOS_CHROME_BROWSER_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_ALERT_COMMANDS_H_
#define IOS_CHROME_BROWSER_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_ALERT_COMMANDS_H_
#import <UIKit/UIKit.h>
@class ContentSuggestionsItem;
@class ContentSuggestionsMostVisitedItem;
@class CollectionViewItem;
// Command protocol for the interactions based on a gesture, handling the
// callbacks from the alerts and the accessibility custom actions.
@protocol ContentSuggestionsGestureCommands
// Command protocol for the ContentSuggestionsAlertFactory, handling the
// callbacks from the alerts.
@protocol ContentSuggestionsAlertCommands
// Opens the URL corresponding to the |item| in a new tab, |incognito| or not.
// The item has to be a suggestion item.
- (void)openNewTabWithSuggestionsItem:(nonnull ContentSuggestionsItem*)item
- (void)openNewTabWithSuggestionsItem:(nonnull CollectionViewItem*)item
incognito:(BOOL)incognito;
// Adds the |item| to the reading list. The item has to be a suggestion item.
- (void)addItemToReadingList:(nonnull ContentSuggestionsItem*)item;
- (void)addItemToReadingList:(nonnull CollectionViewItem*)item;
// Dismiss the |item| at |indexPath|. The item has to be a suggestion item.
// If |indexPath| is nil, the commands handler will find the index path
// associated with the |item|.
- (void)dismissSuggestion:(nonnull ContentSuggestionsItem*)item
atIndexPath:(nullable NSIndexPath*)indexPath;
- (void)dismissSuggestion:(nonnull CollectionViewItem*)item
atIndexPath:(nonnull NSIndexPath*)indexPath;
// Open the URL corresponding to the |item| in a new tab, |incognito| or not.
// The item has to be a Most Visited item.
- (void)openNewTabWithMostVisitedItem:
(nonnull ContentSuggestionsMostVisitedItem*)item
- (void)openNewTabWithMostVisitedItem:(nonnull CollectionViewItem*)item
incognito:(BOOL)incognito
atIndex:(NSInteger)mostVisitedIndex;
// Open the URL corresponding to the |item| in a new tab, |incognito| or not.
// The index of the item will be find by the command handler. The item has to
// be a Most Visited item.
- (void)openNewTabWithMostVisitedItem:
(nonnull ContentSuggestionsMostVisitedItem*)item
incognito:(BOOL)incognito;
// Removes the most visited |item|.
- (void)removeMostVisited:(nonnull ContentSuggestionsMostVisitedItem*)item;
- (void)removeMostVisited:(nonnull CollectionViewItem*)item;
@end
#endif // IOS_CHROME_BROWSER_UI_CONTENT_SUGGESTIONS_CELLS_CONTENT_SUGGESTIONS_GESTURE_COMMANDS_H_
#endif // IOS_CHROME_BROWSER_CONTENT_SUGGESTIONS_CONTENT_SUGGESTIONS_ALERT_COMMANDS_H_
......@@ -7,9 +7,9 @@
#import <EarlGrey/EarlGrey.h>
#import <XCTest/XCTest.h>
#import "ios/chrome/browser/content_suggestions/content_suggestions_alert_commands.h"
#import "ios/chrome/browser/ui/alert_coordinator/alert_coordinator.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_gesture_commands.h"
#include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/util/top_view_controller.h"
#include "ios/chrome/grit/ios_strings.h"
......@@ -35,7 +35,6 @@
onViewController:viewController
atPoint:CGPointMake(50, 50)
atIndexPath:nil
readLaterAction:YES
commandHandler:nil];
[coordinator start];
......@@ -68,11 +67,11 @@
UIViewController* viewController =
top_view_controller::TopPresentedViewController();
AlertCoordinator* coordinator = [ContentSuggestionsAlertFactory
alertCoordinatorForMostVisitedItem:nil
onViewController:viewController
atPoint:CGPointMake(50, 50)
atIndexPath:nil
commandHandler:nil];
alertCoordinatorForSuggestionItem:nil
onViewController:viewController
atPoint:CGPointMake(50, 50)
atIndexPath:nil
commandHandler:nil];
[coordinator start];
[[EarlGrey
......
......@@ -8,9 +8,8 @@
#import <UIKit/UIKit.h>
@class AlertCoordinator;
@class ContentSuggestionsItem;
@class ContentSuggestionsMostVisitedItem;
@protocol ContentSuggestionsGestureCommands;
@class CollectionViewItem;
@protocol ContentSuggestionsAlertCommands;
// Factory for AlertCoordinators for ContentSuggestions.
@interface ContentSuggestionsAlertFactory : NSObject
......@@ -21,22 +20,21 @@
// |commandHandler| will receive callbacks when the user chooses one of the
// options displayed by the alert.
+ (AlertCoordinator*)
alertCoordinatorForSuggestionItem:(ContentSuggestionsItem*)item
alertCoordinatorForSuggestionItem:(CollectionViewItem*)item
onViewController:(UIViewController*)viewController
atPoint:(CGPoint)touchLocation
atIndexPath:(NSIndexPath*)indexPath
readLaterAction:(BOOL)readLaterAction
commandHandler:
(id<ContentSuggestionsGestureCommands>)commandHandler;
(id<ContentSuggestionsAlertCommands>)commandHandler;
// Same as above but for a MostVisited item.
+ (AlertCoordinator*)
alertCoordinatorForMostVisitedItem:(ContentSuggestionsMostVisitedItem*)item
alertCoordinatorForMostVisitedItem:(CollectionViewItem*)item
onViewController:(UIViewController*)viewController
atPoint:(CGPoint)touchLocation
atIndexPath:(NSIndexPath*)indexPath
commandHandler:
(id<ContentSuggestionsGestureCommands>)commandHandler;
(id<ContentSuggestionsAlertCommands>)commandHandler;
@end
......
......@@ -4,10 +4,9 @@
#import "ios/chrome/browser/content_suggestions/content_suggestions_alert_factory.h"
#import "ios/chrome/browser/content_suggestions/content_suggestions_alert_commands.h"
#import "ios/chrome/browser/ui/alert_coordinator/action_sheet_coordinator.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_gesture_commands.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_item.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.h"
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/strings/grit/ui_strings.h"
......@@ -19,13 +18,12 @@
@implementation ContentSuggestionsAlertFactory
+ (AlertCoordinator*)
alertCoordinatorForSuggestionItem:(ContentSuggestionsItem*)item
alertCoordinatorForSuggestionItem:(CollectionViewItem*)item
onViewController:(UIViewController*)viewController
atPoint:(CGPoint)touchLocation
atIndexPath:(NSIndexPath*)indexPath
readLaterAction:(BOOL)readLaterAction
commandHandler:
(id<ContentSuggestionsGestureCommands>)commandHandler {
(id<ContentSuggestionsAlertCommands>)commandHandler {
AlertCoordinator* alertCoordinator = [[ActionSheetCoordinator alloc]
initWithBaseViewController:viewController
title:nil
......@@ -34,15 +32,15 @@ alertCoordinatorForSuggestionItem:(ContentSuggestionsItem*)item
0)
view:[viewController view]];
__weak ContentSuggestionsItem* weakItem = item;
__weak id<ContentSuggestionsGestureCommands> weakCommandHandler =
__weak CollectionViewItem* weakItem = item;
__weak id<ContentSuggestionsAlertCommands> weakCommandHandler =
commandHandler;
NSString* openInNewTabTitle =
l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB);
[alertCoordinator addItemWithTitle:openInNewTabTitle
action:^{
ContentSuggestionsItem* strongItem = weakItem;
CollectionViewItem* strongItem = weakItem;
if (strongItem) {
// TODO(crbug.com/691979): Add metrics.
[weakCommandHandler
......@@ -56,7 +54,7 @@ alertCoordinatorForSuggestionItem:(ContentSuggestionsItem*)item
l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB);
[alertCoordinator addItemWithTitle:openInNewTabIncognitoTitle
action:^{
ContentSuggestionsItem* strongItem = weakItem;
CollectionViewItem* strongItem = weakItem;
if (strongItem) {
// TODO(crbug.com/691979): Add metrics.
[weakCommandHandler
......@@ -66,26 +64,24 @@ alertCoordinatorForSuggestionItem:(ContentSuggestionsItem*)item
}
style:UIAlertActionStyleDefault];
if (readLaterAction) {
NSString* readLaterTitle =
l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_ADDTOREADINGLIST);
[alertCoordinator
addItemWithTitle:readLaterTitle
action:^{
ContentSuggestionsItem* strongItem = weakItem;
if (strongItem) {
// TODO(crbug.com/691979): Add metrics.
[weakCommandHandler addItemToReadingList:strongItem];
}
NSString* readLaterTitle =
l10n_util::GetNSString(IDS_IOS_CONTENT_CONTEXT_ADDTOREADINGLIST);
[alertCoordinator
addItemWithTitle:readLaterTitle
action:^{
CollectionViewItem* strongItem = weakItem;
if (strongItem) {
// TODO(crbug.com/691979): Add metrics.
[weakCommandHandler addItemToReadingList:strongItem];
}
style:UIAlertActionStyleDefault];
}
}
style:UIAlertActionStyleDefault];
NSString* deleteTitle =
l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_REMOVE);
[alertCoordinator addItemWithTitle:deleteTitle
action:^{
ContentSuggestionsItem* strongItem = weakItem;
CollectionViewItem* strongItem = weakItem;
if (strongItem) {
// TODO(crbug.com/691979): Add metrics.
[weakCommandHandler
......@@ -104,12 +100,12 @@ alertCoordinatorForSuggestionItem:(ContentSuggestionsItem*)item
}
+ (AlertCoordinator*)
alertCoordinatorForMostVisitedItem:(ContentSuggestionsMostVisitedItem*)item
alertCoordinatorForMostVisitedItem:(CollectionViewItem*)item
onViewController:(UIViewController*)viewController
atPoint:(CGPoint)touchLocation
atIndexPath:(NSIndexPath*)indexPath
commandHandler:
(id<ContentSuggestionsGestureCommands>)commandHandler {
(id<ContentSuggestionsAlertCommands>)commandHandler {
AlertCoordinator* alertCoordinator = [[ActionSheetCoordinator alloc]
initWithBaseViewController:viewController
title:nil
......@@ -118,15 +114,15 @@ alertCoordinatorForMostVisitedItem:(ContentSuggestionsMostVisitedItem*)item
0)
view:[viewController view]];
__weak ContentSuggestionsMostVisitedItem* weakItem = item;
__weak id<ContentSuggestionsGestureCommands> weakCommandHandler =
__weak CollectionViewItem* weakItem = item;
__weak id<ContentSuggestionsAlertCommands> weakCommandHandler =
commandHandler;
[alertCoordinator
addItemWithTitle:l10n_util::GetNSStringWithFixup(
IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB)
action:^{
ContentSuggestionsMostVisitedItem* strongItem = weakItem;
CollectionViewItem* strongItem = weakItem;
if (strongItem) {
[weakCommandHandler
openNewTabWithMostVisitedItem:strongItem
......@@ -140,7 +136,7 @@ alertCoordinatorForMostVisitedItem:(ContentSuggestionsMostVisitedItem*)item
addItemWithTitle:l10n_util::GetNSStringWithFixup(
IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB)
action:^{
ContentSuggestionsMostVisitedItem* strongItem = weakItem;
CollectionViewItem* strongItem = weakItem;
if (strongItem) {
[weakCommandHandler
openNewTabWithMostVisitedItem:strongItem
......@@ -154,7 +150,7 @@ alertCoordinatorForMostVisitedItem:(ContentSuggestionsMostVisitedItem*)item
addItemWithTitle:l10n_util::GetNSStringWithFixup(
IDS_IOS_CONTENT_SUGGESTIONS_REMOVE)
action:^{
ContentSuggestionsMostVisitedItem* strongItem = weakItem;
CollectionViewItem* strongItem = weakItem;
if (strongItem) {
[weakCommandHandler removeMostVisited:strongItem];
}
......
......@@ -17,6 +17,7 @@
#include "components/reading_list/core/reading_list_model.h"
#include "components/strings/grit/components_strings.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/content_suggestions/content_suggestions_alert_commands.h"
#import "ios/chrome/browser/content_suggestions/content_suggestions_alert_factory.h"
#import "ios/chrome/browser/content_suggestions/content_suggestions_header_view_controller.h"
#import "ios/chrome/browser/content_suggestions/content_suggestions_header_view_controller_delegate.h"
......@@ -34,7 +35,6 @@
#import "ios/chrome/browser/ui/commands/generic_chrome_command.h"
#include "ios/chrome/browser/ui/commands/ios_command_ids.h"
#import "ios/chrome/browser/ui/commands/open_new_tab_command.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_gesture_commands.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_item.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.h"
#import "ios/chrome/browser/ui/content_suggestions/content_suggestions_collection_utils.h"
......@@ -66,8 +66,8 @@ const char kNTPHelpURL[] = "https://support.google.com/chrome/?p=new_tab";
} // namespace
@interface ContentSuggestionsCoordinator ()<
ContentSuggestionsAlertCommands,
ContentSuggestionsCommands,
ContentSuggestionsGestureCommands,
ContentSuggestionsHeaderViewControllerCommandHandler,
ContentSuggestionsHeaderViewControllerDelegate,
ContentSuggestionsViewControllerAudience,
......@@ -219,18 +219,14 @@ const char kNTPHelpURL[] = "https://support.google.com/chrome/?p=new_tab";
rendererInitiated:NO];
}
- (void)displayContextMenuForSuggestion:(CollectionViewItem*)item
atPoint:(CGPoint)touchLocation
atIndexPath:(NSIndexPath*)indexPath
readLaterAction:(BOOL)readLaterAction {
ContentSuggestionsItem* suggestionsItem =
base::mac::ObjCCastStrict<ContentSuggestionsItem>(item);
- (void)displayContextMenuForArticle:(CollectionViewItem*)item
atPoint:(CGPoint)touchLocation
atIndexPath:(NSIndexPath*)indexPath {
self.alertCoordinator = [ContentSuggestionsAlertFactory
alertCoordinatorForSuggestionItem:suggestionsItem
alertCoordinatorForSuggestionItem:item
onViewController:self.suggestionsViewController
atPoint:touchLocation
atIndexPath:indexPath
readLaterAction:readLaterAction
commandHandler:self];
[self.alertCoordinator start];
......@@ -239,10 +235,8 @@ const char kNTPHelpURL[] = "https://support.google.com/chrome/?p=new_tab";
- (void)displayContextMenuForMostVisitedItem:(CollectionViewItem*)item
atPoint:(CGPoint)touchLocation
atIndexPath:(NSIndexPath*)indexPath {
ContentSuggestionsMostVisitedItem* mostVisitedItem =
base::mac::ObjCCastStrict<ContentSuggestionsMostVisitedItem>(item);
self.alertCoordinator = [ContentSuggestionsAlertFactory
alertCoordinatorForMostVisitedItem:mostVisitedItem
alertCoordinatorForMostVisitedItem:item
onViewController:self.suggestionsViewController
atPoint:touchLocation
atIndexPath:indexPath
......@@ -282,54 +276,52 @@ const char kNTPHelpURL[] = "https://support.google.com/chrome/?p=new_tab";
rendererInitiated:NO];
}
#pragma mark - ContentSuggestionsGestureCommands
#pragma mark - ContentSuggestionsAlertCommands
- (void)openNewTabWithSuggestionsItem:(ContentSuggestionsItem*)item
- (void)openNewTabWithSuggestionsItem:(CollectionViewItem*)item
incognito:(BOOL)incognito {
[self openNewTabWithURL:item.URL incognito:incognito];
ContentSuggestionsItem* suggestionsItem =
base::mac::ObjCCastStrict<ContentSuggestionsItem>(item);
[self openNewTabWithURL:suggestionsItem.URL incognito:incognito];
}
- (void)addItemToReadingList:(ContentSuggestionsItem*)item {
- (void)addItemToReadingList:(CollectionViewItem*)item {
ContentSuggestionsItem* suggestionsItem =
base::mac::ObjCCastStrict<ContentSuggestionsItem>(item);
base::RecordAction(base::UserMetricsAction("MobileReadingListAdd"));
ReadingListModel* readingModel =
ReadingListModelFactory::GetForBrowserState(self.browserState);
readingModel->AddEntry(item.URL, base::SysNSStringToUTF8(item.title),
readingModel->AddEntry(suggestionsItem.URL,
base::SysNSStringToUTF8(suggestionsItem.title),
reading_list::ADDED_VIA_CURRENT_APP);
}
- (void)dismissSuggestion:(ContentSuggestionsItem*)item
- (void)dismissSuggestion:(CollectionViewItem*)item
atIndexPath:(NSIndexPath*)indexPath {
NSIndexPath* itemIndexPath = indexPath;
if (!itemIndexPath) {
// If the caller uses a nil |indexPath|, find it from the model.
itemIndexPath = [self.suggestionsViewController.collectionViewModel
indexPathForItem:item];
}
ContentSuggestionsItem* suggestionsItem =
base::mac::ObjCCastStrict<ContentSuggestionsItem>(item);
// TODO(crbug.com/691979): Add metrics.
[self.contentSuggestionsMediator dismissSuggestion:item.suggestionIdentifier];
[self.suggestionsViewController dismissEntryAtIndexPath:itemIndexPath];
[self.contentSuggestionsMediator
dismissSuggestion:suggestionsItem.suggestionIdentifier];
[self.suggestionsViewController dismissEntryAtIndexPath:indexPath];
}
- (void)openNewTabWithMostVisitedItem:(ContentSuggestionsMostVisitedItem*)item
- (void)openNewTabWithMostVisitedItem:(CollectionViewItem*)item
incognito:(BOOL)incognito
atIndex:(NSInteger)index {
[self logMostVisitedOpening:item atIndex:index];
[self openNewTabWithURL:item.URL incognito:incognito];
}
- (void)openNewTabWithMostVisitedItem:(ContentSuggestionsMostVisitedItem*)item
incognito:(BOOL)incognito {
NSInteger index =
[self.suggestionsViewController.collectionViewModel indexPathForItem:item]
.item;
[self openNewTabWithMostVisitedItem:item incognito:incognito atIndex:index];
ContentSuggestionsMostVisitedItem* mostVisitedItem =
base::mac::ObjCCastStrict<ContentSuggestionsMostVisitedItem>(item);
[self logMostVisitedOpening:mostVisitedItem atIndex:index];
[self openNewTabWithURL:mostVisitedItem.URL incognito:incognito];
}
- (void)removeMostVisited:(ContentSuggestionsMostVisitedItem*)item {
- (void)removeMostVisited:(CollectionViewItem*)item {
ContentSuggestionsMostVisitedItem* mostVisitedItem =
base::mac::ObjCCastStrict<ContentSuggestionsMostVisitedItem>(item);
base::RecordAction(base::UserMetricsAction("MostVisited_UrlBlacklisted"));
[self.contentSuggestionsMediator blacklistMostVisitedURL:item.URL];
[self showMostVisitedUndoForURL:item.URL];
[self.contentSuggestionsMediator blacklistMostVisitedURL:mostVisitedItem.URL];
[self showMostVisitedUndoForURL:mostVisitedItem.URL];
}
#pragma mark - ContentSuggestionsHeaderViewControllerDelegate
......
......@@ -25,7 +25,6 @@ class MostVisitedSites;
}
@protocol ContentSuggestionsCommands;
@protocol ContentSuggestionsGestureCommands;
@protocol ContentSuggestionsHeaderProvider;
@class ContentSuggestionIdentifier;
class GURL;
......@@ -50,9 +49,8 @@ initWithContentService:
- (nullable instancetype)init NS_UNAVAILABLE;
// Command handler for the mediator.
@property(nonatomic, weak, nullable)
id<ContentSuggestionsCommands, ContentSuggestionsGestureCommands>
commandHandler;
@property(nonatomic, weak, nullable) id<ContentSuggestionsCommands>
commandHandler;
@property(nonatomic, weak, nullable) id<ContentSuggestionsHeaderProvider>
headerProvider;
......
......@@ -452,7 +452,6 @@ initWithContentService:(ntp_snippets::ContentSuggestionsService*)contentService
ContentSuggestionsItem* suggestion =
ConvertSuggestion(contentSuggestion, sectionInfo, category);
suggestion.delegate = self;
suggestion.commandHandler = self.commandHandler;
[self.faviconMediator fetchFaviconForSuggestions:suggestion
inCategory:category];
......
......@@ -64,7 +64,6 @@ ContentSuggestionsItem* ConvertSuggestion(
}
if (category.IsKnownCategory(ntp_snippets::KnownCategories::ARTICLES)) {
suggestion.hasImage = YES;
suggestion.readLaterAction = YES;
}
return suggestion;
......
......@@ -4,7 +4,6 @@
source_set("cells") {
sources = [
"content_suggestions_gesture_commands.h",
"content_suggestions_item.h",
"content_suggestions_item.mm",
"content_suggestions_most_visited_item.h",
......
......@@ -16,8 +16,6 @@ class Time;
@class FaviconAttributes;
class GURL;
@protocol ContentSuggestionsGestureCommands;
// Delegate for SuggestedContent.
@protocol ContentSuggestionsItemDelegate
......@@ -50,10 +48,6 @@ class GURL;
@property(nonatomic, strong) FaviconAttributes* attributes;
// URL for the favicon, if different of |URL|.
@property(nonatomic, assign) GURL faviconURL;
// Whether this item should have an option to be read later.
@property(nonatomic, assign) BOOL readLaterAction;
// Command handler for the accessibility custom actions.
@property(nonatomic, weak) id<ContentSuggestionsGestureCommands> commandHandler;
@end
......
......@@ -7,7 +7,6 @@
#include "base/strings/sys_string_conversions.h"
#include "base/time/time.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_cell.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_gesture_commands.h"
#import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion_identifier.h"
#import "ios/chrome/browser/ui/favicon/favicon_attributes.h"
#import "ios/chrome/browser/ui/favicon/favicon_view.h"
......@@ -47,8 +46,6 @@
@synthesize faviconURL = _faviconURL;
@synthesize hasImage = _hasImage;
@synthesize firstTimeWithImage = _firstTimeWithImage;
@synthesize readLaterAction = _readLaterAction;
@synthesize commandHandler = _commandHandler;
- (instancetype)initWithType:(NSInteger)type
title:(NSString*)title
......@@ -78,7 +75,6 @@
date:[self relativeDate]];
cell.isAccessibilityElement = YES;
cell.accessibilityLabel = [self accessibilityLabel];
cell.accessibilityCustomActions = [self customActions];
}
- (void)setImage:(UIImage*)image {
......@@ -125,67 +121,4 @@
base::SysNSStringToUTF16([self relativeDate]));
}
#pragma mark - AccessibilityCustomAction
// Custom action for a cell configured with this item.
- (NSArray<UIAccessibilityCustomAction*>*)customActions {
UIAccessibilityCustomAction* openInNewTab =
[[UIAccessibilityCustomAction alloc]
initWithName:l10n_util::GetNSString(
IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB)
target:self
selector:@selector(openInNewTab)];
UIAccessibilityCustomAction* openInNewIncognitoTab =
[[UIAccessibilityCustomAction alloc]
initWithName:l10n_util::GetNSString(
IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB)
target:self
selector:@selector(openInNewIncognitoTab)];
NSMutableArray* customActions = [NSMutableArray
arrayWithObjects:openInNewTab, openInNewIncognitoTab, nil];
if (self.readLaterAction) {
UIAccessibilityCustomAction* readLater =
[[UIAccessibilityCustomAction alloc]
initWithName:l10n_util::GetNSString(
IDS_IOS_CONTENT_CONTEXT_ADDTOREADINGLIST)
target:self
selector:@selector(readLater)];
[customActions addObject:readLater];
}
UIAccessibilityCustomAction* removeSuggestion = [
[UIAccessibilityCustomAction alloc]
initWithName:l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_REMOVE)
target:self
selector:@selector(removeSuggestion)];
[customActions addObject:removeSuggestion];
return customActions;
}
// Target for custom action.
- (BOOL)openInNewTab {
[self.commandHandler openNewTabWithSuggestionsItem:self incognito:NO];
return YES;
}
// Target for custom action.
- (BOOL)openInNewIncognitoTab {
[self.commandHandler openNewTabWithSuggestionsItem:self incognito:YES];
return YES;
}
// Target for custom action.
- (BOOL)readLater {
[self.commandHandler addItemToReadingList:self];
return YES;
}
// Target for custom action.
- (BOOL)removeSuggestion {
[self.commandHandler dismissSuggestion:self atIndexPath:nil];
return YES;
}
@end
......@@ -37,7 +37,6 @@ TEST(ContentSuggestionsItemTest, CellIsConfiguredWithoutImage) {
item.hasImage = YES;
item.publisher = publisher;
item.publishDate = publishTime;
item.readLaterAction = YES;
OCMExpect([delegateMock loadImageForSuggestedItem:item]);
ContentSuggestionsCell* cell = [[[item cellClass] alloc] init];
ASSERT_EQ([ContentSuggestionsCell class], [cell class]);
......@@ -55,7 +54,6 @@ TEST(ContentSuggestionsItemTest, CellIsConfiguredWithoutImage) {
EXPECT_OCMOCK_VERIFY(cellMock);
EXPECT_EQ(title, cell.titleLabel.text);
EXPECT_OCMOCK_VERIFY(delegateMock);
EXPECT_EQ(4U, [cell.accessibilityCustomActions count]);
}
// Tests that configureCell: does not call the delegate if it fetched the image
......@@ -141,24 +139,4 @@ TEST(ContentSuggestionsItemTest, ImageAnimatedOnlyTheFirstTime) {
EXPECT_OCMOCK_VERIFY(cell1);
EXPECT_OCMOCK_VERIFY(cell2);
}
// Tests the custom actions when there is no read later actions.
TEST(ContentSuggestionsItemTest, NoReadLaterAction) {
// Setup.
NSString* title = @"testTitle";
GURL url = GURL("http://chromium.org");
ContentSuggestionsItem* item =
[[ContentSuggestionsItem alloc] initWithType:0 title:title url:url];
item.readLaterAction = NO;
item.image = [[UIImage alloc] init];
ContentSuggestionsCell* cell = [[[item cellClass] alloc] init];
// Action.
[item configureCell:cell];
// Tests.
EXPECT_EQ(3U, [cell.accessibilityCustomActions count]);
}
} // namespace
......@@ -10,7 +10,6 @@
#import "ios/chrome/browser/ui/collection_view/cells/collection_view_item.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/suggested_content.h"
@protocol ContentSuggestionsGestureCommands;
@class FaviconAttributes;
class GURL;
......@@ -27,9 +26,6 @@ class GURL;
@property(nonatomic, assign) ntp_tiles::TileSource source;
// Attributes for favicon.
@property(nonatomic, strong, nullable) FaviconAttributes* attributes;
// Command handler for the accessibility custom actions.
@property(nonatomic, weak, nullable) id<ContentSuggestionsGestureCommands>
commandHandler;
- (ntp_tiles::TileVisualType)tileType;
......
......@@ -4,13 +4,10 @@
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_item.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_gesture_commands.h"
#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_cell.h"
#import "ios/chrome/browser/ui/content_suggestions/identifier/content_suggestion_identifier.h"
#import "ios/chrome/browser/ui/favicon/favicon_attributes.h"
#import "ios/chrome/browser/ui/favicon/favicon_view.h"
#include "ios/chrome/grit/ios_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -24,7 +21,6 @@
@synthesize title = _title;
@synthesize URL = _URL;
@synthesize source = _source;
@synthesize commandHandler = _commandHandler;
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
......@@ -39,7 +35,6 @@
cell.titleLabel.text = self.title;
cell.accessibilityLabel = self.title;
[cell.faviconView configureWithAttributes:self.attributes];
cell.accessibilityCustomActions = [self customActions];
}
- (ntp_tiles::TileVisualType)tileType {
......@@ -57,51 +52,4 @@
return [ContentSuggestionsMostVisitedCell defaultSize].height;
}
#pragma mark - AccessibilityCustomAction
// Custom action for a cell configured with this item.
- (NSArray<UIAccessibilityCustomAction*>*)customActions {
UIAccessibilityCustomAction* openInNewTab =
[[UIAccessibilityCustomAction alloc]
initWithName:l10n_util::GetNSString(
IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWTAB)
target:self
selector:@selector(openInNewTab)];
UIAccessibilityCustomAction* openInNewIncognitoTab =
[[UIAccessibilityCustomAction alloc]
initWithName:l10n_util::GetNSString(
IDS_IOS_CONTENT_CONTEXT_OPENLINKNEWINCOGNITOTAB)
target:self
selector:@selector(openInNewIncognitoTab)];
UIAccessibilityCustomAction* removeMostVisited = [
[UIAccessibilityCustomAction alloc]
initWithName:l10n_util::GetNSString(IDS_IOS_CONTENT_SUGGESTIONS_REMOVE)
target:self
selector:@selector(removeMostVisited)];
NSArray* customActions =
[NSArray arrayWithObjects:openInNewTab, openInNewIncognitoTab,
removeMostVisited, nil];
return customActions;
}
// Target for custom action.
- (BOOL)openInNewTab {
[self.commandHandler openNewTabWithMostVisitedItem:self incognito:NO];
return YES;
}
// Target for custom action.
- (BOOL)openInNewIncognitoTab {
[self.commandHandler openNewTabWithMostVisitedItem:self incognito:YES];
return YES;
}
// Target for custom action.
- (BOOL)removeMostVisited {
[self.commandHandler removeMostVisited:self];
return YES;
}
@end
......@@ -18,12 +18,10 @@
// Opens the Most Visited associated with this |item| at the |mostVisitedItem|.
- (void)openMostVisitedItem:(nonnull CollectionViewItem*)item
atIndex:(NSInteger)mostVisitedIndex;
// Displays a context menu for the |suggestionItem|.
- (void)displayContextMenuForSuggestion:
(nonnull CollectionViewItem*)suggestionItem
atPoint:(CGPoint)touchLocation
atIndexPath:(nonnull NSIndexPath*)indexPath
readLaterAction:(BOOL)readLaterAction;
// Displays a context menu for the |articleItem|.
- (void)displayContextMenuForArticle:(nonnull CollectionViewItem*)articleItem
atPoint:(CGPoint)touchLocation
atIndexPath:(nonnull NSIndexPath*)indexPath;
// Displays a context menu for the |mostVisitedItem|.
- (void)displayContextMenuForMostVisitedItem:
(nonnull CollectionViewItem*)mostVisitedItem
......
......@@ -476,17 +476,9 @@ BOOL ShouldCellsBeFullWidth(UITraitCollection* collection) {
switch (type) {
case ContentSuggestionTypeArticle:
[self.suggestionCommandHandler
displayContextMenuForSuggestion:touchedItem
atPoint:touchLocation
atIndexPath:touchedItemIndexPath
readLaterAction:YES];
break;
case ContentSuggestionTypeReadingList:
[self.suggestionCommandHandler
displayContextMenuForSuggestion:touchedItem
atPoint:touchLocation
atIndexPath:touchedItemIndexPath
readLaterAction:NO];
displayContextMenuForArticle:touchedItem
atPoint:touchLocation
atIndexPath:touchedItemIndexPath];
break;
case ContentSuggestionTypeMostVisited:
[self.suggestionCommandHandler
......
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