OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 /** | 5 /** |
6 * This file is lifted from the GoogleMobile find tool. | 6 * Based heavily on code from the Google iOS app. |
7 * | 7 * |
8 * @fileoverview A find in page tool. It scans the DOM for elements with the | 8 * @fileoverview A find in page tool. It scans the DOM for elements with the |
9 * text being search for, and wraps them with a span that highlights them. | 9 * text being search for, and wraps them with a span that highlights them. |
10 * | |
11 * @author bmcmahan@google.com (Benjamin McMahan) | |
12 * | |
13 */ | 10 */ |
14 | 11 |
15 /** | 12 /** |
16 * Namespace for this file. Depends on __gCrWeb having already been injected. | 13 * Namespace for this file. Depends on __gCrWeb having already been injected. |
17 */ | 14 */ |
18 __gCrWeb['findInPage'] = {}; | 15 __gCrWeb['findInPage'] = {}; |
19 | 16 |
20 /** | 17 /** |
21 * Index of the current highlighted choice. -1 means none. | 18 * Index of the current highlighted choice. -1 means none. |
22 * @type {number} | 19 * @type {number} |
23 */ | 20 */ |
24 __gCrWeb['findInPage']['index'] = -1; | 21 __gCrWeb['findInPage']['index'] = -1; |
25 | 22 |
26 /** | 23 /** |
27 * The list of found searches in span form. | 24 * The list of found searches in span form. |
28 * @type {Array.<Element>} | 25 * @type {Array.<Element>} |
29 */ | 26 */ |
30 __gCrWeb['findInPage']['spans'] = []; | 27 __gCrWeb['findInPage']['spans'] = []; |
31 | 28 |
32 /** | 29 /** |
33 * The list of frame documents. | 30 * The list of frame documents. |
34 * TODO(justincohen): x-domain frames won't work. | 31 * TODO(ios): x-domain frames won't work. |
35 * @type {Array.<Document>} | 32 * @type {Array.<Document>} |
36 */ | 33 */ |
37 __gCrWeb['findInPage'].frameDocs = []; | 34 __gCrWeb['findInPage'].frameDocs = []; |
38 | 35 |
39 /** | 36 /** |
40 * Associate array to stash element styles while the element is highlighted. | 37 * Associate array to stash element styles while the element is highlighted. |
41 * @type {Object.<Element,Object<string,string>>} | 38 * @type {Object.<Element,Object<string,string>>} |
42 */ | 39 */ |
43 __gCrWeb['findInPage'].savedElementStyles = {}; | 40 __gCrWeb['findInPage'].savedElementStyles = {}; |
44 | 41 |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 | 208 |
212 /** | 209 /** |
213 * Break up find in page DOM regex, DOM manipulation and visibility check | 210 * Break up find in page DOM regex, DOM manipulation and visibility check |
214 * into sections that can be stopped and restarted later. Because the js runs | 211 * into sections that can be stopped and restarted later. Because the js runs |
215 * in the main UI thread, anything over timeout will cause the UI to lock up. | 212 * in the main UI thread, anything over timeout will cause the UI to lock up. |
216 * @param {number} timeout Only run find in page until timeout. | 213 * @param {number} timeout Only run find in page until timeout. |
217 * @return {boolean} Whether find in page completed. | 214 * @return {boolean} Whether find in page completed. |
218 */ | 215 */ |
219 __gCrWeb['findInPage']['pumpSearch'] = function(timeout) { | 216 __gCrWeb['findInPage']['pumpSearch'] = function(timeout) { |
220 var opt_split = false; | 217 var opt_split = false; |
221 // TODO(justincohen): It would be better if this DCHECKed. | 218 // TODO(ios): It would be better if this DCHECKed. |
stuartmorgan
2015/05/19 18:26:47
We should *never* be adding TODO(ios); it's a bad
sdefresne
2015/05/20 08:05:32
Acknowledged.
| |
222 if (__gCrWeb['findInPage'].searchInProgress == false) | 219 if (__gCrWeb['findInPage'].searchInProgress == false) |
223 return __gCrWeb['findInPage'].NO_RESULTS; | 220 return __gCrWeb['findInPage'].NO_RESULTS; |
224 | 221 |
225 __gCrWeb['findInPage'].timeout = timeout; | 222 __gCrWeb['findInPage'].timeout = timeout; |
226 __gCrWeb['findInPage'].startTime = __gCrWeb['findInPage'].time(); | 223 __gCrWeb['findInPage'].startTime = __gCrWeb['findInPage'].time(); |
227 | 224 |
228 var regex = __gCrWeb['findInPage'].regex; | 225 var regex = __gCrWeb['findInPage'].regex; |
229 // Go through every node in DFS fashion. | 226 // Go through every node in DFS fashion. |
230 while (__gCrWeb['findInPage'].node) { | 227 while (__gCrWeb['findInPage'].node) { |
231 var node = __gCrWeb['findInPage'].node; | 228 var node = __gCrWeb['findInPage'].node; |
(...skipping 628 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
860 | 857 |
861 var originalElement = elem; | 858 var originalElement = elem; |
862 var nextOffsetParent = originalElement.offsetParent; | 859 var nextOffsetParent = originalElement.offsetParent; |
863 var computedStyle = | 860 var computedStyle = |
864 elem.ownerDocument.defaultView.getComputedStyle(elem, null); | 861 elem.ownerDocument.defaultView.getComputedStyle(elem, null); |
865 | 862 |
866 // We are currently handling all scrolling through the app, which means we can | 863 // We are currently handling all scrolling through the app, which means we can |
867 // only scroll the window, not any scrollable containers in the DOM itself. So | 864 // only scroll the window, not any scrollable containers in the DOM itself. So |
868 // for now this function returns false if the element is scrolled outside the | 865 // for now this function returns false if the element is scrolled outside the |
869 // viewable area of its ancestors. | 866 // viewable area of its ancestors. |
870 // TODO (jonwall): handle scrolling within the DOM. | 867 // TODO (ios): handle scrolling within the DOM. |
stuartmorgan
2015/05/19 18:26:47
TODO(
sdefresne
2015/05/20 08:05:32
Acknowledged.
| |
871 var pageHeight = __gCrWeb['findInPage'].getBodyHeight(); | 868 var pageHeight = __gCrWeb['findInPage'].getBodyHeight(); |
872 var pageWidth = __gCrWeb['findInPage'].getBodyWidth(); | 869 var pageWidth = __gCrWeb['findInPage'].getBodyWidth(); |
873 | 870 |
874 while (elem && elem.nodeName != 'BODY') { | 871 while (elem && elem.nodeName != 'BODY') { |
875 if (elem.style.display === 'none' || | 872 if (elem.style.display === 'none' || |
876 elem.style.visibility === 'hidden' || | 873 elem.style.visibility === 'hidden' || |
877 elem.style.opacity === 0 || | 874 elem.style.opacity === 0 || |
878 computedStyle.display === 'none' || | 875 computedStyle.display === 'none' || |
879 computedStyle.visibility === 'hidden' || | 876 computedStyle.visibility === 'hidden' || |
880 computedStyle.opacity === 0) { | 877 computedStyle.opacity === 0) { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
955 var win = windowsToSearch.pop(); | 952 var win = windowsToSearch.pop(); |
956 for (var i = win.frames.length - 1; i >= 0; i--) { | 953 for (var i = win.frames.length - 1; i >= 0; i--) { |
957 if (win.frames[i].document) { | 954 if (win.frames[i].document) { |
958 documents.push(win.frames[i].document); | 955 documents.push(win.frames[i].document); |
959 windowsToSearch.push(win.frames[i]); | 956 windowsToSearch.push(win.frames[i]); |
960 } | 957 } |
961 } | 958 } |
962 } | 959 } |
963 return documents; | 960 return documents; |
964 }; | 961 }; |
OLD | NEW |