2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Matt Lilek (pewtermoose@gmail.com).
5 * Copyright (C) 2009 Joseph Pecoraro
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
17 * its contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
21 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 * @param {!Element} element
34 * @param {?function(!MouseEvent): boolean} elementDragStart
35 * @param {function(!MouseEvent)} elementDrag
36 * @param {?function(!MouseEvent)} elementDragEnd
37 * @param {!string} cursor
38 * @param {?string=} hoverCursor
40 WebInspector.installDragHandle = function(element, elementDragStart, elementDrag, elementDragEnd, cursor, hoverCursor)
42 element.addEventListener("mousedown", WebInspector.elementDragStart.bind(WebInspector, elementDragStart, elementDrag, elementDragEnd, cursor), false);
43 if (hoverCursor !== null)
44 element.style.cursor = hoverCursor || cursor;
48 * @param {?function(!MouseEvent):boolean} elementDragStart
49 * @param {function(!MouseEvent)} elementDrag
50 * @param {?function(!MouseEvent)} elementDragEnd
51 * @param {string} cursor
52 * @param {?Event} event
54 WebInspector.elementDragStart = function(elementDragStart, elementDrag, elementDragEnd, cursor, event)
56 // Only drag upon left button. Right will likely cause a context menu. So will ctrl-click on mac.
57 if (event.button || (WebInspector.isMac() && event.ctrlKey))
60 if (WebInspector._elementDraggingEventListener)
63 if (elementDragStart && !elementDragStart(/** @type {!MouseEvent} */ (event)))
66 if (WebInspector._elementDraggingGlassPane) {
67 WebInspector._elementDraggingGlassPane.dispose();
68 delete WebInspector._elementDraggingGlassPane;
71 var targetDocument = event.target.ownerDocument;
73 WebInspector._elementDraggingEventListener = elementDrag;
74 WebInspector._elementEndDraggingEventListener = elementDragEnd;
75 WebInspector._mouseOutWhileDraggingTargetDocument = targetDocument;
77 targetDocument.addEventListener("mousemove", WebInspector._elementDragMove, true);
78 targetDocument.addEventListener("mouseup", WebInspector._elementDragEnd, true);
79 targetDocument.addEventListener("mouseout", WebInspector._mouseOutWhileDragging, true);
81 targetDocument.body.style.cursor = cursor;
83 event.preventDefault();
86 WebInspector._mouseOutWhileDragging = function()
88 WebInspector._unregisterMouseOutWhileDragging();
89 WebInspector._elementDraggingGlassPane = new WebInspector.GlassPane();
92 WebInspector._unregisterMouseOutWhileDragging = function()
94 if (!WebInspector._mouseOutWhileDraggingTargetDocument)
96 WebInspector._mouseOutWhileDraggingTargetDocument.removeEventListener("mouseout", WebInspector._mouseOutWhileDragging, true);
97 delete WebInspector._mouseOutWhileDraggingTargetDocument;
101 * @param {!Event} event
103 WebInspector._elementDragMove = function(event)
105 if (WebInspector._elementDraggingEventListener(/** @type {!MouseEvent} */ (event)))
106 WebInspector._cancelDragEvents(event);
110 * @param {!Event} event
112 WebInspector._cancelDragEvents = function(event)
114 var targetDocument = event.target.ownerDocument;
115 targetDocument.removeEventListener("mousemove", WebInspector._elementDragMove, true);
116 targetDocument.removeEventListener("mouseup", WebInspector._elementDragEnd, true);
117 WebInspector._unregisterMouseOutWhileDragging();
119 targetDocument.body.style.removeProperty("cursor");
121 if (WebInspector._elementDraggingGlassPane)
122 WebInspector._elementDraggingGlassPane.dispose();
124 delete WebInspector._elementDraggingGlassPane;
125 delete WebInspector._elementDraggingEventListener;
126 delete WebInspector._elementEndDraggingEventListener;
130 * @param {!Event} event
132 WebInspector._elementDragEnd = function(event)
134 var elementDragEnd = WebInspector._elementEndDraggingEventListener;
136 WebInspector._cancelDragEvents(/** @type {!MouseEvent} */ (event));
138 event.preventDefault();
140 elementDragEnd(/** @type {!MouseEvent} */ (event));
146 WebInspector.GlassPane = function()
148 this.element = document.createElement("div");
149 this.element.style.cssText = "position:absolute;top:0;bottom:0;left:0;right:0;background-color:transparent;z-index:1000;";
150 this.element.id = "glass-pane";
151 document.body.appendChild(this.element);
152 WebInspector._glassPane = this;
155 WebInspector.GlassPane.prototype = {
158 delete WebInspector._glassPane;
159 if (WebInspector.HelpScreen.isVisible())
160 WebInspector.HelpScreen.focus();
162 WebInspector.inspectorView.focus();
163 this.element.remove();
167 WebInspector.isBeingEdited = function(node)
169 if (node.nodeType !== Node.ELEMENT_NODE)
171 var element = /** {!Element} */ (node);
172 if (element.classList.contains("text-prompt") || element.nodeName === "INPUT" || element.nodeName === "TEXTAREA")
175 if (!WebInspector.__editingCount)
179 if (element.__editing)
181 element = element.parentElement;
186 WebInspector.markBeingEdited = function(element, value)
189 if (element.__editing)
191 element.classList.add("being-edited");
192 element.__editing = true;
193 WebInspector.__editingCount = (WebInspector.__editingCount || 0) + 1;
195 if (!element.__editing)
197 element.classList.remove("being-edited");
198 delete element.__editing;
199 --WebInspector.__editingCount;
204 WebInspector.CSSNumberRegex = /^(-?(?:\d+(?:\.\d+)?|\.\d+))$/;
206 WebInspector.StyleValueDelimiters = " \xA0\t\n\"':;,/()";
210 * @param {!Event} event
213 WebInspector._valueModificationDirection = function(event)
215 var direction = null;
216 if (event.type === "mousewheel") {
217 if (event.wheelDeltaY > 0)
219 else if (event.wheelDeltaY < 0)
222 if (event.keyIdentifier === "Up" || event.keyIdentifier === "PageUp")
224 else if (event.keyIdentifier === "Down" || event.keyIdentifier === "PageDown")
231 * @param {string} hexString
232 * @param {!Event} event
234 WebInspector._modifiedHexValue = function(hexString, event)
236 var direction = WebInspector._valueModificationDirection(event);
240 var number = parseInt(hexString, 16);
241 if (isNaN(number) || !isFinite(number))
244 var maxValue = Math.pow(16, hexString.length) - 1;
245 var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyIdentifier === "Down" || event.type === "mousewheel");
248 if (arrowKeyOrMouseWheelEvent)
249 delta = (direction === "Up") ? 1 : -1;
251 delta = (event.keyIdentifier === "PageUp") ? 16 : -16;
256 var result = number + delta;
258 result = 0; // Color hex values are never negative, so clamp to 0.
259 else if (result > maxValue)
262 // Ensure the result length is the same as the original hex value.
263 var resultString = result.toString(16).toUpperCase();
264 for (var i = 0, lengthDelta = hexString.length - resultString.length; i < lengthDelta; ++i)
265 resultString = "0" + resultString;
270 * @param {number} number
271 * @param {!Event} event
273 WebInspector._modifiedFloatNumber = function(number, event)
275 var direction = WebInspector._valueModificationDirection(event);
279 var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyIdentifier === "Down" || event.type === "mousewheel");
281 // Jump by 10 when shift is down or jump by 0.1 when Alt/Option is down.
282 // Also jump by 10 for page up and down, or by 100 if shift is held with a page key.
283 var changeAmount = 1;
284 if (event.shiftKey && !arrowKeyOrMouseWheelEvent)
286 else if (event.shiftKey || !arrowKeyOrMouseWheelEvent)
288 else if (event.altKey)
291 if (direction === "Down")
294 // Make the new number and constrain it to a precision of 6, this matches numbers the engine returns.
295 // Use the Number constructor to forget the fixed precision, so 1.100000 will print as 1.1.
296 var result = Number((number + changeAmount).toFixed(6));
297 if (!String(result).match(WebInspector.CSSNumberRegex))
304 * @param {?Event} event
305 * @param {!Element} element
306 * @param {function(string,string)=} finishHandler
307 * @param {function(string)=} suggestionHandler
308 * @param {function(number):number=} customNumberHandler
311 WebInspector.handleElementValueModifications = function(event, element, finishHandler, suggestionHandler, customNumberHandler)
313 var arrowKeyOrMouseWheelEvent = (event.keyIdentifier === "Up" || event.keyIdentifier === "Down" || event.type === "mousewheel");
314 var pageKeyPressed = (event.keyIdentifier === "PageUp" || event.keyIdentifier === "PageDown");
315 if (!arrowKeyOrMouseWheelEvent && !pageKeyPressed)
318 var selection = window.getSelection();
319 if (!selection.rangeCount)
322 var selectionRange = selection.getRangeAt(0);
323 if (!selectionRange.commonAncestorContainer.isSelfOrDescendant(element))
326 var originalValue = element.textContent;
327 var wordRange = selectionRange.startContainer.rangeOfWord(selectionRange.startOffset, WebInspector.StyleValueDelimiters, element);
328 var wordString = wordRange.toString();
330 if (suggestionHandler && suggestionHandler(wordString))
333 var replacementString;
334 var prefix, suffix, number;
337 matches = /(.*#)([\da-fA-F]+)(.*)/.exec(wordString);
338 if (matches && matches.length) {
341 number = WebInspector._modifiedHexValue(matches[2], event);
343 if (customNumberHandler)
344 number = customNumberHandler(number);
346 replacementString = prefix + number + suffix;
348 matches = /(.*?)(-?(?:\d+(?:\.\d+)?|\.\d+))(.*)/.exec(wordString);
349 if (matches && matches.length) {
352 number = WebInspector._modifiedFloatNumber(parseFloat(matches[2]), event);
354 // Need to check for null explicitly.
358 if (customNumberHandler)
359 number = customNumberHandler(number);
361 replacementString = prefix + number + suffix;
365 if (replacementString) {
366 var replacementTextNode = document.createTextNode(replacementString);
368 wordRange.deleteContents();
369 wordRange.insertNode(replacementTextNode);
371 var finalSelectionRange = document.createRange();
372 finalSelectionRange.setStart(replacementTextNode, 0);
373 finalSelectionRange.setEnd(replacementTextNode, replacementString.length);
375 selection.removeAllRanges();
376 selection.addRange(finalSelectionRange);
378 event.handled = true;
379 event.preventDefault();
382 finishHandler(originalValue, replacementString);
391 * @param {number=} precision
394 Number.preciseMillisToString = function(ms, precision)
396 precision = precision || 0;
397 var format = "%." + precision + "f\u2009ms";
398 return WebInspector.UIString(format, ms);
403 * @param {boolean=} higherResolution
406 Number.millisToString = function(ms, higherResolution)
414 if (higherResolution && ms < 1000)
415 return WebInspector.UIString("%.3f\u2009ms", ms);
417 return WebInspector.UIString("%.0f\u2009ms", ms);
419 var seconds = ms / 1000;
421 return WebInspector.UIString("%.2f\u2009s", seconds);
423 var minutes = seconds / 60;
425 return WebInspector.UIString("%.1f\u2009min", minutes);
427 var hours = minutes / 60;
429 return WebInspector.UIString("%.1f\u2009hrs", hours);
431 var days = hours / 24;
432 return WebInspector.UIString("%.1f\u2009days", days);
436 * @param {number} seconds
437 * @param {boolean=} higherResolution
440 Number.secondsToString = function(seconds, higherResolution)
442 if (!isFinite(seconds))
444 return Number.millisToString(seconds * 1000, higherResolution);
448 * @param {number} bytes
451 Number.bytesToString = function(bytes)
454 return WebInspector.UIString("%.0f\u2009B", bytes);
456 var kilobytes = bytes / 1024;
458 return WebInspector.UIString("%.1f\u2009KB", kilobytes);
459 if (kilobytes < 1024)
460 return WebInspector.UIString("%.0f\u2009KB", kilobytes);
462 var megabytes = kilobytes / 1024;
464 return WebInspector.UIString("%.1f\u2009MB", megabytes);
466 return WebInspector.UIString("%.0f\u2009MB", megabytes);
469 Number.withThousandsSeparator = function(num)
472 var re = /(\d+)(\d{3})/;
473 while (str.match(re))
474 str = str.replace(re, "$1\u2009$2"); // \u2009 is a thin space.
478 WebInspector.useLowerCaseMenuTitles = function()
480 return WebInspector.platform() === "windows";
483 WebInspector.formatLocalized = function(format, substitutions, formatters, initialValue, append)
485 return String.format(WebInspector.UIString(format), substitutions, formatters, initialValue, append);
488 WebInspector.openLinkExternallyLabel = function()
490 return WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Open link in new tab" : "Open Link in New Tab");
493 WebInspector.copyLinkAddressLabel = function()
495 return WebInspector.UIString(WebInspector.useLowerCaseMenuTitles() ? "Copy link address" : "Copy Link Address");
498 WebInspector.installPortStyles = function()
500 var platform = WebInspector.platform();
501 document.body.classList.add("platform-" + platform);
502 var flavor = WebInspector.platformFlavor();
504 document.body.classList.add("platform-" + flavor);
505 var port = WebInspector.port();
506 document.body.classList.add("port-" + port);
509 WebInspector._windowFocused = function(event)
511 if (event.target.document.nodeType === Node.DOCUMENT_NODE)
512 document.body.classList.remove("inactive");
515 WebInspector._windowBlurred = function(event)
517 if (event.target.document.nodeType === Node.DOCUMENT_NODE)
518 document.body.classList.add("inactive");
521 WebInspector.previousFocusElement = function()
523 return WebInspector._previousFocusElement;
526 WebInspector.currentFocusElement = function()
528 return WebInspector._currentFocusElement;
531 WebInspector._focusChanged = function(event)
533 WebInspector.setCurrentFocusElement(event.target);
536 WebInspector._documentBlurred = function(event)
538 // We want to know when currentFocusElement loses focus to nowhere.
539 // This is the case when event.relatedTarget is null (no element is being focused)
540 // and document.activeElement is reset to default (this is not a window blur).
541 if (!event.relatedTarget && document.activeElement === document.body)
542 WebInspector.setCurrentFocusElement(null);
545 WebInspector._textInputTypes = ["text", "search", "tel", "url", "email", "password"].keySet();
546 WebInspector._isTextEditingElement = function(element)
548 if (element instanceof HTMLInputElement)
549 return element.type in WebInspector._textInputTypes;
551 if (element instanceof HTMLTextAreaElement)
557 WebInspector.setCurrentFocusElement = function(x)
559 if (WebInspector._glassPane && x && !WebInspector._glassPane.element.isAncestor(x))
561 if (WebInspector._currentFocusElement !== x)
562 WebInspector._previousFocusElement = WebInspector._currentFocusElement;
563 WebInspector._currentFocusElement = x;
565 if (WebInspector._currentFocusElement) {
566 WebInspector._currentFocusElement.focus();
568 // Make a caret selection inside the new element if there isn't a range selection and there isn't already a caret selection inside.
569 // This is needed (at least) to remove caret from console when focus is moved to some element in the panel.
570 // The code below should not be applied to text fields and text areas, hence _isTextEditingElement check.
571 var selection = window.getSelection();
572 if (!WebInspector._isTextEditingElement(WebInspector._currentFocusElement) && selection.isCollapsed && !WebInspector._currentFocusElement.isInsertionCaretInside()) {
573 var selectionRange = WebInspector._currentFocusElement.ownerDocument.createRange();
574 selectionRange.setStart(WebInspector._currentFocusElement, 0);
575 selectionRange.setEnd(WebInspector._currentFocusElement, 0);
577 selection.removeAllRanges();
578 selection.addRange(selectionRange);
580 } else if (WebInspector._previousFocusElement)
581 WebInspector._previousFocusElement.blur();
584 WebInspector.restoreFocusFromElement = function(element)
586 if (element && element.isSelfOrAncestor(WebInspector.currentFocusElement()))
587 WebInspector.setCurrentFocusElement(WebInspector.previousFocusElement());
590 WebInspector.setToolbarColors = function(backgroundColor, color)
592 if (!WebInspector._themeStyleElement) {
593 WebInspector._themeStyleElement = document.createElement("style");
594 document.head.appendChild(WebInspector._themeStyleElement);
596 var parsedColor = WebInspector.Color.parse(color);
597 var shadowColor = parsedColor ? parsedColor.invert().setAlpha(0.33).toString(WebInspector.Color.Format.RGBA) : "white";
598 var prefix = WebInspector.isMac() ? "body:not(.undocked)" : "";
599 WebInspector._themeStyleElement.textContent =
601 "%s .toolbar-background {\
602 background-image: none !important;\
603 background-color: %s !important;\
604 color: %s !important;\
605 }", prefix, backgroundColor, color) +
607 "%s .toolbar-background button.status-bar-item .glyph, %s .toolbar-background button.status-bar-item .long-click-glyph {\
608 background-color: %s;\
609 }", prefix, prefix, color) +
611 "%s .toolbar-background button.status-bar-item .glyph.shadow, %s .toolbar-background button.status-bar-item .long-click-glyph.shadow {\
612 background-color: %s;\
613 }", prefix, prefix, shadowColor);
616 WebInspector.resetToolbarColors = function()
618 if (WebInspector._themeStyleElement)
619 WebInspector._themeStyleElement.textContent = "";
623 * @param {!Element} element
624 * @param {number} offset
625 * @param {number} length
626 * @param {!Array.<!Object>=} domChanges
628 WebInspector.highlightSearchResult = function(element, offset, length, domChanges)
630 var result = WebInspector.highlightSearchResults(element, [new WebInspector.SourceRange(offset, length)], domChanges);
631 return result.length ? result[0] : null;
635 * @param {!Element} element
636 * @param {!Array.<!WebInspector.SourceRange>} resultRanges
637 * @param {!Array.<!Object>=} changes
639 WebInspector.highlightSearchResults = function(element, resultRanges, changes)
641 return WebInspector.highlightRangesWithStyleClass(element, resultRanges, "highlighted-search-result", changes);
645 * @param {!Element} element
646 * @param {string} className
648 WebInspector.runCSSAnimationOnce = function(element, className)
650 function animationEndCallback()
652 element.classList.remove(className);
653 element.removeEventListener("animationend", animationEndCallback, false);
656 if (element.classList.contains(className))
657 element.classList.remove(className);
659 element.addEventListener("animationend", animationEndCallback, false);
660 element.classList.add(className);
664 * @param {!Element} element
665 * @param {!Array.<!WebInspector.SourceRange>} resultRanges
666 * @param {string} styleClass
667 * @param {!Array.<!Object>=} changes
668 * @return {!Array.<!Element>}
670 WebInspector.highlightRangesWithStyleClass = function(element, resultRanges, styleClass, changes)
672 changes = changes || [];
673 var highlightNodes = [];
674 var lineText = element.textContent;
675 var ownerDocument = element.ownerDocument;
676 var textNodeSnapshot = ownerDocument.evaluate(".//text()", element, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
678 var snapshotLength = textNodeSnapshot.snapshotLength;
679 if (snapshotLength === 0)
680 return highlightNodes;
683 var rangeEndOffset = 0;
684 for (var i = 0; i < snapshotLength; ++i) {
686 range.offset = rangeEndOffset;
687 range.length = textNodeSnapshot.snapshotItem(i).textContent.length;
688 rangeEndOffset = range.offset + range.length;
689 nodeRanges.push(range);
693 for (var i = 0; i < resultRanges.length; ++i) {
694 var startOffset = resultRanges[i].offset;
695 var endOffset = startOffset + resultRanges[i].length;
697 while (startIndex < snapshotLength && nodeRanges[startIndex].offset + nodeRanges[startIndex].length <= startOffset)
699 var endIndex = startIndex;
700 while (endIndex < snapshotLength && nodeRanges[endIndex].offset + nodeRanges[endIndex].length < endOffset)
702 if (endIndex === snapshotLength)
705 var highlightNode = ownerDocument.createElement("span");
706 highlightNode.className = styleClass;
707 highlightNode.textContent = lineText.substring(startOffset, endOffset);
709 var lastTextNode = textNodeSnapshot.snapshotItem(endIndex);
710 var lastText = lastTextNode.textContent;
711 lastTextNode.textContent = lastText.substring(endOffset - nodeRanges[endIndex].offset);
712 changes.push({ node: lastTextNode, type: "changed", oldText: lastText, newText: lastTextNode.textContent });
714 if (startIndex === endIndex) {
715 lastTextNode.parentElement.insertBefore(highlightNode, lastTextNode);
716 changes.push({ node: highlightNode, type: "added", nextSibling: lastTextNode, parent: lastTextNode.parentElement });
717 highlightNodes.push(highlightNode);
719 var prefixNode = ownerDocument.createTextNode(lastText.substring(0, startOffset - nodeRanges[startIndex].offset));
720 lastTextNode.parentElement.insertBefore(prefixNode, highlightNode);
721 changes.push({ node: prefixNode, type: "added", nextSibling: highlightNode, parent: lastTextNode.parentElement });
723 var firstTextNode = textNodeSnapshot.snapshotItem(startIndex);
724 var firstText = firstTextNode.textContent;
725 var anchorElement = firstTextNode.nextSibling;
727 firstTextNode.parentElement.insertBefore(highlightNode, anchorElement);
728 changes.push({ node: highlightNode, type: "added", nextSibling: anchorElement, parent: firstTextNode.parentElement });
729 highlightNodes.push(highlightNode);
731 firstTextNode.textContent = firstText.substring(0, startOffset - nodeRanges[startIndex].offset);
732 changes.push({ node: firstTextNode, type: "changed", oldText: firstText, newText: firstTextNode.textContent });
734 for (var j = startIndex + 1; j < endIndex; j++) {
735 var textNode = textNodeSnapshot.snapshotItem(j);
736 var text = textNode.textContent;
737 textNode.textContent = "";
738 changes.push({ node: textNode, type: "changed", oldText: text, newText: textNode.textContent });
741 startIndex = endIndex;
742 nodeRanges[startIndex].offset = endOffset;
743 nodeRanges[startIndex].length = lastTextNode.textContent.length;
746 return highlightNodes;
749 WebInspector.applyDomChanges = function(domChanges)
751 for (var i = 0, size = domChanges.length; i < size; ++i) {
752 var entry = domChanges[i];
753 switch (entry.type) {
755 entry.parent.insertBefore(entry.node, entry.nextSibling);
758 entry.node.textContent = entry.newText;
764 WebInspector.revertDomChanges = function(domChanges)
766 for (var i = domChanges.length - 1; i >= 0; --i) {
767 var entry = domChanges[i];
768 switch (entry.type) {
773 entry.node.textContent = entry.oldText;
781 * @param {boolean} autoInvoke
783 WebInspector.InvokeOnceHandlers = function(autoInvoke)
785 this._handlers = null;
786 this._autoInvoke = autoInvoke;
789 WebInspector.InvokeOnceHandlers.prototype = {
791 * @param {!Object} object
792 * @param {function()} method
794 add: function(object, method)
796 if (!this._handlers) {
797 this._handlers = new Map();
798 if (this._autoInvoke)
799 this.scheduleInvoke();
801 var methods = this._handlers.get(object);
804 this._handlers.put(object, methods);
809 scheduleInvoke: function()
812 requestAnimationFrame(this._invoke.bind(this));
817 var handlers = this._handlers;
818 this._handlers = null;
819 var keys = handlers.keys();
820 for (var i = 0; i < keys.length; ++i) {
821 var object = keys[i];
822 var methods = handlers.get(object).items();
823 for (var j = 0; j < methods.length; ++j)
824 methods[j].call(object);
829 WebInspector._coalescingLevel = 0;
830 WebInspector._postUpdateHandlers = null;
832 WebInspector.startBatchUpdate = function()
834 if (!WebInspector._coalescingLevel++)
835 WebInspector._postUpdateHandlers = new WebInspector.InvokeOnceHandlers(false);
838 WebInspector.endBatchUpdate = function()
840 if (--WebInspector._coalescingLevel)
842 WebInspector._postUpdateHandlers.scheduleInvoke();
843 WebInspector._postUpdateHandlers = null;
847 * @param {!Object} object
848 * @param {function()} method
850 WebInspector.invokeOnceAfterBatchUpdate = function(object, method)
852 if (!WebInspector._postUpdateHandlers)
853 WebInspector._postUpdateHandlers = new WebInspector.InvokeOnceHandlers(true);
854 WebInspector._postUpdateHandlers.add(object, method);
859 function windowLoaded()
861 window.addEventListener("focus", WebInspector._windowFocused, false);
862 window.addEventListener("blur", WebInspector._windowBlurred, false);
863 document.addEventListener("focus", WebInspector._focusChanged, true);
864 document.addEventListener("blur", WebInspector._documentBlurred, true);
865 window.removeEventListener("DOMContentLoaded", windowLoaded, false);
868 window.addEventListener("DOMContentLoaded", windowLoaded, false);