Commit 2666ab40 authored by Robbie Gibson's avatar Robbie Gibson Committed by Commit Bot

🦁Add G icon for answers with no specific icon

This CL adds the G icon as a fallback icon for answers with no more
specific icon. It also renames the "currency" imageset to "stock" as
that icon is actually used for the stock price suggestion, not the
currency conversion suggestion (which uses the "conversion" icon).

Bug: 963860
Change-Id: I446a07cbab6b1a5ab0a38629947d09e17522499e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1614219
Commit-Queue: Robbie Gibson <rkgibson@google.com>
Reviewed-by: default avatarRohit Rao <rohitrao@chromium.org>
Cr-Commit-Position: refs/heads/master@{#661324}
parent 5c36d549
...@@ -53,6 +53,8 @@ source_set("omnibox_ui_internal") { ...@@ -53,6 +53,8 @@ source_set("omnibox_ui_internal") {
"//components/omnibox/browser", "//components/omnibox/browser",
"//ios/chrome/browser/ui:feature_flags", "//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/colors", "//ios/chrome/browser/ui/colors",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/images",
"//url", "//url",
] ]
} }
...@@ -75,9 +77,9 @@ source_set("omnibox_util") { ...@@ -75,9 +77,9 @@ source_set("omnibox_util") {
deps = [ deps = [
"resources:answer_calculator", "resources:answer_calculator",
"resources:answer_conversion", "resources:answer_conversion",
"resources:answer_currency",
"resources:answer_dictionary", "resources:answer_dictionary",
"resources:answer_local_time", "resources:answer_local_time",
"resources:answer_stock",
"resources:answer_sunrise", "resources:answer_sunrise",
"resources:answer_translation", "resources:answer_translation",
"resources:answer_when_is", "resources:answer_when_is",
......
...@@ -17,6 +17,10 @@ struct AutocompleteMatch; ...@@ -17,6 +17,10 @@ struct AutocompleteMatch;
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
// Whether the default search engine is Google impacts which icon is used in
// some cases
@property(nonatomic, assign) BOOL defaultSearchEngineIsGoogle;
@end @end
#endif // IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_ICON_FORMATTER_H_ #endif // IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_ICON_FORMATTER_H_
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h" #import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
#import "ios/chrome/browser/ui/omnibox/omnibox_util.h" #import "ios/chrome/browser/ui/omnibox/omnibox_util.h"
#import "ios/chrome/browser/ui/ui_feature_flags.h" #import "ios/chrome/browser/ui/ui_feature_flags.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#include "ios/public/provider/chrome/browser/images/branded_image_provider.h"
#import "url/gurl.h" #import "url/gurl.h"
#if !defined(__has_feature) || !__has_feature(objc_arc) #if !defined(__has_feature) || !__has_feature(objc_arc)
...@@ -19,14 +21,12 @@ namespace { ...@@ -19,14 +21,12 @@ namespace {
OmniboxSuggestionIconType IconTypeFromMatchAndAnswerType( OmniboxSuggestionIconType IconTypeFromMatchAndAnswerType(
AutocompleteMatchType::Type type, AutocompleteMatchType::Type type,
base::Optional<int> answerType) { base::Optional<int> answerType) {
// Some suggestions have custom icons. Others fallback to the icon from the
// overall match type.
if (answerType) { if (answerType) {
switch (answerType.value()) { switch (answerType.value()) {
case SuggestionAnswer::ANSWER_TYPE_DICTIONARY: case SuggestionAnswer::ANSWER_TYPE_DICTIONARY:
return DICTIONARY; return DICTIONARY;
case SuggestionAnswer::ANSWER_TYPE_FINANCE: case SuggestionAnswer::ANSWER_TYPE_FINANCE:
return CURRENCY; return STOCK;
case SuggestionAnswer::ANSWER_TYPE_TRANSLATION: case SuggestionAnswer::ANSWER_TYPE_TRANSLATION:
return TRANSLATION; return TRANSLATION;
case SuggestionAnswer::ANSWER_TYPE_WHEN_IS: case SuggestionAnswer::ANSWER_TYPE_WHEN_IS:
...@@ -41,7 +41,7 @@ OmniboxSuggestionIconType IconTypeFromMatchAndAnswerType( ...@@ -41,7 +41,7 @@ OmniboxSuggestionIconType IconTypeFromMatchAndAnswerType(
case SuggestionAnswer::ANSWER_TYPE_LOCAL_TIME: case SuggestionAnswer::ANSWER_TYPE_LOCAL_TIME:
case SuggestionAnswer::ANSWER_TYPE_PLAY_INSTALL: case SuggestionAnswer::ANSWER_TYPE_PLAY_INSTALL:
case SuggestionAnswer::ANSWER_TYPE_WEATHER: case SuggestionAnswer::ANSWER_TYPE_WEATHER:
break; return FALLBACK_ANSWER;
case SuggestionAnswer::ANSWER_TYPE_INVALID: case SuggestionAnswer::ANSWER_TYPE_INVALID:
case SuggestionAnswer::ANSWER_TYPE_TOTAL_COUNT: case SuggestionAnswer::ANSWER_TYPE_TOTAL_COUNT:
NOTREACHED(); NOTREACHED();
...@@ -127,10 +127,12 @@ OmniboxSuggestionIconType IconTypeFromMatchAndAnswerType( ...@@ -127,10 +127,12 @@ OmniboxSuggestionIconType IconTypeFromMatchAndAnswerType(
} }
- (UIImage*)iconImage { - (UIImage*)iconImage {
NSString* imageName = if (self.suggestionIconType == FALLBACK_ANSWER &&
GetOmniboxNewSuggestionIconTypeAssetName(self.suggestionIconType); self.defaultSearchEngineIsGoogle && [self fallbackAnswerBrandedIcon]) {
return [[UIImage imageNamed:imageName] return [[self fallbackAnswerBrandedIcon]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
return GetOmniboxSuggestionIcon(self.suggestionIconType);
} }
- (BOOL)hasCustomAnswerIcon { - (BOOL)hasCustomAnswerIcon {
...@@ -143,18 +145,32 @@ OmniboxSuggestionIconType IconTypeFromMatchAndAnswerType( ...@@ -143,18 +145,32 @@ OmniboxSuggestionIconType IconTypeFromMatchAndAnswerType(
case CALCULATOR: case CALCULATOR:
case CONVERSION: case CONVERSION:
case DICTIONARY: case DICTIONARY:
case CURRENCY: case STOCK:
case SUNRISE: case SUNRISE:
case LOCAL_TIME: case LOCAL_TIME:
case WHEN_IS: case WHEN_IS:
case TRANSLATION: case TRANSLATION:
return YES; return YES;
// For the fallback answer, this depends on whether the branded icon exists
// and whether the default search engine is Google (the icon only exists for
// Google branding).
// The default fallback answer icon uses the grey background styling, like
// the non-answer icons.
case FALLBACK_ANSWER:
return self.defaultSearchEngineIsGoogle &&
[self fallbackAnswerBrandedIcon];
case OMNIBOX_SUGGESTION_ICON_TYPE_COUNT: case OMNIBOX_SUGGESTION_ICON_TYPE_COUNT:
NOTREACHED(); NOTREACHED();
return NO; return NO;
} }
} }
- (UIImage*)fallbackAnswerBrandedIcon {
return ios::GetChromeBrowserProvider()
->GetBrandedImageProvider()
->GetOmniboxAnswerIcon();
}
- (UIColor*)iconImageTintColor { - (UIColor*)iconImageTintColor {
switch (self.iconType) { switch (self.iconType) {
case OmniboxIconTypeImage: case OmniboxIconTypeImage:
......
...@@ -21,11 +21,14 @@ enum OmniboxSuggestionIconType { ...@@ -21,11 +21,14 @@ enum OmniboxSuggestionIconType {
SEARCH, SEARCH,
CONVERSION, CONVERSION,
DICTIONARY, DICTIONARY,
CURRENCY, STOCK,
SUNRISE, SUNRISE,
LOCAL_TIME, LOCAL_TIME,
WHEN_IS, WHEN_IS,
TRANSLATION, TRANSLATION,
// The FALLBACK_ANSWER icon is used for all answers that don't have special
// icons above.
FALLBACK_ANSWER,
OMNIBOX_SUGGESTION_ICON_TYPE_COUNT, OMNIBOX_SUGGESTION_ICON_TYPE_COUNT,
}; };
......
...@@ -36,7 +36,7 @@ NSString* GetOmniboxSuggestionIconTypeAssetName( ...@@ -36,7 +36,7 @@ NSString* GetOmniboxSuggestionIconTypeAssetName(
case DICTIONARY: case DICTIONARY:
NOTREACHED(); NOTREACHED();
return @"omnibox_completion_default_favicon"; return @"omnibox_completion_default_favicon";
case CURRENCY: case STOCK:
NOTREACHED(); NOTREACHED();
return @"omnibox_completion_default_favicon"; return @"omnibox_completion_default_favicon";
case SUNRISE: case SUNRISE:
...@@ -51,6 +51,9 @@ NSString* GetOmniboxSuggestionIconTypeAssetName( ...@@ -51,6 +51,9 @@ NSString* GetOmniboxSuggestionIconTypeAssetName(
case TRANSLATION: case TRANSLATION:
NOTREACHED(); NOTREACHED();
return @"omnibox_completion_default_favicon"; return @"omnibox_completion_default_favicon";
case FALLBACK_ANSWER:
NOTREACHED();
return @"omnibox_completion_default_favicon";
case OMNIBOX_SUGGESTION_ICON_TYPE_COUNT: case OMNIBOX_SUGGESTION_ICON_TYPE_COUNT:
NOTREACHED(); NOTREACHED();
return @"omnibox_completion_default_favicon"; return @"omnibox_completion_default_favicon";
...@@ -78,8 +81,8 @@ NSString* GetOmniboxNewSuggestionIconTypeAssetName( ...@@ -78,8 +81,8 @@ NSString* GetOmniboxNewSuggestionIconTypeAssetName(
return @"answer_conversion"; return @"answer_conversion";
case DICTIONARY: case DICTIONARY:
return @"answer_dictionary"; return @"answer_dictionary";
case CURRENCY: case STOCK:
return @"answer_currency"; return @"answer_stock";
case SUNRISE: case SUNRISE:
return @"answer_sunrise"; return @"answer_sunrise";
case LOCAL_TIME: case LOCAL_TIME:
...@@ -88,6 +91,8 @@ NSString* GetOmniboxNewSuggestionIconTypeAssetName( ...@@ -88,6 +91,8 @@ NSString* GetOmniboxNewSuggestionIconTypeAssetName(
return @"answer_when_is"; return @"answer_when_is";
case TRANSLATION: case TRANSLATION:
return @"answer_translation"; return @"answer_translation";
case FALLBACK_ANSWER:
return @"search";
case OMNIBOX_SUGGESTION_ICON_TYPE_COUNT: case OMNIBOX_SUGGESTION_ICON_TYPE_COUNT:
NOTREACHED(); NOTREACHED();
return @"favicon_fallback"; return @"favicon_fallback";
...@@ -95,9 +100,12 @@ NSString* GetOmniboxNewSuggestionIconTypeAssetName( ...@@ -95,9 +100,12 @@ NSString* GetOmniboxNewSuggestionIconTypeAssetName(
} }
UIImage* GetOmniboxSuggestionIcon(OmniboxSuggestionIconType iconType) { UIImage* GetOmniboxSuggestionIcon(OmniboxSuggestionIconType iconType) {
NSString* imageName = GetOmniboxSuggestionIconTypeAssetName(iconType); NSString* imageName = nil;
if (base::FeatureList::IsEnabled(kNewOmniboxPopupLayout)) if (base::FeatureList::IsEnabled(kNewOmniboxPopupLayout)) {
imageName = GetOmniboxNewSuggestionIconTypeAssetName(iconType); imageName = GetOmniboxNewSuggestionIconTypeAssetName(iconType);
} else {
imageName = GetOmniboxSuggestionIconTypeAssetName(iconType);
}
return [[UIImage imageNamed:imageName] return [[UIImage imageNamed:imageName]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
} }
......
...@@ -22,10 +22,12 @@ source_set("popup") { ...@@ -22,10 +22,12 @@ source_set("popup") {
"//components/image_fetcher/ios", "//components/image_fetcher/ios",
"//components/omnibox/browser", "//components/omnibox/browser",
"//components/open_from_clipboard", "//components/open_from_clipboard",
"//components/search_engines",
"//ios/chrome/app/strings", "//ios/chrome/app/strings",
"//ios/chrome/browser", "//ios/chrome/browser",
"//ios/chrome/browser/browser_state", "//ios/chrome/browser/browser_state",
"//ios/chrome/browser/favicon", "//ios/chrome/browser/favicon",
"//ios/chrome/browser/search_engines",
"//ios/chrome/browser/ui:feature_flags", "//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/commands", "//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/ntp:util", "//ios/chrome/browser/ui/ntp:util",
......
...@@ -8,12 +8,17 @@ ...@@ -8,12 +8,17 @@
#import "ios/chrome/browser/ui/omnibox/popup/autocomplete_suggestion.h" #import "ios/chrome/browser/ui/omnibox/popup/autocomplete_suggestion.h"
struct AutocompleteMatch; struct AutocompleteMatch;
@interface AutocompleteMatchFormatter : NSObject <AutocompleteSuggestion> @interface AutocompleteMatchFormatter : NSObject <AutocompleteSuggestion>
// This is a temporary solution for coloring strings. // This is a temporary solution for coloring strings.
@property(nonatomic, assign, getter=isIncognito) BOOL incognito; @property(nonatomic, assign, getter=isIncognito) BOOL incognito;
@property(nonatomic, assign, getter=isStarred) BOOL starred; @property(nonatomic, assign, getter=isStarred) BOOL starred;
// Whether the default search engine is Google impacts which icon is used in
// some cases
@property(nonatomic, assign) BOOL defaultSearchEngineIsGoogle;
- (instancetype)initWithMatch:(const AutocompleteMatch&)match - (instancetype)initWithMatch:(const AutocompleteMatch&)match
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
......
...@@ -146,7 +146,10 @@ bool ShouldUseNewFormatting() { ...@@ -146,7 +146,10 @@ bool ShouldUseNewFormatting() {
} }
- (id<OmniboxIcon>)icon { - (id<OmniboxIcon>)icon {
return [[OmniboxIconFormatter alloc] initWithMatch:_match]; OmniboxIconFormatter* icon =
[[OmniboxIconFormatter alloc] initWithMatch:_match];
icon.defaultSearchEngineIsGoogle = self.defaultSearchEngineIsGoogle;
return icon;
} }
- (NSInteger)numberOfLines { - (NSInteger)numberOfLines {
......
...@@ -8,8 +8,10 @@ ...@@ -8,8 +8,10 @@
#import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h" #import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h"
#include "components/omnibox/browser/autocomplete_result.h" #include "components/omnibox/browser/autocomplete_result.h"
#include "components/omnibox/common/omnibox_features.h" #include "components/omnibox/common/omnibox_features.h"
#import "components/search_engines/template_url_service.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h" #include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/favicon/ios_chrome_favicon_loader_factory.h" #include "ios/chrome/browser/favicon/ios_chrome_favicon_loader_factory.h"
#include "ios/chrome/browser/search_engines/template_url_service_factory.h"
#import "ios/chrome/browser/ui/commands/command_dispatcher.h" #import "ios/chrome/browser/ui/commands/command_dispatcher.h"
#import "ios/chrome/browser/ui/ntp/ntp_util.h" #import "ios/chrome/browser/ui/ntp/ntp_util.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_legacy_view_controller.h" #import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_legacy_view_controller.h"
...@@ -68,6 +70,13 @@ ...@@ -68,6 +70,13 @@
delegate:_popupView.get()]; delegate:_popupView.get()];
self.mediator.dispatcher = (id<BrowserCommands>)self.dispatcher; self.mediator.dispatcher = (id<BrowserCommands>)self.dispatcher;
self.mediator.webStateList = self.webStateList; self.mediator.webStateList = self.webStateList;
TemplateURLService* templateURLService =
ios::TemplateURLServiceFactory::GetForBrowserState(self.browserState);
self.mediator.defaultSearchEngineIsGoogle =
templateURLService && templateURLService->GetDefaultSearchProvider() &&
templateURLService->GetDefaultSearchProvider()->GetEngineType(
templateURLService->search_terms_data()) == SEARCH_ENGINE_GOOGLE;
if (base::FeatureList::IsEnabled(kNewOmniboxPopupLayout)) { if (base::FeatureList::IsEnabled(kNewOmniboxPopupLayout)) {
self.popupViewController = [[OmniboxPopupViewController alloc] init]; self.popupViewController = [[OmniboxPopupViewController alloc] init];
} else { } else {
......
...@@ -66,6 +66,9 @@ class OmniboxPopupMediatorDelegate { ...@@ -66,6 +66,9 @@ class OmniboxPopupMediatorDelegate {
@property(nonatomic, strong) OmniboxPopupPresenter* presenter; @property(nonatomic, strong) OmniboxPopupPresenter* presenter;
// The web state list this mediator is handling. // The web state list this mediator is handling.
@property(nonatomic, assign) WebStateList* webStateList; @property(nonatomic, assign) WebStateList* webStateList;
// Whether the default search engine is Google impacts which icon is used in
// some cases
@property(nonatomic, assign) BOOL defaultSearchEngineIsGoogle;
// Designated initializer. Takes ownership of |imageFetcher|. // Designated initializer. Takes ownership of |imageFetcher|.
- (instancetype)initWithFetcher: - (instancetype)initWithFetcher:
......
...@@ -81,6 +81,7 @@ const CGFloat kOmniboxIconSize = 16; ...@@ -81,6 +81,7 @@ const CGFloat kOmniboxIconSize = 16;
[AutocompleteMatchFormatter formatterWithMatch:match]; [AutocompleteMatchFormatter formatterWithMatch:match];
formatter.starred = _delegate->IsStarredMatch(match); formatter.starred = _delegate->IsStarredMatch(match);
formatter.incognito = _incognito; formatter.incognito = _incognito;
formatter.defaultSearchEngineIsGoogle = self.defaultSearchEngineIsGoogle;
[wrappedMatches addObject:formatter]; [wrappedMatches addObject:formatter];
} }
......
...@@ -100,11 +100,11 @@ imageset("answer_dictionary") { ...@@ -100,11 +100,11 @@ imageset("answer_dictionary") {
] ]
} }
imageset("answer_currency") { imageset("answer_stock") {
sources = [ sources = [
"answer_currency.imageset/Contents.json", "answer_stock.imageset/Contents.json",
"answer_currency.imageset/answer_currency@2x.png", "answer_stock.imageset/answer_stock@2x.png",
"answer_currency.imageset/answer_currency@3x.png", "answer_stock.imageset/answer_stock@3x.png",
] ]
} }
......
...@@ -3,12 +3,12 @@ ...@@ -3,12 +3,12 @@
{ {
"idiom": "universal", "idiom": "universal",
"scale": "2x", "scale": "2x",
"filename": "answer_currency@2x.png" "filename": "answer_stock@2x.png"
}, },
{ {
"idiom": "universal", "idiom": "universal",
"scale": "3x", "scale": "3x",
"filename": "answer_currency@3x.png" "filename": "answer_stock@3x.png"
} }
], ],
"info": { "info": {
......
...@@ -54,6 +54,10 @@ class BrandedImageProvider { ...@@ -54,6 +54,10 @@ class BrandedImageProvider {
virtual UIImage* GetToolbarSearchIcon(SearchEngineIcon type, virtual UIImage* GetToolbarSearchIcon(SearchEngineIcon type,
bool dark_version); bool dark_version);
// Returns the 30pt x 30pt image to use for the fallback icon for answers in
// the omnibox popup and in the omnibox as the default search engine icon.
virtual UIImage* GetOmniboxAnswerIcon();
private: private:
DISALLOW_COPY_AND_ASSIGN(BrandedImageProvider); DISALLOW_COPY_AND_ASSIGN(BrandedImageProvider);
}; };
......
...@@ -51,3 +51,7 @@ UIImage* BrandedImageProvider::GetToolbarSearchIcon(SearchEngineIcon type, ...@@ -51,3 +51,7 @@ UIImage* BrandedImageProvider::GetToolbarSearchIcon(SearchEngineIcon type,
bool dark_version) { bool dark_version) {
return [UIImage imageNamed:@"toolbar_search"]; return [UIImage imageNamed:@"toolbar_search"];
} }
UIImage* BrandedImageProvider::GetOmniboxAnswerIcon() {
return nil;
}
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