Commit b3f3a209 authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

Use proper view controller containment for omnibox.

Makes Primary Toolbar contain Location Bar to get the view events at
the correct times.
Also clears selection when the omnibox is disappearing to prevent the
selection handles from showing in the tab grid.

Bug: 823423
Change-Id: I848ee9b7ba00bf83614e20fbbd37fe971a92caa7
Reviewed-on: https://chromium-review.googlesource.com/c/1429989
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Auto-Submit: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Cr-Commit-Position: refs/heads/master@{#635609}
parent 789bdca8
......@@ -29,8 +29,9 @@ class WebStateList;
// Command dispatcher.
@property(nonatomic, strong) CommandDispatcher* commandDispatcher;
// View containing the omnibox.
@property(nonatomic, strong, readonly) UIView* view;
// View controller containing the omnibox.
@property(nonatomic, strong, readonly)
UIViewController* locationBarViewController;
// Weak reference to ChromeBrowserState;
@property(nonatomic, assign) ios::ChromeBrowserState* browserState;
// The dispatcher for this view controller.
......
......@@ -103,8 +103,8 @@ const int kLocationAuthorizationStatusCount = 4;
#pragma mark - public
- (UIView*)view {
return self.viewController.view;
- (UIViewController*)locationBarViewController {
return self.viewController;
}
- (void)start {
......
......@@ -111,11 +111,11 @@ class LocationBarCoordinatorTest : public PlatformTest {
};
TEST_F(LocationBarCoordinatorTest, Stops) {
EXPECT_TRUE(coordinator_.view == nil);
EXPECT_TRUE(coordinator_.locationBarViewController == nil);
[coordinator_ start];
EXPECT_TRUE(coordinator_.view != nil);
EXPECT_TRUE(coordinator_.locationBarViewController != nil);
[coordinator_ stop];
EXPECT_TRUE(coordinator_.view == nil);
EXPECT_TRUE(coordinator_.locationBarViewController == nil);
}
// Calls -loadGURLFromLocationBar:transition: with https://www.google.com/ URL.
......
......@@ -118,6 +118,13 @@ const CGFloat kClearButtonSize = 28.0f;
object:self.textField];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
self.textField.selectedTextRange =
[self.textField textRangeFromPosition:self.textField.beginningOfDocument
toPosition:self.textField.beginningOfDocument];
}
- (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection];
[self updateLeadingImageVisibility];
......
......@@ -78,7 +78,8 @@
self.orchestrator.toolbarAnimatee = self.viewController;
[self setUpLocationBar];
self.viewController.locationBarView = self.locationBarCoordinator.view;
self.viewController.locationBarViewController =
self.locationBarCoordinator.locationBarViewController;
self.orchestrator.locationBarAnimatee =
[self.locationBarCoordinator locationBarAnimatee];
......@@ -203,16 +204,16 @@
// Don't do anything for a live non-ntp tab.
if (webState == self.webStateList->GetActiveWebState() && !isNTP) {
[self.locationBarCoordinator.view setHidden:NO];
[self.locationBarCoordinator.locationBarViewController.view setHidden:NO];
} else {
self.viewController.view.hidden = NO;
[self.locationBarCoordinator.view setHidden:YES];
[self.locationBarCoordinator.locationBarViewController.view setHidden:YES];
}
}
- (void)resetToolbarAfterSideSwipeSnapshot {
[super resetToolbarAfterSideSwipeSnapshot];
[self.locationBarCoordinator.view setHidden:NO];
[self.locationBarCoordinator.locationBarViewController.view setHidden:NO];
}
#pragma mark - Private
......
......@@ -21,8 +21,8 @@
@property(nonatomic, weak) id<PrimaryToolbarViewControllerDelegate> delegate;
// Sets the location bar view, containing the omnibox.
- (void)setLocationBarView:(UIView*)locationBarView;
// Sets the location bar view controller, containing the omnibox.
- (void)setLocationBarViewController:(UIViewController*)locationBarView;
// Shows the animation when transitioning to a prerendered page.
- (void)showPrerenderingAnimation;
......
......@@ -163,8 +163,11 @@
#pragma mark - Property accessors
- (void)setLocationBarView:(UIView*)locationBarView {
self.view.locationBarView = locationBarView;
- (void)setLocationBarViewController:
(UIViewController*)locationBarViewController {
[self addChildViewController:locationBarViewController];
[locationBarViewController didMoveToParentViewController:self];
self.view.locationBarView = locationBarViewController.view;
}
- (void)setIsNTP:(BOOL)isNTP {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment