OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ntp/most_visited_cell.h" | 5 #import "ios/chrome/browser/ui/ntp/most_visited_cell.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #import "base/ios/weak_nsobject.h" | 9 #import "base/ios/weak_nsobject.h" |
10 #include "base/mac/bind_objc_block.h" | 10 #include "base/mac/bind_objc_block.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 const CGFloat kLabelTextColor = 0.314; | 39 const CGFloat kLabelTextColor = 0.314; |
40 const CGFloat kMaximumWidth = 73; | 40 const CGFloat kMaximumWidth = 73; |
41 const CGFloat kMaximumHeight = 100; | 41 const CGFloat kMaximumHeight = 100; |
42 | 42 |
43 @interface MostVisitedCell () { | 43 @interface MostVisitedCell () { |
44 // Backs property with the same name. | 44 // Backs property with the same name. |
45 GURL _URL; | 45 GURL _URL; |
46 // Weak reference to the relevant BrowserState. | 46 // Weak reference to the relevant BrowserState. |
47 ios::ChromeBrowserState* _browserState; | 47 ios::ChromeBrowserState* _browserState; |
48 // Backs property with the same name. | 48 // Backs property with the same name. |
49 ntp_tiles::metrics::MostVisitedTileType _tileType; | 49 ntp_tiles::TileVisualType _tileType; |
50 | 50 |
51 base::scoped_nsobject<UILabel> _label; | 51 base::scoped_nsobject<UILabel> _label; |
52 base::scoped_nsobject<UILabel> _noIconLabel; | 52 base::scoped_nsobject<UILabel> _noIconLabel; |
53 base::scoped_nsobject<UIImageView> _imageView; | 53 base::scoped_nsobject<UIImageView> _imageView; |
54 // Used to cancel tasks for the LargeIconService. | 54 // Used to cancel tasks for the LargeIconService. |
55 base::CancelableTaskTracker _cancelable_task_tracker; | 55 base::CancelableTaskTracker _cancelable_task_tracker; |
56 } | 56 } |
57 // Set the background color and center the first letter of the site title (or | 57 // Set the background color and center the first letter of the site title (or |
58 // domain if the title is a url). | 58 // domain if the title is a url). |
59 - (void)updateIconLabelWithColor:(UIColor*)textColor | 59 - (void)updateIconLabelWithColor:(UIColor*)textColor |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 } | 143 } |
144 | 144 |
145 - (void)showPlaceholder { | 145 - (void)showPlaceholder { |
146 [_imageView setBackgroundColor:[[MDCPalette greyPalette] tint50]]; | 146 [_imageView setBackgroundColor:[[MDCPalette greyPalette] tint50]]; |
147 } | 147 } |
148 | 148 |
149 - (void)setupWithURL:(GURL)URL | 149 - (void)setupWithURL:(GURL)URL |
150 title:(NSString*)title | 150 title:(NSString*)title |
151 browserState:(ios::ChromeBrowserState*)browserState { | 151 browserState:(ios::ChromeBrowserState*)browserState { |
152 _browserState = browserState; | 152 _browserState = browserState; |
153 _tileType = ntp_tiles::metrics::NONE; | 153 _tileType = ntp_tiles::TileVisualType::NONE; |
154 [self setText:title]; | 154 [self setText:title]; |
155 [self setURL:URL]; | 155 [self setURL:URL]; |
156 base::WeakNSObject<MostVisitedCell> weakSelf(self); | 156 base::WeakNSObject<MostVisitedCell> weakSelf(self); |
157 | 157 |
158 void (^faviconBlock)(const favicon_base::LargeIconResult&) = | 158 void (^faviconBlock)(const favicon_base::LargeIconResult&) = |
159 ^(const favicon_base::LargeIconResult& result) { | 159 ^(const favicon_base::LargeIconResult& result) { |
160 base::scoped_nsobject<MostVisitedCell> strongSelf([weakSelf retain]); | 160 base::scoped_nsobject<MostVisitedCell> strongSelf([weakSelf retain]); |
161 if (!strongSelf) | 161 if (!strongSelf) |
162 return; | 162 return; |
163 | 163 |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 #pragma mark - Private methods | 221 #pragma mark - Private methods |
222 | 222 |
223 - (void)updateIconLabelWithColor:(UIColor*)textColor | 223 - (void)updateIconLabelWithColor:(UIColor*)textColor |
224 backgroundColor:(UIColor*)backgroundColor | 224 backgroundColor:(UIColor*)backgroundColor |
225 isDefaultBackgroundColor:(BOOL)isDefaultBackgroundColor { | 225 isDefaultBackgroundColor:(BOOL)isDefaultBackgroundColor { |
226 [self setImage:nil]; | 226 [self setImage:nil]; |
227 [_noIconLabel | 227 [_noIconLabel |
228 setText:base::SysUTF16ToNSString(favicon::GetFallbackIconText(_URL))]; | 228 setText:base::SysUTF16ToNSString(favicon::GetFallbackIconText(_URL))]; |
229 [_noIconLabel setTextColor:textColor]; | 229 [_noIconLabel setTextColor:textColor]; |
230 [_imageView setBackgroundColor:backgroundColor]; | 230 [_imageView setBackgroundColor:backgroundColor]; |
231 _tileType = isDefaultBackgroundColor ? ntp_tiles::metrics::ICON_DEFAULT | 231 _tileType = isDefaultBackgroundColor ? ntp_tiles::TileVisualType::ICON_DEFAULT |
232 : ntp_tiles::metrics::ICON_COLOR; | 232 : ntp_tiles::TileVisualType::ICON_COLOR; |
233 } | 233 } |
234 | 234 |
235 - (void)setImage:(UIImage*)image { | 235 - (void)setImage:(UIImage*)image { |
236 [_imageView setBackgroundColor:nil]; | 236 [_imageView setBackgroundColor:nil]; |
237 [_noIconLabel setText:nil]; | 237 [_noIconLabel setText:nil]; |
238 [_imageView setImage:image]; | 238 [_imageView setImage:image]; |
239 _tileType = ntp_tiles::metrics::ICON_REAL; | 239 _tileType = ntp_tiles::TileVisualType::ICON_REAL; |
240 } | 240 } |
241 | 241 |
242 @end | 242 @end |
OLD | NEW |