Commit 5a38873c authored by Nazerke's avatar Nazerke Committed by Commit Bot

[ios] Add a TabStrip Cell.

This CL adds a TabStrip Cell.

Bug: 1128249, 1134075
Change-Id: I3a8d35c9467672edfdfa7693b4c13147e284bd40
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2440556Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Commit-Queue: Nazerke Kalidolda <nazerke@google.com>
Cr-Commit-Position: refs/heads/master@{#818932}
parent 9cad3c10
...@@ -21,6 +21,8 @@ source_set("tab_strip") { ...@@ -21,6 +21,8 @@ source_set("tab_strip") {
source_set("tab_strip_ui") { source_set("tab_strip_ui") {
configs += [ "//build/config/compiler:enable_arc" ] configs += [ "//build/config/compiler:enable_arc" ]
sources = [ sources = [
"tab_strip_cell.h",
"tab_strip_cell.mm",
"tab_strip_view_controller.h", "tab_strip_view_controller.h",
"tab_strip_view_controller.mm", "tab_strip_view_controller.mm",
"tab_strip_view_layout.h", "tab_strip_view_layout.h",
...@@ -29,6 +31,7 @@ source_set("tab_strip_ui") { ...@@ -29,6 +31,7 @@ source_set("tab_strip_ui") {
deps = [ deps = [
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/main:public", "//ios/chrome/browser/main:public",
"//ios/chrome/common/ui/colors",
] ]
frameworks = [ "UIKit.framework" ] frameworks = [ "UIKit.framework" ]
} }
// Copyright 2020 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.
#ifndef IOS_CHROME_BROWSER_UI_TAB_STRIP_TAB_STRIP_CELL_H_
#define IOS_CHROME_BROWSER_UI_TAB_STRIP_TAB_STRIP_CELL_H_
#import <UIKit/UIKit.h>
// UICollectionViewCell that contains a Tab title with a leading imageView
// and a close tab button.
@interface TabStripCell : UICollectionViewCell
@property(nonatomic, strong) UILabel* titleLabel;
@end
#endif // IOS_CHROME_BROWSER_UI_TAB_STRIP_TAB_STRIP_CELL_H_
// Copyright 2020 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_strip/tab_strip_cell.h"
#import "ios/chrome/common/ui/colors/semantic_color_names.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
namespace {
// Tab close button insets.
const CGFloat kTabBackgroundLeftCapInset = 34.0;
const CGFloat kFaviconInset = 28;
const CGFloat kTitleInset = 10.0;
} // namespace
@implementation TabStripCell
- (instancetype)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
NSString* imageName = @"tabstrip_background_tab";
UIImage* image = [UIImage imageNamed:imageName];
UIEdgeInsets insets =
UIEdgeInsetsMake(0, kTabBackgroundLeftCapInset, image.size.height + 1.0,
image.size.width - kTabBackgroundLeftCapInset + 1.0);
self.backgroundView = [[UIImageView alloc]
initWithImage:[image resizableImageWithCapInsets:insets]];
UIImage* favicon = [[UIImage imageNamed:@"default_world_favicon"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIImageView* faviconView = [[UIImageView alloc] initWithImage:favicon];
faviconView.tintColor = [UIColor colorNamed:kGrey500Color];
[self.contentView addSubview:faviconView];
faviconView.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
[faviconView.leadingAnchor
constraintEqualToAnchor:self.contentView.leadingAnchor
constant:kFaviconInset],
[faviconView.centerYAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor],
]];
UIImage* close = [[UIImage imageNamed:@"grid_cell_close_button"]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
UIButton* closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
[closeButton setImage:close forState:UIControlStateNormal];
closeButton.tintColor = [UIColor colorNamed:kGrey500Color];
[self.contentView addSubview:closeButton];
closeButton.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
[closeButton.trailingAnchor
constraintEqualToAnchor:self.contentView.trailingAnchor
constant:-kFaviconInset],
[closeButton.centerYAnchor
constraintEqualToAnchor:self.contentView.centerYAnchor],
]];
UILabel* titleLabel = [[UILabel alloc] init];
[self.contentView addSubview:titleLabel];
titleLabel.translatesAutoresizingMaskIntoConstraints = NO;
[NSLayoutConstraint activateConstraints:@[
[titleLabel.leadingAnchor
constraintEqualToAnchor:faviconView.trailingAnchor
constant:kTitleInset],
[titleLabel.trailingAnchor
constraintLessThanOrEqualToAnchor:closeButton.leadingAnchor
constant:-kTitleInset],
[titleLabel.centerYAnchor
constraintEqualToAnchor:faviconView.centerYAnchor],
]];
self.titleLabel = titleLabel;
}
return self;
}
- (void)prepareForReuse {
[super prepareForReuse];
self.titleLabel.text = nil;
}
@end
...@@ -13,6 +13,8 @@ ...@@ -13,6 +13,8 @@
#error "This file requires ARC support." #error "This file requires ARC support."
#endif #endif
@protocol TabStripContaining;
@implementation TabStripCoordinator @implementation TabStripCoordinator
#pragma mark - ChromeCoordinator #pragma mark - ChromeCoordinator
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#import "ios/chrome/browser/ui/tab_strip/tab_strip_view_controller.h" #import "ios/chrome/browser/ui/tab_strip/tab_strip_view_controller.h"
#import "ios/chrome/browser/ui/tab_strip/tab_strip_cell.h"
#import "ios/chrome/browser/ui/tab_strip/tab_strip_view_layout.h" #import "ios/chrome/browser/ui/tab_strip/tab_strip_view_layout.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -12,6 +13,10 @@ ...@@ -12,6 +13,10 @@
@implementation TabStripViewController @implementation TabStripViewController
namespace {
static NSString* const kReuseIdentifier = @"TabView";
} // namespace
- (instancetype)init { - (instancetype)init {
TabStripViewLayout* layout = [[TabStripViewLayout alloc] init]; TabStripViewLayout* layout = [[TabStripViewLayout alloc] init];
if (self = [super initWithCollectionViewLayout:layout]) { if (self = [super initWithCollectionViewLayout:layout]) {
...@@ -23,6 +28,22 @@ ...@@ -23,6 +28,22 @@
[super viewDidLoad]; [super viewDidLoad];
self.view.translatesAutoresizingMaskIntoConstraints = NO; self.view.translatesAutoresizingMaskIntoConstraints = NO;
self.collectionView.alwaysBounceHorizontal = YES; self.collectionView.alwaysBounceHorizontal = YES;
[self.collectionView registerClass:[TabStripCell class]
forCellWithReuseIdentifier:kReuseIdentifier];
}
- (NSInteger)numberOfSectionsInCollectionView:
(UICollectionView*)collectionView {
return 1;
}
- (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
cellForItemAtIndexPath:(NSIndexPath*)indexPath {
TabStripCell* cell = (TabStripCell*)[collectionView
dequeueReusableCellWithReuseIdentifier:kReuseIdentifier
forIndexPath:indexPath];
cell.titleLabel.text = nil;
return cell;
} }
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment