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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.mm
diff --git a/ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.mm b/ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.mm
index aff02f816b66e92e7755a62bbccaeefe46fcc896..d9b8bf6eb250f334a1c7fced521fad3c8045d168 100644
--- a/ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.mm
+++ b/ios/clean/chrome/browser/ui/toolbar/toolbar_view_controller.mm
@@ -24,7 +24,7 @@ CGFloat kHorizontalMargin = 8.0f;
} // namespace
@interface ToolbarViewController ()
-@property(nonatomic, strong) UITextField* omnibox;
+@property(nonatomic, strong) UIView* locationBarContainer;
@property(nonatomic, strong) UIStackView* stackView;
@property(nonatomic, strong) ToolbarButton* backButton;
@property(nonatomic, strong) ToolbarButton* forwardButton;
@@ -38,8 +38,9 @@ CGFloat kHorizontalMargin = 8.0f;
@implementation ToolbarViewController
@synthesize dispatcher = _dispatcher;
+@synthesize locationBarViewController = _locationBarViewController;
@synthesize stackView = _stackView;
-@synthesize omnibox = _omnibox;
+@synthesize locationBarContainer = _locationBarContainer;
@synthesize backButton = _backButton;
@synthesize forwardButton = _forwardButton;
@synthesize tabSwitchStripButton = _tabSwitchStripButton;
@@ -53,13 +54,7 @@ CGFloat kHorizontalMargin = 8.0f;
self = [super init];
if (self) {
[self setUpToolbarButtons];
- // PLACEHOLDER: Omnibox could have some "Toolbar component" traits if
- // needed.
- UITextField* omnibox = [[UITextField alloc] initWithFrame:CGRectZero];
- omnibox.translatesAutoresizingMaskIntoConstraints = NO;
- omnibox.backgroundColor = [UIColor whiteColor];
- omnibox.enabled = NO;
- self.omnibox = omnibox;
+ [self setUpLocationBarContainer];
}
return self;
}
@@ -67,16 +62,19 @@ CGFloat kHorizontalMargin = 8.0f;
- (void)viewDidLoad {
self.view.backgroundColor = [UIColor lightGrayColor];
+ [self addChildViewController:self.locationBarViewController
+ toSubview:self.locationBarContainer];
+
// Stack view to contain toolbar items.
self.stackView = [[UIStackView alloc] initWithArrangedSubviews:@[
self.backButton, self.forwardButton, self.reloadButton, self.stopButton,
- self.omnibox, self.shareButton, self.tabSwitchStripButton,
+ self.locationBarContainer, self.shareButton, self.tabSwitchStripButton,
self.tabSwitchGridButton, self.toolsMenuButton
]];
[self updateAllButtonsVisibility];
self.stackView.translatesAutoresizingMaskIntoConstraints = NO;
self.stackView.spacing = 16.0;
- self.stackView.distribution = UIStackViewDistributionFillProportionally;
+ self.stackView.distribution = UIStackViewDistributionFill;
[self.view addSubview:self.stackView];
// Set constraints.
@@ -164,6 +162,52 @@ CGFloat kHorizontalMargin = 8.0f;
forControlEvents:UIControlEventTouchUpInside];
}
+- (void)setUpLocationBarContainer {
+ UIView* locationBarContainer = [[UIView alloc] initWithFrame:CGRectZero];
+ locationBarContainer.translatesAutoresizingMaskIntoConstraints = NO;
+ locationBarContainer.backgroundColor = [UIColor whiteColor];
+ [locationBarContainer
+ setContentHuggingPriority:UILayoutPriorityDefaultLow
+ forAxis:UILayoutConstraintAxisHorizontal];
+ self.locationBarContainer = locationBarContainer;
+}
+
+#pragma mark - View Controller Containment
+
+- (void)addChildViewController:(UIViewController*)viewController
+ toSubview:(UIView*)subview {
+ if (!viewController || !subview) {
+ return;
+ }
+ [self addChildViewController:viewController];
+ viewController.view.translatesAutoresizingMaskIntoConstraints = YES;
+ viewController.view.autoresizingMask =
+ UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+ viewController.view.frame = subview.bounds;
+ [subview addSubview:viewController.view];
+ [viewController didMoveToParentViewController:self];
+}
+
+- (void)setLocationBarViewController:(UIViewController*)controller {
+ if (self.locationBarViewController == controller) {
+ return;
+ }
+
+ if ([self isViewLoaded]) {
+ // Remove the old child view controller.
+ if (self.locationBarViewController) {
+ DCHECK_EQ(self, self.locationBarViewController.parentViewController);
+ [self.locationBarViewController willMoveToParentViewController:nil];
+ [self.locationBarViewController.view removeFromSuperview];
+ [self.locationBarViewController removeFromParentViewController];
+ }
+ // Add the new child view controller.
+ [self addChildViewController:controller
+ toSubview:self.locationBarContainer];
+ }
+ _locationBarViewController = controller;
+}
+
#pragma mark - Trait Collection Changes
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
@@ -182,7 +226,6 @@ CGFloat kHorizontalMargin = 8.0f;
#pragma mark - ToolbarWebStateConsumer
- (void)setCurrentPageText:(NSString*)text {
- self.omnibox.text = text;
}
- (void)setCanGoForward:(BOOL)canGoForward {
« 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