OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
3 * Copyright (C) 2012 Google Inc. All rights reserved. | 3 * Copyright (C) 2012 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 * @param {!Event} event | 290 * @param {!Event} event |
291 * @return {boolean} | 291 * @return {boolean} |
292 */ | 292 */ |
293 Element.prototype.containsEventPoint = function(event) | 293 Element.prototype.containsEventPoint = function(event) |
294 { | 294 { |
295 var box = this.getBoundingClientRect(); | 295 var box = this.getBoundingClientRect(); |
296 return box.left < event.x && event.x < box.right && | 296 return box.left < event.x && event.x < box.right && |
297 box.top < event.y && event.y < box.bottom; | 297 box.top < event.y && event.y < box.bottom; |
298 } | 298 } |
299 | 299 |
| 300 /** |
| 301 * @param {!Array.<string>} nameArray |
| 302 * @return {?Node} |
| 303 */ |
300 Node.prototype.enclosingNodeOrSelfWithNodeNameInArray = function(nameArray) | 304 Node.prototype.enclosingNodeOrSelfWithNodeNameInArray = function(nameArray) |
301 { | 305 { |
302 for (var node = this; node && node !== this.ownerDocument; node = node.paren
tNode) | 306 for (var node = this; node && node !== this.ownerDocument; node = node.paren
tNode) { |
303 for (var i = 0; i < nameArray.length; ++i) | 307 for (var i = 0; i < nameArray.length; ++i) { |
304 if (node.nodeName.toLowerCase() === nameArray[i].toLowerCase()) | 308 if (node.nodeName.toLowerCase() === nameArray[i].toLowerCase()) |
305 return node; | 309 return node; |
| 310 } |
| 311 } |
306 return null; | 312 return null; |
307 } | 313 } |
308 | 314 |
| 315 /** |
| 316 * @param {string} nodeName |
| 317 * @return {?Node} |
| 318 */ |
309 Node.prototype.enclosingNodeOrSelfWithNodeName = function(nodeName) | 319 Node.prototype.enclosingNodeOrSelfWithNodeName = function(nodeName) |
310 { | 320 { |
311 return this.enclosingNodeOrSelfWithNodeNameInArray([nodeName]); | 321 return this.enclosingNodeOrSelfWithNodeNameInArray([nodeName]); |
312 } | 322 } |
313 | 323 |
314 /** | 324 /** |
315 * @param {string} className | 325 * @param {string} className |
316 * @param {!Element=} stayWithin | 326 * @param {!Element=} stayWithin |
| 327 * @return {?Element} |
317 */ | 328 */ |
318 Node.prototype.enclosingNodeOrSelfWithClass = function(className, stayWithin) | 329 Node.prototype.enclosingNodeOrSelfWithClass = function(className, stayWithin) |
319 { | 330 { |
320 for (var node = this; node && node !== stayWithin && node !== this.ownerDocu
ment; node = node.parentNode) | 331 for (var node = this; node && node !== stayWithin && node !== this.ownerDocu
ment; node = node.parentNode) { |
321 if (node.nodeType === Node.ELEMENT_NODE && node.classList.contains(class
Name)) | 332 if (node.nodeType === Node.ELEMENT_NODE && node.classList.contains(class
Name)) |
322 return node; | 333 return /** @type {!Element} */ (node); |
| 334 } |
323 return null; | 335 return null; |
324 } | 336 } |
325 | 337 |
| 338 /** |
| 339 * @param {string} query |
| 340 * @return {?Node} |
| 341 */ |
326 Element.prototype.query = function(query) | 342 Element.prototype.query = function(query) |
327 { | 343 { |
328 return this.ownerDocument.evaluate(query, this, null, XPathResult.FIRST_ORDE
RED_NODE_TYPE, null).singleNodeValue; | 344 return this.ownerDocument.evaluate(query, this, null, XPathResult.FIRST_ORDE
RED_NODE_TYPE, null).singleNodeValue; |
329 } | 345 } |
330 | 346 |
331 Element.prototype.removeChildren = function() | 347 Element.prototype.removeChildren = function() |
332 { | 348 { |
333 if (this.firstChild) | 349 if (this.firstChild) |
334 this.textContent = ""; | 350 this.textContent = ""; |
335 } | 351 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 break; | 501 break; |
486 | 502 |
487 curElement = curWindow.frameElement; | 503 curElement = curWindow.frameElement; |
488 curWindow = curWindow.parent; | 504 curWindow = curWindow.parent; |
489 } | 505 } |
490 | 506 |
491 return elementOffset; | 507 return elementOffset; |
492 } | 508 } |
493 | 509 |
494 /** | 510 /** |
495 * @param {!Window} targetWindow | 511 * @param {!Window=} targetWindow |
496 * @return {!AnchorBox} | 512 * @return {!AnchorBox} |
497 */ | 513 */ |
498 Element.prototype.boxInWindow = function(targetWindow) | 514 Element.prototype.boxInWindow = function(targetWindow) |
499 { | 515 { |
500 targetWindow = targetWindow || this.ownerDocument.defaultView; | 516 targetWindow = targetWindow || this.ownerDocument.defaultView; |
501 | 517 |
502 var anchorBox = this.offsetRelativeToWindow(window); | 518 var anchorBox = this.offsetRelativeToWindow(window); |
503 anchorBox.width = Math.min(this.offsetWidth, window.innerWidth - anchorBox.x
); | 519 anchorBox.width = Math.min(this.offsetWidth, window.innerWidth - anchorBox.x
); |
504 anchorBox.height = Math.min(this.offsetHeight, window.innerHeight - anchorBo
x.y); | 520 anchorBox.height = Math.min(this.offsetHeight, window.innerHeight - anchorBo
x.y); |
505 | 521 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
673 */ | 689 */ |
674 function isEnterKey(event) { | 690 function isEnterKey(event) { |
675 // Check if in IME. | 691 // Check if in IME. |
676 return event.keyCode !== 229 && event.keyIdentifier === "Enter"; | 692 return event.keyCode !== 229 && event.keyIdentifier === "Enter"; |
677 } | 693 } |
678 | 694 |
679 function consumeEvent(e) | 695 function consumeEvent(e) |
680 { | 696 { |
681 e.consume(); | 697 e.consume(); |
682 } | 698 } |
OLD | NEW |