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

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

Issue 2361393004: Creates FaviconAttributesProvider. (Closed)
Patch Set: comments & typo 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
« no previous file with comments | « ios/chrome/browser/ui/favicon_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 - (instancetype)initWithFrame:(CGRect)frame {
32 self = [super initWithFrame:frame];
33 if (self) {
34 _propertyReleaser_FaviconViewNew.Init(self, [FaviconViewNew class]);
35 _faviconImageView = [[UIImageView alloc] initWithFrame:self.bounds];
36 _faviconImageView.clipsToBounds = YES;
37 _faviconImageView.layer.cornerRadius = kDefaultCornerRadius;
38 _faviconImageView.image = nil;
39
40 _faviconFallbackLabel = [[UILabel alloc] initWithFrame:self.bounds];
41 _faviconFallbackLabel.backgroundColor = [UIColor clearColor];
42 _faviconFallbackLabel.textAlignment = NSTextAlignmentCenter;
43 _faviconFallbackLabel.isAccessibilityElement = NO;
44 _faviconFallbackLabel.clipsToBounds = YES;
45 _faviconFallbackLabel.layer.cornerRadius = kDefaultCornerRadius;
46 _faviconFallbackLabel.text = nil;
47
48 [self addSubview:_faviconFallbackLabel];
49 [self addSubview:_faviconImageView];
50
51 [_faviconImageView setTranslatesAutoresizingMaskIntoConstraints:NO];
52 [_faviconFallbackLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
53
54 // Both image and fallback label are centered and match the size of favicon.
55 AddSameCenterConstraints(_faviconImageView, self);
56 AddSameCenterConstraints(_faviconFallbackLabel, self);
57 AddSameSizeConstraint(_faviconFallbackLabel, self);
58 AddSameSizeConstraint(_faviconImageView, self);
59 }
60 return self;
61 }
62
63 - (void)configureWithAttributes:(FaviconAttributes*)attributes {
64 if (attributes.faviconImage) {
65 self.faviconImageView.image = attributes.faviconImage;
66 self.faviconImageView.hidden = NO;
67 self.faviconFallbackLabel.hidden = YES;
68 } else {
69 self.faviconFallbackLabel.backgroundColor = attributes.backgroundColor;
70 self.faviconFallbackLabel.textColor = attributes.textColor;
71 self.faviconFallbackLabel.text = attributes.monogramString;
72 self.faviconFallbackLabel.hidden = NO;
73 self.faviconImageView.hidden = YES;
74 }
75 }
76
77 - (void)setFont:(UIFont*)font {
78 self.faviconFallbackLabel.font = font;
79 }
80
81 #pragma mark - UIView
82
83 - (CGSize)intrinsicContentSize {
84 return CGSizeMake(kFaviconPreferredSize, kFaviconPreferredSize);
85 }
86
87 @end
OLDNEW
« no previous file with comments | « 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