| 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_cells.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bookmark_collection_cells.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/objc_property_releaser.h" | 10 #include "base/mac/objc_release_properties.h" |
| 11 #include "base/mac/scoped_nsobject.h" | 11 #include "base/mac/scoped_nsobject.h" |
| 12 #import "ios/chrome/browser/ui/bookmarks/bookmark_extended_button.h" | 12 #import "ios/chrome/browser/ui/bookmarks/bookmark_extended_button.h" |
| 13 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.h" | 13 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.h" |
| 14 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 14 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 15 #import "ios/chrome/browser/ui/rtl_geometry.h" | 15 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 16 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 16 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 17 #include "ios/chrome/grit/ios_strings.h" | 17 #include "ios/chrome/grit/ios_strings.h" |
| 18 #include "ios/chrome/grit/ios_theme_resources.h" | 18 #include "ios/chrome/grit/ios_theme_resources.h" |
| 19 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" | 19 #import "ios/third_party/material_components_ios/src/components/Ink/src/Material
Ink.h" |
| 20 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 20 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 21 #include "ui/base/l10n/l10n_util_mac.h" | 21 #include "ui/base/l10n/l10n_util_mac.h" |
| 22 #import "ui/gfx/ios/NSString+CrStringDrawing.h" | 22 #import "ui/gfx/ios/NSString+CrStringDrawing.h" |
| 23 #include "url/gurl.h" | 23 #include "url/gurl.h" |
| 24 | 24 |
| 25 namespace { | 25 namespace { |
| 26 const CGFloat kBookmarkItemCellDefaultImageSize = 40.0; | 26 const CGFloat kBookmarkItemCellDefaultImageSize = 40.0; |
| 27 const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; | 27 const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; |
| 28 } // namespace | 28 } // namespace |
| 29 | 29 |
| 30 @interface BookmarkCell () { | 30 @interface BookmarkCell () { |
| 31 @protected | 31 @protected |
| 32 // Subclasses should set these in the constructor with the wanted values. | 32 // Subclasses should set these in the constructor with the wanted values. |
| 33 CGFloat _imageSize; | 33 CGFloat _imageSize; |
| 34 | |
| 35 @private | |
| 36 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkCell; | |
| 37 } | 34 } |
| 38 // Redefined to be read-write. | 35 // Redefined to be read-write. |
| 39 @property(nonatomic, retain) UILabel* titleLabel; | 36 @property(nonatomic, retain) UILabel* titleLabel; |
| 40 // Redefined to readwrite. | 37 // Redefined to readwrite. |
| 41 @property(nonatomic, retain) UIImageView* imageView; | 38 @property(nonatomic, retain) UIImageView* imageView; |
| 42 // Label to show placeholder text when there is no image displayed. | 39 // Label to show placeholder text when there is no image displayed. |
| 43 @property(nonatomic, retain) UILabel* placeholderLabel; | 40 @property(nonatomic, retain) UILabel* placeholderLabel; |
| 44 // When the cell is selected for editing, a cover is shown with a blue color. | 41 // When the cell is selected for editing, a cover is shown with a blue color. |
| 45 // Subclasses should insert new views below this view. | 42 // Subclasses should insert new views below this view. |
| 46 @property(nonatomic, retain) UIView* highlightCover; | 43 @property(nonatomic, retain) UIView* highlightCover; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 70 @synthesize placeholderLabel = _placeholderLabel; | 67 @synthesize placeholderLabel = _placeholderLabel; |
| 71 | 68 |
| 72 + (NSString*)reuseIdentifier { | 69 + (NSString*)reuseIdentifier { |
| 73 NOTREACHED(); | 70 NOTREACHED(); |
| 74 return nil; | 71 return nil; |
| 75 } | 72 } |
| 76 | 73 |
| 77 - (instancetype)initWithFrame:(CGRect)frame { | 74 - (instancetype)initWithFrame:(CGRect)frame { |
| 78 self = [super initWithFrame:frame]; | 75 self = [super initWithFrame:frame]; |
| 79 if (self) { | 76 if (self) { |
| 80 _propertyReleaser_BookmarkCell.Init(self, [BookmarkCell class]); | |
| 81 self.exclusiveTouch = YES; | 77 self.exclusiveTouch = YES; |
| 82 self.backgroundColor = [UIColor whiteColor]; | 78 self.backgroundColor = [UIColor whiteColor]; |
| 83 | 79 |
| 84 _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 80 _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
| 85 _titleLabel.textColor = bookmark_utils_ios::darkTextColor(); | 81 _titleLabel.textColor = bookmark_utils_ios::darkTextColor(); |
| 86 self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO; | 82 self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| 87 [self.contentView addSubview:_titleLabel]; | 83 [self.contentView addSubview:_titleLabel]; |
| 88 | 84 |
| 89 _imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; | 85 _imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; |
| 90 _imageView.clipsToBounds = YES; | 86 _imageView.clipsToBounds = YES; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 115 | 111 |
| 116 _accessibilityElements = [[NSMutableArray alloc] init]; | 112 _accessibilityElements = [[NSMutableArray alloc] init]; |
| 117 self.contentView.isAccessibilityElement = YES; | 113 self.contentView.isAccessibilityElement = YES; |
| 118 self.contentView.accessibilityTraits |= UIAccessibilityTraitButton; | 114 self.contentView.accessibilityTraits |= UIAccessibilityTraitButton; |
| 119 [_accessibilityElements addObject:self.contentView]; | 115 [_accessibilityElements addObject:self.contentView]; |
| 120 [self.accessibilityElements addObject:self.button]; | 116 [self.accessibilityElements addObject:self.button]; |
| 121 } | 117 } |
| 122 return self; | 118 return self; |
| 123 } | 119 } |
| 124 | 120 |
| 121 - (void)dealloc { |
| 122 base::mac::ReleaseProperties(self); |
| 123 [super dealloc]; |
| 124 } |
| 125 |
| 125 + (BOOL)requiresConstraintBasedLayout { | 126 + (BOOL)requiresConstraintBasedLayout { |
| 126 return YES; | 127 return YES; |
| 127 } | 128 } |
| 128 | 129 |
| 129 - (void)updateConstraints { | 130 - (void)updateConstraints { |
| 130 if (_imageSize) { | 131 if (_imageSize) { |
| 131 // Create constraints. | 132 // Create constraints. |
| 132 | 133 |
| 133 // Align all the views on the same horizontal line. | 134 // Align all the views on the same horizontal line. |
| 134 AddSameCenterYConstraint(self.contentView, self.titleLabel); | 135 AddSameCenterYConstraint(self.contentView, self.titleLabel); |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 } | 349 } |
| 349 | 350 |
| 350 - (NSInteger)indexOfAccessibilityElement:(id)element { | 351 - (NSInteger)indexOfAccessibilityElement:(id)element { |
| 351 return [self.accessibilityElements indexOfObject:element]; | 352 return [self.accessibilityElements indexOfObject:element]; |
| 352 } | 353 } |
| 353 | 354 |
| 354 @end | 355 @end |
| 355 | 356 |
| 356 #pragma mark - BookmarkItemCell | 357 #pragma mark - BookmarkItemCell |
| 357 | 358 |
| 358 @interface BookmarkItemCell () { | |
| 359 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkItemCell; | |
| 360 } | |
| 361 @end | |
| 362 | |
| 363 @implementation BookmarkItemCell | 359 @implementation BookmarkItemCell |
| 364 | 360 |
| 365 + (NSString*)reuseIdentifier { | 361 + (NSString*)reuseIdentifier { |
| 366 return @"BookmarkItemCell"; | 362 return @"BookmarkItemCell"; |
| 367 } | 363 } |
| 368 | 364 |
| 369 + (CGFloat)preferredImageSize { | 365 + (CGFloat)preferredImageSize { |
| 370 return kBookmarkItemCellDefaultImageSize; | 366 return kBookmarkItemCellDefaultImageSize; |
| 371 } | 367 } |
| 372 | 368 |
| 373 - (instancetype)initWithFrame:(CGRect)frame { | 369 - (instancetype)initWithFrame:(CGRect)frame { |
| 374 self = [super initWithFrame:frame]; | 370 self = [super initWithFrame:frame]; |
| 375 if (self) { | 371 if (self) { |
| 376 _propertyReleaser_BookmarkItemCell.Init(self, [BookmarkItemCell class]); | |
| 377 | |
| 378 // Set the non-layout properties of the titles. | 372 // Set the non-layout properties of the titles. |
| 379 UIFont* font = [MDCTypography subheadFont]; | 373 UIFont* font = [MDCTypography subheadFont]; |
| 380 self.titleLabel.font = font; | 374 self.titleLabel.font = font; |
| 381 self.titleLabel.backgroundColor = [UIColor clearColor]; | 375 self.titleLabel.backgroundColor = [UIColor clearColor]; |
| 382 self.titleLabel.numberOfLines = 1; | 376 self.titleLabel.numberOfLines = 1; |
| 383 | 377 |
| 384 _imageSize = kBookmarkItemCellDefaultImageSize; | 378 _imageSize = kBookmarkItemCellDefaultImageSize; |
| 385 } | 379 } |
| 386 return self; | 380 return self; |
| 387 } | 381 } |
| 388 | 382 |
| 383 - (void)dealloc { |
| 384 base::mac::ReleaseProperties(self); |
| 385 [super dealloc]; |
| 386 } |
| 387 |
| 389 - (void)updateWithTitle:(NSString*)title { | 388 - (void)updateWithTitle:(NSString*)title { |
| 390 [super updateWithTitle:title]; | 389 [super updateWithTitle:title]; |
| 391 [self updateAccessibilityValues]; | 390 [self updateAccessibilityValues]; |
| 392 } | 391 } |
| 393 | 392 |
| 394 - (void)updateAccessibilityValues { | 393 - (void)updateAccessibilityValues { |
| 395 [super updateAccessibilityValues]; | 394 [super updateAccessibilityValues]; |
| 396 self.contentView.accessibilityLabel = | 395 self.contentView.accessibilityLabel = |
| 397 [NSString stringWithFormat:@"%@", self.titleLabel.text]; | 396 [NSString stringWithFormat:@"%@", self.titleLabel.text]; |
| 398 self.contentView.accessibilityIdentifier = self.titleLabel.text; | 397 self.contentView.accessibilityIdentifier = self.titleLabel.text; |
| 399 } | 398 } |
| 400 | 399 |
| 401 - (void)prepareForReuse { | 400 - (void)prepareForReuse { |
| 402 [super prepareForReuse]; | 401 [super prepareForReuse]; |
| 403 [self updateAccessibilityValues]; | 402 [self updateAccessibilityValues]; |
| 404 } | 403 } |
| 405 | 404 |
| 406 @end | 405 @end |
| 407 | 406 |
| 408 #pragma mark - BookmarkFolderCell | 407 #pragma mark - BookmarkFolderCell |
| 409 | 408 |
| 410 @interface BookmarkFolderCell () { | |
| 411 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkFolderCell; | |
| 412 } | |
| 413 | |
| 414 @end | |
| 415 | |
| 416 @implementation BookmarkFolderCell | 409 @implementation BookmarkFolderCell |
| 417 | 410 |
| 418 + (NSString*)reuseIdentifier { | 411 + (NSString*)reuseIdentifier { |
| 419 return @"BookmarkFolderCell"; | 412 return @"BookmarkFolderCell"; |
| 420 } | 413 } |
| 421 | 414 |
| 422 - (instancetype)initWithFrame:(CGRect)frame { | 415 - (instancetype)initWithFrame:(CGRect)frame { |
| 423 self = [super initWithFrame:frame]; | 416 self = [super initWithFrame:frame]; |
| 424 if (self) { | 417 if (self) { |
| 425 _propertyReleaser_BookmarkFolderCell.Init(self, [BookmarkFolderCell class]); | |
| 426 | |
| 427 self.imageView.image = [UIImage imageNamed:@"bookmark_gray_folder"]; | 418 self.imageView.image = [UIImage imageNamed:@"bookmark_gray_folder"]; |
| 428 self.titleLabel.font = [MDCTypography subheadFont]; | 419 self.titleLabel.font = [MDCTypography subheadFont]; |
| 429 | 420 |
| 430 _imageSize = kBookmarkFolderCellDefaultImageSize; | 421 _imageSize = kBookmarkFolderCellDefaultImageSize; |
| 431 } | 422 } |
| 432 return self; | 423 return self; |
| 433 } | 424 } |
| 434 | 425 |
| 426 - (void)dealloc { |
| 427 base::mac::ReleaseProperties(self); |
| 428 [super dealloc]; |
| 429 } |
| 430 |
| 435 - (void)prepareForReuse { | 431 - (void)prepareForReuse { |
| 436 [super prepareForReuse]; | 432 [super prepareForReuse]; |
| 437 [self setImage:[UIImage imageNamed:@"bookmark_gray_folder"]]; | 433 [self setImage:[UIImage imageNamed:@"bookmark_gray_folder"]]; |
| 438 } | 434 } |
| 439 | 435 |
| 440 - (void)updateWithTitle:(NSString*)title { | 436 - (void)updateWithTitle:(NSString*)title { |
| 441 [super updateWithTitle:title]; | 437 [super updateWithTitle:title]; |
| 442 | 438 |
| 443 self.contentView.accessibilityLabel = title; | 439 self.contentView.accessibilityLabel = title; |
| 444 self.contentView.accessibilityIdentifier = title; | 440 self.contentView.accessibilityIdentifier = title; |
| 445 } | 441 } |
| 446 | 442 |
| 447 @end | 443 @end |
| 448 | 444 |
| 449 #pragma mark - BookmarkHeaderView | 445 #pragma mark - BookmarkHeaderView |
| 450 | 446 |
| 451 @interface BookmarkHeaderView () { | 447 @interface BookmarkHeaderView () |
| 452 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkHeaderView; | |
| 453 } | |
| 454 @property(nonatomic, retain) UILabel* titleLabel; | 448 @property(nonatomic, retain) UILabel* titleLabel; |
| 455 @end | 449 @end |
| 456 | 450 |
| 457 @implementation BookmarkHeaderView | 451 @implementation BookmarkHeaderView |
| 458 @synthesize titleLabel = _titleLabel; | 452 @synthesize titleLabel = _titleLabel; |
| 459 + (NSString*)reuseIdentifier { | 453 + (NSString*)reuseIdentifier { |
| 460 return @"BookmarkHeaderView"; | 454 return @"BookmarkHeaderView"; |
| 461 } | 455 } |
| 462 | 456 |
| 463 + (CGFloat)handsetHeight { | 457 + (CGFloat)handsetHeight { |
| 464 return 47.0; | 458 return 47.0; |
| 465 } | 459 } |
| 466 | 460 |
| 467 - (instancetype)initWithFrame:(CGRect)frame { | 461 - (instancetype)initWithFrame:(CGRect)frame { |
| 468 self = [super initWithFrame:frame]; | 462 self = [super initWithFrame:frame]; |
| 469 if (self) { | 463 if (self) { |
| 470 _propertyReleaser_BookmarkHeaderView.Init(self, [BookmarkHeaderView class]); | |
| 471 base::scoped_nsobject<UILabel> titleLabel( | 464 base::scoped_nsobject<UILabel> titleLabel( |
| 472 [[UILabel alloc] initWithFrame:CGRectZero]); | 465 [[UILabel alloc] initWithFrame:CGRectZero]); |
| 473 self.titleLabel = titleLabel; | 466 self.titleLabel = titleLabel; |
| 474 UIFont* font = [MDCTypography body2Font]; | 467 UIFont* font = [MDCTypography body2Font]; |
| 475 self.titleLabel.font = font; | 468 self.titleLabel.font = font; |
| 476 self.titleLabel.textColor = bookmark_utils_ios::lightTextColor(); | 469 self.titleLabel.textColor = bookmark_utils_ios::lightTextColor(); |
| 477 self.titleLabel.backgroundColor = [UIColor clearColor]; | 470 self.titleLabel.backgroundColor = [UIColor clearColor]; |
| 478 self.titleLabel.accessibilityTraits |= UIAccessibilityTraitHeader; | 471 self.titleLabel.accessibilityTraits |= UIAccessibilityTraitHeader; |
| 479 [self addSubview:self.titleLabel]; | 472 [self addSubview:self.titleLabel]; |
| 480 } | 473 } |
| 481 return self; | 474 return self; |
| 482 } | 475 } |
| 483 | 476 |
| 477 - (void)dealloc { |
| 478 base::mac::ReleaseProperties(self); |
| 479 [super dealloc]; |
| 480 } |
| 481 |
| 484 - (void)layoutSubviews { | 482 - (void)layoutSubviews { |
| 485 [super layoutSubviews]; | 483 [super layoutSubviews]; |
| 486 | 484 |
| 487 // On handsets the title is aligned with the icon in the navigation bar. | 485 // On handsets the title is aligned with the icon in the navigation bar. |
| 488 CGFloat margin = 16.0; | 486 CGFloat margin = 16.0; |
| 489 if (IsIPadIdiom()) | 487 if (IsIPadIdiom()) |
| 490 margin = 24.0; // On tablets the alignment is the same as the tiles. | 488 margin = 24.0; // On tablets the alignment is the same as the tiles. |
| 491 self.titleLabel.frame = | 489 self.titleLabel.frame = |
| 492 CGRectMake(margin, 0, self.bounds.size.width - margin * 2.0, | 490 CGRectMake(margin, 0, self.bounds.size.width - margin * 2.0, |
| 493 self.bounds.size.height); | 491 self.bounds.size.height); |
| 494 } | 492 } |
| 495 | 493 |
| 496 - (void)setTitle:(NSString*)title { | 494 - (void)setTitle:(NSString*)title { |
| 497 self.titleLabel.text = title; | 495 self.titleLabel.text = title; |
| 498 } | 496 } |
| 499 | 497 |
| 500 - (void)updateLayoutWithLeftMargin:(CGFloat)leftMargin { | 498 - (void)updateLayoutWithLeftMargin:(CGFloat)leftMargin { |
| 501 self.titleLabel.frame = | 499 self.titleLabel.frame = |
| 502 CGRectMake(leftMargin, 0, self.bounds.size.width - leftMargin, | 500 CGRectMake(leftMargin, 0, self.bounds.size.width - leftMargin, |
| 503 self.bounds.size.height); | 501 self.bounds.size.height); |
| 504 } | 502 } |
| 505 | 503 |
| 506 @end | 504 @end |
| 507 | 505 |
| 508 #pragma mark - BookmarkHeaderSeparatorView | 506 #pragma mark - BookmarkHeaderSeparatorView |
| 509 | 507 |
| 510 @interface BookmarkHeaderSeparatorView () { | 508 @interface BookmarkHeaderSeparatorView () |
| 511 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkHeaderSeparatorView; | |
| 512 } | |
| 513 // The bottom separator line. | 509 // The bottom separator line. |
| 514 @property(nonatomic, retain) UIView* lineView; | 510 @property(nonatomic, retain) UIView* lineView; |
| 515 @end | 511 @end |
| 516 | 512 |
| 517 @implementation BookmarkHeaderSeparatorView | 513 @implementation BookmarkHeaderSeparatorView |
| 518 | 514 |
| 519 @synthesize lineView = _lineView; | 515 @synthesize lineView = _lineView; |
| 520 | 516 |
| 521 + (NSString*)reuseIdentifier { | 517 + (NSString*)reuseIdentifier { |
| 522 return NSStringFromClass(self); | 518 return NSStringFromClass(self); |
| 523 } | 519 } |
| 524 | 520 |
| 525 + (CGFloat)preferredHeight { | 521 + (CGFloat)preferredHeight { |
| 526 return 16; | 522 return 16; |
| 527 } | 523 } |
| 528 | 524 |
| 529 - (instancetype)initWithFrame:(CGRect)frame { | 525 - (instancetype)initWithFrame:(CGRect)frame { |
| 530 self = [super initWithFrame:frame]; | 526 self = [super initWithFrame:frame]; |
| 531 if (self) { | 527 if (self) { |
| 532 _propertyReleaser_BookmarkHeaderSeparatorView.Init( | |
| 533 self, [BookmarkHeaderSeparatorView class]); | |
| 534 _lineView = [[UIView alloc] init]; | 528 _lineView = [[UIView alloc] init]; |
| 535 _lineView.backgroundColor = bookmark_utils_ios::separatorColor(); | 529 _lineView.backgroundColor = bookmark_utils_ios::separatorColor(); |
| 536 [self addSubview:_lineView]; | 530 [self addSubview:_lineView]; |
| 537 } | 531 } |
| 538 return self; | 532 return self; |
| 539 } | 533 } |
| 540 | 534 |
| 535 - (void)dealloc { |
| 536 base::mac::ReleaseProperties(self); |
| 537 [super dealloc]; |
| 538 } |
| 539 |
| 541 - (void)layoutSubviews { | 540 - (void)layoutSubviews { |
| 542 CGFloat lineHeight = 1; | 541 CGFloat lineHeight = 1; |
| 543 CGFloat lineY = self.bounds.size.height - lineHeight - 8; | 542 CGFloat lineY = self.bounds.size.height - lineHeight - 8; |
| 544 _lineView.frame = CGRectMake(0, lineY, self.bounds.size.width, lineHeight); | 543 _lineView.frame = CGRectMake(0, lineY, self.bounds.size.width, lineHeight); |
| 545 } | 544 } |
| 546 | 545 |
| 547 @end | 546 @end |
| OLD | NEW |