| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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/tab_switcher/tab_switcher_header_cell.h" | 5 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_header_cell.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 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" | 8 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_session_cell_data.h" |
| 10 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 9 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 11 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 10 #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" | 11 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 13 | 12 |
| 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 14 #error "This file requires ARC support." |
| 15 #endif |
| 16 |
| 14 namespace { | 17 namespace { |
| 15 // View alpha value used when the header cell is not selected. | 18 // View alpha value used when the header cell is not selected. |
| 16 const CGFloat kInactiveAlpha = 0.54; | 19 const CGFloat kInactiveAlpha = 0.54; |
| 17 const CGFloat kImageViewWidth = 24; | 20 const CGFloat kImageViewWidth = 24; |
| 18 } | 21 } |
| 19 | 22 |
| 20 @interface TabSwitcherHeaderCell () { | 23 @interface TabSwitcherHeaderCell () { |
| 21 base::scoped_nsobject<UIImageView> _imageView; | 24 UIImageView* _imageView; |
| 22 base::scoped_nsobject<UILabel> _label; | 25 UILabel* _label; |
| 23 } | 26 } |
| 24 @end | 27 @end |
| 25 | 28 |
| 26 @implementation TabSwitcherHeaderCell | 29 @implementation TabSwitcherHeaderCell |
| 27 | 30 |
| 28 - (instancetype)initWithFrame:(CGRect)frame { | 31 - (instancetype)initWithFrame:(CGRect)frame { |
| 29 self = [super initWithFrame:frame]; | 32 self = [super initWithFrame:frame]; |
| 30 if (self) { | 33 if (self) { |
| 31 self.backgroundColor = [[MDCPalette greyPalette] tint900]; | 34 self.backgroundColor = [[MDCPalette greyPalette] tint900]; |
| 32 [self loadSubviews]; | 35 [self loadSubviews]; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 52 - (void)setSelected:(BOOL)selected { | 55 - (void)setSelected:(BOOL)selected { |
| 53 [super setSelected:selected]; | 56 [super setSelected:selected]; |
| 54 [_imageView setAlpha:selected ? 1. : kInactiveAlpha]; | 57 [_imageView setAlpha:selected ? 1. : kInactiveAlpha]; |
| 55 [_label setAlpha:selected ? 1. : kInactiveAlpha]; | 58 [_label setAlpha:selected ? 1. : kInactiveAlpha]; |
| 56 [self setNeedsLayout]; | 59 [self setNeedsLayout]; |
| 57 } | 60 } |
| 58 | 61 |
| 59 #pragma mark - Private | 62 #pragma mark - Private |
| 60 | 63 |
| 61 - (void)loadSubviews { | 64 - (void)loadSubviews { |
| 62 _imageView.reset([[UIImageView alloc] initWithFrame:CGRectZero]); | 65 _imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; |
| 63 [_imageView setContentMode:UIViewContentModeCenter]; | 66 [_imageView setContentMode:UIViewContentModeCenter]; |
| 64 [_imageView setTranslatesAutoresizingMaskIntoConstraints:NO]; | 67 [_imageView setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 65 [_imageView setTintColor:[UIColor whiteColor]]; | 68 [_imageView setTintColor:[UIColor whiteColor]]; |
| 66 _label.reset([[UILabel alloc] initWithFrame:CGRectZero]); | 69 _label = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 67 [_label setBackgroundColor:[UIColor clearColor]]; | 70 [_label setBackgroundColor:[UIColor clearColor]]; |
| 68 [_label setTranslatesAutoresizingMaskIntoConstraints:NO]; | 71 [_label setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 69 [_label setTextColor:[UIColor whiteColor]]; | 72 [_label setTextColor:[UIColor whiteColor]]; |
| 70 [_label setFont:[MDCTypography body2Font]]; | 73 [_label setFont:[MDCTypography body2Font]]; |
| 71 | 74 |
| 72 // Configure layout. | 75 // Configure layout. |
| 73 // The icon and the title are centered within |contentView|, have a spacing of | 76 // 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. | 77 // one-third of icon width and the icon is on the leading side of title. |
| 75 base::scoped_nsobject<UIStackView> stackView( | 78 UIStackView* stackView = |
| 76 [[UIStackView alloc] initWithArrangedSubviews:@[ _imageView, _label ]]); | 79 [[UIStackView alloc] initWithArrangedSubviews:@[ _imageView, _label ]]; |
| 77 [stackView setSpacing:kImageViewWidth / 3]; | 80 [stackView setSpacing:kImageViewWidth / 3]; |
| 78 [self.contentView addSubview:stackView]; | 81 [self.contentView addSubview:stackView]; |
| 79 | 82 |
| 80 [stackView setTranslatesAutoresizingMaskIntoConstraints:NO]; | 83 [stackView setTranslatesAutoresizingMaskIntoConstraints:NO]; |
| 81 [NSLayoutConstraint activateConstraints:@[ | 84 [NSLayoutConstraint activateConstraints:@[ |
| 82 [self.contentView.centerYAnchor | 85 [self.contentView.centerYAnchor |
| 83 constraintEqualToAnchor:[stackView centerYAnchor]], | 86 constraintEqualToAnchor:[stackView centerYAnchor]], |
| 84 [self.contentView.centerXAnchor | 87 [self.contentView.centerXAnchor |
| 85 constraintEqualToAnchor:[stackView centerXAnchor]] | 88 constraintEqualToAnchor:[stackView centerXAnchor]] |
| 86 ]]; | 89 ]]; |
| 87 } | 90 } |
| 88 | 91 |
| 89 @end | 92 @end |
| OLD | NEW |