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 @@ ...@@ -7,15 +7,23 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#include "base/optional.h"
#include "components/omnibox/browser/autocomplete_match_type.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 // 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 // is used for showing the current selected suggestion icon, when the
// suggestions popup is visible. // suggestions popup is visible.
@protocol OmniboxLeftImageConsumer @protocol OmniboxLeftImageConsumer
// The |imageId| is a resource id. // The suggestion icon can either be determined by |matchType|, or, in new UI,
- (void)setLeftImageForAutocompleteType:(AutocompleteMatchType::Type)type; // 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 @end
......
...@@ -70,9 +70,13 @@ ...@@ -70,9 +70,13 @@
#pragma mark - OmniboxLeftImageConsumer #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( UIImage* image = GetOmniboxSuggestionIconForAutocompleteMatchType(
type, /* is_starred */ false); matchType, /* is_starred */ false);
[self.consumer updateAutocompleteIcon:image]; [self.consumer updateAutocompleteIcon:image];
} }
......
...@@ -106,7 +106,9 @@ class OmniboxViewIOS : public OmniboxView, ...@@ -106,7 +106,9 @@ class OmniboxViewIOS : public OmniboxView,
// OmniboxPopupViewSuggestionsDelegate methods // OmniboxPopupViewSuggestionsDelegate methods
void OnTopmostSuggestionImageChanged( 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 OnResultsChanged(const AutocompleteResult& result) override;
void OnPopupDidScroll() override; void OnPopupDidScroll() override;
void OnSelectedMatchForAppending(const base::string16& str) override; void OnSelectedMatchForAppending(const base::string16& str) override;
......
...@@ -815,8 +815,12 @@ void OmniboxViewIOS::EmphasizeURLComponents() { ...@@ -815,8 +815,12 @@ void OmniboxViewIOS::EmphasizeURLComponents() {
#pragma mark - OmniboxPopupViewSuggestionsDelegate #pragma mark - OmniboxPopupViewSuggestionsDelegate
void OmniboxViewIOS::OnTopmostSuggestionImageChanged( void OmniboxViewIOS::OnTopmostSuggestionImageChanged(
AutocompleteMatchType::Type type) { AutocompleteMatchType::Type match_type,
[left_image_consumer_ setLeftImageForAutocompleteType: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) { void OmniboxViewIOS::OnResultsChanged(const AutocompleteResult& result) {
......
...@@ -51,7 +51,16 @@ OmniboxPopupViewIOS::~OmniboxPopupViewIOS() { ...@@ -51,7 +51,16 @@ OmniboxPopupViewIOS::~OmniboxPopupViewIOS() {
void OmniboxPopupViewIOS::UpdateEditViewIcon() { void OmniboxPopupViewIOS::UpdateEditViewIcon() {
const AutocompleteResult& result = model_->result(); const AutocompleteResult& result = model_->result();
const AutocompleteMatch& match = result.match_at(model_->selected_line()); 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() { void OmniboxPopupViewIOS::UpdatePopupAppearance() {
......
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
#ifndef IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_POPUP_VIEW_SUGGESTIONS_DELEGATE_H_ #ifndef IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_POPUP_VIEW_SUGGESTIONS_DELEGATE_H_
#define 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; struct AutocompleteMatch;
class AutocompleteResult; class AutocompleteResult;
class GURL; class GURL;
...@@ -13,8 +16,13 @@ enum class WindowOpenDisposition; ...@@ -13,8 +16,13 @@ enum class WindowOpenDisposition;
class OmniboxPopupViewSuggestionsDelegate { class OmniboxPopupViewSuggestionsDelegate {
public: public:
// Called whenever the topmost suggestion image has changed. // 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( 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. // Called when results are updated.
virtual void OnResultsChanged(const AutocompleteResult& result) = 0; virtual void OnResultsChanged(const AutocompleteResult& result) = 0;
// Called whenever the popup is scrolled. // 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