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; ...@@ -71,12 +71,6 @@ using base::UserMetricsAction;
CGPoint origin = CGPointZero; CGPoint origin = CGPointZero;
origin = [self popupOriginForNamedGuide:kBackButtonGuide]; 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 [self.tabHistoryUIUpdater
updateUIForTabHistoryPresentationFrom:ToolbarButtonTypeBack]; updateUIForTabHistoryPresentationFrom:ToolbarButtonTypeBack];
[self presentTabHistoryPopupWithItems:backwardItems origin:origin]; [self presentTabHistoryPopupWithItems:backwardItems origin:origin];
......
...@@ -10,10 +10,18 @@ ...@@ -10,10 +10,18 @@
// Item used to display an item for a navigation menu. // Item used to display an item for a navigation menu.
@interface PopupMenuNavigationItem : TableViewItem<PopupMenuItem> @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 @end
// Associated cell for a PopupMenuNavigationItem. // Associated cell for a PopupMenuNavigationItem.
@interface PopupMenuNavigationCell : UITableViewCell @interface PopupMenuNavigationCell : UITableViewCell
- (void)setTitle:(NSString*)title;
- (void)setFavicon:(UIImage*)favicon;
@end @end
#endif // IOS_CHROME_BROWSER_UI_POPUP_MENU_CELLS_POPUP_MENU_NAVIGATION_ITEM_H_ #endif // IOS_CHROME_BROWSER_UI_POPUP_MENU_CELLS_POPUP_MENU_NAVIGATION_ITEM_H_
...@@ -5,14 +5,27 @@ ...@@ -5,14 +5,27 @@
#import "ios/chrome/browser/ui/popup_menu/cells/popup_menu_navigation_item.h" #import "ios/chrome/browser/ui/popup_menu/cells/popup_menu_navigation_item.h"
#include "base/logging.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) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #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 @implementation PopupMenuNavigationItem
@synthesize actionIdentifier = _actionIdentifier; @synthesize actionIdentifier = _actionIdentifier;
@synthesize favicon = _favicon;
@synthesize title = _title;
- (instancetype)initWithType:(NSInteger)type { - (instancetype)initWithType:(NSInteger)type {
self = [super initWithType:type]; self = [super initWithType:type];
...@@ -22,15 +35,96 @@ ...@@ -22,15 +35,96 @@
return self; 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 #pragma mark - PopupMenuItem
- (CGSize)cellSizeForWidth:(CGFloat)width { - (CGSize)cellSizeForWidth:(CGFloat)width {
// TODO(crbug.com/804779): implement this. // TODO(crbug.com/828357): This should be done at the table view level.
NOTREACHED(); static PopupMenuNavigationCell* cell;
return CGSizeZero; 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 @end
#pragma mark - PopupMenuNavigationCell
@interface PopupMenuNavigationCell ()
@property(nonatomic, strong) UILabel* titleLabel;
@property(nonatomic, strong) UIImageView* faviconView;
@end
@implementation PopupMenuNavigationCell @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 @end
...@@ -26,6 +26,7 @@ const CGFloat kInnerMargin = 11; ...@@ -26,6 +26,7 @@ const CGFloat kInnerMargin = 11;
const CGFloat kMargin = 15; const CGFloat kMargin = 15;
const CGFloat kTopMargin = 8; const CGFloat kTopMargin = 8;
const CGFloat kTopMarginBadge = 14; const CGFloat kTopMarginBadge = 14;
const CGFloat kMaxHeight = 100;
} // namespace } // namespace
@implementation PopupMenuToolsItem @implementation PopupMenuToolsItem
...@@ -67,10 +68,10 @@ const CGFloat kTopMarginBadge = 14; ...@@ -67,10 +68,10 @@ const CGFloat kTopMarginBadge = 14;
}); });
[self configureCell:cell withStyler:[[ChromeTableViewStyler alloc] init]]; [self configureCell:cell withStyler:[[ChromeTableViewStyler alloc] init]];
cell.frame = CGRectMake(0, 0, width, 0); cell.frame = CGRectMake(0, 0, width, kMaxHeight);
[cell setNeedsLayout]; [cell setNeedsLayout];
[cell layoutIfNeeded]; [cell layoutIfNeeded];
return [cell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; return [cell systemLayoutSizeFittingSize:CGSizeMake(width, kMaxHeight)];
} }
@end @end
......
...@@ -75,82 +75,32 @@ PopupMenuCommandType CommandTypeFromPopupType(PopupMenuType type) { ...@@ -75,82 +75,32 @@ PopupMenuCommandType CommandTypeFromPopupType(PopupMenuType type) {
- (void)showNavigationHistoryBackPopupMenu { - (void)showNavigationHistoryBackPopupMenu {
base::RecordAction( base::RecordAction(
base::UserMetricsAction("MobileToolbarShowTabHistoryMenu")); base::UserMetricsAction("MobileToolbarShowTabHistoryMenu"));
UIViewController* viewController = [[UIViewController alloc] init]; [self presentPopupOfType:PopupMenuTypeNavigationBackward
UILabel* label = [[UILabel alloc] init]; fromNamedGuide:kBackButtonGuide];
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];
} }
- (void)showNavigationHistoryForwardPopupMenu { - (void)showNavigationHistoryForwardPopupMenu {
base::RecordAction( base::RecordAction(
base::UserMetricsAction("MobileToolbarShowTabHistoryMenu")); base::UserMetricsAction("MobileToolbarShowTabHistoryMenu"));
UIViewController* viewController = [[UIViewController alloc] init]; [self presentPopupOfType:PopupMenuTypeNavigationForward
UILabel* label = [[UILabel alloc] init]; fromNamedGuide:kForwardButtonGuide];
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];
} }
- (void)showToolsMenuPopup { - (void)showToolsMenuPopup {
PopupMenuTableViewController* tableViewController = // The metric is registered at the toolbar level.
[[PopupMenuTableViewController alloc] [self presentPopupOfType:PopupMenuTypeToolsMenu
initWithStyle:UITableViewStyleGrouped]; fromNamedGuide:kToolsMenuGuide];
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];
} }
- (void)showTabGridButtonPopup { - (void)showTabGridButtonPopup {
base::RecordAction(base::UserMetricsAction("MobileToolbarShowTabGridMenu")); base::RecordAction(base::UserMetricsAction("MobileToolbarShowTabGridMenu"));
PopupMenuTableViewController* tableViewController = [self presentPopupOfType:PopupMenuTypeTabGrid
[[PopupMenuTableViewController alloc] init]; fromNamedGuide:kTabSwitcherGuide];
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];
} }
- (void)searchButtonPopup { - (void)searchButtonPopup {
base::RecordAction(base::UserMetricsAction("MobileToolbarShowSearchMenu")); base::RecordAction(base::UserMetricsAction("MobileToolbarShowSearchMenu"));
UIViewController* viewController = [[UIViewController alloc] init]; [self presentPopupOfType:PopupMenuTypeSearch fromNamedGuide:nil];
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];
} }
- (void)dismissPopupMenu { - (void)dismissPopupMenu {
...@@ -168,21 +118,36 @@ PopupMenuCommandType CommandTypeFromPopupType(PopupMenuType type) { ...@@ -168,21 +118,36 @@ PopupMenuCommandType CommandTypeFromPopupType(PopupMenuType type) {
#pragma mark - Private #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|. // |guideName|.
- (void)presentPopupForContent:(UIViewController*)content - (void)presentPopupOfType:(PopupMenuType)type
ofType:(PopupMenuType)type fromNamedGuide:(GuideName*)guideName {
fromNamedGuide:(GuideName*)guideName {
DCHECK(!self.presenter); DCHECK(!self.presenter);
id<BrowserCommands> callableDispatcher = id<BrowserCommands> callableDispatcher =
static_cast<id<BrowserCommands>>(self.dispatcher); static_cast<id<BrowserCommands>>(self.dispatcher);
[callableDispatcher [callableDispatcher
prepareForPopupMenuPresentation:CommandTypeFromPopupType(type)]; 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 = [[PopupMenuPresenter alloc] init];
self.presenter.baseViewController = self.baseViewController; self.presenter.baseViewController = self.baseViewController;
self.presenter.commandHandler = self; self.presenter.commandHandler = self;
self.presenter.presentedViewController = content; self.presenter.presentedViewController = tableViewController;
self.presenter.guideName = guideName; self.presenter.guideName = guideName;
[self.presenter prepareForPresentation]; [self.presenter prepareForPresentation];
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#import "ios/chrome/browser/ui/commands/browser_commands.h" #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/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_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/cells/popup_menu_tools_item.h"
#import "ios/chrome/browser/ui/popup_menu/popup_menu_table_view_controller.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" #import "ios/chrome/browser/ui/reading_list/reading_list_menu_notification_delegate.h"
...@@ -21,13 +22,16 @@ ...@@ -21,13 +22,16 @@
#include "ios/chrome/grit/ios_strings.h" #include "ios/chrome/grit/ios_strings.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h" #include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/user_feedback/user_feedback_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_item.h"
#import "ios/web/public/navigation_manager.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/user_agent.h"
#include "ios/web/public/web_client.h" #include "ios/web/public/web_client.h"
#include "ios/web/public/web_state/web_state.h" #include "ios/web/public/web_state/web_state.h"
#import "ios/web/public/web_state/web_state_observer_bridge.h" #import "ios/web/public/web_state/web_state_observer_bridge.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/image/image.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support." #error "This file requires ARC support."
...@@ -250,8 +254,10 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID, ...@@ -250,8 +254,10 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
[self createToolsMenuItems]; [self createToolsMenuItems];
break; break;
case PopupMenuTypeNavigationForward: case PopupMenuTypeNavigationForward:
[self createNavigationItemsForType:PopupMenuTypeNavigationForward];
break; break;
case PopupMenuTypeNavigationBackward: case PopupMenuTypeNavigationBackward:
[self createNavigationItemsForType:PopupMenuTypeNavigationBackward];
break; break;
case PopupMenuTypeTabGrid: case PopupMenuTypeTabGrid:
[self createTabGridMenuItems]; [self createTabGridMenuItems];
...@@ -365,6 +371,34 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID, ...@@ -365,6 +371,34 @@ PopupMenuToolsItem* CreateTableViewItem(int titleID,
#pragma mark - Item creation (Private) #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. // Creates the menu items for the tab grid menu.
- (void)createTabGridMenuItems { - (void)createTabGridMenuItems {
NSMutableArray* items = [NSMutableArray arrayWithArray:[self itemsForNewTab]]; NSMutableArray* items = [NSMutableArray arrayWithArray:[self itemsForNewTab]];
......
...@@ -262,18 +262,10 @@ ...@@ -262,18 +262,10 @@
return; return;
if (gesture.view == self.view.backButton) { if (gesture.view == self.view.backButton) {
if (base::FeatureList::IsEnabled(kNewToolsMenu)) { [self.dispatcher showNavigationHistoryBackPopupMenu];
[self.dispatcher showNavigationHistoryBackPopupMenu];
} else {
[self.dispatcher showTabHistoryPopupForBackwardHistory];
}
} else if (gesture.view == self.view.forwardButton || } else if (gesture.view == self.view.forwardButton ||
gesture.view == self.view.forwardButtonTrailingPosition) { gesture.view == self.view.forwardButtonTrailingPosition) {
if (base::FeatureList::IsEnabled(kNewToolsMenu)) { [self.dispatcher showNavigationHistoryForwardPopupMenu];
[self.dispatcher showNavigationHistoryForwardPopupMenu];
} else {
[self.dispatcher showTabHistoryPopupForForwardHistory];
}
} else if (gesture.view == self.view.tabGridButton) { } else if (gesture.view == self.view.tabGridButton) {
[self.dispatcher showTabGridButtonPopup]; [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