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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ui/tab_switcher/tab_switcher_header_cell.mm
diff --git a/ios/chrome/browser/ui/tab_switcher/tab_switcher_header_cell.mm b/ios/chrome/browser/ui/tab_switcher/tab_switcher_header_cell.mm
new file mode 100644
index 0000000000000000000000000000000000000000..a45bad08526bc33ff52b73541ed44a0079bda545
--- /dev/null
+++ b/ios/chrome/browser/ui/tab_switcher/tab_switcher_header_cell.mm
@@ -0,0 +1,89 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_header_cell.h"
+
+#include "base/logging.h"
+#include "base/mac/scoped_nsobject.h"
+#import "ios/chrome/browser/ui/tab_switcher/tab_switcher_session_cell_data.h"
+#import "ios/chrome/browser/ui/uikit_ui_util.h"
+#import "ios/third_party/material_components_ios/src/components/Palettes/src/MaterialPalettes.h"
+#import "ios/third_party/material_components_ios/src/components/Typography/src/MaterialTypography.h"
+
+namespace {
+// View alpha value used when the header cell is not selected.
+const CGFloat kInactiveAlpha = 0.54;
+const CGFloat kImageViewWidth = 24;
+}
+
+@interface TabSwitcherHeaderCell () {
+ base::scoped_nsobject<UIImageView> _imageView;
+ base::scoped_nsobject<UILabel> _label;
+}
+@end
+
+@implementation TabSwitcherHeaderCell
+
+- (instancetype)initWithFrame:(CGRect)frame {
+ self = [super initWithFrame:frame];
+ if (self) {
+ self.backgroundColor = [[MDCPalette greyPalette] tint900];
+ [self loadSubviews];
+ [self setSelected:NO];
+ }
+ return self;
+}
+
++ (NSString*)identifier {
+ return @"TabSwitcherHeaderCell";
+}
+
+- (NSString*)reuseIdentifier {
+ return [[self class] identifier];
+}
+
+- (void)loadSessionCellData:(SessionCellData*)sessionCellData {
+ [_imageView setImage:sessionCellData.image];
+ [_label setText:sessionCellData.title];
+ [self setNeedsLayout];
+}
+
+- (void)setSelected:(BOOL)selected {
+ [super setSelected:selected];
+ [_imageView setAlpha:selected ? 1. : kInactiveAlpha];
+ [_label setAlpha:selected ? 1. : kInactiveAlpha];
+ [self setNeedsLayout];
+}
+
+#pragma mark - Private
+
+- (void)loadSubviews {
+ _imageView.reset([[UIImageView alloc] initWithFrame:CGRectZero]);
+ [_imageView setContentMode:UIViewContentModeCenter];
+ [_imageView setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [_imageView setTintColor:[UIColor whiteColor]];
+ _label.reset([[UILabel alloc] initWithFrame:CGRectZero]);
+ [_label setBackgroundColor:[UIColor clearColor]];
+ [_label setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [_label setTextColor:[UIColor whiteColor]];
+ [_label setFont:[MDCTypography body2Font]];
+
+ // Configure layout.
+ // The icon and the title are centered within |contentView|, have a spacing of
+ // one-third of icon width and the icon is on the leading side of title.
+ base::scoped_nsobject<UIStackView> stackView(
+ [[UIStackView alloc] initWithArrangedSubviews:@[ _imageView, _label ]]);
+ [stackView setSpacing:kImageViewWidth / 3];
+ [self.contentView addSubview:stackView];
+
+ [stackView setTranslatesAutoresizingMaskIntoConstraints:NO];
+ [NSLayoutConstraint activateConstraints:@[
+ [self.contentView.centerYAnchor
+ constraintEqualToAnchor:[stackView centerYAnchor]],
+ [self.contentView.centerXAnchor
+ constraintEqualToAnchor:[stackView centerXAnchor]]
+ ]];
+}
+
+@end

Powered by Google App Engine
This is Rietveld 408576698