Chromium Code Reviews| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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. | 101 * Checks whether the given |node| requires force rendering. |
| 102 * | 102 * |
| 103 * @param {!SearchContext} context | |
| 104 * @param {!Node} node | 103 * @param {!Node} node |
| 105 * @return {boolean} Whether a forced rendering task was scheduled. | 104 * @return {boolean} Whether a forced rendering task was scheduled. |
| 106 * @private | 105 * @private |
| 107 */ | 106 */ |
| 108 function forceRenderNeeded_(context, node) { | 107 function forceRenderNeeded_(node) { |
|
Dan Beam
2016/07/20 18:03:37
i don't think this function is required, I think y
dpapad
2016/07/20 18:22:05
Done.
| |
| 109 if (node.nodeName != 'TEMPLATE' || !node.hasAttribute('name') || node.if) | 108 return 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 } | 109 } |
| 116 | 110 |
| 117 /** | 111 /** |
| 118 * Traverses the entire DOM (including Shadow DOM), finds text nodes that | 112 * Traverses the entire DOM (including Shadow DOM), finds text nodes that |
| 119 * match the given regular expression and applies the highlight UI. It also | 113 * match the given regular expression and applies the highlight UI. It also |
| 120 * ensures that <settings-section> instances become visible if any matches | 114 * ensures that <settings-section> instances become visible if any matches |
| 121 * occurred under their subtree. | 115 * occurred under their subtree. |
| 122 * | 116 * |
| 123 * @param {!SearchContext} context | 117 * @param {!SearchContext} context |
| 124 * @param {!Node} root The root of the sub-tree to be searched | 118 * @param {!Node} root The root of the sub-tree to be searched |
| 125 * @private | 119 * @private |
| 126 */ | 120 */ |
| 127 function findAndHighlightMatches_(context, root) { | 121 function findAndHighlightMatches_(context, root) { |
| 128 function doSearch(node) { | 122 function doSearch(node) { |
| 129 if (forceRenderNeeded_(context, node)) { | 123 if (forceRenderNeeded_(node)) { |
| 130 getSearchManager().queue_.addRenderTask( | 124 getSearchManager().queue_.addRenderTask( |
| 131 new RenderTask(context, node)); | 125 new RenderTask(context, node)); |
| 132 return; | 126 return; |
| 133 } | 127 } |
| 134 | 128 |
| 135 if (IGNORED_ELEMENTS.has(node.nodeName)) | 129 if (IGNORED_ELEMENTS.has(node.nodeName)) |
| 136 return; | 130 return; |
| 137 | 131 |
| 138 if (node.nodeType == Node.TEXT_NODE) { | 132 if (node.nodeType == Node.TEXT_NODE) { |
| 139 var textContent = node.nodeValue.trim(); | 133 var textContent = node.nodeValue.trim(); |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 447 | 441 |
| 448 /** @return {!SearchManager} */ | 442 /** @return {!SearchManager} */ |
| 449 function getSearchManager() { | 443 function getSearchManager() { |
| 450 return SearchManager.getInstance(); | 444 return SearchManager.getInstance(); |
| 451 } | 445 } |
| 452 | 446 |
| 453 return { | 447 return { |
| 454 getSearchManager: getSearchManager, | 448 getSearchManager: getSearchManager, |
| 455 }; | 449 }; |
| 456 }); | 450 }); |
| OLD | NEW |