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; ...@@ -29,8 +29,9 @@ class WebStateList;
// Command dispatcher. // Command dispatcher.
@property(nonatomic, strong) CommandDispatcher* commandDispatcher; @property(nonatomic, strong) CommandDispatcher* commandDispatcher;
// View containing the omnibox. // View controller containing the omnibox.
@property(nonatomic, strong, readonly) UIView* view; @property(nonatomic, strong, readonly)
UIViewController* locationBarViewController;
// Weak reference to ChromeBrowserState; // Weak reference to ChromeBrowserState;
@property(nonatomic, assign) ios::ChromeBrowserState* browserState; @property(nonatomic, assign) ios::ChromeBrowserState* browserState;
// The dispatcher for this view controller. // The dispatcher for this view controller.
......
...@@ -103,8 +103,8 @@ const int kLocationAuthorizationStatusCount = 4; ...@@ -103,8 +103,8 @@ const int kLocationAuthorizationStatusCount = 4;
#pragma mark - public #pragma mark - public
- (UIView*)view { - (UIViewController*)locationBarViewController {
return self.viewController.view; return self.viewController;
} }
- (void)start { - (void)start {
......
...@@ -111,11 +111,11 @@ class LocationBarCoordinatorTest : public PlatformTest { ...@@ -111,11 +111,11 @@ class LocationBarCoordinatorTest : public PlatformTest {
}; };
TEST_F(LocationBarCoordinatorTest, Stops) { TEST_F(LocationBarCoordinatorTest, Stops) {
EXPECT_TRUE(coordinator_.view == nil); EXPECT_TRUE(coordinator_.locationBarViewController == nil);
[coordinator_ start]; [coordinator_ start];
EXPECT_TRUE(coordinator_.view != nil); EXPECT_TRUE(coordinator_.locationBarViewController != nil);
[coordinator_ stop]; [coordinator_ stop];
EXPECT_TRUE(coordinator_.view == nil); EXPECT_TRUE(coordinator_.locationBarViewController == nil);
} }
// Calls -loadGURLFromLocationBar:transition: with https://www.google.com/ URL. // Calls -loadGURLFromLocationBar:transition: with https://www.google.com/ URL.
......
...@@ -118,6 +118,13 @@ const CGFloat kClearButtonSize = 28.0f; ...@@ -118,6 +118,13 @@ const CGFloat kClearButtonSize = 28.0f;
object:self.textField]; 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 { - (void)traitCollectionDidChange:(UITraitCollection*)previousTraitCollection {
[super traitCollectionDidChange:previousTraitCollection]; [super traitCollectionDidChange:previousTraitCollection];
[self updateLeadingImageVisibility]; [self updateLeadingImageVisibility];
......
...@@ -78,7 +78,8 @@ ...@@ -78,7 +78,8 @@
self.orchestrator.toolbarAnimatee = self.viewController; self.orchestrator.toolbarAnimatee = self.viewController;
[self setUpLocationBar]; [self setUpLocationBar];
self.viewController.locationBarView = self.locationBarCoordinator.view; self.viewController.locationBarViewController =
self.locationBarCoordinator.locationBarViewController;
self.orchestrator.locationBarAnimatee = self.orchestrator.locationBarAnimatee =
[self.locationBarCoordinator locationBarAnimatee]; [self.locationBarCoordinator locationBarAnimatee];
...@@ -203,16 +204,16 @@ ...@@ -203,16 +204,16 @@
// Don't do anything for a live non-ntp tab. // Don't do anything for a live non-ntp tab.
if (webState == self.webStateList->GetActiveWebState() && !isNTP) { if (webState == self.webStateList->GetActiveWebState() && !isNTP) {
[self.locationBarCoordinator.view setHidden:NO]; [self.locationBarCoordinator.locationBarViewController.view setHidden:NO];
} else { } else {
self.viewController.view.hidden = NO; self.viewController.view.hidden = NO;
[self.locationBarCoordinator.view setHidden:YES]; [self.locationBarCoordinator.locationBarViewController.view setHidden:YES];
} }
} }
- (void)resetToolbarAfterSideSwipeSnapshot { - (void)resetToolbarAfterSideSwipeSnapshot {
[super resetToolbarAfterSideSwipeSnapshot]; [super resetToolbarAfterSideSwipeSnapshot];
[self.locationBarCoordinator.view setHidden:NO]; [self.locationBarCoordinator.locationBarViewController.view setHidden:NO];
} }
#pragma mark - Private #pragma mark - Private
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
@property(nonatomic, weak) id<PrimaryToolbarViewControllerDelegate> delegate; @property(nonatomic, weak) id<PrimaryToolbarViewControllerDelegate> delegate;
// Sets the location bar view, containing the omnibox. // Sets the location bar view controller, containing the omnibox.
- (void)setLocationBarView:(UIView*)locationBarView; - (void)setLocationBarViewController:(UIViewController*)locationBarView;
// Shows the animation when transitioning to a prerendered page. // Shows the animation when transitioning to a prerendered page.
- (void)showPrerenderingAnimation; - (void)showPrerenderingAnimation;
......
...@@ -163,8 +163,11 @@ ...@@ -163,8 +163,11 @@
#pragma mark - Property accessors #pragma mark - Property accessors
- (void)setLocationBarView:(UIView*)locationBarView { - (void)setLocationBarViewController:
self.view.locationBarView = locationBarView; (UIViewController*)locationBarViewController {
[self addChildViewController:locationBarViewController];
[locationBarViewController didMoveToParentViewController:self];
self.view.locationBarView = locationBarViewController.view;
} }
- (void)setIsNTP:(BOOL)isNTP { - (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