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 | 10 #include "base/mac/objc_property_releaser.h" |
| 11 #include "base/mac/scoped_nsobject.h" |
11 #import "ios/chrome/browser/ui/bookmarks/bookmark_extended_button.h" | 12 #import "ios/chrome/browser/ui/bookmarks/bookmark_extended_button.h" |
12 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.h" | 13 #import "ios/chrome/browser/ui/bookmarks/bookmark_home_view_controller.h" |
13 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 14 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
14 #import "ios/chrome/browser/ui/rtl_geometry.h" | 15 #import "ios/chrome/browser/ui/rtl_geometry.h" |
15 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 16 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
16 #include "ios/chrome/grit/ios_strings.h" | 17 #include "ios/chrome/grit/ios_strings.h" |
17 #include "ios/chrome/grit/ios_theme_resources.h" | 18 #include "ios/chrome/grit/ios_theme_resources.h" |
18 #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" |
19 #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" |
20 #include "ui/base/l10n/l10n_util_mac.h" | 21 #include "ui/base/l10n/l10n_util_mac.h" |
21 #import "ui/gfx/ios/NSString+CrStringDrawing.h" | 22 #import "ui/gfx/ios/NSString+CrStringDrawing.h" |
22 #include "url/gurl.h" | 23 #include "url/gurl.h" |
23 | 24 |
24 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
25 #error "This file requires ARC support." | |
26 #endif | |
27 | |
28 namespace { | 25 namespace { |
29 const CGFloat kBookmarkItemCellDefaultImageSize = 40.0; | 26 const CGFloat kBookmarkItemCellDefaultImageSize = 40.0; |
30 const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; | 27 const CGFloat kBookmarkFolderCellDefaultImageSize = 24.0; |
31 } // namespace | 28 } // namespace |
32 | 29 |
33 @interface BookmarkCell () | 30 @interface BookmarkCell () { |
| 31 @protected |
| 32 // Subclasses should set these in the constructor with the wanted values. |
| 33 CGFloat _imageSize; |
| 34 |
| 35 @private |
| 36 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkCell; |
| 37 } |
34 // Redefined to be read-write. | 38 // Redefined to be read-write. |
35 @property(nonatomic, strong) UILabel* titleLabel; | 39 @property(nonatomic, retain) UILabel* titleLabel; |
36 // Redefined to readwrite. | 40 // Redefined to readwrite. |
37 @property(nonatomic, strong) UIImageView* imageView; | 41 @property(nonatomic, retain) UIImageView* imageView; |
38 // Label to show placeholder text when there is no image displayed. | 42 // Label to show placeholder text when there is no image displayed. |
39 @property(nonatomic, strong) UILabel* placeholderLabel; | 43 @property(nonatomic, retain) UILabel* placeholderLabel; |
40 // When the cell is selected for editing, a cover is shown with a blue color. | 44 // When the cell is selected for editing, a cover is shown with a blue color. |
41 // Subclasses should insert new views below this view. | 45 // Subclasses should insert new views below this view. |
42 @property(nonatomic, strong) UIView* highlightCover; | 46 @property(nonatomic, retain) UIView* highlightCover; |
43 // Lists the accessibility elements that are to be seen by UIAccessibility. | 47 // Lists the accessibility elements that are to be seen by UIAccessibility. |
44 @property(nonatomic, readonly) NSMutableArray* accessibilityElements; | 48 @property(nonatomic, readonly) NSMutableArray* accessibilityElements; |
45 // Location of the last touch on the cell. | 49 // Location of the last touch on the cell. |
46 @property(nonatomic, assign) CGPoint touchLocation; | 50 @property(nonatomic, assign) CGPoint touchLocation; |
47 // The view doing the highlight animation. Only set while the cell is | 51 // The view doing the highlight animation. Only set while the cell is |
48 // highlighted. | 52 // highlighted. |
49 @property(nonatomic, strong) MDCInkView* touchFeedbackView; | 53 @property(nonatomic, retain) MDCInkView* touchFeedbackView; |
50 @property(nonatomic, strong) BookmarkExtendedButton* button; | 54 @property(nonatomic, retain) BookmarkExtendedButton* button; |
51 @property(nonatomic, assign) SEL buttonAction; | 55 @property(nonatomic, assign) SEL buttonAction; |
52 @property(nonatomic, weak) id buttonTarget; | 56 @property(nonatomic, assign) id buttonTarget; |
53 // Side of a square image. Subclasses should set this to desired size. | |
54 @property(nonatomic, assign) CGFloat imageSize; | |
55 @end | 57 @end |
56 | 58 |
57 @implementation BookmarkCell | 59 @implementation BookmarkCell |
58 @synthesize accessibilityElements = _accessibilityElements; | 60 @synthesize accessibilityElements = _accessibilityElements; |
59 @synthesize titleLabel = _titleLabel; | 61 @synthesize titleLabel = _titleLabel; |
60 @synthesize imageView = _imageView; | 62 @synthesize imageView = _imageView; |
61 @synthesize highlightCover = _highlightCover; | 63 @synthesize highlightCover = _highlightCover; |
62 @synthesize shouldAnimateImageChanges = _shouldAnimateImageChanges; | 64 @synthesize shouldAnimateImageChanges = _shouldAnimateImageChanges; |
63 @synthesize touchLocation = _touchLocation; | 65 @synthesize touchLocation = _touchLocation; |
64 @synthesize touchFeedbackView = _touchFeedbackView; | 66 @synthesize touchFeedbackView = _touchFeedbackView; |
65 @synthesize button = _button; | 67 @synthesize button = _button; |
66 @synthesize buttonAction = _buttonAction; | 68 @synthesize buttonAction = _buttonAction; |
67 @synthesize buttonTarget = _buttonTarget; | 69 @synthesize buttonTarget = _buttonTarget; |
68 @synthesize placeholderLabel = _placeholderLabel; | 70 @synthesize placeholderLabel = _placeholderLabel; |
69 @synthesize imageSize = _imageSize; | |
70 | 71 |
71 + (NSString*)reuseIdentifier { | 72 + (NSString*)reuseIdentifier { |
72 NOTREACHED(); | 73 NOTREACHED(); |
73 return nil; | 74 return nil; |
74 } | 75 } |
75 | 76 |
76 - (instancetype)initWithFrame:(CGRect)frame { | 77 - (instancetype)initWithFrame:(CGRect)frame { |
77 self = [super initWithFrame:frame]; | 78 self = [super initWithFrame:frame]; |
78 if (self) { | 79 if (self) { |
| 80 _propertyReleaser_BookmarkCell.Init(self, [BookmarkCell class]); |
79 self.exclusiveTouch = YES; | 81 self.exclusiveTouch = YES; |
80 self.backgroundColor = [UIColor whiteColor]; | 82 self.backgroundColor = [UIColor whiteColor]; |
81 | 83 |
82 _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 84 _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; |
83 _titleLabel.textColor = bookmark_utils_ios::darkTextColor(); | 85 _titleLabel.textColor = bookmark_utils_ios::darkTextColor(); |
84 self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO; | 86 self.titleLabel.translatesAutoresizingMaskIntoConstraints = NO; |
85 [self.contentView addSubview:_titleLabel]; | 87 [self.contentView addSubview:_titleLabel]; |
86 | 88 |
87 _imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; | 89 _imageView = [[UIImageView alloc] initWithFrame:CGRectZero]; |
88 _imageView.clipsToBounds = YES; | 90 _imageView.clipsToBounds = YES; |
89 self.imageView.translatesAutoresizingMaskIntoConstraints = NO; | 91 self.imageView.translatesAutoresizingMaskIntoConstraints = NO; |
90 [self.contentView addSubview:_imageView]; | 92 [self.contentView addSubview:_imageView]; |
91 | 93 |
92 _placeholderLabel = [[UILabel alloc] init]; | 94 _placeholderLabel = [[UILabel alloc] init]; |
93 _placeholderLabel.textAlignment = NSTextAlignmentCenter; | 95 _placeholderLabel.textAlignment = NSTextAlignmentCenter; |
94 [self.contentView addSubview:_placeholderLabel]; | 96 [self.contentView addSubview:_placeholderLabel]; |
95 | 97 |
96 _highlightCover = [[UIView alloc] initWithFrame:CGRectZero]; | 98 _highlightCover = [[UIView alloc] initWithFrame:CGRectZero]; |
97 _highlightCover.backgroundColor = | 99 _highlightCover.backgroundColor = |
98 [bookmark_utils_ios::blueColor() colorWithAlphaComponent:0.7]; | 100 [bookmark_utils_ios::blueColor() colorWithAlphaComponent:0.7]; |
99 _highlightCover.hidden = YES; | 101 _highlightCover.hidden = YES; |
100 _highlightCover.translatesAutoresizingMaskIntoConstraints = NO; | 102 _highlightCover.translatesAutoresizingMaskIntoConstraints = NO; |
101 [self.contentView addSubview:_highlightCover]; | 103 [self.contentView addSubview:_highlightCover]; |
102 | 104 |
103 self.button = [[BookmarkExtendedButton alloc] init]; | 105 self.button = base::scoped_nsobject<BookmarkExtendedButton>( |
| 106 [[BookmarkExtendedButton alloc] init]); |
104 self.button.contentMode = UIViewContentModeCenter; | 107 self.button.contentMode = UIViewContentModeCenter; |
105 self.button.backgroundColor = [UIColor clearColor]; | 108 self.button.backgroundColor = [UIColor clearColor]; |
106 [self.button addTarget:self | 109 [self.button addTarget:self |
107 action:@selector(buttonTapped:) | 110 action:@selector(buttonTapped:) |
108 forControlEvents:UIControlEventTouchUpInside]; | 111 forControlEvents:UIControlEventTouchUpInside]; |
109 self.button.translatesAutoresizingMaskIntoConstraints = NO; | 112 self.button.translatesAutoresizingMaskIntoConstraints = NO; |
110 [self.contentView insertSubview:self.button | 113 [self.contentView insertSubview:self.button |
111 belowSubview:self.highlightCover]; | 114 belowSubview:self.highlightCover]; |
112 | 115 |
113 _accessibilityElements = [[NSMutableArray alloc] init]; | 116 _accessibilityElements = [[NSMutableArray alloc] init]; |
114 self.contentView.isAccessibilityElement = YES; | 117 self.contentView.isAccessibilityElement = YES; |
115 self.contentView.accessibilityTraits |= UIAccessibilityTraitButton; | 118 self.contentView.accessibilityTraits |= UIAccessibilityTraitButton; |
116 [_accessibilityElements addObject:self.contentView]; | 119 [_accessibilityElements addObject:self.contentView]; |
117 [self.accessibilityElements addObject:self.button]; | 120 [self.accessibilityElements addObject:self.button]; |
118 } | 121 } |
119 return self; | 122 return self; |
120 } | 123 } |
121 | 124 |
122 + (BOOL)requiresConstraintBasedLayout { | 125 + (BOOL)requiresConstraintBasedLayout { |
123 return YES; | 126 return YES; |
124 } | 127 } |
125 | 128 |
126 - (void)updateConstraints { | 129 - (void)updateConstraints { |
127 if (self.imageSize) { | 130 if (_imageSize) { |
128 // Create constraints. | 131 // Create constraints. |
129 | 132 |
130 // Align all the views on the same horizontal line. | 133 // Align all the views on the same horizontal line. |
131 AddSameCenterYConstraint(self.contentView, self.titleLabel); | 134 AddSameCenterYConstraint(self.contentView, self.titleLabel); |
132 AddSameCenterYConstraint(self.contentView, self.imageView); | 135 AddSameCenterYConstraint(self.contentView, self.imageView); |
133 AddSameCenterYConstraint(self.contentView, self.button); | 136 AddSameCenterYConstraint(self.contentView, self.button); |
134 | 137 |
135 // clang-format off | 138 // clang-format off |
136 ApplyVisualConstraintsWithMetrics( | 139 ApplyVisualConstraintsWithMetrics( |
137 @[ | 140 @[ |
138 @"H:|-leadingImageMargin-[image(imageSize)]", | 141 @"H:|-leadingImageMargin-[image(imageSize)]", |
139 @"H:|-leadingMargin-[title]-[button(buttonSize)]|", | 142 @"H:|-leadingMargin-[title]-[button(buttonSize)]|", |
140 @"V:[image(imageSize)]", | 143 @"V:[image(imageSize)]", |
141 @"V:[button(buttonSize)]", | 144 @"V:[button(buttonSize)]", |
142 @"H:|[highlight]|", | 145 @"H:|[highlight]|", |
143 @"V:|[highlight]|" | 146 @"V:|[highlight]|" |
144 ], | 147 ], |
145 @{ | 148 @{ |
146 @"title" : self.titleLabel, | 149 @"title" : self.titleLabel, |
147 @"image" : self.imageView, | 150 @"image" : self.imageView, |
148 @"button" : self.button, | 151 @"button" : self.button, |
149 @"highlight" : self.highlightCover | 152 @"highlight" : self.highlightCover |
150 }, | 153 }, |
151 @{ | 154 @{ |
152 @"buttonSize" :@32.0, | 155 @"buttonSize" : [NSNumber numberWithFloat:32.0], |
153 @"leadingImageMargin" : @16.0, | 156 @"leadingImageMargin" : [NSNumber numberWithFloat:16.0], |
154 @"leadingMargin" : @64.0, | 157 @"leadingMargin" : [NSNumber numberWithFloat:64.0], |
155 @"imageSize" : @(self.imageSize), | 158 @"imageSize" : [NSNumber numberWithFloat:_imageSize], |
156 }, | 159 }, |
157 self.contentView); | 160 self.contentView); |
158 // clang-format on | 161 // clang-format on |
159 } | 162 } |
160 | 163 |
161 [NSLayoutConstraint activateConstraints:@[ | 164 [NSLayoutConstraint activateConstraints:@[ |
162 [self.placeholderLabel.leadingAnchor | 165 [self.placeholderLabel.leadingAnchor |
163 constraintEqualToAnchor:self.imageView.leadingAnchor], | 166 constraintEqualToAnchor:self.imageView.leadingAnchor], |
164 [self.placeholderLabel.trailingAnchor | 167 [self.placeholderLabel.trailingAnchor |
165 constraintEqualToAnchor:self.imageView.trailingAnchor], | 168 constraintEqualToAnchor:self.imageView.trailingAnchor], |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
237 | 240 |
238 - (void)setHighlighted:(BOOL)highlighted { | 241 - (void)setHighlighted:(BOOL)highlighted { |
239 [super setHighlighted:highlighted]; | 242 [super setHighlighted:highlighted]; |
240 | 243 |
241 // To prevent selection messing up with ink, immediately remove ink. | 244 // To prevent selection messing up with ink, immediately remove ink. |
242 [self.touchFeedbackView removeFromSuperview]; | 245 [self.touchFeedbackView removeFromSuperview]; |
243 self.touchFeedbackView = nil; | 246 self.touchFeedbackView = nil; |
244 | 247 |
245 if (highlighted) { | 248 if (highlighted) { |
246 // Creates an ink feedback and animates it. | 249 // Creates an ink feedback and animates it. |
247 MDCInkView* touchFeedbackView = | 250 base::scoped_nsobject<MDCInkView> touchFeedbackView( |
248 [[MDCInkView alloc] initWithFrame:self.bounds]; | 251 [[MDCInkView alloc] initWithFrame:self.bounds]); |
249 [self addSubview:touchFeedbackView]; | 252 [self addSubview:touchFeedbackView]; |
250 self.touchFeedbackView = touchFeedbackView; | 253 self.touchFeedbackView = touchFeedbackView; |
251 [self.touchFeedbackView startTouchBeganAnimationAtPoint:self.touchLocation | 254 [self.touchFeedbackView startTouchBeganAnimationAtPoint:self.touchLocation |
252 completion:nil]; | 255 completion:nil]; |
253 } else { | 256 } else { |
254 [self.touchFeedbackView startTouchEndedAnimationAtPoint:self.touchLocation | 257 [self.touchFeedbackView startTouchEndedAnimationAtPoint:self.touchLocation |
255 completion:nil]; | 258 completion:nil]; |
256 } | 259 } |
257 } | 260 } |
258 | 261 |
259 - (void)updateWithTitle:(NSString*)title { | 262 - (void)updateWithTitle:(NSString*)title { |
260 self.titleLabel.text = title; | 263 self.titleLabel.text = title; |
261 [self setNeedsLayout]; | 264 [self setNeedsLayout]; |
262 [self updateAccessibilityValues]; | 265 [self updateAccessibilityValues]; |
263 } | 266 } |
264 | 267 |
265 #pragma mark - Button | 268 #pragma mark - Button |
266 - (void)setButtonTarget:(id)target action:(SEL)action { | 269 - (void)setButtonTarget:(id)target action:(SEL)action { |
267 self.buttonTarget = target; | 270 self.buttonTarget = target; |
268 self.buttonAction = action; | 271 self.buttonAction = action; |
269 } | 272 } |
270 | 273 |
271 - (void)buttonTapped:(id)target { | 274 - (void)buttonTapped:(id)target { |
272 #pragma clang diagnostic push | |
273 #pragma clang diagnostic ignored "-Warc-performSelector-leaks" | |
274 [self.buttonTarget performSelector:self.buttonAction | 275 [self.buttonTarget performSelector:self.buttonAction |
275 withObject:self | 276 withObject:self |
276 withObject:target]; | 277 withObject:target]; |
277 #pragma clang diagnostic pop | |
278 } | 278 } |
279 | 279 |
280 - (void)showButtonOfType:(bookmark_cell::ButtonType)buttonType | 280 - (void)showButtonOfType:(bookmark_cell::ButtonType)buttonType |
281 animated:(BOOL)animated { | 281 animated:(BOOL)animated { |
282 switch (buttonType) { | 282 switch (buttonType) { |
283 case bookmark_cell::ButtonNone: | 283 case bookmark_cell::ButtonNone: |
284 [self removeButtonAnimated:animated]; | 284 [self removeButtonAnimated:animated]; |
285 break; | 285 break; |
286 | 286 |
287 case bookmark_cell::ButtonMenu: { | 287 case bookmark_cell::ButtonMenu: { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 } | 348 } |
349 | 349 |
350 - (NSInteger)indexOfAccessibilityElement:(id)element { | 350 - (NSInteger)indexOfAccessibilityElement:(id)element { |
351 return [self.accessibilityElements indexOfObject:element]; | 351 return [self.accessibilityElements indexOfObject:element]; |
352 } | 352 } |
353 | 353 |
354 @end | 354 @end |
355 | 355 |
356 #pragma mark - BookmarkItemCell | 356 #pragma mark - BookmarkItemCell |
357 | 357 |
| 358 @interface BookmarkItemCell () { |
| 359 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkItemCell; |
| 360 } |
| 361 @end |
| 362 |
358 @implementation BookmarkItemCell | 363 @implementation BookmarkItemCell |
359 | 364 |
360 + (NSString*)reuseIdentifier { | 365 + (NSString*)reuseIdentifier { |
361 return @"BookmarkItemCell"; | 366 return @"BookmarkItemCell"; |
362 } | 367 } |
363 | 368 |
364 + (CGFloat)preferredImageSize { | 369 + (CGFloat)preferredImageSize { |
365 return kBookmarkItemCellDefaultImageSize; | 370 return kBookmarkItemCellDefaultImageSize; |
366 } | 371 } |
367 | 372 |
368 - (instancetype)initWithFrame:(CGRect)frame { | 373 - (instancetype)initWithFrame:(CGRect)frame { |
369 self = [super initWithFrame:frame]; | 374 self = [super initWithFrame:frame]; |
370 if (self) { | 375 if (self) { |
| 376 _propertyReleaser_BookmarkItemCell.Init(self, [BookmarkItemCell class]); |
| 377 |
371 // Set the non-layout properties of the titles. | 378 // Set the non-layout properties of the titles. |
372 UIFont* font = [MDCTypography subheadFont]; | 379 UIFont* font = [MDCTypography subheadFont]; |
373 self.titleLabel.font = font; | 380 self.titleLabel.font = font; |
374 self.titleLabel.backgroundColor = [UIColor clearColor]; | 381 self.titleLabel.backgroundColor = [UIColor clearColor]; |
375 self.titleLabel.numberOfLines = 1; | 382 self.titleLabel.numberOfLines = 1; |
376 | 383 |
377 self.imageSize = kBookmarkItemCellDefaultImageSize; | 384 _imageSize = kBookmarkItemCellDefaultImageSize; |
378 } | 385 } |
379 return self; | 386 return self; |
380 } | 387 } |
381 | 388 |
382 - (void)updateWithTitle:(NSString*)title { | 389 - (void)updateWithTitle:(NSString*)title { |
383 [super updateWithTitle:title]; | 390 [super updateWithTitle:title]; |
384 [self updateAccessibilityValues]; | 391 [self updateAccessibilityValues]; |
385 } | 392 } |
386 | 393 |
387 - (void)updateAccessibilityValues { | 394 - (void)updateAccessibilityValues { |
388 [super updateAccessibilityValues]; | 395 [super updateAccessibilityValues]; |
389 self.contentView.accessibilityLabel = | 396 self.contentView.accessibilityLabel = |
390 [NSString stringWithFormat:@"%@", self.titleLabel.text]; | 397 [NSString stringWithFormat:@"%@", self.titleLabel.text]; |
391 self.contentView.accessibilityIdentifier = self.titleLabel.text; | 398 self.contentView.accessibilityIdentifier = self.titleLabel.text; |
392 } | 399 } |
393 | 400 |
394 - (void)prepareForReuse { | 401 - (void)prepareForReuse { |
395 [super prepareForReuse]; | 402 [super prepareForReuse]; |
396 [self updateAccessibilityValues]; | 403 [self updateAccessibilityValues]; |
397 } | 404 } |
398 | 405 |
399 @end | 406 @end |
400 | 407 |
401 #pragma mark - BookmarkFolderCell | 408 #pragma mark - BookmarkFolderCell |
| 409 |
| 410 @interface BookmarkFolderCell () { |
| 411 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkFolderCell; |
| 412 } |
| 413 |
| 414 @end |
| 415 |
402 @implementation BookmarkFolderCell | 416 @implementation BookmarkFolderCell |
403 | 417 |
404 + (NSString*)reuseIdentifier { | 418 + (NSString*)reuseIdentifier { |
405 return @"BookmarkFolderCell"; | 419 return @"BookmarkFolderCell"; |
406 } | 420 } |
407 | 421 |
408 - (instancetype)initWithFrame:(CGRect)frame { | 422 - (instancetype)initWithFrame:(CGRect)frame { |
409 self = [super initWithFrame:frame]; | 423 self = [super initWithFrame:frame]; |
410 if (self) { | 424 if (self) { |
| 425 _propertyReleaser_BookmarkFolderCell.Init(self, [BookmarkFolderCell class]); |
| 426 |
411 self.imageView.image = [UIImage imageNamed:@"bookmark_gray_folder"]; | 427 self.imageView.image = [UIImage imageNamed:@"bookmark_gray_folder"]; |
412 self.titleLabel.font = [MDCTypography subheadFont]; | 428 self.titleLabel.font = [MDCTypography subheadFont]; |
413 | 429 |
414 self.imageSize = kBookmarkFolderCellDefaultImageSize; | 430 _imageSize = kBookmarkFolderCellDefaultImageSize; |
415 } | 431 } |
416 return self; | 432 return self; |
417 } | 433 } |
418 | 434 |
419 - (void)prepareForReuse { | 435 - (void)prepareForReuse { |
420 [super prepareForReuse]; | 436 [super prepareForReuse]; |
421 [self setImage:[UIImage imageNamed:@"bookmark_gray_folder"]]; | 437 [self setImage:[UIImage imageNamed:@"bookmark_gray_folder"]]; |
422 } | 438 } |
423 | 439 |
424 - (void)updateWithTitle:(NSString*)title { | 440 - (void)updateWithTitle:(NSString*)title { |
425 [super updateWithTitle:title]; | 441 [super updateWithTitle:title]; |
426 | 442 |
427 self.contentView.accessibilityLabel = title; | 443 self.contentView.accessibilityLabel = title; |
428 self.contentView.accessibilityIdentifier = title; | 444 self.contentView.accessibilityIdentifier = title; |
429 } | 445 } |
430 | 446 |
431 @end | 447 @end |
432 | 448 |
433 #pragma mark - BookmarkHeaderView | 449 #pragma mark - BookmarkHeaderView |
434 | 450 |
435 @interface BookmarkHeaderView () | 451 @interface BookmarkHeaderView () { |
436 @property(nonatomic, strong) UILabel* titleLabel; | 452 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkHeaderView; |
| 453 } |
| 454 @property(nonatomic, retain) UILabel* titleLabel; |
437 @end | 455 @end |
438 | 456 |
439 @implementation BookmarkHeaderView | 457 @implementation BookmarkHeaderView |
440 @synthesize titleLabel = _titleLabel; | 458 @synthesize titleLabel = _titleLabel; |
441 | |
442 + (NSString*)reuseIdentifier { | 459 + (NSString*)reuseIdentifier { |
443 return @"BookmarkHeaderView"; | 460 return @"BookmarkHeaderView"; |
444 } | 461 } |
445 | 462 |
446 + (CGFloat)handsetHeight { | 463 + (CGFloat)handsetHeight { |
447 return 47.0; | 464 return 47.0; |
448 } | 465 } |
449 | 466 |
450 - (instancetype)initWithFrame:(CGRect)frame { | 467 - (instancetype)initWithFrame:(CGRect)frame { |
451 self = [super initWithFrame:frame]; | 468 self = [super initWithFrame:frame]; |
452 if (self) { | 469 if (self) { |
453 UILabel* titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; | 470 _propertyReleaser_BookmarkHeaderView.Init(self, [BookmarkHeaderView class]); |
| 471 base::scoped_nsobject<UILabel> titleLabel( |
| 472 [[UILabel alloc] initWithFrame:CGRectZero]); |
454 self.titleLabel = titleLabel; | 473 self.titleLabel = titleLabel; |
455 UIFont* font = [MDCTypography body2Font]; | 474 UIFont* font = [MDCTypography body2Font]; |
456 self.titleLabel.font = font; | 475 self.titleLabel.font = font; |
457 self.titleLabel.textColor = bookmark_utils_ios::lightTextColor(); | 476 self.titleLabel.textColor = bookmark_utils_ios::lightTextColor(); |
458 self.titleLabel.backgroundColor = [UIColor clearColor]; | 477 self.titleLabel.backgroundColor = [UIColor clearColor]; |
459 self.titleLabel.accessibilityTraits |= UIAccessibilityTraitHeader; | 478 self.titleLabel.accessibilityTraits |= UIAccessibilityTraitHeader; |
460 [self addSubview:self.titleLabel]; | 479 [self addSubview:self.titleLabel]; |
461 } | 480 } |
462 return self; | 481 return self; |
463 } | 482 } |
(...skipping 17 matching lines...) Expand all Loading... |
481 - (void)updateLayoutWithLeftMargin:(CGFloat)leftMargin { | 500 - (void)updateLayoutWithLeftMargin:(CGFloat)leftMargin { |
482 self.titleLabel.frame = | 501 self.titleLabel.frame = |
483 CGRectMake(leftMargin, 0, self.bounds.size.width - leftMargin, | 502 CGRectMake(leftMargin, 0, self.bounds.size.width - leftMargin, |
484 self.bounds.size.height); | 503 self.bounds.size.height); |
485 } | 504 } |
486 | 505 |
487 @end | 506 @end |
488 | 507 |
489 #pragma mark - BookmarkHeaderSeparatorView | 508 #pragma mark - BookmarkHeaderSeparatorView |
490 | 509 |
491 @interface BookmarkHeaderSeparatorView () | 510 @interface BookmarkHeaderSeparatorView () { |
| 511 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkHeaderSeparatorView; |
| 512 } |
492 // The bottom separator line. | 513 // The bottom separator line. |
493 @property(nonatomic, strong) UIView* lineView; | 514 @property(nonatomic, retain) UIView* lineView; |
494 @end | 515 @end |
495 | 516 |
496 @implementation BookmarkHeaderSeparatorView | 517 @implementation BookmarkHeaderSeparatorView |
497 | 518 |
498 @synthesize lineView = _lineView; | 519 @synthesize lineView = _lineView; |
499 | 520 |
500 + (NSString*)reuseIdentifier { | 521 + (NSString*)reuseIdentifier { |
501 return NSStringFromClass(self); | 522 return NSStringFromClass(self); |
502 } | 523 } |
503 | 524 |
504 + (CGFloat)preferredHeight { | 525 + (CGFloat)preferredHeight { |
505 return 16; | 526 return 16; |
506 } | 527 } |
507 | 528 |
508 - (instancetype)initWithFrame:(CGRect)frame { | 529 - (instancetype)initWithFrame:(CGRect)frame { |
509 self = [super initWithFrame:frame]; | 530 self = [super initWithFrame:frame]; |
510 if (self) { | 531 if (self) { |
| 532 _propertyReleaser_BookmarkHeaderSeparatorView.Init( |
| 533 self, [BookmarkHeaderSeparatorView class]); |
511 _lineView = [[UIView alloc] init]; | 534 _lineView = [[UIView alloc] init]; |
512 _lineView.backgroundColor = bookmark_utils_ios::separatorColor(); | 535 _lineView.backgroundColor = bookmark_utils_ios::separatorColor(); |
513 [self addSubview:_lineView]; | 536 [self addSubview:_lineView]; |
514 } | 537 } |
515 return self; | 538 return self; |
516 } | 539 } |
517 | 540 |
518 - (void)layoutSubviews { | 541 - (void)layoutSubviews { |
519 CGFloat lineHeight = 1; | 542 CGFloat lineHeight = 1; |
520 CGFloat lineY = self.bounds.size.height - lineHeight - 8; | 543 CGFloat lineY = self.bounds.size.height - lineHeight - 8; |
521 _lineView.frame = CGRectMake(0, lineY, self.bounds.size.width, lineHeight); | 544 _lineView.frame = CGRectMake(0, lineY, self.bounds.size.width, lineHeight); |
522 } | 545 } |
523 | 546 |
524 @end | 547 @end |
OLD | NEW |