Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(222)

Side by Side Diff: ios/chrome/browser/ui/history/tab_history_cell.mm

Issue 2693013005: Updated tab history classes to use NavigationItemLists. (Closed)
Patch Set: update DEPS, include url_formatter in BUILD.gn Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
12 #include "ios/web/public/navigation_item.h" 11 #include "ios/web/public/navigation_item.h"
13 12
14 #if !defined(__has_feature) || !__has_feature(objc_arc) 13 #if !defined(__has_feature) || !__has_feature(objc_arc)
15 #error "This file requires ARC support." 14 #error "This file requires ARC support."
16 #endif 15 #endif
17 16
18 namespace { 17 namespace {
19 // Header horizontal layout inset. 18 // Header horizontal layout inset.
20 const CGFloat kHeaderHorizontalInset = 16; 19 const CGFloat kHeaderHorizontalInset = 16;
21 // Header vertical layout inset. 20 // Header vertical layout inset.
(...skipping 13 matching lines...) Expand all
35 // Width for the header line view. 34 // Width for the header line view.
36 NS_INLINE CGFloat HeaderLineWidth() { 35 NS_INLINE CGFloat HeaderLineWidth() {
37 return IsHighResScreen() ? 1.5 : 2; 36 return IsHighResScreen() ? 1.5 : 2;
38 } 37 }
39 // Corner radius for the header line view. 38 // Corner radius for the header line view.
40 NS_INLINE CGFloat HeaderLineRadius() { 39 NS_INLINE CGFloat HeaderLineRadius() {
41 return HeaderLineWidth() / 2.0; 40 return HeaderLineWidth() / 2.0;
42 } 41 }
43 } 42 }
44 43
45 @implementation TabHistoryCell { 44 @implementation TabHistoryCell
46 CRWSessionEntry* _entry; 45
47 UILabel* _titleLabel; 46 @synthesize item = _item;
48 } 47 @synthesize titleLabel = _titleLabel;
49 48
50 - (instancetype)initWithFrame:(CGRect)frame { 49 - (instancetype)initWithFrame:(CGRect)frame {
51 self = [super initWithFrame:frame]; 50 self = [super initWithFrame:frame];
52 if (self) 51 if (self)
53 [self commonInitialization]; 52 [self commonInitialization];
54 53
55 return self; 54 return self;
56 } 55 }
57 56
58 - (instancetype)initWithCoder:(NSCoder*)coder { 57 - (instancetype)initWithCoder:(NSCoder*)coder {
59 self = [super initWithCoder:coder]; 58 self = [super initWithCoder:coder];
60 if (self) 59 if (self)
61 [self commonInitialization]; 60 [self commonInitialization];
62 61
63 return self; 62 return self;
64 } 63 }
65 64
66 - (void)commonInitialization { 65 - (void)commonInitialization {
67 _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; 66 _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
68 [_titleLabel setTextColor:UIColorFromRGB(kTitleTextRGB)]; 67 [_titleLabel setTextColor:UIColorFromRGB(kTitleTextRGB)];
69 [_titleLabel 68 [_titleLabel
70 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]]; 69 setFont:[[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]];
71 [[self contentView] addSubview:_titleLabel]; 70 [[self contentView] addSubview:_titleLabel];
72 } 71 }
73 72
74 - (void)layoutSubviews { 73 - (void)layoutSubviews {
75 [super layoutSubviews]; 74 [super layoutSubviews];
76 75 self.titleLabel.frame =
77 CGRect bounds = [[self contentView] bounds]; 76 AlignRectOriginAndSizeToPixels(self.contentView.bounds);
78 CGRect frame = AlignRectOriginAndSizeToPixels(bounds);
79 [_titleLabel setFrame:frame];
80 } 77 }
81 78
82 - (CRWSessionEntry*)entry { 79 #pragma mark Accessors
83 return _entry;
84 }
85 80
86 - (void)setEntry:(CRWSessionEntry*)entry { 81 - (void)setItem:(const web::NavigationItem*)item {
87 _entry = entry; 82 _item = item;
88 83
89 NSString* title = nil; 84 self.titleLabel.text =
90 web::NavigationItem* navigationItem = [_entry navigationItem]; 85 _item ? base::SysUTF16ToNSString(_item->GetTitleForDisplay()) : nil;
91 if (navigationItem) { 86 [self setAccessibilityLabel:self.titleLabel.text];
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];
101 [self setNeedsLayout]; 87 [self setNeedsLayout];
102 } 88 }
103 89
104 - (UILabel*)titleLabel { 90 #pragma mark UICollectionViewCell
105 return _titleLabel;
106 }
107 91
108 - (void)prepareForReuse { 92 - (void)prepareForReuse {
109 [super prepareForReuse]; 93 [super prepareForReuse];
110 _entry = nil; 94 self.item = nullptr;
111 [_titleLabel setText:nil];
112 [self setAccessibilityLabel:nil];
113 } 95 }
114 96
115 @end 97 @end
116 98
117 @implementation TabHistorySectionHeader { 99 @implementation TabHistorySectionHeader
118 UIImageView* _iconView;
119 UIView* _lineView;
120 }
121 100
122 - (UIImageView*)iconView { 101 @synthesize iconView = _iconView;
123 return _iconView; 102 @synthesize lineView = _lineView;
124 }
125
126 - (UIView*)lineView {
127 return _lineView;
128 }
129 103
130 - (instancetype)initWithFrame:(CGRect)frame { 104 - (instancetype)initWithFrame:(CGRect)frame {
131 self = [super initWithFrame:frame]; 105 self = [super initWithFrame:frame];
132 if (self) { 106 if (self) {
133 CGRect iconFrame = CGRectMake(0, 0, kSiteIconViewWidth, kSiteIconViewWidth); 107 CGRect iconFrame = CGRectMake(0, 0, kSiteIconViewWidth, kSiteIconViewWidth);
134 _iconView = [[UIImageView alloc] initWithFrame:iconFrame]; 108 _iconView = [[UIImageView alloc] initWithFrame:iconFrame];
135 [self addSubview:_iconView]; 109 [self addSubview:_iconView];
136 110
137 UIColor* lineColor = UIColorFromRGB(kHeaderLineRGB);
138
139 _lineView = [[UIView alloc] initWithFrame:CGRectZero]; 111 _lineView = [[UIView alloc] initWithFrame:CGRectZero];
140 [[_lineView layer] setCornerRadius:HeaderLineRadius()]; 112 _lineView.layer.cornerRadius = HeaderLineRadius();
141 [_lineView setBackgroundColor:lineColor]; 113 _lineView.backgroundColor = UIColorFromRGB(kHeaderLineRGB);
142 [self addSubview:_lineView]; 114 [self addSubview:_lineView];
143 } 115 }
144 116
145 return self; 117 return self;
146 } 118 }
147 119
120 #pragma mark UIView
121
148 - (void)layoutSubviews { 122 - (void)layoutSubviews {
149 [super layoutSubviews]; 123 [super layoutSubviews];
150 124
151 CGRect bounds = 125 CGRect bounds =
152 CGRectInset([self bounds], kHeaderHorizontalInset, kHeaderVerticalInset); 126 CGRectInset([self bounds], kHeaderHorizontalInset, kHeaderVerticalInset);
153 127
154 CGRect iconViewFrame = AlignRectToPixel(bounds); 128 CGRect iconViewFrame = AlignRectToPixel(bounds);
155 iconViewFrame.size = CGSizeMake(kSiteIconViewWidth, kSiteIconViewWidth); 129 iconViewFrame.size = CGSizeMake(kSiteIconViewWidth, kSiteIconViewWidth);
156 [_iconView setFrame:iconViewFrame]; 130 self.iconView.frame = iconViewFrame;
157 131
158 CGFloat iconViewMaxY = CGRectGetMaxY(iconViewFrame); 132 CGFloat iconViewMaxY = CGRectGetMaxY(iconViewFrame);
159 CGFloat height = 133 CGFloat height =
160 CGRectGetHeight(bounds) - iconViewMaxY + kHeaderHeightAdjustment; 134 CGRectGetHeight(bounds) - iconViewMaxY + kHeaderHeightAdjustment;
161 if (height < 0) 135 if (height < 0)
162 height = 0; 136 height = 0;
163 137
164 CGRect lineViewFrame = CGRectZero; 138 CGRect lineViewFrame = CGRectZero;
165 lineViewFrame.origin.x = CGRectGetMidX(bounds) - HeaderLineWidth() / 2.0; 139 lineViewFrame.origin.x = CGRectGetMidX(bounds) - HeaderLineWidth() / 2.0;
166 lineViewFrame.origin.y = iconViewMaxY + kLineViewTopMargin; 140 lineViewFrame.origin.y = iconViewMaxY + kLineViewTopMargin;
167 lineViewFrame.size.width = HeaderLineWidth(); 141 lineViewFrame.size.width = HeaderLineWidth();
168 lineViewFrame.size.height = height; 142 lineViewFrame.size.height = height;
169 lineViewFrame = AlignRectOriginAndSizeToPixels(lineViewFrame); 143 lineViewFrame = AlignRectOriginAndSizeToPixels(lineViewFrame);
170 144 self.lineView.frame = lineViewFrame;
171 [_lineView setFrame:lineViewFrame];
172 } 145 }
173 146
174 @end 147 @end
175 148
176 @implementation TabHistorySectionFooter 149 @implementation TabHistorySectionFooter
177 150
178 - (instancetype)initWithFrame:(CGRect)frame { 151 - (instancetype)initWithFrame:(CGRect)frame {
179 self = [super initWithFrame:frame]; 152 self = [super initWithFrame:frame];
180 if (self) 153 if (self)
181 [self setBackgroundColor:UIColorFromRGB(kFooterRGB)]; 154 self.backgroundColor = UIColorFromRGB(kFooterRGB);
182 155
183 return self; 156 return self;
184 } 157 }
185 158
186 @end 159 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/history/tab_history_cell.h ('k') | ios/chrome/browser/ui/history/tab_history_popup_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698