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

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

Issue 2787503002: Move FaviconAttributes to UI (Closed)
Patch Set: Add blank line Created 3 years, 8 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') | ios/chrome/browser/ui/reading_list/BUILD.gn » ('j') | 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 #import "ios/chrome/browser/ui/uikit_ui_util.h"
8
9 #if !defined(__has_feature) || !__has_feature(objc_arc)
10 #error "This file requires ARC support."
11 #endif
12
13 namespace {
14 // Default corner radius for the favicon image view.
15 const CGFloat kDefaultCornerRadius = 3;
16 }
17
18 @interface FaviconViewNew () {
19 // Property releaser for FaviconViewNew.
20 }
21
22 // Image view for the favicon.
23 @property(nonatomic, strong) UIImageView* faviconImageView;
24 // Label for fallback favicon placeholder.
25 @property(nonatomic, strong) UILabel* faviconFallbackLabel;
26
27 @end
28
29 @implementation FaviconViewNew
30 @synthesize faviconImageView = _faviconImageView;
31 @synthesize faviconFallbackLabel = _faviconFallbackLabel;
32
33 - (instancetype)initWithFrame:(CGRect)frame {
34 self = [super initWithFrame:frame];
35 if (self) {
36 _faviconImageView = [[UIImageView alloc] initWithFrame:self.bounds];
37 _faviconImageView.clipsToBounds = YES;
38 _faviconImageView.layer.cornerRadius = kDefaultCornerRadius;
39 _faviconImageView.image = nil;
40
41 _faviconFallbackLabel = [[UILabel alloc] initWithFrame:self.bounds];
42 _faviconFallbackLabel.backgroundColor = [UIColor clearColor];
43 _faviconFallbackLabel.textAlignment = NSTextAlignmentCenter;
44 _faviconFallbackLabel.isAccessibilityElement = NO;
45 _faviconFallbackLabel.clipsToBounds = YES;
46 _faviconFallbackLabel.layer.cornerRadius = kDefaultCornerRadius;
47 _faviconFallbackLabel.text = nil;
48
49 [self addSubview:_faviconFallbackLabel];
50 [self addSubview:_faviconImageView];
51
52 [_faviconImageView setTranslatesAutoresizingMaskIntoConstraints:NO];
53 [_faviconFallbackLabel setTranslatesAutoresizingMaskIntoConstraints:NO];
54
55 // Both image and fallback label are centered and match the size of favicon.
56 AddSameCenterConstraints(_faviconImageView, self);
57 AddSameCenterConstraints(_faviconFallbackLabel, self);
58 AddSameSizeConstraint(_faviconFallbackLabel, self);
59 AddSameSizeConstraint(_faviconImageView, self);
60 }
61 return self;
62 }
63
64 - (void)configureWithAttributes:(FaviconAttributes*)attributes {
65 if (attributes.faviconImage) {
66 self.faviconImageView.image = attributes.faviconImage;
67 self.faviconImageView.hidden = NO;
68 self.faviconFallbackLabel.hidden = YES;
69 } else {
70 self.faviconFallbackLabel.backgroundColor = attributes.backgroundColor;
71 self.faviconFallbackLabel.textColor = attributes.textColor;
72 self.faviconFallbackLabel.text = attributes.monogramString;
73 self.faviconFallbackLabel.hidden = NO;
74 self.faviconImageView.hidden = YES;
75 }
76 }
77
78 - (void)setFont:(UIFont*)font {
79 self.faviconFallbackLabel.font = font;
80 }
81
82 #pragma mark - UIView
83
84 - (CGSize)intrinsicContentSize {
85 return CGSizeMake(kFaviconPreferredSize, kFaviconPreferredSize);
86 }
87
88 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/favicon_view.h ('k') | ios/chrome/browser/ui/reading_list/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698