Commit 84aae5dd authored by Ewann's avatar Ewann Committed by Commit Bot

[iOS] Adds custom actions to ContentSuggestions Context Menu

Adding:
- Open in New Tab
- Open in New Incognito Tab
- Open in New Window (if Multi-Window is supported and iPad)
- Delete

Bug: 1093302
Change-Id: I86df229a836df599b5f9febab4ba6541ec1e8ed8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2332274Reviewed-by: default avatarSebastien Lalancette <seblalancette@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarSylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Ewann Pellé <ewannpv@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795516}
parent 81603f17
......@@ -999,6 +999,9 @@ Because your account is managed by <ph name="HOSTED_DOMAIN">$1<ex>google.com</ex
<message name="IDS_IOS_REMOVE_ACCOUNT_LABEL" desc="Button label for removing an account.">
Remove
</message>
<message name="IDS_IOS_REMOVE_ACTION_TITLE" desc="Title of the action used to remove a selected item. [iOS only]">
Remove
</message>
<message name="IDS_IOS_MANAGE_SYNC_ENCRYPTION" desc="Title for the cell to open the encryption dialog.">
Encryption
</message>
......
74064d4d5b939dcc9caac18e1fa00af0e353309c
\ No newline at end of file
......@@ -79,6 +79,7 @@ source_set("content_suggestions") {
"//ios/chrome/browser/ui/settings/utils:utils",
"//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/browser/ui/util",
"//ios/chrome/browser/ui/util:multiwindow_util",
"//ios/chrome/browser/url_loading",
"//ios/chrome/browser/voice",
"//ios/chrome/browser/web_state_list",
......
......@@ -57,6 +57,7 @@
#import "ios/chrome/browser/ui/ntp/notification_promo_whats_new.h"
#import "ios/chrome/browser/ui/overscroll_actions/overscroll_actions_controller.h"
#import "ios/chrome/browser/ui/settings/utils/pref_backed_boolean.h"
#import "ios/chrome/browser/ui/util/multi_window_support.h"
#import "ios/chrome/browser/ui/util/uikit_ui_util.h"
#import "ios/chrome/browser/url_loading/url_loading_browser_agent.h"
#import "ios/chrome/browser/url_loading/url_loading_params.h"
......@@ -517,11 +518,46 @@
initWithBrowser:strongSelf.browser
scenario:MenuScenario::kContentSuggestionsEntry];
UIAction* copyAction = [actionFactory actionToCopyURL:item.URL];
NSMutableArray<UIMenuElement*>* menuElements =
[[NSMutableArray alloc] init];
NSIndexPath* indexPath =
[self.suggestionsViewController.collectionViewModel
indexPathForItem:item];
[menuElements addObject:[actionFactory actionToOpenInNewTabWithBlock:^{
[weakSelf.NTPMediator
openNewTabWithMostVisitedItem:item
incognito:NO
atIndex:indexPath.item];
}]];
[menuElements
addObject:[actionFactory actionToOpenInNewIncognitoTabWithBlock:^{
[weakSelf.NTPMediator
openNewTabWithMostVisitedItem:item
incognito:YES
atIndex:indexPath.item];
}]];
if (IsMultipleScenesSupported()) {
[menuElements
addObject:
[actionFactory
actionToOpenInNewWindowWithURL:item.URL
activityOrigin:
WindowActivityContentSuggestionsOrigin
completion:nil]];
}
return [UIMenu menuWithTitle:@"" children:@[ copyAction ]];
};
[menuElements addObject:[actionFactory actionToCopyURL:item.URL]];
[menuElements addObject:[actionFactory actionToRemoveWithBlock:^{
[weakSelf.NTPMediator removeMostVisited:item];
}]];
return [UIMenu menuWithTitle:@"" children:menuElements];
};
return
[UIContextMenuConfiguration configurationWithIdentifier:nil
previewProvider:nil
......
......@@ -69,6 +69,10 @@ API_AVAILABLE(ios(13.0))
activityOrigin:(WindowActivityOrigin)activityOrigin
completion:(ProceduralBlock)completion;
// Creates a UIAction instance configured for suppression which will invoke
// the given delete |block| when executed.
- (UIAction*)actionToRemoveWithBlock:(ProceduralBlock)block;
@end
#endif // IOS_CHROME_BROWSER_UI_MENU_ACTION_FACTORY_H_
......@@ -139,4 +139,14 @@
}];
}
- (UIAction*)actionToRemoveWithBlock:(ProceduralBlock)block {
UIAction* action =
[self actionWithTitle:l10n_util::GetNSString(IDS_IOS_REMOVE_ACTION_TITLE)
image:[UIImage systemImageNamed:@"trash"]
type:MenuActionType::Remove
block:block];
action.attributes = UIMenuElementAttributesDestructive;
return action;
}
@end
......@@ -14,7 +14,8 @@ enum class MenuActionType {
OpenInNewTab = 2,
OpenInNewIncognitoTab = 3,
OpenInNewWindow = 4,
kMaxValue = OpenInNewWindow
Remove = 5,
kMaxValue = Remove
};
#endif // IOS_CHROME_BROWSER_UI_MENU_MENU_ACTION_TYPE_H_
......@@ -34,8 +34,10 @@ typedef NS_ENUM(NSInteger, WindowActivityOrigin) {
WindowActivityRecentTabsOrigin,
// The command origin comes from the location bar steady view.
WindowActivityLocationBarSteadyViewOrigin,
// The command origin comes from the NTP content suggestions.
WindowActivityContentSuggestionsOrigin,
// Size of enum.
kMaxValue = WindowActivityToolsOrigin
kMaxValue = WindowActivityContentSuggestionsOrigin
};
// Helper functions to create NSUserActivity instances that encode specific
......
......@@ -37190,6 +37190,7 @@ Called by update_gpu_driver_bug_workaround_entries.py.-->
<int value="2" label="Open in New Tab"/>
<int value="3" label="Open in New Incognito Tab"/>
<int value="4" label="Open in New Window"/>
<int value="5" label="Remove"/>
</enum>
<enum name="IOSMenuScenario">
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