Commit 2e4f7f7e authored by Esmael El-Moslimany's avatar Esmael El-Moslimany Committed by Commit Bot

WebUI: move FindShortcutBehavior to common webui/resources

Bug: 862839
Change-Id: I3499e9c6abe18c0ffb23a4ed3598320edf757570
Reviewed-on: https://chromium-review.googlesource.com/c/1392063
Commit-Queue: Esmael El-Moslimany <aee@chromium.org>
Reviewed-by: default avatarDan Beam <dbeam@chromium.org>
Reviewed-by: default avatarHector Carmona <hcarmona@chromium.org>
Cr-Commit-Position: refs/heads/master@{#619722}
parent e80f9a52
...@@ -107,7 +107,6 @@ group("closure_compile") { ...@@ -107,7 +107,6 @@ group("closure_compile") {
js_type_check("settings_resources") { js_type_check("settings_resources") {
deps = [ deps = [
":extension_control_browser_proxy", ":extension_control_browser_proxy",
":find_shortcut_behavior",
":global_scroll_target_behavior", ":global_scroll_target_behavior",
":lifetime_browser_proxy", ":lifetime_browser_proxy",
":open_window_proxy", ":open_window_proxy",
...@@ -125,14 +124,6 @@ js_library("extension_control_browser_proxy") { ...@@ -125,14 +124,6 @@ js_library("extension_control_browser_proxy") {
externs_list = [ "$externs_path/chrome_send.js" ] externs_list = [ "$externs_path/chrome_send.js" ]
} }
js_library("find_shortcut_behavior") {
deps = [
"//ui/webui/resources/js:assert",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js/cr/ui:command",
]
}
js_library("global_scroll_target_behavior") { js_library("global_scroll_target_behavior") {
deps = [ deps = [
":route", ":route",
......
<link rel="import" href="chrome://resources/html/assert.html">
<link rel="import" href="chrome://resources/html/cr.html">
<link rel="import" href="chrome://resources/html/cr/ui/command.html">
<script src="find_shortcut_behavior.js"></script>
...@@ -85,8 +85,8 @@ js_library("add_languages_dialog") { ...@@ -85,8 +85,8 @@ js_library("add_languages_dialog") {
deps = [ deps = [
":languages", ":languages",
":languages_types", ":languages_types",
"..:find_shortcut_behavior",
"//ui/webui/resources/cr_elements:cr_scrollable_behavior", "//ui/webui/resources/cr_elements:cr_scrollable_behavior",
"//ui/webui/resources/cr_elements/cr_search_field:cr_search_field", "//ui/webui/resources/cr_elements/cr_search_field:cr_search_field",
"//ui/webui/resources/js:find_shortcut_behavior",
] ]
} }
...@@ -5,10 +5,10 @@ ...@@ -5,10 +5,10 @@
<link rel="import" href="chrome://resources/cr_elements/cr_search_field/cr_search_field.html"> <link rel="import" href="chrome://resources/cr_elements/cr_search_field/cr_search_field.html">
<link rel="import" href="chrome://resources/cr_elements/cr_dialog/cr_dialog.html"> <link rel="import" href="chrome://resources/cr_elements/cr_dialog/cr_dialog.html">
<link rel="import" href="chrome://resources/cr_elements/shared_vars_css.html"> <link rel="import" href="chrome://resources/cr_elements/shared_vars_css.html">
<link rel="import" href="chrome://resources/html/find_shortcut_behavior.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-list/iron-list.html"> <link rel="import" href="chrome://resources/polymer/v1_0/iron-list/iron-list.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html"> <link rel="import" href="chrome://resources/polymer/v1_0/paper-button/paper-button.html">
<link rel="import" href="languages.html"> <link rel="import" href="languages.html">
<link rel="import" href="../find_shortcut_behavior.html">
<link rel="import" href="../settings_shared_css.html"> <link rel="import" href="../settings_shared_css.html">
<dom-module id="settings-add-languages-dialog"> <dom-module id="settings-add-languages-dialog">
......
...@@ -11,7 +11,7 @@ Polymer({ ...@@ -11,7 +11,7 @@ Polymer({
behaviors: [ behaviors: [
CrScrollableBehavior, CrScrollableBehavior,
settings.FindShortcutBehavior, FindShortcutBehavior,
], ],
properties: { properties: {
...@@ -56,7 +56,7 @@ Polymer({ ...@@ -56,7 +56,7 @@ Polymer({
this.removeSelfAsFindShortcutListener(); this.removeSelfAsFindShortcutListener();
}, },
// Override settings.FindShortcutBehavior methods. // Override FindShortcutBehavior methods.
handleFindShortcut: function(modalContextOpen) { handleFindShortcut: function(modalContextOpen) {
// Assumes this is the only open modal. // Assumes this is the only open modal.
const searchInput = this.$.search.getSearchInput(); const searchInput = this.$.search.getSearchInput();
......
...@@ -40,11 +40,11 @@ js_library("settings_section") { ...@@ -40,11 +40,11 @@ js_library("settings_section") {
js_library("settings_subpage") { js_library("settings_subpage") {
deps = [ deps = [
"..:find_shortcut_behavior",
"..:route", "..:route",
"//third_party/polymer/v1_0/components-chromium/iron-resizable-behavior:iron-resizable-behavior-extracted", "//third_party/polymer/v1_0/components-chromium/iron-resizable-behavior:iron-resizable-behavior-extracted",
"//ui/webui/resources/cr_elements/cr_search_field:cr_search_field", "//ui/webui/resources/cr_elements/cr_search_field:cr_search_field",
"//ui/webui/resources/js:assert", "//ui/webui/resources/js:assert",
"//ui/webui/resources/js:find_shortcut_behavior",
"//ui/webui/resources/js/cr/ui:focus_without_ink", "//ui/webui/resources/js/cr/ui:focus_without_ink",
] ]
} }
...@@ -2,12 +2,12 @@ ...@@ -2,12 +2,12 @@
<link rel="import" href="chrome://resources/html/cr/ui/focus_without_ink.html"> <link rel="import" href="chrome://resources/html/cr/ui/focus_without_ink.html">
<link rel="import" href="chrome://resources/cr_elements/cr_search_field/cr_search_field.html"> <link rel="import" href="chrome://resources/cr_elements/cr_search_field/cr_search_field.html">
<link rel="import" href="chrome://resources/html/find_shortcut_behavior.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html"> <link rel="import" href="chrome://resources/polymer/v1_0/iron-icon/iron-icon.html">
<link rel="import" href="chrome://resources/polymer/v1_0/iron-resizable-behavior/iron-resizable-behavior.html"> <link rel="import" href="chrome://resources/polymer/v1_0/iron-resizable-behavior/iron-resizable-behavior.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-icon-button/paper-icon-button-light.html"> <link rel="import" href="chrome://resources/polymer/v1_0/paper-icon-button/paper-icon-button-light.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-ripple/paper-ripple.html"> <link rel="import" href="chrome://resources/polymer/v1_0/paper-ripple/paper-ripple.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-spinner/paper-spinner-lite.html"> <link rel="import" href="chrome://resources/polymer/v1_0/paper-spinner/paper-spinner-lite.html">
<link rel="import" href="../find_shortcut_behavior.html">
<link rel="import" href="../icons.html"> <link rel="import" href="../icons.html">
<link rel="import" href="../route.html"> <link rel="import" href="../route.html">
<link rel="import" href="../settings_shared_css.html"> <link rel="import" href="../settings_shared_css.html">
......
...@@ -12,8 +12,8 @@ Polymer({ ...@@ -12,8 +12,8 @@ Polymer({
is: 'settings-subpage', is: 'settings-subpage',
behaviors: [ behaviors: [
FindShortcutBehavior,
Polymer.IronResizableBehavior, Polymer.IronResizableBehavior,
settings.FindShortcutBehavior,
settings.RouteObserverBehavior, settings.RouteObserverBehavior,
], ],
...@@ -133,7 +133,7 @@ Polymer({ ...@@ -133,7 +133,7 @@ Polymer({
this.searchTerm = e.detail; this.searchTerm = e.detail;
}, },
// Override settings.FindShortcutBehavior methods. // Override FindShortcutBehavior methods.
handleFindShortcut: function(modalContextOpen) { handleFindShortcut: function(modalContextOpen) {
if (modalContextOpen) { if (modalContextOpen) {
return false; return false;
......
...@@ -581,12 +581,6 @@ ...@@ -581,12 +581,6 @@
file="icons.html" file="icons.html"
type="chrome_html" type="chrome_html"
preprocess="true" /> preprocess="true" />
<structure name="IDR_SETTINGS_FIND_SHORTCUT_BEHAVIOR_HTML"
file ="find_shortcut_behavior.html"
type="chrome_html" />
<structure name="IDR_SETTINGS_FIND_SHORTCUT_BEHAVIOR_JS"
file ="find_shortcut_behavior.js"
type="chrome_html" />
<structure name="IDR_SETTINGS_POWERWASH_DIALOG_HTML" <structure name="IDR_SETTINGS_POWERWASH_DIALOG_HTML"
file="reset_page/powerwash_dialog.html" file="reset_page/powerwash_dialog.html"
type="chrome_html" /> type="chrome_html" />
......
...@@ -12,7 +12,6 @@ js_type_check("closure_compile") { ...@@ -12,7 +12,6 @@ js_type_check("closure_compile") {
js_library("settings_ui") { js_library("settings_ui") {
deps = [ deps = [
"..:find_shortcut_behavior",
"..:global_scroll_target_behavior", "..:global_scroll_target_behavior",
"..:page_visibility", "..:page_visibility",
"../prefs:prefs", "../prefs:prefs",
...@@ -23,5 +22,6 @@ js_library("settings_ui") { ...@@ -23,5 +22,6 @@ js_library("settings_ui") {
"//ui/webui/resources/cr_elements/cr_toolbar:cr_toolbar", "//ui/webui/resources/cr_elements/cr_toolbar:cr_toolbar",
"//ui/webui/resources/cr_elements/cr_toolbar:cr_toolbar_search_field", "//ui/webui/resources/cr_elements/cr_toolbar:cr_toolbar_search_field",
"//ui/webui/resources/cr_elements/policy:cr_policy_indicator_behavior", "//ui/webui/resources/cr_elements/policy:cr_policy_indicator_behavior",
"//ui/webui/resources/js:find_shortcut_behavior",
] ]
} }
...@@ -4,9 +4,9 @@ ...@@ -4,9 +4,9 @@
<link rel="import" href="chrome://resources/cr_elements/cr_drawer/cr_drawer.html"> <link rel="import" href="chrome://resources/cr_elements/cr_drawer/cr_drawer.html">
<link rel="import" href="chrome://resources/cr_elements/cr_toolbar/cr_toolbar.html"> <link rel="import" href="chrome://resources/cr_elements/cr_toolbar/cr_toolbar.html">
<link rel="import" href="chrome://resources/cr_elements/icons.html"> <link rel="import" href="chrome://resources/cr_elements/icons.html">
<link rel="import" href="chrome://resources/html/find_shortcut_behavior.html">
<link rel="import" href="chrome://resources/html/util.html"> <link rel="import" href="chrome://resources/html/util.html">
<link rel="import" href="chrome://resources/polymer/v1_0/paper-styles/color.html"> <link rel="import" href="chrome://resources/polymer/v1_0/paper-styles/color.html">
<link rel="import" href="../find_shortcut_behavior.html">
<link rel="import" href="../global_scroll_target_behavior.html"> <link rel="import" href="../global_scroll_target_behavior.html">
<link rel="import" href="../i18n_setup.html"> <link rel="import" href="../i18n_setup.html">
<link rel="import" href="../icons.html"> <link rel="import" href="../icons.html">
......
...@@ -23,7 +23,7 @@ Polymer({ ...@@ -23,7 +23,7 @@ Polymer({
behaviors: [ behaviors: [
settings.RouteObserverBehavior, settings.RouteObserverBehavior,
CrContainerShadowBehavior, CrContainerShadowBehavior,
settings.FindShortcutBehavior, FindShortcutBehavior,
], ],
properties: { properties: {
...@@ -215,7 +215,7 @@ Polymer({ ...@@ -215,7 +215,7 @@ Polymer({
this.$.main.searchContents(urlSearchQuery); this.$.main.searchContents(urlSearchQuery);
}, },
// Override settings.FindShortcutBehavior methods. // Override FindShortcutBehavior methods.
handleFindShortcut: function(modalContextOpen) { handleFindShortcut: function(modalContextOpen) {
if (modalContextOpen) { if (modalContextOpen) {
return false; return false;
......
...@@ -52,6 +52,7 @@ js2gtest("browser_tests_js_webui") { ...@@ -52,6 +52,7 @@ js2gtest("browser_tests_js_webui") {
"chrome_send_browsertest.js", "chrome_send_browsertest.js",
"cr_components/cr_components_browsertest.js", "cr_components/cr_components_browsertest.js",
"cr_elements/cr_elements_browsertest.js", "cr_elements/cr_elements_browsertest.js",
"find_shortcut_behavior_browsertest.js",
"load_time_data_browsertest.js", "load_time_data_browsertest.js",
"md_bookmarks/md_bookmarks_browsertest.js", "md_bookmarks/md_bookmarks_browsertest.js",
"md_history/md_history_browsertest.js", "md_history/md_history_browsertest.js",
......
// Copyright 2018 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.
/** @const {string} Path to source root. */
const ROOT_PATH = '../../../../';
// Polymer BrowserTest fixture.
GEN_INCLUDE(
[ROOT_PATH + 'chrome/test/data/webui/polymer_browser_test_base.js']);
/**
* Test fixture for FindShortcutBehavior.
* @constructor
* @extends {PolymerTest}
*/
function FindShortcutBehaviorTest() {}
FindShortcutBehaviorTest.prototype = {
__proto__: PolymerTest.prototype,
/**
* Preload a module that depends on both cr-dialog and FindShortcutBehavior.
* cr-dialog is used in the tests.
* @override
*/
browsePreload: 'chrome://resources/html/find_shortcut_behavior.html',
/** @override */
extraLibraries: PolymerTest.getLibraries(ROOT_PATH).concat([
'settings/test_util.js',
'find_shortcut_behavior_test.js',
]),
};
TEST_F('FindShortcutBehaviorTest', 'All', function() {
mocha.run();
});
...@@ -3,12 +3,10 @@ ...@@ -3,12 +3,10 @@
// found in the LICENSE file. // found in the LICENSE file.
suite('find-shortcut', () => { suite('find-shortcut', () => {
/** @typedef {{ /** @override */
* becomeActiveFindShortcutListener: !Function, suiteSetup(
* removeSelfAsFindShortcutListener: !Function, () => PolymerTest.importHtml(
* }} 'chrome://resources/cr_elements/cr_dialog/cr_dialog.html'));
*/
let Listener;
/** /**
* @type {PromiseResolver<!{modalContextOpen: boolean, self: HTMLElement}>} * @type {PromiseResolver<!{modalContextOpen: boolean, self: HTMLElement}>}
...@@ -107,7 +105,7 @@ suite('find-shortcut', () => { ...@@ -107,7 +105,7 @@ suite('find-shortcut', () => {
Polymer({ Polymer({
is: 'find-shortcut-element', is: 'find-shortcut-element',
behaviors: [settings.FindShortcutBehavior], behaviors: [FindShortcutBehavior],
handledResponse: true, handledResponse: true,
......
...@@ -2300,34 +2300,6 @@ TEST_F('CrSettingsOnStartupPageTest', 'All', function() { ...@@ -2300,34 +2300,6 @@ TEST_F('CrSettingsOnStartupPageTest', 'All', function() {
mocha.run(); mocha.run();
}); });
/**
* Test fixture for FindShortcutBehavior.
* @constructor
* @extends {CrSettingsBrowserTest}
*/
function CrSettingsFindShortcutBehavior() {}
CrSettingsFindShortcutBehavior.prototype = {
__proto__: CrSettingsBrowserTest.prototype,
/**
* Preload a module that depends on both cr-dialog and FindShortcutBehavior.
* cr-dialog is used in the tests.
* @override
*/
browsePreload: 'chrome://settings/languages_page/add_languages_dialog.html',
/** @override */
extraLibraries: CrSettingsBrowserTest.prototype.extraLibraries.concat([
'test_util.js',
'find_shortcut_behavior_test.js',
]),
};
TEST_F('CrSettingsFindShortcutBehavior', 'All', function() {
mocha.run();
});
/** /**
* @constructor * @constructor
* @extends {CrSettingsBrowserTest} * @extends {CrSettingsBrowserTest}
......
...@@ -9,6 +9,9 @@ ...@@ -9,6 +9,9 @@
<structure name="IDR_WEBUI_HTML_CR_UI_FOCUS_WITHOUT_INK" <structure name="IDR_WEBUI_HTML_CR_UI_FOCUS_WITHOUT_INK"
file="html/cr/ui/focus_without_ink.html" type="chrome_html" file="html/cr/ui/focus_without_ink.html" type="chrome_html"
compress="gzip" /> compress="gzip" />
<structure name="IDR_WEBUI_HTML_FIND_SHORTCUT_BEHAVIOR"
file="html/find_shortcut_behavior.html" type="chrome_html"
compress="gzip" />
<structure name="IDR_WEBUI_HTML_I18N_BEHAVIOR" <structure name="IDR_WEBUI_HTML_I18N_BEHAVIOR"
file="html/i18n_behavior.html" type="chrome_html" file="html/i18n_behavior.html" type="chrome_html"
compress="gzip" /> compress="gzip" />
...@@ -38,6 +41,9 @@ ...@@ -38,6 +41,9 @@
<structure name="IDR_WEBUI_JS_CR_UI_FOCUS_WITHOUT_INK" <structure name="IDR_WEBUI_JS_CR_UI_FOCUS_WITHOUT_INK"
file="js/cr/ui/focus_without_ink.js" type="chrome_html" file="js/cr/ui/focus_without_ink.js" type="chrome_html"
compress="gzip" /> compress="gzip" />
<structure name="IDR_WEBUI_JS_FIND_SHORTCUT_BEHAVIOR"
file="js/find_shortcut_behavior.js" type="chrome_html"
compress="gzip" />
<structure name="IDR_WEBUI_JS_LIST_PROPERTY_UPDATE_BEHAVIOR" <structure name="IDR_WEBUI_JS_LIST_PROPERTY_UPDATE_BEHAVIOR"
file="js/list_property_update_behavior.js" type="chrome_html" file="js/list_property_update_behavior.js" type="chrome_html"
compress="gzip" /> compress="gzip" />
......
<link rel="import" href="../html/assert.html">
<link rel="import" href="../html/cr.html">
<link rel="import" href="../html/cr/ui/command.html">
<script src="../js/find_shortcut_behavior.js"></script>
...@@ -19,6 +19,7 @@ js_type_check("js_resources") { ...@@ -19,6 +19,7 @@ js_type_check("js_resources") {
":cr", ":cr",
":dark_mode", ":dark_mode",
":event_tracker", ":event_tracker",
":find_shortcut_behavior",
":i18n_behavior", ":i18n_behavior",
":i18n_template", ":i18n_template",
":i18n_template_no_process", ":i18n_template_no_process",
...@@ -126,3 +127,11 @@ js_library("web_ui_listener_behavior") { ...@@ -126,3 +127,11 @@ js_library("web_ui_listener_behavior") {
js_library("webui_resource_test") { js_library("webui_resource_test") {
externs_list = [ "dom_automation_controller.js" ] externs_list = [ "dom_automation_controller.js" ]
} }
js_library("find_shortcut_behavior") {
deps = [
":assert",
":cr",
"cr/ui:command",
]
}
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
* top of the stack will be notified that a find shortcut has been invoked. * top of the stack will be notified that a find shortcut has been invoked.
*/ */
cr.define('settings', function() { const FindShortcutManager = (() => {
/** /**
* Stack of listeners. Only the top listener will handle the shortcut. * Stack of listeners. Only the top listener will handle the shortcut.
* @type {!Array<!HTMLElement>} * @type {!Array<!HTMLElement>}
...@@ -54,36 +54,34 @@ cr.define('settings', function() { ...@@ -54,36 +54,34 @@ cr.define('settings', function() {
} }
}); });
return Object.freeze({listeners: listeners});
})();
/**
* Used to determine how to handle find shortcut invocations.
* @polymerBehavior
*/
const FindShortcutBehavior = {
/** /**
* Used to determine how to handle find shortcut invocations. * If handled, return true.
* @polymerBehavior * @param {boolean} modalContextOpen
* @return {boolean}
* @protected
*/ */
const FindShortcutBehavior = { handleFindShortcut(modalContextOpen) {
/** assertNotReached();
* If handled, return true. },
* @param {boolean} modalContextOpen
* @return {boolean}
* @protected
*/
handleFindShortcut(modalContextOpen) {
assertNotReached();
},
becomeActiveFindShortcutListener() {
assert(
listeners.indexOf(this) == -1,
'Already listening for find shortcuts.');
listeners.push(this);
},
removeSelfAsFindShortcutListener() { becomeActiveFindShortcutListener() {
const index = listeners.indexOf(this); const listeners = FindShortcutManager.listeners;
assert(index > -1, 'Find shortcut listener not found.'); assert(!listeners.includes(this), 'Already listening for find shortcuts.');
listeners.splice(index, 1); listeners.push(this);
}, },
};
return { removeSelfAsFindShortcutListener() {
FindShortcutBehavior, const listeners = FindShortcutManager.listeners;
}; const index = listeners.indexOf(this);
}); assert(listeners.includes(this), 'Find shortcut listener not found.');
listeners.splice(index, 1);
},
};
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