Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/clean/chrome/browser/ui/tab_collection/tab_collection_tab_cell.h" | 5 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_tab_cell.h" |
| 6 | 6 |
| 7 #import "ios/chrome/browser/snapshots/snapshot_cache.h" | |
| 7 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_button.h" | 8 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_button.h" |
| 8 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 9 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 9 #include "ios/chrome/grit/ios_theme_resources.h" | 10 #include "ios/chrome/grit/ios_theme_resources.h" |
| 10 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_item.h" | 11 #import "ios/clean/chrome/browser/ui/tab_collection/tab_collection_item.h" |
| 11 | 12 |
| 12 #if !defined(__has_feature) || !__has_feature(objc_arc) | 13 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 13 #error "This file requires ARC support." | 14 #error "This file requires ARC support." |
| 14 #endif | 15 #endif |
| 15 | 16 |
| 16 namespace { | 17 namespace { |
| 17 const CGFloat kBorderMargin = 6.0f; | 18 const CGFloat kBorderMargin = 6.0f; |
| 18 const CGFloat kSelectedBorderCornerRadius = 8.0f; | 19 const CGFloat kSelectedBorderCornerRadius = 8.0f; |
| 19 const CGFloat kSelectedBorderWidth = 4.0f; | 20 const CGFloat kSelectedBorderWidth = 4.0f; |
| 20 } | 21 } |
| 21 | 22 |
| 22 @interface TabCollectionTabCell () | 23 @interface TabCollectionTabCell () |
| 24 @property(nonatomic, strong) TabCollectionItem* item; | |
| 25 @property(nonatomic, strong) SnapshotCache* snapshotCache; | |
| 23 @property(nonatomic, strong) UILabel* titleLabel; | 26 @property(nonatomic, strong) UILabel* titleLabel; |
| 24 @property(nonatomic, strong) UIImageView* favicon; | 27 @property(nonatomic, strong) UIImageView* favicon; |
| 25 @property(nonatomic, strong) TabSwitcherButton* snapshotButton; | 28 @property(nonatomic, strong) TabSwitcherButton* snapshotButton; |
| 26 @end | 29 @end |
| 27 | 30 |
| 28 @implementation TabCollectionTabCell | 31 @implementation TabCollectionTabCell |
| 29 @synthesize item = _item; | 32 @synthesize item = _item; |
| 33 @synthesize snapshotCache = _snapshotCache; | |
| 30 @dynamic titleLabel; | 34 @dynamic titleLabel; |
| 31 @dynamic favicon; | 35 @dynamic favicon; |
| 32 @dynamic snapshotButton; | 36 @dynamic snapshotButton; |
| 33 | 37 |
| 34 - (instancetype)initWithFrame:(CGRect)frame { | 38 - (instancetype)initWithFrame:(CGRect)frame { |
| 35 if ((self = [super initWithFrame:frame])) { | 39 if ((self = [super initWithFrame:frame])) { |
| 36 [self setupSelectedBackgroundView]; | 40 [self setupSelectedBackgroundView]; |
| 37 } | 41 } |
| 38 return self; | 42 return self; |
| 39 } | 43 } |
| 40 | 44 |
| 41 #pragma mark - Properties | 45 #pragma mark - Cell lifecycle |
| 42 | 46 |
| 43 - (void)setItem:(TabCollectionItem*)item { | 47 - (void)prepareForReuse { |
| 48 [super prepareForReuse]; | |
| 49 self.item = nil; | |
| 50 self.snapshotCache = nil; | |
| 51 } | |
| 52 | |
| 53 #pragma mark - Public methods | |
| 54 | |
| 55 - (void)configureCell:(TabCollectionItem*)item | |
| 56 snapshotCache:(SnapshotCache*)snapshotCache { | |
| 44 DCHECK(item); | 57 DCHECK(item); |
| 45 _item = item; | 58 self.item = item; |
| 59 self.snapshotCache = snapshotCache; | |
| 46 self.titleLabel.text = item.title; | 60 self.titleLabel.text = item.title; |
| 47 self.snapshotButton.accessibilityIdentifier = | 61 self.snapshotButton.accessibilityIdentifier = |
| 48 [NSString stringWithFormat:@"%@_button", item.title]; | 62 [NSString stringWithFormat:@"%@_button", item.title]; |
| 49 self.contentView.accessibilityLabel = item.title; | 63 self.contentView.accessibilityLabel = item.title; |
| 50 self.favicon.image = NativeImage(IDR_IOS_OMNIBOX_HTTP); | 64 self.favicon.image = NativeImage(IDR_IOS_OMNIBOX_HTTP); |
| 65 __weak TabCollectionTabCell* weakSelf = self; | |
| 66 [self.snapshotCache | |
| 67 retrieveImageForSessionID:self.item.tabID | |
| 68 callback:^(UIImage* snapshot) { | |
| 69 DCHECK([NSThread isMainThread]); | |
|
marq (ping after 24h)
2017/07/06 12:41:17
This check shouldn't be needed; if the contract is
edchin
2017/07/06 14:47:18
Done.
| |
| 70 // PLACEHOLDER: This operation will be cancellable. | |
| 71 if ([weakSelf.item.tabID isEqualToString:item.tabID]) { | |
| 72 [weakSelf.snapshotButton | |
| 73 setImage:snapshot | |
| 74 forState:UIControlStateNormal]; | |
| 75 } | |
| 76 }]; | |
| 51 } | 77 } |
| 52 | 78 |
| 53 #pragma mark - Private | 79 #pragma mark - Private methods |
| 54 | 80 |
| 55 - (void)setupSelectedBackgroundView { | 81 - (void)setupSelectedBackgroundView { |
| 56 self.selectedBackgroundView = [[UIView alloc] init]; | 82 self.selectedBackgroundView = [[UIView alloc] init]; |
| 57 self.selectedBackgroundView.backgroundColor = [UIColor blackColor]; | 83 self.selectedBackgroundView.backgroundColor = [UIColor blackColor]; |
| 58 | 84 |
| 59 UIView* border = [[UIView alloc] init]; | 85 UIView* border = [[UIView alloc] init]; |
| 60 border.translatesAutoresizingMaskIntoConstraints = NO; | 86 border.translatesAutoresizingMaskIntoConstraints = NO; |
| 61 border.backgroundColor = [UIColor blackColor]; | 87 border.backgroundColor = [UIColor blackColor]; |
| 62 border.layer.cornerRadius = kSelectedBorderCornerRadius; | 88 border.layer.cornerRadius = kSelectedBorderCornerRadius; |
| 63 border.layer.borderWidth = kSelectedBorderWidth; | 89 border.layer.borderWidth = kSelectedBorderWidth; |
| 64 border.layer.borderColor = self.tintColor.CGColor; | 90 border.layer.borderColor = self.tintColor.CGColor; |
| 65 [self.selectedBackgroundView addSubview:border]; | 91 [self.selectedBackgroundView addSubview:border]; |
| 66 [NSLayoutConstraint activateConstraints:@[ | 92 [NSLayoutConstraint activateConstraints:@[ |
| 67 [border.topAnchor | 93 [border.topAnchor |
| 68 constraintEqualToAnchor:self.selectedBackgroundView.topAnchor | 94 constraintEqualToAnchor:self.selectedBackgroundView.topAnchor |
| 69 constant:-kBorderMargin], | 95 constant:-kBorderMargin], |
| 70 [border.leadingAnchor | 96 [border.leadingAnchor |
| 71 constraintEqualToAnchor:self.selectedBackgroundView.leadingAnchor | 97 constraintEqualToAnchor:self.selectedBackgroundView.leadingAnchor |
| 72 constant:-kBorderMargin], | 98 constant:-kBorderMargin], |
| 73 [border.trailingAnchor | 99 [border.trailingAnchor |
| 74 constraintEqualToAnchor:self.selectedBackgroundView.trailingAnchor | 100 constraintEqualToAnchor:self.selectedBackgroundView.trailingAnchor |
| 75 constant:kBorderMargin], | 101 constant:kBorderMargin], |
| 76 [border.bottomAnchor | 102 [border.bottomAnchor |
| 77 constraintEqualToAnchor:self.selectedBackgroundView.bottomAnchor | 103 constraintEqualToAnchor:self.selectedBackgroundView.bottomAnchor |
| 78 constant:kBorderMargin] | 104 constant:kBorderMargin] |
| 79 ]]; | 105 ]]; |
| 80 } | 106 } |
| 81 | 107 |
| 82 @end | 108 @end |
| OLD | NEW |