| 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 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. |
| 17 * @const {string} |
| 18 */ |
| 19 var SKIP_SEARCH_CSS_ATTRIBUTE = 'no-search'; |
| 20 |
| 21 /** |
| 16 * List of elements types that should not be searched at all. | 22 * List of elements types that should not be searched at all. |
| 17 * 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 |
| 18 * DOM-MODULE is not needed in this set. | 24 * DOM-MODULE is not needed in this set. |
| 19 * @const {!Set<string>} | 25 * @const {!Set<string>} |
| 20 */ | 26 */ |
| 21 var IGNORED_ELEMENTS = new Set([ | 27 var IGNORED_ELEMENTS = new Set([ |
| 22 'CONTENT', | 28 'CONTENT', |
| 23 'CR-EVENTS', | 29 'CR-EVENTS', |
| 24 'IMG', | 30 'IMG', |
| 25 'IRON-ICON', | 31 'IRON-ICON', |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 * occurred under their subtree. | 115 * occurred under their subtree. |
| 110 * | 116 * |
| 111 * @param {!settings.SearchRequest} request | 117 * @param {!settings.SearchRequest} request |
| 112 * @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 |
| 113 * @private | 119 * @private |
| 114 */ | 120 */ |
| 115 function findAndHighlightMatches_(request, root) { | 121 function findAndHighlightMatches_(request, root) { |
| 116 var foundMatches = false; | 122 var foundMatches = false; |
| 117 function doSearch(node) { | 123 function doSearch(node) { |
| 118 if (node.nodeName == 'TEMPLATE' && node.hasAttribute('name') && | 124 if (node.nodeName == 'TEMPLATE' && node.hasAttribute('name') && |
| 119 !node.if) { | 125 !node.if && !node.hasAttribute(SKIP_SEARCH_CSS_ATTRIBUTE)) { |
| 120 getSearchManager().queue_.addRenderTask( | 126 getSearchManager().queue_.addRenderTask( |
| 121 new RenderTask(request, node)); | 127 new RenderTask(request, node)); |
| 122 return; | 128 return; |
| 123 } | 129 } |
| 124 | 130 |
| 125 if (IGNORED_ELEMENTS.has(node.nodeName)) | 131 if (IGNORED_ELEMENTS.has(node.nodeName) || |
| 132 (node.hasAttribute && node.hasAttribute(SKIP_SEARCH_CSS_ATTRIBUTE))) { |
| 126 return; | 133 return; |
| 134 } |
| 127 | 135 |
| 128 if (node.nodeType == Node.TEXT_NODE) { | 136 if (node.nodeType == Node.TEXT_NODE) { |
| 129 var textContent = node.nodeValue.trim(); | 137 var textContent = node.nodeValue.trim(); |
| 130 if (textContent.length == 0) | 138 if (textContent.length == 0) |
| 131 return; | 139 return; |
| 132 | 140 |
| 133 if (request.regExp.test(textContent)) { | 141 if (request.regExp.test(textContent)) { |
| 134 foundMatches = true; | 142 foundMatches = true; |
| 135 revealParentSection_(node, request.rawQuery_); | 143 revealParentSection_(node, request.rawQuery_); |
| 136 highlight_(node, textContent.split(request.regExp)); | 144 highlight_(node, textContent.split(request.regExp)); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 */ | 200 */ |
| 193 function revealParentSection_(node, rawQuery) { | 201 function revealParentSection_(node, rawQuery) { |
| 194 var associatedControl = null; | 202 var associatedControl = null; |
| 195 // Find corresponding SETTINGS-SECTION parent and make it visible. | 203 // Find corresponding SETTINGS-SECTION parent and make it visible. |
| 196 var parent = node; | 204 var parent = node; |
| 197 while (parent && parent.nodeName !== 'SETTINGS-SECTION') { | 205 while (parent && parent.nodeName !== 'SETTINGS-SECTION') { |
| 198 parent = parent.nodeType == Node.DOCUMENT_FRAGMENT_NODE ? | 206 parent = parent.nodeType == Node.DOCUMENT_FRAGMENT_NODE ? |
| 199 parent.host : parent.parentNode; | 207 parent.host : parent.parentNode; |
| 200 if (parent.nodeName == 'SETTINGS-SUBPAGE') { | 208 if (parent.nodeName == 'SETTINGS-SUBPAGE') { |
| 201 // TODO(dpapad): Cast to SettingsSubpageElement here. | 209 // TODO(dpapad): Cast to SettingsSubpageElement here. |
| 202 if (!parent.noAssociatedControl) { | 210 associatedControl = assert( |
| 203 associatedControl = assert( | 211 parent.associatedControl, |
| 204 parent.associatedControl, | 212 'An associated control was expected for SETTINGS-SUBPAGE ' + |
| 205 'An associated control was expected for SETTINGS-SUBPAGE ' + | 213 parent.pageTitle + ', but was not found.'); |
| 206 parent.pageTitle + ', but was not found.'); | |
| 207 } | |
| 208 } | 214 } |
| 209 } | 215 } |
| 210 if (parent) | 216 if (parent) |
| 211 parent.hidden = false; | 217 parent.hidden = false; |
| 212 | 218 |
| 213 // Need to add the search bubble after the parent SETTINGS-SECTION has | 219 // Need to add the search bubble after the parent SETTINGS-SECTION has |
| 214 // become visible, otherwise |offsetWidth| returns zero. | 220 // become visible, otherwise |offsetWidth| returns zero. |
| 215 if (associatedControl) | 221 if (associatedControl) |
| 216 highlightAssociatedControl_(associatedControl, rawQuery); | 222 highlightAssociatedControl_(associatedControl, rawQuery); |
| 217 } | 223 } |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 570 function setSearchManagerForTesting(searchManager) { | 576 function setSearchManagerForTesting(searchManager) { |
| 571 SearchManagerImpl.instance_ = searchManager; | 577 SearchManagerImpl.instance_ = searchManager; |
| 572 } | 578 } |
| 573 | 579 |
| 574 return { | 580 return { |
| 575 getSearchManager: getSearchManager, | 581 getSearchManager: getSearchManager, |
| 576 setSearchManagerForTesting: setSearchManagerForTesting, | 582 setSearchManagerForTesting: setSearchManagerForTesting, |
| 577 SearchRequest: SearchRequest, | 583 SearchRequest: SearchRequest, |
| 578 }; | 584 }; |
| 579 }); | 585 }); |
| OLD | NEW |