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

Side by Side Diff: ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.mm

Issue 2892113002: [ios clean] Fixes Toolbar constraints. (Closed)
Patch Set: Created 3 years, 7 months 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
« no previous file with comments | « ios/clean/chrome/browser/ui/toolbar/toolbar_constants.mm ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/clean/chrome/browser/ui/toolbar/toolbar_view_controller.h" 5 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.h"
6 6
7 #import "base/mac/foundation_util.h" 7 #import "base/mac/foundation_util.h"
8 #import "ios/clean/chrome/browser/ui/actions/tab_strip_actions.h" 8 #import "ios/clean/chrome/browser/ui/actions/tab_strip_actions.h"
9 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h" 9 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h"
10 #import "ios/clean/chrome/browser/ui/commands/tab_grid_commands.h" 10 #import "ios/clean/chrome/browser/ui/commands/tab_grid_commands.h"
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 ]]; 83 ]];
84 self.stackView.translatesAutoresizingMaskIntoConstraints = NO; 84 self.stackView.translatesAutoresizingMaskIntoConstraints = NO;
85 self.stackView.spacing = kStackViewSpacing; 85 self.stackView.spacing = kStackViewSpacing;
86 self.stackView.distribution = UIStackViewDistributionFill; 86 self.stackView.distribution = UIStackViewDistributionFill;
87 [self updateAllButtonsVisibility]; 87 [self updateAllButtonsVisibility];
88 } 88 }
89 89
90 - (void)setConstraints { 90 - (void)setConstraints {
91 [self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 91 [self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
92 UIViewAutoresizingFlexibleHeight]; 92 UIViewAutoresizingFlexibleHeight];
93 [NSLayoutConstraint activateConstraints:@[ 93 NSArray* constraints = @[
94 [self.stackView.topAnchor constraintEqualToAnchor:self.view.topAnchor 94 [self.stackView.topAnchor constraintEqualToAnchor:self.view.topAnchor
95 constant:kVerticalMargin], 95 constant:kVerticalMargin],
96 [self.stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor 96 [self.stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor
97 constant:-kVerticalMargin], 97 constant:-kVerticalMargin],
98 [self.stackView.leadingAnchor 98 [self.stackView.leadingAnchor
99 constraintEqualToAnchor:self.view.leadingAnchor 99 constraintEqualToAnchor:self.view.leadingAnchor
100 constant:kHorizontalMargin], 100 constant:kHorizontalMargin],
101 [self.stackView.trailingAnchor 101 [self.stackView.trailingAnchor
102 constraintEqualToAnchor:self.view.trailingAnchor 102 constraintEqualToAnchor:self.view.trailingAnchor
103 constant:-kHorizontalMargin], 103 constant:-kHorizontalMargin],
104 [self.progressBar.leadingAnchor 104 [self.progressBar.leadingAnchor
105 constraintEqualToAnchor:self.view.leadingAnchor], 105 constraintEqualToAnchor:self.view.leadingAnchor],
106 [self.progressBar.trailingAnchor 106 [self.progressBar.trailingAnchor
107 constraintEqualToAnchor:self.view.trailingAnchor], 107 constraintEqualToAnchor:self.view.trailingAnchor],
108 [self.progressBar.bottomAnchor 108 [self.progressBar.bottomAnchor
109 constraintEqualToAnchor:self.view.bottomAnchor], 109 constraintEqualToAnchor:self.view.bottomAnchor],
110 [self.progressBar.heightAnchor 110 [self.progressBar.heightAnchor
111 constraintEqualToConstant:kProgressBarHeight], 111 constraintEqualToConstant:kProgressBarHeight],
112 ]]; 112 ];
113
114 // Set the constraints priority to UILayoutPriorityDefaultHigh so these are
115 // not broken when the views are hidden or the VC's view size is 0.
116 [self activateConstraints:constraints
117 withPriority:UILayoutPriorityDefaultHigh];
113 } 118 }
114 119
115 - (void)viewWillTransitionToSize:(CGSize)size 120 - (void)viewWillTransitionToSize:(CGSize)size
116 withTransitionCoordinator: 121 withTransitionCoordinator:
117 (id<UIViewControllerTransitionCoordinator>)coordinator { 122 (id<UIViewControllerTransitionCoordinator>)coordinator {
118 // We need to dismiss the ToolsMenu everytime the Toolbar frame changes 123 // We need to dismiss the ToolsMenu everytime the Toolbar frame changes
119 // (e.g. Size changes, rotation changes, etc.) 124 // (e.g. Size changes, rotation changes, etc.)
120 [self.dispatcher closeToolsMenu]; 125 [self.dispatcher closeToolsMenu];
121 } 126 }
122 127
123 #pragma mark - Components Setup 128 #pragma mark - Components Setup
124 129
125 - (void)setUpToolbarButtons { 130 - (void)setUpToolbarButtons {
131 NSMutableArray* buttonConstraints = [[NSMutableArray alloc] init];
132
126 // Back button. 133 // Back button.
127 self.backButton = [ToolbarButton backToolbarButton]; 134 self.backButton = [ToolbarButton backToolbarButton];
128 self.backButton.visibilityMask = ToolbarComponentVisibilityCompactWidth | 135 self.backButton.visibilityMask = ToolbarComponentVisibilityCompactWidth |
129 ToolbarComponentVisibilityRegularWidth; 136 ToolbarComponentVisibilityRegularWidth;
137 [buttonConstraints
138 addObject:[self.backButton.widthAnchor
139 constraintEqualToConstant:kToolbarButtonWidth]];
130 [self.backButton addTarget:self 140 [self.backButton addTarget:self
131 action:@selector(goBack:) 141 action:@selector(goBack:)
132 forControlEvents:UIControlEventTouchUpInside]; 142 forControlEvents:UIControlEventTouchUpInside];
133 143
134 // Forward button. 144 // Forward button.
135 self.forwardButton = [ToolbarButton forwardToolbarButton]; 145 self.forwardButton = [ToolbarButton forwardToolbarButton];
136 self.forwardButton.visibilityMask = 146 self.forwardButton.visibilityMask =
137 ToolbarComponentVisibilityCompactWidthOnlyWhenEnabled | 147 ToolbarComponentVisibilityCompactWidthOnlyWhenEnabled |
138 ToolbarComponentVisibilityRegularWidth; 148 ToolbarComponentVisibilityRegularWidth;
149 [buttonConstraints
150 addObject:[self.forwardButton.widthAnchor
151 constraintEqualToConstant:kToolbarButtonWidth]];
139 [self.forwardButton addTarget:self 152 [self.forwardButton addTarget:self
140 action:@selector(goForward:) 153 action:@selector(goForward:)
141 forControlEvents:UIControlEventTouchUpInside]; 154 forControlEvents:UIControlEventTouchUpInside];
142 155
143 // Tab switcher Strip button. 156 // Tab switcher Strip button.
144 self.tabSwitchStripButton = [ToolbarButton tabSwitcherStripToolbarButton]; 157 self.tabSwitchStripButton = [ToolbarButton tabSwitcherStripToolbarButton];
145 self.tabSwitchStripButton.visibilityMask = 158 self.tabSwitchStripButton.visibilityMask =
146 ToolbarComponentVisibilityCompactWidth | 159 ToolbarComponentVisibilityCompactWidth |
147 ToolbarComponentVisibilityRegularWidth; 160 ToolbarComponentVisibilityRegularWidth;
161 [buttonConstraints
162 addObject:[self.tabSwitchStripButton.widthAnchor
163 constraintEqualToConstant:kToolbarButtonWidth]];
148 [self.tabSwitchStripButton addTarget:nil 164 [self.tabSwitchStripButton addTarget:nil
149 action:@selector(showTabStrip:) 165 action:@selector(showTabStrip:)
150 forControlEvents:UIControlEventTouchUpInside]; 166 forControlEvents:UIControlEventTouchUpInside];
151 167
152 // Tab switcher Grid button. 168 // Tab switcher Grid button.
153 self.tabSwitchGridButton = [ToolbarButton tabSwitcherGridToolbarButton]; 169 self.tabSwitchGridButton = [ToolbarButton tabSwitcherGridToolbarButton];
154 self.tabSwitchGridButton.visibilityMask = 170 self.tabSwitchGridButton.visibilityMask =
155 ToolbarComponentVisibilityCompactWidth | 171 ToolbarComponentVisibilityCompactWidth |
156 ToolbarComponentVisibilityRegularWidth; 172 ToolbarComponentVisibilityRegularWidth;
173 [buttonConstraints
174 addObject:[self.tabSwitchGridButton.widthAnchor
175 constraintEqualToConstant:kToolbarButtonWidth]];
157 [self.tabSwitchGridButton addTarget:self 176 [self.tabSwitchGridButton addTarget:self
158 action:@selector(showTabGrid:) 177 action:@selector(showTabGrid:)
159 forControlEvents:UIControlEventTouchUpInside]; 178 forControlEvents:UIControlEventTouchUpInside];
160 self.tabSwitchGridButton.hiddenInCurrentState = YES; 179 self.tabSwitchGridButton.hiddenInCurrentState = YES;
161 180
162 // Tools menu button. 181 // Tools menu button.
163 self.toolsMenuButton = [ToolbarButton toolsMenuToolbarButton]; 182 self.toolsMenuButton = [ToolbarButton toolsMenuToolbarButton];
164 self.toolsMenuButton.visibilityMask = ToolbarComponentVisibilityCompactWidth | 183 self.toolsMenuButton.visibilityMask = ToolbarComponentVisibilityCompactWidth |
165 ToolbarComponentVisibilityRegularWidth; 184 ToolbarComponentVisibilityRegularWidth;
185 [buttonConstraints
186 addObject:[self.toolsMenuButton.widthAnchor
187 constraintEqualToConstant:kToolbarButtonWidth]];
166 [self.toolsMenuButton addTarget:self 188 [self.toolsMenuButton addTarget:self
167 action:@selector(showToolsMenu:) 189 action:@selector(showToolsMenu:)
168 forControlEvents:UIControlEventTouchUpInside]; 190 forControlEvents:UIControlEventTouchUpInside];
169 191
170 // Share button. 192 // Share button.
171 self.shareButton = [ToolbarButton shareToolbarButton]; 193 self.shareButton = [ToolbarButton shareToolbarButton];
172 self.shareButton.visibilityMask = ToolbarComponentVisibilityRegularWidth; 194 self.shareButton.visibilityMask = ToolbarComponentVisibilityRegularWidth;
195 [buttonConstraints
196 addObject:[self.shareButton.widthAnchor
197 constraintEqualToConstant:kToolbarButtonWidth]];
173 [self.shareButton addTarget:self 198 [self.shareButton addTarget:self
174 action:@selector(showShareMenu:) 199 action:@selector(showShareMenu:)
175 forControlEvents:UIControlEventTouchUpInside]; 200 forControlEvents:UIControlEventTouchUpInside];
176 201
177 // Reload button. 202 // Reload button.
178 self.reloadButton = [ToolbarButton reloadToolbarButton]; 203 self.reloadButton = [ToolbarButton reloadToolbarButton];
179 self.reloadButton.visibilityMask = ToolbarComponentVisibilityRegularWidth; 204 self.reloadButton.visibilityMask = ToolbarComponentVisibilityRegularWidth;
205 [buttonConstraints
206 addObject:[self.reloadButton.widthAnchor
207 constraintEqualToConstant:kToolbarButtonWidth]];
180 [self.reloadButton addTarget:self 208 [self.reloadButton addTarget:self
181 action:@selector(reload:) 209 action:@selector(reload:)
182 forControlEvents:UIControlEventTouchUpInside]; 210 forControlEvents:UIControlEventTouchUpInside];
183 211
184 // Stop button. 212 // Stop button.
185 self.stopButton = [ToolbarButton stopToolbarButton]; 213 self.stopButton = [ToolbarButton stopToolbarButton];
186 self.stopButton.visibilityMask = ToolbarComponentVisibilityRegularWidth; 214 self.stopButton.visibilityMask = ToolbarComponentVisibilityRegularWidth;
215 [buttonConstraints
216 addObject:[self.stopButton.widthAnchor
217 constraintEqualToConstant:kToolbarButtonWidth]];
187 [self.stopButton addTarget:self 218 [self.stopButton addTarget:self
188 action:@selector(stop:) 219 action:@selector(stop:)
189 forControlEvents:UIControlEventTouchUpInside]; 220 forControlEvents:UIControlEventTouchUpInside];
221
222 // // Set the buttons constraints priority to UILayoutPriorityDefaultHigh so
223 // these are not broken when being hidden by the StackView.
224 [self activateConstraints:buttonConstraints
225 withPriority:UILayoutPriorityDefaultHigh];
190 } 226 }
191 227
192 - (void)setUpLocationBarContainer { 228 - (void)setUpLocationBarContainer {
193 UIView* locationBarContainer = [[UIView alloc] initWithFrame:CGRectZero]; 229 UIView* locationBarContainer = [[UIView alloc] initWithFrame:CGRectZero];
194 locationBarContainer.translatesAutoresizingMaskIntoConstraints = NO; 230 locationBarContainer.translatesAutoresizingMaskIntoConstraints = NO;
195 locationBarContainer.backgroundColor = [UIColor whiteColor]; 231 locationBarContainer.backgroundColor = [UIColor whiteColor];
196 locationBarContainer.layer.borderWidth = kLocationBarBorderWidth; 232 locationBarContainer.layer.borderWidth = kLocationBarBorderWidth;
197 locationBarContainer.layer.borderColor = 233 locationBarContainer.layer.borderColor =
198 [UIColor colorWithWhite:kLocationBarBorderColorBrightness alpha:1.0] 234 [UIColor colorWithWhite:kLocationBarBorderColorBrightness alpha:1.0]
199 .CGColor; 235 .CGColor;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 // Updates all Buttons visibility to match any recent WebState change. 385 // Updates all Buttons visibility to match any recent WebState change.
350 - (void)updateAllButtonsVisibility { 386 - (void)updateAllButtonsVisibility {
351 for (UIView* view in self.stackView.arrangedSubviews) { 387 for (UIView* view in self.stackView.arrangedSubviews) {
352 if ([view isKindOfClass:[ToolbarButton class]]) { 388 if ([view isKindOfClass:[ToolbarButton class]]) {
353 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view); 389 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view);
354 [button setHiddenForCurrentStateAndSizeClass]; 390 [button setHiddenForCurrentStateAndSizeClass];
355 } 391 }
356 } 392 }
357 } 393 }
358 394
395 // Sets the priority for an array of constraints and activates them.
396 - (void)activateConstraints:(NSArray*)constraintsArray
397 withPriority:(UILayoutPriority)priority {
398 for (NSLayoutConstraint* constraint in constraintsArray) {
399 constraint.priority = priority;
400 }
401 [NSLayoutConstraint activateConstraints:constraintsArray];
402 }
403
359 @end 404 @end
OLDNEW
« no previous file with comments | « ios/clean/chrome/browser/ui/toolbar/toolbar_constants.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698