| 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/bars/bookmark_editing_bar.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_editing_bar.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/mac/objc_property_releaser.h" | 8 |
| 9 #include "base/mac/scoped_nsobject.h" | |
| 10 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 11 #import "ios/chrome/browser/ui/bookmarks/bookmark_extended_button.h" | 10 #import "ios/chrome/browser/ui/bookmarks/bookmark_extended_button.h" |
| 12 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 11 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 13 #import "ios/chrome/browser/ui/rtl_geometry.h" | 12 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 14 #include "ios/chrome/grit/ios_strings.h" | 13 #include "ios/chrome/grit/ios_strings.h" |
| 15 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 14 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 17 | 16 |
| 17 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 18 #error "This file requires ARC support." |
| 19 #endif |
| 20 |
| 18 namespace { | 21 namespace { |
| 19 // The distance between buttons. | 22 // The distance between buttons. |
| 20 CGFloat kInterButtonMargin = 24; | 23 CGFloat kInterButtonMargin = 24; |
| 21 } // namespace | 24 } // namespace |
| 22 | 25 |
| 23 @interface BookmarkEditingBar () { | 26 @interface BookmarkEditingBar () { |
| 24 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkEditingBar; | |
| 25 } | 27 } |
| 26 @property(nonatomic, retain) BookmarkExtendedButton* cancelButton; | 28 @property(nonatomic, strong) BookmarkExtendedButton* cancelButton; |
| 27 // This label is slightly left off center, and reflects the number of bookmarks | 29 // This label is slightly left off center, and reflects the number of bookmarks |
| 28 // selected for editing. | 30 // selected for editing. |
| 29 @property(nonatomic, retain) UILabel* countLabel; | 31 @property(nonatomic, strong) UILabel* countLabel; |
| 30 @property(nonatomic, retain) BookmarkExtendedButton* deleteButton; | 32 @property(nonatomic, strong) BookmarkExtendedButton* deleteButton; |
| 31 @property(nonatomic, retain) UIView* dropShadow; | 33 @property(nonatomic, strong) UIView* dropShadow; |
| 32 @property(nonatomic, retain) BookmarkExtendedButton* editButton; | 34 @property(nonatomic, strong) BookmarkExtendedButton* editButton; |
| 33 @property(nonatomic, retain) BookmarkExtendedButton* moveButton; | 35 @property(nonatomic, strong) BookmarkExtendedButton* moveButton; |
| 34 @end | 36 @end |
| 35 | 37 |
| 36 @implementation BookmarkEditingBar | 38 @implementation BookmarkEditingBar |
| 37 @synthesize cancelButton = _cancelButton; | 39 @synthesize cancelButton = _cancelButton; |
| 38 @synthesize countLabel = _countLabel; | 40 @synthesize countLabel = _countLabel; |
| 39 @synthesize deleteButton = _deleteButton; | 41 @synthesize deleteButton = _deleteButton; |
| 40 @synthesize dropShadow = _dropShadow; | 42 @synthesize dropShadow = _dropShadow; |
| 41 @synthesize editButton = _editButton; | 43 @synthesize editButton = _editButton; |
| 42 @synthesize moveButton = _moveButton; | 44 @synthesize moveButton = _moveButton; |
| 43 | 45 |
| 44 - (id)initWithFrame:(CGRect)outerFrame { | 46 - (id)initWithFrame:(CGRect)outerFrame { |
| 45 self = [super initWithFrame:outerFrame]; | 47 self = [super initWithFrame:outerFrame]; |
| 46 if (self) { | 48 if (self) { |
| 47 _propertyReleaser_BookmarkEditingBar.Init(self, [BookmarkEditingBar class]); | |
| 48 self.backgroundColor = bookmark_utils_ios::blueColor(); | 49 self.backgroundColor = bookmark_utils_ios::blueColor(); |
| 49 | 50 |
| 50 CGRect bounds = self.contentView.bounds; | 51 CGRect bounds = self.contentView.bounds; |
| 51 | 52 |
| 52 // Add the cancel button to the leading side of the bar. | 53 // Add the cancel button to the leading side of the bar. |
| 53 CGFloat cancelButtonWidth = 24; | 54 CGFloat cancelButtonWidth = 24; |
| 54 CGFloat cancelButtonHeight = 24; | 55 CGFloat cancelButtonHeight = 24; |
| 55 CGFloat cancelButtonY = | 56 CGFloat cancelButtonY = |
| 56 floor((bounds.size.height - cancelButtonHeight) / 2); | 57 floor((bounds.size.height - cancelButtonHeight) / 2); |
| 57 CGFloat cancelButtonX = cancelButtonY; | 58 CGFloat cancelButtonX = cancelButtonY; |
| 58 base::scoped_nsobject<BookmarkExtendedButton> button( | 59 BookmarkExtendedButton* button = [[BookmarkExtendedButton alloc] |
| 59 [[BookmarkExtendedButton alloc] | 60 initWithFrame:LayoutRectGetRect(LayoutRectMake( |
| 60 initWithFrame:LayoutRectGetRect(LayoutRectMake( | 61 cancelButtonX, |
| 61 cancelButtonX, | 62 CGRectGetWidth(self.contentView.bounds), |
| 62 CGRectGetWidth(self.contentView.bounds), | 63 cancelButtonY, cancelButtonWidth, |
| 63 cancelButtonY, cancelButtonWidth, | 64 cancelButtonHeight))]; |
| 64 cancelButtonHeight))]); | |
| 65 self.cancelButton = button; | 65 self.cancelButton = button; |
| 66 self.cancelButton.extendedEdges = UIEdgeInsetsMakeDirected( | 66 self.cancelButton.extendedEdges = UIEdgeInsetsMakeDirected( |
| 67 cancelButtonY, cancelButtonX, cancelButtonY, cancelButtonX); | 67 cancelButtonY, cancelButtonX, cancelButtonY, cancelButtonX); |
| 68 self.cancelButton.autoresizingMask = | 68 self.cancelButton.autoresizingMask = |
| 69 UIViewAutoresizingFlexibleTrailingMargin(); | 69 UIViewAutoresizingFlexibleTrailingMargin(); |
| 70 self.cancelButton.backgroundColor = [UIColor clearColor]; | 70 self.cancelButton.backgroundColor = [UIColor clearColor]; |
| 71 UIImage* cancelImage = [UIImage imageNamed:@"bookmark_white_close"]; | 71 UIImage* cancelImage = [UIImage imageNamed:@"bookmark_white_close"]; |
| 72 [self.cancelButton setBackgroundImage:cancelImage | 72 [self.cancelButton setBackgroundImage:cancelImage |
| 73 forState:UIControlStateNormal]; | 73 forState:UIControlStateNormal]; |
| 74 self.cancelButton.accessibilityLabel = | 74 self.cancelButton.accessibilityLabel = |
| 75 l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_CANCEL_BUTTON_LABEL); | 75 l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_CANCEL_BUTTON_LABEL); |
| 76 self.cancelButton.accessibilityIdentifier = @"Exit Edit Mode"; | 76 self.cancelButton.accessibilityIdentifier = @"Exit Edit Mode"; |
| 77 [self.contentView addSubview:self.cancelButton]; | 77 [self.contentView addSubview:self.cancelButton]; |
| 78 | 78 |
| 79 // Add the count label to the right of the cancel button. | 79 // Add the count label to the right of the cancel button. |
| 80 CGFloat labelX = bookmark_utils_ios::titleMargin; | 80 CGFloat labelX = bookmark_utils_ios::titleMargin; |
| 81 CGFloat labelY = 0; | 81 CGFloat labelY = 0; |
| 82 base::scoped_nsobject<UILabel> label([[UILabel alloc] | 82 UILabel* label = [[UILabel alloc] |
| 83 initWithFrame:LayoutRectGetRect(LayoutRectMake( | 83 initWithFrame:LayoutRectGetRect(LayoutRectMake( |
| 84 labelX, CGRectGetWidth(self.contentView.bounds), | 84 labelX, CGRectGetWidth(self.contentView.bounds), |
| 85 labelY, 150, CGRectGetHeight(bounds)))]); | 85 labelY, 150, CGRectGetHeight(bounds)))]; |
| 86 self.countLabel = label; | 86 self.countLabel = label; |
| 87 self.countLabel.textColor = [UIColor whiteColor]; | 87 self.countLabel.textColor = [UIColor whiteColor]; |
| 88 self.countLabel.autoresizingMask = | 88 self.countLabel.autoresizingMask = |
| 89 UIViewAutoresizingFlexibleTrailingMargin(); | 89 UIViewAutoresizingFlexibleTrailingMargin(); |
| 90 self.countLabel.font = [MDCTypography titleFont]; | 90 self.countLabel.font = [MDCTypography titleFont]; |
| 91 self.countLabel.backgroundColor = [UIColor clearColor]; | 91 self.countLabel.backgroundColor = [UIColor clearColor]; |
| 92 [self.contentView addSubview:self.countLabel]; | 92 [self.contentView addSubview:self.countLabel]; |
| 93 | 93 |
| 94 // Add the edit button to the right side of the bar. | 94 // Add the edit button to the right side of the bar. |
| 95 CGFloat editButtonWidth = 24; | 95 CGFloat editButtonWidth = 24; |
| 96 CGFloat editButtonHeight = 24; | 96 CGFloat editButtonHeight = 24; |
| 97 // The margin is the same to the top, the bottom, and the right. | 97 // The margin is the same to the top, the bottom, and the right. |
| 98 CGFloat editButtonY = floor((bounds.size.height - editButtonHeight) / 2); | 98 CGFloat editButtonY = floor((bounds.size.height - editButtonHeight) / 2); |
| 99 CGFloat editButtonRightMargin = editButtonY; | 99 CGFloat editButtonRightMargin = editButtonY; |
| 100 CGFloat editButtonX = | 100 CGFloat editButtonX = |
| 101 bounds.size.width - editButtonRightMargin - editButtonWidth; | 101 bounds.size.width - editButtonRightMargin - editButtonWidth; |
| 102 button.reset([[BookmarkExtendedButton alloc] | 102 button = [[BookmarkExtendedButton alloc] |
| 103 initWithFrame:LayoutRectGetRect(LayoutRectMake( | 103 initWithFrame:LayoutRectGetRect(LayoutRectMake( |
| 104 editButtonX, CGRectGetWidth(self.contentView.bounds), | 104 editButtonX, CGRectGetWidth(self.contentView.bounds), |
| 105 editButtonY, editButtonWidth, editButtonHeight))]); | 105 editButtonY, editButtonWidth, editButtonHeight))]; |
| 106 self.editButton = button; | 106 self.editButton = button; |
| 107 self.editButton.extendedEdges = | 107 self.editButton.extendedEdges = |
| 108 UIEdgeInsetsMakeDirected(editButtonY, kInterButtonMargin / 2.0, | 108 UIEdgeInsetsMakeDirected(editButtonY, kInterButtonMargin / 2.0, |
| 109 editButtonY, editButtonRightMargin); | 109 editButtonY, editButtonRightMargin); |
| 110 self.editButton.autoresizingMask = | 110 self.editButton.autoresizingMask = |
| 111 UIViewAutoresizingFlexibleLeadingMargin(); | 111 UIViewAutoresizingFlexibleLeadingMargin(); |
| 112 self.editButton.backgroundColor = [UIColor clearColor]; | 112 self.editButton.backgroundColor = [UIColor clearColor]; |
| 113 UIImage* editImage = [UIImage imageNamed:@"bookmark_white_edit"]; | 113 UIImage* editImage = [UIImage imageNamed:@"bookmark_white_edit"]; |
| 114 [self.editButton setBackgroundImage:editImage | 114 [self.editButton setBackgroundImage:editImage |
| 115 forState:UIControlStateNormal]; | 115 forState:UIControlStateNormal]; |
| 116 self.editButton.accessibilityLabel = | 116 self.editButton.accessibilityLabel = |
| 117 l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_EDIT_BUTTON_LABEL); | 117 l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_EDIT_BUTTON_LABEL); |
| 118 self.editButton.accessibilityIdentifier = @"Edit_editing_bar"; | 118 self.editButton.accessibilityIdentifier = @"Edit_editing_bar"; |
| 119 [self.contentView addSubview:self.editButton]; | 119 [self.contentView addSubview:self.editButton]; |
| 120 | 120 |
| 121 // Add the move button to the same position as the edit button. | 121 // Add the move button to the same position as the edit button. |
| 122 button.reset( | 122 button = |
| 123 [[BookmarkExtendedButton alloc] initWithFrame:self.editButton.frame]); | 123 [[BookmarkExtendedButton alloc] initWithFrame:self.editButton.frame]; |
| 124 self.moveButton = button; | 124 self.moveButton = button; |
| 125 self.moveButton.extendedEdges = | 125 self.moveButton.extendedEdges = |
| 126 UIEdgeInsetsMakeDirected(editButtonY, kInterButtonMargin / 2.0, | 126 UIEdgeInsetsMakeDirected(editButtonY, kInterButtonMargin / 2.0, |
| 127 editButtonY, editButtonRightMargin); | 127 editButtonY, editButtonRightMargin); |
| 128 self.moveButton.autoresizingMask = | 128 self.moveButton.autoresizingMask = |
| 129 UIViewAutoresizingFlexibleLeadingMargin(); | 129 UIViewAutoresizingFlexibleLeadingMargin(); |
| 130 self.moveButton.backgroundColor = [UIColor clearColor]; | 130 self.moveButton.backgroundColor = [UIColor clearColor]; |
| 131 UIImage* moveImage = [UIImage imageNamed:@"bookmark_white_move"]; | 131 UIImage* moveImage = [UIImage imageNamed:@"bookmark_white_move"]; |
| 132 [self.moveButton setBackgroundImage:moveImage | 132 [self.moveButton setBackgroundImage:moveImage |
| 133 forState:UIControlStateNormal]; | 133 forState:UIControlStateNormal]; |
| 134 self.moveButton.accessibilityLabel = | 134 self.moveButton.accessibilityLabel = |
| 135 l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_MOVE_BUTTON_LABEL); | 135 l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_MOVE_BUTTON_LABEL); |
| 136 self.moveButton.accessibilityIdentifier = @"Move"; | 136 self.moveButton.accessibilityIdentifier = @"Move"; |
| 137 [self.contentView addSubview:self.moveButton]; | 137 [self.contentView addSubview:self.moveButton]; |
| 138 | 138 |
| 139 // Add the delete button to the left of the edit button. | 139 // Add the delete button to the left of the edit button. |
| 140 CGFloat deleteButtonWidth = 24; | 140 CGFloat deleteButtonWidth = 24; |
| 141 CGFloat deleteButtonHeight = 24; | 141 CGFloat deleteButtonHeight = 24; |
| 142 CGFloat deleteButtonY = | 142 CGFloat deleteButtonY = |
| 143 floor((bounds.size.height - deleteButtonHeight) / 2); | 143 floor((bounds.size.height - deleteButtonHeight) / 2); |
| 144 CGFloat deleteButtonX = | 144 CGFloat deleteButtonX = |
| 145 CGRectGetLeadingLayoutOffsetInBoundingRect(self.editButton.frame, | 145 CGRectGetLeadingLayoutOffsetInBoundingRect(self.editButton.frame, |
| 146 self.contentView.bounds) - | 146 self.contentView.bounds) - |
| 147 kInterButtonMargin - deleteButtonWidth; | 147 kInterButtonMargin - deleteButtonWidth; |
| 148 button.reset([[BookmarkExtendedButton alloc] | 148 button = [[BookmarkExtendedButton alloc] |
| 149 initWithFrame:LayoutRectGetRect(LayoutRectMake( | 149 initWithFrame:LayoutRectGetRect(LayoutRectMake( |
| 150 deleteButtonX, | 150 deleteButtonX, |
| 151 CGRectGetWidth(self.contentView.bounds), | 151 CGRectGetWidth(self.contentView.bounds), |
| 152 deleteButtonY, deleteButtonWidth, | 152 deleteButtonY, deleteButtonWidth, |
| 153 deleteButtonHeight))]); | 153 deleteButtonHeight))]; |
| 154 self.deleteButton = button; | 154 self.deleteButton = button; |
| 155 self.deleteButton.extendedEdges = UIEdgeInsetsMakeDirected( | 155 self.deleteButton.extendedEdges = UIEdgeInsetsMakeDirected( |
| 156 deleteButtonY, deleteButtonY, deleteButtonY, kInterButtonMargin / 2.0); | 156 deleteButtonY, deleteButtonY, deleteButtonY, kInterButtonMargin / 2.0); |
| 157 self.deleteButton.autoresizingMask = | 157 self.deleteButton.autoresizingMask = |
| 158 UIViewAutoresizingFlexibleLeadingMargin(); | 158 UIViewAutoresizingFlexibleLeadingMargin(); |
| 159 self.deleteButton.backgroundColor = [UIColor clearColor]; | 159 self.deleteButton.backgroundColor = [UIColor clearColor]; |
| 160 UIImage* deleteImage = [UIImage imageNamed:@"bookmark_white_delete"]; | 160 UIImage* deleteImage = [UIImage imageNamed:@"bookmark_white_delete"]; |
| 161 [self.deleteButton setBackgroundImage:deleteImage | 161 [self.deleteButton setBackgroundImage:deleteImage |
| 162 forState:UIControlStateNormal]; | 162 forState:UIControlStateNormal]; |
| 163 self.deleteButton.accessibilityLabel = | 163 self.deleteButton.accessibilityLabel = |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 self.editButton.hidden = YES; | 243 self.editButton.hidden = YES; |
| 244 self.moveButton.hidden = NO; | 244 self.moveButton.hidden = NO; |
| 245 self.deleteButton.hidden = NO; | 245 self.deleteButton.hidden = NO; |
| 246 } | 246 } |
| 247 | 247 |
| 248 - (void)showShadow:(BOOL)show { | 248 - (void)showShadow:(BOOL)show { |
| 249 self.dropShadow.hidden = !show; | 249 self.dropShadow.hidden = !show; |
| 250 } | 250 } |
| 251 | 251 |
| 252 @end | 252 @end |
| OLD | NEW |