Changeset 93584 in webkit


Ignore:
Timestamp:
Aug 23, 2011 2:23:31 AM (13 years ago)
Author:
pfeldman@chromium.org
Message:

Web Inspector: Prepare utilities.js for compilation.
https://bugs.webkit.org/show_bug.cgi?id=66656

Removes "this" usage in functions, does not define getters for offsets.

Reviewed by Tony Gentilcore.

  • inspector/front-end/ConsoleView.js:

(WebInspector.ConsoleMessage.prototype._format):
(WebInspector.ConsoleMessage.prototype._formatWithSubstitutionString.valueFormatter):

  • inspector/front-end/DOMAgent.js:

(WebInspector.DOMNode.prototype.appropriateSelectorFor):
(WebInspector.DOMNode.prototype.isAncestor):
(WebInspector.DOMNode.prototype.isDescendant):
(WebInspector.DOMNode.prototype.isWhitespace):

  • inspector/front-end/DataGrid.js:

(WebInspector.DataGrid.prototype._resizerDragging):
(WebInspector.DataGridNode.prototype.isEventWithinDisclosureTriangle):

  • inspector/front-end/Drawer.js:

(WebInspector.Drawer.prototype.get savedHeight):
(WebInspector.Drawer.prototype.onResize):
(WebInspector.Drawer.prototype._startStatusBarDragging):
(WebInspector.Drawer.prototype._statusBarDragging):

  • inspector/front-end/ElementsPanel.js:

(WebInspector.ElementsPanel.prototype.updateModifiedNodes):
(WebInspector.ElementsPanel.prototype.updateBreadcrumb):
(WebInspector.ElementsPanel.prototype.updateBreadcrumbSizes.crumbsAreSmallerThanContainer):

  • inspector/front-end/ElementsTreeOutline.js:

(WebInspector.ElementsTreeOutline.prototype.findTreeElement):
(WebInspector.ElementsTreeOutline.prototype._treeElementFromEvent):
():

  • inspector/front-end/RemoteObject.js:

(WebInspector.RemoteObject):

  • inspector/front-end/ResourceTimingView.js:

(WebInspector.ResourceTimingView.createTimingTable):

  • inspector/front-end/ResourcesPanel.js:

(WebInspector.BaseStorageTreeElement.prototype.isEventWithinDisclosureTriangle):

  • inspector/front-end/ScriptsPanel.js:

(WebInspector.ScriptsPanel.prototype._startSidebarResizeDrag):

  • inspector/front-end/SoftContextMenu.js:

(.WebInspector.SoftContextMenu.prototype.show):

  • inspector/front-end/Toolbar.js:

(WebInspector.ToolbarDropdown.prototype.show):

  • inspector/front-end/WatchExpressionsSidebarPane.js:

(WebInspector.WatchExpressionsSection.prototype._updateHoveredElement):

  • inspector/front-end/inspector.js:

(Number.secondsToString):
(Number.bytesToString):

  • inspector/front-end/treeoutline.js:

(TreeElement.prototype.isEventWithinDisclosureTriangle):

  • inspector/front-end/utilities.js:

(setupPrototypeUtilities.Element.prototype.totalOffsetLeft):
(setupPrototypeUtilities.Element.prototype.totalOffsetTop):
(setupPrototypeUtilities.Element.prototype.offsetRelativeToWindow):
(setupPrototypeUtilities):
(setupPrototypeUtilities.):
():

