Commit 0c742742 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Add navigation action to popup menu

This CL adds the "navigate to page" action to the popup menu presenting
the navigation history menu.

Bug: 831189
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I04f26af28aada63278fa6530f9b8c8efaac42a30
Reviewed-on: https://chromium-review.googlesource.com/1005085Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#549872}
parent 01ebde12
......@@ -28,6 +28,7 @@ typedef NS_ENUM(NSInteger, PopupMenuAction) {
PopupMenuActionSettings,
PopupMenuActionCloseTab,
PopupMenuActionCloseAllIncognitoTabs,
PopupMenuActionNavigate,
};
// Protocol defining a popup item.
......
......@@ -8,12 +8,18 @@
#import "ios/chrome/browser/ui/popup_menu/cells/popup_menu_item.h"
#import "ios/chrome/browser/ui/table_view/cells/table_view_item.h"
namespace web {
class NavigationItem;
} // namespace web
// Item used to display an item for a navigation menu.
@interface PopupMenuNavigationItem : TableViewItem<PopupMenuItem>
// Title of the navigation item.
@property(nonatomic, copy) NSString* title;
// Favicon to be displayed. Set to nil to display the default favicon.
@property(nonatomic, strong) UIImage* favicon;
// Item used to navigate in the history.
@property(nonatomic, assign) web::NavigationItem* navigationItem;
@end
// Associated cell for a PopupMenuNavigationItem.
......
......@@ -26,6 +26,7 @@ const CGFloat kMaxHeight = 100;
@synthesize actionIdentifier = _actionIdentifier;
@synthesize favicon = _favicon;
@synthesize title = _title;
@synthesize navigationItem = _navigationItem;
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
......
......@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/popup_menu/popup_menu_mediator.h"
#include "base/mac/foundation_util.h"
#include "base/strings/sys_string_conversions.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "components/feature_engagement/public/feature_constants.h"
......@@ -384,6 +385,12 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
});
}
- (void)navigateToPageForItem:(TableViewItem<PopupMenuItem>*)item {
PopupMenuNavigationItem* navigationItem =
base::mac::ObjCCastStrict<PopupMenuNavigationItem>(item);
[self.dispatcher navigateToHistoryItem:navigationItem.navigationItem];
}
#pragma mark - ReadingListMenuNotificationDelegate Implementation
- (void)unreadCountChanged:(NSInteger)unreadCount {
......@@ -506,6 +513,8 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
const gfx::Image& image = navigationItem->GetFavicon().image;
if (!image.IsEmpty())
item.favicon = image.ToUIImage();
item.actionIdentifier = PopupMenuActionNavigate;
item.navigationItem = navigationItem;
[items addObject:item];
}
......
......@@ -15,6 +15,8 @@
@protocol PopupMenuTableViewControllerCommand
// Adds the current page to the reading list.
- (void)readPageLater;
// Navigates to the page associated with |item|.
- (void)navigateToPageForItem:(TableViewItem<PopupMenuItem>*)item;
@end
// TableViewController for the popup menu.
......
......@@ -96,11 +96,10 @@ const CGFloat kScrollIndicatorVerticalInsets = 11;
- (void)tableView:(UITableView*)tableView
didSelectRowAtIndexPath:(NSIndexPath*)indexPath {
TableViewItem<PopupMenuItem>* item =
[self.tableViewModel itemAtIndexPath:indexPath];
UIView* cell = [self.tableView cellForRowAtIndexPath:indexPath];
CGPoint center = [cell convertPoint:cell.center toView:nil];
[self executeActionForIdentifier:item.actionIdentifier origin:center];
[self executeActionForItem:[self.tableViewModel itemAtIndexPath:indexPath]
origin:center];
}
- (CGFloat)tableView:(UITableView*)tableView
......@@ -114,8 +113,9 @@ const CGFloat kScrollIndicatorVerticalInsets = 11;
// Executes the action associated with |identifier|, using |origin| as the point
// of origin of the action if one is needed.
- (void)executeActionForIdentifier:(PopupMenuAction)identifier
origin:(CGPoint)origin {
- (void)executeActionForItem:(TableViewItem<PopupMenuItem>*)item
origin:(CGPoint)origin {
NSInteger identifier = item.actionIdentifier;
switch (identifier) {
case PopupMenuActionReload:
base::RecordAction(UserMetricsAction("MobileMenuReload"));
......@@ -199,6 +199,10 @@ const CGFloat kScrollIndicatorVerticalInsets = 11;
base::RecordAction(UserMetricsAction("MobileMenuCloseAllIncognitoTabs"));
[self.dispatcher closeAllIncognitoTabs];
break;
case PopupMenuActionNavigate:
// No metrics for this item.
[self.commandHandler navigateToPageForItem:item];
break;
}
// Close the tools menu.
......
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