Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: Source/devtools/front_end/ui/DOMExtension.js

Issue 675753002: [DevTools] Drop "ui" module from toolbox. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: rootview bug fix Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Google Inc. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15 * its contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * Contains diff method based on Javascript Diff Algorithm By John Resig
30 * http://ejohn.org/files/jsdiff.js (released under the MIT license).
31 */
32
33 /**
34 * @param {number} offset
35 * @param {string} stopCharacters
36 * @param {!Node} stayWithinNode
37 * @param {string=} direction
38 * @return {!Range}
39 */
40 Node.prototype.rangeOfWord = function(offset, stopCharacters, stayWithinNode, di rection)
41 {
42 var startNode;
43 var startOffset = 0;
44 var endNode;
45 var endOffset = 0;
46
47 if (!stayWithinNode)
48 stayWithinNode = this;
49
50 if (!direction || direction === "backward" || direction === "both") {
51 var node = this;
52 while (node) {
53 if (node === stayWithinNode) {
54 if (!startNode)
55 startNode = stayWithinNode;
56 break;
57 }
58
59 if (node.nodeType === Node.TEXT_NODE) {
60 var start = (node === this ? (offset - 1) : (node.nodeValue.leng th - 1));
61 for (var i = start; i >= 0; --i) {
62 if (stopCharacters.indexOf(node.nodeValue[i]) !== -1) {
63 startNode = node;
64 startOffset = i + 1;
65 break;
66 }
67 }
68 }
69
70 if (startNode)
71 break;
72
73 node = node.traversePreviousNode(stayWithinNode);
74 }
75
76 if (!startNode) {
77 startNode = stayWithinNode;
78 startOffset = 0;
79 }
80 } else {
81 startNode = this;
82 startOffset = offset;
83 }
84
85 if (!direction || direction === "forward" || direction === "both") {
86 node = this;
87 while (node) {
88 if (node === stayWithinNode) {
89 if (!endNode)
90 endNode = stayWithinNode;
91 break;
92 }
93
94 if (node.nodeType === Node.TEXT_NODE) {
95 var start = (node === this ? offset : 0);
96 for (var i = start; i < node.nodeValue.length; ++i) {
97 if (stopCharacters.indexOf(node.nodeValue[i]) !== -1) {
98 endNode = node;
99 endOffset = i;
100 break;
101 }
102 }
103 }
104
105 if (endNode)
106 break;
107
108 node = node.traverseNextNode(stayWithinNode);
109 }
110
111 if (!endNode) {
112 endNode = stayWithinNode;
113 endOffset = stayWithinNode.nodeType === Node.TEXT_NODE ? stayWithinN ode.nodeValue.length : stayWithinNode.childNodes.length;
114 }
115 } else {
116 endNode = this;
117 endOffset = offset;
118 }
119
120 var result = this.ownerDocument.createRange();
121 result.setStart(startNode, startOffset);
122 result.setEnd(endNode, endOffset);
123
124 return result;
125 }
126
127 /**
128 * @param {!Node=} stayWithin
129 * @return {?Node}
130 */
131 Node.prototype.traverseNextTextNode = function(stayWithin)
132 {
133 var node = this.traverseNextNode(stayWithin);
134 if (!node)
135 return null;
136
137 while (node && node.nodeType !== Node.TEXT_NODE)
138 node = node.traverseNextNode(stayWithin);
139
140 return node;
141 }
142
143 /**
144 * @param {number} offset
145 * @return {!{container: !Node, offset: number}}
146 */
147 Node.prototype.rangeBoundaryForOffset = function(offset)
148 {
149 var node = this.traverseNextTextNode(this);
150 while (node && offset > node.nodeValue.length) {
151 offset -= node.nodeValue.length;
152 node = node.traverseNextTextNode(this);
153 }
154 if (!node)
155 return { container: this, offset: 0 };
156 return { container: node, offset: offset };
157 }
158
159 /**
160 * @param {number|undefined} x
161 * @param {number|undefined} y
162 * @param {!Element=} relativeTo
163 */
164 Element.prototype.positionAt = function(x, y, relativeTo)
165 {
166 var shift = {x: 0, y: 0};
167 if (relativeTo)
168 shift = relativeTo.boxInWindow(this.ownerDocument.defaultView);
169
170 if (typeof x === "number")
171 this.style.setProperty("left", (shift.x + x) + "px");
172 else
173 this.style.removeProperty("left");
174
175 if (typeof y === "number")
176 this.style.setProperty("top", (shift.y + y) + "px");
177 else
178 this.style.removeProperty("top");
179 }
180
181 /**
182 * @return {boolean}
183 */
184 Element.prototype.isScrolledToBottom = function()
185 {
186 // This code works only for 0-width border.
187 // Both clientHeight and scrollHeight are rounded to integer values, so we t olerate
188 // one pixel error.
189 return Math.abs(this.scrollTop + this.clientHeight - this.scrollHeight) <= 1 ;
190 }
191
192 /**
193 * @param {!Node} fromNode
194 * @param {!Node} toNode
195 */
196 function removeSubsequentNodes(fromNode, toNode)
197 {
198 for (var node = fromNode; node && node !== toNode; ) {
199 var nodeToRemove = node;
200 node = node.nextSibling;
201 nodeToRemove.remove();
202 }
203 }
204
205 /**
206 * @constructor
207 * @param {!Size} minimum
208 * @param {?Size=} preferred
209 */
210 function Constraints(minimum, preferred)
211 {
212 /**
213 * @type {!Size}
214 */
215 this.minimum = minimum;
216
217 /**
218 * @type {!Size}
219 */
220 this.preferred = preferred || minimum;
221
222 if (this.minimum.width > this.preferred.width || this.minimum.height > this. preferred.height)
223 throw new Error("Minimum size is greater than preferred.");
224 }
225
226 /**
227 * @param {?Constraints} constraints
228 * @return {boolean}
229 */
230 Constraints.prototype.isEqual = function(constraints)
231 {
232 return !!constraints && this.minimum.isEqual(constraints.minimum) && this.pr eferred.isEqual(constraints.preferred);
233 }
234
235 /**
236 * @param {!Constraints|number} value
237 * @return {!Constraints}
238 */
239 Constraints.prototype.widthToMax = function(value)
240 {
241 if (typeof value === "number")
242 return new Constraints(this.minimum.widthToMax(value), this.preferred.wi dthToMax(value));
243 return new Constraints(this.minimum.widthToMax(value.minimum), this.preferre d.widthToMax(value.preferred));
244 }
245
246 /**
247 * @param {!Constraints|number} value
248 * @return {!Constraints}
249 */
250 Constraints.prototype.addWidth = function(value)
251 {
252 if (typeof value === "number")
253 return new Constraints(this.minimum.addWidth(value), this.preferred.addW idth(value));
254 return new Constraints(this.minimum.addWidth(value.minimum), this.preferred. addWidth(value.preferred));
255 }
256
257 /**
258 * @param {!Constraints|number} value
259 * @return {!Constraints}
260 */
261 Constraints.prototype.heightToMax = function(value)
262 {
263 if (typeof value === "number")
264 return new Constraints(this.minimum.heightToMax(value), this.preferred.h eightToMax(value));
265 return new Constraints(this.minimum.heightToMax(value.minimum), this.preferr ed.heightToMax(value.preferred));
266 }
267
268 /**
269 * @param {!Constraints|number} value
270 * @return {!Constraints}
271 */
272 Constraints.prototype.addHeight = function(value)
273 {
274 if (typeof value === "number")
275 return new Constraints(this.minimum.addHeight(value), this.preferred.add Height(value));
276 return new Constraints(this.minimum.addHeight(value.minimum), this.preferred .addHeight(value.preferred));
277 }
278
279 /**
280 * @param {?Element=} containerElement
281 * @return {!Size}
282 */
283 Element.prototype.measurePreferredSize = function(containerElement)
284 {
285 containerElement = containerElement || this.ownerDocument.body;
286 containerElement.appendChild(this);
287 var fakingComponentRoot = false;
288 if (!this.classList.contains("component-root")) {
289 fakingComponentRoot = true;
290 this.classList.add("component-root");
291 }
292 this.positionAt(0, 0);
293 var result = new Size(this.offsetWidth, this.offsetHeight);
294 this.positionAt(undefined, undefined);
295 this.remove();
296 if (fakingComponentRoot)
297 this.classList.remove("component-root");
298 return result;
299 }
300
301 /**
302 * @param {!Event} event
303 * @return {boolean}
304 */
305 Element.prototype.containsEventPoint = function(event)
306 {
307 var box = this.getBoundingClientRect();
308 return box.left < event.x && event.x < box.right &&
309 box.top < event.y && event.y < box.bottom;
310 }
311
312 /**
313 * @param {!Array.<string>} nameArray
314 * @return {?Node}
315 */
316 Node.prototype.enclosingNodeOrSelfWithNodeNameInArray = function(nameArray)
317 {
318 for (var node = this; node && node !== this.ownerDocument; node = node.paren tNodeOrShadowHost()) {
319 for (var i = 0; i < nameArray.length; ++i) {
320 if (node.nodeName.toLowerCase() === nameArray[i].toLowerCase())
321 return node;
322 }
323 }
324 return null;
325 }
326
327 /**
328 * @param {string} nodeName
329 * @return {?Node}
330 */
331 Node.prototype.enclosingNodeOrSelfWithNodeName = function(nodeName)
332 {
333 return this.enclosingNodeOrSelfWithNodeNameInArray([nodeName]);
334 }
335
336 /**
337 * @param {string} className
338 * @param {!Element=} stayWithin
339 * @return {?Element}
340 */
341 Node.prototype.enclosingNodeOrSelfWithClass = function(className, stayWithin)
342 {
343 for (var node = this; node && node !== stayWithin && node !== this.ownerDocu ment; node = node.parentNodeOrShadowHost()) {
344 if (node.nodeType === Node.ELEMENT_NODE && node.classList.contains(class Name))
345 return /** @type {!Element} */ (node);
346 }
347 return null;
348 }
349
350 /**
351 * @return {?Element}
352 */
353 Node.prototype.parentElementOrShadowHost = function()
354 {
355 var node = this.parentNode;
356 if (!node)
357 return null;
358 if (node.nodeType === Node.ELEMENT_NODE)
359 return /** @type {!Element} */ (node);
360 if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE)
361 return /** @type {!Element} */ (node.host);
362 return null;
363 }
364
365 /**
366 * @return {?Node}
367 */
368 Node.prototype.parentNodeOrShadowHost = function()
369 {
370 return this.parentNode || this.host || null;
371 }
372
373 /**
374 * @param {string} query
375 * @return {?Node}
376 */
377 Element.prototype.query = function(query)
378 {
379 return this.ownerDocument.evaluate(query, this, null, XPathResult.FIRST_ORDE RED_NODE_TYPE, null).singleNodeValue;
380 }
381
382 Element.prototype.removeChildren = function()
383 {
384 if (this.firstChild)
385 this.textContent = "";
386 }
387
388 /**
389 * @return {boolean}
390 */
391 Element.prototype.isInsertionCaretInside = function()
392 {
393 var selection = window.getSelection();
394 if (!selection.rangeCount || !selection.isCollapsed)
395 return false;
396 var selectionRange = selection.getRangeAt(0);
397 return selectionRange.startContainer.isSelfOrDescendant(this);
398 }
399
400 /**
401 * @param {string} tagName
402 * @return {!Element}
403 * @suppressGlobalPropertiesCheck
404 */
405 function createElement(tagName)
406 {
407 return document.createElement(tagName);
408 }
409
410 /**
411 * @param {number|string} data
412 * @return {!Text}
413 * @suppressGlobalPropertiesCheck
414 */
415 function createTextNode(data)
416 {
417 return document.createTextNode(data);
418 }
419
420 /**
421 * @param {string} elementName
422 * @param {string=} className
423 * @return {!Element}
424 */
425 Document.prototype.createElementWithClass = function(elementName, className)
426 {
427 var element = this.createElement(elementName);
428 if (className)
429 element.className = className;
430 return element;
431 }
432
433 /**
434 * @param {string} elementName
435 * @param {string=} className
436 * @return {!Element}
437 * @suppressGlobalPropertiesCheck
438 */
439 function createElementWithClass(elementName, className)
440 {
441 return document.createElementWithClass(elementName, className);
442 }
443
444 /**
445 * @return {!DocumentFragment}
446 * @suppressGlobalPropertiesCheck
447 */
448 function createDocumentFragment()
449 {
450 return document.createDocumentFragment();
451 }
452
453 /**
454 * @param {string} elementName
455 * @param {string=} className
456 * @return {!Element}
457 */
458 Element.prototype.createChild = function(elementName, className)
459 {
460 var element = this.ownerDocument.createElementWithClass(elementName, classNa me);
461 this.appendChild(element);
462 return element;
463 }
464
465 DocumentFragment.prototype.createChild = Element.prototype.createChild;
466
467 /**
468 * @param {string} text
469 * @return {!Text}
470 */
471 Element.prototype.createTextChild = function(text)
472 {
473 var element = this.ownerDocument.createTextNode(text);
474 this.appendChild(element);
475 return element;
476 }
477
478 DocumentFragment.prototype.createTextChild = Element.prototype.createTextChild;
479
480 /**
481 * @param {...string} var_args
482 */
483 Element.prototype.createTextChildren = function(var_args)
484 {
485 for (var i = 0, n = arguments.length; i < n; ++i)
486 this.createTextChild(arguments[i]);
487 }
488
489 DocumentFragment.prototype.createTextChildren = Element.prototype.createTextChil dren;
490
491 /**
492 * @param {...!Element} var_args
493 */
494 Element.prototype.appendChildren = function(var_args)
495 {
496 for (var i = 0, n = arguments.length; i < n; ++i)
497 this.appendChild(arguments[i]);
498 }
499
500 /**
501 * @return {number}
502 */
503 Element.prototype.totalOffsetLeft = function()
504 {
505 return this.totalOffset().left;
506 }
507
508 /**
509 * @return {number}
510 */
511 Element.prototype.totalOffsetTop = function()
512 {
513 return this.totalOffset().top;
514 }
515
516 /**
517 * @return {!{left: number, top: number}}
518 */
519 Element.prototype.totalOffset = function()
520 {
521 var rect = this.getBoundingClientRect();
522 return { left: rect.left, top: rect.top };
523 }
524
525 /**
526 * @return {!{left: number, top: number}}
527 */
528 Element.prototype.scrollOffset = function()
529 {
530 var curLeft = 0;
531 var curTop = 0;
532 for (var element = this; element; element = element.scrollParent) {
533 curLeft += element.scrollLeft;
534 curTop += element.scrollTop;
535 }
536 return { left: curLeft, top: curTop };
537 }
538
539 /**
540 * @constructor
541 * @param {number=} x
542 * @param {number=} y
543 * @param {number=} width
544 * @param {number=} height
545 */
546 function AnchorBox(x, y, width, height)
547 {
548 this.x = x || 0;
549 this.y = y || 0;
550 this.width = width || 0;
551 this.height = height || 0;
552 }
553
554 /**
555 * @param {!AnchorBox} box
556 * @return {!AnchorBox}
557 */
558 AnchorBox.prototype.relativeTo = function(box)
559 {
560 return new AnchorBox(
561 this.x - box.x, this.y - box.y, this.width, this.height);
562 }
563
564 /**
565 * @param {!Element} element
566 * @return {!AnchorBox}
567 */
568 AnchorBox.prototype.relativeToElement = function(element)
569 {
570 return this.relativeTo(element.boxInWindow(element.ownerDocument.defaultView ));
571 }
572
573 /**
574 * @param {?AnchorBox} anchorBox
575 * @return {boolean}
576 */
577 AnchorBox.prototype.equals = function(anchorBox)
578 {
579 return !!anchorBox && this.x === anchorBox.x && this.y === anchorBox.y && th is.width === anchorBox.width && this.height === anchorBox.height;
580 }
581
582 /**
583 * @param {!Window} targetWindow
584 * @return {!AnchorBox}
585 */
586 Element.prototype.offsetRelativeToWindow = function(targetWindow)
587 {
588 var elementOffset = new AnchorBox();
589 var curElement = this;
590 var curWindow = this.ownerDocument.defaultView;
591 while (curWindow && curElement) {
592 elementOffset.x += curElement.totalOffsetLeft();
593 elementOffset.y += curElement.totalOffsetTop();
594 if (curWindow === targetWindow)
595 break;
596
597 curElement = curWindow.frameElement;
598 curWindow = curWindow.parent;
599 }
600
601 return elementOffset;
602 }
603
604 /**
605 * @param {!Window=} targetWindow
606 * @return {!AnchorBox}
607 */
608 Element.prototype.boxInWindow = function(targetWindow)
609 {
610 targetWindow = targetWindow || this.ownerDocument.defaultView;
611
612 var anchorBox = this.offsetRelativeToWindow(window);
613 anchorBox.width = Math.min(this.offsetWidth, window.innerWidth - anchorBox.x );
614 anchorBox.height = Math.min(this.offsetHeight, window.innerHeight - anchorBo x.y);
615
616 return anchorBox;
617 }
618
619 /**
620 * @param {string} text
621 */
622 Element.prototype.setTextAndTitle = function(text)
623 {
624 this.textContent = text;
625 this.title = text;
626 }
627
628 KeyboardEvent.prototype.__defineGetter__("data", function()
629 {
630 // Emulate "data" attribute from DOM 3 TextInput event.
631 // See http://www.w3.org/TR/DOM-Level-3-Events/#events-Events-TextEvent-data
632 switch (this.type) {
633 case "keypress":
634 if (!this.ctrlKey && !this.metaKey)
635 return String.fromCharCode(this.charCode);
636 else
637 return "";
638 case "keydown":
639 case "keyup":
640 if (!this.ctrlKey && !this.metaKey && !this.altKey)
641 return String.fromCharCode(this.which);
642 else
643 return "";
644 }
645 });
646
647 /**
648 * @param {boolean=} preventDefault
649 */
650 Event.prototype.consume = function(preventDefault)
651 {
652 this.stopImmediatePropagation();
653 if (preventDefault)
654 this.preventDefault();
655 this.handled = true;
656 }
657
658 /**
659 * @param {number=} start
660 * @param {number=} end
661 * @return {!Text}
662 */
663 Text.prototype.select = function(start, end)
664 {
665 start = start || 0;
666 end = end || this.textContent.length;
667
668 if (start < 0)
669 start = end + start;
670
671 var selection = this.ownerDocument.defaultView.getSelection();
672 selection.removeAllRanges();
673 var range = this.ownerDocument.createRange();
674 range.setStart(this, start);
675 range.setEnd(this, end);
676 selection.addRange(range);
677 return this;
678 }
679
680 /**
681 * @return {?number}
682 */
683 Element.prototype.selectionLeftOffset = function()
684 {
685 // Calculate selection offset relative to the current element.
686
687 var selection = window.getSelection();
688 if (!selection.containsNode(this, true))
689 return null;
690
691 var leftOffset = selection.anchorOffset;
692 var node = selection.anchorNode;
693
694 while (node !== this) {
695 while (node.previousSibling) {
696 node = node.previousSibling;
697 leftOffset += node.textContent.length;
698 }
699 node = node.parentNodeOrShadowHost();
700 }
701
702 return leftOffset;
703 }
704
705 /**
706 * @return {string}
707 */
708 Node.prototype.deepTextContent = function()
709 {
710 var node = this.traverseNextTextNode(this);
711 var result = [];
712 var nonTextTags = { "STYLE": 1, "SCRIPT": 1 };
713 while (node) {
714 if (!nonTextTags[node.parentElement.nodeName])
715 result.push(node.textContent);
716 node = node.traverseNextTextNode(this);
717 }
718 return result.join("");
719 }
720
721 /**
722 * @param {?Node} node
723 * @return {boolean}
724 */
725 Node.prototype.isAncestor = function(node)
726 {
727 if (!node)
728 return false;
729
730 var currentNode = node.parentNodeOrShadowHost();
731 while (currentNode) {
732 if (this === currentNode)
733 return true;
734 currentNode = currentNode.parentNodeOrShadowHost();
735 }
736 return false;
737 }
738
739 /**
740 * @param {?Node} descendant
741 * @return {boolean}
742 */
743 Node.prototype.isDescendant = function(descendant)
744 {
745 return !!descendant && descendant.isAncestor(this);
746 }
747
748 /**
749 * @param {?Node} node
750 * @return {boolean}
751 */
752 Node.prototype.isSelfOrAncestor = function(node)
753 {
754 return !!node && (node === this || this.isAncestor(node));
755 }
756
757 /**
758 * @param {?Node} node
759 * @return {boolean}
760 */
761 Node.prototype.isSelfOrDescendant = function(node)
762 {
763 return !!node && (node === this || this.isDescendant(node));
764 }
765
766 /**
767 * @param {!Node=} stayWithin
768 * @return {?Node}
769 */
770 Node.prototype.traverseNextNode = function(stayWithin)
771 {
772 if (this.firstChild)
773 return this.firstChild;
774
775 if (this.shadowRoot)
776 return this.shadowRoot;
777
778 if (stayWithin && this === stayWithin)
779 return null;
780
781 var node = this.nextSibling;
782 if (node)
783 return node;
784
785 node = this;
786 while (node && !node.nextSibling && (!stayWithin || !node.parentNodeOrShadow Host() || node.parentNodeOrShadowHost() !== stayWithin))
787 node = node.parentNodeOrShadowHost();
788 if (!node)
789 return null;
790
791 return node.nextSibling;
792 }
793
794 /**
795 * @param {!Node=} stayWithin
796 * @return {?Node}
797 */
798 Node.prototype.traversePreviousNode = function(stayWithin)
799 {
800 if (stayWithin && this === stayWithin)
801 return null;
802 var node = this.previousSibling;
803 while (node && node.lastChild)
804 node = node.lastChild;
805 if (node)
806 return node;
807 return this.parentNodeOrShadowHost();
808 }
809
810 /**
811 * @param {*} text
812 * @param {string=} placeholder
813 * @return {boolean} true if was truncated
814 */
815 Node.prototype.setTextContentTruncatedIfNeeded = function(text, placeholder)
816 {
817 // Huge texts in the UI reduce rendering performance drastically.
818 // Moreover, Blink/WebKit uses <unsigned short> internally for storing text content
819 // length, so texts longer than 65535 are inherently displayed incorrectly.
820 const maxTextContentLength = 65535;
821
822 if (typeof text === "string" && text.length > maxTextContentLength) {
823 this.textContent = typeof placeholder === "string" ? placeholder : text. trimEnd(maxTextContentLength);
824 return true;
825 }
826
827 this.textContent = text;
828 return false;
829 }
830
831 /**
832 * @return {?Node}
833 */
834 Event.prototype.deepElementFromPoint = function()
835 {
836 // 1. climb to the component root.
837 var node = this.target;
838 while (node && node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE && node.nodeTyp e !== Node.DOCUMENT_NODE)
839 node = node.parentNode;
840
841 if (!node)
842 return null;
843
844 // 2. Find deepest node by coordinates.
845 node = node.elementFromPoint(this.pageX, this.pageY);
846 while (node && node.shadowRoot)
847 node = node.shadowRoot.elementFromPoint(this.pageX, this.pageY);
848 return node;
849 }
850
851 /**
852 * @param {number} x
853 * @param {number} y
854 * @return {?Node}
855 */
856 Document.prototype.deepElementFromPoint = function(x, y)
857 {
858 var node = this.elementFromPoint(x, y);
859 while (node && node.shadowRoot)
860 node = node.shadowRoot.elementFromPoint(x, y);
861 return node;
862 }
863
864 /**
865 * @return {boolean}
866 */
867 function isEnterKey(event) {
868 // Check if in IME.
869 return event.keyCode !== 229 && event.keyIdentifier === "Enter";
870 }
871
872 function consumeEvent(e)
873 {
874 e.consume();
875 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698