Chromium Code Reviews| Index: ios/chrome/browser/ui/favicon_view.mm |
| diff --git a/ios/chrome/browser/ui/favicon_view.mm b/ios/chrome/browser/ui/favicon_view.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..efe315e72684d586a083d1ce0301aa497736dda1 |
| --- /dev/null |
| +++ b/ios/chrome/browser/ui/favicon_view.mm |
| @@ -0,0 +1,88 @@ |
| +// Copyright 2016 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/favicon_view.h" |
| + |
| +#include "base/mac/objc_property_releaser.h" |
| +#import "ios/chrome/browser/ui/uikit_ui_util.h" |
| + |
| +namespace { |
| +// Default corner radius for the favicon image view. |
| +const CGFloat kDefaultCornerRadius = 3; |
| +} |
| + |
| +@interface FaviconViewNew () { |
| + // Property releaser for FaviconViewNew. |
| + base::mac::ObjCPropertyReleaser _propertyReleaser_FaviconViewNew; |
| +} |
| + |
| +// Image view for the favicon. |
| +@property(nonatomic, retain) UIImageView* faviconImageView; |
| +// Label for fallback favicon placeholder. |
| +@property(nonatomic, retain) UILabel* faviconFallbackLabel; |
| + |
| +@end |
| + |
| +@implementation FaviconViewNew |
| +@synthesize faviconImageView = _faviconImageView; |
| +@synthesize faviconFallbackLabel = _faviconFallbackLabel; |
| + |
| ++ (CGFloat)defaultSize { |
| + return 24.0f; |
| +} |
| + |
| ++ (CGFloat)minSize { |
| + return 16.0f; |
| +} |
| + |
| +- (instancetype)initWithFrame:(CGRect)frame { |
| + self = [super initWithFrame:frame]; |
| + if (self) { |
| + _propertyReleaser_FaviconViewNew.Init(self, [FaviconViewNew class]); |
| + _faviconImageView = [[UIImageView alloc] initWithFrame:self.bounds]; |
| + _faviconImageView.clipsToBounds = YES; |
| + _faviconImageView.layer.cornerRadius = kDefaultCornerRadius; |
| + _faviconImageView.image = nil; |
| + |
| + _faviconFallbackLabel = [[UILabel alloc] initWithFrame:self.bounds]; |
| + _faviconFallbackLabel.backgroundColor = [UIColor clearColor]; |
| + _faviconFallbackLabel.textAlignment = NSTextAlignmentCenter; |
| + _faviconFallbackLabel.isAccessibilityElement = NO; |
| + _faviconFallbackLabel.clipsToBounds = YES; |
| + _faviconFallbackLabel.layer.cornerRadius = kDefaultCornerRadius; |
| + _faviconFallbackLabel.text = nil; |
| + |
| + [self addSubview:_faviconFallbackLabel]; |
| + [self addSubview:_faviconImageView]; |
| + |
| + [_faviconImageView setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| + [_faviconFallbackLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| + |
| + // Both image and fallback label are centered and match the size of favicon. |
| + AddSameCenterConstraints(_faviconImageView, _faviconFallbackLabel); |
| + AddSameSizeConstraint(_faviconFallbackLabel, self); |
|
Jackie Quinn
2016/09/23 23:11:01
I think we may still need to constrain the subview
stkhapugin
2016/09/26 15:51:36
You are right! I don't know why it even worked. Go
|
| + AddSameSizeConstraint(_faviconImageView, self); |
| + } |
| + return self; |
| +} |
| + |
| +- (void)configureWithAttribues:(FaviconAttributes* _Nonnull)attributes { |
| + if (attributes.faviconImage) { |
| + self.faviconImageView.image = attributes.faviconImage; |
| + self.faviconImageView.hidden = NO; |
| + self.faviconFallbackLabel.hidden = YES; |
| + } else { |
| + self.faviconFallbackLabel.backgroundColor = attributes.backgroundColor; |
| + self.faviconFallbackLabel.textColor = attributes.textColor; |
| + self.faviconFallbackLabel.text = attributes.monogramString; |
| + self.faviconFallbackLabel.hidden = NO; |
| + self.faviconImageView.hidden = YES; |
| + } |
| +} |
| + |
| +- (void)setFont:(UIFont* _Nonnull)font { |
| + self.faviconFallbackLabel.font = font; |
| +} |
| + |
| +@end |