OLD | NEW |
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/history/clear_browsing_bar.h" | 5 #import "ios/chrome/browser/ui/history/clear_browsing_bar.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/mac/objc_property_releaser.h" | |
9 #include "components/strings/grit/components_strings.h" | 8 #include "components/strings/grit/components_strings.h" |
10 #include "ios/chrome/browser/ui/rtl_geometry.h" | 9 #include "ios/chrome/browser/ui/rtl_geometry.h" |
11 #import "ios/chrome/browser/ui/uikit_ui_util.h" | 10 #import "ios/chrome/browser/ui/uikit_ui_util.h" |
12 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" | 11 #import "ios/third_party/material_components_ios/src/components/Palettes/src/Mat
erialPalettes.h" |
13 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" | 12 #import "ios/third_party/material_components_ios/src/components/Typography/src/M
aterialTypography.h" |
14 #include "ui/base/l10n/l10n_util_mac.h" | 13 #include "ui/base/l10n/l10n_util_mac.h" |
15 | 14 |
| 15 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 16 #error "This file requires ARC support." |
| 17 #endif |
| 18 |
16 namespace { | 19 namespace { |
17 // Shadow opacity for the clear browsing bar. | 20 // Shadow opacity for the clear browsing bar. |
18 CGFloat kShadowOpacity = 0.2f; | 21 CGFloat kShadowOpacity = 0.2f; |
19 // Horizontal margin for the contents of ClearBrowsingBar. | 22 // Horizontal margin for the contents of ClearBrowsingBar. |
20 CGFloat kHorizontalMargin = 8.0f; | 23 CGFloat kHorizontalMargin = 8.0f; |
21 // Enum to specify button position in the clear browsing bar. | 24 // Enum to specify button position in the clear browsing bar. |
22 typedef NS_ENUM(BOOL, ButtonPlacement) { Leading, Trailing }; | 25 typedef NS_ENUM(BOOL, ButtonPlacement) { Leading, Trailing }; |
23 } // namespace | 26 } // namespace |
24 | 27 |
25 @interface ClearBrowsingBar () { | 28 @interface ClearBrowsingBar () |
26 base::mac::ObjCPropertyReleaser propertyReleaser_ClearBrowsingBar_; | |
27 } | |
28 | 29 |
29 // Button that displays "Clear Browsing Data...". | 30 // Button that displays "Clear Browsing Data...". |
30 @property(nonatomic, strong) UIButton* clearBrowsingDataButton; | 31 @property(nonatomic, strong) UIButton* clearBrowsingDataButton; |
31 // Button that displays "Edit". | 32 // Button that displays "Edit". |
32 @property(nonatomic, strong) UIButton* editButton; | 33 @property(nonatomic, strong) UIButton* editButton; |
33 // Button that displays "Delete". | 34 // Button that displays "Delete". |
34 @property(nonatomic, strong) UIButton* deleteButton; | 35 @property(nonatomic, strong) UIButton* deleteButton; |
35 // Button that displays "Cancel". | 36 // Button that displays "Cancel". |
36 @property(nonatomic, strong) UIButton* cancelButton; | 37 @property(nonatomic, strong) UIButton* cancelButton; |
37 // Stack view for arranging the buttons. | 38 // Stack view for arranging the buttons. |
(...skipping 11 matching lines...) Expand all Loading... |
49 @synthesize editing = _editing; | 50 @synthesize editing = _editing; |
50 @synthesize clearBrowsingDataButton = _clearBrowsingDataButton; | 51 @synthesize clearBrowsingDataButton = _clearBrowsingDataButton; |
51 @synthesize editButton = _editButton; | 52 @synthesize editButton = _editButton; |
52 @synthesize deleteButton = _deleteButton; | 53 @synthesize deleteButton = _deleteButton; |
53 @synthesize cancelButton = _cancelButton; | 54 @synthesize cancelButton = _cancelButton; |
54 @synthesize stackView = _stackView; | 55 @synthesize stackView = _stackView; |
55 | 56 |
56 - (instancetype)initWithFrame:(CGRect)frame { | 57 - (instancetype)initWithFrame:(CGRect)frame { |
57 self = [super initWithFrame:frame]; | 58 self = [super initWithFrame:frame]; |
58 if (self) { | 59 if (self) { |
59 _clearBrowsingDataButton = | 60 _clearBrowsingDataButton = [UIButton buttonWithType:UIButtonTypeCustom]; |
60 [[UIButton buttonWithType:UIButtonTypeCustom] retain]; | |
61 [_clearBrowsingDataButton | 61 [_clearBrowsingDataButton |
62 setTitle:l10n_util::GetNSStringWithFixup( | 62 setTitle:l10n_util::GetNSStringWithFixup( |
63 IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG) | 63 IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG) |
64 forState:UIControlStateNormal]; | 64 forState:UIControlStateNormal]; |
65 [self styleButton:_clearBrowsingDataButton forPlacement:Leading]; | 65 [self styleButton:_clearBrowsingDataButton forPlacement:Leading]; |
66 | 66 |
67 _editButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; | 67 _editButton = [UIButton buttonWithType:UIButtonTypeCustom]; |
68 [_editButton | 68 [_editButton |
69 setTitle:l10n_util::GetNSString(IDS_HISTORY_START_EDITING_BUTTON) | 69 setTitle:l10n_util::GetNSString(IDS_HISTORY_START_EDITING_BUTTON) |
70 forState:UIControlStateNormal]; | 70 forState:UIControlStateNormal]; |
71 [self styleButton:_editButton forPlacement:Trailing]; | 71 [self styleButton:_editButton forPlacement:Trailing]; |
72 | 72 |
73 _deleteButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; | 73 _deleteButton = [UIButton buttonWithType:UIButtonTypeCustom]; |
74 [_deleteButton setTitle:l10n_util::GetNSString( | 74 [_deleteButton setTitle:l10n_util::GetNSString( |
75 IDS_HISTORY_DELETE_SELECTED_ENTRIES_BUTTON) | 75 IDS_HISTORY_DELETE_SELECTED_ENTRIES_BUTTON) |
76 forState:UIControlStateNormal]; | 76 forState:UIControlStateNormal]; |
77 [self styleButton:_deleteButton forPlacement:Leading]; | 77 [self styleButton:_deleteButton forPlacement:Leading]; |
78 | 78 |
79 _cancelButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain]; | 79 _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom]; |
80 [_cancelButton | 80 [_cancelButton |
81 setTitle:l10n_util::GetNSString(IDS_HISTORY_CANCEL_EDITING_BUTTON) | 81 setTitle:l10n_util::GetNSString(IDS_HISTORY_CANCEL_EDITING_BUTTON) |
82 forState:UIControlStateNormal]; | 82 forState:UIControlStateNormal]; |
83 [self styleButton:_cancelButton forPlacement:Trailing]; | 83 [self styleButton:_cancelButton forPlacement:Trailing]; |
84 | 84 |
85 _stackView = [[UIStackView alloc] initWithArrangedSubviews:@[ | 85 _stackView = [[UIStackView alloc] initWithArrangedSubviews:@[ |
86 _clearBrowsingDataButton, _editButton, _deleteButton, _cancelButton | 86 _clearBrowsingDataButton, _editButton, _deleteButton, _cancelButton |
87 ]]; | 87 ]]; |
88 _stackView.alignment = UIStackViewAlignmentFill; | 88 _stackView.alignment = UIStackViewAlignmentFill; |
89 _stackView.distribution = UIStackViewDistributionEqualSpacing; | 89 _stackView.distribution = UIStackViewDistributionEqualSpacing; |
90 _stackView.axis = UILayoutConstraintAxisHorizontal; | 90 _stackView.axis = UILayoutConstraintAxisHorizontal; |
91 | 91 |
92 [self addSubview:_stackView]; | 92 [self addSubview:_stackView]; |
93 _stackView.translatesAutoresizingMaskIntoConstraints = NO; | 93 _stackView.translatesAutoresizingMaskIntoConstraints = NO; |
94 _stackView.layoutMarginsRelativeArrangement = YES; | 94 _stackView.layoutMarginsRelativeArrangement = YES; |
95 [NSLayoutConstraint activateConstraints:@[ | 95 [NSLayoutConstraint activateConstraints:@[ |
96 [_stackView.layoutMarginsGuide.leadingAnchor | 96 [_stackView.layoutMarginsGuide.leadingAnchor |
97 constraintEqualToAnchor:self.leadingAnchor | 97 constraintEqualToAnchor:self.leadingAnchor |
98 constant:kHorizontalMargin], | 98 constant:kHorizontalMargin], |
99 [_stackView.layoutMarginsGuide.trailingAnchor | 99 [_stackView.layoutMarginsGuide.trailingAnchor |
100 constraintEqualToAnchor:self.trailingAnchor | 100 constraintEqualToAnchor:self.trailingAnchor |
101 constant:-kHorizontalMargin], | 101 constant:-kHorizontalMargin], |
102 [_stackView.topAnchor constraintEqualToAnchor:self.topAnchor], | 102 [_stackView.topAnchor constraintEqualToAnchor:self.topAnchor], |
103 [_stackView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor], | 103 [_stackView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor], |
104 ]]; | 104 ]]; |
105 | 105 |
106 [self setBackgroundColor:[UIColor whiteColor]]; | 106 [self setBackgroundColor:[UIColor whiteColor]]; |
107 [[self layer] setShadowOpacity:kShadowOpacity]; | 107 [[self layer] setShadowOpacity:kShadowOpacity]; |
108 [self setEditing:NO]; | 108 [self setEditing:NO]; |
109 propertyReleaser_ClearBrowsingBar_.Init(self, [ClearBrowsingBar class]); | |
110 } | 109 } |
111 return self; | 110 return self; |
112 } | 111 } |
113 | 112 |
114 #pragma mark Public Methods | 113 #pragma mark Public Methods |
115 | 114 |
116 - (void)setEditing:(BOOL)editing { | 115 - (void)setEditing:(BOOL)editing { |
117 _editing = editing; | 116 _editing = editing; |
118 self.clearBrowsingDataButton.hidden = editing; | 117 self.clearBrowsingDataButton.hidden = editing; |
119 self.editButton.hidden = editing; | 118 self.editButton.hidden = editing; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 forState:UIControlStateDisabled]; | 172 forState:UIControlStateDisabled]; |
174 [[button titleLabel] | 173 [[button titleLabel] |
175 setFont:[[MDCTypography fontLoader] regularFontOfSize:14]]; | 174 setFont:[[MDCTypography fontLoader] regularFontOfSize:14]]; |
176 button.contentHorizontalAlignment = | 175 button.contentHorizontalAlignment = |
177 leading ^ UseRTLLayout() ? UIControlContentHorizontalAlignmentLeft | 176 leading ^ UseRTLLayout() ? UIControlContentHorizontalAlignmentLeft |
178 : UIControlContentHorizontalAlignmentRight; | 177 : UIControlContentHorizontalAlignmentRight; |
179 [button setTranslatesAutoresizingMaskIntoConstraints:NO]; | 178 [button setTranslatesAutoresizingMaskIntoConstraints:NO]; |
180 } | 179 } |
181 | 180 |
182 @end | 181 @end |
OLD | NEW |