| 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/history/favicon_view.h" | 5 #import "ios/chrome/browser/ui/history/favicon_view.h" |
| 6 | 6 |
| 7 #include "base/mac/objc_property_releaser.h" | |
| 8 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 7 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 9 | 8 |
| 9 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 10 #error "This file requires ARC support." |
| 11 #endif |
| 12 |
| 10 namespace { | 13 namespace { |
| 11 // Default corner radius for the favicon image view. | 14 // Default corner radius for the favicon image view. |
| 12 const CGFloat kDefaultCornerRadius = 3; | 15 const CGFloat kDefaultCornerRadius = 3; |
| 13 } | 16 } |
| 14 | 17 |
| 15 @interface FaviconView () { | 18 @interface FaviconView () { |
| 16 // Property releaser for FaviconView. | 19 // Property releaser for FaviconView. |
| 17 base::mac::ObjCPropertyReleaser _propertyReleaser_FaviconView; | |
| 18 } | 20 } |
| 19 // Size constraints for the favicon views. | 21 // Size constraints for the favicon views. |
| 20 @property(nonatomic, copy) NSArray* faviconSizeConstraints; | 22 @property(nonatomic, copy) NSArray* faviconSizeConstraints; |
| 21 @end | 23 @end |
| 22 | 24 |
| 23 @implementation FaviconView | 25 @implementation FaviconView |
| 24 | 26 |
| 25 @synthesize size = _size; | 27 @synthesize size = _size; |
| 26 @synthesize faviconImage = _faviconImage; | 28 @synthesize faviconImage = _faviconImage; |
| 27 @synthesize faviconFallbackLabel = _faviconFallbackLabel; | 29 @synthesize faviconFallbackLabel = _faviconFallbackLabel; |
| 28 @synthesize faviconSizeConstraints = _faviconSizeConstraints; | 30 @synthesize faviconSizeConstraints = _faviconSizeConstraints; |
| 29 | 31 |
| 30 - (instancetype)initWithFrame:(CGRect)frame { | 32 - (instancetype)initWithFrame:(CGRect)frame { |
| 31 self = [super initWithFrame:frame]; | 33 self = [super initWithFrame:frame]; |
| 32 if (self) { | 34 if (self) { |
| 33 _propertyReleaser_FaviconView.Init(self, [FaviconView class]); | |
| 34 _faviconImage = [[UIImageView alloc] init]; | 35 _faviconImage = [[UIImageView alloc] init]; |
| 35 _faviconImage.clipsToBounds = YES; | 36 _faviconImage.clipsToBounds = YES; |
| 36 _faviconImage.layer.cornerRadius = kDefaultCornerRadius; | 37 _faviconImage.layer.cornerRadius = kDefaultCornerRadius; |
| 37 _faviconImage.image = nil; | 38 _faviconImage.image = nil; |
| 38 | 39 |
| 39 _faviconFallbackLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 40 _faviconFallbackLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 40 _faviconFallbackLabel.backgroundColor = [UIColor clearColor]; | 41 _faviconFallbackLabel.backgroundColor = [UIColor clearColor]; |
| 41 _faviconFallbackLabel.textAlignment = NSTextAlignmentCenter; | 42 _faviconFallbackLabel.textAlignment = NSTextAlignmentCenter; |
| 42 _faviconFallbackLabel.isAccessibilityElement = NO; | 43 _faviconFallbackLabel.isAccessibilityElement = NO; |
| 43 _faviconFallbackLabel.text = nil; | 44 _faviconFallbackLabel.text = nil; |
| 44 | 45 |
| 45 [self addSubview:_faviconImage]; | 46 [self addSubview:_faviconImage]; |
| 46 [self addSubview:_faviconFallbackLabel]; | 47 [self addSubview:_faviconFallbackLabel]; |
| 47 | 48 |
| 48 [_faviconImage setTranslatesAutoresizingMaskIntoConstraints:NO]; | 49 [_faviconImage setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 49 [_faviconFallbackLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; | 50 [_faviconFallbackLabel setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 50 AddSameCenterConstraints(_faviconImage, self); | 51 AddSameCenterConstraints(_faviconImage, self); |
| 51 AddSameSizeConstraint(_faviconImage, self); | 52 AddSameSizeConstraint(_faviconImage, self); |
| 52 AddSameCenterConstraints(_faviconFallbackLabel, self); | 53 AddSameCenterConstraints(_faviconFallbackLabel, self); |
| 53 AddSameSizeConstraint(_faviconFallbackLabel, self); | 54 AddSameSizeConstraint(_faviconFallbackLabel, self); |
| 54 _faviconSizeConstraints = [@[ | 55 _faviconSizeConstraints = @[ |
| 55 [self.widthAnchor constraintEqualToConstant:0], | 56 [self.widthAnchor constraintEqualToConstant:0], |
| 56 [self.heightAnchor constraintEqualToConstant:0], | 57 [self.heightAnchor constraintEqualToConstant:0], |
| 57 ] retain]; | 58 ]; |
| 58 [NSLayoutConstraint activateConstraints:_faviconSizeConstraints]; | 59 [NSLayoutConstraint activateConstraints:_faviconSizeConstraints]; |
| 59 } | 60 } |
| 60 return self; | 61 return self; |
| 61 } | 62 } |
| 62 | 63 |
| 63 - (void)setSize:(CGFloat)size { | 64 - (void)setSize:(CGFloat)size { |
| 64 _size = size; | 65 _size = size; |
| 65 for (NSLayoutConstraint* constraint in self.faviconSizeConstraints) { | 66 for (NSLayoutConstraint* constraint in self.faviconSizeConstraints) { |
| 66 constraint.constant = size; | 67 constraint.constant = size; |
| 67 } | 68 } |
| 68 } | 69 } |
| 69 | 70 |
| 70 @end | 71 @end |
| OLD | NEW |