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

Side by Side Diff: ios/chrome/browser/ui/tab_switcher/tab_switcher_header_cell.mm

Issue 2588733002: Upstream Chrome on iOS source code [9/11]. (Closed)
Patch Set: Created 4 years 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 2015 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/tab_switcher/tab_switcher_header_cell.h"
6
7 #include "base/logging.h"
8 #include "base/mac/scoped_nsobject.h"
9 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_session_cell_data.h"
10 #import "ios/chrome/browser/ui/uikit_ui_util.h"
11 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
12 #import "ios/third_party/material_components_ios/src/components/Typography/src/M aterialTypography.h"
13
14 namespace {
15 // View alpha value used when the header cell is not selected.
16 const CGFloat kInactiveAlpha = 0.54;
17 const CGFloat kImageViewWidth = 24;
18 }
19
20 @interface TabSwitcherHeaderCell () {
21 base::scoped_nsobject<UIImageView> _imageView;
22 base::scoped_nsobject<UILabel> _label;
23 }
24 @end
25
26 @implementation TabSwitcherHeaderCell
27
28 - (instancetype)initWithFrame:(CGRect)frame {
29 self = [super initWithFrame:frame];
30 if (self) {
31 self.backgroundColor = [[MDCPalette greyPalette] tint900];
32 [self loadSubviews];
33 [self setSelected:NO];
34 }
35 return self;
36 }
37
38 + (NSString*)identifier {
39 return @"TabSwitcherHeaderCell";
40 }
41
42 - (NSString*)reuseIdentifier {
43 return [[self class] identifier];
44 }
45
46 - (void)loadSessionCellData:(SessionCellData*)sessionCellData {
47 [_imageView setImage:sessionCellData.image];
48 [_label setText:sessionCellData.title];
49 [self setNeedsLayout];
50 }
51
52 - (void)setSelected:(BOOL)selected {
53 [super setSelected:selected];
54 [_imageView setAlpha:selected ? 1. : kInactiveAlpha];
55 [_label setAlpha:selected ? 1. : kInactiveAlpha];
56 [self setNeedsLayout];
57 }
58
59 #pragma mark - Private
60
61 - (void)loadSubviews {
62 _imageView.reset([[UIImageView alloc] initWithFrame:CGRectZero]);
63 [_imageView setContentMode:UIViewContentModeCenter];
64 [_imageView setTranslatesAutoresizingMaskIntoConstraints:NO];
65 [_imageView setTintColor:[UIColor whiteColor]];
66 _label.reset([[UILabel alloc] initWithFrame:CGRectZero]);
67 [_label setBackgroundColor:[UIColor clearColor]];
68 [_label setTranslatesAutoresizingMaskIntoConstraints:NO];
69 [_label setTextColor:[UIColor whiteColor]];
70 [_label setFont:[MDCTypography body2Font]];
71
72 // Configure layout.
73 // The icon and the title are centered within |contentView|, have a spacing of
74 // one-third of icon width and the icon is on the leading side of title.
75 base::scoped_nsobject<UIStackView> stackView(
76 [[UIStackView alloc] initWithArrangedSubviews:@[ _imageView, _label ]]);
77 [stackView setSpacing:kImageViewWidth / 3];
78 [self.contentView addSubview:stackView];
79
80 [stackView setTranslatesAutoresizingMaskIntoConstraints:NO];
81 [NSLayoutConstraint activateConstraints:@[
82 [self.contentView.centerYAnchor
83 constraintEqualToAnchor:[stackView centerYAnchor]],
84 [self.contentView.centerXAnchor
85 constraintEqualToAnchor:[stackView centerXAnchor]]
86 ]];
87 }
88
89 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698