Commit db8e1009 authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

OmniboxPopup don't need toolbar view anymore

This CL changes the OmniboxPopup such as it doesn't need access to the
toolbar view to be presented. Instead it only needs a pointer to its
superview.
The pointer to the view was used to present the popup above or below it
to show the shadow between the omnibox and the popup or not.

This CL changes it by adding the shadow if needed in the popup.

It also removes the white rectangle recovering the place normally
occupied by the toolbar during NTP animation (to avoid seeing the
google logo moving up as the toolbar is hidden). To do that, the
toolbar is directly shown if there are results to be displayed.

Bug: 786940
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: I6a8dea25702b4644f0f0c76fc34b01c1deaf6a88
Reviewed-on: https://chromium-review.googlesource.com/881182
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#531864}
parent dbd136e4
...@@ -35,6 +35,9 @@ class OmniboxPopupMediatorDelegate { ...@@ -35,6 +35,9 @@ class OmniboxPopupMediatorDelegate {
imageFetcher imageFetcher
delegate:(OmniboxPopupMediatorDelegate*)delegate; delegate:(OmniboxPopupMediatorDelegate*)delegate;
// Whether the mediator has results to show.
@property(nonatomic, assign) BOOL hasResults;
- (void)updateMatches:(const AutocompleteResult&)result - (void)updateMatches:(const AutocompleteResult&)result
withAnimation:(BOOL)animated; withAnimation:(BOOL)animated;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
AutocompleteResult _currentResult; AutocompleteResult _currentResult;
} }
@synthesize consumer = _consumer; @synthesize consumer = _consumer;
@synthesize hasResults = _hasResults;
@synthesize incognito = _incognito; @synthesize incognito = _incognito;
@synthesize open = _open; @synthesize open = _open;
@synthesize presenter = _presenter; @synthesize presenter = _presenter;
...@@ -49,6 +50,8 @@ ...@@ -49,6 +50,8 @@
_currentResult.Reset(); _currentResult.Reset();
_currentResult.CopyFrom(result); _currentResult.CopyFrom(result);
self.hasResults = !_currentResult.empty();
[self.consumer updateMatches:[self wrappedMatches] withAnimation:animation]; [self.consumer updateMatches:[self wrappedMatches] withAnimation:animation];
} }
......
...@@ -11,8 +11,12 @@ ...@@ -11,8 +11,12 @@
// Returns the view the popup is anchored next to. Callers are responsible for // Returns the view the popup is anchored next to. Callers are responsible for
// adding the popup as a sibling either above or below this view. // adding the popup as a sibling either above or below this view.
// TODO(crbug.com/788705): Remove this method when removing legacy toolbar.
- (UIView*)popupAnchorView; - (UIView*)popupAnchorView;
// View to which the popup view should be added as subview.
- (UIView*)popupParentView;
@end @end
#endif // IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_POPUP_POSITIONER_H_ #endif // IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_POPUP_POSITIONER_H_
...@@ -19,9 +19,10 @@ ...@@ -19,9 +19,10 @@
namespace { namespace {
const CGFloat kExpandAnimationDuration = 0.1; const CGFloat kExpandAnimationDuration = 0.1;
const CGFloat kCollapseAnimationDuration = 0.05; const CGFloat kCollapseAnimationDuration = 0.05;
const CGFloat kShadowHeight = 10;
const CGFloat kWhiteBackgroundHeight = 74; const CGFloat kWhiteBackgroundHeight = 74;
NS_INLINE CGFloat ShadowHeight() { NS_INLINE CGFloat BottomPadding() {
return IsIPadIdiom() ? 10 : 0; return IsIPadIdiom() ? kShadowHeight : 0;
} }
} // namespace } // namespace
...@@ -50,35 +51,68 @@ NS_INLINE CGFloat ShadowHeight() { ...@@ -50,35 +51,68 @@ NS_INLINE CGFloat ShadowHeight() {
_positioner = positioner; _positioner = positioner;
_viewController = viewController; _viewController = viewController;
UIView* popupContainer = [[UIView alloc] init];
if (!base::FeatureList::IsEnabled(kCleanToolbar)) {
if (IsIPadIdiom()) { if (IsIPadIdiom()) {
_popupContainerView = [OmniboxPopupPresenter newBackgroundViewIpad]; popupContainer = [OmniboxPopupPresenter newBackgroundViewIpad];
} else { } else {
_popupContainerView = [OmniboxPopupPresenter newBackgroundViewIPhone]; popupContainer = [OmniboxPopupPresenter newBackgroundViewIPhone];
} }
_popupContainerView.translatesAutoresizingMaskIntoConstraints = NO; }
popupContainer.translatesAutoresizingMaskIntoConstraints = NO;
_heightConstraint = _heightConstraint =
[_popupContainerView.heightAnchor constraintEqualToConstant:0]; [popupContainer.heightAnchor constraintEqualToConstant:0];
_heightConstraint.active = YES; _heightConstraint.active = YES;
CGRect popupControllerFrame = viewController.view.frame; CGRect popupControllerFrame = viewController.view.frame;
popupControllerFrame.origin = CGPointZero; popupControllerFrame.origin = CGPointZero;
viewController.view.frame = popupControllerFrame; viewController.view.frame = popupControllerFrame;
[_popupContainerView addSubview:viewController.view]; [popupContainer addSubview:viewController.view];
if (base::FeatureList::IsEnabled(kCleanToolbar)) {
UIImageView* shadowView = [[UIImageView alloc]
initWithImage:NativeImage(IDR_IOS_TOOLBAR_SHADOW_FULL_BLEED)];
[shadowView setUserInteractionEnabled:NO];
[shadowView setTranslatesAutoresizingMaskIntoConstraints:NO];
[popupContainer addSubview:shadowView];
[NSLayoutConstraint activateConstraints:@[
[shadowView.leadingAnchor
constraintEqualToAnchor:popupContainer.leadingAnchor],
[shadowView.trailingAnchor
constraintEqualToAnchor:popupContainer.trailingAnchor],
]];
if (IsIPadIdiom()) {
[shadowView.topAnchor
constraintEqualToAnchor:popupContainer.bottomAnchor]
.active = YES;
} else {
[shadowView.topAnchor
constraintEqualToAnchor:viewController.view.topAnchor]
.active = YES;
}
}
_popupContainerView = popupContainer;
} }
return self; return self;
} }
- (void)updateHeightAndAnimateAppearanceIfNecessary { - (void)updateHeightAndAnimateAppearanceIfNecessary {
UIView* popup = self.popupContainerView; UIView* popup = self.popupContainerView;
UIView* siblingView = [self.positioner popupAnchorView];
BOOL newlyAdded = ([popup superview] == nil); BOOL newlyAdded = ([popup superview] == nil);
if (!base::FeatureList::IsEnabled(kCleanToolbar)) {
UIView* siblingView = [self.positioner popupAnchorView];
if (IsIPadIdiom()) { if (IsIPadIdiom()) {
[[siblingView superview] insertSubview:popup aboveSubview:siblingView]; [[siblingView superview] insertSubview:popup aboveSubview:siblingView];
} else { } else {
[[siblingView superview] insertSubview:popup belowSubview:siblingView]; [[siblingView superview] insertSubview:popup belowSubview:siblingView];
} }
} else {
[[self.positioner popupParentView] addSubview:popup];
}
if (newlyAdded) { if (newlyAdded) {
[self initialLayout]; [self initialLayout];
...@@ -93,7 +127,7 @@ NS_INLINE CGFloat ShadowHeight() { ...@@ -93,7 +127,7 @@ NS_INLINE CGFloat ShadowHeight() {
// insets.top + insets.bottom. |insets.bottom| will be larger than // insets.top + insets.bottom. |insets.bottom| will be larger than
// |insets.top| when the keyboard is visible, but |parentHeight| should stay // |insets.top| when the keyboard is visible, but |parentHeight| should stay
// the same. // the same.
CGFloat iPadHeight = height + insets.top * 2 + ShadowHeight(); CGFloat iPadHeight = height + insets.top * 2 + BottomPadding();
self.heightConstraint.constant = iPadHeight; self.heightConstraint.constant = iPadHeight;
} else { } else {
self.heightConstraint.active = NO; self.heightConstraint.active = NO;
...@@ -113,7 +147,7 @@ NS_INLINE CGFloat ShadowHeight() { ...@@ -113,7 +147,7 @@ NS_INLINE CGFloat ShadowHeight() {
// Set the size the table view. // Set the size the table view.
CGRect popupControllerFrame = self.viewController.view.frame; CGRect popupControllerFrame = self.viewController.view.frame;
popupControllerFrame.size.height = popup.frame.size.height - ShadowHeight(); popupControllerFrame.size.height = popup.frame.size.height - BottomPadding();
self.viewController.view.frame = popupControllerFrame; self.viewController.view.frame = popupControllerFrame;
} }
...@@ -179,6 +213,7 @@ NS_INLINE CGFloat ShadowHeight() { ...@@ -179,6 +213,7 @@ NS_INLINE CGFloat ShadowHeight() {
#pragma mark - Background creation #pragma mark - Background creation
// TODO(crbug.com/788705): Remove this method.
+ (UIView*)newBackgroundViewIpad { + (UIView*)newBackgroundViewIpad {
UIView* view = [[UIView alloc] init]; UIView* view = [[UIView alloc] init];
[view setClipsToBounds:YES]; [view setClipsToBounds:YES];
...@@ -209,6 +244,7 @@ NS_INLINE CGFloat ShadowHeight() { ...@@ -209,6 +244,7 @@ NS_INLINE CGFloat ShadowHeight() {
return view; return view;
} }
// TODO(crbug.com/788705): Remove this method.
+ (UIView*)newBackgroundViewIPhone { + (UIView*)newBackgroundViewIPhone {
UIView* view = [[UIView alloc] init]; UIView* view = [[UIView alloc] init];
...@@ -242,5 +278,4 @@ NS_INLINE CGFloat ShadowHeight() { ...@@ -242,5 +278,4 @@ NS_INLINE CGFloat ShadowHeight() {
constant:0]]; constant:0]];
return view; return view;
} }
@end @end
...@@ -27,6 +27,8 @@ class ChromeBrowserState; ...@@ -27,6 +27,8 @@ class ChromeBrowserState;
@property(nonatomic, assign) ios::ChromeBrowserState* browserState; @property(nonatomic, assign) ios::ChromeBrowserState* browserState;
// Positioner for the popup. // Positioner for the popup.
@property(nonatomic, weak) id<OmniboxPopupPositioner> positioner; @property(nonatomic, weak) id<OmniboxPopupPositioner> positioner;
// Whether this coordinator has results to show.
@property(nonatomic, assign, readonly) BOOL hasResults;
- (void)start; - (void)start;
- (void)stop; - (void)stop;
......
...@@ -70,4 +70,10 @@ ...@@ -70,4 +70,10 @@
_popupView.reset(); _popupView.reset();
} }
#pragma mark - Property accessor
- (BOOL)hasResults {
return self.mediator.hasResults;
}
@end @end
...@@ -154,6 +154,10 @@ ...@@ -154,6 +154,10 @@
return self.viewController.view; return self.viewController.view;
} }
- (UIView*)popupParentView {
return self.viewController.view.superview;
}
#pragma mark - SideSwipeToolbarInteracting #pragma mark - SideSwipeToolbarInteracting
- (UIView*)toolbarView { - (UIView*)toolbarView {
......
...@@ -292,6 +292,10 @@ ...@@ -292,6 +292,10 @@
return self.toolbarViewController.view; return self.toolbarViewController.view;
} }
- (UIView*)popupParentView {
return self.toolbarViewController.view.superview;
}
#pragma mark - LocationBarDelegate #pragma mark - LocationBarDelegate
- (void)locationBarHasBecomeFirstResponder { - (void)locationBarHasBecomeFirstResponder {
...@@ -343,6 +347,9 @@ ...@@ -343,6 +347,9 @@
} }
[self.locationBarCoordinator focusOmnibox]; [self.locationBarCoordinator focusOmnibox];
if (self.omniboxPopupCoordinator.hasResults) {
[self onFakeboxAnimationComplete];
}
} }
- (void)onFakeboxBlur { - (void)onFakeboxBlur {
......
...@@ -1028,6 +1028,11 @@ initWithDelegate:(id<WebToolbarDelegate>)delegate ...@@ -1028,6 +1028,11 @@ initWithDelegate:(id<WebToolbarDelegate>)delegate
return self.view; return self.view;
} }
- (UIView*)popupParentView {
NOTREACHED();
return nil;
}
#pragma mark - #pragma mark -
#pragma mark ToolbarViewDelegate methods. #pragma mark ToolbarViewDelegate methods.
......
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