Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(449)

Side by Side Diff: chrome/browser/resources/settings/search_settings.js

Issue 2223083003: MD Settings: Skip hidden nodes when searching. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_subpage_assertion
Patch Set: Change class to attribute. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/resources/settings/settings_page/settings_section.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 cr.define('settings', function() { 5 cr.define('settings', function() {
6 /** @const {string} */ 6 /** @const {string} */
7 var WRAPPER_CSS_CLASS = 'search-highlight-wrapper'; 7 var WRAPPER_CSS_CLASS = 'search-highlight-wrapper';
8 8
9 /** @const {string} */ 9 /** @const {string} */
10 var HIT_CSS_CLASS = 'search-highlight-hit'; 10 var HIT_CSS_CLASS = 'search-highlight-hit';
11 11
12 /** @const {string} */ 12 /** @const {string} */
13 var SEARCH_BUBBLE_CSS_CLASS = 'search-bubble'; 13 var SEARCH_BUBBLE_CSS_CLASS = 'search-bubble';
14 14
15 /** 15 /**
16 * A CSS attribute indicating that a node shoud be ignored during searching. 16 * A CSS attribute indicating that a node should be ignored during searching.
17 * @const {string} 17 * @const {string}
18 */ 18 */
19 var SKIP_SEARCH_CSS_ATTRIBUTE = 'no-search'; 19 var SKIP_SEARCH_CSS_ATTRIBUTE = 'no-search';
20 20
21 /** 21 /**
22 * List of elements types that should not be searched at all. 22 * List of elements types that should not be searched at all.
23 * The only DOM-MODULE node is in <body> which is not searched, therefore 23 * The only DOM-MODULE node is in <body> which is not searched, therefore
24 * DOM-MODULE is not needed in this set. 24 * DOM-MODULE is not needed in this set.
25 * @const {!Set<string>} 25 * @const {!Set<string>}
26 */ 26 */
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 function findAndHighlightMatches_(request, root) { 121 function findAndHighlightMatches_(request, root) {
122 var foundMatches = false; 122 var foundMatches = false;
123 function doSearch(node) { 123 function doSearch(node) {
124 if (node.nodeName == 'TEMPLATE' && node.hasAttribute('name') && 124 if (node.nodeName == 'TEMPLATE' && node.hasAttribute('name') &&
125 !node.if && !node.hasAttribute(SKIP_SEARCH_CSS_ATTRIBUTE)) { 125 !node.if && !node.hasAttribute(SKIP_SEARCH_CSS_ATTRIBUTE)) {
126 getSearchManager().queue_.addRenderTask( 126 getSearchManager().queue_.addRenderTask(
127 new RenderTask(request, node)); 127 new RenderTask(request, node));
128 return; 128 return;
129 } 129 }
130 130
131 if (IGNORED_ELEMENTS.has(node.nodeName) || 131 if (IGNORED_ELEMENTS.has(node.nodeName))
132 (node.hasAttribute && node.hasAttribute(SKIP_SEARCH_CSS_ATTRIBUTE))) {
133 return; 132 return;
133
134 if (node instanceof HTMLElement) {
135 var element = /** @type {HTMLElement} */(node);
136 if (element.hasAttribute(SKIP_SEARCH_CSS_ATTRIBUTE) ||
137 element.hasAttribute('hidden') ||
138 element.style.display == 'none') {
139 return;
140 }
134 } 141 }
135 142
136 if (node.nodeType == Node.TEXT_NODE) { 143 if (node.nodeType == Node.TEXT_NODE) {
137 var textContent = node.nodeValue.trim(); 144 var textContent = node.nodeValue.trim();
138 if (textContent.length == 0) 145 if (textContent.length == 0)
139 return; 146 return;
140 147
141 if (request.regExp.test(textContent)) { 148 if (request.regExp.test(textContent)) {
142 foundMatches = true; 149 foundMatches = true;
143 revealParentSection_(node, request.rawQuery_); 150 revealParentSection_(node, request.rawQuery_);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 parent.host : parent.parentNode; 214 parent.host : parent.parentNode;
208 if (parent.nodeName == 'SETTINGS-SUBPAGE') { 215 if (parent.nodeName == 'SETTINGS-SUBPAGE') {
209 // TODO(dpapad): Cast to SettingsSubpageElement here. 216 // TODO(dpapad): Cast to SettingsSubpageElement here.
210 associatedControl = assert( 217 associatedControl = assert(
211 parent.associatedControl, 218 parent.associatedControl,
212 'An associated control was expected for SETTINGS-SUBPAGE ' + 219 'An associated control was expected for SETTINGS-SUBPAGE ' +
213 parent.pageTitle + ', but was not found.'); 220 parent.pageTitle + ', but was not found.');
214 } 221 }
215 } 222 }
216 if (parent) 223 if (parent)
217 parent.hidden = false; 224 parent.hiddenBySearch = false;
218 225
219 // Need to add the search bubble after the parent SETTINGS-SECTION has 226 // Need to add the search bubble after the parent SETTINGS-SECTION has
220 // become visible, otherwise |offsetWidth| returns zero. 227 // become visible, otherwise |offsetWidth| returns zero.
221 if (associatedControl) 228 if (associatedControl)
222 highlightAssociatedControl_(associatedControl, rawQuery); 229 highlightAssociatedControl_(associatedControl, rawQuery);
223 } 230 }
224 231
225 /** 232 /**
226 * @constructor 233 * @constructor
227 * 234 *
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 }, 335 },
329 336
330 /** 337 /**
331 * @param {boolean} visible 338 * @param {boolean} visible
332 * @private 339 * @private
333 */ 340 */
334 setSectionsVisibility_: function(visible) { 341 setSectionsVisibility_: function(visible) {
335 var sections = Polymer.dom( 342 var sections = Polymer.dom(
336 this.node.root).querySelectorAll('settings-section'); 343 this.node.root).querySelectorAll('settings-section');
337 for (var i = 0; i < sections.length; i++) 344 for (var i = 0; i < sections.length; i++)
338 sections[i].hidden = !visible; 345 sections[i].hiddenBySearch = !visible;
339 }, 346 },
340 }; 347 };
341 348
342 /** 349 /**
343 * @constructor 350 * @constructor
344 */ 351 */
345 function TaskQueue() { 352 function TaskQueue() {
346 /** 353 /**
347 * @private {{ 354 * @private {{
348 * high: !Array<!Task>, 355 * high: !Array<!Task>,
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 function setSearchManagerForTesting(searchManager) { 583 function setSearchManagerForTesting(searchManager) {
577 SearchManagerImpl.instance_ = searchManager; 584 SearchManagerImpl.instance_ = searchManager;
578 } 585 }
579 586
580 return { 587 return {
581 getSearchManager: getSearchManager, 588 getSearchManager: getSearchManager,
582 setSearchManagerForTesting: setSearchManagerForTesting, 589 setSearchManagerForTesting: setSearchManagerForTesting,
583 SearchRequest: SearchRequest, 590 SearchRequest: SearchRequest,
584 }; 591 };
585 }); 592 });
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/resources/settings/settings_page/settings_section.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698