Changeset 102447 in webkit


Ignore:
Timestamp:
Dec 9, 2011 1:25:58 AM (12 years ago)
Author:
vsevik@chromium.org
Message:

Web Inspector: Introduce a Map class allowing to store values indexed by arbitrary objects.
https://bugs.webkit.org/show_bug.cgi?id=74084

Reviewed by Pavel Feldman.

Source/WebCore:

Test: inspector/map.html

  • inspector/front-end/treeoutline.js:

(TreeOutline):
():
(TreeElement.prototype.collapse):
(TreeElement.prototype.expand):

  • inspector/front-end/utilities.js:

():

LayoutTests:

  • inspector/map-expected.txt: Added.
  • inspector/map.html: Added.
Location:
trunk
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r102443 r102447  
     12011-12-08  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: Introduce a Map class allowing to store values indexed by arbitrary objects.
     4        https://bugs.webkit.org/show_bug.cgi?id=74084
     5
     6        Reviewed by Pavel Feldman.
     7
     8        * inspector/map-expected.txt: Added.
     9        * inspector/map.html: Added.
     10
    1112011-12-09  Csaba Osztrogonác  <ossy@webkit.org>
    212
  • trunk/Source/WebCore/ChangeLog

    r102441 r102447  
     12011-12-08  Vsevolod Vlasov  <vsevik@chromium.org>
     2
     3        Web Inspector: Introduce a Map class allowing to store values indexed by arbitrary objects.
     4        https://bugs.webkit.org/show_bug.cgi?id=74084
     5
     6        Reviewed by Pavel Feldman.
     7
     8        Test: inspector/map.html
     9
     10        * inspector/front-end/treeoutline.js:
     11        (TreeOutline):
     12        ():
     13        (TreeElement.prototype.collapse):
     14        (TreeElement.prototype.expand):
     15        * inspector/front-end/utilities.js:
     16        ():
     17
    1182011-12-09  Peter Rybin  <peter.rybin@gmail.com>
    219
  • trunk/Source/WebCore/inspector/front-end/treeoutline.js

    r101509 r102447  
    3939    this._childrenListNode = listNode;
    4040    this._childrenListNode.removeChildren();
    41     this._knownTreeElements = [];
    42     this._treeElementsExpandedState = [];
    4341    this.expandTreeElementsWhenArrowing = false;
    4442    this.root = true;
     
    5048    this._childrenListNode.tabIndex = 0;
    5149    this._childrenListNode.addEventListener("keydown", this._treeKeyDown.bind(this), true);
    52 }
    53 
    54 TreeOutline._knownTreeElementNextIdentifier = 1;
     50   
     51    this._treeElementsMap = new Map();
     52    this._expandedStateMap = new Map();
     53}
    5554
    5655TreeOutline.prototype.appendChild = function(child)
     
    8180    }
    8281
    83     if (child.hasChildren && child.treeOutline._treeElementsExpandedState[child.identifier] !== undefined)
    84         child.expanded = child.treeOutline._treeElementsExpandedState[child.identifier];
     82    child.expanded = child.hasChildren && !!child.treeOutline._expandedStateMap.get(child.representedObject);
    8583
    8684    if (!this._childrenListNode) {
     
    132130    }
    133131
    134     if (child.hasChildren && child.treeOutline._treeElementsExpandedState[child.identifier] !== undefined)
    135         child.expanded = child.treeOutline._treeElementsExpandedState[child.identifier];
     132    child.expanded = child.hasChildren && !!child.treeOutline._expandedStateMap.get(child.representedObject);
    136133
    137134    if (!this._childrenListNode) {
     
    246243TreeOutline.prototype._rememberTreeElement = function(element)
    247244{
    248     if (!this._knownTreeElements[element.identifier])
    249         this._knownTreeElements[element.identifier] = [];
    250 
     245    if (!this._treeElementsMap.get(element.representedObject))
     246        this._treeElementsMap.put(element.representedObject, []);
     247       
    251248    // check if the element is already known
    252     var elements = this._knownTreeElements[element.identifier];
     249    var elements = this._treeElementsMap.get(element.representedObject);
    253250    if (elements.indexOf(element) !== -1)
    254251        return;
     
    260257TreeOutline.prototype._forgetTreeElement = function(element)
    261258{
    262     if (this._knownTreeElements[element.identifier])
    263         this._knownTreeElements[element.identifier].remove(element, true);
     259    if (this._treeElementsMap.get(element.representedObject))
     260        this._treeElementsMap.get(element.representedObject).remove(element, true);
    264261}
    265262
     
    278275        return null;
    279276
    280     if ("__treeElementIdentifier" in representedObject) {
    281         // If this representedObject has a tree element identifier, and it is a known TreeElement
    282         // in our tree we can just return that tree element.
    283         var elements = this._knownTreeElements[representedObject.__treeElementIdentifier];
    284         if (elements) {
    285             for (var i = 0; i < elements.length; ++i)
    286                 if (elements[i].representedObject === representedObject)
    287                     return elements[i];
    288         }
    289     }
     277    var elements = this._treeElementsMap.get(representedObject);
     278    if (elements && elements.length)
     279        return elements[0];
    290280    return null;
    291281}
     
    480470    this.representedObject = (representedObject || {});
    481471
    482     if (this.representedObject.__treeElementIdentifier)
    483         this.identifier = this.representedObject.__treeElementIdentifier;
    484     else {
    485         this.identifier = TreeOutline._knownTreeElementNextIdentifier++;
    486         this.representedObject.__treeElementIdentifier = this.identifier;
    487     }
    488 
    489472    this._hidden = false;
    490473    this._selectable = true;
     
    743726
    744727    this.expanded = false;
     728   
    745729    if (this.treeOutline)
    746         this.treeOutline._treeElementsExpandedState[this.identifier] = false;
     730        this.treeOutline._expandedStateMap.put(this.representedObject, false);
    747731
    748732    if (this.oncollapse)
     
    771755    this.expanded = true;
    772756    if (this.treeOutline)
    773         this.treeOutline._treeElementsExpandedState[this.identifier] = true;
     757        this.treeOutline._expandedStateMap.put(this.representedObject, true);
    774758
    775759    if (this.treeOutline && (!this._childrenListNode || this._shouldRefreshChildren)) {
  • trunk/Source/WebCore/inspector/front-end/utilities.js

    r101670 r102447  
    11501150    return diffData;
    11511151}
     1152
     1153/**
     1154 * @constructor
     1155 */
     1156Map = function()
     1157{
     1158    this._map = {};
     1159}
     1160
     1161Map._lastObjectIdentifier = 0;
     1162
     1163Map.prototype = {
     1164    /**
     1165     * @param {Object} key
     1166     */
     1167    put: function(key, value)
     1168    {
     1169        var objectIdentifier = key.__identifier;
     1170        if (!objectIdentifier) {
     1171            objectIdentifier = ++Map._lastObjectIdentifier;
     1172            key.__identifier = objectIdentifier;
     1173        }
     1174        this._map[objectIdentifier] = value;
     1175    },
     1176   
     1177    /**
     1178     * @param {Object} key
     1179     */
     1180    remove: function(key)
     1181    {
     1182        delete this._map[key.__identifier];
     1183    },
     1184   
     1185    /**
     1186     * @param {Object} key
     1187     */
     1188    get: function(key)
     1189    {
     1190        return this._map[key.__identifier];
     1191    },
     1192}
Note: See TracChangeset for help on using the changeset viewer.