| 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 ORIGINAL_CONTENT_CSS_CLASS = 'search-highlight-original-content'; | 10 var ORIGINAL_CONTENT_CSS_CLASS = 'search-highlight-original-content'; |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 50 * Finds all previous highlighted nodes under |node| (both within self and | 50 * Finds all previous highlighted nodes under |node| (both within self and |
| 51 * children's Shadow DOM) and replaces the highlights (yellow rectangle and | 51 * children's Shadow DOM) and replaces the highlights (yellow rectangle and |
| 52 * search bubbles) with the original text node. | 52 * search bubbles) with the original text node. |
| 53 * TODO(dpapad): Consider making this a private method of TopLevelSearchTask. | 53 * TODO(dpapad): Consider making this a private method of TopLevelSearchTask. |
| 54 * @param {!Node} node | 54 * @param {!Node} node |
| 55 * @private | 55 * @private |
| 56 */ | 56 */ |
| 57 function findAndRemoveHighlights_(node) { | 57 function findAndRemoveHighlights_(node) { |
| 58 var wrappers = node.querySelectorAll('* /deep/ .' + WRAPPER_CSS_CLASS); | 58 var wrappers = node.querySelectorAll('* /deep/ .' + WRAPPER_CSS_CLASS); |
| 59 | 59 |
| 60 for (var wrapper of wrappers) { | 60 for (var i = 0; i < wrappers.length; i++ ) { |
| 61 var wrapper = wrappers[i]; |
| 61 var originalNode = wrapper.querySelector( | 62 var originalNode = wrapper.querySelector( |
| 62 '.' + ORIGINAL_CONTENT_CSS_CLASS); | 63 '.' + ORIGINAL_CONTENT_CSS_CLASS); |
| 63 wrapper.parentElement.replaceChild(originalNode.firstChild, wrapper); | 64 wrapper.parentElement.replaceChild(originalNode.firstChild, wrapper); |
| 64 } | 65 } |
| 65 | 66 |
| 66 var searchBubbles = node.querySelectorAll( | 67 var searchBubbles = node.querySelectorAll( |
| 67 '* /deep/ .' + SEARCH_BUBBLE_CSS_CLASS); | 68 '* /deep/ .' + SEARCH_BUBBLE_CSS_CLASS); |
| 68 for (var searchBubble of searchBubbles) | 69 for (var j = 0; j < searchBubbles.length; j++) |
| 69 searchBubble.remove(); | 70 searchBubbles[j].remove(); |
| 70 } | 71 } |
| 71 | 72 |
| 72 /** | 73 /** |
| 73 * Applies the highlight UI (yellow rectangle) around all matches in |node|. | 74 * Applies the highlight UI (yellow rectangle) around all matches in |node|. |
| 74 * @param {!Node} node The text node to be highlighted. |node| ends up | 75 * @param {!Node} node The text node to be highlighted. |node| ends up |
| 75 * being removed from the DOM tree. | 76 * being removed from the DOM tree. |
| 76 * @param {!Array<string>} tokens The string tokens after splitting on the | 77 * @param {!Array<string>} tokens The string tokens after splitting on the |
| 77 * relevant regExp. Even indices hold text that doesn't need highlighting, | 78 * relevant regExp. Even indices hold text that doesn't need highlighting, |
| 78 * odd indices hold the text to be highlighted. For example: | 79 * odd indices hold the text to be highlighted. For example: |
| 79 * var r = new RegExp('(foo)', 'i'); | 80 * var r = new RegExp('(foo)', 'i'); |
| (...skipping 526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 function setSearchManagerForTesting(searchManager) { | 607 function setSearchManagerForTesting(searchManager) { |
| 607 SearchManagerImpl.instance_ = searchManager; | 608 SearchManagerImpl.instance_ = searchManager; |
| 608 } | 609 } |
| 609 | 610 |
| 610 return { | 611 return { |
| 611 getSearchManager: getSearchManager, | 612 getSearchManager: getSearchManager, |
| 612 setSearchManagerForTesting: setSearchManagerForTesting, | 613 setSearchManagerForTesting: setSearchManagerForTesting, |
| 613 SearchRequest: SearchRequest, | 614 SearchRequest: SearchRequest, |
| 614 }; | 615 }; |
| 615 }); | 616 }); |
| OLD | NEW |