Location:
trunk/Source/WebCore
Files:
17 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r93580 r93584  
     12011-08-22  Pavel Feldman  <pfeldman@google.com>
     2
     3        Web Inspector: Prepare utilities.js for compilation.
     4        https://bugs.webkit.org/show_bug.cgi?id=66656
     5
     6        Removes "this" usage in functions, does not define getters for offsets.
     7
     8        Reviewed by Tony Gentilcore.
     9
     10        * inspector/front-end/ConsoleView.js:
     11        (WebInspector.ConsoleMessage.prototype._format):
     12        (WebInspector.ConsoleMessage.prototype._formatWithSubstitutionString.valueFormatter):
     13        * inspector/front-end/DOMAgent.js:
     14        (WebInspector.DOMNode.prototype.appropriateSelectorFor):
     15        (WebInspector.DOMNode.prototype.isAncestor):
     16        (WebInspector.DOMNode.prototype.isDescendant):
     17        (WebInspector.DOMNode.prototype.isWhitespace):
     18        * inspector/front-end/DataGrid.js:
     19        (WebInspector.DataGrid.prototype._resizerDragging):
     20        (WebInspector.DataGridNode.prototype.isEventWithinDisclosureTriangle):
     21        * inspector/front-end/Drawer.js:
     22        (WebInspector.Drawer.prototype.get savedHeight):
     23        (WebInspector.Drawer.prototype.onResize):
     24        (WebInspector.Drawer.prototype._startStatusBarDragging):
     25        (WebInspector.Drawer.prototype._statusBarDragging):
     26        * inspector/front-end/ElementsPanel.js:
     27        (WebInspector.ElementsPanel.prototype.updateModifiedNodes):
     28        (WebInspector.ElementsPanel.prototype.updateBreadcrumb):
     29        (WebInspector.ElementsPanel.prototype.updateBreadcrumbSizes.crumbsAreSmallerThanContainer):
     30        * inspector/front-end/ElementsTreeOutline.js:
     31        (WebInspector.ElementsTreeOutline.prototype.findTreeElement):
     32        (WebInspector.ElementsTreeOutline.prototype._treeElementFromEvent):
     33        ():
     34        * inspector/front-end/RemoteObject.js:
     35        (WebInspector.RemoteObject):
     36        * inspector/front-end/ResourceTimingView.js:
     37        (WebInspector.ResourceTimingView.createTimingTable):
     38        * inspector/front-end/ResourcesPanel.js:
     39        (WebInspector.BaseStorageTreeElement.prototype.isEventWithinDisclosureTriangle):
     40        * inspector/front-end/ScriptsPanel.js:
     41        (WebInspector.ScriptsPanel.prototype._startSidebarResizeDrag):
     42        * inspector/front-end/SoftContextMenu.js:
     43        (.WebInspector.SoftContextMenu.prototype.show):
     44        * inspector/front-end/Toolbar.js:
     45        (WebInspector.ToolbarDropdown.prototype.show):
     46        * inspector/front-end/WatchExpressionsSidebarPane.js:
     47        (WebInspector.WatchExpressionsSection.prototype._updateHoveredElement):
     48        * inspector/front-end/inspector.js:
     49        (Number.secondsToString):
     50        (Number.bytesToString):
     51        * inspector/front-end/treeoutline.js:
     52        (TreeElement.prototype.isEventWithinDisclosureTriangle):
     53        * inspector/front-end/utilities.js:
     54        (setupPrototypeUtilities.Element.prototype.totalOffsetLeft):
     55        (setupPrototypeUtilities.Element.prototype.totalOffsetTop):
     56        (setupPrototypeUtilities.Element.prototype.offsetRelativeToWindow):
     57        (setupPrototypeUtilities):
     58        (setupPrototypeUtilities.):
     59        ():
     60
    1612011-08-22  John Bates  <jbates@google.com>
    262
  • trunk/Source/WebCore/inspector/front-end/ConsoleView.js

    r93510 r93584  
    981981    {
    982982        var formatters = {}
    983         for (var i in String.standardFormatters)
    984             formatters[i] = String.standardFormatters[i];
    985983
    986984        function consoleFormatWrapper(force)
     
    991989        }
    992990
     991        function valueFormatter(obj)
     992        {
     993            return obj.description;
     994        }
     995
    993996        // Firebug uses %o for formatting objects.
    994997        formatters.o = consoleFormatWrapper();
     998        formatters.s = valueFormatter;
     999        formatters.f = valueFormatter;
    9951000        // Firebug allows both %i and %d for formatting integers.
    996         formatters.i = formatters.d;
     1001        formatters.i = valueFormatter;
     1002        formatters.d = valueFormatter;
     1003
    9971004        // Support %O to force object formatting, instead of the type-based %o formatting.
    9981005        formatters.O = consoleFormatWrapper(true);
  • trunk/Source/WebCore/inspector/front-end/DOMAgent.js

    r93510 r93584  
    217217    appropriateSelectorFor: function(justSelector)
    218218    {
    219         var lowerCaseName = this.localName() || node.nodeName().toLowerCase();
     219        var lowerCaseName = this.localName() || this.nodeName().toLowerCase();
    220220
    221221        var id = this.getAttribute("id");
     
    235235
    236236        return lowerCaseName;
     237    },
     238
     239    isAncestor: function(node)
     240    {
     241        if (!node)
     242            return false;
     243   
     244        var currentNode = node.parentNode;
     245        while (currentNode) {
     246            if (this === currentNode)
     247                return true;
     248            currentNode = currentNode.parentNode;
     249        }
     250        return false;
     251    },
     252
     253    isDescendant: function(descendant)
     254    {
     255        return descendant !== null && descendant.isAncestor(this);
     256    },
     257
     258    isWhitespace: function()
     259    {
     260        if (this.nodeType !== Node.TEXT_NODE)
     261            return false;
     262        if (!this.nodeValue.length)
     263            return true;
     264        return this.nodeValue.match(/^[\s\xA0]+$/);
    237265    },
    238266
  • trunk/Source/WebCore/inspector/front-end/DataGrid.js

    r92956 r93584  
    966966        // Constrain the dragpoint to be within the containing div of the
    967967        // datagrid.
    968         var dragPoint = event.clientX - this.element.totalOffsetLeft;
     968        var dragPoint = event.clientX - this.element.totalOffsetLeft();
    969969        // Constrain the dragpoint to be within the space made up by the
    970970        // column directly to the left and the column directly to the right.
     
    14461446            return false;
    14471447        var computedLeftPadding = window.getComputedStyle(cell).getPropertyCSSValue("padding-left").getFloatValue(CSSPrimitiveValue.CSS_PX);
    1448         var left = cell.totalOffsetLeft + computedLeftPadding;
     1448        var left = cell.totalOffsetLeft() + computedLeftPadding;
    14491449        return event.pageX >= left && event.pageX <= left + this.disclosureToggleWidth;
    14501450    },
  • trunk/Source/WebCore/inspector/front-end/Drawer.js

    r93196 r93584  
    7878    {
    7979        var height = this._savedHeight || this.element.offsetHeight;
    80         return Number.constrain(height, Preferences.minConsoleHeight, window.innerHeight - this._mainElement.totalOffsetTop - Preferences.minConsoleHeight);
     80        return Number.constrain(height, Preferences.minConsoleHeight, window.innerHeight - this._mainElement.totalOffsetTop() - Preferences.minConsoleHeight);
    8181    },
    8282
     
    207207        if (this.state === WebInspector.Drawer.State.Variable) {
    208208            height = parseInt(this.element.style.height);
    209             height = Number.constrain(height, Preferences.minConsoleHeight, window.innerHeight - this._mainElement.totalOffsetTop - Preferences.minConsoleHeight);
     209            height = Number.constrain(height, Preferences.minConsoleHeight, window.innerHeight - this._mainElement.totalOffsetTop() - Preferences.minConsoleHeight);
    210210        } else
    211211            height = window.innerHeight - this._toolbarElement.offsetHeight;
     
    332332        WebInspector.elementDragStart(this._mainStatusBar, this._statusBarDragging.bind(this), this._endStatusBarDragging.bind(this), event, "row-resize");
    333333
    334         this._statusBarDragOffset = event.pageY - this.element.totalOffsetTop;
     334        this._statusBarDragOffset = event.pageY - this.element.totalOffsetTop();
    335335
    336336        event.stopPropagation();
     
    340340    {
    341341        var height = window.innerHeight - event.pageY + this._statusBarDragOffset;
    342         height = Number.constrain(height, Preferences.minConsoleHeight, window.innerHeight - this._mainElement.totalOffsetTop - Preferences.minConsoleHeight);
     342        height = Number.constrain(height, Preferences.minConsoleHeight, window.innerHeight - this._mainElement.totalOffsetTop() - Preferences.minConsoleHeight);
    343343
    344344        this._mainElement.style.bottom = height + "px";
  • trunk/Source/WebCore/inspector/front-end/ElementsPanel.js

    r93196 r93584  
    480480            }
    481481
    482             if (!updateBreadcrumbs && (this.selectedDOMNode() === parent || isAncestorNode(this.selectedDOMNode(), parent)))
     482            if (!updateBreadcrumbs && (this.selectedDOMNode() === parent || (this.selectedDOMNode() && this.selectedDOMNode().isAncestor(parent))))
    483483                updateBreadcrumbs = true;
    484484        }
     
    622622
    623623                case Node.TEXT_NODE:
    624                     if (isNodeWhitespace.call(current))
     624                    if (current.isWhitespace())
    625625                        crumbTitle = WebInspector.UIString("(whitespace)");
    626626                    else
     
    784784            if (!WebInspector.drawer.visible && errorWarningElement)
    785785                rightPadding += errorWarningElement.offsetWidth;
    786             return ((crumbs.totalOffsetLeft + crumbs.offsetWidth + rightPadding) < window.innerWidth);
     786            return ((crumbs.totalOffsetLeft() + crumbs.offsetWidth + rightPadding) < window.innerWidth);
    787787        }
    788788
  • trunk/Source/WebCore/inspector/front-end/ElementsTreeOutline.js

    r93035 r93584  
    147147    findTreeElement: function(node)
    148148    {
     149        function isAncestorNode(ancestor, node)
     150        {
     151            return ancestor.isAncestor(node);
     152        }
    149153        var treeElement = TreeOutline.prototype.findTreeElement.call(this, node, isAncestorNode, parentNode);
    150154        if (!treeElement && node.nodeType() === Node.TEXT_NODE) {
     
    198202        // In the no-word-wrap mode the outer <ol> may be wider than the tree container
    199203        // (and partially hidden), in which case we are left to use only its right boundary.
    200         var x = scrollContainer.totalOffsetLeft + scrollContainer.offsetWidth - 36;
     204        var x = scrollContainer.totalOffsetLeft() + scrollContainer.offsetWidth - 36;
    201205
    202206        var y = event.pageY;
     
    14671471
    14681472            case Node.TEXT_NODE:
    1469                 if (isNodeWhitespace.call(node))
     1473                if (node.isWhitespace())
    14701474                    info.titleDOM.appendChild(document.createTextNode("(whitespace)"));
    14711475                else {
  • trunk/Source/WebCore/inspector/front-end/RemoteObject.js

    r93389 r93584  
    4343        this._description = description || (value + "");
    4444        this._hasChildren = false;
     45        this.value = value;
    4546    }
    4647}
  • trunk/Source/WebCore/inspector/front-end/ResourceTimingView.js

    r93196 r93584  
    149149        else
    150150            title.style.left = (scale * rows[i].start + 3) + "px";
    151         title.textContent = Number.millisToString(rows[i].end - rows[i].start);
     151        title.textContent = Number.secondsToString((rows[i].end - rows[i].start) / 1000);
    152152        row.appendChild(title);
    153153
  • trunk/Source/WebCore/inspector/front-end/ResourcesPanel.js

    r93196 r93584  
    973973        // icons in the tree.
    974974        const paddingLeft = 14;
    975         var left = this.listItemElement.totalOffsetLeft + paddingLeft;
     975        var left = this.listItemElement.totalOffsetLeft() + paddingLeft;
    976976        return event.pageX >= left && event.pageX <= left + this.arrowToggleWidth && this.hasChildren;
    977977    }
  • trunk/Source/WebCore/inspector/front-end/ScriptsPanel.js

    r93419 r93584  
    765765
    766766        if (event.target === this.sidebarResizeWidgetElement)
    767             this._dragOffset = (event.target.offsetWidth - (event.pageX - event.target.totalOffsetLeft));
     767            this._dragOffset = (event.target.offsetWidth - (event.pageX - event.target.totalOffsetLeft()));
    768768        else
    769769            this._dragOffset = 0;
  • trunk/Source/WebCore/inspector/front-end/SoftContextMenu.js

    r93034 r93584  
    4444        while (targetElement && window !== targetElement.ownerDocument.defaultView) {
    4545            var frameElement = targetElement.ownerDocument.defaultView.frameElement;
    46             absoluteY += frameElement.totalOffsetTop;
    47             absoluteX += frameElement.totalOffsetLeft;
     46            absoluteY += frameElement.totalOffsetTop();
     47            absoluteX += frameElement.totalOffsetLeft();
    4848            targetElement = frameElement;
    4949        }
  • trunk/Source/WebCore/inspector/front-end/Toolbar.js

    r87894 r93584  
    188188        var style = this.element.style;
    189189        this._populate();
    190         var top = this._arrow.totalOffsetTop + this._arrow.clientHeight;
     190        var top = this._arrow.totalOffsetTop() + this._arrow.clientHeight;
    191191        this._arrow.addStyleClass("dropdown-visible");
    192192        this.element.style.top = top + "px";
    193         this.element.style.left = this._arrow.totalOffsetLeft + "px";
     193        this.element.style.left = this._arrow.totalOffsetLeft() + "px";
    194194        this._contentElement.style.maxHeight = window.innerHeight - top - 20 + "px";
    195195        this._toolbar.appendChild(this.element);
  • trunk/Source/WebCore/inspector/front-end/WatchExpressionsSidebarPane.js

    r92827 r93584  
    260260            while(next && !next.clientHeight)
    261261                next = next.nextSibling;
    262             if (!next || next.totalOffsetTop > pageY)
     262            if (!next || next.totalOffsetTop() > pageY)
    263263                break;
    264264            this._hoveredElement = next;
  • trunk/Source/WebCore/inspector/front-end/inspector.js

    r93510 r93584  
    17171717    }
    17181718}
     1719
     1720Number.secondsToString = function(seconds, higherResolution)
     1721{
     1722    if (seconds === 0)
     1723        return "0";
     1724
     1725    var ms = seconds * 1000;
     1726    if (higherResolution && ms < 1000)
     1727        return WebInspector.UIString("%.3fms", ms);
     1728    else if (ms < 1000)
     1729        return WebInspector.UIString("%.0fms", ms);
     1730
     1731    if (seconds < 60)
     1732        return WebInspector.UIString("%.2fs", seconds);
     1733
     1734    var minutes = seconds / 60;
     1735    if (minutes < 60)
     1736        return WebInspector.UIString("%.1fmin", minutes);
     1737
     1738    var hours = minutes / 60;
     1739    if (hours < 24)
     1740        return WebInspector.UIString("%.1fhrs", hours);
     1741
     1742    var days = hours / 24;
     1743    return WebInspector.UIString("%.1f days", days);
     1744}
     1745
     1746Number.bytesToString = function(bytes, higherResolution)
     1747{
     1748    if (typeof higherResolution === "undefined")
     1749        higherResolution = true;
     1750
     1751    if (bytes < 1024)
     1752        return WebInspector.UIString("%.0fB", bytes);
     1753
     1754    var kilobytes = bytes / 1024;
     1755    if (higherResolution && kilobytes < 1024)
     1756        return WebInspector.UIString("%.2fKB", kilobytes);
     1757    else if (kilobytes < 1024)
     1758        return WebInspector.UIString("%.0fKB", kilobytes);
     1759
     1760    var megabytes = kilobytes / 1024;
     1761    if (higherResolution)
     1762        return WebInspector.UIString("%.2fMB", megabytes);
     1763    else
     1764        return WebInspector.UIString("%.0fMB", megabytes);
     1765}
  • trunk/Source/WebCore/inspector/front-end/treeoutline.js

    r92956 r93584  
    2727 */
    2828
     29/**
     30 * @constructor
     31 */
    2932function TreeOutline(listNode)
    3033{
     34    /**
     35     * @type {Array.<TreeElement>}
     36     */
    3137    this.children = [];
    3238    this.selectedTreeElement = null;
     
    4854TreeOutline._knownTreeElementNextIdentifier = 1;
    4955
    50 TreeOutline._appendChild = function(child)
     56TreeOutline.prototype.appendChild = function(child)
    5157{
    5258    if (!child)
     
    8995}
    9096
    91 TreeOutline._insertChild = function(child, index)
     97TreeOutline.prototype.insertChild = function(child, index)
    9298{
    9399    if (!child)
     
    137143}
    138144
    139 TreeOutline._removeChildAtIndex = function(childIndex)
     145TreeOutline.prototype.removeChildAtIndex = function(childIndex)
    140146{
    141147    if (childIndex < 0 || childIndex >= this.children.length)
     
    172178}
    173179
    174 TreeOutline._removeChild = function(child)
     180TreeOutline.prototype.removeChild = function(child)
    175181{
    176182    if (!child)
     
    181187        throw("child not found in this node's children");
    182188
    183     TreeOutline._removeChildAtIndex.call(this, childIndex);
    184 }
    185 
    186 TreeOutline._removeChildren = function()
     189    this.removeChildAtIndex.call(this, childIndex);
     190}
     191
     192TreeOutline.prototype.removeChildren = function()
    187193{
    188194    for (var i = 0; i < this.children.length; ++i) {
     
    205211}
    206212
    207 TreeOutline._removeChildrenRecursive = function()
     213TreeOutline.prototype.removeChildrenRecursive = function()
    208214{
    209215    var childrenToRemove = this.children;
     
    217223
    218224    for (var i = 0; i < childrenToRemove.length; ++i) {
    219         var child = childrenToRemove[i];
     225        child = childrenToRemove[i];
    220226        child.deselect();
    221227        if (child.treeOutline)
     
    323329        // ancestor exists in the tree.
    324330        item = this.findTreeElement(ancestors[i], isAncestor, getParent);
    325         if (item && item.onpopulate)
    326             item.onpopulate(item);
     331        if (item)
     332            item.onpopulate();
    327333    }
    328334
     
    393399            }
    394400        }
    395     } else if (event.keyCode === WebInspector.KeyboardShortcut.Keys.Backspace.code || event.keyCode === WebInspector.KeyboardShortcut.Keys.Delete.code) {
     401    } else if (event.keyCode === 27 /* Esc */ || event.keyCode === 46 /* Delete */) {
    396402        if (this.selectedTreeElement.ondelete)
    397403            handled = this.selectedTreeElement.ondelete();
     
    442448}
    443449
    444 TreeOutline.prototype.appendChild = TreeOutline._appendChild;
    445 TreeOutline.prototype.insertChild = TreeOutline._insertChild;
    446 TreeOutline.prototype.removeChild = TreeOutline._removeChild;
    447 TreeOutline.prototype.removeChildAtIndex = TreeOutline._removeChildAtIndex;
    448 TreeOutline.prototype.removeChildren = TreeOutline._removeChildren;
    449 TreeOutline.prototype.removeChildrenRecursive = TreeOutline._removeChildrenRecursive;
    450 
     450/**
     451 * @constructor
     452 */
    451453function TreeElement(title, representedObject, hasChildren)
    452454{
     
    587589}
    588590
    589 TreeElement.prototype.appendChild = TreeOutline._appendChild;
    590 TreeElement.prototype.insertChild = TreeOutline._insertChild;
    591 TreeElement.prototype.removeChild = TreeOutline._removeChild;
    592 TreeElement.prototype.removeChildAtIndex = TreeOutline._removeChildAtIndex;
    593 TreeElement.prototype.removeChildren = TreeOutline._removeChildren;
    594 TreeElement.prototype.removeChildrenRecursive = TreeOutline._removeChildrenRecursive;
     591TreeElement.prototype.appendChild = TreeOutline.prototype.appendChild;
     592TreeElement.prototype.insertChild = TreeOutline.prototype.insertChild;
     593TreeElement.prototype.removeChild = TreeOutline.prototype.removeChild;
     594TreeElement.prototype.removeChildAtIndex = TreeOutline.prototype.removeChildAtIndex;
     595TreeElement.prototype.removeChildren = TreeOutline.prototype.removeChildren;
     596TreeElement.prototype.removeChildrenRecursive = TreeOutline.prototype.removeChildrenRecursive;
    595597
    596598TreeElement.prototype._attach = function()
     
    732734            this._childrenListNode.addStyleClass("hidden");
    733735
    734         if (this.onpopulate)
    735             this.onpopulate(this);
     736        this.onpopulate();
    736737
    737738        for (var i = 0; i < this.children.length; ++i)
     
    822823}
    823824
     825/**
     826 * @param {boolean=} omitFocus
     827 * @param {boolean=} selectedByUser
     828 */
    824829TreeElement.prototype.select = function(omitFocus, selectedByUser)
    825830{
     
    852857}
    853858
     859/**
     860 * @param {boolean=} supressOnDeselect
     861 */
    854862TreeElement.prototype.deselect = function(supressOnDeselect)
    855863{
     
    867875}
    868876
     877TreeElement.prototype.onpopulate = function()
     878{
     879    // Overriden by subclasses.
     880}
     881
    869882TreeElement.prototype.traverseNextTreeElement = function(skipHidden, stayWithin, dontPopulate, info)
    870883{
    871     if (!dontPopulate && this.hasChildren && this.onpopulate)
    872         this.onpopulate(this);
     884    if (!dontPopulate && this.hasChildren)
     885        this.onpopulate();
    873886
    874887    if (info)
     
    905918{
    906919    var element = skipHidden ? (this.revealed() ? this.previousSibling : null) : this.previousSibling;
    907     if (!dontPopulate && element && element.hasChildren && element.onpopulate)
    908         element.onpopulate(element);
     920    if (!dontPopulate && element && element.hasChildren)
     921        element.onpopulate();
    909922
    910923    while (element && (skipHidden ? (element.revealed() && element.expanded ? element.children[element.children.length - 1] : null) : element.children[element.children.length - 1])) {
    911         if (!dontPopulate && element.hasChildren && element.onpopulate)
    912             element.onpopulate(element);
     924        if (!dontPopulate && element.hasChildren)
     925            element.onpopulate();
    913926        element = (skipHidden ? (element.revealed() && element.expanded ? element.children[element.children.length - 1] : null) : element.children[element.children.length - 1]);
    914927    }
     
    925938TreeElement.prototype.isEventWithinDisclosureTriangle = function(event)
    926939{
    927     var left = this._listItemNode.totalOffsetLeft;
     940    var left = this._listItemNode.totalOffsetLeft();
    928941    return event.pageX >= left && event.pageX <= left + this.arrowToggleWidth && this.hasChildren;
    929942}
  • trunk/Source/WebCore/inspector/front-end/utilities.js

    r91359 r93584  
    262262DocumentFragment.prototype.createChild = Element.prototype.createChild;
    263263
    264 Element.prototype.__defineGetter__("totalOffsetLeft", function()
     264Element.prototype.totalOffsetLeft = function()
    265265{
    266266    var total = 0;
     
    268268        total += element.offsetLeft + (this !== element ? element.clientLeft : 0);
    269269    return total;
    270 });
    271 
    272 Element.prototype.__defineGetter__("totalOffsetTop", function()
     270}
     271
     272Element.prototype.totalOffsetTop = function()
    273273{
    274274    var total = 0;
     
    276276        total += element.offsetTop + (this !== element ? element.clientTop : 0);
    277277    return total;
    278 });
     278}
    279279
    280280Element.prototype.offsetRelativeToWindow = function(targetWindow)
     
    284284    var curWindow = this.ownerDocument.defaultView;
    285285    while (curWindow && curElement) {
    286         elementOffset.x += curElement.totalOffsetLeft;
    287         elementOffset.y += curElement.totalOffsetTop;
     286        elementOffset.x += curElement.totalOffsetLeft();
     287        elementOffset.y += curElement.totalOffsetTop();
    288288        if (curWindow === targetWindow)
    289289            break;
     
    469469}
    470470
    471 window.isNodeWhitespace = function()
    472 {
    473     if (!this || this.nodeType !== Node.TEXT_NODE)
    474         return false;
    475     if (!this.nodeValue.length)
    476         return true;
    477     return this.nodeValue.match(/^[\s\xA0]+$/);
    478 }
    479 
    480 function nodeDisplayName()
    481 {
    482     if (!this)
    483         return "";
    484 
    485     switch (this.nodeType) {
    486         case Node.DOCUMENT_NODE:
    487             return "Document";
    488 
    489         case Node.ELEMENT_NODE:
    490             var name = "<" + this.nodeName.toLowerCase();
    491 
    492             if (this.hasAttributes()) {
    493                 var value = this.getAttribute("id");
    494                 if (value)
    495                     name += " id=\"" + value + "\"";
    496                 value = this.getAttribute("class");
    497                 if (value)
    498                     name += " class=\"" + value + "\"";
    499                 if (this.nodeName.toLowerCase() === "a") {
    500                     value = this.getAttribute("name");
    501                     if (value)
    502                         name += " name=\"" + value + "\"";
    503                     value = this.getAttribute("href");
    504                     if (value)
    505                         name += " href=\"" + value + "\"";
    506                 } else if (this.nodeName.toLowerCase() === "img") {
    507                     value = this.getAttribute("src");
    508                     if (value)
    509                         name += " src=\"" + value + "\"";
    510                 } else if (this.nodeName.toLowerCase() === "iframe") {
    511                     value = this.getAttribute("src");
    512                     if (value)
    513                         name += " src=\"" + value + "\"";
    514                 } else if (this.nodeName.toLowerCase() === "input") {
    515                     value = this.getAttribute("name");
    516                     if (value)
    517                         name += " name=\"" + value + "\"";
    518                     value = this.getAttribute("type");
    519                     if (value)
    520                         name += " type=\"" + value + "\"";
    521                 } else if (this.nodeName.toLowerCase() === "form") {
    522                     value = this.getAttribute("action");
    523                     if (value)
    524                         name += " action=\"" + value + "\"";
    525                 }
    526             }
    527 
    528             return name + ">";
    529 
    530         case Node.TEXT_NODE:
    531             if (isNodeWhitespace.call(this))
    532                 return "(whitespace)";
    533             return "\"" + this.nodeValue + "\"";
    534 
    535         case Node.COMMENT_NODE:
    536             return "<!--" + this.nodeValue + "-->";
    537            
    538         case Node.DOCUMENT_TYPE_NODE:
    539             var docType = "<!DOCTYPE " + this.nodeName;
    540             if (this.publicId) {
    541                 docType += " PUBLIC \"" + this.publicId + "\"";
    542                 if (this.systemId)
    543                     docType += " \"" + this.systemId + "\"";
    544             } else if (this.systemId)
    545                 docType += " SYSTEM \"" + this.systemId + "\"";
    546             if (this.internalSubset)
    547                 docType += " [" + this.internalSubset + "]";
    548             return docType + ">";
    549     }
    550 
    551     return this.nodeName.toLowerCase().collapseWhitespace();
    552 }
    553 
    554 window.isAncestorNode = function(ancestor, node)
    555 {
    556     if (!node || !ancestor)
     471Node.prototype.isAncestor = function(node)
     472{
     473    if (!node)
    557474        return false;
    558475
    559476    var currentNode = node.parentNode;
    560477    while (currentNode) {
    561         if (ancestor === currentNode)
     478        if (this === currentNode)
    562479            return true;
    563480        currentNode = currentNode.parentNode;
     
    566483}
    567484
    568 window.isDescendantNode = function(descendant)
    569 {
    570     return isAncestorNode(descendant, this);
    571 }
    572 
    573 function traverseNextNode(stayWithin)
    574 {
    575     if (!this)
    576         return;
    577 
     485Node.prototype.isDescendant = function(descendant)
     486{
     487    return !!descendant && descendant.isAncestor(this);
     488}
     489
     490Node.prototype.traverseNextNode = function(stayWithin)
     491{
    578492    var node = this.firstChild;
    579493    if (node)
     
    596510}
    597511
    598 function traversePreviousNode(stayWithin)
    599 {
    600     if (!this)
    601         return;
     512Node.prototype.traversePreviousNode = function(stayWithin)
     513{
    602514    if (stayWithin && this === stayWithin)
    603515        return null;
     
    613525{
    614526    return node.parentNode;
    615 }
    616 
    617 Node.prototype.isWhitespace = isNodeWhitespace;
    618 Node.prototype.displayName = nodeDisplayName;
    619 Node.prototype.isAncestor = function(node)
    620 {
    621     return isAncestorNode(this, node);
    622 };
    623 Node.prototype.isDescendant = isDescendantNode;
    624 Node.prototype.traverseNextNode = traverseNextNode;
    625 Node.prototype.traversePreviousNode = traversePreviousNode;
    626 
    627 Number.millisToString = function(ms, higherResolution)
    628 {
    629     return Number.secondsToString(ms / 1000, higherResolution);
    630 }
    631 
    632 Number.secondsToString = function(seconds, higherResolution)
    633 {
    634     if (seconds === 0)
    635         return "0";
    636 
    637     var ms = seconds * 1000;
    638     if (higherResolution && ms < 1000)
    639         return WebInspector.UIString("%.3fms", ms);
    640     else if (ms < 1000)
    641         return WebInspector.UIString("%.0fms", ms);
    642 
    643     if (seconds < 60)
    644         return WebInspector.UIString("%.2fs", seconds);
    645 
    646     var minutes = seconds / 60;
    647     if (minutes < 60)
    648         return WebInspector.UIString("%.1fmin", minutes);
    649 
    650     var hours = minutes / 60;
    651     if (hours < 24)
    652         return WebInspector.UIString("%.1fhrs", hours);
    653 
    654     var days = hours / 24;
    655     return WebInspector.UIString("%.1f days", days);
    656 }
    657 
    658 Number.bytesToString = function(bytes, higherResolution)
    659 {
    660     if (typeof higherResolution === "undefined")
    661         higherResolution = true;
    662 
    663     if (bytes < 1024)
    664         return WebInspector.UIString("%.0fB", bytes);
    665 
    666     var kilobytes = bytes / 1024;
    667     if (higherResolution && kilobytes < 1024)
    668         return WebInspector.UIString("%.2fKB", kilobytes);
    669     else if (kilobytes < 1024)
    670         return WebInspector.UIString("%.0fKB", kilobytes);
    671 
    672     var megabytes = kilobytes / 1024;
    673     if (higherResolution)
    674         return WebInspector.UIString("%.2fMB", megabytes);
    675     else
    676         return WebInspector.UIString("%.0fMB", megabytes);
    677527}
    678528
     
    709559}
    710560
    711 Object.defineProperty(Array.prototype, "remove", { value: function(value, onlyFirst)
    712 {
    713     if (onlyFirst) {
    714         var index = this.indexOf(value);
    715         if (index !== -1)
    716             this.splice(index, 1);
    717         return;
    718     }
    719 
    720     var length = this.length;
    721     for (var i = 0; i < length; ++i) {
    722         if (this[i] === value)
    723             this.splice(i, 1);
    724     }
    725 }});
    726 
    727 Object.defineProperty(Array.prototype, "keySet", { value: function()
    728 {
    729     var keys = {};
    730     for (var i = 0; i < this.length; ++i)
    731         keys[this[i]] = true;
    732     return keys;
    733 }});
    734 
    735 Object.defineProperty(Array.prototype, "upperBound", { value: function(value)
    736 {
    737     var first = 0;
    738     var count = this.length;
    739     while (count > 0) {
    740       var step = count >> 1;
    741       var middle = first + step;
    742       if (value >= this[middle]) {
    743           first = middle + 1;
    744           count -= step + 1;
    745       } else
    746           count = step;
    747     }
    748     return first;
    749 }});
     561Object.defineProperty(Array.prototype, "remove",
     562{
     563    /**
     564     * @this {Array.<*>}
     565     */
     566    value: function(value, onlyFirst)
     567    {
     568        if (onlyFirst) {
     569            var index = this.indexOf(value);
     570            if (index !== -1)
     571                this.splice(index, 1);
     572            return;
     573        }
     574   
     575        var length = this.length;
     576        for (var i = 0; i < length; ++i) {
     577            if (this[i] === value)
     578                this.splice(i, 1);
     579        }
     580    }
     581});
     582
     583Object.defineProperty(Array.prototype, "keySet",
     584{
     585    /**
     586     * @this {Array.<*>}
     587     */
     588    value: function()
     589    {
     590        var keys = {};
     591        for (var i = 0; i < this.length; ++i)
     592            keys[this[i]] = true;
     593        return keys;
     594    }
     595});
     596
     597Object.defineProperty(Array.prototype, "upperBound",
     598{
     599    /**
     600     * @this {Array.<number>}
     601     */
     602    value: function(value)
     603    {
     604        var first = 0;
     605        var count = this.length;
     606        while (count > 0) {
     607          var step = count >> 1;
     608          var middle = first + step;
     609          if (value >= this[middle]) {
     610              first = middle + 1;
     611              count -= step + 1;
     612          } else
     613              count = step;
     614        }
     615        return first;
     616    }
     617});
    750618
    751619Array.diff = function(left, right)
     
    833701        if (!isNaN(format[index])) {
    834702            // The first character is a number, it might be a substitution index.
    835             var number = parseInt(format.substring(index));
     703            var number = parseInt(format.substring(index), 10);
    836704            while (!isNaN(format[index]))
    837705                ++index;
     
    849717            // then the precision should be zero.
    850718            ++index;
    851             precision = parseInt(format.substring(index));
     719            precision = parseInt(format.substring(index), 10);
    852720            if (isNaN(precision))
    853721                precision = 0;
     
    870738    d: function(substitution)
    871739    {
    872         if (typeof substitution == "object" && WebInspector.RemoteObject.type(substitution) === "number")
    873             substitution = substitution.description;
    874         substitution = parseInt(substitution);
    875740        return !isNaN(substitution) ? substitution : 0;
    876741    },
     
    878743    f: function(substitution, token)
    879744    {
    880         if (typeof substitution == "object" && WebInspector.RemoteObject.type(substitution) === "number")
    881             substitution = substitution.description;
    882         substitution = parseFloat(substitution);
    883745        if (substitution && token.precision > -1)
    884746            substitution = substitution.toFixed(token.precision);
     
    888750    s: function(substitution)
    889751    {
    890         if (typeof substitution == "object" && WebInspector.RemoteObject.type(substitution) !== "null")
    891             substitution = substitution.description;
    892752        return substitution;
    893     },
    894 };
     753    }
     754}
    895755
    896756String.vsprintf = function(format, substitutions)
     
    1049909            textNode = textNodeSnapshot.snapshotItem(currentSnapshotItem++);
    1050910            snapshotNodeOffset += textNode.nodeValue.length;
    1051             var text = textNode.textContent;
     911            text = textNode.textContent;
    1052912            if (length < text.length) {
    1053913                textNode.textContent = text.substring(length);
     
    1103963{
    1104964    // This should be kept the same as the one in InspectorPageAgent.cpp.
    1105     regexSpecialCharacters = "[](){}+-*.,?\\^$|";
     965    var regexSpecialCharacters = "[](){}+-*.,?\\^$|";
    1106966    var regex = "";
    1107967    for (var i = 0; i < query.length; ++i) {
    1108         var char = query.charAt(i);
    1109         if (regexSpecialCharacters.indexOf(char) != -1)
     968        var c = query.charAt(i);
     969        if (regexSpecialCharacters.indexOf(c) != -1)
    1110970            regex += "\\";
    1111         regex += char;
     971        regex += c;
    1112972    }
    1113973    return new RegExp(regex, "i" + (extraFlags || ""));
Note: See TracChangeset for help on using the changeset viewer.