| OLD | NEW |
| 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 /** @typedef {{id: number, rawQuery: ?string, regExp: ?RegExp}} */ | 5 /** @typedef {{id: number, rawQuery: ?string, regExp: ?RegExp}} */ |
| 6 var SearchContext; | 6 var SearchContext; |
| 7 | 7 |
| 8 cr.define('settings', function() { | 8 cr.define('settings', function() { |
| 9 /** @const {string} */ | 9 /** @const {string} */ |
| 10 var WRAPPER_CSS_CLASS = 'search-highlight-wrapper'; | 10 var WRAPPER_CSS_CLASS = 'search-highlight-wrapper'; |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 var span = document.createElement('span'); | 91 var span = document.createElement('span'); |
| 92 span.classList.add(HIT_CSS_CLASS); | 92 span.classList.add(HIT_CSS_CLASS); |
| 93 span.style.backgroundColor = 'yellow'; | 93 span.style.backgroundColor = 'yellow'; |
| 94 span.textContent = tokens[i]; | 94 span.textContent = tokens[i]; |
| 95 wrapper.appendChild(span); | 95 wrapper.appendChild(span); |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 } | 98 } |
| 99 | 99 |
| 100 /** | 100 /** |
| 101 * Checks whether the given |node| requires force rendering. | |
| 102 * | |
| 103 * @param {!SearchContext} context | |
| 104 * @param {!Node} node | |
| 105 * @return {boolean} Whether a forced rendering task was scheduled. | |
| 106 * @private | |
| 107 */ | |
| 108 function forceRenderNeeded_(context, node) { | |
| 109 if (node.nodeName != 'TEMPLATE' || !node.hasAttribute('name') || node.if) | |
| 110 return false; | |
| 111 | |
| 112 // TODO(dpapad): Temporarily ignore site-settings because it throws an | |
| 113 // assertion error during force-rendering. | |
| 114 return node.getAttribute('name').indexOf('site-') != 0; | |
| 115 } | |
| 116 | |
| 117 /** | |
| 118 * Traverses the entire DOM (including Shadow DOM), finds text nodes that | 101 * Traverses the entire DOM (including Shadow DOM), finds text nodes that |
| 119 * match the given regular expression and applies the highlight UI. It also | 102 * match the given regular expression and applies the highlight UI. It also |
| 120 * ensures that <settings-section> instances become visible if any matches | 103 * ensures that <settings-section> instances become visible if any matches |
| 121 * occurred under their subtree. | 104 * occurred under their subtree. |
| 122 * | 105 * |
| 123 * @param {!SearchContext} context | 106 * @param {!SearchContext} context |
| 124 * @param {!Node} root The root of the sub-tree to be searched | 107 * @param {!Node} root The root of the sub-tree to be searched |
| 125 * @private | 108 * @private |
| 126 */ | 109 */ |
| 127 function findAndHighlightMatches_(context, root) { | 110 function findAndHighlightMatches_(context, root) { |
| 128 function doSearch(node) { | 111 function doSearch(node) { |
| 129 if (forceRenderNeeded_(context, node)) { | 112 if (node.nodeName == 'TEMPLATE' && node.hasAttribute('name') && |
| 113 !node.if) { |
| 130 getSearchManager().queue_.addRenderTask( | 114 getSearchManager().queue_.addRenderTask( |
| 131 new RenderTask(context, node)); | 115 new RenderTask(context, node)); |
| 132 return; | 116 return; |
| 133 } | 117 } |
| 134 | 118 |
| 135 if (IGNORED_ELEMENTS.has(node.nodeName)) | 119 if (IGNORED_ELEMENTS.has(node.nodeName)) |
| 136 return; | 120 return; |
| 137 | 121 |
| 138 if (node.nodeType == Node.TEXT_NODE) { | 122 if (node.nodeType == Node.TEXT_NODE) { |
| 139 var textContent = node.nodeValue.trim(); | 123 var textContent = node.nodeValue.trim(); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 | 431 |
| 448 /** @return {!SearchManager} */ | 432 /** @return {!SearchManager} */ |
| 449 function getSearchManager() { | 433 function getSearchManager() { |
| 450 return SearchManager.getInstance(); | 434 return SearchManager.getInstance(); |
| 451 } | 435 } |
| 452 | 436 |
| 453 return { | 437 return { |
| 454 getSearchManager: getSearchManager, | 438 getSearchManager: getSearchManager, |
| 455 }; | 439 }; |
| 456 }); | 440 }); |
| OLD | NEW |