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

Box OmniboxPopup to a coordinator

This CL creates a OmniboxPopupCoordinator and boxes the ViewController,
mediator and presenter inside.
For now the coordinator is still owned and activated by the
OmniboxPopupViewIOS. In future CL the coordinator will own the
OmniboxPopupViewIOS.

Bug: 762597,788640
Cq-Include-Trybots: master.tryserver.chromium.mac:ios-simulator-cronet;master.tryserver.chromium.mac:ios-simulator-full-configs
Change-Id: Ief006d3c8e8668824111fd513d249dc90be51d1e
Reviewed-on: https://chromium-review.googlesource.com/824664Reviewed-by: default avatarJustin Cohen <justincohen@chromium.org>
Reviewed-by: default avatarStepan Khapugin <stkhapugin@chromium.org>
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#524062}
parent bc58510e
...@@ -94,6 +94,7 @@ source_set("omnibox_internal") { ...@@ -94,6 +94,7 @@ source_set("omnibox_internal") {
"//ios/chrome/browser/sessions", "//ios/chrome/browser/sessions",
"//ios/chrome/browser/ui", "//ios/chrome/browser/ui",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/omnibox/popup",
"//ios/chrome/browser/ui/toolbar/clean:toolbar_components_ui", "//ios/chrome/browser/ui/toolbar/clean:toolbar_components_ui",
"//ios/chrome/browser/ui/toolbar/public", "//ios/chrome/browser/ui/toolbar/public",
"//ios/chrome/browser/ui/toolbar/public:toolbar_base_feature", "//ios/chrome/browser/ui/toolbar/public:toolbar_base_feature",
...@@ -110,6 +111,7 @@ source_set("omnibox_internal") { ...@@ -110,6 +111,7 @@ source_set("omnibox_internal") {
"//ui/gfx/geometry", "//ui/gfx/geometry",
"//url", "//url",
] ]
allow_circular_includes_from = [ "//ios/chrome/browser/ui/omnibox/popup" ]
public_deps = [ public_deps = [
"//components/omnibox/browser", "//components/omnibox/browser",
] ]
......
...@@ -17,12 +17,11 @@ ...@@ -17,12 +17,11 @@
#import "ios/chrome/browser/ui/omnibox/omnibox_popup_view_controller.h" #import "ios/chrome/browser/ui/omnibox/omnibox_popup_view_controller.h"
class OmniboxEditModel; class OmniboxEditModel;
@class OmniboxPopupViewController; @class OmniboxPopupCoordinator;
class OmniboxPopupModel; class OmniboxPopupModel;
class OmniboxPopupViewSuggestionsDelegate; class OmniboxPopupViewSuggestionsDelegate;
@protocol OmniboxPopupPositioner; @protocol OmniboxPopupPositioner;
struct AutocompleteMatch; struct AutocompleteMatch;
@class OmniboxPopupPresenter;
namespace ios { namespace ios {
class ChromeBrowserState; class ChromeBrowserState;
...@@ -68,10 +67,7 @@ class OmniboxPopupViewIOS : public OmniboxPopupView, ...@@ -68,10 +67,7 @@ class OmniboxPopupViewIOS : public OmniboxPopupView,
private: private:
std::unique_ptr<OmniboxPopupModel> model_; std::unique_ptr<OmniboxPopupModel> model_;
OmniboxPopupViewSuggestionsDelegate* delegate_; // weak OmniboxPopupViewSuggestionsDelegate* delegate_; // weak
base::scoped_nsobject<OmniboxPopupMediator> mediator_; base::scoped_nsobject<OmniboxPopupCoordinator> coordinator_;
base::scoped_nsobject<OmniboxPopupPresenter> presenter_;
base::scoped_nsobject<OmniboxPopupViewController> popup_controller_;
bool is_open_;
}; };
#endif // IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_POPUP_VIEW_IOS_H_ #endif // IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_POPUP_VIEW_IOS_H_
...@@ -24,6 +24,7 @@ ...@@ -24,6 +24,7 @@
#import "ios/chrome/browser/ui/omnibox/omnibox_popup_view_controller.h" #import "ios/chrome/browser/ui/omnibox/omnibox_popup_view_controller.h"
#include "ios/chrome/browser/ui/omnibox/omnibox_popup_view_suggestions_delegate.h" #include "ios/chrome/browser/ui/omnibox/omnibox_popup_view_suggestions_delegate.h"
#include "ios/chrome/browser/ui/omnibox/omnibox_util.h" #include "ios/chrome/browser/ui/omnibox/omnibox_util.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_coordinator.h"
#include "ios/chrome/browser/ui/ui_util.h" #include "ios/chrome/browser/ui/ui_util.h"
#import "ios/chrome/browser/ui/uikit_ui_util.h" #import "ios/chrome/browser/ui/uikit_ui_util.h"
#include "ios/chrome/grit/ios_theme_resources.h" #include "ios/chrome/grit/ios_theme_resources.h"
...@@ -42,31 +43,19 @@ OmniboxPopupViewIOS::OmniboxPopupViewIOS( ...@@ -42,31 +43,19 @@ OmniboxPopupViewIOS::OmniboxPopupViewIOS(
OmniboxEditModel* edit_model, OmniboxEditModel* edit_model,
OmniboxPopupViewSuggestionsDelegate* delegate, OmniboxPopupViewSuggestionsDelegate* delegate,
id<OmniboxPopupPositioner> positioner) id<OmniboxPopupPositioner> positioner)
: model_(new OmniboxPopupModel(this, edit_model)), : model_(new OmniboxPopupModel(this, edit_model)), delegate_(delegate) {
delegate_(delegate),
is_open_(false) {
DCHECK(delegate); DCHECK(delegate);
DCHECK(browser_state); DCHECK(browser_state);
DCHECK(edit_model); DCHECK(edit_model);
std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> imageFetcher = // TODO(crbug.com/788640): The coordinator should own the OmniboxPopupViewIOS,
base::MakeUnique<image_fetcher::IOSImageDataFetcherWrapper>( // not the other way around.
browser_state->GetRequestContext()); coordinator_.reset([[OmniboxPopupCoordinator alloc] init]);
[coordinator_ setBrowserState:browser_state];
[coordinator_ setMediatorDelegate:this];
[coordinator_ setPositioner:positioner];
mediator_.reset([[OmniboxPopupMediator alloc] [coordinator_ start];
initWithFetcher:std::move(imageFetcher)
delegate:this]);
popup_controller_.reset([[OmniboxPopupViewController alloc] init]);
[popup_controller_ setIncognito:browser_state->IsOffTheRecord()];
[mediator_ setIncognito:browser_state->IsOffTheRecord()];
[mediator_ setConsumer:popup_controller_];
[popup_controller_ setImageRetriever:mediator_];
[popup_controller_ setDelegate:mediator_];
presenter_.reset([[OmniboxPopupPresenter alloc]
initWithPopupPositioner:positioner
popupViewController:popup_controller_]);
} }
OmniboxPopupViewIOS::~OmniboxPopupViewIOS() { OmniboxPopupViewIOS::~OmniboxPopupViewIOS() {
...@@ -87,23 +76,9 @@ void OmniboxPopupViewIOS::UpdateEditViewIcon() { ...@@ -87,23 +76,9 @@ void OmniboxPopupViewIOS::UpdateEditViewIcon() {
void OmniboxPopupViewIOS::UpdatePopupAppearance() { void OmniboxPopupViewIOS::UpdatePopupAppearance() {
const AutocompleteResult& result = model_->result(); const AutocompleteResult& result = model_->result();
// TODO(crbug.com/762597): this logic should move to PopupCoordinator. [coordinator_ updateWithResults:result];
if (!is_open_ && !result.empty()) { if ([coordinator_ isOpen]) {
// The popup is not currently open and there are results to display. Update
// and animate the cells
[mediator_ updateMatches:result withAnimation:YES];
} else {
// The popup is already displayed or there are no results to display. Update
// the cells without animating.
[mediator_ updateMatches:result withAnimation:NO];
}
is_open_ = !result.empty();
if (is_open_) {
[presenter_ updateHeightAndAnimateAppearanceIfNecessary];
UpdateEditViewIcon(); UpdateEditViewIcon();
} else {
[presenter_ animateCollapse];
} }
delegate_->OnResultsChanged(result); delegate_->OnResultsChanged(result);
...@@ -114,7 +89,7 @@ gfx::Rect OmniboxPopupViewIOS::GetTargetBounds() { ...@@ -114,7 +89,7 @@ gfx::Rect OmniboxPopupViewIOS::GetTargetBounds() {
} }
bool OmniboxPopupViewIOS::IsOpen() const { bool OmniboxPopupViewIOS::IsOpen() const {
return is_open_; return [coordinator_ isOpen];
} }
OmniboxPopupModel* OmniboxPopupViewIOS::model() const { OmniboxPopupModel* OmniboxPopupViewIOS::model() const {
...@@ -124,11 +99,11 @@ OmniboxPopupModel* OmniboxPopupViewIOS::model() const { ...@@ -124,11 +99,11 @@ OmniboxPopupModel* OmniboxPopupViewIOS::model() const {
#pragma mark - OmniboxPopupProvider #pragma mark - OmniboxPopupProvider
bool OmniboxPopupViewIOS::IsPopupOpen() { bool OmniboxPopupViewIOS::IsPopupOpen() {
return is_open_; return [coordinator_ isOpen];
} }
void OmniboxPopupViewIOS::SetTextAlignment(NSTextAlignment alignment) { void OmniboxPopupViewIOS::SetTextAlignment(NSTextAlignment alignment) {
[popup_controller_ setTextAlignment:alignment]; [coordinator_ setTextAlignment:alignment];
} }
#pragma mark - OmniboxPopupViewControllerDelegate #pragma mark - OmniboxPopupViewControllerDelegate
......
# Copyright 2017 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
source_set("popup") {
sources = [
"omnibox_popup_coordinator.h",
"omnibox_popup_coordinator.mm",
]
deps = [
"//base",
"//components/image_fetcher/ios",
"//components/omnibox/browser",
"//ios/chrome/browser/browser_state",
"//net",
]
configs += [ "//build/config/compiler:enable_arc" ]
}
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_UI_OMNIBOX_POPUP_OMNIBOX_POPUP_COORDINATOR_H_
#define IOS_CHROME_BROWSER_UI_OMNIBOX_POPUP_OMNIBOX_POPUP_COORDINATOR_H_
#import <UIKit/UIKit.h>
class AutocompleteResult;
class OmniboxPopupMediatorDelegate;
@protocol OmniboxPopupPositioner;
namespace ios {
class ChromeBrowserState;
}
// Coordinator for the Omnibox Popup.
@interface OmniboxPopupCoordinator : NSObject
// BrowserState.
@property(nonatomic, assign) ios::ChromeBrowserState* browserState;
// Positioner for the popup.
@property(nonatomic, weak) id<OmniboxPopupPositioner> positioner;
// Delegate for the popup mediator.
@property(nonatomic, assign) OmniboxPopupMediatorDelegate* mediatorDelegate;
// Whether the popup is open.
@property(nonatomic, assign, getter=isOpen) BOOL open;
- (void)start;
// Updates the popup with the |results|.
- (void)updateWithResults:(const AutocompleteResult&)results;
// Sets the text alignment of the popup content.
- (void)setTextAlignment:(NSTextAlignment)alignment;
@end
#endif // IOS_CHROME_BROWSER_UI_OMNIBOX_POPUP_OMNIBOX_POPUP_COORDINATOR_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_coordinator.h"
#import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h"
#include "components/omnibox/browser/autocomplete_result.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#import "ios/chrome/browser/ui/omnibox/omnibox_popup_mediator.h"
#import "ios/chrome/browser/ui/omnibox/omnibox_popup_presenter.h"
#import "ios/chrome/browser/ui/omnibox/omnibox_popup_view_controller.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
@interface OmniboxPopupCoordinator ()
@property(nonatomic, strong) OmniboxPopupViewController* popupViewController;
@property(nonatomic, strong) OmniboxPopupMediator* mediator;
@property(nonatomic, strong) OmniboxPopupPresenter* presenter;
@end
@implementation OmniboxPopupCoordinator
@synthesize browserState = _browserState;
@synthesize mediator = _mediator;
@synthesize mediatorDelegate = _mediatorDelegate;
@synthesize open = _open;
@synthesize popupViewController = _popupViewController;
@synthesize positioner = _positioner;
@synthesize presenter = _presenter;
#pragma mark - Public
- (void)start {
self.open = NO;
std::unique_ptr<image_fetcher::IOSImageDataFetcherWrapper> imageFetcher =
std::make_unique<image_fetcher::IOSImageDataFetcherWrapper>(
self.browserState->GetRequestContext());
self.mediator =
[[OmniboxPopupMediator alloc] initWithFetcher:std::move(imageFetcher)
delegate:self.mediatorDelegate];
self.popupViewController = [[OmniboxPopupViewController alloc] init];
self.popupViewController.incognito = self.browserState->IsOffTheRecord();
self.mediator.incognito = self.browserState->IsOffTheRecord();
self.mediator.consumer = self.popupViewController;
self.popupViewController.imageRetriever = self.mediator;
self.popupViewController.delegate = self.mediator;
self.presenter = [[OmniboxPopupPresenter alloc]
initWithPopupPositioner:self.positioner
popupViewController:self.popupViewController];
}
- (void)updateWithResults:(const AutocompleteResult&)result {
if (!self.open && !result.empty()) {
// The popup is not currently open and there are results to display. Update
// and animate the cells
[self.mediator updateMatches:result withAnimation:YES];
} else {
// The popup is already displayed or there are no results to display. Update
// the cells without animating.
[self.mediator updateMatches:result withAnimation:NO];
}
self.open = !result.empty();
if (self.open) {
[self.presenter updateHeightAndAnimateAppearanceIfNecessary];
} else {
[self.presenter animateCollapse];
}
}
- (void)setTextAlignment:(NSTextAlignment)alignment {
[self.popupViewController setTextAlignment:alignment];
}
@end
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