Commit ae937956 authored by Ewann's avatar Ewann Committed by Commit Bot

[iOS] Adds custom actions to the ReadingList Context Menu

This CL adds the following actions to the ReadingList Context Menu:
- Mark As Read
- Mark As Unread
- View Offline Version in New Tab

Bug: 1093302
Change-Id: Ie17e58417738cbc5cc2c3a345c281464339170b5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2366799Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarSebastien Lalancette <seblalancette@chromium.org>
Commit-Queue: Ewann Pellé <ewannpv@chromium.org>
Cr-Commit-Position: refs/heads/master@{#803116}
parent 096493df
......@@ -1562,6 +1562,12 @@ While in incognito, sites can't use cookies to see your browsing activity across
<message name="IDS_IOS_READING_LIST_MARK_ALL_UNREAD_ACTION" desc="Label of the action button to mark all reading list entries as unread. [Length: 25em]" meaning="Mark all entries as unread. [Length: 25em]">
Mark All Unread
</message>
<message name="IDS_IOS_READING_LIST_MARK_AS_READ_ACTION" desc="Label of the action button to mark a reading list entry as read. [Length: 25em]" meaning="Mark an entry as read. [Length: 25em]">
Mark As Read
</message>
<message name="IDS_IOS_READING_LIST_MARK_AS_UNREAD_ACTION" desc="Label of the action button to mark a reading list entry as unread. [Length: 25em]" meaning="Mark an entry as unread. [Length: 25em]">
Mark As Unread
</message>
<message name="IDS_IOS_READING_LIST_MARK_BUTTON" desc="Label of the button to mark the selected reading list as either read or unread [Length: 25em]" meaning="Display options letting the user mark all the selected entries as read or as unread. [Length: 25em]">
Mark…
</message>
......
f161a910bfd5e5ab0f4d56fad46168c1e8fa8a91
\ No newline at end of file
4b2be7047e523a4064e16dc2ad3fc07ee332bb37
\ No newline at end of file
......@@ -15,6 +15,7 @@ source_set("menu") {
"resources:copy_link_url",
"resources:delete",
"resources:edit",
"resources:mark_read",
"resources:move_folder",
"resources:open_in_incognito",
"resources:open_in_new_tab",
......@@ -42,6 +43,7 @@ source_set("unit_tests") {
"resources:copy_link_url",
"resources:delete",
"resources:edit",
"resources:mark_read",
"resources:move_folder",
"resources:open_in_incognito",
"resources:open_in_new_tab",
......
......@@ -94,6 +94,20 @@ API_AVAILABLE(ios(13.0))
// the given |block| when executed.
- (UIAction*)actionToMoveFolderWithBlock:(ProceduralBlock)block;
// Creates a UIAction instance configured for marking an entry from the
// ReadingList as read, which will invoke the given |block| when executed.
- (UIAction*)actionToMarkAsReadWithBlock:(ProceduralBlock)block;
// Creates a UIAction instance configured for marking an entry from the
// ReadingList as unread, which will invoke the given |block| when executed.
- (UIAction*)actionToMarkAsUnreadWithBlock:(ProceduralBlock)block;
// Creates a UIAction instance whose title and icon are configured for viewing
// an offline version of an URL in a new tab. When triggered, the action will
// invoke the |block| when executed.
- (UIAction*)actionToViewOfflineVersionInInNewTabWithBlock:
(ProceduralBlock)block;
@end
#endif // IOS_CHROME_BROWSER_UI_MENU_ACTION_FACTORY_H_
......@@ -191,4 +191,29 @@
block:block];
}
- (UIAction*)actionToMarkAsReadWithBlock:(ProceduralBlock)block {
return [self actionWithTitle:l10n_util::GetNSString(
IDS_IOS_READING_LIST_MARK_AS_READ_ACTION)
image:[UIImage imageNamed:@"mark_read"]
type:MenuActionType::Read
block:block];
}
- (UIAction*)actionToMarkAsUnreadWithBlock:(ProceduralBlock)block {
return [self actionWithTitle:l10n_util::GetNSString(
IDS_IOS_READING_LIST_MARK_AS_UNREAD_ACTION)
image:[UIImage imageNamed:@"remove"]
type:MenuActionType::Unread
block:block];
}
- (UIAction*)actionToViewOfflineVersionInInNewTabWithBlock:
(ProceduralBlock)block {
return [self actionWithTitle:l10n_util::GetNSString(
IDS_IOS_READING_LIST_CONTENT_CONTEXT_OFFLINE)
image:nil
type:MenuActionType::ViewOffline
block:block];
}
@end
......@@ -316,4 +316,65 @@ TEST_F(ActionFactoryTest, MoveFolderAction) {
}
}
// Tests that the Mark As Read action has the right title and image.
TEST_F(ActionFactoryTest, markAsReadAction) {
if (@available(iOS 13.0, *)) {
ActionFactory* factory =
[[ActionFactory alloc] initWithBrowser:test_browser_.get()
scenario:kTestMenuScenario];
UIImage* expectedImage = [UIImage imageNamed:@"mark_read"];
NSString* expectedTitle =
l10n_util::GetNSString(IDS_IOS_READING_LIST_MARK_AS_READ_ACTION);
UIAction* action = [factory actionToMarkAsReadWithBlock:^{
}];
EXPECT_TRUE([expectedTitle isEqualToString:action.title]);
EXPECT_EQ(expectedImage, action.image);
}
}
// Tests that the Mark As Unread action has the right title and image.
TEST_F(ActionFactoryTest, markAsUnreadAction) {
if (@available(iOS 13.0, *)) {
ActionFactory* factory =
[[ActionFactory alloc] initWithBrowser:test_browser_.get()
scenario:kTestMenuScenario];
UIImage* expectedImage = [UIImage imageNamed:@"remove"];
NSString* expectedTitle =
l10n_util::GetNSString(IDS_IOS_READING_LIST_MARK_AS_UNREAD_ACTION);
UIAction* action = [factory actionToMarkAsUnreadWithBlock:^{
}];
EXPECT_TRUE([expectedTitle isEqualToString:action.title]);
EXPECT_EQ(expectedImage, action.image);
}
}
// Tests that the View Offline Version in New Tab action has the right title and
// image.
TEST_F(ActionFactoryTest, viewOfflineVersion) {
if (@available(iOS 13.0, *)) {
ActionFactory* factory =
[[ActionFactory alloc] initWithBrowser:test_browser_.get()
scenario:kTestMenuScenario];
UIImage* expectedImage = nil;
NSString* expectedTitle =
l10n_util::GetNSString(IDS_IOS_READING_LIST_CONTENT_CONTEXT_OFFLINE);
UIAction* action = [factory actionToViewOfflineVersionInInNewTabWithBlock:^{
}];
EXPECT_TRUE([expectedTitle isEqualToString:action.title]);
EXPECT_EQ(expectedImage, action.image);
}
}
#endif // defined(__IPHONE_13_0)
......@@ -20,7 +20,10 @@ enum class MenuActionType {
Delete = 8,
Remove = 9,
Hide = 10,
kMaxValue = Hide
Read = 11,
Unread = 12,
ViewOffline = 13,
kMaxValue = ViewOffline
};
#endif // IOS_CHROME_BROWSER_UI_MENU_MENU_ACTION_TYPE_H_
......@@ -75,3 +75,11 @@ imageset("move_folder") {
"move_folder.imageset/move_folder@3x.png",
]
}
imageset("mark_read") {
sources = [
"mark_read.imageset/Contents.json",
"mark_read.imageset/mark_read@2x.png",
"mark_read.imageset/mark_read@3x.png",
]
}
{
"images": [
{
"idiom": "universal",
"filename": "mark_read@2x.png",
"scale": "2x"
},
{
"idiom": "universal",
"filename": "mark_read@3x.png",
"scale": "3x"
}
],
"info": {
"author": "xcode",
"version": 1
},
"properties": {
"template-rendering-intent": "template"
}
}
\ No newline at end of file
......@@ -465,6 +465,20 @@ animationControllerForDismissedController:(UIViewController*)dismissed {
incognito:YES];
}]];
const ReadingListEntry* entry = [self.mediator entryFromItem:item];
if (entry->DistilledState() == ReadingListEntry::PROCESSED) {
GURL offlineURL = reading_list::OfflineURLForPath(
entry->DistilledPath(), item.entryURL, entry->DistilledURL());
[menuElements
addObject:[actionFactory
actionToViewOfflineVersionInInNewTabWithBlock:^{
[weakSelf loadEntryURL:item.entryURL
withOfflineURL:offlineURL
inNewTab:YES
incognito:NO];
}]];
}
if (IsMultipleScenesSupported()) {
[menuElements
addObject:[actionFactory
......@@ -474,6 +488,17 @@ animationControllerForDismissedController:(UIViewController*)dismissed {
completion:nil]];
}
if ([accessibilityDelegate isItemRead:item]) {
[menuElements
addObject:[actionFactory actionToMarkAsUnreadWithBlock:^{
[accessibilityDelegate markItemUnread:item];
}]];
} else {
[menuElements addObject:[actionFactory actionToMarkAsReadWithBlock:^{
[accessibilityDelegate markItemRead:item];
}]];
}
[menuElements addObject:[actionFactory actionToCopyURL:item.entryURL]];
[menuElements addObject:[actionFactory actionToShareWithBlock:^{
......
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