Chromium Code Reviews| Index: ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_tile.mm |
| diff --git a/ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_tile.mm b/ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_tile.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..f6aa0980f1d950c5dd69e794d526a638f200ef6b |
| --- /dev/null |
| +++ b/ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_tile.mm |
| @@ -0,0 +1,96 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "ios/chrome/browser/ui/content_suggestions/cells/content_suggestions_most_visited_tile.h" |
| + |
| +#import "ios/chrome/browser/ui/favicon/favicon_attributes.h" |
| +#import "ios/chrome/browser/ui/favicon/favicon_view.h" |
| +#import "ios/chrome/browser/ui/uikit_ui_util.h" |
| +#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +namespace { |
| +const CGFloat kLabelTextColor = 0.314; |
| +const NSInteger kLabelNumLines = 2; |
| +const CGFloat kFaviconSize = 48; |
| +const CGFloat kSpaceFaviconTitle = 10; |
| + |
| +// Size of the tile. |
| +const CGFloat kWidth = 73; |
| +const CGFloat kHeight = 100; |
| +} |
| + |
| +@interface ContentSuggestionsMostVisitedTile () |
| + |
| +@property(nonatomic, strong) UILabel* title; |
| + |
| +@end |
| + |
| +@implementation ContentSuggestionsMostVisitedTile |
| + |
| ++ (NSInteger)width { |
| + return kWidth; |
| +} |
| + |
| ++ (ContentSuggestionsMostVisitedTile*)tileWithTitle:(NSString*)title |
| + attributes: |
| + (FaviconAttributes*)attributes { |
| + ContentSuggestionsMostVisitedTile* tile = |
| + [[ContentSuggestionsMostVisitedTile alloc] init]; |
| + [tile.faviconView configureWithAttributes:attributes]; |
| + [tile setText:title]; |
| + return tile; |
| +} |
| + |
| +@synthesize title = _title; |
|
lpromero
2017/04/07 10:58:22
Nit: Move these before the class methods.
gambard
2017/04/07 14:47:22
Done.
|
| +@synthesize faviconView = _faviconView; |
| + |
| +- (instancetype)initWithFrame:(CGRect)frame { |
| + self = [super initWithFrame:frame]; |
| + if (self) { |
| + _title = [[UILabel alloc] init]; |
| + _title.textColor = [UIColor colorWithWhite:kLabelTextColor alpha:1.0]; |
| + _title.font = [MDCTypography captionFont]; |
| + _title.textAlignment = NSTextAlignmentCenter; |
| + _title.preferredMaxLayoutWidth = kWidth; |
|
lpromero
2017/04/07 10:58:22
Should you reuse [[self class] width]?
gambard
2017/04/07 14:47:22
Done.
|
| + _title.numberOfLines = kLabelNumLines; |
| + |
| + _faviconView = [[FaviconViewNew alloc] init]; |
| + _faviconView.font = |
| + [[MDCTypography fontLoader] regularFontOfSize:kFaviconSize / 2]; |
|
stkhapugin
2017/04/07 11:15:18
This looks weird to me: you're determining the fon
gambard
2017/04/07 14:47:22
Done.
|
| + |
| + _title.translatesAutoresizingMaskIntoConstraints = NO; |
| + _faviconView.translatesAutoresizingMaskIntoConstraints = NO; |
| + |
| + [self addSubview:_title]; |
| + [self addSubview:_faviconView]; |
| + [NSLayoutConstraint activateConstraints:@[ |
| + [_faviconView.widthAnchor constraintEqualToConstant:kFaviconSize], |
|
stkhapugin
2017/04/07 11:15:18
Optional nit
You can instead modify your constrain
gambard
2017/04/07 14:47:22
I considered doing this but I don't like constrain
|
| + [_faviconView.heightAnchor |
| + constraintEqualToAnchor:_faviconView.widthAnchor], |
| + [_faviconView.centerXAnchor constraintEqualToAnchor:_title.centerXAnchor], |
| + [self.widthAnchor constraintEqualToConstant:kWidth], |
|
stkhapugin
2017/04/07 11:15:18
It is preferred to use -(CGSize)intrinsicContentSi
gambard
2017/04/07 14:47:22
Done.
|
| + [self.heightAnchor constraintEqualToConstant:kHeight], |
| + ]]; |
| + |
| + ApplyVisualConstraintsWithMetrics( |
| + @[ @"V:|[favicon]-(space)-[title]", @"H:|[title]|" ], |
| + @{ @"favicon" : _faviconView, |
| + @"title" : _title }, |
| + @{ @"space" : @(kSpaceFaviconTitle) }); |
| + |
| + self.isAccessibilityElement = YES; |
| + } |
| + return self; |
| +} |
| + |
| +- (void)setText:(NSString*)text { |
| + self.title.text = text; |
| + self.accessibilityLabel = text; |
| +} |
| + |
| +@end |