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 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 return null; | 563 return null; |
564 var node = this.previousSibling; | 564 var node = this.previousSibling; |
565 while (node && node.lastChild) | 565 while (node && node.lastChild) |
566 node = node.lastChild; | 566 node = node.lastChild; |
567 if (node) | 567 if (node) |
568 return node; | 568 return node; |
569 return this.parentNode; | 569 return this.parentNode; |
570 } | 570 } |
571 | 571 |
572 /** | 572 /** |
| 573 * @param {*} text |
| 574 * @param {string=} placeholder |
| 575 * @return {boolean} true if was truncated |
| 576 */ |
| 577 Node.prototype.setTextContentTruncatedIfNeeded = function(text, placeholder) |
| 578 { |
| 579 // Huge texts in the UI reduce rendering performance drastically. |
| 580 // Moreover, Blink/WebKit uses <unsigned short> internally for storing text
content |
| 581 // length, so texts longer than 65535 are inherently displayed incorrectly. |
| 582 const maxTextContentLength = 65535; |
| 583 |
| 584 if (typeof text === "string" && text.length > maxTextContentLength) { |
| 585 this.textContent = typeof placeholder === "string" ? placeholder : text.
trimEnd(maxTextContentLength); |
| 586 return true; |
| 587 } |
| 588 |
| 589 this.textContent = text; |
| 590 return false; |
| 591 } |
| 592 |
| 593 /** |
573 * @return {boolean} | 594 * @return {boolean} |
574 */ | 595 */ |
575 function isEnterKey(event) { | 596 function isEnterKey(event) { |
576 // Check if in IME. | 597 // Check if in IME. |
577 return event.keyCode !== 229 && event.keyIdentifier === "Enter"; | 598 return event.keyCode !== 229 && event.keyIdentifier === "Enter"; |
578 } | 599 } |
579 | 600 |
580 function consumeEvent(e) | 601 function consumeEvent(e) |
581 { | 602 { |
582 e.consume(); | 603 e.consume(); |
583 } | 604 } |
OLD | NEW |