OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #import "ios/chrome/browser/ui/bookmarks/cells/bookmark_parent_folder_item.h" |
| 6 |
| 7 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 8 #import "ios/chrome/browser/ui/icons/chrome_icon.h" |
| 9 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
| 10 #include "ios/chrome/grit/ios_strings.h" |
| 11 #import "ios/third_party/material_roboto_font_loader_ios/src/src/MaterialRobotoF
ontLoader.h" |
| 12 #include "ui/base/l10n/l10n_util_mac.h" |
| 13 |
| 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 15 #error "This file requires ARC support." |
| 16 #endif |
| 17 |
| 18 @interface BookmarkParentFolderCell () |
| 19 @property(nonatomic, readwrite, strong) UILabel* parentFolderNameLabel; |
| 20 @property(nonatomic, strong) UILabel* decorationLabel; |
| 21 @end |
| 22 |
| 23 @implementation BookmarkParentFolderItem |
| 24 |
| 25 @synthesize title = _title; |
| 26 |
| 27 - (instancetype)initWithType:(NSInteger)type { |
| 28 self = [super initWithType:type]; |
| 29 if (self) { |
| 30 self.accessibilityIdentifier = @"Change Folder"; |
| 31 self.cellClass = [BookmarkParentFolderCell class]; |
| 32 } |
| 33 return self; |
| 34 } |
| 35 |
| 36 #pragma mark CollectionViewItem |
| 37 |
| 38 - (void)configureCell:(BookmarkParentFolderCell*)cell { |
| 39 [super configureCell:cell]; |
| 40 cell.parentFolderNameLabel.text = self.title; |
| 41 } |
| 42 |
| 43 @end |
| 44 |
| 45 @implementation BookmarkParentFolderCell |
| 46 |
| 47 @synthesize parentFolderNameLabel = _parentFolderNameLabel; |
| 48 @synthesize decorationLabel = _decorationLabel; |
| 49 |
| 50 - (instancetype)initWithFrame:(CGRect)frame { |
| 51 self = [super initWithFrame:frame]; |
| 52 if (!self) |
| 53 return nil; |
| 54 |
| 55 self.isAccessibilityElement = YES; |
| 56 self.accessibilityTraits |= UIAccessibilityTraitButton; |
| 57 |
| 58 const CGFloat kHorizontalPadding = 15; |
| 59 const CGFloat kVerticalPadding = 8; |
| 60 const CGFloat kParentFolderLabelTopPadding = 7; |
| 61 |
| 62 _decorationLabel = [[UILabel alloc] init]; |
| 63 _decorationLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| 64 _decorationLabel.text = l10n_util::GetNSString(IDS_IOS_BOOKMARK_GROUP_BUTTON); |
| 65 _decorationLabel.font = |
| 66 [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:12]; |
| 67 _decorationLabel.textColor = bookmark_utils_ios::lightTextColor(); |
| 68 [self.contentView addSubview:_decorationLabel]; |
| 69 |
| 70 _parentFolderNameLabel = [[UILabel alloc] init]; |
| 71 _parentFolderNameLabel.translatesAutoresizingMaskIntoConstraints = NO; |
| 72 _parentFolderNameLabel.font = |
| 73 [[MDFRobotoFontLoader sharedInstance] regularFontOfSize:16]; |
| 74 _parentFolderNameLabel.textColor = |
| 75 [UIColor colorWithWhite:33.0 / 255.0 alpha:1.0]; |
| 76 _parentFolderNameLabel.textAlignment = NSTextAlignmentNatural; |
| 77 [self.contentView addSubview:_parentFolderNameLabel]; |
| 78 |
| 79 UIImageView* navigationChevronImage = [[UIImageView alloc] init]; |
| 80 UIImage* image = TintImage([ChromeIcon chevronIcon], [UIColor grayColor]); |
| 81 navigationChevronImage.image = image; |
| 82 navigationChevronImage.translatesAutoresizingMaskIntoConstraints = NO; |
| 83 [self.contentView addSubview:navigationChevronImage]; |
| 84 |
| 85 // Set up the constraints. |
| 86 [NSLayoutConstraint activateConstraints:@[ |
| 87 [_decorationLabel.topAnchor constraintEqualToAnchor:self.topAnchor |
| 88 constant:kVerticalPadding], |
| 89 [_decorationLabel.leadingAnchor constraintEqualToAnchor:self.leadingAnchor |
| 90 constant:kHorizontalPadding], |
| 91 [_parentFolderNameLabel.topAnchor |
| 92 constraintEqualToAnchor:_decorationLabel.bottomAnchor |
| 93 constant:kParentFolderLabelTopPadding], |
| 94 [_parentFolderNameLabel.leadingAnchor |
| 95 constraintEqualToAnchor:_decorationLabel.leadingAnchor], |
| 96 [navigationChevronImage.centerYAnchor |
| 97 constraintEqualToAnchor:_parentFolderNameLabel.centerYAnchor], |
| 98 [navigationChevronImage.leadingAnchor |
| 99 constraintEqualToAnchor:_parentFolderNameLabel.trailingAnchor], |
| 100 [navigationChevronImage.widthAnchor |
| 101 constraintEqualToConstant:navigationChevronImage.image.size.width], |
| 102 [navigationChevronImage.trailingAnchor |
| 103 constraintEqualToAnchor:self.trailingAnchor |
| 104 constant:-kHorizontalPadding], |
| 105 ]]; |
| 106 |
| 107 self.shouldHideSeparator = YES; |
| 108 return self; |
| 109 } |
| 110 |
| 111 - (void)prepareForReuse { |
| 112 [super prepareForReuse]; |
| 113 self.parentFolderNameLabel.text = nil; |
| 114 } |
| 115 |
| 116 - (NSString*)accessibilityLabel { |
| 117 return self.parentFolderNameLabel.text; |
| 118 } |
| 119 |
| 120 - (NSString*)accessibilityHint { |
| 121 return l10n_util::GetNSString( |
| 122 IDS_IOS_BOOKMARK_EDIT_PARENT_FOLDER_BUTTON_HINT); |
| 123 } |
| 124 |
| 125 @end |
OLD | NEW |