| 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/history/tab_history_view_controller.h" | 5 #import "ios/chrome/browser/ui/history/tab_history_view_controller.h" |
| 6 | 6 |
| 7 #import "base/ios/weak_nsobject.h" | 7 #import "base/ios/weak_nsobject.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #include "base/mac/objc_property_releaser.h" | |
| 11 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 11 #include "base/strings/sys_string_conversions.h" |
| 13 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" | 12 #import "ios/chrome/browser/ui/commands/UIKit+ChromeExecuteCommand.h" |
| 14 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" | 13 #include "ios/chrome/browser/ui/commands/ios_command_ids.h" |
| 15 #import "ios/chrome/browser/ui/history/tab_history_cell.h" | 14 #import "ios/chrome/browser/ui/history/tab_history_cell.h" |
| 16 #include "ios/chrome/browser/ui/rtl_geometry.h" | 15 #include "ios/chrome/browser/ui/rtl_geometry.h" |
| 17 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" | 16 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" |
| 18 #import "ios/web/navigation/crw_session_entry.h" | 17 #import "ios/web/navigation/crw_session_entry.h" |
| 19 #include "ios/web/public/favicon_status.h" | 18 #include "ios/web/public/favicon_status.h" |
| 20 #include "ios/web/public/navigation_item.h" | 19 #include "ios/web/public/navigation_item.h" |
| 21 #include "ui/gfx/image/image.h" | 20 #include "ui/gfx/image/image.h" |
| 22 | 21 |
| 22 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 23 #error "This file requires ARC support." |
| 24 #endif |
| 25 |
| 23 namespace { | 26 namespace { |
| 24 | 27 |
| 25 // Visible percentage of the last visible row on the Tools menu if the | 28 // Visible percentage of the last visible row on the Tools menu if the |
| 26 // Tools menu is scrollable. | 29 // Tools menu is scrollable. |
| 27 const CGFloat kLastRowVisiblePercentage = 0.6; | 30 const CGFloat kLastRowVisiblePercentage = 0.6; |
| 28 // Reuse identifier for cells. | 31 // Reuse identifier for cells. |
| 29 NSString* cellIdentifier = @"TabHistoryCell"; | 32 NSString* cellIdentifier = @"TabHistoryCell"; |
| 30 NSString* footerIdentifier = @"Footer"; | 33 NSString* footerIdentifier = @"Footer"; |
| 31 NSString* headerIdentifier = @"Header"; | 34 NSString* headerIdentifier = @"Header"; |
| 32 // Height of rows. | 35 // Height of rows. |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 @interface TabHistoryViewController ()<MDCInkTouchControllerDelegate> { | 222 @interface TabHistoryViewController ()<MDCInkTouchControllerDelegate> { |
| 220 base::scoped_nsobject<MDCInkTouchController> _inkTouchController; | 223 base::scoped_nsobject<MDCInkTouchController> _inkTouchController; |
| 221 base::scoped_nsobject<NSArray> _partitionedEntries; | 224 base::scoped_nsobject<NSArray> _partitionedEntries; |
| 222 base::scoped_nsobject<NSArray> _sessionEntries; | 225 base::scoped_nsobject<NSArray> _sessionEntries; |
| 223 } | 226 } |
| 224 @end | 227 @end |
| 225 | 228 |
| 226 @implementation TabHistoryViewController | 229 @implementation TabHistoryViewController |
| 227 | 230 |
| 228 - (NSArray*)sessionEntries { | 231 - (NSArray*)sessionEntries { |
| 229 return [[_sessionEntries retain] autorelease]; | 232 return _sessionEntries; |
| 230 } | 233 } |
| 231 | 234 |
| 232 #pragma mark Public Methods | 235 #pragma mark Public Methods |
| 233 | 236 |
| 234 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { | 237 - (CGFloat)optimalHeight:(CGFloat)suggestedHeight { |
| 235 DCHECK(suggestedHeight >= kCellHeight); | 238 DCHECK(suggestedHeight >= kCellHeight); |
| 236 CGFloat optimalHeight = 0; | 239 CGFloat optimalHeight = 0; |
| 237 | 240 |
| 238 for (NSArray* sectionArray in _partitionedEntries.get()) { | 241 for (NSArray* sectionArray in _partitionedEntries.get()) { |
| 239 NSUInteger sectionItemCount = [sectionArray count]; | 242 NSUInteger sectionItemCount = [sectionArray count]; |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 iconImage = image.ToUIImage(); | 366 iconImage = image.ToUIImage(); |
| 364 else | 367 else |
| 365 iconImage = [UIImage imageNamed:@"default_favicon"]; | 368 iconImage = [UIImage imageNamed:@"default_favicon"]; |
| 366 | 369 |
| 367 [[header iconView] setImage:iconImage]; | 370 [[header iconView] setImage:iconImage]; |
| 368 | 371 |
| 369 return header; | 372 return header; |
| 370 } | 373 } |
| 371 | 374 |
| 372 - (void)setSessionEntries:(NSArray*)sessionEntries { | 375 - (void)setSessionEntries:(NSArray*)sessionEntries { |
| 373 _sessionEntries.reset([sessionEntries retain]); | 376 _sessionEntries.reset(sessionEntries); |
| 374 | 377 |
| 375 std::string previousHost; | 378 std::string previousHost; |
| 376 | 379 |
| 377 NSMutableArray* sectionArray = [NSMutableArray array]; | 380 NSMutableArray* sectionArray = [NSMutableArray array]; |
| 378 NSMutableArray* partitionedEntries = [NSMutableArray array]; | 381 NSMutableArray* partitionedEntries = [NSMutableArray array]; |
| 379 | 382 |
| 380 NSInteger numberOfEntries = [_sessionEntries count]; | 383 NSInteger numberOfEntries = [_sessionEntries count]; |
| 381 for (NSInteger index = 0; index < numberOfEntries; ++index) { | 384 for (NSInteger index = 0; index < numberOfEntries; ++index) { |
| 382 CRWSessionEntry* sessionEntry = [_sessionEntries objectAtIndex:index]; | 385 CRWSessionEntry* sessionEntry = [_sessionEntries objectAtIndex:index]; |
| 383 web::NavigationItem* navigationItem = [sessionEntry navigationItem]; | 386 web::NavigationItem* navigationItem = [sessionEntry navigationItem]; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 399 previousHost = currentHost; | 402 previousHost = currentHost; |
| 400 } | 403 } |
| 401 } | 404 } |
| 402 | 405 |
| 403 if ([sectionArray count]) | 406 if ([sectionArray count]) |
| 404 [partitionedEntries addObject:sectionArray]; | 407 [partitionedEntries addObject:sectionArray]; |
| 405 | 408 |
| 406 if (![partitionedEntries count]) | 409 if (![partitionedEntries count]) |
| 407 partitionedEntries = nil; | 410 partitionedEntries = nil; |
| 408 | 411 |
| 409 _partitionedEntries.reset([partitionedEntries retain]); | 412 _partitionedEntries.reset(partitionedEntries); |
| 410 } | 413 } |
| 411 | 414 |
| 412 #pragma mark MDCInkTouchControllerDelegate | 415 #pragma mark MDCInkTouchControllerDelegate |
| 413 | 416 |
| 414 - (BOOL)inkTouchController:(MDCInkTouchController*)inkTouchController | 417 - (BOOL)inkTouchController:(MDCInkTouchController*)inkTouchController |
| 415 shouldProcessInkTouchesAtTouchLocation:(CGPoint)location { | 418 shouldProcessInkTouchesAtTouchLocation:(CGPoint)location { |
| 416 NSIndexPath* indexPath = | 419 NSIndexPath* indexPath = |
| 417 [self.collectionView indexPathForItemAtPoint:location]; | 420 [self.collectionView indexPathForItemAtPoint:location]; |
| 418 TabHistoryCell* cell = base::mac::ObjCCastStrict<TabHistoryCell>( | 421 TabHistoryCell* cell = base::mac::ObjCCastStrict<TabHistoryCell>( |
| 419 [self.collectionView cellForItemAtIndexPath:indexPath]); | 422 [self.collectionView cellForItemAtIndexPath:indexPath]); |
| 420 if (!cell) { | 423 if (!cell) { |
| 421 return NO; | 424 return NO; |
| 422 } | 425 } |
| 423 | 426 |
| 424 // Increase the size of the ink view to cover the collection view from edge | 427 // Increase the size of the ink view to cover the collection view from edge |
| 425 // to edge. | 428 // to edge. |
| 426 CGRect inkViewFrame = [cell frame]; | 429 CGRect inkViewFrame = [cell frame]; |
| 427 inkViewFrame.origin.x = 0; | 430 inkViewFrame.origin.x = 0; |
| 428 inkViewFrame.size.width = CGRectGetWidth([self.collectionView bounds]); | 431 inkViewFrame.size.width = CGRectGetWidth([self.collectionView bounds]); |
| 429 [[inkTouchController defaultInkView] setFrame:inkViewFrame]; | 432 [[inkTouchController defaultInkView] setFrame:inkViewFrame]; |
| 430 return YES; | 433 return YES; |
| 431 } | 434 } |
| 432 | 435 |
| 433 @end | 436 @end |
| OLD | NEW |