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

Side by Side Diff: ios/chrome/browser/ui/ntp/most_visited_cell.mm

Issue 2955363002: [ObjC ARC] Converts ios/chrome/browser/ui/ntp:ntp_internal to ARC. (Closed)
Patch Set: rebase Created 3 years, 5 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 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"
10 #include "base/mac/bind_objc_block.h" 9 #include "base/mac/bind_objc_block.h"
11 #import "base/mac/scoped_nsobject.h"
12 #include "base/memory/ref_counted_memory.h" 10 #include "base/memory/ref_counted_memory.h"
13 #include "base/strings/sys_string_conversions.h" 11 #include "base/strings/sys_string_conversions.h"
14 #include "components/favicon/core/fallback_url_util.h" 12 #include "components/favicon/core/fallback_url_util.h"
15 #import "ios/chrome/browser/ui/ntp/google_landing_data_source.h" 13 #import "ios/chrome/browser/ui/ntp/google_landing_data_source.h"
16 #import "ios/chrome/browser/ui/uikit_ui_util.h" 14 #import "ios/chrome/browser/ui/uikit_ui_util.h"
17 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" 15 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
18 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h" 16 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
19 17
18 #if !defined(__has_feature) || !__has_feature(objc_arc)
19 #error "This file requires ARC support."
20 #endif
21
20 const CGFloat kFaviconSize = 48; 22 const CGFloat kFaviconSize = 48;
21 const CGFloat kImageViewBackgroundColor = 0.941; 23 const CGFloat kImageViewBackgroundColor = 0.941;
22 const CGFloat kImageViewCornerRadius = 3; 24 const CGFloat kImageViewCornerRadius = 3;
23 const NSInteger kLabelNumLines = 2; 25 const NSInteger kLabelNumLines = 2;
24 const CGFloat kLabelTextColor = 0.314; 26 const CGFloat kLabelTextColor = 0.314;
25 const CGFloat kMaximumWidth = 73; 27 const CGFloat kMaximumWidth = 73;
26 const CGFloat kMaximumHeight = 100; 28 const CGFloat kMaximumHeight = 100;
27 29
28 @interface MostVisitedCell () { 30 @interface MostVisitedCell () {
29 // Backs property with the same name. 31 // Backs property with the same name.
30 GURL _URL; 32 GURL _URL;
31 // Weak reference to the relevant GoogleLandingDataSource. 33 // Weak reference to the relevant GoogleLandingDataSource.
32 base::WeakNSProtocol<id<GoogleLandingDataSource>> _dataSource; 34 __weak id<GoogleLandingDataSource> _dataSource;
33 // Backs property with the same name. 35 // Backs property with the same name.
34 ntp_tiles::TileVisualType _tileType; 36 ntp_tiles::TileVisualType _tileType;
35 37
36 base::scoped_nsobject<UILabel> _label; 38 UILabel* _label;
37 base::scoped_nsobject<UILabel> _noIconLabel; 39 UILabel* _noIconLabel;
38 base::scoped_nsobject<UIImageView> _imageView; 40 UIImageView* _imageView;
39 } 41 }
40 // Set the background color and center the first letter of the site title (or 42 // Set the background color and center the first letter of the site title (or
41 // domain if the title is a url). 43 // domain if the title is a url).
42 - (void)updateIconLabelWithColor:(UIColor*)textColor 44 - (void)updateIconLabelWithColor:(UIColor*)textColor
43 backgroundColor:(UIColor*)backgroundColor 45 backgroundColor:(UIColor*)backgroundColor
44 isDefaultBackgroundColor:(BOOL)isDefaultBackgroundColor; 46 isDefaultBackgroundColor:(BOOL)isDefaultBackgroundColor;
45 // Set icon of top site. 47 // Set icon of top site.
46 - (void)setImage:(UIImage*)image; 48 - (void)setImage:(UIImage*)image;
47 @end 49 @end
48 50
49 @implementation MostVisitedCell 51 @implementation MostVisitedCell
50 52
51 @synthesize URL = _URL; 53 @synthesize URL = _URL;
52 @synthesize tileType = _tileType; 54 @synthesize tileType = _tileType;
53 55
54 - (instancetype)initWithFrame:(CGRect)frame { 56 - (instancetype)initWithFrame:(CGRect)frame {
55 self = [super initWithFrame:frame]; 57 self = [super initWithFrame:frame];
56 if (!self) { 58 if (!self) {
57 return nil; 59 return nil;
58 } 60 }
59 _label.reset([[UILabel alloc] initWithFrame:CGRectZero]); 61 _label = [[UILabel alloc] initWithFrame:CGRectZero];
60 [_label setTextColor:[UIColor colorWithWhite:kLabelTextColor alpha:1.0]]; 62 [_label setTextColor:[UIColor colorWithWhite:kLabelTextColor alpha:1.0]];
61 [_label setBackgroundColor:[UIColor clearColor]]; 63 [_label setBackgroundColor:[UIColor clearColor]];
62 [_label setFont:[MDCTypography captionFont]]; 64 [_label setFont:[MDCTypography captionFont]];
63 [_label setTextAlignment:NSTextAlignmentCenter]; 65 [_label setTextAlignment:NSTextAlignmentCenter];
64 CGSize maxSize = [self.class maximumSize]; 66 CGSize maxSize = [self.class maximumSize];
65 [_label setPreferredMaxLayoutWidth:maxSize.width]; 67 [_label setPreferredMaxLayoutWidth:maxSize.width];
66 [_label setNumberOfLines:kLabelNumLines]; 68 [_label setNumberOfLines:kLabelNumLines];
67 69
68 _noIconLabel.reset([[UILabel alloc] initWithFrame:CGRectZero]); 70 _noIconLabel = [[UILabel alloc] initWithFrame:CGRectZero];
69 [_noIconLabel setBackgroundColor:[UIColor clearColor]]; 71 [_noIconLabel setBackgroundColor:[UIColor clearColor]];
70 [_noIconLabel setFont:[MDCTypography headlineFont]]; 72 [_noIconLabel setFont:[MDCTypography headlineFont]];
71 [_noIconLabel setTextAlignment:NSTextAlignmentCenter]; 73 [_noIconLabel setTextAlignment:NSTextAlignmentCenter];
72 74
73 _imageView.reset([[UIImageView alloc] initWithFrame:CGRectZero]); 75 _imageView = [[UIImageView alloc] initWithFrame:CGRectZero];
74 [_imageView layer].cornerRadius = kImageViewCornerRadius; 76 [_imageView layer].cornerRadius = kImageViewCornerRadius;
75 [_imageView setClipsToBounds:YES]; 77 [_imageView setClipsToBounds:YES];
76 [self addSubview:_imageView]; 78 [self addSubview:_imageView];
77 [self addSubview:_label]; 79 [self addSubview:_label];
78 [self addSubview:_noIconLabel]; 80 [self addSubview:_noIconLabel];
79 81
80 [_noIconLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; 82 [_noIconLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
81 [_imageView setTranslatesAutoresizingMaskIntoConstraints:NO]; 83 [_imageView setTranslatesAutoresizingMaskIntoConstraints:NO];
82 [_label setTranslatesAutoresizingMaskIntoConstraints:NO]; 84 [_label setTranslatesAutoresizingMaskIntoConstraints:NO];
83 85
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 [self setUserInteractionEnabled:YES]; 126 [self setUserInteractionEnabled:YES];
125 } 127 }
126 128
127 - (void)showPlaceholder { 129 - (void)showPlaceholder {
128 [_imageView setBackgroundColor:[[MDCPalette greyPalette] tint50]]; 130 [_imageView setBackgroundColor:[[MDCPalette greyPalette] tint50]];
129 } 131 }
130 132
131 - (void)setupWithURL:(GURL)URL 133 - (void)setupWithURL:(GURL)URL
132 title:(NSString*)title 134 title:(NSString*)title
133 dataSource:(id<GoogleLandingDataSource>)dataSource { 135 dataSource:(id<GoogleLandingDataSource>)dataSource {
134 _dataSource.reset(dataSource); 136 _dataSource = dataSource;
135 _tileType = ntp_tiles::TileVisualType::NONE; 137 _tileType = ntp_tiles::TileVisualType::NONE;
136 [self setText:title]; 138 [self setText:title];
137 [self setURL:URL]; 139 [self setURL:URL];
138 base::WeakNSObject<MostVisitedCell> weakSelf(self); 140 __weak MostVisitedCell* weakSelf = self;
139 141
140 void (^faviconImageBlock)(UIImage*) = ^(UIImage* favicon) { 142 void (^faviconImageBlock)(UIImage*) = ^(UIImage* favicon) {
141 143
142 if (URL == [weakSelf URL]) // Tile has not been reused. 144 if (URL == [weakSelf URL]) // Tile has not been reused.
143 [weakSelf setImage:favicon]; 145 [weakSelf setImage:favicon];
144 }; 146 };
145 147
146 void (^faviconFallbackBlock)(UIColor*, UIColor*, BOOL) = 148 void (^faviconFallbackBlock)(UIColor*, UIColor*, BOOL) =
147 ^(UIColor* textColor, UIColor* backgroundColor, BOOL isDefaultColor) { 149 ^(UIColor* textColor, UIColor* backgroundColor, BOOL isDefaultColor) {
148 if (URL == [weakSelf URL]) // Tile has not been reused. 150 if (URL == [weakSelf URL]) // Tile has not been reused.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 } 186 }
185 187
186 - (void)setImage:(UIImage*)image { 188 - (void)setImage:(UIImage*)image {
187 [_imageView setBackgroundColor:nil]; 189 [_imageView setBackgroundColor:nil];
188 [_noIconLabel setText:nil]; 190 [_noIconLabel setText:nil];
189 [_imageView setImage:image]; 191 [_imageView setImage:image];
190 _tileType = ntp_tiles::TileVisualType::ICON_REAL; 192 _tileType = ntp_tiles::TileVisualType::ICON_REAL;
191 } 193 }
192 194
193 @end 195 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/ntp/incognito_panel_controller.mm ('k') | ios/chrome/browser/ui/ntp/most_visited_layout.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698