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