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 5c6c1245fd216fbdc3c5739f0f059bd111684ab9..832de03afada7c2b7e8a4fcdb927d90f924e01d3 100644 |
--- a/ios/chrome/browser/ui/history/tab_history_popup_controller.mm |
+++ b/ios/chrome/browser/ui/history/tab_history_popup_controller.mm |
@@ -15,22 +15,20 @@ |
#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 { |
-const CGFloat kTabHistoryMinWidth = 250.0; |
-const CGFloat kTabHistoryMaxWidthLandscapePhone = 350.0; |
+static const CGFloat kTabHistoryMinWidth = 250.0; |
+static const CGFloat kTabHistoryMaxWidthLandscapePhone = 350.0; |
// x coordinate for the textLabel in a default table cell with an image. |
-const CGFloat kCellTextXCoordinate = 60.0; |
-// The corner radius for the popover container view. |
-const CGFloat kPopoverCornerRadius = 2.0; |
+static const CGFloat kCellTextXCoordinate = 60.0; |
// Inset for the shadows of the contained views. |
NS_INLINE UIEdgeInsets TabHistoryPopupMenuInsets() { |
return UIEdgeInsetsMakeDirected(9, 11, 12, 11); |
@@ -43,90 +41,91 @@ |
static const CGFloat kHeightPercentage = 0.85; |
} // anonymous namespace |
-@interface TabHistoryPopupController () |
+@interface TabHistoryPopupController () { |
+ // TableViewController for the table displaying tab history entries. |
+ TabHistoryViewController* tabHistoryTableViewController_; |
-// The UITableViewController displaying Tab history items. |
+ // 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; |
+ |
@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 |
- items:(const web::NavigationItemList&)items { |
+ entries:(NSArray*)entries { |
DCHECK(parent); |
- if ((self = [super initWithParentView:parent])) { |
- // Create the table view controller. |
- _tabHistoryTableViewController = |
- [[TabHistoryViewController alloc] initWithItems:items]; |
+ self = [super initWithParentView:parent]; |
+ if (self) { |
+ tabHistoryTableViewController_ = [[TabHistoryViewController alloc] init]; |
+ [tabHistoryTableViewController_ setSessionEntries:entries]; |
- // Set up the container view. |
- _tabHistoryTableViewContainer = [[UIView alloc] initWithFrame:CGRectZero]; |
- _tabHistoryTableViewContainer.layer.cornerRadius = kPopoverCornerRadius; |
- _tabHistoryTableViewContainer.layer.masksToBounds = YES; |
- [_tabHistoryTableViewContainer |
- addSubview:_tabHistoryTableViewController.view]; |
+ UICollectionView* collectionView = |
+ [tabHistoryTableViewController_ collectionView]; |
+ [collectionView setAccessibilityIdentifier:@"Tab History"]; |
- // Calculate the optimal popup size. |
+ tabHistoryTableViewContainer_ = [[UIView alloc] initWithFrame:CGRectZero]; |
+ [tabHistoryTableViewContainer_ layer].cornerRadius = 2; |
+ [tabHistoryTableViewContainer_ layer].masksToBounds = YES; |
+ [tabHistoryTableViewContainer_ addSubview:collectionView]; |
+ |
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 class] popupWidthForItems:items]; |
+ [tabHistoryTableViewController_ optimalHeight:availableHeight]; |
+ CGFloat popupWidth = [self calculatePopupWidth:entries]; |
[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 { |
- // 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]; |
+ [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]; |
} |
-#pragma mark - |
- |
-+ (CGFloat)popupWidthForItems:(const web::NavigationItemList)items { |
+- (CGFloat)calculatePopupWidth:(NSArray*)entries { |
CGFloat maxWidth; |
// Determine the maximum width for the device and orientation. |
@@ -146,7 +145,8 @@ |
// Increase the width to fit the text to display but don't exceed maxWidth. |
CGFloat cellWidth = kTabHistoryMinWidth; |
UIFont* font = [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]; |
- for (web::NavigationItem* item : items) { |
+ for (CRWSessionEntry* sessionEntry in entries) { |
+ web::NavigationItem* item = sessionEntry.navigationItem; |
// TODO(rohitrao): Can this be replaced with GetTitleForDisplay()? |
NSString* cellText = item->GetTitle().empty() |
? base::SysUTF8ToNSString(item->GetURL().spec()) |
@@ -155,7 +155,7 @@ |
kCellTextXCoordinate; |
// If contentWidth is larger than maxWidth, return maxWidth instead of |
- // checking the rest of the items. |
+ // checking the rest of the entries. |
if (contentWidth > maxWidth) |
return maxWidth; |
if (contentWidth > cellWidth) |
@@ -164,4 +164,8 @@ |
return cellWidth; |
} |
+- (void)dealloc { |
+ [tabHistoryTableViewContainer_ removeFromSuperview]; |
+} |
+ |
@end |