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