⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 136163 in webkit


Ignore:
Timestamp:
Nov 29, 2012, 2:16:19 PM (14 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: Allow sorting in NMI snapshot grid view
​https://bugs.webkit.org/show_bug.cgi?id=102955

Patch by Alexei Filippov <​alph@chromium.org> on 2012-11-29
Reviewed by Yury Semikhatsky.

  • English.lproj/localizedStrings.js:
  • inspector/front-end/NativeMemorySnapshotView.js:

(WebInspector.NativeSnapshotDataGrid.prototype.sortingChanged):
(WebInspector.NativeSnapshotDataGrid.prototype._sortingFunction):
(WebInspector.NativeSnapshotNode):
(WebInspector.NativeSnapshotNode.prototype._storeState):
(WebInspector.NativeSnapshotNode.prototype._restoreState):
(WebInspector.NativeSnapshotNode.prototype.uid):
(WebInspector.NativeSnapshotNode.prototype._createSizeCell):

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r136152 r136163  
     12012-11-29  Alexei Filippov  <alph@chromium.org>
     2
     3        Web Inspector: Allow sorting in NMI snapshot grid view
     4        https://bugs.webkit.org/show_bug.cgi?id=102955
     5
     6        Reviewed by Yury Semikhatsky.
     7
     8        * English.lproj/localizedStrings.js:
     9        * inspector/front-end/NativeMemorySnapshotView.js:
     10        (WebInspector.NativeSnapshotDataGrid.prototype.sortingChanged):
     11        (WebInspector.NativeSnapshotDataGrid.prototype._sortingFunction):
     12        (WebInspector.NativeSnapshotNode):
     13        (WebInspector.NativeSnapshotNode.prototype._storeState):
     14        (WebInspector.NativeSnapshotNode.prototype._restoreState):
     15        (WebInspector.NativeSnapshotNode.prototype.uid):
     16        (WebInspector.NativeSnapshotNode.prototype._createSizeCell):
     17
    1182012-11-29  Martin Robinson  <mrobinson@igalia.com>
    219
  • trunk/Source/WebCore/English.lproj/localizedStrings.js

    r135487 r136163  
    232232localizedStrings["Install Timer"] = "Install Timer";
    233233localizedStrings["Invalid property value."] = "Invalid property value.";
     234localizedStrings["KB"] = "KB";
    234235localizedStrings["Key"] = "Key";
    235236localizedStrings["Shortcuts"] = "Shortcuts";
  • trunk/Source/WebCore/inspector/front-end/NativeMemorySnapshotView.js

    r135608 r136163  
    5656{
    5757    var columns = {
    58         object: { title: WebInspector.UIString("Object"), width: "200px", disclosure: true, sortable: false },
    59         size: { title: WebInspector.UIString("Size"), sortable: false },
     58        name: { title: WebInspector.UIString("Object"), width: "200px", disclosure: true, sortable: true },
     59        size: { title: WebInspector.UIString("Size"), sortable: true, sort: "descending" },
    6060    };
    6161    WebInspector.DataGrid.call(this, columns);
    62     var totalNode = new WebInspector.NativeSnapshotNode(profile, profile);
     62    this._totalNode = new WebInspector.NativeSnapshotNode(profile, profile);
    6363    if (WebInspector.settings.showNativeSnapshotUninstrumentedSize.get()) {
    6464        this.setRootNode(new WebInspector.DataGridNode(null, true));
    65         this.rootNode().appendChild(totalNode)
    66         totalNode.expand();
     65        this.rootNode().appendChild(this._totalNode)
     66        this._totalNode.expand();
    6767    } else {
    68         this.setRootNode(totalNode);
    69         totalNode._populate();
     68        this.setRootNode(this._totalNode);
     69        this._totalNode._populate();
    7070    }
     71    this.addEventListener("sorting changed", this.sortingChanged.bind(this), this);
    7172}
    7273
    7374WebInspector.NativeSnapshotDataGrid.prototype = {
     75    sortingChanged: function()
     76    {
     77        var expandedNodes = {};
     78        this._totalNode._storeState(expandedNodes);
     79        this._totalNode.removeChildren();
     80        this._totalNode._populate();
     81        this._totalNode._shouldRefreshChildren = true;
     82        this._totalNode._restoreState(expandedNodes);
     83    },
     84
     85    /**
     86     * @param {MemoryAgent.MemoryBlock} nodeA
     87     * @param {MemoryAgent.MemoryBlock} nodeB
     88     */
     89    _sortingFunction: function(nodeA, nodeB)
     90    {
     91        var sortColumnIdentifier = this.sortColumnIdentifier;
     92        var sortAscending = this.sortOrder === "ascending";
     93        var field1 = nodeA[sortColumnIdentifier];
     94        var field2 = nodeB[sortColumnIdentifier];
     95        var result = field1 < field2 ? -1 : (field1 > field2 ? 1 : 0);
     96        if (!sortAscending)
     97            result = -result;
     98        return result;
     99    },
     100
    74101    __proto__: WebInspector.DataGrid.prototype
    75102}
    … …  
    86113    this._profile = profile;
    87114    var viewProperties = WebInspector.MemoryBlockViewProperties._forMemoryBlock(nodeData);
    88     var data = { object: viewProperties._description, size: this._nodeData.size };
     115    var data = { name: viewProperties._description, size: this._nodeData.size };
    89116    var hasChildren = !!nodeData.children && nodeData.children.length !== 0;
    90117    WebInspector.DataGridNode.call(this, data, hasChildren);
    … …  
    104131            WebInspector.DataGridNode.prototype.createCell.call(this, columnIdentifier);
    105132        return cell;
     133    },
     134
     135    /**
     136     * @param {Object} expandedNodes
     137     */
     138    _storeState: function(expandedNodes)
     139    {
     140        if (!this.expanded)
     141            return;
     142        expandedNodes[this.uid()] = true;
     143        for (var i in this.children)
     144            this.children[i]._storeState(expandedNodes);
     145    },
     146
     147    /**
     148     * @param {Object} expandedNodes
     149     */
     150    _restoreState: function(expandedNodes)
     151    {
     152        if (!expandedNodes[this.uid()])
     153            return;
     154        this.expand();
     155        for (var i in this.children)
     156            this.children[i]._restoreState(expandedNodes);
     157    },
     158
     159    /**
     160     * @return {string}
     161     */
     162    uid: function()
     163    {
     164        if (!this._uid)
     165            this._uid = (!this.parent || !this.parent.uid ? "" : this.parent.uid() || "") + "/" + this._nodeData.name;
     166        return this._uid;
    106167    },
    107168
    … …  
    122183        }
    123184
    124         var sizeKiB = this._nodeData.size / 1024;
     185        var sizeKB = this._nodeData.size / 1024;
    125186        var totalSize = this._profile.size;
    126187        var percentage = this._nodeData.size / totalSize  * 100;
    … …  
    130191
    131192        var textDiv = document.createElement("div");
    132         textDiv.textContent = Number.withThousandsSeparator(sizeKiB.toFixed(0)) + "\u2009" + WebInspector.UIString("KiB");
     193        textDiv.textContent = Number.withThousandsSeparator(sizeKB.toFixed(0)) + "\u2009" + WebInspector.UIString("KB");
    133194        textDiv.className = "size-text";
    134195        cell.appendChild(textDiv);
    … …  
    158219    _populate: function() {
    159220        this.removeEventListener("populate", this._populate, this);
    160         function comparator(a, b) {
    161             return b.size - a.size;
    162         }
    163         if (this._nodeData !== this._profile)
    164             this._nodeData.children.sort(comparator);
     221        this._nodeData.children.sort(this.dataGrid._sortingFunction.bind(this.dataGrid));
    165222        for (var node in this._nodeData.children) {
    166223            var nodeData = this._nodeData.children[node];
Note: See TracChangeset for help on using the changeset viewer.