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

Side by Side Diff: ios/chrome/browser/ui/history/clear_browsing_bar.mm

Issue 2590473002: Upstream Chrome on iOS source code [5/11]. (Closed)
Patch Set: Created 4 years 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
(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/history/clear_browsing_bar.h"
6
7 #include "base/logging.h"
8 #include "base/mac/objc_property_releaser.h"
9 #include "components/strings/grit/components_strings.h"
10 #include "ios/chrome/browser/ui/rtl_geometry.h"
11 #import "ios/chrome/browser/ui/uikit_ui_util.h"
12 #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"
14 #include "ui/base/l10n/l10n_util_mac.h"
15
16 namespace {
17 // Shadow opacity for the clear browsing bar.
18 CGFloat kShadowOpacity = 0.2f;
19 // Horizontal margin for the contents of ClearBrowsingBar.
20 CGFloat kHorizontalMargin = 8.0f;
21 // Enum to specify button position in the clear browsing bar.
22 typedef NS_ENUM(BOOL, ButtonPlacement) { Leading, Trailing };
23 } // namespace
24
25 @interface ClearBrowsingBar () {
26 base::mac::ObjCPropertyReleaser propertyReleaser_ClearBrowsingBar_;
27 }
28
29 // Button that displays "Clear Browsing Data...".
30 @property(nonatomic, strong) UIButton* clearBrowsingDataButton;
31 // Button that displays "Edit".
32 @property(nonatomic, strong) UIButton* editButton;
33 // Button that displays "Delete".
34 @property(nonatomic, strong) UIButton* deleteButton;
35 // Button that displays "Cancel".
36 @property(nonatomic, strong) UIButton* cancelButton;
37 // Stack view for arranging the buttons.
38 @property(nonatomic, strong) UIStackView* stackView;
39
40 // Styles button for Leading or Trailing placement. Leading buttons have red
41 // text that is aligned to the leading edge. Trailing buttons have blue text
42 // that is aligned to the trailing edge.
43 - (void)styleButton:(UIButton*)button forPlacement:(ButtonPlacement)placement;
44
45 @end
46
47 @implementation ClearBrowsingBar
48
49 @synthesize editing = _editing;
50 @synthesize clearBrowsingDataButton = _clearBrowsingDataButton;
51 @synthesize editButton = _editButton;
52 @synthesize deleteButton = _deleteButton;
53 @synthesize cancelButton = _cancelButton;
54 @synthesize stackView = _stackView;
55
56 - (instancetype)initWithFrame:(CGRect)frame {
57 self = [super initWithFrame:frame];
58 if (self) {
59 _clearBrowsingDataButton =
60 [[UIButton buttonWithType:UIButtonTypeCustom] retain];
61 [_clearBrowsingDataButton
62 setTitle:l10n_util::GetNSStringWithFixup(
63 IDS_HISTORY_OPEN_CLEAR_BROWSING_DATA_DIALOG)
64 forState:UIControlStateNormal];
65 [self styleButton:_clearBrowsingDataButton forPlacement:Leading];
66
67 _editButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
68 [_editButton
69 setTitle:l10n_util::GetNSString(IDS_HISTORY_START_EDITING_BUTTON)
70 forState:UIControlStateNormal];
71 [self styleButton:_editButton forPlacement:Trailing];
72
73 _deleteButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
74 [_deleteButton setTitle:l10n_util::GetNSString(
75 IDS_HISTORY_DELETE_SELECTED_ENTRIES_BUTTON)
76 forState:UIControlStateNormal];
77 [self styleButton:_deleteButton forPlacement:Leading];
78
79 _cancelButton = [[UIButton buttonWithType:UIButtonTypeCustom] retain];
80 [_cancelButton
81 setTitle:l10n_util::GetNSString(IDS_HISTORY_CANCEL_EDITING_BUTTON)
82 forState:UIControlStateNormal];
83 [self styleButton:_cancelButton forPlacement:Trailing];
84
85 _stackView = [[UIStackView alloc] initWithArrangedSubviews:@[
86 _clearBrowsingDataButton, _editButton, _deleteButton, _cancelButton
87 ]];
88 _stackView.alignment = UIStackViewAlignmentFill;
89 _stackView.distribution = UIStackViewDistributionEqualSpacing;
90 _stackView.axis = UILayoutConstraintAxisHorizontal;
91
92 [self addSubview:_stackView];
93 _stackView.translatesAutoresizingMaskIntoConstraints = NO;
94 _stackView.layoutMarginsRelativeArrangement = YES;
95 [NSLayoutConstraint activateConstraints:@[
96 [_stackView.layoutMarginsGuide.leadingAnchor
97 constraintEqualToAnchor:self.leadingAnchor
98 constant:kHorizontalMargin],
99 [_stackView.layoutMarginsGuide.trailingAnchor
100 constraintEqualToAnchor:self.trailingAnchor
101 constant:-kHorizontalMargin],
102 [_stackView.topAnchor constraintEqualToAnchor:self.topAnchor],
103 [_stackView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor],
104 ]];
105
106 [self setBackgroundColor:[UIColor whiteColor]];
107 [[self layer] setShadowOpacity:kShadowOpacity];
108 [self setEditing:NO];
109 propertyReleaser_ClearBrowsingBar_.Init(self, [ClearBrowsingBar class]);
110 }
111 return self;
112 }
113
114 #pragma mark Public Methods
115
116 - (void)setEditing:(BOOL)editing {
117 _editing = editing;
118 self.clearBrowsingDataButton.hidden = editing;
119 self.editButton.hidden = editing;
120 self.deleteButton.hidden = !editing;
121 self.cancelButton.hidden = !editing;
122 }
123
124 - (BOOL)isEditButtonEnabled {
125 return self.editButton.enabled;
126 }
127
128 - (void)setEditButtonEnabled:(BOOL)editButtonEnabled {
129 self.editButton.enabled = editButtonEnabled;
130 }
131
132 - (BOOL)isDeleteButtonEnabled {
133 return self.deleteButton.enabled;
134 }
135
136 - (void)setDeleteButtonEnabled:(BOOL)deleteButtonEnabled {
137 self.deleteButton.enabled = deleteButtonEnabled;
138 }
139
140 - (void)setClearBrowsingDataTarget:(id)target action:(SEL)action {
141 [self.clearBrowsingDataButton addTarget:target
142 action:action
143 forControlEvents:UIControlEventTouchUpInside];
144 }
145
146 - (void)setEditTarget:(id)target action:(SEL)action {
147 [self.editButton addTarget:target
148 action:action
149 forControlEvents:UIControlEventTouchUpInside];
150 }
151
152 - (void)setDeleteTarget:(id)target action:(SEL)action {
153 [self.deleteButton addTarget:target
154 action:action
155 forControlEvents:UIControlEventTouchUpInside];
156 }
157
158 - (void)setCancelTarget:(id)target action:(SEL)action {
159 [self.cancelButton addTarget:target
160 action:action
161 forControlEvents:UIControlEventTouchUpInside];
162 }
163
164 #pragma mark Private Methods
165
166 - (void)styleButton:(UIButton*)button forPlacement:(ButtonPlacement)placement {
167 BOOL leading = placement == Leading;
168 [button setBackgroundColor:[UIColor whiteColor]];
169 UIColor* textColor = leading ? [[MDCPalette redPalette] tint500]
170 : [[MDCPalette bluePalette] tint500];
171 [button setTitleColor:textColor forState:UIControlStateNormal];
172 [button setTitleColor:[[MDCPalette greyPalette] tint500]
173 forState:UIControlStateDisabled];
174 [[button titleLabel]
175 setFont:[[MDCTypography fontLoader] regularFontOfSize:14]];
176 button.contentHorizontalAlignment =
177 leading ^ UseRTLLayout() ? UIControlContentHorizontalAlignmentLeft
178 : UIControlContentHorizontalAlignmentRight;
179 [button setTranslatesAutoresizingMaskIntoConstraints:NO];
180 }
181
182 @end
OLDNEW
« no previous file with comments | « ios/chrome/browser/ui/history/clear_browsing_bar.h ('k') | ios/chrome/browser/ui/history/favicon_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698