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_
#import "ios/chrome/browser/omnibox/model/autocomplete_suggestion.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/autocomplete_result_consumer.h"
@protocol PopupMatchPreviewDelegate;
@class AutocompleteMatchFormatter;

@ -180,10 +180,10 @@ source_set("popup_icon") {
source_set("popup_ui_protocols") {
sources = [
"autocomplete_result_consumer.h",
"content_providing.h",
"omnibox_icon.h",
"omnibox_popup_consumer.h",
"omnibox_popup_mutator.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_
#define IOS_CHROME_BROWSER_OMNIBOX_UI_BUNDLED_POPUP_OMNIBOX_POPUP_CONSUMER_H_
@protocol AutocompleteSuggestionGroup;
// The omnibox popup consumer.
@protocol OmniboxPopupConsumer <NSObject>

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

@ -12,10 +12,10 @@
#import "components/history/core/browser/top_sites.h"
#import "components/omnibox/browser/autocomplete_result.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/favicon_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"
@protocol ApplicationCommands;
@ -58,8 +58,7 @@ class Tracker;
@end
@interface OmniboxPopupMediator
: NSObject <AutocompleteResultConsumerDelegate,
AutocompleteResultDataSource,
: NSObject <OmniboxPopupMutator,
OmniboxAutocompleteControllerDelegate,
CarouselItemMenuProvider,
ImageRetriever,

@ -157,24 +157,14 @@ const NSUInteger kMaxSuggestTileTypePosition = 15;
preselectedMatchGroupIndex:self.preselectedGroupIndex];
}
#pragma mark - AutocompleteResultDataSource
#pragma mark - OmniboxPopupMutator
- (void)requestResultsWithVisibleSuggestionCount:
(NSUInteger)visibleSuggestionCount {
[self.omniboxAutocompleteController
requestSuggestionsWithVisibleSuggestionCount:visibleSuggestionCount];
}
#pragma mark - AutocompleteResultConsumerDelegate
- (void)autocompleteResultConsumerDidChangeTraitCollection:
(id<OmniboxPopupConsumer>)sender {
- (void)onTraitCollectionChange {
[self.presenter updatePopupAfterTraitCollectionChange];
}
- (void)omniboxPopupConsumer:(id<OmniboxPopupConsumer>)sender
didSelectSuggestion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row {
- (void)selectSuggestion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row {
[self logPedalShownForCurrentResult];
// Log the suggest actions that were shown and not used.
@ -226,10 +216,9 @@ const NSUInteger kMaxSuggestTileTypePosition = 15;
}
}
- (void)omniboxPopupConsumer:(id<OmniboxPopupConsumer>)sender
didSelectSuggestionAction:(SuggestAction*)action
suggestion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row {
- (void)selectSuggestionAction:(SuggestAction*)action
suggestion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row {
OmniboxActionInSuggest::RecordShownAndUsedMetrics(action.type,
true /* used */);
@ -267,9 +256,8 @@ const NSUInteger kMaxSuggestTileTypePosition = 15;
}
}
- (void)omniboxPopupConsumer:(id<OmniboxPopupConsumer>)sender
didTapTrailingButtonOnSuggestion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row {
- (void)tapTrailingButtonOnSuggestion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row {
if ([suggestion isKindOfClass:[AutocompleteMatchFormatter class]]) {
AutocompleteMatchFormatter* autocompleteMatchFormatter =
(AutocompleteMatchFormatter*)suggestion;
@ -296,9 +284,8 @@ const NSUInteger kMaxSuggestTileTypePosition = 15;
}
}
- (void)omniboxPopupConsumer:(id<OmniboxPopupConsumer>)sender
didSelectSuggestionForDeletion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row {
- (void)selectSuggestionForDeletion:(id<AutocompleteSuggestion>)suggestion
inRow:(NSUInteger)row {
if ([suggestion isKindOfClass:[AutocompleteMatchFormatter class]]) {
AutocompleteMatchFormatter* autocompleteMatchFormatter =
(AutocompleteMatchFormatter*)suggestion;
@ -312,11 +299,17 @@ const NSUInteger kMaxSuggestTileTypePosition = 15;
}
}
- (void)autocompleteResultConsumerDidScroll:(id<OmniboxPopupConsumer>)sender {
- (void)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.
- (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_pedal.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/image_retriever.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/omnibox_popup_consumer.h"
@ -148,9 +147,7 @@ TEST_F(OmniboxPopupMediatorTest, SelectManagePasswordSuggestionMetricLogged) {
"PasswordManager.ManagePasswordsReferrer",
password_manager::ManagePasswordsReferrer::kOmniboxPedalSuggestion, 0);
[mediator_ omniboxPopupConsumer:mockResultConsumer_
didSelectSuggestion:mockSuggestionWithPedal
inRow:0];
[mediator_ selectSuggestion:mockSuggestionWithPedal inRow:0];
// Bucket count should now be one.
histogram_tester.ExpectBucketCount(
@ -196,18 +193,14 @@ TEST_F(OmniboxPopupMediatorTest, ActionInSuggestMetricLogged) {
kActionTypeReview, 0);
// Select an action suggestion.
[mediator_ omniboxPopupConsumer:nil
didSelectSuggestion:actionSuggestion
inRow:0];
[mediator_ selectSuggestion:actionSuggestion inRow:0];
// Expect Shown not logged when selecting an action.
histogram_tester.ExpectBucketCount("Omnibox.ActionInSuggest.Shown",
kActionTypeReview, 0);
// Select another suggestion.
[mediator_ omniboxPopupConsumer:nil
didSelectSuggestion:nonActionSuggestion
inRow:1];
[mediator_ selectSuggestion:nonActionSuggestion inRow:1];
// Expect Shown logged.
histogram_tester.ExpectBucketCount("Omnibox.ActionInSuggest.Shown",
@ -244,7 +237,7 @@ TEST_F(OmniboxPopupMediatorTest, PedalMetricLogged) {
base::HistogramTester histogram_tester;
// Select a suggestion.
[mediator_ omniboxPopupConsumer:nil didSelectSuggestion:match2 inRow:1];
[mediator_ selectSuggestion:match2 inRow: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 "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/content_providing.h"
#import "ios/chrome/browser/omnibox/ui_bundled/popup/omnibox_popup_consumer.h"
@protocol AutocompleteSuggestionGroup;
@protocol CarouselItemMenuProvider;
@protocol FaviconRetriever;
class LargeIconCache;
@ -20,6 +20,7 @@ namespace favicon {
class LargeIconService;
}
@class LayoutGuideCenter;
@protocol OmniboxPopupMutator;
@protocol ImageRetriever;
@protocol PopupMatchPreviewDelegate;
@ -37,8 +38,7 @@ class LargeIconService;
UIScrollViewDelegate>
@property(nonatomic, assign) BOOL incognito;
@property(nonatomic, weak) id<AutocompleteResultConsumerDelegate> delegate;
@property(nonatomic, weak) id<AutocompleteResultDataSource> dataSource;
@property(nonatomic, weak) id<OmniboxPopupMutator> mutator;
@property(nonatomic, weak) id<PopupMatchPreviewDelegate> matchPreviewDelegate;
@property(nonatomic, weak) id<ImageRetriever> imageRetriever;
@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/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_mutator.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_delegate.h"
@ -394,7 +395,7 @@ const CGFloat kHeaderTopPadding = 16.0f;
if (self.shouldUpdateVisibleSuggestionCount) {
[self updateVisibleSuggestionCount];
}
[self.dataSource
[self.mutator
requestResultsWithVisibleSuggestionCount:self.visibleSuggestionCount];
}
@ -624,9 +625,7 @@ const CGFloat kHeaderTopPadding = 16.0f;
[self suggestionAtIndexPath:self.highlightedIndexPath];
NSInteger absoluteRow =
[self absoluteRowIndexForIndexPath:self.highlightedIndexPath];
[self.delegate omniboxPopupConsumer:self
didSelectSuggestion:suggestion
inRow:absoluteRow];
[self.mutator selectSuggestion:suggestion inRow:absoluteRow];
}
#pragma mark - OmniboxPopupRowDelegate
@ -639,9 +638,7 @@ const CGFloat kHeaderTopPadding = 16.0f;
if (suggestion != configuration.suggestion) {
return;
}
[self.delegate omniboxPopupConsumer:self
didTapTrailingButtonOnSuggestion:suggestion
inRow:indexPath.row];
[self.mutator tapTrailingButtonOnSuggestion:suggestion inRow:indexPath.row];
}
- (void)omniboxPopupRowWithConfiguration:
@ -669,10 +666,9 @@ const CGFloat kHeaderTopPadding = 16.0f;
CHECK(suggestion == configuration.suggestion);
[self.delegate omniboxPopupConsumer:self
didSelectSuggestionAction:action
suggestion:suggestion
inRow:configuration.indexPath.row];
[self.mutator selectSuggestionAction:action
suggestion:suggestion
inRow:configuration.indexPath.row];
}
- (void)tableView:(UITableView*)tableView
@ -705,9 +701,8 @@ const CGFloat kHeaderTopPadding = 16.0f;
return;
}
NSInteger absoluteRow = [self absoluteRowIndexForIndexPath:indexPath];
[self.delegate omniboxPopupConsumer:self
didSelectSuggestion:[self suggestionAtIndexPath:indexPath]
inRow:absoluteRow];
[self.mutator selectSuggestion:[self suggestionAtIndexPath:indexPath]
inRow:absoluteRow];
}
- (CGFloat)tableView:(UITableView*)tableView
@ -809,9 +804,7 @@ const CGFloat kHeaderTopPadding = 16.0f;
[self suggestionAtIndexPath:indexPath];
DCHECK(suggestion);
if (editingStyle == UITableViewCellEditingStyleDelete) {
[self.delegate omniboxPopupConsumer:self
didSelectSuggestionForDeletion:suggestion
inRow:indexPath.row];
[self.mutator selectSuggestionForDeletion:suggestion inRow:indexPath.row];
}
}
@ -989,9 +982,7 @@ const CGFloat kHeaderTopPadding = 16.0f;
NSInteger absoluteRow =
[self absoluteRowIndexForIndexPath:carouselItem.indexPath];
[self.delegate omniboxPopupConsumer:self
didSelectSuggestion:suggestion
inRow:absoluteRow];
[self.mutator selectSuggestion:suggestion inRow:absoluteRow];
}
#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
// refactored.
if (self.forwardsScrollEvents) {
[self.delegate autocompleteResultConsumerDidScroll:self];
[self.mutator onScroll];
}
[self.tableView deselectRowAtIndexPath:self.tableView.indexPathForSelectedRow
@ -1196,7 +1187,7 @@ const CGFloat kHeaderTopPadding = 16.0f;
- (void)updateUIOnTraitChange {
[self updateBackgroundColor];
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/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 "testing/gtest_mac.h"
#import "testing/platform_test.h"
@ -56,12 +57,11 @@ class OmniboxPopupViewControllerTest : public PlatformTest {
void SetUp() override {
PlatformTest::SetUp();
delegate_ = [OCMockObject
mockForProtocol:@protocol(AutocompleteResultConsumerDelegate)];
mutator_ = [OCMockObject mockForProtocol:@protocol(OmniboxPopupMutator)];
preview_delegate_ =
[OCMockObject mockForProtocol:@protocol(PopupMatchPreviewDelegate)];
popup_view_controller_ = [[OmniboxPopupViewController alloc] init];
popup_view_controller_.delegate = delegate_;
popup_view_controller_.mutator = mutator_;
popup_view_controller_.matchPreviewDelegate = preview_delegate_;
// Force view initialisation since this view controller is never added into
// the hierarchy in this unit test.
@ -78,7 +78,7 @@ class OmniboxPopupViewControllerTest : public PlatformTest {
suggestion_groups_ = @[ first_suggestion_group_, second_suggestion_group_ ];
}
OCMockObject<AutocompleteResultConsumerDelegate>* delegate_;
OCMockObject<OmniboxPopupMutator>* mutator_;
OCMockObject<PopupMatchPreviewDelegate>* preview_delegate_;
OmniboxPopupViewController* popup_view_controller_;
@ -226,16 +226,14 @@ TEST_F(OmniboxPopupViewControllerTest, ReturnHighlightedSuggestion) {
[preview_delegate_ verify];
// Pressing return key when a suggestion is highlighted call the
// AutocompleteResultConsumerDelegate.
[[delegate_ expect]
omniboxPopupConsumer:popup_view_controller_
didSelectSuggestion:first_suggestion_group_.suggestions[0]
inRow:0];
// mutator.
[[mutator_ expect] selectSuggestion:first_suggestion_group_.suggestions[0]
inRow:0];
EXPECT_TRUE([popup_view_controller_
canPerformKeyboardAction:OmniboxKeyboardAction::kReturnKey]);
[popup_view_controller_
performKeyboardAction:OmniboxKeyboardAction::kReturnKey];
[delegate_ verify];
[mutator_ verify];
}
} // namespace