Commit 952b66d4 authored by Stepan Khapugin's avatar Stepan Khapugin Committed by Commit Bot

[iOS] Adds plumbing for DSE favicon and answer icons in the omnibox.

Plumbs the url of the favicon and the answer type from OPVI to
OmniboxMediator.

Bug: 945313, 945324
Change-Id: I759c5d83d7a677bb6be9e5aedf3ddd8666989fec
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1572354
Commit-Queue: Stepan Khapugin <stkhapugin@chromium.org>
Reviewed-by: default avatarRobbie Gibson <rkgibson@google.com>
Cr-Commit-Position: refs/heads/master@{#652214}
parent 9e885a06
......@@ -7,15 +7,23 @@
#import <UIKit/UIKit.h>
#include "base/optional.h"
#include "components/omnibox/browser/autocomplete_match_type.h"
#include "components/omnibox/browser/suggestion_answer.h"
// Describes an object that accepts a left image for the omnibox. The left image
// is used for showing the current selected suggestion icon, when the
// suggestions popup is visible.
@protocol OmniboxLeftImageConsumer
// The |imageId| is a resource id.
- (void)setLeftImageForAutocompleteType:(AutocompleteMatchType::Type)type;
// The suggestion icon can either be determined by |matchType|, or, in new UI,
// answer icons will be used instead, if available (i.e. the match is an
// answer). Favicons are only used for non-search match types.
- (void)setLeftImageForAutocompleteType:(AutocompleteMatchType::Type)matchType
answerType:
(base::Optional<SuggestionAnswer::AnswerType>)
answerType
faviconURL:(GURL)faviconURL;
@end
......
......@@ -70,9 +70,13 @@
#pragma mark - OmniboxLeftImageConsumer
- (void)setLeftImageForAutocompleteType:(AutocompleteMatchType::Type)type {
- (void)setLeftImageForAutocompleteType:(AutocompleteMatchType::Type)matchType
answerType:
(base::Optional<SuggestionAnswer::AnswerType>)
answerType
faviconURL:(GURL)faviconURL {
UIImage* image = GetOmniboxSuggestionIconForAutocompleteMatchType(
type, /* is_starred */ false);
matchType, /* is_starred */ false);
[self.consumer updateAutocompleteIcon:image];
}
......
......@@ -106,7 +106,9 @@ class OmniboxViewIOS : public OmniboxView,
// OmniboxPopupViewSuggestionsDelegate methods
void OnTopmostSuggestionImageChanged(
AutocompleteMatchType::Type type) override;
AutocompleteMatchType::Type match_type,
base::Optional<SuggestionAnswer::AnswerType> answer_type,
GURL favicon_url) override;
void OnResultsChanged(const AutocompleteResult& result) override;
void OnPopupDidScroll() override;
void OnSelectedMatchForAppending(const base::string16& str) override;
......
......@@ -815,8 +815,12 @@ void OmniboxViewIOS::EmphasizeURLComponents() {
#pragma mark - OmniboxPopupViewSuggestionsDelegate
void OmniboxViewIOS::OnTopmostSuggestionImageChanged(
AutocompleteMatchType::Type type) {
[left_image_consumer_ setLeftImageForAutocompleteType:type];
AutocompleteMatchType::Type match_type,
base::Optional<SuggestionAnswer::AnswerType> answer_type,
GURL favicon_url) {
[left_image_consumer_ setLeftImageForAutocompleteType:match_type
answerType:answer_type
faviconURL:favicon_url];
}
void OmniboxViewIOS::OnResultsChanged(const AutocompleteResult& result) {
......
......@@ -51,7 +51,16 @@ OmniboxPopupViewIOS::~OmniboxPopupViewIOS() {
void OmniboxPopupViewIOS::UpdateEditViewIcon() {
const AutocompleteResult& result = model_->result();
const AutocompleteMatch& match = result.match_at(model_->selected_line());
delegate_->OnTopmostSuggestionImageChanged(match.type);
base::Optional<SuggestionAnswer::AnswerType> optAnswerType = base::nullopt;
if (match.answer && match.answer->type() > 0 &&
match.answer->type() <
SuggestionAnswer::AnswerType::ANSWER_TYPE_TOTAL_COUNT) {
optAnswerType =
static_cast<SuggestionAnswer::AnswerType>(match.answer->type());
}
delegate_->OnTopmostSuggestionImageChanged(match.type, optAnswerType,
match.destination_url);
}
void OmniboxPopupViewIOS::UpdatePopupAppearance() {
......
......@@ -5,6 +5,9 @@
#ifndef IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_POPUP_VIEW_SUGGESTIONS_DELEGATE_H_
#define IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_POPUP_VIEW_SUGGESTIONS_DELEGATE_H_
#include "base/optional.h"
#include "components/omnibox/browser/suggestion_answer.h"
struct AutocompleteMatch;
class AutocompleteResult;
class GURL;
......@@ -13,8 +16,13 @@ enum class WindowOpenDisposition;
class OmniboxPopupViewSuggestionsDelegate {
public:
// Called whenever the topmost suggestion image has changed.
// Current UI should only use |matchType|; new UI may use |answerType| and
// |faviconURL| if available.
virtual void OnTopmostSuggestionImageChanged(
AutocompleteMatchType::Type type) = 0;
AutocompleteMatchType::Type match_type,
base::Optional<SuggestionAnswer::AnswerType> answer_type,
GURL favicon_url) = 0;
// Called when results are updated.
virtual void OnResultsChanged(const AutocompleteResult& result) = 0;
// Called whenever the popup is scrolled.
......
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