Commit f0f0bc5a authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

Add navigation history menu

This CL change the navigation history menu to be the new navigation
menu by default when the UI Refresh flag is enabled.

Bug: 804779, 828771
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ib0bc001275102400538d989f1e7af744a8e1d18a
Reviewed-on: https://chromium-review.googlesource.com/995441
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarSergio Collazos <sczs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#548709}
parent 2ad1f83a
......@@ -71,12 +71,6 @@ using base::UserMetricsAction;
CGPoint origin = CGPointZero;
origin = [self popupOriginForNamedGuide:kBackButtonGuide];
if (IsUIRefreshPhase1Enabled() && origin.y > 200) {
// TODO(crbug.com/804772): Remove this workaround once the new navigation
// menu popup can be presented from the bottom back/forward arrows.
origin.y -= 100;
}
[self.tabHistoryUIUpdater
updateUIForTabHistoryPresentationFrom:ToolbarButtonTypeBack];
[self presentTabHistoryPopupWithItems:backwardItems origin:origin];
......
......@@ -10,10 +10,18 @@
// 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;
@end
// Associated cell for a PopupMenuNavigationItem.
@interface PopupMenuNavigationCell : UITableViewCell
- (void)setTitle:(NSString*)title;
- (void)setFavicon:(UIImage*)favicon;
@end
#endif // IOS_CHROME_BROWSER_UI_POPUP_MENU_CELLS_POPUP_MENU_NAVIGATION_ITEM_H_
......@@ -5,14 +5,27 @@
#import "ios/chrome/browser/ui/popup_menu/cells/popup_menu_navigation_item.h"
#include "base/logging.h"
#import "ios/chrome/browser/ui/table_view/chrome_table_view_styler.h"
#import "ios/chrome/browser/ui/util/constraints_ui_util.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
const CGFloat kImageLength = 16;
const CGFloat kCellHeight = 44;
const CGFloat kImageTextMargin = 11;
const CGFloat kMargin = 15;
const CGFloat kVerticalMargin = 8;
const CGFloat kMaxHeight = 100;
} // namespace
@implementation PopupMenuNavigationItem
@synthesize actionIdentifier = _actionIdentifier;
@synthesize favicon = _favicon;
@synthesize title = _title;
- (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type];
......@@ -22,15 +35,96 @@
return self;
}
- (void)configureCell:(PopupMenuNavigationCell*)cell
withStyler:(ChromeTableViewStyler*)styler {
[super configureCell:cell withStyler:styler];
[cell setFavicon:self.favicon];
[cell setTitle:self.title];
}
#pragma mark - PopupMenuItem
- (CGSize)cellSizeForWidth:(CGFloat)width {
// TODO(crbug.com/804779): implement this.
NOTREACHED();
return CGSizeZero;
// TODO(crbug.com/828357): This should be done at the table view level.
static PopupMenuNavigationCell* cell;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
cell = [[PopupMenuNavigationCell alloc] init];
});
[self configureCell:cell withStyler:[[ChromeTableViewStyler alloc] init]];
cell.frame = CGRectMake(0, 0, width, kMaxHeight);
[cell setNeedsLayout];
[cell layoutIfNeeded];
return [cell systemLayoutSizeFittingSize:CGSizeMake(width, kMaxHeight)];
}
@end
#pragma mark - PopupMenuNavigationCell
@interface PopupMenuNavigationCell ()
@property(nonatomic, strong) UILabel* titleLabel;
@property(nonatomic, strong) UIImageView* faviconView;
@end
@implementation PopupMenuNavigationCell
@synthesize faviconView = _faviconView;
@synthesize titleLabel = _titleLabel;
- (instancetype)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString*)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
_titleLabel = [[UILabel alloc] init];
_titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
_titleLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleBody];
_faviconView = [[UIImageView alloc] init];
_faviconView.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:_titleLabel];
[self.contentView addSubview:_faviconView];
ApplyVisualConstraintsWithMetrics(
@[
@"H:|-(margin)-[image(imageSize)]-(textImage)-[text]-(margin)-|",
@"V:[image(imageSize)]",
@"V:|-(verticalMargin)-[text]-(verticalMargin)-|"
],
@{@"image" : _faviconView, @"text" : _titleLabel}, @{
@"margin" : @(kMargin),
@"imageSize" : @(kImageLength),
@"textImage" : @(kImageTextMargin),
@"verticalMargin" : @(kVerticalMargin),
});
[self.contentView.heightAnchor
constraintGreaterThanOrEqualToConstant:kCellHeight]
.active = YES;
[_faviconView.centerYAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor]
.active = YES;
}
return self;
}
- (void)setTitle:(NSString*)title {
self.titleLabel.text = title;
}
- (void)setFavicon:(UIImage*)favicon {
if (favicon) {
self.faviconView.image = favicon;
} else {
self.faviconView.image = [UIImage imageNamed:@"default_favicon"];
}
}
- (void)prepareForReuse {
[super prepareForReuse];
[self setFavicon:nil];
}
@end
......@@ -26,6 +26,7 @@ const CGFloat kInnerMargin = 11;
const CGFloat kMargin = 15;
const CGFloat kTopMargin = 8;
const CGFloat kTopMarginBadge = 14;
const CGFloat kMaxHeight = 100;
} // namespace
@implementation PopupMenuToolsItem
......@@ -67,10 +68,10 @@ const CGFloat kTopMarginBadge = 14;
});
[self configureCell:cell withStyler:[[ChromeTableViewStyler alloc] init]];
cell.frame = CGRectMake(0, 0, width, 0);
cell.frame = CGRectMake(0, 0, width, kMaxHeight);
[cell setNeedsLayout];
[cell layoutIfNeeded];
return [cell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize];
return [cell systemLayoutSizeFittingSize:CGSizeMake(width, kMaxHeight)];
}
@end
......
......@@ -75,82 +75,32 @@ PopupMenuCommandType CommandTypeFromPopupType(PopupMenuType type) {
- (void)showNavigationHistoryBackPopupMenu {
base::RecordAction(
base::UserMetricsAction("MobileToolbarShowTabHistoryMenu"));
UIViewController* viewController = [[UIViewController alloc] init];
UILabel* label = [[UILabel alloc] init];
label.text = @"Back";
viewController.view = label;
// TODO(crbug.com/804779): Use the Navigation menu instead of a label.
[self presentPopupForContent:viewController
ofType:PopupMenuTypeNavigationBackward
fromNamedGuide:kBackButtonGuide];
[self presentPopupOfType:PopupMenuTypeNavigationBackward
fromNamedGuide:kBackButtonGuide];
}
- (void)showNavigationHistoryForwardPopupMenu {
base::RecordAction(
base::UserMetricsAction("MobileToolbarShowTabHistoryMenu"));
UIViewController* viewController = [[UIViewController alloc] init];
UILabel* label = [[UILabel alloc] init];
label.text = @"Forward";
viewController.view = label;
// TODO(crbug.com/804779): Use the Navigation menu instead of a label.
[self presentPopupForContent:viewController
ofType:PopupMenuTypeNavigationForward
fromNamedGuide:kForwardButtonGuide];
[self presentPopupOfType:PopupMenuTypeNavigationForward
fromNamedGuide:kForwardButtonGuide];
}
- (void)showToolsMenuPopup {
PopupMenuTableViewController* tableViewController =
[[PopupMenuTableViewController alloc]
initWithStyle:UITableViewStyleGrouped];
tableViewController.dispatcher =
static_cast<id<ApplicationCommands, BrowserCommands>>(self.dispatcher);
tableViewController.baseViewController = self.baseViewController;
self.mediator = [[PopupMenuMediator alloc]
initWithType:PopupMenuTypeToolsMenu
isIncognito:self.browserState->IsOffTheRecord()
readingListModel:ReadingListModelFactory::GetForBrowserState(
self.browserState)];
self.mediator.webStateList = self.webStateList;
self.mediator.popupMenu = tableViewController;
self.mediator.dispatcher = static_cast<id<BrowserCommands>>(self.dispatcher);
[self presentPopupForContent:tableViewController
ofType:PopupMenuTypeToolsMenu
fromNamedGuide:kToolsMenuGuide];
// The metric is registered at the toolbar level.
[self presentPopupOfType:PopupMenuTypeToolsMenu
fromNamedGuide:kToolsMenuGuide];
}
- (void)showTabGridButtonPopup {
base::RecordAction(base::UserMetricsAction("MobileToolbarShowTabGridMenu"));
PopupMenuTableViewController* tableViewController =
[[PopupMenuTableViewController alloc] init];
tableViewController.dispatcher =
static_cast<id<ApplicationCommands, BrowserCommands>>(self.dispatcher);
tableViewController.baseViewController = self.baseViewController;
self.mediator = [[PopupMenuMediator alloc]
initWithType:PopupMenuTypeTabGrid
isIncognito:self.browserState->IsOffTheRecord()
readingListModel:ReadingListModelFactory::GetForBrowserState(
self.browserState)];
self.mediator.webStateList = self.webStateList;
self.mediator.popupMenu = tableViewController;
[self presentPopupForContent:tableViewController
ofType:PopupMenuTypeTabGrid
fromNamedGuide:kTabSwitcherGuide];
[self presentPopupOfType:PopupMenuTypeTabGrid
fromNamedGuide:kTabSwitcherGuide];
}
- (void)searchButtonPopup {
base::RecordAction(base::UserMetricsAction("MobileToolbarShowSearchMenu"));
UIViewController* viewController = [[UIViewController alloc] init];
UILabel* label = [[UILabel alloc] init];
label.text = @"Search";
viewController.view = label;
// TODO(crbug.com/821560): Use the search menu instead of a label.
[self presentPopupForContent:viewController
ofType:PopupMenuTypeSearch
fromNamedGuide:nil];
[self presentPopupOfType:PopupMenuTypeSearch fromNamedGuide:nil];
}
- (void)dismissPopupMenu {
......@@ -168,21 +118,36 @@ PopupMenuCommandType CommandTypeFromPopupType(PopupMenuType type) {
#pragma mark - Private
// Presents the |content| of type |type| with an animation starting from
// Presents a popup menu of type |type| with an animation starting from
// |guideName|.
- (void)presentPopupForContent:(UIViewController*)content
ofType:(PopupMenuType)type
fromNamedGuide:(GuideName*)guideName {
- (void)presentPopupOfType:(PopupMenuType)type
fromNamedGuide:(GuideName*)guideName {
DCHECK(!self.presenter);
id<BrowserCommands> callableDispatcher =
static_cast<id<BrowserCommands>>(self.dispatcher);
[callableDispatcher
prepareForPopupMenuPresentation:CommandTypeFromPopupType(type)];
PopupMenuTableViewController* tableViewController =
[[PopupMenuTableViewController alloc]
initWithStyle:UITableViewStyleGrouped];
tableViewController.dispatcher =
static_cast<id<ApplicationCommands, BrowserCommands>>(self.dispatcher);
tableViewController.baseViewController = self.baseViewController;
self.mediator = [[PopupMenuMediator alloc]
initWithType:type
isIncognito:self.browserState->IsOffTheRecord()
readingListModel:ReadingListModelFactory::GetForBrowserState(
self.browserState)];
self.mediator.webStateList = self.webStateList;
self.mediator.popupMenu = tableViewController;
self.mediator.dispatcher = static_cast<id<BrowserCommands>>(self.dispatcher);
self.presenter = [[PopupMenuPresenter alloc] init];
self.presenter.baseViewController = self.baseViewController;
self.presenter.commandHandler = self;
self.presenter.presentedViewController = content;
self.presenter.presentedViewController = tableViewController;
self.presenter.guideName = guideName;
[self.presenter prepareForPresentation];
......
......@@ -10,6 +10,7 @@
#import "ios/chrome/browser/ui/commands/browser_commands.h"
#import "ios/chrome/browser/ui/commands/reading_list_add_command.h"
#import "ios/chrome/browser/ui/popup_menu/cells/popup_menu_item.h"
#import "ios/chrome/browser/ui/popup_menu/cells/popup_menu_navigation_item.h"
#import "ios/chrome/browser/ui/popup_menu/cells/popup_menu_tools_item.h"
#import "ios/chrome/browser/ui/popup_menu/popup_menu_table_view_controller.h"
#import "ios/chrome/browser/ui/reading_list/reading_list_menu_notification_delegate.h"
......@@ -21,13 +22,16 @@
#include "ios/chrome/grit/ios_strings.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/user_feedback/user_feedback_provider.h"
#include "ios/web/public/favicon_status.h"
#import "ios/web/public/navigation_item.h"
#import "ios/web/public/navigation_manager.h"
#include "ios/web/public/navigation_manager.h"
#include "ios/web/public/user_agent.h"
#include "ios/web/public/web_client.h"
#include "ios/web/public/web_state/web_state.h"
#import "ios/web/public/web_state/web_state_observer_bridge.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
......@@ -250,8 +254,10 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
[self createToolsMenuItems];
break;
case PopupMenuTypeNavigationForward:
[self createNavigationItemsForType:PopupMenuTypeNavigationForward];
break;
case PopupMenuTypeNavigationBackward:
[self createNavigationItemsForType:PopupMenuTypeNavigationBackward];
break;
case PopupMenuTypeTabGrid:
[self createTabGridMenuItems];
......@@ -365,6 +371,34 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
#pragma mark - Item creation (Private)
- (void)createNavigationItemsForType:(PopupMenuType)type {
DCHECK(type == PopupMenuTypeNavigationForward ||
type == PopupMenuTypeNavigationBackward);
if (!self.webState)
return;
web::NavigationManager* navigationManager =
self.webState->GetNavigationManager();
std::vector<web::NavigationItem*> navigationItems;
if (type == PopupMenuTypeNavigationForward) {
navigationItems = navigationManager->GetForwardItems();
} else {
navigationItems = navigationManager->GetBackwardItems();
}
NSMutableArray* items = [NSMutableArray array];
for (web::NavigationItem* navigationItem : navigationItems) {
PopupMenuNavigationItem* item =
[[PopupMenuNavigationItem alloc] initWithType:kItemTypeEnumZero];
item.title = base::SysUTF16ToNSString(navigationItem->GetTitleForDisplay());
const gfx::Image& image = navigationItem->GetFavicon().image;
if (!image.IsEmpty())
item.favicon = image.ToUIImage();
[items addObject:item];
}
self.items = @[ items ];
}
// Creates the menu items for the tab grid menu.
- (void)createTabGridMenuItems {
NSMutableArray* items = [NSMutableArray arrayWithArray:[self itemsForNewTab]];
......
......@@ -262,18 +262,10 @@
return;
if (gesture.view == self.view.backButton) {
if (base::FeatureList::IsEnabled(kNewToolsMenu)) {
[self.dispatcher showNavigationHistoryBackPopupMenu];
} else {
[self.dispatcher showTabHistoryPopupForBackwardHistory];
}
[self.dispatcher showNavigationHistoryBackPopupMenu];
} else if (gesture.view == self.view.forwardButton ||
gesture.view == self.view.forwardButtonTrailingPosition) {
if (base::FeatureList::IsEnabled(kNewToolsMenu)) {
[self.dispatcher showNavigationHistoryForwardPopupMenu];
} else {
[self.dispatcher showTabHistoryPopupForForwardHistory];
}
[self.dispatcher showNavigationHistoryForwardPopupMenu];
} else if (gesture.view == self.view.tabGridButton) {
[self.dispatcher showTabGridButtonPopup];
}
......
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