0

[IOS][OR] Rename the omnibox popup delegate

Bug: 402392210
Change-Id: Ie63a721539d6cf06ec2bc5d57c8bba2ee73ff3bf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6440820
Auto-Submit: Ameur Hosni <ameurhosni@google.com>
Reviewed-by: Christian Xu <christianxu@chromium.org>
Commit-Queue: Christian Xu <christianxu@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1444084}
This commit is contained in:
Ameur Hosni
2025-04-08 06:23:57 -07:00
committed by Chromium LUCI CQ
parent d2b784bf99
commit f25c332024
12 changed files with 102 additions and 144 deletions

@@ -6,7 +6,6 @@
#define IOS_CHROME_BROWSER_OMNIBOX_MODEL_PEDAL_SECTION_EXTRACTOR_H_ #define IOS_CHROME_BROWSER_OMNIBOX_MODEL_PEDAL_SECTION_EXTRACTOR_H_
#import "ios/chrome/browser/omnibox/model/autocomplete_suggestion.h" #import "ios/chrome/browser/omnibox/model/autocomplete_suggestion.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/autocomplete_result_consumer.h"
@protocol PopupMatchPreviewDelegate; @protocol PopupMatchPreviewDelegate;
@class AutocompleteMatchFormatter; @class AutocompleteMatchFormatter;

