| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #import "ios/chrome/browser/ui/history/tab_history_popup_controller.h" | 5 #import "ios/chrome/browser/ui/history/tab_history_popup_controller.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/bundle_locations.h" | 10 #include "base/mac/bundle_locations.h" |
| 11 #include "base/mac/objc_property_releaser.h" | |
| 12 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 13 #import "ios/chrome/browser/ui/history/tab_history_view_controller.h" | 12 #import "ios/chrome/browser/ui/history/tab_history_view_controller.h" |
| 14 #import "ios/chrome/browser/ui/popup_menu/popup_menu_view.h" | 13 #import "ios/chrome/browser/ui/popup_menu/popup_menu_view.h" |
| 15 #include "ios/chrome/browser/ui/rtl_geometry.h" | 14 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 16 #include "ios/chrome/browser/ui/ui_util.h" | 15 #include "ios/chrome/browser/ui/ui_util.h" |
| 17 #import "ios/chrome/common/material_timing.h" | 16 #import "ios/chrome/common/material_timing.h" |
| 18 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 17 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
| 19 #import "ios/web/navigation/crw_session_entry.h" | 18 #import "ios/web/navigation/crw_session_entry.h" |
| 20 #include "ios/web/public/navigation_item.h" | 19 #include "ios/web/public/navigation_item.h" |
| 21 #import "ui/gfx/ios/NSString+CrStringDrawing.h" | 20 #import "ui/gfx/ios/NSString+CrStringDrawing.h" |
| 22 #include "ui/gfx/ios/uikit_util.h" | 21 #include "ui/gfx/ios/uikit_util.h" |
| 23 | 22 |
| 23 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 24 #error "This file requires ARC support." |
| 25 #endif |
| 26 |
| 24 namespace { | 27 namespace { |
| 25 static const CGFloat kTabHistoryMinWidth = 250.0; | 28 static const CGFloat kTabHistoryMinWidth = 250.0; |
| 26 static const CGFloat kTabHistoryMaxWidthLandscapePhone = 350.0; | 29 static const CGFloat kTabHistoryMaxWidthLandscapePhone = 350.0; |
| 27 // x coordinate for the textLabel in a default table cell with an image. | 30 // x coordinate for the textLabel in a default table cell with an image. |
| 28 static const CGFloat kCellTextXCoordinate = 60.0; | 31 static const CGFloat kCellTextXCoordinate = 60.0; |
| 29 // Inset for the shadows of the contained views. | 32 // Inset for the shadows of the contained views. |
| 30 NS_INLINE UIEdgeInsets TabHistoryPopupMenuInsets() { | 33 NS_INLINE UIEdgeInsets TabHistoryPopupMenuInsets() { |
| 31 return UIEdgeInsetsMakeDirected(9, 11, 12, 11); | 34 return UIEdgeInsetsMakeDirected(9, 11, 12, 11); |
| 32 } | 35 } |
| 33 | 36 |
| 34 // Layout for popup: shift twelve pixels towards the leading edge. | 37 // Layout for popup: shift twelve pixels towards the leading edge. |
| 35 LayoutOffset kHistoryPopupLeadingOffset = -12; | 38 LayoutOffset kHistoryPopupLeadingOffset = -12; |
| 36 CGFloat kHistoryPopupYOffset = 3; | 39 CGFloat kHistoryPopupYOffset = 3; |
| 37 // Occupation of the Tools Container as a percentage of the parent height. | 40 // Occupation of the Tools Container as a percentage of the parent height. |
| 38 static const CGFloat kHeightPercentage = 0.85; | 41 static const CGFloat kHeightPercentage = 0.85; |
| 39 } // anonymous namespace | 42 } // anonymous namespace |
| 40 | 43 |
| 41 @interface TabHistoryPopupController () { | 44 @interface TabHistoryPopupController () { |
| 42 // TableViewController for the table displaying tab history entries. | 45 // TableViewController for the table displaying tab history entries. |
| 43 TabHistoryViewController* tabHistoryTableViewController_; | 46 TabHistoryViewController* tabHistoryTableViewController_; |
| 44 | 47 |
| 45 // Container view of the history entries table. | 48 // Container view of the history entries table. |
| 46 UIView* tabHistoryTableViewContainer_; | 49 UIView* tabHistoryTableViewContainer_; |
| 47 | |
| 48 base::mac::ObjCPropertyReleaser propertyReleaser_TabHistoryPopupController_; | |
| 49 } | 50 } |
| 50 | 51 |
| 51 // Determines the width for the popup depending on the device, orientation, and | 52 // Determines the width for the popup depending on the device, orientation, and |
| 52 // CRWSessionEntrys to display. | 53 // CRWSessionEntrys to display. |
| 53 - (CGFloat)calculatePopupWidth:(NSArray*)entries; | 54 - (CGFloat)calculatePopupWidth:(NSArray*)entries; |
| 54 | 55 |
| 55 @property(nonatomic, retain) | 56 @property(nonatomic, strong) |
| 56 TabHistoryViewController* tabHistoryTableViewController; | 57 TabHistoryViewController* tabHistoryTableViewController; |
| 57 @property(nonatomic, retain) UIView* tabHistoryTableViewContainer; | 58 @property(nonatomic, strong) UIView* tabHistoryTableViewContainer; |
| 58 | 59 |
| 59 @end | 60 @end |
| 60 | 61 |
| 61 @implementation TabHistoryPopupController | 62 @implementation TabHistoryPopupController |
| 62 | 63 |
| 63 @synthesize tabHistoryTableViewController = tabHistoryTableViewController_; | 64 @synthesize tabHistoryTableViewController = tabHistoryTableViewController_; |
| 64 @synthesize tabHistoryTableViewContainer = tabHistoryTableViewContainer_; | 65 @synthesize tabHistoryTableViewContainer = tabHistoryTableViewContainer_; |
| 65 | 66 |
| 66 - (id)initWithOrigin:(CGPoint)origin | 67 - (id)initWithOrigin:(CGPoint)origin |
| 67 parentView:(UIView*)parent | 68 parentView:(UIView*)parent |
| 68 entries:(NSArray*)entries { | 69 entries:(NSArray*)entries { |
| 69 DCHECK(parent); | 70 DCHECK(parent); |
| 70 self = [super initWithParentView:parent]; | 71 self = [super initWithParentView:parent]; |
| 71 if (self) { | 72 if (self) { |
| 72 propertyReleaser_TabHistoryPopupController_.Init( | |
| 73 self, [TabHistoryPopupController class]); | |
| 74 | |
| 75 tabHistoryTableViewController_ = [[TabHistoryViewController alloc] init]; | 73 tabHistoryTableViewController_ = [[TabHistoryViewController alloc] init]; |
| 76 [tabHistoryTableViewController_ setSessionEntries:entries]; | 74 [tabHistoryTableViewController_ setSessionEntries:entries]; |
| 77 | 75 |
| 78 UICollectionView* collectionView = | 76 UICollectionView* collectionView = |
| 79 [tabHistoryTableViewController_ collectionView]; | 77 [tabHistoryTableViewController_ collectionView]; |
| 80 [collectionView setAccessibilityIdentifier:@"Tab History"]; | 78 [collectionView setAccessibilityIdentifier:@"Tab History"]; |
| 81 | 79 |
| 82 tabHistoryTableViewContainer_ = [[UIView alloc] initWithFrame:CGRectZero]; | 80 tabHistoryTableViewContainer_ = [[UIView alloc] initWithFrame:CGRectZero]; |
| 83 [tabHistoryTableViewContainer_ layer].cornerRadius = 2; | 81 [tabHistoryTableViewContainer_ layer].cornerRadius = 2; |
| 84 [tabHistoryTableViewContainer_ layer].masksToBounds = YES; | 82 [tabHistoryTableViewContainer_ layer].masksToBounds = YES; |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 if (contentWidth > maxWidth) | 159 if (contentWidth > maxWidth) |
| 162 return maxWidth; | 160 return maxWidth; |
| 163 if (contentWidth > cellWidth) | 161 if (contentWidth > cellWidth) |
| 164 cellWidth = contentWidth; | 162 cellWidth = contentWidth; |
| 165 } | 163 } |
| 166 return cellWidth; | 164 return cellWidth; |
| 167 } | 165 } |
| 168 | 166 |
| 169 - (void)dealloc { | 167 - (void)dealloc { |
| 170 [tabHistoryTableViewContainer_ removeFromSuperview]; | 168 [tabHistoryTableViewContainer_ removeFromSuperview]; |
| 171 [super dealloc]; | |
| 172 } | 169 } |
| 173 | 170 |
| 174 @end | 171 @end |
| OLD | NEW |