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_panel_cell.h" | 5 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_panel_cell.h" |
6 | 6 |
7 #include "base/mac/scoped_nsobject.h" | 7 #include "base/mac/scoped_nsobject.h" |
8 #import "ios/chrome/browser/tabs/tab.h" | 8 #import "ios/chrome/browser/tabs/tab.h" |
9 #import "ios/chrome/browser/ui/fade_truncated_label.h" | 9 #import "ios/chrome/browser/ui/fade_truncated_label.h" |
10 #import "ios/chrome/browser/ui/image_util.h" | 10 #import "ios/chrome/browser/ui/image_util.h" |
11 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_button.h" | 11 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_button.h" |
12 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_cache.h" | 12 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_cache.h" |
13 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_utils.h" | 13 #import "ios/chrome/browser/ui/tab_switcher/tab_switcher_utils.h" |
14 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 14 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
15 #include "ios/chrome/grit/ios_strings.h" | 15 #include "ios/chrome/grit/ios_strings.h" |
16 #include "ios/chrome/grit/ios_theme_resources.h" | 16 #include "ios/chrome/grit/ios_theme_resources.h" |
17 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 17 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
18 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" | 18 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
19 #import "ios/third_party/material_text_accessibility_ios/src/src/MDFTextAccessib
ility.h" | 19 #import "ios/third_party/material_text_accessibility_ios/src/src/MDFTextAccessib
ility.h" |
20 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/base/resource/resource_bundle.h" | |
22 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
23 #include "url/gurl.h" | 22 #include "url/gurl.h" |
24 | 23 |
25 namespace gfx { | 24 namespace gfx { |
26 class ImageSkia; | 25 class ImageSkia; |
27 } | 26 } |
28 | 27 |
29 namespace { | 28 namespace { |
30 const CGFloat kFontSize = 16; | 29 const CGFloat kFontSize = 16; |
31 const CGFloat kCellCornerRadius = 2; | 30 const CGFloat kCellCornerRadius = 2; |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 _snapshotButton.reset([[TabSwitcherButton alloc] initWithFrame:CGRectZero]); | 128 _snapshotButton.reset([[TabSwitcherButton alloc] initWithFrame:CGRectZero]); |
130 [_snapshotButton setTranslatesAutoresizingMaskIntoConstraints:NO]; | 129 [_snapshotButton setTranslatesAutoresizingMaskIntoConstraints:NO]; |
131 [_snapshotButton addTarget:self | 130 [_snapshotButton addTarget:self |
132 action:@selector(snapshotPressed) | 131 action:@selector(snapshotPressed) |
133 forControlEvents:UIControlEventTouchUpInside]; | 132 forControlEvents:UIControlEventTouchUpInside]; |
134 [[self containerView] addSubview:_snapshotButton]; | 133 [[self containerView] addSubview:_snapshotButton]; |
135 | 134 |
136 // Shadow view. | 135 // Shadow view. |
137 _shadow.reset([[UIImageView alloc] initWithFrame:CGRectZero]); | 136 _shadow.reset([[UIImageView alloc] initWithFrame:CGRectZero]); |
138 [_shadow setTranslatesAutoresizingMaskIntoConstraints:NO]; | 137 [_shadow setTranslatesAutoresizingMaskIntoConstraints:NO]; |
139 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 138 [_shadow setImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW)]; |
140 gfx::Image shadow = rb.GetNativeImageNamed(IDR_IOS_TOOLBAR_SHADOW); | |
141 [_shadow setImage:shadow.ToUIImage()]; | |
142 [[self containerView] addSubview:_shadow]; | 139 [[self containerView] addSubview:_shadow]; |
143 | 140 |
144 // Constraints on the Top bar, snapshot view, and shadow view. | 141 // Constraints on the Top bar, snapshot view, and shadow view. |
145 NSDictionary* viewsDictionary = @{ | 142 NSDictionary* viewsDictionary = @{ |
146 @"bar" : _topBar.get(), | 143 @"bar" : _topBar.get(), |
147 @"shadow" : _shadow.get(), | 144 @"shadow" : _shadow.get(), |
148 @"snapshot" : _snapshot.get(), | 145 @"snapshot" : _snapshot.get(), |
149 @"snapshotButton" : _snapshotButton.get(), | 146 @"snapshotButton" : _snapshotButton.get(), |
150 }; | 147 }; |
151 NSArray* constraints = @[ | 148 NSArray* constraints = @[ |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 DCHECK(!ImageHasAlphaChannel(image)); | 216 DCHECK(!ImageHasAlphaChannel(image)); |
220 [_snapshot setImage:image]; | 217 [_snapshot setImage:image]; |
221 } | 218 } |
222 | 219 |
223 - (void)setAppearanceForTab:(Tab*)tab cellSize:(CGSize)cellSize { | 220 - (void)setAppearanceForTab:(Tab*)tab cellSize:(CGSize)cellSize { |
224 [_titleLabel setText:tab.title]; | 221 [_titleLabel setText:tab.title]; |
225 [self contentView].accessibilityLabel = tab.title; | 222 [self contentView].accessibilityLabel = tab.title; |
226 if (tab.favicon) { | 223 if (tab.favicon) { |
227 [_favicon setImage:tab.favicon]; | 224 [_favicon setImage:tab.favicon]; |
228 } else { | 225 } else { |
229 // No favicon is available, use placeholder instead. | 226 [_favicon setImage:NativeImage(IDR_IOS_OMNIBOX_HTTP)]; |
230 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
231 [_favicon | |
232 setImage:rb.GetNativeImageNamed(IDR_IOS_OMNIBOX_HTTP).ToUIImage()]; | |
233 } | 227 } |
234 | 228 |
235 CGSize snapshotSize = cellSize; | 229 CGSize snapshotSize = cellSize; |
236 snapshotSize.height -= tabSwitcherLocalSessionCellTopBarHeight(); | 230 snapshotSize.height -= tabSwitcherLocalSessionCellTopBarHeight(); |
237 base::WeakNSObject<TabSwitcherLocalSessionCell> weakCell(self); | 231 base::WeakNSObject<TabSwitcherLocalSessionCell> weakCell(self); |
238 _currentPendingSnapshotRequest = | 232 _currentPendingSnapshotRequest = |
239 [[self cache] requestSnapshotForTab:tab | 233 [[self cache] requestSnapshotForTab:tab |
240 withSize:snapshotSize | 234 withSize:snapshotSize |
241 completionBlock:^(UIImage* image) { | 235 completionBlock:^(UIImage* image) { |
242 DCHECK([NSThread isMainThread]); | 236 DCHECK([NSThread isMainThread]); |
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 - (void)prepareForReuse { | 441 - (void)prepareForReuse { |
448 [_newTabIcon setAlpha:0]; | 442 [_newTabIcon setAlpha:0]; |
449 [_faviconObtainer cancel]; | 443 [_faviconObtainer cancel]; |
450 _faviconObtainer.reset(); | 444 _faviconObtainer.reset(); |
451 [_raisedButton setAlpha:0]; | 445 [_raisedButton setAlpha:0]; |
452 [_raisedButton resetState]; | 446 [_raisedButton resetState]; |
453 [super prepareForReuse]; | 447 [super prepareForReuse]; |
454 } | 448 } |
455 | 449 |
456 @end | 450 @end |
OLD | NEW |