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

Side by Side Diff: ios/chrome/browser/ui/favicon_view.mm

Issue 2361393004: Creates FaviconAttributesProvider. (Closed)
Patch Set: Created 4 years, 2 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #import "ios/chrome/browser/ui/favicon_view.h"
6
7 #include "base/mac/objc_property_releaser.h"
8 #import "ios/chrome/browser/ui/uikit_ui_util.h"
9
10 namespace {
11 // Default corner radius for the favicon image view.
12 const CGFloat kDefaultCornerRadius = 3;
13 }
14
15 @interface FaviconViewNew () {
16 // Property releaser for FaviconViewNew.
17 base::mac::ObjCPropertyReleaser _propertyReleaser_FaviconViewNew;
18 }
19
20 // Image view for the favicon.
21 @property(nonatomic, retain) UIImageView* faviconImageView;
22 // Label for fallback favicon placeholder.
23 @property(nonatomic, retain) UILabel* faviconFallbackLabel;
24
25 @end
26
27 @implementation FaviconViewNew
28 @synthesize faviconImageView = _faviconImageView;
29 @synthesize faviconFallbackLabel = _faviconFallbackLabel;
30
31 + (CGFloat)defaultSize {
32 return 24.0f;
33 }
34
35 + (CGFloat)minSize {
36 return 16.0f;
37 }
38
39 - (instancetype)initWithFrame:(CGRect)frame {
40 self = [super initWithFrame:frame];
41 if (self) {
42 _propertyReleaser_FaviconViewNew.Init(self, [FaviconViewNew class]);
43 _faviconImageView = [[UIImageView alloc] initWithFrame:self.bounds];
44 _faviconImageView.clipsToBounds = YES;
45 _faviconImageView.layer.cornerRadius = kDefaultCornerRadius;
46 _faviconImageView.image = nil;
47
48 _faviconFallbackLabel = [[UILabel alloc] initWithFrame:self.bounds];
49 _faviconFallbackLabel.backgroundColor = [UIColor clearColor];
50 _faviconFallbackLabel.textAlignment = NSTextAlignmentCenter;
51 _faviconFallbackLabel.isAccessibilityElement = NO;
52 _faviconFallbackLabel.clipsToBounds = YES;
53 _faviconFallbackLabel.layer.cornerRadius = kDefaultCornerRadius;
54 _faviconFallbackLabel.text = nil;
55
56 [self addSubview:_faviconFallbackLabel];
57 [self addSubview:_faviconImageView];
58
59 [_faviconImageView setTranslatesAutoresizingMaskIntoConstraints:NO];
60 [_faviconFallbackLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
61
62 // Both image and fallback label are centered and match the size of favicon.
63 AddSameCenterConstraints(_faviconImageView, _faviconFallbackLabel);
64 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
65 AddSameSizeConstraint(_faviconImageView, self);
66 }
67 return self;
68 }
69
70 - (void)configureWithAttribues:(FaviconAttributes* _Nonnull)attributes {
71 if (attributes.faviconImage) {
72 self.faviconImageView.image = attributes.faviconImage;
73 self.faviconImageView.hidden = NO;
74 self.faviconFallbackLabel.hidden = YES;
75 } else {
76 self.faviconFallbackLabel.backgroundColor = attributes.backgroundColor;
77 self.faviconFallbackLabel.textColor = attributes.textColor;
78 self.faviconFallbackLabel.text = attributes.monogramString;
79 self.faviconFallbackLabel.hidden = NO;
80 self.faviconImageView.hidden = YES;
81 }
82 }
83
84 - (void)setFont:(UIFont* _Nonnull)font {
85 self.faviconFallbackLabel.font = font;
86 }
87
88 @end
OLDNEW
« ios/chrome/browser/ui/favicon_view.h ('K') | « ios/chrome/browser/ui/favicon_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698