| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_cell.h" | 5 #import "ios/chrome/browser/ui/history/tab_history_cell.h" |
| 6 | 6 |
| 7 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
| 8 #include "ios/chrome/browser/ui/ui_util.h" | 8 #include "ios/chrome/browser/ui/ui_util.h" |
| 9 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 9 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 10 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 10 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
| 11 #import "ios/web/navigation/crw_session_entry.h" |
| 11 #include "ios/web/public/navigation_item.h" | 12 #include "ios/web/public/navigation_item.h" |
| 12 | 13 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) | 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." | 15 #error "This file requires ARC support." |
| 15 #endif | 16 #endif |
| 16 | 17 |
| 17 namespace { | 18 namespace { |
| 18 // Header horizontal layout inset. | 19 // Header horizontal layout inset. |
| 19 const CGFloat kHeaderHorizontalInset = 16; | 20 const CGFloat kHeaderHorizontalInset = 16; |
| 20 // Header vertical layout inset. | 21 // Header vertical layout inset. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 // Width for the header line view. | 35 // Width for the header line view. |
| 35 NS_INLINE CGFloat HeaderLineWidth() { | 36 NS_INLINE CGFloat HeaderLineWidth() { |
| 36 return IsHighResScreen() ? 1.5 : 2; | 37 return IsHighResScreen() ? 1.5 : 2; |
| 37 } | 38 } |
| 38 // Corner radius for the header line view. | 39 // Corner radius for the header line view. |
| 39 NS_INLINE CGFloat HeaderLineRadius() { | 40 NS_INLINE CGFloat HeaderLineRadius() { |
| 40 return HeaderLineWidth() / 2.0; | 41 return HeaderLineWidth() / 2.0; |
| 41 } | 42 } |
| 42 } | 43 } |
| 43 | 44 |
| 44 @implementation TabHistoryCell | 45 @implementation TabHistoryCell { |
| 45 | 46 CRWSessionEntry* _entry; |
| 46 @synthesize item = _item; | 47 UILabel* _titleLabel; |
| 47 @synthesize titleLabel = _titleLabel; | 48 } |
| 48 | 49 |
| 49 - (instancetype)initWithFrame:(CGRect)frame { | 50 - (instancetype)initWithFrame:(CGRect)frame { |
| 50 self = [super initWithFrame:frame]; | 51 self = [super initWithFrame:frame]; |
| 51 if (self) | 52 if (self) |
| 52 [self commonInitialization]; | 53 [self commonInitialization]; |
| 53 | 54 |
| 54 return self; | 55 return self; |
| 55 } | 56 } |
| 56 | 57 |
| 57 - (instancetype)initWithCoder:(NSCoder*)coder { | 58 - (instancetype)initWithCoder:(NSCoder*)coder { |
| 58 self = [super initWithCoder:coder]; | 59 self = [super initWithCoder:coder]; |
| 59 if (self) | 60 if (self) |
| 60 [self commonInitialization]; | 61 [self commonInitialization]; |
| 61 | 62 |
| 62 return self; | 63 return self; |
| 63 } | 64 } |
| 64 | 65 |
| 65 - (void)commonInitialization { | 66 - (void)commonInitialization { |
| 66 _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 67 _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 67 [_titleLabel setTextColor:UIColorFromRGB(kTitleTextRGB)]; | 68 [_titleLabel setTextColor:UIColorFromRGB(kTitleTextRGB)]; |
| 68 [_titleLabel | 69 [_titleLabel |
| 69 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]]; | 70 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]]; |
| 70 [[self contentView] addSubview:_titleLabel]; | 71 [[self contentView] addSubview:_titleLabel]; |
| 71 } | 72 } |
| 72 | 73 |
| 73 - (void)layoutSubviews { | 74 - (void)layoutSubviews { |
| 74 [super layoutSubviews]; | 75 [super layoutSubviews]; |
| 75 self.titleLabel.frame = | 76 |
| 76 AlignRectOriginAndSizeToPixels(self.contentView.bounds); | 77 CGRect bounds = [[self contentView] bounds]; |
| 78 CGRect frame = AlignRectOriginAndSizeToPixels(bounds); |
| 79 [_titleLabel setFrame:frame]; |
| 77 } | 80 } |
| 78 | 81 |
| 79 #pragma mark Accessors | 82 - (CRWSessionEntry*)entry { |
| 83 return _entry; |
| 84 } |
| 80 | 85 |
| 81 - (void)setItem:(const web::NavigationItem*)item { | 86 - (void)setEntry:(CRWSessionEntry*)entry { |
| 82 _item = item; | 87 _entry = entry; |
| 83 | 88 |
| 84 self.titleLabel.text = | 89 NSString* title = nil; |
| 85 _item ? base::SysUTF16ToNSString(_item->GetTitleForDisplay()) : nil; | 90 web::NavigationItem* navigationItem = [_entry navigationItem]; |
| 86 [self setAccessibilityLabel:self.titleLabel.text]; | 91 if (navigationItem) { |
| 92 // TODO(rohitrao): Can this use GetTitleForDisplay() instead? |
| 93 if (navigationItem->GetTitle().empty()) |
| 94 title = base::SysUTF8ToNSString(navigationItem->GetURL().spec()); |
| 95 else |
| 96 title = base::SysUTF16ToNSString(navigationItem->GetTitle()); |
| 97 } |
| 98 |
| 99 [_titleLabel setText:title]; |
| 100 [self setAccessibilityLabel:title]; |
| 87 [self setNeedsLayout]; | 101 [self setNeedsLayout]; |
| 88 } | 102 } |
| 89 | 103 |
| 90 #pragma mark UICollectionViewCell | 104 - (UILabel*)titleLabel { |
| 105 return _titleLabel; |
| 106 } |
| 91 | 107 |
| 92 - (void)prepareForReuse { | 108 - (void)prepareForReuse { |
| 93 [super prepareForReuse]; | 109 [super prepareForReuse]; |
| 94 self.item = nullptr; | 110 _entry = nil; |
| 111 [_titleLabel setText:nil]; |
| 112 [self setAccessibilityLabel:nil]; |
| 95 } | 113 } |
| 96 | 114 |
| 97 @end | 115 @end |
| 98 | 116 |
| 99 @implementation TabHistorySectionHeader | 117 @implementation TabHistorySectionHeader { |
| 118 UIImageView* _iconView; |
| 119 UIView* _lineView; |
| 120 } |
| 100 | 121 |
| 101 @synthesize iconView = _iconView; | 122 - (UIImageView*)iconView { |
| 102 @synthesize lineView = _lineView; | 123 return _iconView; |
| 124 } |
| 125 |
| 126 - (UIView*)lineView { |
| 127 return _lineView; |
| 128 } |
| 103 | 129 |
| 104 - (instancetype)initWithFrame:(CGRect)frame { | 130 - (instancetype)initWithFrame:(CGRect)frame { |
| 105 self = [super initWithFrame:frame]; | 131 self = [super initWithFrame:frame]; |
| 106 if (self) { | 132 if (self) { |
| 107 CGRect iconFrame = CGRectMake(0, 0, kSiteIconViewWidth, kSiteIconViewWidth); | 133 CGRect iconFrame = CGRectMake(0, 0, kSiteIconViewWidth, kSiteIconViewWidth); |
| 108 _iconView = [[UIImageView alloc] initWithFrame:iconFrame]; | 134 _iconView = [[UIImageView alloc] initWithFrame:iconFrame]; |
| 109 [self addSubview:_iconView]; | 135 [self addSubview:_iconView]; |
| 110 | 136 |
| 137 UIColor* lineColor = UIColorFromRGB(kHeaderLineRGB); |
| 138 |
| 111 _lineView = [[UIView alloc] initWithFrame:CGRectZero]; | 139 _lineView = [[UIView alloc] initWithFrame:CGRectZero]; |
| 112 _lineView.layer.cornerRadius = HeaderLineRadius(); | 140 [[_lineView layer] setCornerRadius:HeaderLineRadius()]; |
| 113 _lineView.backgroundColor = UIColorFromRGB(kHeaderLineRGB); | 141 [_lineView setBackgroundColor:lineColor]; |
| 114 [self addSubview:_lineView]; | 142 [self addSubview:_lineView]; |
| 115 } | 143 } |
| 116 | 144 |
| 117 return self; | 145 return self; |
| 118 } | 146 } |
| 119 | 147 |
| 120 #pragma mark UIView | |
| 121 | |
| 122 - (void)layoutSubviews { | 148 - (void)layoutSubviews { |
| 123 [super layoutSubviews]; | 149 [super layoutSubviews]; |
| 124 | 150 |
| 125 CGRect bounds = | 151 CGRect bounds = |
| 126 CGRectInset([self bounds], kHeaderHorizontalInset, kHeaderVerticalInset); | 152 CGRectInset([self bounds], kHeaderHorizontalInset, kHeaderVerticalInset); |
| 127 | 153 |
| 128 CGRect iconViewFrame = AlignRectToPixel(bounds); | 154 CGRect iconViewFrame = AlignRectToPixel(bounds); |
| 129 iconViewFrame.size = CGSizeMake(kSiteIconViewWidth, kSiteIconViewWidth); | 155 iconViewFrame.size = CGSizeMake(kSiteIconViewWidth, kSiteIconViewWidth); |
| 130 self.iconView.frame = iconViewFrame; | 156 [_iconView setFrame:iconViewFrame]; |
| 131 | 157 |
| 132 CGFloat iconViewMaxY = CGRectGetMaxY(iconViewFrame); | 158 CGFloat iconViewMaxY = CGRectGetMaxY(iconViewFrame); |
| 133 CGFloat height = | 159 CGFloat height = |
| 134 CGRectGetHeight(bounds) - iconViewMaxY + kHeaderHeightAdjustment; | 160 CGRectGetHeight(bounds) - iconViewMaxY + kHeaderHeightAdjustment; |
| 135 if (height < 0) | 161 if (height < 0) |
| 136 height = 0; | 162 height = 0; |
| 137 | 163 |
| 138 CGRect lineViewFrame = CGRectZero; | 164 CGRect lineViewFrame = CGRectZero; |
| 139 lineViewFrame.origin.x = CGRectGetMidX(bounds) - HeaderLineWidth() / 2.0; | 165 lineViewFrame.origin.x = CGRectGetMidX(bounds) - HeaderLineWidth() / 2.0; |
| 140 lineViewFrame.origin.y = iconViewMaxY + kLineViewTopMargin; | 166 lineViewFrame.origin.y = iconViewMaxY + kLineViewTopMargin; |
| 141 lineViewFrame.size.width = HeaderLineWidth(); | 167 lineViewFrame.size.width = HeaderLineWidth(); |
| 142 lineViewFrame.size.height = height; | 168 lineViewFrame.size.height = height; |
| 143 lineViewFrame = AlignRectOriginAndSizeToPixels(lineViewFrame); | 169 lineViewFrame = AlignRectOriginAndSizeToPixels(lineViewFrame); |
| 144 self.lineView.frame = lineViewFrame; | 170 |
| 171 [_lineView setFrame:lineViewFrame]; |
| 145 } | 172 } |
| 146 | 173 |
| 147 @end | 174 @end |
| 148 | 175 |
| 149 @implementation TabHistorySectionFooter | 176 @implementation TabHistorySectionFooter |
| 150 | 177 |
| 151 - (instancetype)initWithFrame:(CGRect)frame { | 178 - (instancetype)initWithFrame:(CGRect)frame { |
| 152 self = [super initWithFrame:frame]; | 179 self = [super initWithFrame:frame]; |
| 153 if (self) | 180 if (self) |
| 154 self.backgroundColor = UIColorFromRGB(kFooterRGB); | 181 [self setBackgroundColor:UIColorFromRGB(kFooterRGB)]; |
| 155 | 182 |
| 156 return self; | 183 return self; |
| 157 } | 184 } |
| 158 | 185 |
| 159 @end | 186 @end |
| OLD | NEW |