| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/bookmarks/bookmark_collection_view.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view.h" |
| 6 | 6 |
| 7 #import <UIKit/UIGestureRecognizerSubclass.h> | 7 #import <UIKit/UIGestureRecognizerSubclass.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| 11 | 11 |
| 12 #include "base/ios/weak_nsobject.h" |
| 12 #include "base/mac/bind_objc_block.h" | 13 #include "base/mac/bind_objc_block.h" |
| 13 #include "base/mac/foundation_util.h" | 14 #include "base/mac/foundation_util.h" |
| 15 #include "base/mac/objc_property_releaser.h" |
| 16 #include "base/mac/scoped_nsobject.h" |
| 14 #include "base/strings/sys_string_conversions.h" | 17 #include "base/strings/sys_string_conversions.h" |
| 15 #include "components/bookmarks/browser/bookmark_model.h" | 18 #include "components/bookmarks/browser/bookmark_model.h" |
| 16 #include "components/bookmarks/browser/bookmark_model_observer.h" | 19 #include "components/bookmarks/browser/bookmark_model_observer.h" |
| 17 #include "components/favicon/core/fallback_url_util.h" | 20 #include "components/favicon/core/fallback_url_util.h" |
| 18 #include "components/favicon/core/large_icon_service.h" | 21 #include "components/favicon/core/large_icon_service.h" |
| 19 #include "components/favicon_base/fallback_icon_style.h" | 22 #include "components/favicon_base/fallback_icon_style.h" |
| 20 #include "components/favicon_base/favicon_types.h" | 23 #include "components/favicon_base/favicon_types.h" |
| 21 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" | 24 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
| 22 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" | 25 #include "ios/chrome/browser/bookmarks/bookmarks_utils.h" |
| 23 #include "ios/chrome/browser/favicon/ios_chrome_large_icon_service_factory.h" | 26 #include "ios/chrome/browser/favicon/ios_chrome_large_icon_service_factory.h" |
| 24 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" | 27 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" |
| 25 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view_background.h" | 28 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_view_background.h" |
| 26 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h" | 29 #import "ios/chrome/browser/ui/bookmarks/bookmark_promo_cell.h" |
| 27 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 30 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 28 #include "ios/chrome/browser/ui/ui_util.h" | 31 #include "ios/chrome/browser/ui/ui_util.h" |
| 29 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 32 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 30 #include "ios/chrome/grit/ios_strings.h" | 33 #include "ios/chrome/grit/ios_strings.h" |
| 31 #include "skia/ext/skia_utils_ios.h" | 34 #include "skia/ext/skia_utils_ios.h" |
| 32 #include "ui/base/l10n/l10n_util_mac.h" | 35 #include "ui/base/l10n/l10n_util_mac.h" |
| 33 | 36 |
| 34 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 35 #error "This file requires ARC support." | |
| 36 #endif | |
| 37 | |
| 38 using bookmarks::BookmarkNode; | 37 using bookmarks::BookmarkNode; |
| 39 | 38 |
| 40 namespace { | 39 namespace { |
| 41 | 40 |
| 42 // Used to store a pair of NSIntegers when storing a NSIndexPath in C++ | 41 // Used to store a pair of NSIntegers when storing a NSIndexPath in C++ |
| 43 // collections. | 42 // collections. |
| 44 using IntegerPair = std::pair<NSInteger, NSInteger>; | 43 using IntegerPair = std::pair<NSInteger, NSInteger>; |
| 45 | 44 |
| 46 // The margin between the side of the view and the first and last tile. | 45 // The margin between the side of the view and the first and last tile. |
| 47 CGFloat rowMarginTablet = 24.0; | 46 CGFloat rowMarginTablet = 24.0; |
| 48 CGFloat rowHeight = 48.0; | 47 CGFloat rowHeight = 48.0; |
| 49 // Minimal acceptable favicon size, in points. | 48 // Minimal acceptable favicon size, in points. |
| 50 CGFloat minFaviconSizePt = 16; | 49 CGFloat minFaviconSizePt = 16; |
| 51 | 50 |
| 52 // Delay in seconds to which the empty background view will be shown when the | 51 // Delay in seconds to which the empty background view will be shown when the |
| 53 // collection view is empty. | 52 // collection view is empty. |
| 54 // This delay should not be too small to let enough time to load bookmarks | 53 // This delay should not be too small to let enough time to load bookmarks |
| 55 // from network. | 54 // from network. |
| 56 const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; | 55 const NSTimeInterval kShowEmptyBookmarksBackgroundRefreshDelay = 1.0; |
| 57 | 56 |
| 58 } // namespace | 57 } // namespace |
| 59 | 58 |
| 60 @interface BookmarkCollectionView ()<UICollectionViewDataSource, | 59 @interface BookmarkCollectionView ()<UICollectionViewDataSource, |
| 61 UICollectionViewDelegateFlowLayout, | 60 UICollectionViewDelegateFlowLayout, |
| 62 UIGestureRecognizerDelegate> { | 61 UIGestureRecognizerDelegate> { |
| 63 std::unique_ptr<bookmarks::BookmarkModelBridge> _modelBridge; | 62 std::unique_ptr<bookmarks::BookmarkModelBridge> _modelBridge; |
| 64 ios::ChromeBrowserState* _browserState; | 63 ios::ChromeBrowserState* _browserState; |
| 65 | 64 |
| 65 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkCollectionView; |
| 66 |
| 66 // Map of favicon load tasks for each index path. Used to keep track of | 67 // Map of favicon load tasks for each index path. Used to keep track of |
| 67 // pending favicon load operations so that they can be cancelled upon cell | 68 // pending favicon load operations so that they can be cancelled upon cell |
| 68 // reuse. Keys are (section, item) pairs of cell index paths. | 69 // reuse. Keys are (section, item) pairs of cell index paths. |
| 69 std::map<IntegerPair, base::CancelableTaskTracker::TaskId> _faviconLoadTasks; | 70 std::map<IntegerPair, base::CancelableTaskTracker::TaskId> _faviconLoadTasks; |
| 70 // Task tracker used for async favicon loads. | 71 // Task tracker used for async favicon loads. |
| 71 base::CancelableTaskTracker _faviconTaskTracker; | 72 base::CancelableTaskTracker _faviconTaskTracker; |
| 72 } | 73 } |
| 73 | 74 |
| 74 // Redefined to be readwrite. | 75 // Redefined to be readwrite. |
| 75 @property(nonatomic, assign) bookmarks::BookmarkModel* bookmarkModel; | 76 @property(nonatomic, assign) bookmarks::BookmarkModel* bookmarkModel; |
| 76 // Redefined to be readwrite. | 77 // Redefined to be readwrite. |
| 77 @property(nonatomic, strong) UICollectionView* collectionView; | 78 @property(nonatomic, retain) UICollectionView* collectionView; |
| 78 // Redefined to be readwrite. | 79 // Redefined to be readwrite. |
| 79 @property(nonatomic, assign) BOOL editing; | 80 @property(nonatomic, assign) BOOL editing; |
| 80 // Detects a long press on a cell. | 81 // Detects a long press on a cell. |
| 81 @property(nonatomic, strong) UILongPressGestureRecognizer* longPressRecognizer; | 82 @property(nonatomic, retain) UILongPressGestureRecognizer* longPressRecognizer; |
| 82 // Background view of the collection view shown when there is no items. | 83 // Background view of the collection view shown when there is no items. |
| 83 @property(nonatomic, strong) | 84 @property(nonatomic, retain) |
| 84 BookmarkCollectionViewBackground* emptyCollectionBackgroundView; | 85 BookmarkCollectionViewBackground* emptyCollectionBackgroundView; |
| 85 // Shadow to display over the content. | 86 // Shadow to display over the content. |
| 86 @property(nonatomic, strong) UIView* shadow; | 87 @property(nonatomic, retain) UIView* shadow; |
| 87 | 88 |
| 88 // Updates the editing state for the cell. | 89 // Updates the editing state for the cell. |
| 89 - (void)updateEditingStateOfCell:(BookmarkCell*)cell | 90 - (void)updateEditingStateOfCell:(BookmarkCell*)cell |
| 90 atIndexPath:(NSIndexPath*)indexPath | 91 atIndexPath:(NSIndexPath*)indexPath |
| 91 animateMenuVisibility:(BOOL)animateMenuVisibility | 92 animateMenuVisibility:(BOOL)animateMenuVisibility |
| 92 animateSelectedState:(BOOL)animateSelectedState; | 93 animateSelectedState:(BOOL)animateSelectedState; |
| 93 | 94 |
| 94 // Callback received when the user taps the menu button on the cell. | 95 // Callback received when the user taps the menu button on the cell. |
| 95 - (void)didTapMenuButton:(BookmarkItemCell*)cell view:(UIView*)view; | 96 - (void)didTapMenuButton:(BookmarkItemCell*)cell view:(UIView*)view; |
| 96 | 97 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 | 130 |
| 130 - (id)initWithFrame:(CGRect)frame { | 131 - (id)initWithFrame:(CGRect)frame { |
| 131 NOTREACHED(); | 132 NOTREACHED(); |
| 132 return nil; | 133 return nil; |
| 133 } | 134 } |
| 134 | 135 |
| 135 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState | 136 - (instancetype)initWithBrowserState:(ios::ChromeBrowserState*)browserState |
| 136 frame:(CGRect)frame { | 137 frame:(CGRect)frame { |
| 137 self = [super initWithFrame:frame]; | 138 self = [super initWithFrame:frame]; |
| 138 if (self) { | 139 if (self) { |
| 140 _propertyReleaser_BookmarkCollectionView.Init( |
| 141 self, [BookmarkCollectionView class]); |
| 142 |
| 139 _browserState = browserState; | 143 _browserState = browserState; |
| 140 | 144 |
| 141 // Set up connection to the BookmarkModel. | 145 // Set up connection to the BookmarkModel. |
| 142 _bookmarkModel = | 146 _bookmarkModel = |
| 143 ios::BookmarkModelFactory::GetForBrowserState(browserState); | 147 ios::BookmarkModelFactory::GetForBrowserState(browserState); |
| 144 | 148 |
| 145 // Set up observers. | 149 // Set up observers. |
| 146 _modelBridge.reset( | 150 _modelBridge.reset( |
| 147 new bookmarks::BookmarkModelBridge(self, _bookmarkModel)); | 151 new bookmarks::BookmarkModelBridge(self, _bookmarkModel)); |
| 148 | 152 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 159 // A collection view with a layout that uses a dynamic animator (aka | 163 // A collection view with a layout that uses a dynamic animator (aka |
| 160 // something that changes the layout over time) will crash if it is | 164 // something that changes the layout over time) will crash if it is |
| 161 // deallocated while the animation is currently playing. | 165 // deallocated while the animation is currently playing. |
| 162 // Apparently if a tick has been dispatched it will execute, invoking a | 166 // Apparently if a tick has been dispatched it will execute, invoking a |
| 163 // method on the deallocated collection. | 167 // method on the deallocated collection. |
| 164 // The only purpose of this block is to retain the collection view for a | 168 // The only purpose of this block is to retain the collection view for a |
| 165 // while, giving the layout a chance to perform its last tick. | 169 // while, giving the layout a chance to perform its last tick. |
| 166 [moi self]; | 170 [moi self]; |
| 167 }); | 171 }); |
| 168 _faviconTaskTracker.TryCancelAll(); | 172 _faviconTaskTracker.TryCancelAll(); |
| 173 [super dealloc]; |
| 169 } | 174 } |
| 170 | 175 |
| 171 - (void)setupViews { | 176 - (void)setupViews { |
| 172 self.backgroundColor = bookmark_utils_ios::mainBackgroundColor(); | 177 self.backgroundColor = bookmark_utils_ios::mainBackgroundColor(); |
| 173 UICollectionViewFlowLayout* layout = | 178 base::scoped_nsobject<UICollectionViewFlowLayout> layout( |
| 174 [[UICollectionViewFlowLayout alloc] init]; | 179 [[UICollectionViewFlowLayout alloc] init]); |
| 175 | 180 |
| 176 UICollectionView* collectionView = | 181 base::scoped_nsobject<UICollectionView> collectionView( |
| 177 [[UICollectionView alloc] initWithFrame:self.bounds | 182 [[UICollectionView alloc] initWithFrame:self.bounds |
| 178 collectionViewLayout:layout]; | 183 collectionViewLayout:layout]); |
| 179 self.collectionView = collectionView; | 184 self.collectionView = collectionView; |
| 180 self.collectionView.backgroundColor = [UIColor clearColor]; | 185 self.collectionView.backgroundColor = [UIColor clearColor]; |
| 181 self.collectionView.autoresizingMask = | 186 self.collectionView.autoresizingMask = |
| 182 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | 187 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; |
| 183 self.collectionView.alwaysBounceVertical = YES; | 188 self.collectionView.alwaysBounceVertical = YES; |
| 184 self.collectionView.delegate = self; | 189 self.collectionView.delegate = self; |
| 185 self.collectionView.dataSource = self; | 190 self.collectionView.dataSource = self; |
| 186 [self.collectionView registerClass:[BookmarkFolderCell class] | 191 [self.collectionView registerClass:[BookmarkFolderCell class] |
| 187 forCellWithReuseIdentifier:[BookmarkFolderCell reuseIdentifier]]; | 192 forCellWithReuseIdentifier:[BookmarkFolderCell reuseIdentifier]]; |
| 188 [self.collectionView registerClass:[BookmarkItemCell class] | 193 [self.collectionView registerClass:[BookmarkItemCell class] |
| 189 forCellWithReuseIdentifier:[BookmarkItemCell reuseIdentifier]]; | 194 forCellWithReuseIdentifier:[BookmarkItemCell reuseIdentifier]]; |
| 190 [self.collectionView registerClass:[BookmarkHeaderView class] | 195 [self.collectionView registerClass:[BookmarkHeaderView class] |
| 191 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader | 196 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader |
| 192 withReuseIdentifier:[BookmarkHeaderView reuseIdentifier]]; | 197 withReuseIdentifier:[BookmarkHeaderView reuseIdentifier]]; |
| 193 [self.collectionView | 198 [self.collectionView |
| 194 registerClass:[BookmarkHeaderSeparatorView class] | 199 registerClass:[BookmarkHeaderSeparatorView class] |
| 195 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader | 200 forSupplementaryViewOfKind:UICollectionElementKindSectionHeader |
| 196 withReuseIdentifier:[BookmarkHeaderSeparatorView reuseIdentifier]]; | 201 withReuseIdentifier:[BookmarkHeaderSeparatorView reuseIdentifier]]; |
| 197 [self.collectionView registerClass:[BookmarkPromoCell class] | 202 [self.collectionView registerClass:[BookmarkPromoCell class] |
| 198 forCellWithReuseIdentifier:[BookmarkPromoCell reuseIdentifier]]; | 203 forCellWithReuseIdentifier:[BookmarkPromoCell reuseIdentifier]]; |
| 199 | 204 |
| 200 [self addSubview:self.collectionView]; | 205 [self addSubview:self.collectionView]; |
| 201 | 206 |
| 202 // Set up the background view shown when the collection is empty. | 207 // Set up the background view shown when the collection is empty. |
| 203 BookmarkCollectionViewBackground* emptyCollectionBackgroundView = | 208 base::scoped_nsobject<BookmarkCollectionViewBackground> |
| 204 [[BookmarkCollectionViewBackground alloc] initWithFrame:CGRectZero]; | 209 emptyCollectionBackgroundView( |
| 210 [[BookmarkCollectionViewBackground alloc] initWithFrame:CGRectZero]); |
| 205 self.emptyCollectionBackgroundView = emptyCollectionBackgroundView; | 211 self.emptyCollectionBackgroundView = emptyCollectionBackgroundView; |
| 206 self.emptyCollectionBackgroundView.autoresizingMask = | 212 self.emptyCollectionBackgroundView.autoresizingMask = |
| 207 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; | 213 UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth; |
| 208 self.emptyCollectionBackgroundView.alpha = 0; | 214 self.emptyCollectionBackgroundView.alpha = 0; |
| 209 self.emptyCollectionBackgroundView.text = [self textWhenCollectionIsEmpty]; | 215 self.emptyCollectionBackgroundView.text = [self textWhenCollectionIsEmpty]; |
| 210 | 216 |
| 211 self.emptyCollectionBackgroundView.frame = self.collectionView.bounds; | 217 self.emptyCollectionBackgroundView.frame = self.collectionView.bounds; |
| 212 self.collectionView.backgroundView = self.emptyCollectionBackgroundView; | 218 self.collectionView.backgroundView = self.emptyCollectionBackgroundView; |
| 213 | 219 |
| 214 [self updateShadow]; | 220 [self updateShadow]; |
| 215 | 221 |
| 216 self.longPressRecognizer = [[UILongPressGestureRecognizer alloc] | 222 self.longPressRecognizer = |
| 217 initWithTarget:self | 223 base::scoped_nsobject<UILongPressGestureRecognizer>( |
| 218 action:@selector(longPress:)]; | 224 [[UILongPressGestureRecognizer alloc] |
| 225 initWithTarget:self |
| 226 action:@selector(longPress:)]); |
| 219 self.longPressRecognizer.delegate = self; | 227 self.longPressRecognizer.delegate = self; |
| 220 [self.collectionView addGestureRecognizer:self.longPressRecognizer]; | 228 [self.collectionView addGestureRecognizer:self.longPressRecognizer]; |
| 221 } | 229 } |
| 222 | 230 |
| 223 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { | 231 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { |
| 224 [self updateShadow]; | 232 [self updateShadow]; |
| 225 } | 233 } |
| 226 | 234 |
| 227 - (void)updateShadow { | 235 - (void)updateShadow { |
| 228 // Remove the current one, if any. | 236 // Remove the current one, if any. |
| 229 [self.shadow removeFromSuperview]; | 237 [self.shadow removeFromSuperview]; |
| 230 | 238 |
| 231 if (IsCompact(self)) { | 239 if (IsCompact(self)) { |
| 232 self.shadow = | 240 self.shadow = |
| 233 bookmark_utils_ios::dropShadowWithWidth(CGRectGetWidth(self.bounds)); | 241 bookmark_utils_ios::dropShadowWithWidth(CGRectGetWidth(self.bounds)); |
| 234 } else { | 242 } else { |
| 235 self.shadow = [[UIView alloc] | 243 self.shadow = [[[UIView alloc] |
| 236 initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), | 244 initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.bounds), |
| 237 1 / [[UIScreen mainScreen] scale])]; | 245 1 / [[UIScreen mainScreen] scale])] |
| 246 autorelease]; |
| 238 self.shadow.backgroundColor = [UIColor colorWithWhite:0.0 alpha:.12]; | 247 self.shadow.backgroundColor = [UIColor colorWithWhite:0.0 alpha:.12]; |
| 239 } | 248 } |
| 240 | 249 |
| 241 [self updateShadowFrame]; | 250 [self updateShadowFrame]; |
| 242 self.shadow.autoresizingMask = UIViewAutoresizingFlexibleWidth; | 251 self.shadow.autoresizingMask = UIViewAutoresizingFlexibleWidth; |
| 243 if (self.editing) | 252 if (self.editing) |
| 244 self.shadow.alpha = 0.0; | 253 self.shadow.alpha = 0.0; |
| 245 | 254 |
| 246 // Add the new shadow. | 255 // Add the new shadow. |
| 247 [self addSubview:self.shadow]; | 256 [self addSubview:self.shadow]; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 470 - (void)cancelLoadingFaviconAtIndexPath:(NSIndexPath*)indexPath { | 479 - (void)cancelLoadingFaviconAtIndexPath:(NSIndexPath*)indexPath { |
| 471 _faviconTaskTracker.TryCancel( | 480 _faviconTaskTracker.TryCancel( |
| 472 _faviconLoadTasks[IntegerPair(indexPath.section, indexPath.item)]); | 481 _faviconLoadTasks[IntegerPair(indexPath.section, indexPath.item)]); |
| 473 } | 482 } |
| 474 | 483 |
| 475 - (void)loadFaviconAtIndexPath:(NSIndexPath*)indexPath { | 484 - (void)loadFaviconAtIndexPath:(NSIndexPath*)indexPath { |
| 476 // Cancel previous load attempts. | 485 // Cancel previous load attempts. |
| 477 [self cancelLoadingFaviconAtIndexPath:indexPath]; | 486 [self cancelLoadingFaviconAtIndexPath:indexPath]; |
| 478 | 487 |
| 479 // Start loading a favicon. | 488 // Start loading a favicon. |
| 480 __weak BookmarkCollectionView* weakSelf = self; | 489 base::WeakNSObject<BookmarkCollectionView> weakSelf(self); |
| 481 const bookmarks::BookmarkNode* node = [self nodeAtIndexPath:indexPath]; | 490 const bookmarks::BookmarkNode* node = [self nodeAtIndexPath:indexPath]; |
| 482 GURL blockURL(node->url()); | 491 GURL blockURL(node->url()); |
| 483 void (^faviconBlock)(const favicon_base::LargeIconResult&) = ^( | 492 void (^faviconBlock)(const favicon_base::LargeIconResult&) = ^( |
| 484 const favicon_base::LargeIconResult& result) { | 493 const favicon_base::LargeIconResult& result) { |
| 485 BookmarkCollectionView* strongSelf = weakSelf; | 494 base::scoped_nsobject<BookmarkCollectionView> strongSelf([weakSelf retain]); |
| 486 if (!strongSelf) | 495 if (!strongSelf) |
| 487 return; | 496 return; |
| 488 UIImage* favIcon = nil; | 497 UIImage* favIcon = nil; |
| 489 UIColor* backgroundColor = nil; | 498 UIColor* backgroundColor = nil; |
| 490 UIColor* textColor = nil; | 499 UIColor* textColor = nil; |
| 491 NSString* fallbackText = nil; | 500 NSString* fallbackText = nil; |
| 492 if (result.bitmap.is_valid()) { | 501 if (result.bitmap.is_valid()) { |
| 493 scoped_refptr<base::RefCountedMemory> data = result.bitmap.bitmap_data; | 502 scoped_refptr<base::RefCountedMemory> data = |
| 503 result.bitmap.bitmap_data.get(); |
| 494 favIcon = [UIImage imageWithData:[NSData dataWithBytes:data->front() | 504 favIcon = [UIImage imageWithData:[NSData dataWithBytes:data->front() |
| 495 length:data->size()]]; | 505 length:data->size()]]; |
| 496 } else if (result.fallback_icon_style) { | 506 } else if (result.fallback_icon_style) { |
| 497 backgroundColor = skia::UIColorFromSkColor( | 507 backgroundColor = skia::UIColorFromSkColor( |
| 498 result.fallback_icon_style->background_color); | 508 result.fallback_icon_style->background_color); |
| 499 textColor = | 509 textColor = |
| 500 skia::UIColorFromSkColor(result.fallback_icon_style->text_color); | 510 skia::UIColorFromSkColor(result.fallback_icon_style->text_color); |
| 501 | 511 |
| 502 fallbackText = | 512 fallbackText = |
| 503 base::SysUTF16ToNSString(favicon::GetFallbackIconText(blockURL)); | 513 base::SysUTF16ToNSString(favicon::GetFallbackIconText(blockURL)); |
| 504 } | 514 } |
| 505 | 515 |
| 506 [strongSelf updateCellAtIndexPath:indexPath | 516 [strongSelf updateCellAtIndexPath:indexPath |
| 507 withImage:favIcon | 517 withImage:favIcon |
| 508 backgroundColor:backgroundColor | 518 backgroundColor:backgroundColor |
| 509 textColor:textColor | 519 textColor:textColor |
| 510 fallbackText:fallbackText]; | 520 fallbackText:fallbackText]; |
| 511 }; | 521 }; |
| 512 | 522 |
| 513 CGFloat scale = [UIScreen mainScreen].scale; | 523 CGFloat scale = [UIScreen mainScreen].scale; |
| 514 CGFloat preferredSize = scale * [BookmarkItemCell preferredImageSize]; | 524 CGFloat preferredSize = scale * [BookmarkItemCell preferredImageSize]; |
| 515 CGFloat minSize = scale * minFaviconSizePt; | 525 CGFloat minSize = scale * minFaviconSizePt; |
| 516 | 526 |
| 517 base::CancelableTaskTracker::TaskId taskId = | 527 base::CancelableTaskTracker::TaskId taskId = |
| 518 IOSChromeLargeIconServiceFactory::GetForBrowserState(self.browserState) | 528 IOSChromeLargeIconServiceFactory::GetForBrowserState(self.browserState) |
| 519 ->GetLargeIconOrFallbackStyle(node->url(), minSize, preferredSize, | 529 ->GetLargeIconOrFallbackStyle(node->url(), minSize, preferredSize, |
| 520 base::BindBlockArc(faviconBlock), | 530 base::BindBlock(faviconBlock), |
| 521 &_faviconTaskTracker); | 531 &_faviconTaskTracker); |
| 522 _faviconLoadTasks[IntegerPair(indexPath.section, indexPath.item)] = taskId; | 532 _faviconLoadTasks[IntegerPair(indexPath.section, indexPath.item)] = taskId; |
| 523 } | 533 } |
| 524 | 534 |
| 525 - (BookmarkFolderCell*)cellForFolder:(const BookmarkNode*)node | 535 - (BookmarkFolderCell*)cellForFolder:(const BookmarkNode*)node |
| 526 indexPath:(NSIndexPath*)indexPath { | 536 indexPath:(NSIndexPath*)indexPath { |
| 527 DCHECK(![self isPromoSection:indexPath.section]); | 537 DCHECK(![self isPromoSection:indexPath.section]); |
| 528 BookmarkFolderCell* cell = [self.collectionView | 538 BookmarkFolderCell* cell = [self.collectionView |
| 529 dequeueReusableCellWithReuseIdentifier:[BookmarkFolderCell | 539 dequeueReusableCellWithReuseIdentifier:[BookmarkFolderCell |
| 530 reuseIdentifier] | 540 reuseIdentifier] |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 684 return UIEdgeInsetsZero; | 694 return UIEdgeInsetsZero; |
| 685 } | 695 } |
| 686 } | 696 } |
| 687 | 697 |
| 688 - (CGSize)cellSizeForIndexPath:(NSIndexPath*)indexPath { | 698 - (CGSize)cellSizeForIndexPath:(NSIndexPath*)indexPath { |
| 689 if ([self isPromoSection:indexPath.section]) { | 699 if ([self isPromoSection:indexPath.section]) { |
| 690 CGRect estimatedFrame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), 100); | 700 CGRect estimatedFrame = CGRectMake(0, 0, CGRectGetWidth(self.bounds), 100); |
| 691 UICollectionViewCell* cell = | 701 UICollectionViewCell* cell = |
| 692 [self.collectionView cellForItemAtIndexPath:indexPath]; | 702 [self.collectionView cellForItemAtIndexPath:indexPath]; |
| 693 if (!cell) { | 703 if (!cell) { |
| 694 cell = [[BookmarkPromoCell alloc] initWithFrame:estimatedFrame]; | 704 cell = [[[BookmarkPromoCell alloc] initWithFrame:estimatedFrame] |
| 705 autorelease]; |
| 695 } | 706 } |
| 696 cell.frame = estimatedFrame; | 707 cell.frame = estimatedFrame; |
| 697 [cell layoutIfNeeded]; | 708 [cell layoutIfNeeded]; |
| 698 return [cell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; | 709 return [cell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize]; |
| 699 } | 710 } |
| 700 | 711 |
| 701 UIEdgeInsets insets = [self insetForSectionAtIndex:indexPath.section]; | 712 UIEdgeInsets insets = [self insetForSectionAtIndex:indexPath.section]; |
| 702 return CGSizeMake(self.bounds.size.width - (insets.right + insets.left), | 713 return CGSizeMake(self.bounds.size.width - (insets.right + insets.left), |
| 703 rowHeight); | 714 rowHeight); |
| 704 } | 715 } |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 839 | 850 |
| 840 - (BOOL)shouldShowPromoCell { | 851 - (BOOL)shouldShowPromoCell { |
| 841 return NO; | 852 return NO; |
| 842 } | 853 } |
| 843 | 854 |
| 844 - (BOOL)isPromoActive { | 855 - (BOOL)isPromoActive { |
| 845 return NO; | 856 return NO; |
| 846 } | 857 } |
| 847 | 858 |
| 848 @end | 859 @end |
| OLD | NEW |