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

Side by Side Diff: ios/clean/chrome/browser/ui/tab_collection/tab_collection_tab_cell.mm

Issue 2967083002: [ios] TabCollectionTabCell to use SnapshotCache. (Closed)
Patch Set: Clean up Created 3 years, 5 months 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
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;
23 @property(nonatomic, strong) UILabel* titleLabel; 25 @property(nonatomic, strong) UILabel* titleLabel;
24 @property(nonatomic, strong) UIImageView* favicon; 26 @property(nonatomic, strong) UIImageView* favicon;
25 @property(nonatomic, strong) TabSwitcherButton* snapshotButton; 27 @property(nonatomic, strong) TabSwitcherButton* snapshotButton;
26 @end 28 @end
27 29
28 @implementation TabCollectionTabCell 30 @implementation TabCollectionTabCell
29 @synthesize item = _item; 31 @synthesize item = _item;
30 @dynamic titleLabel; 32 @dynamic titleLabel;
31 @dynamic favicon; 33 @dynamic favicon;
32 @dynamic snapshotButton; 34 @dynamic snapshotButton;
33 35
34 - (instancetype)initWithFrame:(CGRect)frame { 36 - (instancetype)initWithFrame:(CGRect)frame {
35 if ((self = [super initWithFrame:frame])) { 37 if ((self = [super initWithFrame:frame])) {
36 [self setupSelectedBackgroundView]; 38 [self setupSelectedBackgroundView];
37 } 39 }
38 return self; 40 return self;
39 } 41 }
40 42
41 #pragma mark - Properties 43 #pragma mark - Cell lifecycle
42 44
43 - (void)setItem:(TabCollectionItem*)item { 45 - (void)prepareForReuse {
46 [super prepareForReuse];
47 self.item = nil;
48 }
49
50 #pragma mark - Public methods
51
52 - (void)configureCell:(TabCollectionItem*)item
53 snapshotCache:(SnapshotCache*)snapshotCache {
44 DCHECK(item); 54 DCHECK(item);
45 _item = item; 55 self.item = item;
46 self.titleLabel.text = item.title; 56 self.titleLabel.text = item.title;
47 self.snapshotButton.accessibilityIdentifier = 57 self.snapshotButton.accessibilityIdentifier =
48 [NSString stringWithFormat:@"%@_button", item.title]; 58 [NSString stringWithFormat:@"%@_button", item.title];
49 self.contentView.accessibilityLabel = item.title; 59 self.contentView.accessibilityLabel = item.title;
50 self.favicon.image = NativeImage(IDR_IOS_OMNIBOX_HTTP); 60 self.favicon.image = NativeImage(IDR_IOS_OMNIBOX_HTTP);
61 __weak TabCollectionTabCell* weakSelf = self;
62 [snapshotCache
63 retrieveImageForSessionID:self.item.tabID
64 callback:^(UIImage* snapshot) {
65 // PLACEHOLDER: This operation will be cancellable.
66 if ([weakSelf.item.tabID isEqualToString:item.tabID]) {
67 [weakSelf.snapshotButton
68 setImage:snapshot
69 forState:UIControlStateNormal];
70 }
71 }];
51 } 72 }
52 73
53 #pragma mark - Private 74 #pragma mark - Private methods
54 75
55 - (void)setupSelectedBackgroundView { 76 - (void)setupSelectedBackgroundView {
56 self.selectedBackgroundView = [[UIView alloc] init]; 77 self.selectedBackgroundView = [[UIView alloc] init];
57 self.selectedBackgroundView.backgroundColor = [UIColor blackColor]; 78 self.selectedBackgroundView.backgroundColor = [UIColor blackColor];
58 79
59 UIView* border = [[UIView alloc] init]; 80 UIView* border = [[UIView alloc] init];
60 border.translatesAutoresizingMaskIntoConstraints = NO; 81 border.translatesAutoresizingMaskIntoConstraints = NO;
61 border.backgroundColor = [UIColor blackColor]; 82 border.backgroundColor = [UIColor blackColor];
62 border.layer.cornerRadius = kSelectedBorderCornerRadius; 83 border.layer.cornerRadius = kSelectedBorderCornerRadius;
63 border.layer.borderWidth = kSelectedBorderWidth; 84 border.layer.borderWidth = kSelectedBorderWidth;
64 border.layer.borderColor = self.tintColor.CGColor; 85 border.layer.borderColor = self.tintColor.CGColor;
65 [self.selectedBackgroundView addSubview:border]; 86 [self.selectedBackgroundView addSubview:border];
66 [NSLayoutConstraint activateConstraints:@[ 87 [NSLayoutConstraint activateConstraints:@[
67 [border.topAnchor 88 [border.topAnchor
68 constraintEqualToAnchor:self.selectedBackgroundView.topAnchor 89 constraintEqualToAnchor:self.selectedBackgroundView.topAnchor
69 constant:-kBorderMargin], 90 constant:-kBorderMargin],
70 [border.leadingAnchor 91 [border.leadingAnchor
71 constraintEqualToAnchor:self.selectedBackgroundView.leadingAnchor 92 constraintEqualToAnchor:self.selectedBackgroundView.leadingAnchor
72 constant:-kBorderMargin], 93 constant:-kBorderMargin],
73 [border.trailingAnchor 94 [border.trailingAnchor
74 constraintEqualToAnchor:self.selectedBackgroundView.trailingAnchor 95 constraintEqualToAnchor:self.selectedBackgroundView.trailingAnchor
75 constant:kBorderMargin], 96 constant:kBorderMargin],
76 [border.bottomAnchor 97 [border.bottomAnchor
77 constraintEqualToAnchor:self.selectedBackgroundView.bottomAnchor 98 constraintEqualToAnchor:self.selectedBackgroundView.bottomAnchor
78 constant:kBorderMargin] 99 constant:kBorderMargin]
79 ]]; 100 ]];
80 } 101 }
81 102
82 @end 103 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698