@@ -180,10 +180,10 @@ source_set("popup_icon") {
source_set("popup_ui_protocols") { source_set("popup_ui_protocols") {
sources = [ sources = [
"autocomplete_result_consumer.h",
"content_providing.h", "content_providing.h",
"omnibox_icon.h", "omnibox_icon.h",
"omnibox_popup_consumer.h", "omnibox_popup_consumer.h",
"omnibox_popup_mutator.h",
"popup_match_preview_delegate.h", "popup_match_preview_delegate.h",
] ]
} }

@@ -1,65 +0,0 @@
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_OMNIBOX_UI_BUNDLED_POPUP_AUTOCOMPLETE_RESULT_CONSUMER_H_
#define IOS_CHROME_BROWSER_OMNIBOX_UI_BUNDLED_POPUP_AUTOCOMPLETE_RESULT_CONSUMER_H_
#import <UIKit/UIKit.h>
@protocol AutocompleteSuggestion;
@protocol AutocompleteSuggestionGroup;
@protocol OmniboxPopupConsumer;
@class SuggestAction;
/// Delegate for AutocompleteResultConsumer.
@protocol AutocompleteResultConsumerDelegate <NSObject>
/// Notify about a size change.
- (void)autocompleteResultConsumerDidChangeTraitCollection:
(id<OmniboxPopupConsumer>)sender;
/// Tells the delegate on scroll.
- (void)autocompleteResultConsumerDidScroll:(id<OmniboxPopupConsumer>)sender;
/// Tells the delegate when `suggestion` in `row` was selected.
- (void)omniboxPopupConsumer:(id<OmniboxPopupConsumer>)sender
didSelectSuggestion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row;
/// Tells the delegate when a `suggestion`'s `action` was selected in a given
/// row index, for example "Directions" button for a local entity suggestion.
- (void)omniboxPopupConsumer:(id<OmniboxPopupConsumer>)sender
didSelectSuggestionAction:(SuggestAction*)action
suggestion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row;
/// Tells the delegate when `suggestion` in `row` was chosen for appending to
/// omnibox.
- (void)omniboxPopupConsumer:(id<OmniboxPopupConsumer>)sender
didTapTrailingButtonOnSuggestion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row;
/// Tells the delegate when `suggestion` in `row` was removed.
- (void)omniboxPopupConsumer:(id<OmniboxPopupConsumer>)sender
didSelectSuggestionForDeletion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row;
@end
/// An abstract data source for autocomplete results.
@protocol AutocompleteResultDataSource <NSObject>
/// Request suggestions from the data source.
/// `n` is the number of suggestions that are considered visible. Meaning the
/// user doesn't have to scroll or hide the keyboard to see those `n` first
/// suggestions.
- (void)requestResultsWithVisibleSuggestionCount:
(NSUInteger)visibleSuggestionCount
__attribute__((swift_name("requestResults(visibleSuggestionCount:)")));
;
@end
#endif // IOS_CHROME_BROWSER_OMNIBOX_UI_BUNDLED_POPUP_AUTOCOMPLETE_RESULT_CONSUMER_H_

@@ -5,6 +5,8 @@
#ifndef IOS_CHROME_BROWSER_OMNIBOX_UI_BUNDLED_POPUP_OMNIBOX_POPUP_CONSUMER_H_ #ifndef IOS_CHROME_BROWSER_OMNIBOX_UI_BUNDLED_POPUP_OMNIBOX_POPUP_CONSUMER_H_
#define IOS_CHROME_BROWSER_OMNIBOX_UI_BUNDLED_POPUP_OMNIBOX_POPUP_CONSUMER_H_ #define IOS_CHROME_BROWSER_OMNIBOX_UI_BUNDLED_POPUP_OMNIBOX_POPUP_CONSUMER_H_
@protocol AutocompleteSuggestionGroup;
// The omnibox popup consumer. // The omnibox popup consumer.
@protocol OmniboxPopupConsumer <NSObject> @protocol OmniboxPopupConsumer <NSObject>

@@ -131,8 +131,7 @@
self.mediator.omniboxAutocompleteController = _omniboxAutocompleteController; self.mediator.omniboxAutocompleteController = _omniboxAutocompleteController;
self.popupViewController.imageRetriever = self.mediator; self.popupViewController.imageRetriever = self.mediator;
self.popupViewController.faviconRetriever = self.mediator; self.popupViewController.faviconRetriever = self.mediator;
self.popupViewController.delegate = self.mediator; self.popupViewController.mutator = self.mediator;
self.popupViewController.dataSource = self.mediator;
self.popupViewController.incognito = isIncognito; self.popupViewController.incognito = isIncognito;
favicon::LargeIconService* largeIconService = favicon::LargeIconService* largeIconService =
IOSChromeLargeIconServiceFactory::GetForProfile(self.profile); IOSChromeLargeIconServiceFactory::GetForProfile(self.profile);

@@ -12,10 +12,10 @@
#import "components/history/core/browser/top_sites.h" #import "components/history/core/browser/top_sites.h"
#import "components/omnibox/browser/autocomplete_result.h" #import "components/omnibox/browser/autocomplete_result.h"
#import "ios/chrome/browser/omnibox/model/omnibox_autocomplete_controller_delegate.h" #import "ios/chrome/browser/omnibox/model/omnibox_autocomplete_controller_delegate.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/autocomplete_result_consumer.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/carousel/carousel_item_menu_provider.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/carousel/carousel_item_menu_provider.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/favicon_retriever.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/favicon_retriever.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/image_retriever.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/image_retriever.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/omnibox_popup_mutator.h"
#import "ui/base/window_open_disposition.h" #import "ui/base/window_open_disposition.h"
@protocol ApplicationCommands; @protocol ApplicationCommands;
@@ -58,8 +58,7 @@ class Tracker;
@end @end
@interface OmniboxPopupMediator @interface OmniboxPopupMediator
: NSObject <AutocompleteResultConsumerDelegate, : NSObject <OmniboxPopupMutator,
AutocompleteResultDataSource,
OmniboxAutocompleteControllerDelegate, OmniboxAutocompleteControllerDelegate,
CarouselItemMenuProvider, CarouselItemMenuProvider,
ImageRetriever, ImageRetriever,

@@ -157,24 +157,14 @@ const NSUInteger kMaxSuggestTileTypePosition = 15;
preselectedMatchGroupIndex:self.preselectedGroupIndex]; preselectedMatchGroupIndex:self.preselectedGroupIndex];
} }
#pragma mark - AutocompleteResultDataSource #pragma mark - OmniboxPopupMutator
- (void)requestResultsWithVisibleSuggestionCount: - (void)onTraitCollectionChange {
(NSUInteger)visibleSuggestionCount {
[self.omniboxAutocompleteController
requestSuggestionsWithVisibleSuggestionCount:visibleSuggestionCount];
}
#pragma mark - AutocompleteResultConsumerDelegate
- (void)autocompleteResultConsumerDidChangeTraitCollection:
(id<OmniboxPopupConsumer>)sender {
[self.presenter updatePopupAfterTraitCollectionChange]; [self.presenter updatePopupAfterTraitCollectionChange];
} }
- (void)omniboxPopupConsumer:(id<OmniboxPopupConsumer>)sender - (void)selectSuggestion:(id<AutocompleteSuggestion>)suggestion
didSelectSuggestion:(id<AutocompleteSuggestion>)suggestion inRow:(NSUInteger)row {
inRow:(NSUInteger)row {
[self logPedalShownForCurrentResult]; [self logPedalShownForCurrentResult];
// Log the suggest actions that were shown and not used. // Log the suggest actions that were shown and not used.
@@ -226,10 +216,9 @@ const NSUInteger kMaxSuggestTileTypePosition = 15;
} }
} }
- (void)omniboxPopupConsumer:(id<OmniboxPopupConsumer>)sender - (void)selectSuggestionAction:(SuggestAction*)action
didSelectSuggestionAction:(SuggestAction*)action suggestion:(id<AutocompleteSuggestion>)suggestion
suggestion:(id<AutocompleteSuggestion>)suggestion inRow:(NSUInteger)row {
inRow:(NSUInteger)row {
OmniboxActionInSuggest::RecordShownAndUsedMetrics(action.type, OmniboxActionInSuggest::RecordShownAndUsedMetrics(action.type,
true /* used */); true /* used */);
@@ -267,9 +256,8 @@ const NSUInteger kMaxSuggestTileTypePosition = 15;
} }
} }
- (void)omniboxPopupConsumer:(id<OmniboxPopupConsumer>)sender - (void)tapTrailingButtonOnSuggestion:(id<AutocompleteSuggestion>)suggestion
didTapTrailingButtonOnSuggestion:(id<AutocompleteSuggestion>)suggestion inRow:(NSUInteger)row {
inRow:(NSUInteger)row {
if ([suggestion isKindOfClass:[AutocompleteMatchFormatter class]]) { if ([suggestion isKindOfClass:[AutocompleteMatchFormatter class]]) {
AutocompleteMatchFormatter* autocompleteMatchFormatter = AutocompleteMatchFormatter* autocompleteMatchFormatter =
(AutocompleteMatchFormatter*)suggestion; (AutocompleteMatchFormatter*)suggestion;
@@ -296,9 +284,8 @@ const NSUInteger kMaxSuggestTileTypePosition = 15;
} }
} }
- (void)omniboxPopupConsumer:(id<OmniboxPopupConsumer>)sender - (void)selectSuggestionForDeletion:(id<AutocompleteSuggestion>)suggestion
didSelectSuggestionForDeletion:(id<AutocompleteSuggestion>)suggestion inRow:(NSUInteger)row {
inRow:(NSUInteger)row {
if ([suggestion isKindOfClass:[AutocompleteMatchFormatter class]]) { if ([suggestion isKindOfClass:[AutocompleteMatchFormatter class]]) {
AutocompleteMatchFormatter* autocompleteMatchFormatter = AutocompleteMatchFormatter* autocompleteMatchFormatter =
(AutocompleteMatchFormatter*)suggestion; (AutocompleteMatchFormatter*)suggestion;
@@ -312,11 +299,17 @@ const NSUInteger kMaxSuggestTileTypePosition = 15;
} }
} }
- (void)autocompleteResultConsumerDidScroll:(id<OmniboxPopupConsumer>)sender { - (void)onScroll {
[self.omniboxAutocompleteController onScroll]; [self.omniboxAutocompleteController onScroll];
} }
#pragma mark AutocompleteResultConsumerDelegate Private - (void)requestResultsWithVisibleSuggestionCount:
(NSUInteger)visibleSuggestionCount {
[self.omniboxAutocompleteController
requestSuggestionsWithVisibleSuggestionCount:visibleSuggestionCount];
}
#pragma mark OmniboxPopupMutator Private
/// Logs selected tile index and type. /// Logs selected tile index and type.
- (void)logSelectedAutocompleteTile:(const AutocompleteMatch&)match { - (void)logSelectedAutocompleteTile:(const AutocompleteMatch&)match {

@@ -33,7 +33,6 @@
#import "ios/chrome/browser/omnibox/model/omnibox_image_fetcher.h" #import "ios/chrome/browser/omnibox/model/omnibox_image_fetcher.h"
#import "ios/chrome/browser/omnibox/model/omnibox_pedal.h" #import "ios/chrome/browser/omnibox/model/omnibox_pedal.h"
#import "ios/chrome/browser/omnibox/model/suggest_action.h" #import "ios/chrome/browser/omnibox/model/suggest_action.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/autocomplete_result_consumer.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/favicon_retriever.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/favicon_retriever.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/image_retriever.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/image_retriever.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/omnibox_popup_consumer.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/omnibox_popup_consumer.h"
@@ -148,9 +147,7 @@ TEST_F(OmniboxPopupMediatorTest, SelectManagePasswordSuggestionMetricLogged) {
"PasswordManager.ManagePasswordsReferrer", "PasswordManager.ManagePasswordsReferrer",
password_manager::ManagePasswordsReferrer::kOmniboxPedalSuggestion, 0); password_manager::ManagePasswordsReferrer::kOmniboxPedalSuggestion, 0);
[mediator_ omniboxPopupConsumer:mockResultConsumer_ [mediator_ selectSuggestion:mockSuggestionWithPedal inRow:0];
didSelectSuggestion:mockSuggestionWithPedal
inRow:0];
// Bucket count should now be one. // Bucket count should now be one.
histogram_tester.ExpectBucketCount( histogram_tester.ExpectBucketCount(
@@ -196,18 +193,14 @@ TEST_F(OmniboxPopupMediatorTest, ActionInSuggestMetricLogged) {
kActionTypeReview, 0); kActionTypeReview, 0);
// Select an action suggestion. // Select an action suggestion.
[mediator_ omniboxPopupConsumer:nil [mediator_ selectSuggestion:actionSuggestion inRow:0];
didSelectSuggestion:actionSuggestion
inRow:0];
// Expect Shown not logged when selecting an action. // Expect Shown not logged when selecting an action.
histogram_tester.ExpectBucketCount("Omnibox.ActionInSuggest.Shown", histogram_tester.ExpectBucketCount("Omnibox.ActionInSuggest.Shown",
kActionTypeReview, 0); kActionTypeReview, 0);
// Select another suggestion. // Select another suggestion.
[mediator_ omniboxPopupConsumer:nil [mediator_ selectSuggestion:nonActionSuggestion inRow:1];
didSelectSuggestion:nonActionSuggestion
inRow:1];
// Expect Shown logged. // Expect Shown logged.
histogram_tester.ExpectBucketCount("Omnibox.ActionInSuggest.Shown", histogram_tester.ExpectBucketCount("Omnibox.ActionInSuggest.Shown",
@@ -244,7 +237,7 @@ TEST_F(OmniboxPopupMediatorTest, PedalMetricLogged) {
base::HistogramTester histogram_tester; base::HistogramTester histogram_tester;
// Select a suggestion. // Select a suggestion.
[mediator_ omniboxPopupConsumer:nil didSelectSuggestion:match2 inRow:1]; [mediator_ selectSuggestion:match2 inRow:1];
histogram_tester.ExpectUniqueSample("Omnibox.PedalShown", 1, 1); histogram_tester.ExpectUniqueSample("Omnibox.PedalShown", 1, 1);
} }

@@ -0,0 +1,49 @@
// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef IOS_CHROME_BROWSER_OMNIBOX_UI_BUNDLED_POPUP_OMNIBOX_POPUP_MUTATOR_H_
#define IOS_CHROME_BROWSER_OMNIBOX_UI_BUNDLED_POPUP_OMNIBOX_POPUP_MUTATOR_H_
@protocol AutocompleteSuggestion;
@class SuggestAction;
// The omnibox popup mutator
@protocol OmniboxPopupMutator <NSObject>
/// Notify about a size change.
- (void)onTraitCollectionChange;
/// Tells the mutator on scroll.
- (void)onScroll;
/// Tells the mutator when `suggestion` in `row` was selected.
- (void)selectSuggestion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row;
/// Tells the mutator when a `suggestion`'s `action` was selected in a given
/// row index, for example "Directions" button for a local entity suggestion.
- (void)selectSuggestionAction:(SuggestAction*)action
suggestion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row;
/// Tells the mutator when `suggestion` in `row` was chosen for appending to
/// omnibox.
- (void)tapTrailingButtonOnSuggestion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row;
/// Tells the mutator when `suggestion` in `row` was removed.
- (void)selectSuggestionForDeletion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row;
/// Request suggestions from the data source.
/// `n` is the number of suggestions that are considered visible. Meaning the
/// user doesn't have to scroll or hide the keyboard to see those `n` first
/// suggestions.
- (void)requestResultsWithVisibleSuggestionCount:
(NSUInteger)visibleSuggestionCount
__attribute__((swift_name("requestResults(visibleSuggestionCount:)")));
@end
#endif // IOS_CHROME_BROWSER_OMNIBOX_UI_BUNDLED_POPUP_OMNIBOX_POPUP_MUTATOR_H_

@@ -8,11 +8,11 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "ios/chrome/browser/omnibox/ui_bundled/omnibox_keyboard_delegate.h" #import "ios/chrome/browser/omnibox/ui_bundled/omnibox_keyboard_delegate.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/autocomplete_result_consumer.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/carousel/carousel_item.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/carousel/carousel_item.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/content_providing.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/content_providing.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/omnibox_popup_consumer.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/omnibox_popup_consumer.h"
@protocol AutocompleteSuggestionGroup;
@protocol CarouselItemMenuProvider; @protocol CarouselItemMenuProvider;
@protocol FaviconRetriever; @protocol FaviconRetriever;
class LargeIconCache; class LargeIconCache;
@@ -20,6 +20,7 @@ namespace favicon {
class LargeIconService; class LargeIconService;
} }
@class LayoutGuideCenter; @class LayoutGuideCenter;
@protocol OmniboxPopupMutator;
@protocol ImageRetriever; @protocol ImageRetriever;
@protocol PopupMatchPreviewDelegate; @protocol PopupMatchPreviewDelegate;
@@ -37,8 +38,7 @@ class LargeIconService;
UIScrollViewDelegate> UIScrollViewDelegate>
@property(nonatomic, assign) BOOL incognito; @property(nonatomic, assign) BOOL incognito;
@property(nonatomic, weak) id<AutocompleteResultConsumerDelegate> delegate; @property(nonatomic, weak) id<OmniboxPopupMutator> mutator;
@property(nonatomic, weak) id<AutocompleteResultDataSource> dataSource;
@property(nonatomic, weak) id<PopupMatchPreviewDelegate> matchPreviewDelegate; @property(nonatomic, weak) id<PopupMatchPreviewDelegate> matchPreviewDelegate;
@property(nonatomic, weak) id<ImageRetriever> imageRetriever; @property(nonatomic, weak) id<ImageRetriever> imageRetriever;
@property(nonatomic, weak) id<FaviconRetriever> faviconRetriever; @property(nonatomic, weak) id<FaviconRetriever> faviconRetriever;

@@ -21,6 +21,7 @@
#import "ios/chrome/browser/omnibox/ui_bundled/popup/carousel/omnibox_popup_carousel_cell.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/carousel/omnibox_popup_carousel_cell.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/content_providing.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/content_providing.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/omnibox_popup_accessibility_identifier_constants.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/omnibox_popup_accessibility_identifier_constants.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/omnibox_popup_mutator.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/popup_match_preview_delegate.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/popup_match_preview_delegate.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/row/actions/omnibox_popup_actions_row_content_configuration.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/row/actions/omnibox_popup_actions_row_content_configuration.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/row/actions/omnibox_popup_actions_row_delegate.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/row/actions/omnibox_popup_actions_row_delegate.h"
@@ -394,7 +395,7 @@ const CGFloat kHeaderTopPadding = 16.0f;
if (self.shouldUpdateVisibleSuggestionCount) { if (self.shouldUpdateVisibleSuggestionCount) {
[self updateVisibleSuggestionCount]; [self updateVisibleSuggestionCount];
} }
[self.dataSource [self.mutator
requestResultsWithVisibleSuggestionCount:self.visibleSuggestionCount]; requestResultsWithVisibleSuggestionCount:self.visibleSuggestionCount];
} }
@@ -624,9 +625,7 @@ const CGFloat kHeaderTopPadding = 16.0f;
[self suggestionAtIndexPath:self.highlightedIndexPath]; [self suggestionAtIndexPath:self.highlightedIndexPath];
NSInteger absoluteRow = NSInteger absoluteRow =
[self absoluteRowIndexForIndexPath:self.highlightedIndexPath]; [self absoluteRowIndexForIndexPath:self.highlightedIndexPath];
[self.delegate omniboxPopupConsumer:self [self.mutator selectSuggestion:suggestion inRow:absoluteRow];
didSelectSuggestion:suggestion
inRow:absoluteRow];
} }
#pragma mark - OmniboxPopupRowDelegate #pragma mark - OmniboxPopupRowDelegate
@@ -639,9 +638,7 @@ const CGFloat kHeaderTopPadding = 16.0f;
if (suggestion != configuration.suggestion) { if (suggestion != configuration.suggestion) {
return; return;
} }
[self.delegate omniboxPopupConsumer:self [self.mutator tapTrailingButtonOnSuggestion:suggestion inRow:indexPath.row];
didTapTrailingButtonOnSuggestion:suggestion
inRow:indexPath.row];
} }
- (void)omniboxPopupRowWithConfiguration: - (void)omniboxPopupRowWithConfiguration:
@@ -669,10 +666,9 @@ const CGFloat kHeaderTopPadding = 16.0f;
CHECK(suggestion == configuration.suggestion); CHECK(suggestion == configuration.suggestion);
[self.delegate omniboxPopupConsumer:self [self.mutator selectSuggestionAction:action
didSelectSuggestionAction:action suggestion:suggestion
suggestion:suggestion inRow:configuration.indexPath.row];
inRow:configuration.indexPath.row];
} }
- (void)tableView:(UITableView*)tableView - (void)tableView:(UITableView*)tableView
@@ -705,9 +701,8 @@ const CGFloat kHeaderTopPadding = 16.0f;
return; return;
} }
NSInteger absoluteRow = [self absoluteRowIndexForIndexPath:indexPath]; NSInteger absoluteRow = [self absoluteRowIndexForIndexPath:indexPath];
[self.delegate omniboxPopupConsumer:self [self.mutator selectSuggestion:[self suggestionAtIndexPath:indexPath]
didSelectSuggestion:[self suggestionAtIndexPath:indexPath] inRow:absoluteRow];
inRow:absoluteRow];
} }
- (CGFloat)tableView:(UITableView*)tableView - (CGFloat)tableView:(UITableView*)tableView
@@ -809,9 +804,7 @@ const CGFloat kHeaderTopPadding = 16.0f;
[self suggestionAtIndexPath:indexPath]; [self suggestionAtIndexPath:indexPath];
DCHECK(suggestion); DCHECK(suggestion);
if (editingStyle == UITableViewCellEditingStyleDelete) { if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.delegate omniboxPopupConsumer:self [self.mutator selectSuggestionForDeletion:suggestion inRow:indexPath.row];
didSelectSuggestionForDeletion:suggestion
inRow:indexPath.row];
} }
} }
@@ -989,9 +982,7 @@ const CGFloat kHeaderTopPadding = 16.0f;
NSInteger absoluteRow = NSInteger absoluteRow =
[self absoluteRowIndexForIndexPath:carouselItem.indexPath]; [self absoluteRowIndexForIndexPath:carouselItem.indexPath];
[self.delegate omniboxPopupConsumer:self [self.mutator selectSuggestion:suggestion inRow:absoluteRow];
didSelectSuggestion:suggestion
inRow:absoluteRow];
} }
#pragma mark - Internal API methods #pragma mark - Internal API methods
@@ -1030,7 +1021,7 @@ const CGFloat kHeaderTopPadding = 16.0f;
// dismisses the keyboard, but involves many layers of plumbing, and should be // dismisses the keyboard, but involves many layers of plumbing, and should be
// refactored. // refactored.
if (self.forwardsScrollEvents) { if (self.forwardsScrollEvents) {
[self.delegate autocompleteResultConsumerDidScroll:self]; [self.mutator onScroll];
} }
[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow [self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow
@@ -1196,7 +1187,7 @@ const CGFloat kHeaderTopPadding = 16.0f;
- (void)updateUIOnTraitChange { - (void)updateUIOnTraitChange {
[self updateBackgroundColor]; [self updateBackgroundColor];
if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET) { if (ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET) {
[self.delegate autocompleteResultConsumerDidChangeTraitCollection:self]; [self.mutator onTraitCollectionChange];
} }
} }

@@ -6,6 +6,7 @@
#import "ios/chrome/browser/omnibox/model/autocomplete_suggestion_group_impl.h" #import "ios/chrome/browser/omnibox/model/autocomplete_suggestion_group_impl.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/omnibox_popup_consumer.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/omnibox_popup_consumer.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/omnibox_popup_mutator.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/popup_match_preview_delegate.h" #import "ios/chrome/browser/omnibox/ui_bundled/popup/popup_match_preview_delegate.h"
#import "testing/gtest_mac.h" #import "testing/gtest_mac.h"
#import "testing/platform_test.h" #import "testing/platform_test.h"
@@ -56,12 +57,11 @@ class OmniboxPopupViewControllerTest : public PlatformTest {
void SetUp() override { void SetUp() override {
PlatformTest::SetUp(); PlatformTest::SetUp();
delegate_ = [OCMockObject mutator_ = [OCMockObject mockForProtocol:@protocol(OmniboxPopupMutator)];
mockForProtocol:@protocol(AutocompleteResultConsumerDelegate)];
preview_delegate_ = preview_delegate_ =
[OCMockObject mockForProtocol:@protocol(PopupMatchPreviewDelegate)]; [OCMockObject mockForProtocol:@protocol(PopupMatchPreviewDelegate)];
popup_view_controller_ = [[OmniboxPopupViewController alloc] init]; popup_view_controller_ = [[OmniboxPopupViewController alloc] init];
popup_view_controller_.delegate = delegate_; popup_view_controller_.mutator = mutator_;
popup_view_controller_.matchPreviewDelegate = preview_delegate_; popup_view_controller_.matchPreviewDelegate = preview_delegate_;
// Force view initialisation since this view controller is never added into // Force view initialisation since this view controller is never added into
// the hierarchy in this unit test. // the hierarchy in this unit test.
@@ -78,7 +78,7 @@ class OmniboxPopupViewControllerTest : public PlatformTest {
suggestion_groups_ = @[ first_suggestion_group_, second_suggestion_group_ ]; suggestion_groups_ = @[ first_suggestion_group_, second_suggestion_group_ ];
} }
OCMockObject<AutocompleteResultConsumerDelegate>* delegate_; OCMockObject<OmniboxPopupMutator>* mutator_;
OCMockObject<PopupMatchPreviewDelegate>* preview_delegate_; OCMockObject<PopupMatchPreviewDelegate>* preview_delegate_;
OmniboxPopupViewController* popup_view_controller_; OmniboxPopupViewController* popup_view_controller_;
@@ -226,16 +226,14 @@ TEST_F(OmniboxPopupViewControllerTest, ReturnHighlightedSuggestion) {
[preview_delegate_ verify]; [preview_delegate_ verify];
// Pressing return key when a suggestion is highlighted call the // Pressing return key when a suggestion is highlighted call the
// AutocompleteResultConsumerDelegate. // mutator.
[[delegate_ expect] [[mutator_ expect] selectSuggestion:first_suggestion_group_.suggestions[0]
omniboxPopupConsumer:popup_view_controller_ inRow:0];
didSelectSuggestion:first_suggestion_group_.suggestions[0]
inRow:0];
EXPECT_TRUE([popup_view_controller_ EXPECT_TRUE([popup_view_controller_
canPerformKeyboardAction:OmniboxKeyboardAction::kReturnKey]); canPerformKeyboardAction:OmniboxKeyboardAction::kReturnKey]);
[popup_view_controller_ [popup_view_controller_
performKeyboardAction:OmniboxKeyboardAction::kReturnKey]; performKeyboardAction:OmniboxKeyboardAction::kReturnKey];
[delegate_ verify]; [mutator_ verify];
} }
} // namespace } // namespace