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 {
imageFetcher
delegate:(OmniboxPopupMediatorDelegate*)delegate;
// Whether the mediator has results to show.
@property(nonatomic, assign) BOOL hasResults;
- (void)updateMatches:(const AutocompleteResult&)result
withAnimation:(BOOL)animated;
......
......@@ -26,6 +26,7 @@
AutocompleteResult _currentResult;
}
@synthesize consumer = _consumer;
@synthesize hasResults = _hasResults;
@synthesize incognito = _incognito;
@synthesize open = _open;
@synthesize presenter = _presenter;
......@@ -49,6 +50,8 @@
_currentResult.Reset();
_currentResult.CopyFrom(result);
self.hasResults = !_currentResult.empty();
[self.consumer updateMatches:[self wrappedMatches] withAnimation:animation];
}
......
......@@ -11,8 +11,12 @@
// 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.
// TODO(crbug.com/788705): Remove this method when removing legacy toolbar.
- (UIView*)popupAnchorView;
// View to which the popup view should be added as subview.
- (UIView*)popupParentView;
@end
#endif // IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_POPUP_POSITIONER_H_
......@@ -19,9 +19,10 @@
namespace {
const CGFloat kExpandAnimationDuration = 0.1;
const CGFloat kCollapseAnimationDuration = 0.05;
const CGFloat kShadowHeight = 10;
const CGFloat kWhiteBackgroundHeight = 74;
NS_INLINE CGFloat ShadowHeight() {
return IsIPadIdiom() ? 10 : 0;
NS_INLINE CGFloat BottomPadding() {
return IsIPadIdiom() ? kShadowHeight : 0;
}
} // namespace
......@@ -50,34 +51,67 @@ NS_INLINE CGFloat ShadowHeight() {
_positioner = positioner;
_viewController = viewController;
if (IsIPadIdiom()) {
_popupContainerView = [OmniboxPopupPresenter newBackgroundViewIpad];
} else {
_popupContainerView = [OmniboxPopupPresenter newBackgroundViewIPhone];
UIView* popupContainer = [[UIView alloc] init];
if (!base::FeatureList::IsEnabled(kCleanToolbar)) {
if (IsIPadIdiom()) {
popupContainer = [OmniboxPopupPresenter newBackgroundViewIpad];
} else {
popupContainer = [OmniboxPopupPresenter newBackgroundViewIPhone];
}
}
_popupContainerView.translatesAutoresizingMaskIntoConstraints = NO;
popupContainer.translatesAutoresizingMaskIntoConstraints = NO;
_heightConstraint =
[_popupContainerView.heightAnchor constraintEqualToConstant:0];
[popupContainer.heightAnchor constraintEqualToConstant:0];
_heightConstraint.active = YES;
CGRect popupControllerFrame = viewController.view.frame;
popupControllerFrame.origin = CGPointZero;
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;
}
- (void)updateHeightAndAnimateAppearanceIfNecessary {
UIView* popup = self.popupContainerView;
UIView* siblingView = [self.positioner popupAnchorView];
BOOL newlyAdded = ([popup superview] == nil);
if (IsIPadIdiom()) {
[[siblingView superview] insertSubview:popup aboveSubview:siblingView];
if (!base::FeatureList::IsEnabled(kCleanToolbar)) {
UIView* siblingView = [self.positioner popupAnchorView];
if (IsIPadIdiom()) {
[[siblingView superview] insertSubview:popup aboveSubview:siblingView];
} else {
[[siblingView superview] insertSubview:popup belowSubview:siblingView];
}
} else {
[[siblingView superview] insertSubview:popup belowSubview:siblingView];
[[self.positioner popupParentView] addSubview:popup];
}
if (newlyAdded) {
......@@ -93,7 +127,7 @@ NS_INLINE CGFloat ShadowHeight() {
// insets.top + insets.bottom. |insets.bottom| will be larger than
// |insets.top| when the keyboard is visible, but |parentHeight| should stay
// the same.
CGFloat iPadHeight = height + insets.top * 2 + ShadowHeight();
CGFloat iPadHeight = height + insets.top * 2 + BottomPadding();
self.heightConstraint.constant = iPadHeight;
} else {
self.heightConstraint.active = NO;
......@@ -113,7 +147,7 @@ NS_INLINE CGFloat ShadowHeight() {
// Set the size the table view.
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;
}
......@@ -179,6 +213,7 @@ NS_INLINE CGFloat ShadowHeight() {
#pragma mark - Background creation
// TODO(crbug.com/788705): Remove this method.
+ (UIView*)newBackgroundViewIpad {
UIView* view = [[UIView alloc] init];
[view setClipsToBounds:YES];
......@@ -209,6 +244,7 @@ NS_INLINE CGFloat ShadowHeight() {
return view;
}
// TODO(crbug.com/788705): Remove this method.
+ (UIView*)newBackgroundViewIPhone {
UIView* view = [[UIView alloc] init];
......@@ -242,5 +278,4 @@ NS_INLINE CGFloat ShadowHeight() {
constant:0]];
return view;
}
@end
......@@ -27,6 +27,8 @@ class ChromeBrowserState;
@property(nonatomic, assign) ios::ChromeBrowserState* browserState;
// Positioner for the popup.
@property(nonatomic, weak) id<OmniboxPopupPositioner> positioner;
// Whether this coordinator has results to show.
@property(nonatomic, assign, readonly) BOOL hasResults;
- (void)start;
- (void)stop;
......
......@@ -70,4 +70,10 @@
_popupView.reset();
}
#pragma mark - Property accessor
- (BOOL)hasResults {
return self.mediator.hasResults;
}
@end
......@@ -154,6 +154,10 @@
return self.viewController.view;
}
- (UIView*)popupParentView {
return self.viewController.view.superview;
}
#pragma mark - SideSwipeToolbarInteracting
- (UIView*)toolbarView {
......
......@@ -292,6 +292,10 @@
return self.toolbarViewController.view;
}
- (UIView*)popupParentView {
return self.toolbarViewController.view.superview;
}
#pragma mark - LocationBarDelegate
- (void)locationBarHasBecomeFirstResponder {
......@@ -343,6 +347,9 @@
}
[self.locationBarCoordinator focusOmnibox];
if (self.omniboxPopupCoordinator.hasResults) {
[self onFakeboxAnimationComplete];
}
}
- (void)onFakeboxBlur {
......
......@@ -1028,6 +1028,11 @@ initWithDelegate:(id<WebToolbarDelegate>)delegate
return self.view;
}
- (UIView*)popupParentView {
NOTREACHED();
return nil;
}
#pragma mark -
#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