Commit 2392f2ae authored by Gauthier Ambard's avatar Gauthier Ambard Committed by Commit Bot

[iOS] Add switch to change the search icon

This CL adds a switch enum to chrome://flags to change the icon
displayed by the search button in the bottom toolbar.

Bug: 866013
Change-Id: I1892cb02f42bc6d1324e276b9022663e48b45b3b
Reviewed-on: https://chromium-review.googlesource.com/c/1297972
Commit-Queue: Gauthier Ambard <gambard@chromium.org>
Reviewed-by: default avatarMark Cogan <marq@chromium.org>
Cr-Commit-Position: refs/heads/master@{#602361}
parent c832d15f
......@@ -132,6 +132,24 @@ const FeatureEntry::Choice kAutofillIOSDelayBetweenFieldsChoices[] = {
{"1000", autofill::switches::kAutofillIOSDelayBetweenFields, "1000"},
};
const FeatureEntry::FeatureParam kIconForSearchButtonGrey[] = {
{kIconForSearchButtonFeatureParameterName,
kIconForSearchButtonParameterGrey}};
const FeatureEntry::FeatureParam kIconForSearchButtonColorful[] = {
{kIconForSearchButtonFeatureParameterName,
kIconForSearchButtonParameterColorful}};
const FeatureEntry::FeatureParam kIconForSearchButtonMagnifying[] = {
{kIconForSearchButtonFeatureParameterName,
kIconForSearchButtonParameterMagnifying}};
const FeatureEntry::FeatureVariation kIconForSearchButtonVariations[] = {
{"Grey search engine logo", kIconForSearchButtonGrey,
base::size(kIconForSearchButtonGrey), nullptr},
{"Colorful search engine logo", kIconForSearchButtonColorful,
base::size(kIconForSearchButtonColorful), nullptr},
{"Magnifying glass", kIconForSearchButtonMagnifying,
base::size(kIconForSearchButtonMagnifying), nullptr}};
// To add a new entry, add to the end of kFeatureEntries. There are four
// distinct types of entries:
// . ENABLE_DISABLE_VALUE: entry is either enabled, disabled, or uses the
......@@ -391,6 +409,11 @@ const flags_ui::FeatureEntry kFeatureEntries[] = {
flag_descriptions::kBrowserContainerContainsNTPName,
flag_descriptions::kBrowserContainerContainsNTPDescription,
flags_ui::kOsIos, FEATURE_VALUE_TYPE(kBrowserContainerContainsNTP)},
{"search-icon-toggle", flag_descriptions::kSearchIconToggleName,
flag_descriptions::kSearchIconToggleDescription, flags_ui::kOsIos,
FEATURE_WITH_PARAMS_VALUE_TYPE(kIconForSearchButtonFeature,
kIconForSearchButtonVariations,
"ToggleSearchButtonIcon")},
};
// Add all switches from experimental flags to |command_line|.
......
......@@ -250,6 +250,10 @@ const char kIgnoresViewportScaleLimitsName[] = "Ignore Viewport Scale Limits";
const char kIgnoresViewportScaleLimitsDescription[] =
"When enabled the page can always be scaled, regardless of author intent.";
const char kSearchIconToggleName[] = "Change the icon for the search button";
const char kSearchIconToggleDescription[] =
"Different icons for the search button.";
const char kSlimNavigationManagerName[] = "Use Slim Navigation Manager";
const char kSlimNavigationManagerDescription[] =
"When enabled, uses the experimental slim navigation manager that provides "
......
......@@ -207,6 +207,10 @@ extern const char kPhysicalWebDescription[];
extern const char kIgnoresViewportScaleLimitsName[];
extern const char kIgnoresViewportScaleLimitsDescription[];
// Title and description for the flag to toggle the flag of the search button.
extern const char kSearchIconToggleName[];
extern const char kSearchIconToggleDescription[];
// Title and description for the flag to enable WKBackForwardList based
// navigation manager.
extern const char kSlimNavigationManagerName[];
......
......@@ -55,6 +55,7 @@ source_set("toolbar") {
"//ios/chrome/browser/web_state_list",
"//ios/chrome/common",
"//ios/public/provider/chrome/browser",
"//ios/public/provider/chrome/browser/images",
"//ios/public/provider/chrome/browser/voice",
"//ios/web",
]
......
......@@ -6,6 +6,7 @@
#include "ios/chrome/browser/bookmarks/bookmark_model_factory.h"
#include "ios/chrome/browser/browser_state/chrome_browser_state.h"
#include "ios/chrome/browser/search_engines/template_url_service_factory.h"
#import "ios/chrome/browser/ui/ntp/ntp_util.h"
#import "ios/chrome/browser/ui/toolbar/adaptive_toolbar_coordinator+subclassing.h"
#import "ios/chrome/browser/ui/toolbar/adaptive_toolbar_view_controller.h"
......@@ -53,6 +54,8 @@
self.viewController.longPressDelegate = self.longPressDelegate;
self.mediator = [[ToolbarMediator alloc] init];
self.mediator.templateURLService =
ios::TemplateURLServiceFactory::GetForBrowserState(self.browserState);
self.mediator.consumer = self.viewController;
self.mediator.webStateList = self.webStateList;
self.mediator.bookmarkModel =
......
......@@ -225,6 +225,10 @@ const CGFloat kTabGridAnimationsTotalDuration = 0.5;
_isNTP = isNTP;
}
- (void)setSearchIcon:(UIImage*)searchIcon {
[self.view.omniboxButton setImage:searchIcon forState:UIControlStateNormal];
}
#pragma mark - NewTabPageControllerDelegate
- (void)setScrollProgressForTabletOmnibox:(CGFloat)progress {
......
......@@ -48,7 +48,10 @@ const CGFloat kSpotlightHeight = 38.0f;
spotlightView.layer.cornerRadius = kSpotlightHeight / 2;
spotlightView.backgroundColor =
[self.configuration locationBarBackgroundColorWithVisibility:1];
[self addSubview:spotlightView];
// Make sure that the spotlightView is below the image to avoid changing the
// color of the image.
[self insertSubview:spotlightView belowSubview:self.imageView];
AddSameCenterConstraints(self, spotlightView);
[spotlightView.heightAnchor constraintEqualToConstant:kSpotlightHeight]
.active = YES;
......
......@@ -27,8 +27,8 @@ source_set("public") {
source_set("feature_flags") {
sources = [
"features.cc",
"features.h",
"features.mm",
]
deps = [
"//base",
......
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/toolbar/public/features.h"
#include "base/command_line.h"
const base::Feature kMemexTabSwitcher{"MemexTabSwitcher",
base::FEATURE_DISABLED_BY_DEFAULT};
......@@ -5,10 +5,33 @@
#ifndef IOS_CHROME_BROWSER_UI_TOOLBAR_PUBLIC_FEATURES_H_
#define IOS_CHROME_BROWSER_UI_TOOLBAR_PUBLIC_FEATURES_H_
#import <Foundation/Foundation.h>
#include "base/feature_list.h"
// Enum for the different icons for the search button.
typedef NS_ENUM(NSUInteger, ToolbarSearchButtonIcon) {
ToolbarSearchButtonIconGrey,
ToolbarSearchButtonIconColorful,
ToolbarSearchButtonIconMagnifying,
};
// Feature to choose whether to use the memex prototype tab switcher or the
// regular native tab switcher.
extern const base::Feature kMemexTabSwitcher;
// Feature for changing the different icons for search icon in the bottom
// toolbar.
extern const base::Feature kIconForSearchButtonFeature;
// Switch with the different values for the search icon on the bottom adaptive
// toolbar.
extern const char kIconForSearchButtonFeatureParameterName[];
extern const char kIconForSearchButtonParameterGrey[];
extern const char kIconForSearchButtonParameterColorful[];
extern const char kIconForSearchButtonParameterMagnifying[];
// Returns the currently selected icon option.
ToolbarSearchButtonIcon IconForSearchButton();
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_PUBLIC_FEATURES_H_
// Copyright 2017 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#import "ios/chrome/browser/ui/toolbar/public/features.h"
#include "base/command_line.h"
#include "base/metrics/field_trial_params.h"
#if !defined(__has_feature) || !__has_feature(objc_arc)
#error "This file requires ARC support."
#endif
const base::Feature kMemexTabSwitcher{"MemexTabSwitcher",
base::FEATURE_DISABLED_BY_DEFAULT};
const base::Feature kIconForSearchButtonFeature{
"IconForSearchButtonFeature", base::FEATURE_DISABLED_BY_DEFAULT};
const char kIconForSearchButtonFeatureParameterName[] = "icon";
const char kIconForSearchButtonParameterGrey[] = "grey";
const char kIconForSearchButtonParameterColorful[] = "colorful";
const char kIconForSearchButtonParameterMagnifying[] = "magnifying";
ToolbarSearchButtonIcon IconForSearchButton() {
if (base::FeatureList::IsEnabled(kIconForSearchButtonFeature)) {
std::string parameter = base::GetFieldTrialParamValueByFeature(
kIconForSearchButtonFeature, kIconForSearchButtonFeatureParameterName);
if (parameter == kIconForSearchButtonParameterGrey) {
return ToolbarSearchButtonIconGrey;
} else if (parameter == kIconForSearchButtonParameterColorful) {
return ToolbarSearchButtonIconColorful;
} else if (parameter == kIconForSearchButtonParameterMagnifying) {
return ToolbarSearchButtonIconMagnifying;
}
}
return ToolbarSearchButtonIconMagnifying;
}
......@@ -111,8 +111,9 @@
AddSameConstraints(self.blur, self);
UIView* contentView = self;
if (UIVisualEffect* vibrancy = [self.buttonFactory.toolbarConfiguration
vibrancyEffectForBlurEffect:blurEffect]) {
UIVisualEffect* vibrancy = [self.buttonFactory.toolbarConfiguration
vibrancyEffectForBlurEffect:blurEffect];
if (vibrancy && IconForSearchButton() != ToolbarSearchButtonIconColorful) {
// Add vibrancy only if we have a vibrancy effect.
UIVisualEffectView* vibrancyView =
[[UIVisualEffectView alloc] initWithEffect:vibrancy];
......
......@@ -29,6 +29,8 @@
- (void)setShareMenuEnabled:(BOOL)enabled;
// Sets whether the toolbar is displaying for an NTP.
- (void)setIsNTP:(BOOL)isNTP;
// Sets the image for the search button of the toolbar.
- (void)setSearchIcon:(UIImage*)searchIcon;
@end
#endif // IOS_CHROME_BROWSER_UI_TOOLBAR_TOOLBAR_CONSUMER_H_
......@@ -15,12 +15,16 @@ class BookmarkModel;
namespace web {
class WebState;
}
class TemplateURLService;
class WebStateList;
// A mediator object that provides the relevant properties of a web state
// to a consumer.
@interface ToolbarMediator : NSObject
// TemplateURLService used to check the default search engine.
@property(nonatomic, assign) TemplateURLService* templateURLService;
// The WebStateList that this mediator listens for any changes on the total
// number of Webstates.
@property(nonatomic, assign) WebStateList* webStateList;
......
......@@ -9,12 +9,14 @@
#include "base/strings/sys_string_conversions.h"
#include "components/bookmarks/browser/bookmark_model.h"
#include "ios/chrome/browser/chrome_url_constants.h"
#import "ios/chrome/browser/search_engines/search_engine_observer_bridge.h"
#include "ios/chrome/browser/ui/bookmarks/bookmark_model_bridge_observer.h"
#import "ios/chrome/browser/ui/ntp/ntp_util.h"
#import "ios/chrome/browser/ui/toolbar/toolbar_consumer.h"
#import "ios/chrome/browser/web_state_list/web_state_list.h"
#import "ios/chrome/browser/web_state_list/web_state_list_observer_bridge.h"
#include "ios/public/provider/chrome/browser/chrome_browser_provider.h"
#import "ios/public/provider/chrome/browser/images/branded_image_provider.h"
#import "ios/public/provider/chrome/browser/voice/voice_search_provider.h"
#import "ios/web/public/navigation_manager.h"
#import "ios/web/public/web_client.h"
......@@ -27,6 +29,7 @@
@interface ToolbarMediator ()<BookmarkModelBridgeObserver,
CRWWebStateObserver,
SearchEngineObserving,
WebStateListObserving>
// The current web state associated with the toolbar.
......@@ -39,6 +42,8 @@
std::unique_ptr<WebStateListObserverBridge> _webStateListObserver;
// Bridge to register for bookmark changes.
std::unique_ptr<bookmarks::BookmarkModelBridge> _bookmarkModelBridge;
// Listen for default search engine changes.
std::unique_ptr<SearchEngineObserverBridge> _searchEngineObserver;
}
@synthesize bookmarkModel = _bookmarkModel;
......@@ -80,6 +85,7 @@
_webState = nullptr;
}
_bookmarkModelBridge.reset();
_searchEngineObserver.reset();
}
#pragma mark - CRWWebStateObserver
......@@ -168,6 +174,16 @@
#pragma mark - Setters
- (void)setTemplateURLService:(TemplateURLService*)templateURLService {
_templateURLService = templateURLService;
if (templateURLService) {
// Listen for default search engine changes.
_searchEngineObserver =
std::make_unique<SearchEngineObserverBridge>(self, templateURLService);
templateURLService->Load();
}
}
- (void)setWebState:(web::WebState*)webState {
if (_webState) {
_webState->RemoveObserver(_webStateObserver.get());
......@@ -301,4 +317,21 @@
// No-op -- required by BookmarkModelBridgeObserver but not used.
}
#pragma mark - SearchEngineObserving
- (void)searchEngineChanged {
SearchEngineIcon searchEngineIcon = SEARCH_ENGINE_ICON_OTHER;
if (self.templateURLService &&
self.templateURLService->GetDefaultSearchProvider() &&
self.templateURLService->GetDefaultSearchProvider()->GetEngineType(
self.templateURLService->search_terms_data()) ==
SEARCH_ENGINE_GOOGLE) {
searchEngineIcon = SEARCH_ENGINE_ICON_GOOGLE_SEARCH;
}
UIImage* searchIcon = ios::GetChromeBrowserProvider()
->GetBrandedImageProvider()
->GetToolbarSearchIcon(searchEngineIcon);
[self.consumer setSearchIcon:searchIcon];
}
@end
......@@ -50,6 +50,9 @@ class BrandedImageProvider {
// on Download Manager UI.
virtual UIImage* GetDownloadGoogleDriveImage();
// Returns the 28pt x 28pt image to use for the "Search" icon in the toolbar.
virtual UIImage* GetToolbarSearchIcon(SearchEngineIcon type);
private:
DISALLOW_COPY_AND_ASSIGN(BrandedImageProvider);
};
......
......@@ -46,3 +46,7 @@ UIImage* BrandedImageProvider::GetWhatsNewIconImage(WhatsNewIcon type) {
UIImage* BrandedImageProvider::GetDownloadGoogleDriveImage() {
return nil;
}
UIImage* BrandedImageProvider::GetToolbarSearchIcon(SearchEngineIcon type) {
return [UIImage imageNamed:@"toolbar_search"];
}
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