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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 document.onselectstart = function(e) { | 113 document.onselectstart = function(e) { |
114 e.preventDefault(); | 114 e.preventDefault(); |
115 } | 115 } |
116 | 116 |
117 // Disable dragging. | 117 // Disable dragging. |
118 document.ondragstart = function(e) { | 118 document.ondragstart = function(e) { |
119 e.preventDefault(); | 119 e.preventDefault(); |
120 } | 120 } |
121 } | 121 } |
122 | 122 |
| 123 /** |
| 124 * Check the directionality of the page. |
| 125 * @return {boolean} True if Chrome is running an RTL UI. |
| 126 */ |
| 127 function isRTL() { |
| 128 return document.documentElement.dir == 'rtl'; |
| 129 } |
| 130 |
| 131 /** |
| 132 * Simple common assertion API |
| 133 * @param {*} condition The condition to test. Note that this may be used to |
| 134 * test whether a value is defined or not, and we don't want to force a |
| 135 * cast to Boolean. |
| 136 * @param {string=} opt_message A message to use in any error. |
| 137 */ |
| 138 function assert(condition, opt_message) { |
| 139 'use strict'; |
| 140 if (!condition) { |
| 141 var msg = 'Assertion failed'; |
| 142 if (opt_message) |
| 143 msg = msg + ': ' + opt_message; |
| 144 throw new Error(msg); |
| 145 } |
| 146 } |
| 147 |
| 148 /** |
| 149 * Get an element that's known to exist by its ID. We use this instead of just |
| 150 * calling getElementById and not checking the result because this lets us |
| 151 * satisfy the JSCompiler type system. |
| 152 * @param {string} id The identifier name. |
| 153 * @return {!Element} the Element. |
| 154 */ |
| 155 function getRequiredElement(id) { |
| 156 var element = $(id); |
| 157 assert(element, 'Missing required element: ' + id); |
| 158 return element; |
| 159 } |
| 160 |
123 // Handle click on a link. If the link points to a chrome: or file: url, then | 161 // Handle click on a link. If the link points to a chrome: or file: url, then |
124 // call into the browser to do the navigation. | 162 // call into the browser to do the navigation. |
125 document.addEventListener('click', function(e) { | 163 document.addEventListener('click', function(e) { |
126 // Allow preventDefault to work. | 164 // Allow preventDefault to work. |
127 if (!e.returnValue) | 165 if (!e.returnValue) |
128 return; | 166 return; |
129 | 167 |
130 var el = e.target; | 168 var el = e.target; |
131 if (el.nodeType == Node.ELEMENT_NODE && | 169 if (el.nodeType == Node.ELEMENT_NODE && |
132 el.webkitMatchesSelector('A, A *')) { | 170 el.webkitMatchesSelector('A, A *')) { |
133 while (el.tagName != 'A') { | 171 while (el.tagName != 'A') { |
134 el = el.parentElement; | 172 el = el.parentElement; |
135 } | 173 } |
136 | 174 |
137 if ((el.protocol == 'file:' || el.protocol == 'about:') && | 175 if ((el.protocol == 'file:' || el.protocol == 'about:') && |
138 (e.button == 0 || e.button == 1)) { | 176 (e.button == 0 || e.button == 1)) { |
139 chrome.send('navigateToUrl', [ | 177 chrome.send('navigateToUrl', [ |
140 el.href, | 178 el.href, |
141 el.target, | 179 el.target, |
142 e.button, | 180 e.button, |
143 e.altKey, | 181 e.altKey, |
144 e.ctrlKey, | 182 e.ctrlKey, |
145 e.metaKey, | 183 e.metaKey, |
146 e.shiftKey | 184 e.shiftKey |
147 ]); | 185 ]); |
148 e.preventDefault(); | 186 e.preventDefault(); |
149 } | 187 } |
150 } | 188 } |
151 }); | 189 }); |
OLD | NEW |