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

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

Issue 2761343002: [ios] Adds LocationBarCoordinator. (Closed)
Patch Set: Rebased. Created 3 years, 8 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
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_grid_actions.h" 8 #import "ios/clean/chrome/browser/ui/actions/tab_grid_actions.h"
9 #import "ios/clean/chrome/browser/ui/actions/tab_strip_actions.h" 9 #import "ios/clean/chrome/browser/ui/actions/tab_strip_actions.h"
10 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h" 10 #import "ios/clean/chrome/browser/ui/commands/navigation_commands.h"
11 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h" 11 #import "ios/clean/chrome/browser/ui/commands/tools_menu_commands.h"
12 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h" 12 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_button+factory.h"
13 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_component_options.h" 13 #import "ios/clean/chrome/browser/ui/toolbar/toolbar_component_options.h"
14 14
15 #if !defined(__has_feature) || !__has_feature(objc_arc) 15 #if !defined(__has_feature) || !__has_feature(objc_arc)
16 #error "This file requires ARC support." 16 #error "This file requires ARC support."
17 #endif 17 #endif
18 18
19 namespace { 19 namespace {
20 // Stackview Vertical Margin. 20 // Stackview Vertical Margin.
21 CGFloat kVerticalMargin = 5.0f; 21 CGFloat kVerticalMargin = 5.0f;
22 // Stackview Horizontal Margin. 22 // Stackview Horizontal Margin.
23 CGFloat kHorizontalMargin = 8.0f; 23 CGFloat kHorizontalMargin = 8.0f;
24 } // namespace 24 } // namespace
25 25
26 @interface ToolbarViewController () 26 @interface ToolbarViewController ()
27 @property(nonatomic, strong) UITextField* omnibox; 27 @property(nonatomic, strong) UIView* locationBarContainer;
28 @property(nonatomic, strong) UIStackView* stackView; 28 @property(nonatomic, strong) UIStackView* stackView;
29 @property(nonatomic, strong) ToolbarButton* backButton; 29 @property(nonatomic, strong) ToolbarButton* backButton;
30 @property(nonatomic, strong) ToolbarButton* forwardButton; 30 @property(nonatomic, strong) ToolbarButton* forwardButton;
31 @property(nonatomic, strong) ToolbarButton* tabSwitchStripButton; 31 @property(nonatomic, strong) ToolbarButton* tabSwitchStripButton;
32 @property(nonatomic, strong) ToolbarButton* tabSwitchGridButton; 32 @property(nonatomic, strong) ToolbarButton* tabSwitchGridButton;
33 @property(nonatomic, strong) ToolbarButton* toolsMenuButton; 33 @property(nonatomic, strong) ToolbarButton* toolsMenuButton;
34 @property(nonatomic, strong) ToolbarButton* shareButton; 34 @property(nonatomic, strong) ToolbarButton* shareButton;
35 @property(nonatomic, strong) ToolbarButton* reloadButton; 35 @property(nonatomic, strong) ToolbarButton* reloadButton;
36 @property(nonatomic, strong) ToolbarButton* stopButton; 36 @property(nonatomic, strong) ToolbarButton* stopButton;
37 @end 37 @end
38 38
39 @implementation ToolbarViewController 39 @implementation ToolbarViewController
40 @synthesize dispatcher = _dispatcher; 40 @synthesize dispatcher = _dispatcher;
41 @synthesize locationBarViewController = _locationBarViewController;
41 @synthesize stackView = _stackView; 42 @synthesize stackView = _stackView;
42 @synthesize omnibox = _omnibox; 43 @synthesize locationBarContainer = _locationBarContainer;
43 @synthesize backButton = _backButton; 44 @synthesize backButton = _backButton;
44 @synthesize forwardButton = _forwardButton; 45 @synthesize forwardButton = _forwardButton;
45 @synthesize tabSwitchStripButton = _tabSwitchStripButton; 46 @synthesize tabSwitchStripButton = _tabSwitchStripButton;
46 @synthesize tabSwitchGridButton = _tabSwitchGridButton; 47 @synthesize tabSwitchGridButton = _tabSwitchGridButton;
47 @synthesize toolsMenuButton = _toolsMenuButton; 48 @synthesize toolsMenuButton = _toolsMenuButton;
48 @synthesize shareButton = _shareButton; 49 @synthesize shareButton = _shareButton;
49 @synthesize reloadButton = _reloadButton; 50 @synthesize reloadButton = _reloadButton;
50 @synthesize stopButton = _stopButton; 51 @synthesize stopButton = _stopButton;
51 52
52 - (instancetype)init { 53 - (instancetype)init {
53 self = [super init]; 54 self = [super init];
54 if (self) { 55 if (self) {
55 [self setUpToolbarButtons]; 56 [self setUpToolbarButtons];
56 // PLACEHOLDER: Omnibox could have some "Toolbar component" traits if 57 [self setUpLocationBarContainer];
57 // needed.
58 UITextField* omnibox = [[UITextField alloc] initWithFrame:CGRectZero];
59 omnibox.translatesAutoresizingMaskIntoConstraints = NO;
60 omnibox.backgroundColor = [UIColor whiteColor];
61 omnibox.enabled = NO;
62 self.omnibox = omnibox;
63 } 58 }
64 return self; 59 return self;
65 } 60 }
66 61
67 - (void)viewDidLoad { 62 - (void)viewDidLoad {
68 self.view.backgroundColor = [UIColor lightGrayColor]; 63 self.view.backgroundColor = [UIColor lightGrayColor];
69 64
65 [self addChildViewController:self.locationBarViewController
66 toSubview:self.locationBarContainer];
67
70 // Stack view to contain toolbar items. 68 // Stack view to contain toolbar items.
71 self.stackView = [[UIStackView alloc] initWithArrangedSubviews:@[ 69 self.stackView = [[UIStackView alloc] initWithArrangedSubviews:@[
72 self.backButton, self.forwardButton, self.reloadButton, self.stopButton, 70 self.backButton, self.forwardButton, self.reloadButton, self.stopButton,
73 self.omnibox, self.shareButton, self.tabSwitchStripButton, 71 self.locationBarContainer, self.shareButton, self.tabSwitchStripButton,
74 self.tabSwitchGridButton, self.toolsMenuButton 72 self.tabSwitchGridButton, self.toolsMenuButton
75 ]]; 73 ]];
76 [self updateAllButtonsVisibility]; 74 [self updateAllButtonsVisibility];
77 self.stackView.translatesAutoresizingMaskIntoConstraints = NO; 75 self.stackView.translatesAutoresizingMaskIntoConstraints = NO;
78 self.stackView.spacing = 16.0; 76 self.stackView.spacing = 16.0;
79 self.stackView.distribution = UIStackViewDistributionFillProportionally; 77 self.stackView.distribution = UIStackViewDistributionFill;
80 [self.view addSubview:self.stackView]; 78 [self.view addSubview:self.stackView];
81 79
82 // Set constraints. 80 // Set constraints.
83 [self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth | 81 [self.view setAutoresizingMask:UIViewAutoresizingFlexibleWidth |
84 UIViewAutoresizingFlexibleHeight]; 82 UIViewAutoresizingFlexibleHeight];
85 [NSLayoutConstraint activateConstraints:@[ 83 [NSLayoutConstraint activateConstraints:@[
86 [self.stackView.topAnchor constraintEqualToAnchor:self.view.topAnchor 84 [self.stackView.topAnchor constraintEqualToAnchor:self.view.topAnchor
87 constant:kVerticalMargin], 85 constant:kVerticalMargin],
88 [self.stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor 86 [self.stackView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor
89 constant:-kVerticalMargin], 87 constant:-kVerticalMargin],
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 forControlEvents:UIControlEventTouchUpInside]; 155 forControlEvents:UIControlEventTouchUpInside];
158 156
159 // Stop button. 157 // Stop button.
160 self.stopButton = [ToolbarButton stopToolbarButton]; 158 self.stopButton = [ToolbarButton stopToolbarButton];
161 self.stopButton.visibilityMask = ToolbarComponentVisibilityRegularWidth; 159 self.stopButton.visibilityMask = ToolbarComponentVisibilityRegularWidth;
162 [self.stopButton addTarget:self 160 [self.stopButton addTarget:self
163 action:@selector(stop:) 161 action:@selector(stop:)
164 forControlEvents:UIControlEventTouchUpInside]; 162 forControlEvents:UIControlEventTouchUpInside];
165 } 163 }
166 164
165 - (void)setUpLocationBarContainer {
166 UIView* locationBarContainer = [[UIView alloc] initWithFrame:CGRectZero];
167 locationBarContainer.translatesAutoresizingMaskIntoConstraints = NO;
168 locationBarContainer.backgroundColor = [UIColor whiteColor];
169 [locationBarContainer
170 setContentHuggingPriority:UILayoutPriorityDefaultLow
171 forAxis:UILayoutConstraintAxisHorizontal];
172 self.locationBarContainer = locationBarContainer;
173 }
174
175 #pragma mark - View Controller Containment
176
177 - (void)addChildViewController:(UIViewController*)viewController
178 toSubview:(UIView*)subview {
179 if (!viewController || !subview) {
180 return;
181 }
182 [self addChildViewController:viewController];
183 viewController.view.translatesAutoresizingMaskIntoConstraints = YES;
184 viewController.view.autoresizingMask =
185 UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
186 viewController.view.frame = subview.bounds;
187 [subview addSubview:viewController.view];
188 [viewController didMoveToParentViewController:self];
189 }
190
191 - (void)setLocationBarViewController:(UIViewController*)controller {
192 if (self.locationBarViewController == controller) {
193 return;
194 }
195
196 if ([self isViewLoaded]) {
197 // Remove the old child view controller.
198 if (self.locationBarViewController) {
199 DCHECK_EQ(self, self.locationBarViewController.parentViewController);
200 [self.locationBarViewController willMoveToParentViewController:nil];
201 [self.locationBarViewController.view removeFromSuperview];
202 [self.locationBarViewController removeFromParentViewController];
203 }
204 // Add the new child view controller.
205 [self addChildViewController:controller
206 toSubview:self.locationBarContainer];
207 }
208 _locationBarViewController = controller;
209 }
210
167 #pragma mark - Trait Collection Changes 211 #pragma mark - Trait Collection Changes
168 212
169 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection { 213 - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
170 [super traitCollectionDidChange:previousTraitCollection]; 214 [super traitCollectionDidChange:previousTraitCollection];
171 if (self.traitCollection.horizontalSizeClass != 215 if (self.traitCollection.horizontalSizeClass !=
172 previousTraitCollection.horizontalSizeClass) { 216 previousTraitCollection.horizontalSizeClass) {
173 for (UIView* view in self.stackView.arrangedSubviews) { 217 for (UIView* view in self.stackView.arrangedSubviews) {
174 if ([view isKindOfClass:[ToolbarButton class]]) { 218 if ([view isKindOfClass:[ToolbarButton class]]) {
175 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view); 219 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view);
176 [button updateHiddenInCurrentSizeClass]; 220 [button updateHiddenInCurrentSizeClass];
177 } 221 }
178 } 222 }
179 } 223 }
180 } 224 }
181 225
182 #pragma mark - ToolbarWebStateConsumer 226 #pragma mark - ToolbarWebStateConsumer
183 227
184 - (void)setCurrentPageText:(NSString*)text { 228 - (void)setCurrentPageText:(NSString*)text {
185 self.omnibox.text = text;
186 } 229 }
187 230
188 - (void)setCanGoForward:(BOOL)canGoForward { 231 - (void)setCanGoForward:(BOOL)canGoForward {
189 self.forwardButton.enabled = canGoForward; 232 self.forwardButton.enabled = canGoForward;
190 } 233 }
191 234
192 - (void)setCanGoBack:(BOOL)canGoBack { 235 - (void)setCanGoBack:(BOOL)canGoBack {
193 self.backButton.enabled = canGoBack; 236 self.backButton.enabled = canGoBack;
194 } 237 }
195 238
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 - (void)updateAllButtonsVisibility { 299 - (void)updateAllButtonsVisibility {
257 for (UIView* view in self.stackView.arrangedSubviews) { 300 for (UIView* view in self.stackView.arrangedSubviews) {
258 if ([view isKindOfClass:[ToolbarButton class]]) { 301 if ([view isKindOfClass:[ToolbarButton class]]) {
259 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view); 302 ToolbarButton* button = base::mac::ObjCCastStrict<ToolbarButton>(view);
260 [button setHiddenForCurrentStateAndSizeClass]; 303 [button setHiddenForCurrentStateAndSizeClass];
261 } 304 }
262 } 305 }
263 } 306 }
264 307
265 @end 308 @end
OLDNEW
« no previous file with comments | « ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.h ('k') | ios/clean/chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698