Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: ios/chrome/browser/ui/tools_menu/reading_list_menu_view_item.mm

Issue 2941043002: [ObjC ARC] Converts ios/chrome/browser/ui/tools_menu:tools_menu to ARC. (Closed)
Patch Set: manual review. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/tools_menu/reading_list_menu_view_item.h" 5 #import "ios/chrome/browser/ui/tools_menu/reading_list_menu_view_item.h"
6 6
7 #include "base/mac/foundation_util.h" 7 #include "base/mac/foundation_util.h"
8 #import "base/mac/scoped_nsobject.h"
9 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" 8 #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
10 #import "ios/chrome/browser/ui/reading_list/number_badge_view.h" 9 #import "ios/chrome/browser/ui/reading_list/number_badge_view.h"
11 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h" 10 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat erialPalettes.h"
12 11
12 #if !defined(__has_feature) || !__has_feature(objc_arc)
13 #error "This file requires ARC support."
14 #endif
15
13 namespace { 16 namespace {
14 // ID for cell reuse 17 // ID for cell reuse
15 static NSString* const kReadingListCellID = @"ReadingListCellID"; 18 static NSString* const kReadingListCellID = @"ReadingListCellID";
16 const CGFloat kToolsMenuItemTrailingMargin = 25; 19 const CGFloat kToolsMenuItemTrailingMargin = 25;
17 } // namespace 20 } // namespace
18 21
19 @interface ReadingListMenuViewCell () { 22 @interface ReadingListMenuViewCell () {
20 base::scoped_nsobject<NumberBadgeView> _badge; 23 NumberBadgeView* _badge;
21 } 24 }
22 @end 25 @end
23 26
24 @implementation ReadingListMenuViewItem 27 @implementation ReadingListMenuViewItem
25 28
26 + (NSString*)cellID { 29 + (NSString*)cellID {
27 return kReadingListCellID; 30 return kReadingListCellID;
28 } 31 }
29 32
30 + (Class)cellClass { 33 + (Class)cellClass {
31 return [ReadingListMenuViewCell class]; 34 return [ReadingListMenuViewCell class];
32 } 35 }
33 36
34 @end 37 @end
35 38
36 @implementation ReadingListMenuViewCell 39 @implementation ReadingListMenuViewCell
37 40
38 - (void)initializeViews { 41 - (void)initializeViews {
39 if (_badge && [self title]) { 42 if (_badge && [self title]) {
40 return; 43 return;
41 } 44 }
42 45
43 [super initializeViews]; 46 [super initializeViews];
44 47
45 _badge.reset([[NumberBadgeView alloc] initWithFrame:CGRectZero]); 48 _badge = [[NumberBadgeView alloc] initWithFrame:CGRectZero];
46 [_badge setTranslatesAutoresizingMaskIntoConstraints:NO]; 49 [_badge setTranslatesAutoresizingMaskIntoConstraints:NO];
47 [self.contentView addSubview:_badge]; 50 [self.contentView addSubview:_badge];
48 51
49 [self.contentView removeConstraints:self.contentView.constraints]; 52 [self.contentView removeConstraints:self.contentView.constraints];
50 53
51 NSMutableArray<NSLayoutConstraint*>* constraintsToApply = [NSMutableArray 54 NSMutableArray<NSLayoutConstraint*>* constraintsToApply = [NSMutableArray
52 arrayWithArray:[NSLayoutConstraint 55 arrayWithArray:[NSLayoutConstraint
53 constraintsWithVisualFormat: 56 constraintsWithVisualFormat:
54 @"H:|-(margin)-[title]-[badge]-(endMargin)-|" 57 @"H:|-(margin)-[title]-[badge]-(endMargin)-|"
55 options:NSLayoutFormatDirectionLeadingToTrailing 58 options:NSLayoutFormatDirectionLeadingToTrailing
56 metrics:@{ 59 metrics:@{
57 @"margin" : @(self.horizontalMargin), 60 @"margin" : @(self.horizontalMargin),
58 @"endMargin" : @(kToolsMenuItemTrailingMargin) 61 @"endMargin" : @(kToolsMenuItemTrailingMargin)
59 } 62 }
60 views:@{ 63 views:@{
61 @"title" : self.title, 64 @"title" : self.title,
62 @"badge" : _badge 65 @"badge" : _badge
63 }]]; 66 }]];
64 [constraintsToApply 67 [constraintsToApply
65 addObject:[self.title.centerYAnchor 68 addObject:[self.title.centerYAnchor
66 constraintEqualToAnchor:self.contentView.centerYAnchor]]; 69 constraintEqualToAnchor:self.contentView.centerYAnchor]];
67 [constraintsToApply 70 [constraintsToApply
68 addObject:[_badge.get().centerYAnchor 71 addObject:[_badge.centerYAnchor
69 constraintEqualToAnchor:self.contentView.centerYAnchor]]; 72 constraintEqualToAnchor:self.contentView.centerYAnchor]];
70 73
71 [NSLayoutConstraint activateConstraints:constraintsToApply]; 74 [NSLayoutConstraint activateConstraints:constraintsToApply];
72 } 75 }
73 76
74 - (void)updateBadgeCount:(NSInteger)count animated:(BOOL)animated { 77 - (void)updateBadgeCount:(NSInteger)count animated:(BOOL)animated {
75 [_badge setNumber:count animated:animated]; 78 [_badge setNumber:count animated:animated];
76 } 79 }
77 80
78 - (void)updateSeenState:(BOOL)hasUnseenItems animated:(BOOL)animated { 81 - (void)updateSeenState:(BOOL)hasUnseenItems animated:(BOOL)animated {
79 if (hasUnseenItems) { 82 if (hasUnseenItems) {
80 UIColor* highlightedColor = [[MDCPalette cr_bluePalette] tint500]; 83 UIColor* highlightedColor = [[MDCPalette cr_bluePalette] tint500];
81 84
82 [_badge setBackgroundColor:highlightedColor animated:animated]; 85 [_badge setBackgroundColor:highlightedColor animated:animated];
83 [self.title setTextColor:highlightedColor]; 86 [self.title setTextColor:highlightedColor];
84 } else { 87 } else {
85 UIColor* regularColor = [[MDCPalette greyPalette] tint500]; 88 UIColor* regularColor = [[MDCPalette greyPalette] tint500];
86 89
87 [_badge setBackgroundColor:regularColor animated:animated]; 90 [_badge setBackgroundColor:regularColor animated:animated];
88 [self.title setTextColor:[UIColor blackColor]]; 91 [self.title setTextColor:[UIColor blackColor]];
89 } 92 }
90 } 93 }
91 94
92 @end 95 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698