Commit 30d56c8f authored by Sebastien Lalancette's avatar Sebastien Lalancette Committed by Commit Bot

[iOS] Adding a Delete Action to History New Context Menu

Added a new Delete action to History entries' context menus. Selecting
that action will delete the focused entry.

Regarding the business logic of the action (deleting the entry), this CL
reuses the existing delete logic used by entries' accessibility actions.

Bug: 1093302
Change-Id: Id1a21fe441ee922d63e10107e9bdbaadadc7be75
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2308849Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Sebastien Lalancette <seblalancette@chromium.org>
Cr-Commit-Position: refs/heads/master@{#792672}
parent 6cbc117e
...@@ -354,6 +354,9 @@ locale. The strings in this file are specific to iOS. ...@@ -354,6 +354,9 @@ locale. The strings in this file are specific to iOS.
<message name="IDS_IOS_COPY_ACTION_TITLE" desc="Title of the action used to copy the selected piece of content to the clipboard. Targeted content type includes URL or image. [iOS only]"> <message name="IDS_IOS_COPY_ACTION_TITLE" desc="Title of the action used to copy the selected piece of content to the clipboard. Targeted content type includes URL or image. [iOS only]">
Copy Copy
</message> </message>
<message name="IDS_IOS_DELETE_ACTION_TITLE" desc="Title of the action used to delete a selected item. Item types include, for example, a Bookmark or an History Entry. [iOS only]">
Delete
</message>
<message name="IDS_IOS_BADGE_INCOGNITO_HINT" desc="Button displayed when the user is in Incognito mode. [iOS only]"> <message name="IDS_IOS_BADGE_INCOGNITO_HINT" desc="Button displayed when the user is in Incognito mode. [iOS only]">
Current Webpage is on Incognito Current Webpage is on Incognito
</message> </message>
......
9caa7694a2ef308a353a2ab234f4f1ba44920f86
\ No newline at end of file
...@@ -179,22 +179,31 @@ ...@@ -179,22 +179,31 @@
(HistoryEntryItem*)item (HistoryEntryItem*)item
withView:(UIView*)view withView:(UIView*)view
API_AVAILABLE(ios(13.0)) { API_AVAILABLE(ios(13.0)) {
return [UIContextMenuConfiguration __weak id<HistoryEntryItemDelegate> historyItemDelegate =
configurationWithIdentifier:nil self.historyTableViewController;
previewProvider:nil
actionProvider:^(NSArray<UIMenuElement*>* suggestedActions) { UIContextMenuActionProvider actionProvider =
^(NSArray<UIMenuElement*>* suggestedActions) {
// Record that this context menu was shown to the user. // Record that this context menu was shown to the user.
RecordMenuShown(MenuScenario::HistoryEntry); RecordMenuShown(MenuScenario::HistoryEntry);
ActionFactory* actionFactory = [[ActionFactory alloc] ActionFactory* actionFactory =
initWithScenario:MenuScenario::HistoryEntry]; [[ActionFactory alloc] initWithScenario:MenuScenario::HistoryEntry];
UIAction* copyAction = UIAction* copyAction = [actionFactory actionToCopyURL:item.URL];
[actionFactory actionToCopyURL:item.URL];
return [UIMenu menuWithTitle:[NSString string] UIAction* deleteAction = [actionFactory actionToDeleteWithBlock:^{
children:@[ copyAction ]]; [historyItemDelegate historyEntryItemDidRequestDelete:item];
}]; }];
return [UIMenu menuWithTitle:[NSString string]
children:@[ copyAction, deleteAction ]];
};
return
[UIContextMenuConfiguration configurationWithIdentifier:nil
previewProvider:nil
actionProvider:actionProvider];
} }
@end @end
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h" #import "ios/chrome/browser/ui/table_view/chrome_table_view_controller.h"
#include "ios/chrome/browser/ui/history/history_consumer.h" #include "ios/chrome/browser/ui/history/history_consumer.h"
#import "ios/chrome/browser/ui/history/history_entry_item_delegate.h"
class Browser; class Browser;
enum class UrlLoadStrategy; enum class UrlLoadStrategy;
...@@ -21,6 +22,7 @@ enum class UrlLoadStrategy; ...@@ -21,6 +22,7 @@ enum class UrlLoadStrategy;
// ChromeTableViewController for displaying history items. // ChromeTableViewController for displaying history items.
@interface HistoryTableViewController @interface HistoryTableViewController
: ChromeTableViewController <HistoryConsumer, : ChromeTableViewController <HistoryConsumer,
HistoryEntryItemDelegate,
UIAdaptivePresentationControllerDelegate> UIAdaptivePresentationControllerDelegate>
// The ViewController's Browser. // The ViewController's Browser.
@property(nonatomic, assign) Browser* browser; @property(nonatomic, assign) Browser* browser;
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#import "ios/chrome/browser/ui/history/history_entries_status_item_delegate.h" #import "ios/chrome/browser/ui/history/history_entries_status_item_delegate.h"
#include "ios/chrome/browser/ui/history/history_entry_inserter.h" #include "ios/chrome/browser/ui/history/history_entry_inserter.h"
#import "ios/chrome/browser/ui/history/history_entry_item.h" #import "ios/chrome/browser/ui/history/history_entry_item.h"
#import "ios/chrome/browser/ui/history/history_entry_item_delegate.h"
#include "ios/chrome/browser/ui/history/history_menu_provider.h" #include "ios/chrome/browser/ui/history/history_menu_provider.h"
#import "ios/chrome/browser/ui/history/history_ui_constants.h" #import "ios/chrome/browser/ui/history/history_ui_constants.h"
#include "ios/chrome/browser/ui/history/history_ui_delegate.h" #include "ios/chrome/browser/ui/history/history_ui_delegate.h"
...@@ -88,7 +87,6 @@ const CGFloat kButtonHorizontalPadding = 30.0; ...@@ -88,7 +87,6 @@ const CGFloat kButtonHorizontalPadding = 30.0;
@interface HistoryTableViewController () <HistoryEntriesStatusItemDelegate, @interface HistoryTableViewController () <HistoryEntriesStatusItemDelegate,
HistoryEntryInserterDelegate, HistoryEntryInserterDelegate,
HistoryEntryItemDelegate,
TableViewTextLinkCellDelegate, TableViewTextLinkCellDelegate,
TableViewURLDragDataSource, TableViewURLDragDataSource,
UISearchControllerDelegate, UISearchControllerDelegate,
......
...@@ -34,6 +34,10 @@ API_AVAILABLE(ios(13.0)) ...@@ -34,6 +34,10 @@ API_AVAILABLE(ios(13.0))
// pasteboard. // pasteboard.
- (UIAction*)actionToCopyURL:(const GURL)URL; - (UIAction*)actionToCopyURL:(const GURL)URL;
// Creates a UIAction instance configured for deletion which will invoke
// the given |block| upon being triggered.
- (UIAction*)actionToDeleteWithBlock:(ProceduralBlock)block;
@end @end
#endif // IOS_CHROME_BROWSER_UI_MENU_ACTION_FACTORY_H_ #endif // IOS_CHROME_BROWSER_UI_MENU_ACTION_FACTORY_H_
...@@ -55,4 +55,14 @@ ...@@ -55,4 +55,14 @@
}]; }];
} }
- (UIAction*)actionToDeleteWithBlock:(ProceduralBlock)block {
UIAction* action =
[self actionWithTitle:l10n_util::GetNSString(IDS_IOS_DELETE_ACTION_TITLE)
image:[UIImage systemImageNamed:@"trash"]
type:MenuActionType::Delete
block:block];
action.attributes = UIMenuElementAttributesDestructive;
return action;
}
@end @end
...@@ -84,4 +84,22 @@ TEST_F(ActionFactoryTest, CopyAction) { ...@@ -84,4 +84,22 @@ TEST_F(ActionFactoryTest, CopyAction) {
} }
} }
// Tests that the delete action has the right title and image.
TEST_F(ActionFactoryTest, DeleteAction) {
if (@available(iOS 13.0, *)) {
ActionFactory* factory =
[[ActionFactory alloc] initWithScenario:kTestMenuScenario];
UIImage* expectedImage = [UIImage systemImageNamed:@"trash"];
NSString* expectedTitle =
l10n_util::GetNSString(IDS_IOS_DELETE_ACTION_TITLE);
UIAction* action = [factory actionToDeleteWithBlock:^{
}];
EXPECT_TRUE([expectedTitle isEqualToString:action.title]);
EXPECT_EQ(expectedImage, action.image);
}
}
#endif // defined(__IPHONE_13_0) #endif // defined(__IPHONE_13_0)
...@@ -8,6 +8,6 @@ ...@@ -8,6 +8,6 @@
// Enum representing the existing set of menu actions as types. Current values // Enum representing the existing set of menu actions as types. Current values
// should not be renumbered. Please keep in sync with "IOSMenuAction" in // should not be renumbered. Please keep in sync with "IOSMenuAction" in
// src/tools/metrics/histograms/enums.xml. // src/tools/metrics/histograms/enums.xml.
enum class MenuActionType { Copy = 0, kMaxValue = Copy }; enum class MenuActionType { Copy = 0, Delete = 1, kMaxValue = Delete };
#endif // IOS_CHROME_BROWSER_UI_MENU_MENU_ACTION_TYPE_H_ #endif // IOS_CHROME_BROWSER_UI_MENU_MENU_ACTION_TYPE_H_
...@@ -37085,6 +37085,7 @@ Called by update_gpu_driver_bug_workaround_entries.py.--> ...@@ -37085,6 +37085,7 @@ Called by update_gpu_driver_bug_workaround_entries.py.-->
<enum name="IOSMenuAction"> <enum name="IOSMenuAction">
<int value="0" label="Copy"/> <int value="0" label="Copy"/>
<int value="1" label="Delete"/>
</enum> </enum>
<enum name="IOSMenuScenario"> <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