| 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/mac/scoped_nsobject.h" | |
| 8 #include "base/strings/sys_string_conversions.h" | 7 #include "base/strings/sys_string_conversions.h" |
| 9 #include "ios/chrome/browser/ui/ui_util.h" | 8 #include "ios/chrome/browser/ui/ui_util.h" |
| 10 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 9 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 11 #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" |
| 12 #import "ios/web/navigation/crw_session_entry.h" | 11 #import "ios/web/navigation/crw_session_entry.h" |
| 13 #include "ios/web/public/navigation_item.h" | 12 #include "ios/web/public/navigation_item.h" |
| 14 | 13 |
| 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 15 #error "This file requires ARC support." |
| 16 #endif |
| 17 |
| 15 namespace { | 18 namespace { |
| 16 // Header horizontal layout inset. | 19 // Header horizontal layout inset. |
| 17 const CGFloat kHeaderHorizontalInset = 16; | 20 const CGFloat kHeaderHorizontalInset = 16; |
| 18 // Header vertical layout inset. | 21 // Header vertical layout inset. |
| 19 const CGFloat kHeaderVerticalInset = 16; | 22 const CGFloat kHeaderVerticalInset = 16; |
| 20 // Width and Height for the site icon view. | 23 // Width and Height for the site icon view. |
| 21 const CGFloat kSiteIconViewWidth = 16; | 24 const CGFloat kSiteIconViewWidth = 16; |
| 22 // Height adjustment for the line view. The design calls for some overlap. | 25 // Height adjustment for the line view. The design calls for some overlap. |
| 23 const CGFloat kHeaderHeightAdjustment = 6; | 26 const CGFloat kHeaderHeightAdjustment = 6; |
| 24 // Margin between the icon and the line view in the header. | 27 // Margin between the icon and the line view in the header. |
| 25 const CGFloat kLineViewTopMargin = 3; | 28 const CGFloat kLineViewTopMargin = 3; |
| 26 // Color for the line with in the header section. | 29 // Color for the line with in the header section. |
| 27 const int kHeaderLineRGB = 0xE5E5E5; | 30 const int kHeaderLineRGB = 0xE5E5E5; |
| 28 // Color for the footer line. | 31 // Color for the footer line. |
| 29 const int kFooterRGB = 0xD2D2D2; | 32 const int kFooterRGB = 0xD2D2D2; |
| 30 // Color for the text in the title label. | 33 // Color for the text in the title label. |
| 31 const int kTitleTextRGB = 0x333333; | 34 const int kTitleTextRGB = 0x333333; |
| 32 // Width for the header line view. | 35 // Width for the header line view. |
| 33 NS_INLINE CGFloat HeaderLineWidth() { | 36 NS_INLINE CGFloat HeaderLineWidth() { |
| 34 return IsHighResScreen() ? 1.5 : 2; | 37 return IsHighResScreen() ? 1.5 : 2; |
| 35 } | 38 } |
| 36 // Corner radius for the header line view. | 39 // Corner radius for the header line view. |
| 37 NS_INLINE CGFloat HeaderLineRadius() { | 40 NS_INLINE CGFloat HeaderLineRadius() { |
| 38 return HeaderLineWidth() / 2.0; | 41 return HeaderLineWidth() / 2.0; |
| 39 } | 42 } |
| 40 } | 43 } |
| 41 | 44 |
| 42 @implementation TabHistoryCell { | 45 @implementation TabHistoryCell { |
| 43 base::scoped_nsobject<CRWSessionEntry> _entry; | 46 CRWSessionEntry* _entry; |
| 44 base::scoped_nsobject<UILabel> _titleLabel; | 47 UILabel* _titleLabel; |
| 45 } | 48 } |
| 46 | 49 |
| 47 - (instancetype)initWithFrame:(CGRect)frame { | 50 - (instancetype)initWithFrame:(CGRect)frame { |
| 48 self = [super initWithFrame:frame]; | 51 self = [super initWithFrame:frame]; |
| 49 if (self) | 52 if (self) |
| 50 [self commonInitialization]; | 53 [self commonInitialization]; |
| 51 | 54 |
| 52 return self; | 55 return self; |
| 53 } | 56 } |
| 54 | 57 |
| 55 - (instancetype)initWithCoder:(NSCoder*)coder { | 58 - (instancetype)initWithCoder:(NSCoder*)coder { |
| 56 self = [super initWithCoder:coder]; | 59 self = [super initWithCoder:coder]; |
| 57 if (self) | 60 if (self) |
| 58 [self commonInitialization]; | 61 [self commonInitialization]; |
| 59 | 62 |
| 60 return self; | 63 return self; |
| 61 } | 64 } |
| 62 | 65 |
| 63 - (void)commonInitialization { | 66 - (void)commonInitialization { |
| 64 _titleLabel.reset([[UILabel alloc] initWithFrame:CGRectZero]); | 67 _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 65 [_titleLabel setTextColor:UIColorFromRGB(kTitleTextRGB)]; | 68 [_titleLabel setTextColor:UIColorFromRGB(kTitleTextRGB)]; |
| 66 [_titleLabel | 69 [_titleLabel |
| 67 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]]; | 70 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]]; |
| 68 [[self contentView] addSubview:_titleLabel]; | 71 [[self contentView] addSubview:_titleLabel]; |
| 69 } | 72 } |
| 70 | 73 |
| 71 - (void)layoutSubviews { | 74 - (void)layoutSubviews { |
| 72 [super layoutSubviews]; | 75 [super layoutSubviews]; |
| 73 | 76 |
| 74 CGRect bounds = [[self contentView] bounds]; | 77 CGRect bounds = [[self contentView] bounds]; |
| 75 CGRect frame = AlignRectOriginAndSizeToPixels(bounds); | 78 CGRect frame = AlignRectOriginAndSizeToPixels(bounds); |
| 76 [_titleLabel setFrame:frame]; | 79 [_titleLabel setFrame:frame]; |
| 77 } | 80 } |
| 78 | 81 |
| 79 - (CRWSessionEntry*)entry { | 82 - (CRWSessionEntry*)entry { |
| 80 return [[_entry retain] autorelease]; | 83 return _entry; |
| 81 } | 84 } |
| 82 | 85 |
| 83 - (void)setEntry:(CRWSessionEntry*)entry { | 86 - (void)setEntry:(CRWSessionEntry*)entry { |
| 84 _entry.reset([entry retain]); | 87 _entry = entry; |
| 85 | 88 |
| 86 NSString* title = nil; | 89 NSString* title = nil; |
| 87 web::NavigationItem* navigationItem = [_entry navigationItem]; | 90 web::NavigationItem* navigationItem = [_entry navigationItem]; |
| 88 if (navigationItem) { | 91 if (navigationItem) { |
| 89 // TODO(rohitrao): Can this use GetTitleForDisplay() instead? | 92 // TODO(rohitrao): Can this use GetTitleForDisplay() instead? |
| 90 if (navigationItem->GetTitle().empty()) | 93 if (navigationItem->GetTitle().empty()) |
| 91 title = base::SysUTF8ToNSString(navigationItem->GetURL().spec()); | 94 title = base::SysUTF8ToNSString(navigationItem->GetURL().spec()); |
| 92 else | 95 else |
| 93 title = base::SysUTF16ToNSString(navigationItem->GetTitle()); | 96 title = base::SysUTF16ToNSString(navigationItem->GetTitle()); |
| 94 } | 97 } |
| 95 | 98 |
| 96 [_titleLabel setText:title]; | 99 [_titleLabel setText:title]; |
| 97 [self setAccessibilityLabel:title]; | 100 [self setAccessibilityLabel:title]; |
| 98 [self setNeedsLayout]; | 101 [self setNeedsLayout]; |
| 99 } | 102 } |
| 100 | 103 |
| 101 - (UILabel*)titleLabel { | 104 - (UILabel*)titleLabel { |
| 102 return [[_titleLabel retain] autorelease]; | 105 return _titleLabel; |
| 103 } | 106 } |
| 104 | 107 |
| 105 - (void)prepareForReuse { | 108 - (void)prepareForReuse { |
| 106 [super prepareForReuse]; | 109 [super prepareForReuse]; |
| 107 _entry.reset(nil); | 110 _entry = nil; |
| 108 [_titleLabel setText:nil]; | 111 [_titleLabel setText:nil]; |
| 109 [self setAccessibilityLabel:nil]; | 112 [self setAccessibilityLabel:nil]; |
| 110 } | 113 } |
| 111 | 114 |
| 112 @end | 115 @end |
| 113 | 116 |
| 114 @implementation TabHistorySectionHeader { | 117 @implementation TabHistorySectionHeader { |
| 115 base::scoped_nsobject<UIImageView> _iconView; | 118 UIImageView* _iconView; |
| 116 base::scoped_nsobject<UIView> _lineView; | 119 UIView* _lineView; |
| 117 } | 120 } |
| 118 | 121 |
| 119 - (UIImageView*)iconView { | 122 - (UIImageView*)iconView { |
| 120 return [[_iconView retain] autorelease]; | 123 return _iconView; |
| 121 } | 124 } |
| 122 | 125 |
| 123 - (UIView*)lineView { | 126 - (UIView*)lineView { |
| 124 return [[_lineView retain] autorelease]; | 127 return _lineView; |
| 125 } | 128 } |
| 126 | 129 |
| 127 - (instancetype)initWithFrame:(CGRect)frame { | 130 - (instancetype)initWithFrame:(CGRect)frame { |
| 128 self = [super initWithFrame:frame]; | 131 self = [super initWithFrame:frame]; |
| 129 if (self) { | 132 if (self) { |
| 130 CGRect iconFrame = CGRectMake(0, 0, kSiteIconViewWidth, kSiteIconViewWidth); | 133 CGRect iconFrame = CGRectMake(0, 0, kSiteIconViewWidth, kSiteIconViewWidth); |
| 131 _iconView.reset([[UIImageView alloc] initWithFrame:iconFrame]); | 134 _iconView = [[UIImageView alloc] initWithFrame:iconFrame]; |
| 132 [self addSubview:_iconView]; | 135 [self addSubview:_iconView]; |
| 133 | 136 |
| 134 UIColor* lineColor = UIColorFromRGB(kHeaderLineRGB); | 137 UIColor* lineColor = UIColorFromRGB(kHeaderLineRGB); |
| 135 | 138 |
| 136 _lineView.reset([[UIView alloc] initWithFrame:CGRectZero]); | 139 _lineView = [[UIView alloc] initWithFrame:CGRectZero]; |
| 137 [[_lineView layer] setCornerRadius:HeaderLineRadius()]; | 140 [[_lineView layer] setCornerRadius:HeaderLineRadius()]; |
| 138 [_lineView setBackgroundColor:lineColor]; | 141 [_lineView setBackgroundColor:lineColor]; |
| 139 [self addSubview:_lineView]; | 142 [self addSubview:_lineView]; |
| 140 } | 143 } |
| 141 | 144 |
| 142 return self; | 145 return self; |
| 143 } | 146 } |
| 144 | 147 |
| 145 - (void)layoutSubviews { | 148 - (void)layoutSubviews { |
| 146 [super layoutSubviews]; | 149 [super layoutSubviews]; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 174 | 177 |
| 175 - (instancetype)initWithFrame:(CGRect)frame { | 178 - (instancetype)initWithFrame:(CGRect)frame { |
| 176 self = [super initWithFrame:frame]; | 179 self = [super initWithFrame:frame]; |
| 177 if (self) | 180 if (self) |
| 178 [self setBackgroundColor:UIColorFromRGB(kFooterRGB)]; | 181 [self setBackgroundColor:UIColorFromRGB(kFooterRGB)]; |
| 179 | 182 |
| 180 return self; | 183 return self; |
| 181 } | 184 } |
| 182 | 185 |
| 183 @end | 186 @end |
| OLD | NEW |