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 17 matching lines...) Expand all Loading... |
28 * | 28 * |
29 * Contains diff method based on Javascript Diff Algorithm By John Resig | 29 * Contains diff method based on Javascript Diff Algorithm By John Resig |
30 * http://ejohn.org/files/jsdiff.js (released under the MIT license). | 30 * http://ejohn.org/files/jsdiff.js (released under the MIT license). |
31 */ | 31 */ |
32 | 32 |
33 /** | 33 /** |
34 * @param {number} offset | 34 * @param {number} offset |
35 * @param {string} stopCharacters | 35 * @param {string} stopCharacters |
36 * @param {!Node} stayWithinNode | 36 * @param {!Node} stayWithinNode |
37 * @param {string=} direction | 37 * @param {string=} direction |
| 38 * @return {!Range} |
38 */ | 39 */ |
39 Node.prototype.rangeOfWord = function(offset, stopCharacters, stayWithinNode, di
rection) | 40 Node.prototype.rangeOfWord = function(offset, stopCharacters, stayWithinNode, di
rection) |
40 { | 41 { |
41 var startNode; | 42 var startNode; |
42 var startOffset = 0; | 43 var startOffset = 0; |
43 var endNode; | 44 var endNode; |
44 var endOffset = 0; | 45 var endOffset = 0; |
45 | 46 |
46 if (!stayWithinNode) | 47 if (!stayWithinNode) |
47 stayWithinNode = this; | 48 stayWithinNode = this; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 endOffset = offset; | 117 endOffset = offset; |
117 } | 118 } |
118 | 119 |
119 var result = this.ownerDocument.createRange(); | 120 var result = this.ownerDocument.createRange(); |
120 result.setStart(startNode, startOffset); | 121 result.setStart(startNode, startOffset); |
121 result.setEnd(endNode, endOffset); | 122 result.setEnd(endNode, endOffset); |
122 | 123 |
123 return result; | 124 return result; |
124 } | 125 } |
125 | 126 |
| 127 /** |
| 128 * @param {!Node=} stayWithin |
| 129 * @return {?Node} |
| 130 */ |
126 Node.prototype.traverseNextTextNode = function(stayWithin) | 131 Node.prototype.traverseNextTextNode = function(stayWithin) |
127 { | 132 { |
128 var node = this.traverseNextNode(stayWithin); | 133 var node = this.traverseNextNode(stayWithin); |
129 if (!node) | 134 if (!node) |
130 return; | 135 return null; |
131 | 136 |
132 while (node && node.nodeType !== Node.TEXT_NODE) | 137 while (node && node.nodeType !== Node.TEXT_NODE) |
133 node = node.traverseNextNode(stayWithin); | 138 node = node.traverseNextNode(stayWithin); |
134 | 139 |
135 return node; | 140 return node; |
136 } | 141 } |
137 | 142 |
| 143 /** |
| 144 * @param {number} offset |
| 145 * @return {!{container: !Node, offset: number}} |
| 146 */ |
138 Node.prototype.rangeBoundaryForOffset = function(offset) | 147 Node.prototype.rangeBoundaryForOffset = function(offset) |
139 { | 148 { |
140 var node = this.traverseNextTextNode(this); | 149 var node = this.traverseNextTextNode(this); |
141 while (node && offset > node.nodeValue.length) { | 150 while (node && offset > node.nodeValue.length) { |
142 offset -= node.nodeValue.length; | 151 offset -= node.nodeValue.length; |
143 node = node.traverseNextTextNode(this); | 152 node = node.traverseNextTextNode(this); |
144 } | 153 } |
145 if (!node) | 154 if (!node) |
146 return { container: this, offset: 0 }; | 155 return { container: this, offset: 0 }; |
147 return { container: node, offset: offset }; | 156 return { container: node, offset: offset }; |
(...skipping 21 matching lines...) Expand all Loading... |
169 this.style.setProperty("left", (shift.x + x) + "px"); | 178 this.style.setProperty("left", (shift.x + x) + "px"); |
170 else | 179 else |
171 this.style.removeProperty("left"); | 180 this.style.removeProperty("left"); |
172 | 181 |
173 if (typeof y === "number") | 182 if (typeof y === "number") |
174 this.style.setProperty("top", (shift.y + y) + "px"); | 183 this.style.setProperty("top", (shift.y + y) + "px"); |
175 else | 184 else |
176 this.style.removeProperty("top"); | 185 this.style.removeProperty("top"); |
177 } | 186 } |
178 | 187 |
| 188 /** |
| 189 * @return {boolean} |
| 190 */ |
179 Element.prototype.isScrolledToBottom = function() | 191 Element.prototype.isScrolledToBottom = function() |
180 { | 192 { |
181 // This code works only for 0-width border. | 193 // This code works only for 0-width border. |
182 // Both clientHeight and scrollHeight are rounded to integer values, so we t
olerate | 194 // Both clientHeight and scrollHeight are rounded to integer values, so we t
olerate |
183 // one pixel error. | 195 // one pixel error. |
184 return Math.abs(this.scrollTop + this.clientHeight - this.scrollHeight) <= 1
; | 196 return Math.abs(this.scrollTop + this.clientHeight - this.scrollHeight) <= 1
; |
185 } | 197 } |
186 | 198 |
187 /** | 199 /** |
188 * @param {!Node} fromNode | 200 * @param {!Node} fromNode |
(...skipping 29 matching lines...) Expand all Loading... |
218 throw new Error("Minimum size is greater than preferred."); | 230 throw new Error("Minimum size is greater than preferred."); |
219 } | 231 } |
220 | 232 |
221 /** | 233 /** |
222 * @param {?Constraints} constraints | 234 * @param {?Constraints} constraints |
223 * @return {boolean} | 235 * @return {boolean} |
224 */ | 236 */ |
225 Constraints.prototype.isEqual = function(constraints) | 237 Constraints.prototype.isEqual = function(constraints) |
226 { | 238 { |
227 return !!constraints && this.minimum.isEqual(constraints.minimum) && this.pr
eferred.isEqual(constraints.preferred); | 239 return !!constraints && this.minimum.isEqual(constraints.minimum) && this.pr
eferred.isEqual(constraints.preferred); |
228 }; | 240 } |
229 | 241 |
230 /** | 242 /** |
231 * @param {!Constraints|number} value | 243 * @param {!Constraints|number} value |
232 * @return {!Constraints} | 244 * @return {!Constraints} |
233 */ | 245 */ |
234 Constraints.prototype.widthToMax = function(value) | 246 Constraints.prototype.widthToMax = function(value) |
235 { | 247 { |
236 if (typeof value === "number") | 248 if (typeof value === "number") |
237 return new Constraints(this.minimum.widthToMax(value), this.preferred.wi
dthToMax(value)); | 249 return new Constraints(this.minimum.widthToMax(value), this.preferred.wi
dthToMax(value)); |
238 return new Constraints(this.minimum.widthToMax(value.minimum), this.preferre
d.widthToMax(value.preferred)); | 250 return new Constraints(this.minimum.widthToMax(value.minimum), this.preferre
d.widthToMax(value.preferred)); |
239 }; | 251 } |
240 | 252 |
241 /** | 253 /** |
242 * @param {!Constraints|number} value | 254 * @param {!Constraints|number} value |
243 * @return {!Constraints} | 255 * @return {!Constraints} |
244 */ | 256 */ |
245 Constraints.prototype.addWidth = function(value) | 257 Constraints.prototype.addWidth = function(value) |
246 { | 258 { |
247 if (typeof value === "number") | 259 if (typeof value === "number") |
248 return new Constraints(this.minimum.addWidth(value), this.preferred.addW
idth(value)); | 260 return new Constraints(this.minimum.addWidth(value), this.preferred.addW
idth(value)); |
249 return new Constraints(this.minimum.addWidth(value.minimum), this.preferred.
addWidth(value.preferred)); | 261 return new Constraints(this.minimum.addWidth(value.minimum), this.preferred.
addWidth(value.preferred)); |
250 }; | 262 } |
251 | 263 |
252 /** | 264 /** |
253 * @param {!Constraints|number} value | 265 * @param {!Constraints|number} value |
254 * @return {!Constraints} | 266 * @return {!Constraints} |
255 */ | 267 */ |
256 Constraints.prototype.heightToMax = function(value) | 268 Constraints.prototype.heightToMax = function(value) |
257 { | 269 { |
258 if (typeof value === "number") | 270 if (typeof value === "number") |
259 return new Constraints(this.minimum.heightToMax(value), this.preferred.h
eightToMax(value)); | 271 return new Constraints(this.minimum.heightToMax(value), this.preferred.h
eightToMax(value)); |
260 return new Constraints(this.minimum.heightToMax(value.minimum), this.preferr
ed.heightToMax(value.preferred)); | 272 return new Constraints(this.minimum.heightToMax(value.minimum), this.preferr
ed.heightToMax(value.preferred)); |
261 }; | 273 } |
262 | 274 |
263 /** | 275 /** |
264 * @param {!Constraints|number} value | 276 * @param {!Constraints|number} value |
265 * @return {!Constraints} | 277 * @return {!Constraints} |
266 */ | 278 */ |
267 Constraints.prototype.addHeight = function(value) | 279 Constraints.prototype.addHeight = function(value) |
268 { | 280 { |
269 if (typeof value === "number") | 281 if (typeof value === "number") |
270 return new Constraints(this.minimum.addHeight(value), this.preferred.add
Height(value)); | 282 return new Constraints(this.minimum.addHeight(value), this.preferred.add
Height(value)); |
271 return new Constraints(this.minimum.addHeight(value.minimum), this.preferred
.addHeight(value.preferred)); | 283 return new Constraints(this.minimum.addHeight(value.minimum), this.preferred
.addHeight(value.preferred)); |
272 }; | 284 } |
273 | 285 |
274 /** | 286 /** |
275 * @param {?Element=} containerElement | 287 * @param {?Element=} containerElement |
276 * @return {!Size} | 288 * @return {!Size} |
277 */ | 289 */ |
278 Element.prototype.measurePreferredSize = function(containerElement) | 290 Element.prototype.measurePreferredSize = function(containerElement) |
279 { | 291 { |
280 containerElement = containerElement || document.body; | 292 containerElement = containerElement || document.body; |
281 containerElement.appendChild(this); | 293 containerElement.appendChild(this); |
282 this.positionAt(0, 0); | 294 this.positionAt(0, 0); |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 for (var i = 0; i < children.length; ++i) | 367 for (var i = 0; i < children.length; ++i) |
356 this.appendChild(children[i]); | 368 this.appendChild(children[i]); |
357 } | 369 } |
358 | 370 |
359 Element.prototype.setChildren = function(children) | 371 Element.prototype.setChildren = function(children) |
360 { | 372 { |
361 this.removeChildren(); | 373 this.removeChildren(); |
362 this.appendChildren(children); | 374 this.appendChildren(children); |
363 } | 375 } |
364 | 376 |
| 377 /** |
| 378 * @return {boolean} |
| 379 */ |
365 Element.prototype.isInsertionCaretInside = function() | 380 Element.prototype.isInsertionCaretInside = function() |
366 { | 381 { |
367 var selection = window.getSelection(); | 382 var selection = window.getSelection(); |
368 if (!selection.rangeCount || !selection.isCollapsed) | 383 if (!selection.rangeCount || !selection.isCollapsed) |
369 return false; | 384 return false; |
370 var selectionRange = selection.getRangeAt(0); | 385 var selectionRange = selection.getRangeAt(0); |
371 return selectionRange.startContainer.isSelfOrDescendant(this); | 386 return selectionRange.startContainer.isSelfOrDescendant(this); |
372 } | 387 } |
373 | 388 |
374 /** | 389 /** |
375 * @param {string} elementName | 390 * @param {string} elementName |
376 * @param {string=} className | 391 * @param {string=} className |
| 392 * @return {!Element} |
377 */ | 393 */ |
378 Document.prototype.createElementWithClass = function(elementName, className) | 394 Document.prototype.createElementWithClass = function(elementName, className) |
379 { | 395 { |
380 var element = this.createElement(elementName); | 396 var element = this.createElement(elementName); |
381 if (className) | 397 if (className) |
382 element.className = className; | 398 element.className = className; |
383 return element; | 399 return element; |
384 } | 400 } |
385 | 401 |
386 /** | 402 /** |
387 * @param {string} elementName | 403 * @param {string} elementName |
388 * @param {string=} className | 404 * @param {string=} className |
| 405 * @return {!Element} |
389 */ | 406 */ |
390 Element.prototype.createChild = function(elementName, className) | 407 Element.prototype.createChild = function(elementName, className) |
391 { | 408 { |
392 var element = this.ownerDocument.createElementWithClass(elementName, classNa
me); | 409 var element = this.ownerDocument.createElementWithClass(elementName, classNa
me); |
393 this.appendChild(element); | 410 this.appendChild(element); |
394 return element; | 411 return element; |
395 } | 412 } |
396 | 413 |
397 DocumentFragment.prototype.createChild = Element.prototype.createChild; | 414 DocumentFragment.prototype.createChild = Element.prototype.createChild; |
398 | 415 |
399 /** | 416 /** |
400 * @param {string} text | 417 * @param {string} text |
| 418 * @return {!Text} |
401 */ | 419 */ |
402 Element.prototype.createTextChild = function(text) | 420 Element.prototype.createTextChild = function(text) |
403 { | 421 { |
404 var element = this.ownerDocument.createTextNode(text); | 422 var element = this.ownerDocument.createTextNode(text); |
405 this.appendChild(element); | 423 this.appendChild(element); |
406 return element; | 424 return element; |
407 } | 425 } |
408 | 426 |
409 DocumentFragment.prototype.createTextChild = Element.prototype.createTextChild; | 427 DocumentFragment.prototype.createTextChild = Element.prototype.createTextChild; |
410 | 428 |
411 /** | 429 /** |
412 * @return {number} | 430 * @return {number} |
413 */ | 431 */ |
414 Element.prototype.totalOffsetLeft = function() | 432 Element.prototype.totalOffsetLeft = function() |
415 { | 433 { |
416 return this.totalOffset().left; | 434 return this.totalOffset().left; |
417 } | 435 } |
418 | 436 |
419 /** | 437 /** |
420 * @return {number} | 438 * @return {number} |
421 */ | 439 */ |
422 Element.prototype.totalOffsetTop = function() | 440 Element.prototype.totalOffsetTop = function() |
423 { | 441 { |
424 return this.totalOffset().top; | 442 return this.totalOffset().top; |
425 | 443 |
426 } | 444 } |
427 | 445 |
| 446 /** |
| 447 * @return {!{left: number, top: number}} |
| 448 */ |
428 Element.prototype.totalOffset = function() | 449 Element.prototype.totalOffset = function() |
429 { | 450 { |
430 var rect = this.getBoundingClientRect(); | 451 var rect = this.getBoundingClientRect(); |
431 return { left: rect.left, top: rect.top }; | 452 return { left: rect.left, top: rect.top }; |
432 } | 453 } |
433 | 454 |
| 455 /** |
| 456 * @return {!{left: number, top: number}} |
| 457 */ |
434 Element.prototype.scrollOffset = function() | 458 Element.prototype.scrollOffset = function() |
435 { | 459 { |
436 var curLeft = 0; | 460 var curLeft = 0; |
437 var curTop = 0; | 461 var curTop = 0; |
438 for (var element = this; element; element = element.scrollParent) { | 462 for (var element = this; element; element = element.scrollParent) { |
439 curLeft += element.scrollLeft; | 463 curLeft += element.scrollLeft; |
440 curTop += element.scrollTop; | 464 curTop += element.scrollTop; |
441 } | 465 } |
442 return { left: curLeft, top: curTop }; | 466 return { left: curLeft, top: curTop }; |
443 } | 467 } |
(...skipping 14 matching lines...) Expand all Loading... |
458 } | 482 } |
459 | 483 |
460 /** | 484 /** |
461 * @param {!AnchorBox} box | 485 * @param {!AnchorBox} box |
462 * @return {!AnchorBox} | 486 * @return {!AnchorBox} |
463 */ | 487 */ |
464 AnchorBox.prototype.relativeTo = function(box) | 488 AnchorBox.prototype.relativeTo = function(box) |
465 { | 489 { |
466 return new AnchorBox( | 490 return new AnchorBox( |
467 this.x - box.x, this.y - box.y, this.width, this.height); | 491 this.x - box.x, this.y - box.y, this.width, this.height); |
468 }; | 492 } |
469 | 493 |
470 /** | 494 /** |
471 * @param {!Element} element | 495 * @param {!Element} element |
472 * @return {!AnchorBox} | 496 * @return {!AnchorBox} |
473 */ | 497 */ |
474 AnchorBox.prototype.relativeToElement = function(element) | 498 AnchorBox.prototype.relativeToElement = function(element) |
475 { | 499 { |
476 return this.relativeTo(element.boxInWindow(element.ownerDocument.defaultView
)); | 500 return this.relativeTo(element.boxInWindow(element.ownerDocument.defaultView
)); |
477 }; | 501 } |
478 | 502 |
479 /** | 503 /** |
480 * @param {?AnchorBox} anchorBox | 504 * @param {?AnchorBox} anchorBox |
481 * @return {boolean} | 505 * @return {boolean} |
482 */ | 506 */ |
483 AnchorBox.prototype.equals = function(anchorBox) | 507 AnchorBox.prototype.equals = function(anchorBox) |
484 { | 508 { |
485 return !!anchorBox && this.x === anchorBox.x && this.y === anchorBox.y && th
is.width === anchorBox.width && this.height === anchorBox.height; | 509 return !!anchorBox && this.x === anchorBox.x && this.y === anchorBox.y && th
is.width === anchorBox.width && this.height === anchorBox.height; |
486 }; | 510 } |
487 | 511 |
488 /** | 512 /** |
489 * @param {!Window} targetWindow | 513 * @param {!Window} targetWindow |
490 * @return {!AnchorBox} | 514 * @return {!AnchorBox} |
491 */ | 515 */ |
492 Element.prototype.offsetRelativeToWindow = function(targetWindow) | 516 Element.prototype.offsetRelativeToWindow = function(targetWindow) |
493 { | 517 { |
494 var elementOffset = new AnchorBox(); | 518 var elementOffset = new AnchorBox(); |
495 var curElement = this; | 519 var curElement = this; |
496 var curWindow = this.ownerDocument.defaultView; | 520 var curWindow = this.ownerDocument.defaultView; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 * @param {boolean=} preventDefault | 578 * @param {boolean=} preventDefault |
555 */ | 579 */ |
556 Event.prototype.consume = function(preventDefault) | 580 Event.prototype.consume = function(preventDefault) |
557 { | 581 { |
558 this.stopImmediatePropagation(); | 582 this.stopImmediatePropagation(); |
559 if (preventDefault) | 583 if (preventDefault) |
560 this.preventDefault(); | 584 this.preventDefault(); |
561 this.handled = true; | 585 this.handled = true; |
562 } | 586 } |
563 | 587 |
| 588 /** |
| 589 * @param {number=} start |
| 590 * @param {number=} end |
| 591 * @return {!Text} |
| 592 */ |
564 Text.prototype.select = function(start, end) | 593 Text.prototype.select = function(start, end) |
565 { | 594 { |
566 start = start || 0; | 595 start = start || 0; |
567 end = end || this.textContent.length; | 596 end = end || this.textContent.length; |
568 | 597 |
569 if (start < 0) | 598 if (start < 0) |
570 start = end + start; | 599 start = end + start; |
571 | 600 |
572 var selection = this.ownerDocument.defaultView.getSelection(); | 601 var selection = this.ownerDocument.defaultView.getSelection(); |
573 selection.removeAllRanges(); | 602 selection.removeAllRanges(); |
574 var range = this.ownerDocument.createRange(); | 603 var range = this.ownerDocument.createRange(); |
575 range.setStart(this, start); | 604 range.setStart(this, start); |
576 range.setEnd(this, end); | 605 range.setEnd(this, end); |
577 selection.addRange(range); | 606 selection.addRange(range); |
578 return this; | 607 return this; |
579 } | 608 } |
580 | 609 |
| 610 /** |
| 611 * @return {?number} |
| 612 */ |
581 Element.prototype.selectionLeftOffset = function() | 613 Element.prototype.selectionLeftOffset = function() |
582 { | 614 { |
583 // Calculate selection offset relative to the current element. | 615 // Calculate selection offset relative to the current element. |
584 | 616 |
585 var selection = window.getSelection(); | 617 var selection = window.getSelection(); |
586 if (!selection.containsNode(this, true)) | 618 if (!selection.containsNode(this, true)) |
587 return null; | 619 return null; |
588 | 620 |
589 var leftOffset = selection.anchorOffset; | 621 var leftOffset = selection.anchorOffset; |
590 var node = selection.anchorNode; | 622 var node = selection.anchorNode; |
591 | 623 |
592 while (node !== this) { | 624 while (node !== this) { |
593 while (node.previousSibling) { | 625 while (node.previousSibling) { |
594 node = node.previousSibling; | 626 node = node.previousSibling; |
595 leftOffset += node.textContent.length; | 627 leftOffset += node.textContent.length; |
596 } | 628 } |
597 node = node.parentNode; | 629 node = node.parentNode; |
598 } | 630 } |
599 | 631 |
600 return leftOffset; | 632 return leftOffset; |
601 } | 633 } |
602 | 634 |
| 635 /** |
| 636 * @param {?Node} node |
| 637 * @return {boolean} |
| 638 */ |
603 Node.prototype.isAncestor = function(node) | 639 Node.prototype.isAncestor = function(node) |
604 { | 640 { |
605 if (!node) | 641 if (!node) |
606 return false; | 642 return false; |
607 | 643 |
608 var currentNode = node.parentNode; | 644 var currentNode = node.parentNode; |
609 while (currentNode) { | 645 while (currentNode) { |
610 if (this === currentNode) | 646 if (this === currentNode) |
611 return true; | 647 return true; |
612 currentNode = currentNode.parentNode; | 648 currentNode = currentNode.parentNode; |
613 } | 649 } |
614 return false; | 650 return false; |
615 } | 651 } |
616 | 652 |
| 653 /** |
| 654 * @param {?Node} descendant |
| 655 * @return {boolean} |
| 656 */ |
617 Node.prototype.isDescendant = function(descendant) | 657 Node.prototype.isDescendant = function(descendant) |
618 { | 658 { |
619 return !!descendant && descendant.isAncestor(this); | 659 return !!descendant && descendant.isAncestor(this); |
620 } | 660 } |
621 | 661 |
| 662 /** |
| 663 * @param {?Node} node |
| 664 * @return {boolean} |
| 665 */ |
622 Node.prototype.isSelfOrAncestor = function(node) | 666 Node.prototype.isSelfOrAncestor = function(node) |
623 { | 667 { |
624 return !!node && (node === this || this.isAncestor(node)); | 668 return !!node && (node === this || this.isAncestor(node)); |
625 } | 669 } |
626 | 670 |
| 671 /** |
| 672 * @param {?Node} node |
| 673 * @return {boolean} |
| 674 */ |
627 Node.prototype.isSelfOrDescendant = function(node) | 675 Node.prototype.isSelfOrDescendant = function(node) |
628 { | 676 { |
629 return !!node && (node === this || this.isDescendant(node)); | 677 return !!node && (node === this || this.isDescendant(node)); |
630 } | 678 } |
631 | 679 |
| 680 /** |
| 681 * @param {!Node=} stayWithin |
| 682 * @return {?Node} |
| 683 */ |
632 Node.prototype.traverseNextNode = function(stayWithin) | 684 Node.prototype.traverseNextNode = function(stayWithin) |
633 { | 685 { |
634 var node = this.firstChild; | 686 var node = this.firstChild; |
635 if (node) | 687 if (node) |
636 return node; | 688 return node; |
637 | 689 |
638 if (stayWithin && this === stayWithin) | 690 if (stayWithin && this === stayWithin) |
639 return null; | 691 return null; |
640 | 692 |
641 node = this.nextSibling; | 693 node = this.nextSibling; |
642 if (node) | 694 if (node) |
643 return node; | 695 return node; |
644 | 696 |
645 node = this; | 697 node = this; |
646 while (node && !node.nextSibling && (!stayWithin || !node.parentNode || node
.parentNode !== stayWithin)) | 698 while (node && !node.nextSibling && (!stayWithin || !node.parentNode || node
.parentNode !== stayWithin)) |
647 node = node.parentNode; | 699 node = node.parentNode; |
648 if (!node) | 700 if (!node) |
649 return null; | 701 return null; |
650 | 702 |
651 return node.nextSibling; | 703 return node.nextSibling; |
652 } | 704 } |
653 | 705 |
| 706 /** |
| 707 * @param {!Node=} stayWithin |
| 708 * @return {?Node} |
| 709 */ |
654 Node.prototype.traversePreviousNode = function(stayWithin) | 710 Node.prototype.traversePreviousNode = function(stayWithin) |
655 { | 711 { |
656 if (stayWithin && this === stayWithin) | 712 if (stayWithin && this === stayWithin) |
657 return null; | 713 return null; |
658 var node = this.previousSibling; | 714 var node = this.previousSibling; |
659 while (node && node.lastChild) | 715 while (node && node.lastChild) |
660 node = node.lastChild; | 716 node = node.lastChild; |
661 if (node) | 717 if (node) |
662 return node; | 718 return node; |
663 return this.parentNode; | 719 return this.parentNode; |
(...skipping 25 matching lines...) Expand all Loading... |
689 */ | 745 */ |
690 function isEnterKey(event) { | 746 function isEnterKey(event) { |
691 // Check if in IME. | 747 // Check if in IME. |
692 return event.keyCode !== 229 && event.keyIdentifier === "Enter"; | 748 return event.keyCode !== 229 && event.keyIdentifier === "Enter"; |
693 } | 749 } |
694 | 750 |
695 function consumeEvent(e) | 751 function consumeEvent(e) |
696 { | 752 { |
697 e.consume(); | 753 e.consume(); |
698 } | 754 } |
OLD | NEW |