Commit 2aa19d70 authored by Robbie Gibson's avatar Robbie Gibson Committed by Commit Bot

Fix NTP omnibox animation when there are suggestions

Before, if there were suggestions on the NTP, they would immediately
appear. The better animation is to scroll the fakebox up to the top
of the screen and then present the suggestions.

To do this, when entering the omnibox from NTP, we only focus the
location bar, which causes the scrolling animation. -fakeboxFocused
is already called in the animation completion block, which does the
actual work to make the omnibox text field first responder, causing the
suggestions to appear.

To finish off, the -locationBarDidBecomeFirstResponder code now only
focuses the location bar if we are not on the regular NTP.

Bug: 1057643
Change-Id: I472ee1ee5693fa4102717275bf266f4ab97e121a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2082556
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: default avatarGauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746450}
parent 1bfa35dc
...@@ -3914,7 +3914,13 @@ NSString* const kBrowserViewControllerSnackbarCategory = ...@@ -3914,7 +3914,13 @@ NSString* const kBrowserViewControllerSnackbarCategory =
[[OmniboxGeolocationController sharedInstance] [[OmniboxGeolocationController sharedInstance]
locationBarDidBecomeFirstResponder:self.browserState]; locationBarDidBecomeFirstResponder:self.browserState];
// On the non-incognito NTP, the primaryToolbarCoordinator focuses the
// location bar itself when focusing the fakebox (while animating the
// fakebox). On all other pages, the fakebox is focused here after the
// location bar becomes first responder.
if (!IsVisibleURLNewTabPage(self.currentWebState) || self.isOffTheRecord) {
[self.primaryToolbarCoordinator transitionToLocationBarFocusedState:YES]; [self.primaryToolbarCoordinator transitionToLocationBarFocusedState:YES];
}
} }
- (void)locationBarDidResignFirstResponder { - (void)locationBarDidResignFirstResponder {
......
...@@ -450,12 +450,19 @@ using base::UserMetricsAction; ...@@ -450,12 +450,19 @@ using base::UserMetricsAction;
if (self.disableScrollAnimation) if (self.disableScrollAnimation)
return; return;
// Focus the location bar if the omnibox is not already focused.
if (!self.omniboxFocused) {
// Only animated the location bar focus if the header is scrolled to the
// top.
BOOL animated = [self.delegate isScrolledToTop];
[self.dispatcher focusLocationBarWithAnimation:animated];
}
void (^animations)() = nil; void (^animations)() = nil;
if (![self.delegate isScrolledToTop]) { if (![self.delegate isScrolledToTop]) {
// Only trigger the fake omnibox animation if the header isn't scrolled to // Only trigger the fake omnibox animation if the header isn't scrolled to
// the top. Otherwise just rely on the normal animation. // the top. Otherwise just rely on the normal animation.
self.disableScrollAnimation = YES; self.disableScrollAnimation = YES;
[self.dispatcher focusOmniboxNoAnimation];
NamedGuide* omniboxGuide = [NamedGuide guideWithName:kOmniboxGuide NamedGuide* omniboxGuide = [NamedGuide guideWithName:kOmniboxGuide
view:self.headerView]; view:self.headerView];
// Layout the owning view to make sure that the constrains are applied. // Layout the owning view to make sure that the constrains are applied.
......
...@@ -159,16 +159,10 @@ ...@@ -159,16 +159,10 @@
#pragma mark - FakeboxFocuser #pragma mark - FakeboxFocuser
- (void)focusOmniboxNoAnimation { - (void)focusLocationBarWithAnimation:(BOOL)animated {
self.enableAnimationsForOmniboxFocus = NO; self.enableAnimationsForOmniboxFocus = animated;
[self fakeboxFocused]; [self transitionToLocationBarFocusedState:YES];
self.enableAnimationsForOmniboxFocus = YES; self.enableAnimationsForOmniboxFocus = YES;
// If the pasteboard is containing a URL, the omnibox popup suggestions are
// displayed as soon as the omnibox is focused.
// If the fake omnibox animation is triggered at the same time, it is possible
// to see the NTP going up where the real omnibox should be displayed.
if ([self.locationBarCoordinator omniboxPopupHasAutocompleteResults])
[self onFakeboxAnimationComplete];
} }
- (void)fakeboxFocused { - (void)fakeboxFocused {
......
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
// This protocol provides callbacks for focusing and blurring the fake omnibox // This protocol provides callbacks for focusing and blurring the fake omnibox
// on NTP. // on NTP.
@protocol FakeboxFocuser @protocol FakeboxFocuser
// Focuses the omnibox without animations. // Focuses the location bar.
- (void)focusOmniboxNoAnimation; - (void)focusLocationBarWithAnimation:(BOOL)animated;
// Give focus to the omnibox, but indicate that the focus event was initiated // Give focus to the omnibox, but indicate that the focus event was initiated
// from the fakebox on the Google landing page. // from the fakebox on the Google landing page.
- (void)fakeboxFocused; - (void)fakeboxFocused;
......
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