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} |
(...skipping 837 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(justincohen): handle scrolling within the DOM. |
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 |