From 10f565216206a71a4d7da5d04c73be89069442d0 Mon Sep 17 00:00:00 2001 From: orenb Date: Fri, 1 May 2015 18:13:19 -0700 Subject: [PATCH] Clicking "manage search engines" on the search settings page now opens the new subpage. It also provides a mechanism for adding a new search engine. BUG=479359 Review URL: https://codereview.chromium.org/1119773002 Cr-Commit-Position: refs/heads/master@{#328037} --- chrome/app/settings_strings.grdp | 26 +++++++++++ chrome/browser/resources/settings/routes.html | 4 +- .../search_engines_page/search_engine_adder.html | 45 +++++++++++++++++++ .../search_engines_page/search_engine_adder.js | 27 +++++++++++ .../search_engine_adder_style.html | 21 +++++++++ .../search_engines_page/search_engines_page.html | 20 +++++++++ .../search_engines_page.js} | 52 ++++++++++++++++------ .../search_engines_page_style.html | 16 +++++++ .../settings/search_page/search_page.html | 4 +- .../resources/settings/search_page/search_page.js | 18 +++++++- .../settings/settings_main/settings_main.html | 4 ++ .../resources/settings/settings_resources.grd | 22 +++++++++ .../md_settings_localized_strings_provider.cc | 22 +++++++++ .../resources/cr_elements/cr_input/cr_input.js | 6 ++- 14 files changed, 268 insertions(+), 19 deletions(-) create mode 100644 chrome/browser/resources/settings/search_engines_page/search_engine_adder.html create mode 100644 chrome/browser/resources/settings/search_engines_page/search_engine_adder.js create mode 100644 chrome/browser/resources/settings/search_engines_page/search_engine_adder_style.html create mode 100644 chrome/browser/resources/settings/search_engines_page/search_engines_page.html copy chrome/browser/resources/settings/{search_page/search_page.js => search_engines_page/search_engines_page.js} (66%) create mode 100644 chrome/browser/resources/settings/search_engines_page/search_engines_page_style.html diff --git a/chrome/app/settings_strings.grdp b/chrome/app/settings_strings.grdp index 1376ca809bbf..6db525a54830 100644 --- a/chrome/app/settings_strings.grdp +++ b/chrome/app/settings_strings.grdp @@ -110,4 +110,30 @@ Say "Ok Google" in a new tab and google.com + + + Search Engines + + + Add a search engine + + + Search engines + + + Other search engines + + + Domain + + + Keyword + + + Query URL + + + Add + + diff --git a/chrome/browser/resources/settings/routes.html b/chrome/browser/resources/settings/routes.html index 56f65e92db2c..80a3d4bfef95 100644 --- a/chrome/browser/resources/settings/routes.html +++ b/chrome/browser/resources/settings/routes.html @@ -10,4 +10,6 @@ - + + + diff --git a/chrome/browser/resources/settings/search_engines_page/search_engine_adder.html b/chrome/browser/resources/settings/search_engines_page/search_engine_adder.html new file mode 100644 index 000000000000..e93112bbd5fe --- /dev/null +++ b/chrome/browser/resources/settings/search_engines_page/search_engine_adder.html @@ -0,0 +1,45 @@ + + + + + + + + + + + diff --git a/chrome/browser/resources/settings/search_engines_page/search_engine_adder.js b/chrome/browser/resources/settings/search_engines_page/search_engine_adder.js new file mode 100644 index 000000000000..1ec55227ffc7 --- /dev/null +++ b/chrome/browser/resources/settings/search_engines_page/search_engine_adder.js @@ -0,0 +1,27 @@ +// Copyright 2015 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. + +/** + * @fileoverview 'cr-search-engine-adder' is a component for adding a new search + * engine. + * + * @group Chrome Settings Elements + * @element cr-settings-search-engine-adder + */ +Polymer('cr-search-engine-adder', { + /** @private */ + add_: function() { + if (!this.$.domainField.isInvalid && + !this.$.keywordField.isInvalid && + !this.$.queryURLField.isInvalid) { + chrome.searchEnginesPrivate.addOtherSearchEngine( + /* name */ this.$.domainField.value, + /* keyword */ this.$.keywordField.value, + /* url */ this.$.queryURLField.value); + this.$.domainField.value = ''; + this.$.keywordField.value = ''; + this.$.queryURLField.value = ''; + } + }, +}); diff --git a/chrome/browser/resources/settings/search_engines_page/search_engine_adder_style.html b/chrome/browser/resources/settings/search_engines_page/search_engine_adder_style.html new file mode 100644 index 000000000000..d2ae03e63212 --- /dev/null +++ b/chrome/browser/resources/settings/search_engines_page/search_engine_adder_style.html @@ -0,0 +1,21 @@ + + + + +.input-label { + font-size: 0.75em; +} + +.container { + margin-top: 14px; + width: 660px; +} + +.add-label { + width: 660px; +} + +.input-field { + -webkit-margin-end: 20px; +} + diff --git a/chrome/browser/resources/settings/search_engines_page/search_engines_page.html b/chrome/browser/resources/settings/search_engines_page/search_engines_page.html new file mode 100644 index 000000000000..4338ee949a5d --- /dev/null +++ b/chrome/browser/resources/settings/search_engines_page/search_engines_page.html @@ -0,0 +1,20 @@ + + + + + + + + + + + diff --git a/chrome/browser/resources/settings/search_page/search_page.js b/chrome/browser/resources/settings/search_engines_page/search_engines_page.js similarity index 66% copy from chrome/browser/resources/settings/search_page/search_page.js copy to chrome/browser/resources/settings/search_engines_page/search_engines_page.js index 00c03cdce399..176468ff44fb 100644 --- a/chrome/browser/resources/settings/search_page/search_page.js +++ b/chrome/browser/resources/settings/search_engines_page/search_engines_page.js @@ -3,20 +3,21 @@ // found in the LICENSE file. /** - * @fileoverview - * 'cr-settings-search-page' is the settings page containing search settings. + * @fileoverview 'cr-settings-search-engines-page' is the settings page + * containing search engines settings. * * Example: * * - * + * + * * ... other pages ... * * * @group Chrome Settings Elements - * @element cr-settings-search-page + * @element cr-settings-search-engines-page */ -Polymer('cr-settings-search-page', { +Polymer('cr-settings-search-engines-page', { publish: { /** * Preferences state. @@ -28,13 +29,22 @@ Polymer('cr-settings-search-page', { prefs: null, /** + * Route for the page. + * + * @attribute route + * @type {string} + * @default '' + */ + route: '', + + /** * Whether the page is a subpage. * * @attribute subpage * @type {boolean} - * @default false + * @default true */ - subpage: false, + subpage: true, /** * ID of the page. @@ -43,7 +53,7 @@ Polymer('cr-settings-search-page', { * @const {string} * @default 'search' */ - PAGE_ID: 'search', + PAGE_ID: 'search_engines', /** * Title for the page header and navigation menu. @@ -51,7 +61,7 @@ Polymer('cr-settings-search-page', { * @attribute pageTitle * @type {string} */ - pageTitle: loadTimeData.getString('searchPageTitle'), + pageTitle: loadTimeData.getString('searchEnginesPageTitle'), /** * Name of the 'core-icon' to be shown in the settings-page-header. @@ -65,11 +75,20 @@ Polymer('cr-settings-search-page', { /** * List of default search engines available. * - * @attribute searchEngines - * @type {Array} + * @default null + */ + defaultSearchEngines: null, + + /** + * List of other search engines available. + * + * @attribute otherSearchEngines + * @type {Array} * @default null */ - searchEngines: null, + otherSearchEngines: null, /** * GUID of the currently selected default search engine. @@ -104,12 +123,13 @@ Polymer('cr-settings-search-page', { /** - * Updates the list of default search engines based on the given |engines|. + * Updates the lists of search engines based on the given |engines|. * @param {!Array} engines All the search engines. * @private */ updateSearchEngines_: function(engines) { var defaultEngines = []; + var otherEngines = []; engines.forEach(function(engine) { if (engine.type == @@ -118,9 +138,13 @@ Polymer('cr-settings-search-page', { if (engine.isSelected) { this.defaultEngineGuid = engine.guid; } + } else if (engine.type == + chrome.searchEnginesPrivate.SearchEngineType.OTHER) { + otherEngines.push(engine); } }, this); - this.searchEngines = defaultEngines; + this.defaultSearchEngines = defaultEngines; + this.otherSearchEngines = otherEngines; } }); diff --git a/chrome/browser/resources/settings/search_engines_page/search_engines_page_style.html b/chrome/browser/resources/settings/search_engines_page/search_engines_page_style.html new file mode 100644 index 000000000000..b4ad9e69a707 --- /dev/null +++ b/chrome/browser/resources/settings/search_engines_page/search_engines_page_style.html @@ -0,0 +1,16 @@ + + + + +.manage-search-engines { + -webkit-margin-start: 10px; +} + +.search-engines { + margin-top: 20px; +} + +.search-engines-dropdown { + min-width: 150px; +} + diff --git a/chrome/browser/resources/settings/search_page/search_page.html b/chrome/browser/resources/settings/search_page/search_page.html index f14ff3679584..0774f308cf15 100644 --- a/chrome/browser/resources/settings/search_page/search_page.html +++ b/chrome/browser/resources/settings/search_page/search_page.html @@ -1,5 +1,6 @@ + @@ -24,7 +25,8 @@ + i18n-content="searchManageButtonLabel" + on-click="{{manageSearchEngines_}}" raised> diff --git a/chrome/browser/resources/settings/search_page/search_page.js b/chrome/browser/resources/settings/search_page/search_page.js index 00c03cdce399..00c54dd95ad5 100644 --- a/chrome/browser/resources/settings/search_page/search_page.js +++ b/chrome/browser/resources/settings/search_page/search_page.js @@ -28,6 +28,15 @@ Polymer('cr-settings-search-page', { prefs: null, /** + * Route for the page. + * + * @attribute route + * @type {string} + * @default '' + */ + route: '', + + /** * Whether the page is a subpage. * * @attribute subpage @@ -66,7 +75,7 @@ Polymer('cr-settings-search-page', { * List of default search engines available. * * @attribute searchEngines - * @type {Array} * @default null */ searchEngines: null, @@ -122,5 +131,10 @@ Polymer('cr-settings-search-page', { }, this); this.searchEngines = defaultEngines; - } + }, + + /** @private */ + manageSearchEngines_: function() { + MoreRouting.navigateTo('search-engines'); + }, }); diff --git a/chrome/browser/resources/settings/settings_main/settings_main.html b/chrome/browser/resources/settings/settings_main/settings_main.html index 17bbe19112bc..6f52e7080dcd 100644 --- a/chrome/browser/resources/settings/settings_main/settings_main.html +++ b/chrome/browser/resources/settings/settings_main/settings_main.html @@ -6,6 +6,7 @@ + @@ -33,6 +34,9 @@ + + diff --git a/chrome/browser/resources/settings/settings_resources.grd b/chrome/browser/resources/settings/settings_resources.grd index daaca072fd12..eb2d3f00afe5 100644 --- a/chrome/browser/resources/settings/settings_resources.grd +++ b/chrome/browser/resources/settings/settings_resources.grd @@ -205,6 +205,28 @@ + + + + + + diff --git a/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc b/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc index 77fbb47e9959..a844347316f2 100644 --- a/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc +++ b/chrome/browser/ui/webui/settings/md_settings_localized_strings_provider.cc @@ -121,6 +121,27 @@ void AddSearchStrings(content::WebUIDataSource* html_source) { IDS_SETTINGS_SEARCH_OK_GOOGLE_DESCRIPTION_LABEL); } +void AddSearchEnginesStrings(content::WebUIDataSource* html_source) { + html_source->AddLocalizedString("searchEnginesPageTitle", + IDS_SETTINGS_SEARCH_ENGINES_PAGE_TITLE); + html_source->AddLocalizedString( + "searchEnginesAddSearchEngineLabel", + IDS_SETTINGS_SEARCH_ENGINES_ADD_SEARCH_ENGINE_LABEL); + html_source->AddLocalizedString("searchEnginesLabel", + IDS_SETTINGS_SEARCH_ENGINES_LABEL); + html_source->AddLocalizedString( + "searchEnginesOtherLabel", + IDS_SETTINGS_SEARCH_ENGINES_OTHER_ENGINES_LABEL); + html_source->AddLocalizedString("searchEnginesDomainLabel", + IDS_SETTINGS_SEARCH_ENGINES_DOMAIN_LABEL); + html_source->AddLocalizedString("searchEnginesKeywordLabel", + IDS_SETTINGS_SEARCH_ENGINES_KEYWORD_LABEL); + html_source->AddLocalizedString("searchEnginesQueryURLLabel", + IDS_SETTINGS_SEARCH_ENGINES_QUERY_URL_LABEL); + html_source->AddLocalizedString("searchEnginesAddButtonLabel", + IDS_SETTINGS_SEARCH_ENGINES_ADD_BUTTON_LABEL); +} + } // namespace namespace settings { @@ -133,6 +154,7 @@ void AddLocalizedStrings(content::WebUIDataSource* html_source) { AddInternetStrings(html_source); #endif AddSearchStrings(html_source); + AddSearchEnginesStrings(html_source); html_source->SetJsonPath(kLocalizedStringsFile); } diff --git a/ui/webui/resources/cr_elements/cr_input/cr_input.js b/ui/webui/resources/cr_elements/cr_input/cr_input.js index ce373113541f..d705acbf7c8b 100644 --- a/ui/webui/resources/cr_elements/cr_input/cr_input.js +++ b/ui/webui/resources/cr_elements/cr_input/cr_input.js @@ -108,7 +108,11 @@ Polymer('cr-input', { * @type string * @default '' */ - committedValue: '' + committedValue: '', + }, + + computed: { + isInvalid: '$.decorator.isInvalid' }, /** -- 2.11.4.GIT