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") {
"//components/omnibox/browser",
"//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/colors",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/images",
"//url",
]
}
......@@ -75,9 +77,9 @@ source_set("omnibox_util") {
deps = [
"resources:answer_calculator",
"resources:answer_conversion",
"resources:answer_currency",
"resources:answer_dictionary",
"resources:answer_local_time",
"resources:answer_stock",
"resources:answer_sunrise",
"resources:answer_translation",
"resources:answer_when_is",
......
......@@ -17,6 +17,10 @@ struct AutocompleteMatch;
NS_DESIGNATED_INITIALIZER;
- (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
#endif // IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_ICON_FORMATTER_H_
......@@ -8,6 +8,8 @@
#import "ios/chrome/browser/ui/colors/MDCPalette+CrAdditions.h"
#import "ios/chrome/browser/ui/omnibox/omnibox_util.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"
#if !defined(__has_feature) || !__has_feature(objc_arc)
......@@ -19,14 +21,12 @@ namespace {
OmniboxSuggestionIconType IconTypeFromMatchAndAnswerType(
AutocompleteMatchType::Type type,
base::Optional<int> answerType) {
// Some suggestions have custom icons. Others fallback to the icon from the
// overall match type.
if (answerType) {
switch (answerType.value()) {
case SuggestionAnswer::ANSWER_TYPE_DICTIONARY:
return DICTIONARY;
case SuggestionAnswer::ANSWER_TYPE_FINANCE:
return CURRENCY;
return STOCK;
case SuggestionAnswer::ANSWER_TYPE_TRANSLATION:
return TRANSLATION;
case SuggestionAnswer::ANSWER_TYPE_WHEN_IS:
......@@ -41,7 +41,7 @@ OmniboxSuggestionIconType IconTypeFromMatchAndAnswerType(
case SuggestionAnswer::ANSWER_TYPE_LOCAL_TIME:
case SuggestionAnswer::ANSWER_TYPE_PLAY_INSTALL:
case SuggestionAnswer::ANSWER_TYPE_WEATHER:
break;
return FALLBACK_ANSWER;
case SuggestionAnswer::ANSWER_TYPE_INVALID:
case SuggestionAnswer::ANSWER_TYPE_TOTAL_COUNT:
NOTREACHED();
......@@ -127,10 +127,12 @@ OmniboxSuggestionIconType IconTypeFromMatchAndAnswerType(
}
- (UIImage*)iconImage {
NSString* imageName =
GetOmniboxNewSuggestionIconTypeAssetName(self.suggestionIconType);
return [[UIImage imageNamed:imageName]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
if (self.suggestionIconType == FALLBACK_ANSWER &&
self.defaultSearchEngineIsGoogle && [self fallbackAnswerBrandedIcon]) {
return [[self fallbackAnswerBrandedIcon]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
return GetOmniboxSuggestionIcon(self.suggestionIconType);
}
- (BOOL)hasCustomAnswerIcon {
......@@ -143,18 +145,32 @@ OmniboxSuggestionIconType IconTypeFromMatchAndAnswerType(
case CALCULATOR:
case CONVERSION:
case DICTIONARY:
case CURRENCY:
case STOCK:
case SUNRISE:
case LOCAL_TIME:
case WHEN_IS:
case TRANSLATION:
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:
NOTREACHED();
return NO;
}
}
- (UIImage*)fallbackAnswerBrandedIcon {
return ios::GetChromeBrowserProvider()
->GetBrandedImageProvider()
->GetOmniboxAnswerIcon();
}
- (UIColor*)iconImageTintColor {
switch (self.iconType) {
case OmniboxIconTypeImage:
......
......@@ -21,11 +21,14 @@ enum OmniboxSuggestionIconType {
SEARCH,
CONVERSION,
DICTIONARY,
CURRENCY,
STOCK,
SUNRISE,
LOCAL_TIME,
WHEN_IS,
TRANSLATION,
// The FALLBACK_ANSWER icon is used for all answers that don't have special
// icons above.
FALLBACK_ANSWER,
OMNIBOX_SUGGESTION_ICON_TYPE_COUNT,
};
......
......@@ -36,7 +36,7 @@ NSString* GetOmniboxSuggestionIconTypeAssetName(
case DICTIONARY:
NOTREACHED();
return @"omnibox_completion_default_favicon";
case CURRENCY:
case STOCK:
NOTREACHED();
return @"omnibox_completion_default_favicon";
case SUNRISE:
......@@ -51,6 +51,9 @@ NSString* GetOmniboxSuggestionIconTypeAssetName(
case TRANSLATION:
NOTREACHED();
return @"omnibox_completion_default_favicon";
case FALLBACK_ANSWER:
NOTREACHED();
return @"omnibox_completion_default_favicon";
case OMNIBOX_SUGGESTION_ICON_TYPE_COUNT:
NOTREACHED();
return @"omnibox_completion_default_favicon";
......@@ -78,8 +81,8 @@ NSString* GetOmniboxNewSuggestionIconTypeAssetName(
return @"answer_conversion";
case DICTIONARY:
return @"answer_dictionary";
case CURRENCY:
return @"answer_currency";
case STOCK:
return @"answer_stock";
case SUNRISE:
return @"answer_sunrise";
case LOCAL_TIME:
......@@ -88,6 +91,8 @@ NSString* GetOmniboxNewSuggestionIconTypeAssetName(
return @"answer_when_is";
case TRANSLATION:
return @"answer_translation";
case FALLBACK_ANSWER:
return @"search";
case OMNIBOX_SUGGESTION_ICON_TYPE_COUNT:
NOTREACHED();
return @"favicon_fallback";
......@@ -95,9 +100,12 @@ NSString* GetOmniboxNewSuggestionIconTypeAssetName(
}
UIImage* GetOmniboxSuggestionIcon(OmniboxSuggestionIconType iconType) {
NSString* imageName = GetOmniboxSuggestionIconTypeAssetName(iconType);
if (base::FeatureList::IsEnabled(kNewOmniboxPopupLayout))
NSString* imageName = nil;
if (base::FeatureList::IsEnabled(kNewOmniboxPopupLayout)) {
imageName = GetOmniboxNewSuggestionIconTypeAssetName(iconType);
} else {
imageName = GetOmniboxSuggestionIconTypeAssetName(iconType);
}
return [[UIImage imageNamed:imageName]
imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
}
......
......@@ -22,10 +22,12 @@ source_set("popup") {
"//components/image_fetcher/ios",
"//components/omnibox/browser",
"//components/open_from_clipboard",
"//components/search_engines",
"//ios/chrome/app/strings",
"//ios/chrome/browser",
"//ios/chrome/browser/browser_state",
"//ios/chrome/browser/favicon",
"//ios/chrome/browser/search_engines",
"//ios/chrome/browser/ui:feature_flags",
"//ios/chrome/browser/ui/commands",
"//ios/chrome/browser/ui/ntp:util",
......
......@@ -8,12 +8,17 @@
#import "ios/chrome/browser/ui/omnibox/popup/autocomplete_suggestion.h"
struct AutocompleteMatch;
@interface AutocompleteMatchFormatter : NSObject <AutocompleteSuggestion>
// This is a temporary solution for coloring strings.
@property(nonatomic, assign, getter=isIncognito) BOOL incognito;
@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
NS_DESIGNATED_INITIALIZER;
- (instancetype)init NS_UNAVAILABLE;
......
......@@ -146,7 +146,10 @@ bool ShouldUseNewFormatting() {
}
- (id<OmniboxIcon>)icon {
return [[OmniboxIconFormatter alloc] initWithMatch:_match];
OmniboxIconFormatter* icon =
[[OmniboxIconFormatter alloc] initWithMatch:_match];
icon.defaultSearchEngineIsGoogle = self.defaultSearchEngineIsGoogle;
return icon;
}
- (NSInteger)numberOfLines {
......
......@@ -8,8 +8,10 @@
#import "components/image_fetcher/ios/ios_image_data_fetcher_wrapper.h"
#include "components/omnibox/browser/autocomplete_result.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/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/ntp/ntp_util.h"
#import "ios/chrome/browser/ui/omnibox/popup/omnibox_popup_legacy_view_controller.h"
......@@ -68,6 +70,13 @@
delegate:_popupView.get()];
self.mediator.dispatcher = (id<BrowserCommands>)self.dispatcher;
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)) {
self.popupViewController = [[OmniboxPopupViewController alloc] init];
} else {
......
......@@ -66,6 +66,9 @@ class OmniboxPopupMediatorDelegate {
@property(nonatomic, strong) OmniboxPopupPresenter* presenter;
// The web state list this mediator is handling.
@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|.
- (instancetype)initWithFetcher:
......
......@@ -81,6 +81,7 @@ const CGFloat kOmniboxIconSize = 16;
[AutocompleteMatchFormatter formatterWithMatch:match];
formatter.starred = _delegate->IsStarredMatch(match);
formatter.incognito = _incognito;
formatter.defaultSearchEngineIsGoogle = self.defaultSearchEngineIsGoogle;
[wrappedMatches addObject:formatter];
}
......
......@@ -100,11 +100,11 @@ imageset("answer_dictionary") {
]
}
imageset("answer_currency") {
imageset("answer_stock") {
sources = [
"answer_currency.imageset/Contents.json",
"answer_currency.imageset/answer_currency@2x.png",
"answer_currency.imageset/answer_currency@3x.png",
"answer_stock.imageset/Contents.json",
"answer_stock.imageset/answer_stock@2x.png",
"answer_stock.imageset/answer_stock@3x.png",
]
}
......
......@@ -3,12 +3,12 @@
{
"idiom": "universal",
"scale": "2x",
"filename": "answer_currency@2x.png"
"filename": "answer_stock@2x.png"
},
{
"idiom": "universal",
"scale": "3x",
"filename": "answer_currency@3x.png"
"filename": "answer_stock@3x.png"
}
],
"info": {
......
......@@ -54,6 +54,10 @@ class BrandedImageProvider {
virtual UIImage* GetToolbarSearchIcon(SearchEngineIcon type,
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:
DISALLOW_COPY_AND_ASSIGN(BrandedImageProvider);
};
......
......@@ -51,3 +51,7 @@ UIImage* BrandedImageProvider::GetToolbarSearchIcon(SearchEngineIcon type,
bool dark_version) {
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