OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 * The global object. | 6 * The global object. |
7 * @type {!Object} | 7 * @type {!Object} |
8 */ | 8 */ |
9 const global = this; | 9 const global = this; |
10 | 10 |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 var afterA = a.nextSibling; | 101 var afterA = a.nextSibling; |
102 if (afterA == b) { | 102 if (afterA == b) { |
103 swapDomNodes(b, a); | 103 swapDomNodes(b, a); |
104 return; | 104 return; |
105 } | 105 } |
106 var aParent = a.parentNode; | 106 var aParent = a.parentNode; |
107 b.parentNode.replaceChild(a, b); | 107 b.parentNode.replaceChild(a, b); |
108 aParent.insertBefore(b, afterA); | 108 aParent.insertBefore(b, afterA); |
109 } | 109 } |
110 | 110 |
111 /* | 111 // Handle click on a link. If the link points to a chrome: or file: url, then |
112 * Handles a click or mouseup on a link. If the link points to a chrome: or | 112 // call into the browser to do the navigation. |
113 * file: url, then call into the browser to do the navigation. | 113 document.addEventListener('click', function(e) { |
114 * @return {Object} e The click or mouseup event. | |
115 */ | |
116 function handleLinkClickOrMouseUp(e) { | |
117 // Allow preventDefault to work. | 114 // Allow preventDefault to work. |
118 if (!e.returnValue) | 115 if (!e.returnValue) |
119 return; | 116 return; |
120 | 117 |
121 var el = e.target; | 118 var el = e.target; |
122 if (el.nodeType == Node.ELEMENT_NODE && | 119 if (el.nodeType == Node.ELEMENT_NODE && |
123 el.webkitMatchesSelector('A, A *')) { | 120 el.webkitMatchesSelector('A, A *')) { |
124 while (el.tagName != 'A') { | 121 while (el.tagName != 'A') { |
125 el = el.parentElement; | 122 el = el.parentElement; |
126 } | 123 } |
127 | 124 |
128 if ((el.protocol == 'file:' || el.protocol == 'about:') && | 125 if ((el.protocol == 'file:' || el.protocol == 'about:') && |
129 ((e.button == 0 && e.type == 'click') || | 126 (e.button == 0 || e.button == 1)) { |
130 (e.button == 1 && e.type == 'mouseup'))) { | |
131 chrome.send('navigateToUrl', | 127 chrome.send('navigateToUrl', |
132 [el.href, e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); | 128 [el.href, e.button, e.altKey, e.ctrlKey, e.metaKey, e.shiftKey]); |
133 e.preventDefault(); | 129 e.preventDefault(); |
134 } | 130 } |
135 } | 131 } |
136 } | 132 }); |
137 | |
138 document.addEventListener('click', handleLinkClickOrMouseUp); | |
139 document.addEventListener('mouseup', handleLinkClickOrMouseUp); | |
OLD | NEW |