| Index: ios/chrome/browser/ui/history/tab_history_popup_controller.mm
|
| diff --git a/ios/chrome/browser/ui/history/tab_history_popup_controller.mm b/ios/chrome/browser/ui/history/tab_history_popup_controller.mm
|
| index 832de03afada7c2b7e8a4fcdb927d90f924e01d3..5c6c1245fd216fbdc3c5739f0f059bd111684ab9 100644
|
| --- a/ios/chrome/browser/ui/history/tab_history_popup_controller.mm
|
| +++ b/ios/chrome/browser/ui/history/tab_history_popup_controller.mm
|
| @@ -15,20 +15,22 @@
|
| #include "ios/chrome/browser/ui/ui_util.h"
|
| #import "ios/chrome/common/material_timing.h"
|
| #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoFontLoader.h"
|
| -#import "ios/web/navigation/crw_session_entry.h"
|
| #include "ios/web/public/navigation_item.h"
|
| #import "ui/gfx/ios/NSString+CrStringDrawing.h"
|
| #include "ui/gfx/ios/uikit_util.h"
|
| +#include "url/gurl.h"
|
|
|
| #if !defined(__has_feature) || !__has_feature(objc_arc)
|
| #error "This file requires ARC support."
|
| #endif
|
|
|
| namespace {
|
| -static const CGFloat kTabHistoryMinWidth = 250.0;
|
| -static const CGFloat kTabHistoryMaxWidthLandscapePhone = 350.0;
|
| +const CGFloat kTabHistoryMinWidth = 250.0;
|
| +const CGFloat kTabHistoryMaxWidthLandscapePhone = 350.0;
|
| // x coordinate for the textLabel in a default table cell with an image.
|
| -static const CGFloat kCellTextXCoordinate = 60.0;
|
| +const CGFloat kCellTextXCoordinate = 60.0;
|
| +// The corner radius for the popover container view.
|
| +const CGFloat kPopoverCornerRadius = 2.0;
|
| // Inset for the shadows of the contained views.
|
| NS_INLINE UIEdgeInsets TabHistoryPopupMenuInsets() {
|
| return UIEdgeInsetsMakeDirected(9, 11, 12, 11);
|
| @@ -41,91 +43,90 @@ NS_INLINE UIEdgeInsets TabHistoryPopupMenuInsets() {
|
| static const CGFloat kHeightPercentage = 0.85;
|
| } // anonymous namespace
|
|
|
| -@interface TabHistoryPopupController () {
|
| - // TableViewController for the table displaying tab history entries.
|
| - TabHistoryViewController* tabHistoryTableViewController_;
|
| -
|
| - // Container view of the history entries table.
|
| - UIView* tabHistoryTableViewContainer_;
|
| -}
|
| -
|
| -// Determines the width for the popup depending on the device, orientation, and
|
| -// CRWSessionEntrys to display.
|
| -- (CGFloat)calculatePopupWidth:(NSArray*)entries;
|
| +@interface TabHistoryPopupController ()
|
|
|
| +// The UITableViewController displaying Tab history items.
|
| @property(nonatomic, strong)
|
| TabHistoryViewController* tabHistoryTableViewController;
|
| +// The container view that displays |tabHistoryTableViewController|.
|
| @property(nonatomic, strong) UIView* tabHistoryTableViewContainer;
|
|
|
| +// Determines the width for the popup depending on the device, orientation, and
|
| +// number of NavigationItems to display.
|
| ++ (CGFloat)popupWidthForItems:(const web::NavigationItemList)items;
|
| +
|
| @end
|
|
|
| @implementation TabHistoryPopupController
|
|
|
| -@synthesize tabHistoryTableViewController = tabHistoryTableViewController_;
|
| -@synthesize tabHistoryTableViewContainer = tabHistoryTableViewContainer_;
|
| +@synthesize tabHistoryTableViewController = _tabHistoryTableViewController;
|
| +@synthesize tabHistoryTableViewContainer = _tabHistoryTableViewContainer;
|
|
|
| - (id)initWithOrigin:(CGPoint)origin
|
| parentView:(UIView*)parent
|
| - entries:(NSArray*)entries {
|
| + items:(const web::NavigationItemList&)items {
|
| DCHECK(parent);
|
| - self = [super initWithParentView:parent];
|
| - if (self) {
|
| - tabHistoryTableViewController_ = [[TabHistoryViewController alloc] init];
|
| - [tabHistoryTableViewController_ setSessionEntries:entries];
|
| -
|
| - UICollectionView* collectionView =
|
| - [tabHistoryTableViewController_ collectionView];
|
| - [collectionView setAccessibilityIdentifier:@"Tab History"];
|
| -
|
| - tabHistoryTableViewContainer_ = [[UIView alloc] initWithFrame:CGRectZero];
|
| - [tabHistoryTableViewContainer_ layer].cornerRadius = 2;
|
| - [tabHistoryTableViewContainer_ layer].masksToBounds = YES;
|
| - [tabHistoryTableViewContainer_ addSubview:collectionView];
|
| -
|
| + if ((self = [super initWithParentView:parent])) {
|
| + // Create the table view controller.
|
| + _tabHistoryTableViewController =
|
| + [[TabHistoryViewController alloc] initWithItems:items];
|
| +
|
| + // Set up the container view.
|
| + _tabHistoryTableViewContainer = [[UIView alloc] initWithFrame:CGRectZero];
|
| + _tabHistoryTableViewContainer.layer.cornerRadius = kPopoverCornerRadius;
|
| + _tabHistoryTableViewContainer.layer.masksToBounds = YES;
|
| + [_tabHistoryTableViewContainer
|
| + addSubview:_tabHistoryTableViewController.view];
|
| +
|
| + // Calculate the optimal popup size.
|
| LayoutOffset originOffset =
|
| kHistoryPopupLeadingOffset - TabHistoryPopupMenuInsets().left;
|
| CGPoint newOrigin = CGPointLayoutOffset(origin, originOffset);
|
| newOrigin.y += kHistoryPopupYOffset;
|
| -
|
| CGFloat availableHeight =
|
| (CGRectGetHeight([parent bounds]) - origin.y) * kHeightPercentage;
|
| CGFloat optimalHeight =
|
| - [tabHistoryTableViewController_ optimalHeight:availableHeight];
|
| - CGFloat popupWidth = [self calculatePopupWidth:entries];
|
| + [_tabHistoryTableViewController optimalHeight:availableHeight];
|
| + CGFloat popupWidth = [[self class] popupWidthForItems:items];
|
| [self setOptimalSize:CGSizeMake(popupWidth, optimalHeight)
|
| atOrigin:newOrigin];
|
| -
|
| - CGRect bounds = [[self popupContainer] bounds];
|
| - CGRect frame = UIEdgeInsetsInsetRect(bounds, TabHistoryPopupMenuInsets());
|
| -
|
| - [tabHistoryTableViewContainer_ setFrame:frame];
|
| - [collectionView setFrame:[tabHistoryTableViewContainer_ bounds]];
|
| -
|
| - [[self popupContainer] addSubview:tabHistoryTableViewContainer_];
|
| - CGRect containerFrame = [[self popupContainer] frame];
|
| - CGPoint destination = CGPointMake(CGRectGetLeadingEdge(containerFrame),
|
| - CGRectGetMinY(containerFrame));
|
| - [self fadeInPopupFromSource:origin toDestination:destination];
|
| }
|
| return self;
|
| }
|
|
|
| +- (void)dealloc {
|
| + [_tabHistoryTableViewContainer removeFromSuperview];
|
| +}
|
| +
|
| +#pragma mark - PopupMenuController
|
| +
|
| - (void)fadeInPopupFromSource:(CGPoint)source
|
| toDestination:(CGPoint)destination {
|
| - [tabHistoryTableViewContainer_ setAlpha:0];
|
| + // Add the container view to the popup view and resize.
|
| + if (!_tabHistoryTableViewContainer.superview)
|
| + [self.popupContainer addSubview:_tabHistoryTableViewContainer];
|
| + _tabHistoryTableViewContainer.frame = UIEdgeInsetsInsetRect(
|
| + self.popupContainer.bounds, TabHistoryPopupMenuInsets());
|
| + _tabHistoryTableViewController.view.frame =
|
| + _tabHistoryTableViewContainer.bounds;
|
| +
|
| + // Set up the animation.
|
| + [_tabHistoryTableViewContainer setAlpha:0];
|
| [UIView animateWithDuration:ios::material::kDuration1
|
| animations:^{
|
| - [tabHistoryTableViewContainer_ setAlpha:1];
|
| + [_tabHistoryTableViewContainer setAlpha:1];
|
| }];
|
| [super fadeInPopupFromSource:source toDestination:destination];
|
| }
|
|
|
| - (void)dismissAnimatedWithCompletion:(void (^)(void))completion {
|
| - [tabHistoryTableViewContainer_ setAlpha:0];
|
| + [_tabHistoryTableViewContainer setAlpha:0];
|
| [super dismissAnimatedWithCompletion:completion];
|
| }
|
|
|
| -- (CGFloat)calculatePopupWidth:(NSArray*)entries {
|
| +#pragma mark -
|
| +
|
| ++ (CGFloat)popupWidthForItems:(const web::NavigationItemList)items {
|
| CGFloat maxWidth;
|
|
|
| // Determine the maximum width for the device and orientation.
|
| @@ -145,8 +146,7 @@ - (CGFloat)calculatePopupWidth:(NSArray*)entries {
|
| // Increase the width to fit the text to display but don't exceed maxWidth.
|
| CGFloat cellWidth = kTabHistoryMinWidth;
|
| UIFont* font = [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16];
|
| - for (CRWSessionEntry* sessionEntry in entries) {
|
| - web::NavigationItem* item = sessionEntry.navigationItem;
|
| + for (web::NavigationItem* item : items) {
|
| // TODO(rohitrao): Can this be replaced with GetTitleForDisplay()?
|
| NSString* cellText = item->GetTitle().empty()
|
| ? base::SysUTF8ToNSString(item->GetURL().spec())
|
| @@ -155,7 +155,7 @@ - (CGFloat)calculatePopupWidth:(NSArray*)entries {
|
| kCellTextXCoordinate;
|
|
|
| // If contentWidth is larger than maxWidth, return maxWidth instead of
|
| - // checking the rest of the entries.
|
| + // checking the rest of the items.
|
| if (contentWidth > maxWidth)
|
| return maxWidth;
|
| if (contentWidth > cellWidth)
|
| @@ -164,8 +164,4 @@ - (CGFloat)calculatePopupWidth:(NSArray*)entries {
|
| return cellWidth;
|
| }
|
|
|
| -- (void)dealloc {
|
| - [tabHistoryTableViewContainer_ removeFromSuperview];
|
| -}
|
| -
|
| @end
|
|
|