| 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_navigation_bar.h" | 5 #import "ios/chrome/browser/ui/bookmarks/bars/bookmark_navigation_bar.h" |
| 6 | 6 |
| 7 #import <QuartzCore/QuartzCore.h> | 7 #import <QuartzCore/QuartzCore.h> |
| 8 | |
| 9 #include "base/mac/objc_property_releaser.h" | |
| 10 #include "base/mac/scoped_nsobject.h" | |
| 11 #import "ios/chrome/browser/ui/bookmarks/bookmark_extended_button.h" | 8 #import "ios/chrome/browser/ui/bookmarks/bookmark_extended_button.h" |
| 12 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" | 9 #import "ios/chrome/browser/ui/bookmarks/bookmark_utils_ios.h" |
| 13 #import "ios/chrome/browser/ui/rtl_geometry.h" | 10 #import "ios/chrome/browser/ui/rtl_geometry.h" |
| 14 #include "ios/chrome/browser/ui/ui_util.h" | 11 #include "ios/chrome/browser/ui/ui_util.h" |
| 15 #include "ios/chrome/grit/ios_strings.h" | 12 #include "ios/chrome/grit/ios_strings.h" |
| 16 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 13 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
| 18 | 15 |
| 16 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 17 #error "This file requires ARC support." |
| 18 #endif |
| 19 |
| 19 namespace { | 20 namespace { |
| 20 const CGFloat kButtonHeight = 24; | 21 const CGFloat kButtonHeight = 24; |
| 21 const CGFloat kButtonWidth = 24; | 22 const CGFloat kButtonWidth = 24; |
| 22 | 23 |
| 23 // The height of the content, not including possible extra space for the status | 24 // The height of the content, not including possible extra space for the status |
| 24 // bar. | 25 // bar. |
| 25 const CGFloat kContentHeight = 56; | 26 const CGFloat kContentHeight = 56; |
| 26 // The distance between buttons. | 27 // The distance between buttons. |
| 27 const CGFloat kInterButtonMargin = 24; | 28 const CGFloat kInterButtonMargin = 24; |
| 28 }; // namespace | 29 }; // namespace |
| 29 | 30 |
| 30 @interface BookmarkNavigationBar () { | 31 @interface BookmarkNavigationBar () |
| 31 base::mac::ObjCPropertyReleaser _propertyReleaser_BookmarkNavigationBar; | 32 |
| 32 } | 33 @property(nonatomic, strong) BookmarkExtendedButton* cancelButton; |
| 33 @property(nonatomic, retain) BookmarkExtendedButton* cancelButton; | |
| 34 // All subviews are added to |contentView|, which allows easy repositioning of | 34 // All subviews are added to |contentView|, which allows easy repositioning of |
| 35 // the content to account for iOS 6 and iOS 7+ layout differences. | 35 // the content to account for iOS 6 and iOS 7+ layout differences. |
| 36 @property(nonatomic, retain) UIView* contentView; | 36 @property(nonatomic, strong) UIView* contentView; |
| 37 @property(nonatomic, retain) BookmarkExtendedButton* backButton; | 37 @property(nonatomic, strong) BookmarkExtendedButton* backButton; |
| 38 @property(nonatomic, retain) BookmarkExtendedButton* editButton; | 38 @property(nonatomic, strong) BookmarkExtendedButton* editButton; |
| 39 @property(nonatomic, retain) BookmarkExtendedButton* menuButton; | 39 @property(nonatomic, strong) BookmarkExtendedButton* menuButton; |
| 40 @property(nonatomic, retain) UILabel* titleLabel; | 40 @property(nonatomic, strong) UILabel* titleLabel; |
| 41 @end | 41 @end |
| 42 | 42 |
| 43 @implementation BookmarkNavigationBar | 43 @implementation BookmarkNavigationBar |
| 44 @synthesize backButton = _backButton; | 44 @synthesize backButton = _backButton; |
| 45 @synthesize cancelButton = _cancelButton; | 45 @synthesize cancelButton = _cancelButton; |
| 46 @synthesize contentView = _contentView; | 46 @synthesize contentView = _contentView; |
| 47 @synthesize editButton = _editButton; | 47 @synthesize editButton = _editButton; |
| 48 @synthesize menuButton = _menuButton; | 48 @synthesize menuButton = _menuButton; |
| 49 @synthesize titleLabel = _titleLabel; | 49 @synthesize titleLabel = _titleLabel; |
| 50 | 50 |
| 51 - (id)initWithFrame:(CGRect)outerFrame { | 51 - (id)initWithFrame:(CGRect)outerFrame { |
| 52 self = [super initWithFrame:outerFrame]; | 52 self = [super initWithFrame:outerFrame]; |
| 53 if (self) { | 53 if (self) { |
| 54 _propertyReleaser_BookmarkNavigationBar.Init(self, | |
| 55 [BookmarkNavigationBar class]); | |
| 56 | |
| 57 self.backgroundColor = bookmark_utils_ios::mainBackgroundColor(); | 54 self.backgroundColor = bookmark_utils_ios::mainBackgroundColor(); |
| 58 self.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | | 55 self.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | |
| 59 UIViewAutoresizingFlexibleWidth; | 56 UIViewAutoresizingFlexibleWidth; |
| 60 | 57 |
| 61 // Position the content view at the bottom of |self|. | 58 // Position the content view at the bottom of |self|. |
| 62 CGFloat contentY = CGRectGetHeight(outerFrame) - kContentHeight; | 59 CGFloat contentY = CGRectGetHeight(outerFrame) - kContentHeight; |
| 63 self.contentView = base::scoped_nsobject<UIView>([[UIView alloc] | 60 self.contentView = [[UIView alloc] |
| 64 initWithFrame:CGRectMake(0, contentY, CGRectGetWidth(outerFrame), | 61 initWithFrame:CGRectMake(0, contentY, CGRectGetWidth(outerFrame), |
| 65 kContentHeight)]); | 62 kContentHeight)]; |
| 66 [self addSubview:self.contentView]; | 63 [self addSubview:self.contentView]; |
| 67 self.contentView.backgroundColor = [UIColor clearColor]; | 64 self.contentView.backgroundColor = [UIColor clearColor]; |
| 68 self.contentView.autoresizingMask = | 65 self.contentView.autoresizingMask = |
| 69 UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth; | 66 UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth; |
| 70 CGRect contentViewBounds = self.contentView.bounds; | 67 CGRect contentViewBounds = self.contentView.bounds; |
| 71 | 68 |
| 72 base::scoped_nsobject<UILabel> label([[UILabel alloc] init]); | 69 UILabel* label = [[UILabel alloc] init]; |
| 73 self.titleLabel = label; | 70 self.titleLabel = label; |
| 74 self.titleLabel.textColor = [UIColor colorWithWhite:68 / 255.0 alpha:1.0]; | 71 self.titleLabel.textColor = [UIColor colorWithWhite:68 / 255.0 alpha:1.0]; |
| 75 self.titleLabel.backgroundColor = [UIColor clearColor]; | 72 self.titleLabel.backgroundColor = [UIColor clearColor]; |
| 76 self.titleLabel.font = [MDCTypography titleFont]; | 73 self.titleLabel.font = [MDCTypography titleFont]; |
| 77 [self.contentView addSubview:self.titleLabel]; | 74 [self.contentView addSubview:self.titleLabel]; |
| 78 | 75 |
| 79 // The buttons should be on the right side of the screen. | 76 // The buttons should be on the right side of the screen. |
| 80 CGFloat buttonVerticalMargin = | 77 CGFloat buttonVerticalMargin = |
| 81 floor((CGRectGetHeight(contentViewBounds) - kButtonHeight) / 2); | 78 floor((CGRectGetHeight(contentViewBounds) - kButtonHeight) / 2); |
| 82 CGFloat buttonSideMargin = buttonVerticalMargin; | 79 CGFloat buttonSideMargin = buttonVerticalMargin; |
| 83 if (IsIPadIdiom()) | 80 if (IsIPadIdiom()) |
| 84 buttonSideMargin = kInterButtonMargin; | 81 buttonSideMargin = kInterButtonMargin; |
| 85 | 82 |
| 86 CGFloat buttonX = CGRectGetWidth(contentViewBounds) - buttonSideMargin; | 83 CGFloat buttonX = CGRectGetWidth(contentViewBounds) - buttonSideMargin; |
| 87 | 84 |
| 88 if (!IsIPadIdiom()) { | 85 if (!IsIPadIdiom()) { |
| 89 base::scoped_nsobject<BookmarkExtendedButton> button( | 86 BookmarkExtendedButton* button = |
| 90 [[BookmarkExtendedButton alloc] initWithFrame:CGRectZero]); | 87 [[BookmarkExtendedButton alloc] initWithFrame:CGRectZero]; |
| 91 | 88 |
| 92 self.cancelButton = button; | 89 self.cancelButton = button; |
| 93 self.cancelButton.autoresizingMask = | 90 self.cancelButton.autoresizingMask = |
| 94 UIViewAutoresizingFlexibleLeadingMargin(); | 91 UIViewAutoresizingFlexibleLeadingMargin(); |
| 95 self.cancelButton.backgroundColor = [UIColor clearColor]; | 92 self.cancelButton.backgroundColor = [UIColor clearColor]; |
| 96 [self.cancelButton | 93 [self.cancelButton |
| 97 setTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON) | 94 setTitle:l10n_util::GetNSString(IDS_IOS_NAVIGATION_BAR_DONE_BUTTON) |
| 98 .uppercaseString | 95 .uppercaseString |
| 99 forState:UIControlStateNormal]; | 96 forState:UIControlStateNormal]; |
| 100 [self.cancelButton | 97 [self.cancelButton |
| (...skipping 20 matching lines...) Expand all Loading... |
| 121 buttonX = buttonX - kInterButtonMargin; | 118 buttonX = buttonX - kInterButtonMargin; |
| 122 } | 119 } |
| 123 | 120 |
| 124 CGRect buttonFrame = LayoutRectGetRect( | 121 CGRect buttonFrame = LayoutRectGetRect( |
| 125 LayoutRectMake(buttonX - kButtonWidth, CGRectGetWidth(self.bounds), | 122 LayoutRectMake(buttonX - kButtonWidth, CGRectGetWidth(self.bounds), |
| 126 buttonVerticalMargin, kButtonWidth, kButtonHeight)); | 123 buttonVerticalMargin, kButtonWidth, kButtonHeight)); |
| 127 UIEdgeInsets buttonInsets = | 124 UIEdgeInsets buttonInsets = |
| 128 UIEdgeInsetsMake(buttonVerticalMargin, kInterButtonMargin / 2.0, | 125 UIEdgeInsetsMake(buttonVerticalMargin, kInterButtonMargin / 2.0, |
| 129 buttonVerticalMargin, kInterButtonMargin / 2.0); | 126 buttonVerticalMargin, kInterButtonMargin / 2.0); |
| 130 | 127 |
| 131 base::scoped_nsobject<BookmarkExtendedButton> editButton( | 128 BookmarkExtendedButton* editButton = |
| 132 [[BookmarkExtendedButton alloc] initWithFrame:buttonFrame]); | 129 [[BookmarkExtendedButton alloc] initWithFrame:buttonFrame]; |
| 133 self.editButton = editButton; | 130 self.editButton = editButton; |
| 134 self.editButton.extendedEdges = buttonInsets; | 131 self.editButton.extendedEdges = buttonInsets; |
| 135 self.editButton.autoresizingMask = | 132 self.editButton.autoresizingMask = |
| 136 UIViewAutoresizingFlexibleLeadingMargin(); | 133 UIViewAutoresizingFlexibleLeadingMargin(); |
| 137 self.editButton.backgroundColor = [UIColor clearColor]; | 134 self.editButton.backgroundColor = [UIColor clearColor]; |
| 138 UIImage* editImage = [UIImage imageNamed:@"bookmark_gray_edit"]; | 135 UIImage* editImage = [UIImage imageNamed:@"bookmark_gray_edit"]; |
| 139 [self.editButton setBackgroundImage:editImage | 136 [self.editButton setBackgroundImage:editImage |
| 140 forState:UIControlStateNormal]; | 137 forState:UIControlStateNormal]; |
| 141 self.editButton.accessibilityLabel = | 138 self.editButton.accessibilityLabel = |
| 142 l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_EDIT_BUTTON_LABEL); | 139 l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_EDIT_BUTTON_LABEL); |
| 143 self.editButton.accessibilityIdentifier = @"Edit_navigation_bar"; | 140 self.editButton.accessibilityIdentifier = @"Edit_navigation_bar"; |
| 144 [self.contentView addSubview:self.editButton]; | 141 [self.contentView addSubview:self.editButton]; |
| 145 | 142 |
| 146 CGRect leftButtonFrame = LayoutRectGetRect( | 143 CGRect leftButtonFrame = LayoutRectGetRect( |
| 147 LayoutRectMake(buttonSideMargin, CGRectGetWidth(self.bounds), | 144 LayoutRectMake(buttonSideMargin, CGRectGetWidth(self.bounds), |
| 148 buttonVerticalMargin, kButtonWidth, kButtonHeight)); | 145 buttonVerticalMargin, kButtonWidth, kButtonHeight)); |
| 149 UIEdgeInsets leftButtonInsets = | 146 UIEdgeInsets leftButtonInsets = |
| 150 UIEdgeInsetsMake(buttonVerticalMargin, buttonSideMargin, | 147 UIEdgeInsetsMake(buttonVerticalMargin, buttonSideMargin, |
| 151 buttonVerticalMargin, buttonSideMargin); | 148 buttonVerticalMargin, buttonSideMargin); |
| 152 | 149 |
| 153 base::scoped_nsobject<BookmarkExtendedButton> menuButton( | 150 BookmarkExtendedButton* menuButton = |
| 154 [[BookmarkExtendedButton alloc] initWithFrame:leftButtonFrame]); | 151 [[BookmarkExtendedButton alloc] initWithFrame:leftButtonFrame]; |
| 155 self.menuButton = menuButton; | 152 self.menuButton = menuButton; |
| 156 self.menuButton.extendedEdges = leftButtonInsets; | 153 self.menuButton.extendedEdges = leftButtonInsets; |
| 157 self.menuButton.autoresizingMask = | 154 self.menuButton.autoresizingMask = |
| 158 UIViewAutoresizingFlexibleTrailingMargin(); | 155 UIViewAutoresizingFlexibleTrailingMargin(); |
| 159 self.menuButton.backgroundColor = [UIColor clearColor]; | 156 self.menuButton.backgroundColor = [UIColor clearColor]; |
| 160 UIImage* menuImage = [UIImage imageNamed:@"bookmark_gray_menu"]; | 157 UIImage* menuImage = [UIImage imageNamed:@"bookmark_gray_menu"]; |
| 161 [self.menuButton setBackgroundImage:menuImage | 158 [self.menuButton setBackgroundImage:menuImage |
| 162 forState:UIControlStateNormal]; | 159 forState:UIControlStateNormal]; |
| 163 self.menuButton.accessibilityLabel = | 160 self.menuButton.accessibilityLabel = |
| 164 l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_MENU_LABEL); | 161 l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_MENU_LABEL); |
| 165 self.menuButton.accessibilityIdentifier = @"Menu"; | 162 self.menuButton.accessibilityIdentifier = @"Menu"; |
| 166 [self.contentView addSubview:self.menuButton]; | 163 [self.contentView addSubview:self.menuButton]; |
| 167 self.menuButton.hidden = YES; | 164 self.menuButton.hidden = YES; |
| 168 base::scoped_nsobject<BookmarkExtendedButton> backButton( | 165 BookmarkExtendedButton* backButton = |
| 169 [[BookmarkExtendedButton alloc] initWithFrame:leftButtonFrame]); | 166 [[BookmarkExtendedButton alloc] initWithFrame:leftButtonFrame]; |
| 170 self.backButton = backButton; | 167 self.backButton = backButton; |
| 171 self.backButton.extendedEdges = leftButtonInsets; | 168 self.backButton.extendedEdges = leftButtonInsets; |
| 172 self.backButton.autoresizingMask = | 169 self.backButton.autoresizingMask = |
| 173 UIViewAutoresizingFlexibleTrailingMargin(); | 170 UIViewAutoresizingFlexibleTrailingMargin(); |
| 174 self.backButton.backgroundColor = [UIColor clearColor]; | 171 self.backButton.backgroundColor = [UIColor clearColor]; |
| 175 UIImage* backImage = [UIImage imageNamed:@"bookmark_gray_back"]; | 172 UIImage* backImage = [UIImage imageNamed:@"bookmark_gray_back"]; |
| 176 [self.backButton setBackgroundImage:backImage | 173 [self.backButton setBackgroundImage:backImage |
| 177 forState:UIControlStateNormal]; | 174 forState:UIControlStateNormal]; |
| 178 self.backButton.accessibilityLabel = | 175 self.backButton.accessibilityLabel = |
| 179 l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_BACK_LABEL); | 176 l10n_util::GetNSString(IDS_IOS_BOOKMARK_NEW_BACK_LABEL); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 self.backButton.alpha = 1.0; | 348 self.backButton.alpha = 1.0; |
| 352 } | 349 } |
| 353 completion:^(BOOL finished) { | 350 completion:^(BOOL finished) { |
| 354 if (finished) { | 351 if (finished) { |
| 355 [self setNeedsLayout]; | 352 [self setNeedsLayout]; |
| 356 } | 353 } |
| 357 }]; | 354 }]; |
| 358 } | 355 } |
| 359 | 356 |
| 360 @end | 357 @end |
| OLD | NEW |