Changeset 181089 in webkit


Ignore:
Timestamp:
Mar 5, 2015 11:40:07 AM (9 years ago)
Author:
commit-queue@webkit.org
Message:

Web Inspector: Add ObjectTreeBaseTreeElement to share functionality
https://bugs.webkit.org/show_bug.cgi?id=142323

Patch by Joseph Pecoraro <Joseph Pecoraro> on 2015-03-05
Reviewed by Timothy Hatcher.

By making this change:

  • Share lots of duplicated code.
  • Array / Set / Map tree elements get context menu support
  • UserInterface/Main.html:
  • UserInterface/Views/ObjectTreeBaseTreeElement.js: Added.

(WebInspector.ObjectTreeBaseTreeElement):
(WebInspector.ObjectTreeBaseTreeElement.prototype.get property):
(WebInspector.ObjectTreeBaseTreeElement.prototype.get propertyPath):
(WebInspector.ObjectTreeBaseTreeElement.prototype.oncontextmenu):
(WebInspector.ObjectTreeBaseTreeElement.prototype.resolvedValue):
(WebInspector.ObjectTreeBaseTreeElement.prototype.resolvedValuePropertyPath):
(WebInspector.ObjectTreeBaseTreeElement.prototype.thisPropertyPath):
(WebInspector.ObjectTreeBaseTreeElement.prototype.hadError):
(WebInspector.ObjectTreeBaseTreeElement.prototype.propertyPathType):
(WebInspector.ObjectTreeBaseTreeElement.prototype.propertyPathString):
(WebInspector.ObjectTreeBaseTreeElement.prototype.createInteractiveGetterElement):
(WebInspector.ObjectTreeBaseTreeElement.prototype.createReadOnlyIconElement):
New file, copying most of the code from PropertyTreeElement so it can be shared.

  • UserInterface/Views/ObjectTreeArrayIndexTreeElement.js:

(WebInspector.ObjectTreeArrayIndexTreeElement):
(WebInspector.ObjectTreeArrayIndexTreeElement.prototype.invokedGetter):
(WebInspector.ObjectTreeArrayIndexTreeElement.prototype._titleFragment):
(WebInspector.ObjectTreeArrayIndexTreeElement.prototype.get property): Deleted.
(WebInspector.ObjectTreeArrayIndexTreeElement.prototype._resolvedValue): Deleted.
(WebInspector.ObjectTreeArrayIndexTreeElement.prototype._propertyPathType): Deleted.
(WebInspector.ObjectTreeArrayIndexTreeElement.prototype._resolvedValuePropertyPath): Deleted.
(WebInspector.ObjectTreeArrayIndexTreeElement.prototype._thisPropertyPath): Deleted.
(WebInspector.ObjectTreeArrayIndexTreeElement.prototype._propertyPathString): Deleted.
(WebInspector.ObjectTreeArrayIndexTreeElement.prototype._updateTitle): Deleted.
(WebInspector.ObjectTreeArrayIndexTreeElement.prototype._createInteractiveGetterElement.): Deleted.
(WebInspector.ObjectTreeArrayIndexTreeElement.prototype._createReadOnlyIconElement): Deleted.

  • UserInterface/Views/ObjectTreePropertyTreeElement.js:

(WebInspector.ObjectTreePropertyTreeElement):
(WebInspector.ObjectTreePropertyTreeElement.prototype.invokedGetter):
(WebInspector.ObjectTreePropertyTreeElement.prototype._updateHasChildren):
(WebInspector.ObjectTreePropertyTreeElement.prototype._updateTooltips):
(WebInspector.ObjectTreePropertyTreeElement.prototype._titleFragment):
(WebInspector.ObjectTreePropertyTreeElement.prototype._createTitlePrototype):
(WebInspector.ObjectTreePropertyTreeElement.prototype._createTitlePropertyStyle):
(WebInspector.ObjectTreePropertyTreeElement.prototype._createTitleAPIStyle):
(WebInspector.ObjectTreePropertyTreeElement.prototype._alwaysDisplayAsProperty):
(WebInspector.ObjectTreePropertyTreeElement.prototype._updateChildren):
(WebInspector.ObjectTreePropertyTreeElement.prototype._updateChildrenInternal):
(WebInspector.ObjectTreePropertyTreeElement.prototype._updateEntries):
(WebInspector.ObjectTreePropertyTreeElement.prototype._updateProperties):
(WebInspector.ObjectTreePropertyTreeElement.prototype.get property): Deleted.
(WebInspector.ObjectTreePropertyTreeElement.prototype.oncontextmenu): Deleted.
(WebInspector.ObjectTreePropertyTreeElement.prototype._resolvedValue): Deleted.
(WebInspector.ObjectTreePropertyTreeElement.prototype._propertyPathType): Deleted.
(WebInspector.ObjectTreePropertyTreeElement.prototype._resolvedValuePropertyPath): Deleted.
(WebInspector.ObjectTreePropertyTreeElement.prototype._thisPropertyPath): Deleted.
(WebInspector.ObjectTreePropertyTreeElement.prototype._updateTitleAndIcon): Deleted.
(WebInspector.ObjectTreePropertyTreeElement.prototype._createInteractiveGetterElement.): Deleted.
(WebInspector.ObjectTreePropertyTreeElement.prototype._createReadOnlyIconElement): Deleted.
(WebInspector.ObjectTreePropertyTreeElement.prototype): Deleted.
Subclass ObjectTreeBaseTreeElement and eliminate the code now
automatically handled by the base class.

  • UserInterface/Views/ObjectTreeMapEntryTreeElement.js:

(WebInspector.ObjectTreeMapEntryTreeElement):
(WebInspector.ObjectTreeMapEntryTreeElement.prototype.resolvedValue):
(WebInspector.ObjectTreeMapEntryTreeElement.prototype._titleFragment):
(WebInspector.ObjectTreeMapEntryTreeElement.prototype._propertyPathString): Deleted.

  • UserInterface/Views/ObjectTreeSetIndexTreeElement.js:

(WebInspector.ObjectTreeSetIndexTreeElement):
(WebInspector.ObjectTreeSetIndexTreeElement.prototype.resolvedValue):
(WebInspector.ObjectTreeSetIndexTreeElement.prototype._titleFragment):
(WebInspector.ObjectTreeSetIndexTreeElement.prototype._resolvedValuePropertyPath): Deleted.
Override resolved value since these are not about PropertyDescriptors.
This will make context menus work automatically.

Location:
trunk/Source/WebInspectorUI
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebInspectorUI/ChangeLog

    r181066 r181089  
     12015-03-05  Joseph Pecoraro  <pecoraro@apple.com>
     2
     3        Web Inspector: Add ObjectTreeBaseTreeElement to share functionality
     4        https://bugs.webkit.org/show_bug.cgi?id=142323
     5
     6        Reviewed by Timothy Hatcher.
     7
     8        By making this change:
     9
     10          - Share lots of duplicated code.
     11          - Array / Set / Map tree elements get context menu support
     12
     13        * UserInterface/Main.html:
     14        * UserInterface/Views/ObjectTreeBaseTreeElement.js: Added.
     15        (WebInspector.ObjectTreeBaseTreeElement):
     16        (WebInspector.ObjectTreeBaseTreeElement.prototype.get property):
     17        (WebInspector.ObjectTreeBaseTreeElement.prototype.get propertyPath):
     18        (WebInspector.ObjectTreeBaseTreeElement.prototype.oncontextmenu):
     19        (WebInspector.ObjectTreeBaseTreeElement.prototype.resolvedValue):
     20        (WebInspector.ObjectTreeBaseTreeElement.prototype.resolvedValuePropertyPath):
     21        (WebInspector.ObjectTreeBaseTreeElement.prototype.thisPropertyPath):
     22        (WebInspector.ObjectTreeBaseTreeElement.prototype.hadError):
     23        (WebInspector.ObjectTreeBaseTreeElement.prototype.propertyPathType):
     24        (WebInspector.ObjectTreeBaseTreeElement.prototype.propertyPathString):
     25        (WebInspector.ObjectTreeBaseTreeElement.prototype.createInteractiveGetterElement):
     26        (WebInspector.ObjectTreeBaseTreeElement.prototype.createReadOnlyIconElement):
     27        New file, copying most of the code from PropertyTreeElement so it can be shared.
     28
     29        * UserInterface/Views/ObjectTreeArrayIndexTreeElement.js:
     30        (WebInspector.ObjectTreeArrayIndexTreeElement):
     31        (WebInspector.ObjectTreeArrayIndexTreeElement.prototype.invokedGetter):
     32        (WebInspector.ObjectTreeArrayIndexTreeElement.prototype._titleFragment):
     33        (WebInspector.ObjectTreeArrayIndexTreeElement.prototype.get property): Deleted.
     34        (WebInspector.ObjectTreeArrayIndexTreeElement.prototype._resolvedValue): Deleted.
     35        (WebInspector.ObjectTreeArrayIndexTreeElement.prototype._propertyPathType): Deleted.
     36        (WebInspector.ObjectTreeArrayIndexTreeElement.prototype._resolvedValuePropertyPath): Deleted.
     37        (WebInspector.ObjectTreeArrayIndexTreeElement.prototype._thisPropertyPath): Deleted.
     38        (WebInspector.ObjectTreeArrayIndexTreeElement.prototype._propertyPathString): Deleted.
     39        (WebInspector.ObjectTreeArrayIndexTreeElement.prototype._updateTitle): Deleted.
     40        (WebInspector.ObjectTreeArrayIndexTreeElement.prototype._createInteractiveGetterElement.): Deleted.
     41        (WebInspector.ObjectTreeArrayIndexTreeElement.prototype._createReadOnlyIconElement): Deleted.
     42        * UserInterface/Views/ObjectTreePropertyTreeElement.js:
     43        (WebInspector.ObjectTreePropertyTreeElement):
     44        (WebInspector.ObjectTreePropertyTreeElement.prototype.invokedGetter):
     45        (WebInspector.ObjectTreePropertyTreeElement.prototype._updateHasChildren):
     46        (WebInspector.ObjectTreePropertyTreeElement.prototype._updateTooltips):
     47        (WebInspector.ObjectTreePropertyTreeElement.prototype._titleFragment):
     48        (WebInspector.ObjectTreePropertyTreeElement.prototype._createTitlePrototype):
     49        (WebInspector.ObjectTreePropertyTreeElement.prototype._createTitlePropertyStyle):
     50        (WebInspector.ObjectTreePropertyTreeElement.prototype._createTitleAPIStyle):
     51        (WebInspector.ObjectTreePropertyTreeElement.prototype._alwaysDisplayAsProperty):
     52        (WebInspector.ObjectTreePropertyTreeElement.prototype._updateChildren):
     53        (WebInspector.ObjectTreePropertyTreeElement.prototype._updateChildrenInternal):
     54        (WebInspector.ObjectTreePropertyTreeElement.prototype._updateEntries):
     55        (WebInspector.ObjectTreePropertyTreeElement.prototype._updateProperties):
     56        (WebInspector.ObjectTreePropertyTreeElement.prototype.get property): Deleted.
     57        (WebInspector.ObjectTreePropertyTreeElement.prototype.oncontextmenu): Deleted.
     58        (WebInspector.ObjectTreePropertyTreeElement.prototype._resolvedValue): Deleted.
     59        (WebInspector.ObjectTreePropertyTreeElement.prototype._propertyPathType): Deleted.
     60        (WebInspector.ObjectTreePropertyTreeElement.prototype._resolvedValuePropertyPath): Deleted.
     61        (WebInspector.ObjectTreePropertyTreeElement.prototype._thisPropertyPath): Deleted.
     62        (WebInspector.ObjectTreePropertyTreeElement.prototype._updateTitleAndIcon): Deleted.
     63        (WebInspector.ObjectTreePropertyTreeElement.prototype._createInteractiveGetterElement.): Deleted.
     64        (WebInspector.ObjectTreePropertyTreeElement.prototype._createReadOnlyIconElement): Deleted.
     65        (WebInspector.ObjectTreePropertyTreeElement.prototype): Deleted.
     66        Subclass ObjectTreeBaseTreeElement and eliminate the code now
     67        automatically handled by the base class.
     68
     69        * UserInterface/Views/ObjectTreeMapEntryTreeElement.js:
     70        (WebInspector.ObjectTreeMapEntryTreeElement):
     71        (WebInspector.ObjectTreeMapEntryTreeElement.prototype.resolvedValue):
     72        (WebInspector.ObjectTreeMapEntryTreeElement.prototype._titleFragment):
     73        (WebInspector.ObjectTreeMapEntryTreeElement.prototype._propertyPathString): Deleted.
     74        * UserInterface/Views/ObjectTreeSetIndexTreeElement.js:
     75        (WebInspector.ObjectTreeSetIndexTreeElement):
     76        (WebInspector.ObjectTreeSetIndexTreeElement.prototype.resolvedValue):
     77        (WebInspector.ObjectTreeSetIndexTreeElement.prototype._titleFragment):
     78        (WebInspector.ObjectTreeSetIndexTreeElement.prototype._resolvedValuePropertyPath): Deleted.
     79        Override resolved value since these are not about PropertyDescriptors.
     80        This will make context menus work automatically.
     81
    1822015-03-04  Joseph Pecoraro  <pecoraro@apple.com>
    283
  • trunk/Source/WebInspectorUI/UserInterface/Main.html

    r180941 r181089  
    317317
    318318    <script src="Views/DOMDetailsSidebarPanel.js"></script>
     319    <script src="Views/ObjectTreeBaseTreeElement.js"></script>
    319320    <script src="Views/FolderizedTreeElement.js"></script>
    320321    <script src="Views/SourceCodeTreeElement.js"></script>
  • trunk/Source/WebInspectorUI/UserInterface/Views/ObjectTreeArrayIndexTreeElement.js

    r180891 r181089  
    2424 */
    2525
    26 // FIXME: This should share more code with ObjectTreePropertyTreeElement. (getters, resolved values, context menus)
    27 
    2826WebInspector.ObjectTreeArrayIndexTreeElement = function(property, propertyPath)
    2927{
    30     console.assert(property instanceof WebInspector.PropertyDescriptor);
    31     console.assert(propertyPath instanceof WebInspector.PropertyPath);
    3228    console.assert(property.isIndexProperty(), "ArrayIndexTreeElement expects numeric property names");
    3329
    34     this._property = property;
    35     this._propertyPath = propertyPath;
     30    WebInspector.ObjectTreeBaseTreeElement.call(this, property, propertyPath, property);
    3631
    37     var classNames = ["object-tree-property", "object-tree-array-index"];
    38     if (!this._property.hasValue())
    39         classNames.push("accessor");
     32    this.mainTitle = this._titleFragment();
     33    this.addClassName("object-tree-property");
     34    this.addClassName("object-tree-array-index");
    4035
    41     WebInspector.GeneralTreeElement.call(this, classNames, this._titleFragment(), null, this._property, false);
    42 
    43     this.small = true;
    44     this.toggleOnClick = false;
    45     this.selectable = false;
    46     this.tooltipHandledSeparately = true;
    47     this.hasChildren = false;
     36    if (!this.property.hasValue())
     37        this.addClassName("accessor");
    4838};
    4939
    5040WebInspector.ObjectTreeArrayIndexTreeElement.prototype = {
    5141    constructor: WebInspector.ObjectTreeArrayIndexTreeElement,
    52     __proto__: WebInspector.GeneralTreeElement.prototype,
     42    __proto__: WebInspector.ObjectTreeBaseTreeElement.prototype,
    5343
    54     // Public
     44    // Protected
    5545
    56     get property()
     46    invokedGetter: function()
    5747    {
    58         return this._property;
     48        this.mainTitle = this._titleFragment();
     49
     50        this.removeClassName("accessor");
    5951    },
    6052
    6153    // Private
    62 
    63     _resolvedValue: function()
    64     {
    65         if (this._getterValue)
    66             return this._getterValue;
    67         if (this._property.hasValue())
    68             return this._property.value;
    69         return null;
    70     },
    71 
    72     _propertyPathType: function()
    73     {
    74         if (this._getterValue || this._property.hasValue())
    75             return WebInspector.PropertyPath.Type.Value;
    76         if (this._property.hasGetter())
    77             return WebInspector.PropertyPath.Type.Getter;
    78         if (this._property.hasSetter())
    79             return WebInspector.PropertyPath.Type.Setter;
    80         return WebInspector.PropertyPath.Type.Value;
    81     },
    82 
    83     _resolvedValuePropertyPath: function()
    84     {
    85         if (this._getterValue)
    86             return this._propertyPath.appendPropertyDescriptor(this._getterValue, this._property, WebInspector.PropertyPath.Type.Value);
    87         if (this._property.hasValue())
    88             return this._propertyPath.appendPropertyDescriptor(this._property.value, this._property, WebInspector.PropertyPath.Type.Value);
    89         return null;
    90     },
    91 
    92     _thisPropertyPath: function()
    93     {
    94         return this._propertyPath.appendPropertyDescriptor(null, this._property, this._propertyPathType());
    95     },
    96 
    97     _propertyPathString: function(propertyPath)
    98     {
    99         if (propertyPath.isFullPathImpossible())
    100             return WebInspector.UIString("Unable to determine path to property from root");
    101 
    102         return propertyPath.displayPath(this._propertyPathType());
    103     },
    104 
    105     _updateTitle: function()
    106     {
    107         this.mainTitle = this._titleFragment();
    108 
    109         if (this._getterValue)
    110             this.removeClassName("accessor");
    111 
    112         this._updateHasChildren();
    113     },
    11454
    11555    _titleFragment: function()
     
    12060        var nameElement = container.appendChild(document.createElement("span"));
    12161        nameElement.className = "index-name";
    122         nameElement.textContent = this._property.name;
    123         nameElement.title = this._propertyPathString(this._thisPropertyPath());
     62        nameElement.textContent = this.property.name;
     63        nameElement.title = this.propertyPathString(this.thisPropertyPath());
    12464
    12565        // Value.
     
    12767        valueElement.className = "index-value";
    12868
    129         var resolvedValue = this._resolvedValue();
     69        var resolvedValue = this.resolvedValue();
    13070        if (resolvedValue)
    131             valueElement.appendChild(WebInspector.FormattedValue.createObjectTreeOrFormattedValueForRemoteObject(resolvedValue, this._resolvedValuePropertyPath()));
     71            valueElement.appendChild(WebInspector.FormattedValue.createObjectTreeOrFormattedValueForRemoteObject(resolvedValue, this.resolvedValuePropertyPath()));
    13272        else {
    133             if (this._property.hasGetter())
    134                 container.appendChild(this._createInteractiveGetterElement());
    135             if (!this._property.hasSetter())
    136                 container.appendChild(this._createReadOnlyIconElement());
     73            if (this.property.hasGetter())
     74                container.appendChild(this.createInteractiveGetterElement());
     75            if (!this.property.hasSetter())
     76                container.appendChild(this.createReadOnlyIconElement());
    13777            // FIXME: What if just a setter?
    13878        }
    13979
    14080        valueElement.classList.add("value");
    141         if (this._property.wasThrown || this._getterHadError)
     81        if (this.hadError())
    14282            valueElement.classList.add("error");
    14383
    14484        return container;
    145     },
    146 
    147     _createInteractiveGetterElement: function()
    148     {
    149         var getterElement = document.createElement("img");
    150         getterElement.className = "getter";
    151         getterElement.title = WebInspector.UIString("Invoke getter");
    152 
    153         getterElement.addEventListener("click", function(event) {
    154             event.stopPropagation();
    155             var lastNonPrototypeObject = this._propertyPath.lastNonPrototypeObject;
    156             var getterObject = this._property.get;
    157             lastNonPrototypeObject.invokeGetter(getterObject, function(error, result, wasThrown) {
    158                 this._getterHadError = !!(error || wasThrown);
    159                 this._getterValue = result;
    160                 this._updateTitle();
    161             }.bind(this));
    162         }.bind(this));
    163 
    164         return getterElement;
    165     },
    166 
    167     _createReadOnlyIconElement: function()
    168     {
    169         var readOnlyElement = document.createElement("img");
    170         readOnlyElement.className = "read-only";
    171         readOnlyElement.title = WebInspector.UIString("Read only");
    172         return readOnlyElement;
    173     },
     85    }
    17486};
  • trunk/Source/WebInspectorUI/UserInterface/Views/ObjectTreeMapEntryTreeElement.js

    r180713 r181089  
    2727{
    2828    console.assert(object instanceof WebInspector.RemoteObject);
    29     console.assert(propertyPath instanceof WebInspector.PropertyPath);
    3029
    3130    this._object = object;
    32     this._propertyPath = propertyPath;
    3331
    3432    // Treat the same as an array-index just with different strings and widths.
    35     WebInspector.GeneralTreeElement.call(this, ["object-tree-array-index", "object-tree-map-entry"], this._titleFragment(), null, this._object, false);
     33    WebInspector.ObjectTreeBaseTreeElement.call(this, this._object, propertyPath);
    3634
    37     this.small = true;
    38     this.toggleOnClick = false;
    39     this.selectable = false;
    40     this.tooltipHandledSeparately = true;
    41     this.hasChildren = false;
     35    this.mainTitle = this._titleFragment();
     36    this.addClassName("object-tree-array-index");
     37    this.addClassName("object-tree-map-entry");
    4238};
    4339
    4440WebInspector.ObjectTreeMapEntryTreeElement.prototype = {
    4541    constructor: WebInspector.ObjectTreeMapEntryTreeElement,
    46     __proto__: WebInspector.GeneralTreeElement.prototype,
     42    __proto__: WebInspector.ObjectTreeBaseTreeElement.prototype,
    4743
    4844    // Public
     
    5349    },
    5450
     51    // Protected
     52
     53    resolvedValue: function()
     54    {
     55        return this._object;
     56    },
     57
    5558    // Private
    56 
    57     _propertyPathString: function(propertyPath)
    58     {
    59         if (propertyPath.isFullPathImpossible())
    60             return WebInspector.UIString("Unable to determine path to property from root");
    61 
    62         return propertyPath.displayPath(WebInspector.PropertyPath.Type.Value);
    63     },
    6459
    6560    _titleFragment: function()
     
    7368        nameElement.className = "index-name";
    7469        nameElement.textContent = this.displayPropertyName();
    75         nameElement.title = this._propertyPathString(propertyPath);
     70        nameElement.title = this.propertyPathString(propertyPath);
    7671
    7772        // Value.
     
    8984    WebInspector.ObjectTreeMapEntryTreeElement.call(this, object, propertyPath);
    9085    this.addClassName("key");
    91 }
     86};
    9287
    9388WebInspector.ObjectTreeMapKeyTreeElement.prototype = {
     
    114109    WebInspector.ObjectTreeMapEntryTreeElement.call(this, object, propertyPath);
    115110    this.addClassName("value");
    116 }
     111};
    117112
    118113WebInspector.ObjectTreeMapValueTreeElement.prototype = {
  • trunk/Source/WebInspectorUI/UserInterface/Views/ObjectTreePropertyTreeElement.js

    r181061 r181089  
    2626WebInspector.ObjectTreePropertyTreeElement = function(property, propertyPath, mode, prototypeName)
    2727{
    28     console.assert(property instanceof WebInspector.PropertyDescriptor);
    29     console.assert(propertyPath instanceof WebInspector.PropertyPath);
    30 
    31     this._property = property;
    3228    this._mode = mode || WebInspector.ObjectTreeView.Mode.Properties;
    33     this._propertyPath = propertyPath;
    3429    this._prototypeName = prototypeName;
    3530
    36     var classNames = ["object-tree-property"];
    37 
    38     if (this._property.hasValue()) {
    39         classNames.push(this._property.value.type);
    40         if (this._property.value.subtype)
    41             classNames.push(this._property.value.subtype);
     31    WebInspector.ObjectTreeBaseTreeElement.call(this, property, propertyPath, property);
     32
     33    this.mainTitle = this._titleFragment();
     34    this.addClassName("object-tree-property");
     35
     36    if (this.property.hasValue()) {
     37        this.addClassName(this.property.value.type);
     38        if (this.property.value.subtype)
     39            this.addClassName(this.property.value.subtype);
    4240    } else
    43         classNames.push("accessor");
    44 
    45     if (this._property.wasThrown)
    46         classNames.push("had-error");
    47 
    48     if (this._property.name === "__proto__")
    49         classNames.push("prototype-property");
    50 
    51     WebInspector.GeneralTreeElement.call(this, classNames, this._titleFragment(), null, this._property, false);
     41        this.addClassName("accessor");
     42
     43    if (this.property.wasThrown)
     44        this.addClassName("had-error");
     45    if (this.property.name === "__proto__")
     46        this.addClassName("prototype-property");
     47
    5248    this._updateTooltips();
    5349    this._updateHasChildren();
    54 
    55     this.small = true;
    56     this.toggleOnClick = true;
    57     this.selectable = false;
    58     this.tooltipHandledSeparately = true;
    5950};
    6051
    6152WebInspector.ObjectTreePropertyTreeElement.prototype = {
    6253    constructor: WebInspector.ObjectTreePropertyTreeElement,
    63     __proto__: WebInspector.GeneralTreeElement.prototype,
    64 
    65     // Public
    66 
    67     get property()
    68     {
    69         return this._property;
    70     },
     54    __proto__: WebInspector.ObjectTreeBaseTreeElement.prototype,
    7155
    7256    // Protected
     
    8973    },
    9074
    91     oncontextmenu: function(event)
    92     {
    93         this._contextMenuHandler(event);
     75    invokedGetter: function()
     76    {
     77        this.mainTitle = this._titleFragment();
     78
     79        var resolvedValue = this.resolvedValue();
     80        this.addClassName(resolvedValue.type);
     81        if (resolvedValue.subtype)
     82            this.addClassName(resolvedValue.subtype);
     83        if (this.hadError())
     84            this.addClassName("had-error");
     85        this.removeClassName("accessor");
     86
     87        this._updateHasChildren();
    9488    },
    9589
    9690    // Private
    9791
    98     _resolvedValue: function()
    99     {
    100         if (this._getterValue)
    101             return this._getterValue;
    102         if (this._property.hasValue())
    103             return this._property.value;
    104         return null;
    105     },
    106 
    107     _propertyPathType: function()
    108     {
    109         if (this._getterValue || this._property.hasValue())
    110             return WebInspector.PropertyPath.Type.Value;
    111         if (this._property.hasGetter())
    112             return WebInspector.PropertyPath.Type.Getter;
    113         if (this._property.hasSetter())
    114             return WebInspector.PropertyPath.Type.Setter;
    115         return WebInspector.PropertyPath.Type.Value;
    116     },
    117 
    118     _resolvedValuePropertyPath: function()
    119     {
    120         if (this._getterValue)
    121             return this._propertyPath.appendPropertyDescriptor(this._getterValue, this._property, WebInspector.PropertyPath.Type.Value);
    122         if (this._property.hasValue())
    123             return this._propertyPath.appendPropertyDescriptor(this._property.value, this._property, WebInspector.PropertyPath.Type.Value);
    124         return null;
    125     },
    126 
    127     _thisPropertyPath: function()
    128     {
    129         return this._propertyPath.appendPropertyDescriptor(null, this._property, this._propertyPathType());
    130     },
    131 
    13292    _updateHasChildren: function()
    13393    {
    134         var resolvedValue = this._resolvedValue();
     94        var resolvedValue = this.resolvedValue();
    13595        var valueHasChildren = (resolvedValue && resolvedValue.hasChildren);
    136         var wasThrown = this._property.wasThrown || this._getterHadError;
     96        var wasThrown = this.hadError();
    13797
    13898        if (this._mode === WebInspector.ObjectTreeView.Mode.Properties)
    13999            this.hasChildren = !wasThrown && valueHasChildren;
    140100        else
    141             this.hasChildren = !wasThrown && valueHasChildren && (this._property.name === "__proto__" || this._alwaysDisplayAsProperty());
     101            this.hasChildren = !wasThrown && valueHasChildren && (this.property.name === "__proto__" || this._alwaysDisplayAsProperty());
    142102    },
    143103
     
    146106        var attributes = [];
    147107
    148         if (this._property.configurable)
     108        if (this.property.configurable)
    149109            attributes.push("configurable");
    150         if (this._property.enumerable)
     110        if (this.property.enumerable)
    151111            attributes.push("enumerable");
    152         if (this._property.writable)
     112        if (this.property.writable)
    153113            attributes.push("writable");
    154114
     
    156116    },
    157117
    158     _updateTitleAndIcon: function()
    159     {
    160         this.mainTitle = this._titleFragment();
    161 
    162         if (this._getterValue) {
    163             this.addClassName(this._getterValue.type);
    164             if (this._getterValue.subtype)
    165                 this.addClassName(this._getterValue.subtype);
    166             if (this._getterHadError)
    167                 this.addClassName("had-error");
    168             this.removeClassName("accessor");
    169         }
    170 
    171         this._updateHasChildren();
    172     },
    173 
    174118    _titleFragment: function()
    175119    {
    176         if (this._property.name === "__proto__")
     120        if (this.property.name === "__proto__")
    177121            return this._createTitlePrototype();
    178122
     
    185129    _createTitlePrototype: function()
    186130    {
    187         console.assert(this._property.hasValue());
    188         console.assert(this._property.name === "__proto__");
     131        console.assert(this.property.hasValue());
     132        console.assert(this.property.name === "__proto__");
    189133
    190134        var nameElement = document.createElement("span");
    191135        nameElement.className = "prototype-name";
    192         nameElement.textContent = WebInspector.UIString("%s Prototype").format(this._sanitizedPrototypeString(this._property.value));
    193         nameElement.title = this._propertyPathString(this._thisPropertyPath());
     136        nameElement.textContent = WebInspector.UIString("%s Prototype").format(this._sanitizedPrototypeString(this.property.value));
     137        nameElement.title = this.propertyPathString(this.thisPropertyPath());
    194138        return nameElement;
    195139    },
     
    202146        var nameElement = document.createElement("span");
    203147        nameElement.className = "property-name";
    204         nameElement.textContent = this._property.name + ": ";
    205         nameElement.title = this._propertyPathString(this._thisPropertyPath());
     148        nameElement.textContent = this.property.name + ": ";
     149        nameElement.title = this.propertyPathString(this.thisPropertyPath());
    206150
    207151        // Property attributes.
    208152        if (this._mode === WebInspector.ObjectTreeView.Mode.Properties) {
    209             if (!this._property.enumerable)
     153            if (!this.property.enumerable)
    210154                nameElement.classList.add("not-enumerable");
    211155        }
     
    213157        // Value / Getter Value / Getter.
    214158        var valueOrGetterElement;
    215         var resolvedValue = this._resolvedValue();
     159        var resolvedValue = this.resolvedValue();
    216160        if (resolvedValue) {
    217161            if (resolvedValue.preview) {
     
    219163                valueOrGetterElement = this._previewView.element;
    220164            } else {
    221                 valueOrGetterElement = WebInspector.FormattedValue.createElementForRemoteObject(resolvedValue, this._property.wasThrown || this._getterHadError);
     165                valueOrGetterElement = WebInspector.FormattedValue.createElementForRemoteObject(resolvedValue, this.hadError());
    222166
    223167                // Special case a function property string.
     
    225169                    valueOrGetterElement.textContent = this._functionPropertyString();
    226170            }
    227 
    228             // FIXME: Option+Click for Value.
    229171        } else {
    230172            valueOrGetterElement = document.createElement("span");
    231             if (this._property.hasGetter())
    232                 valueOrGetterElement.appendChild(this._createInteractiveGetterElement());
    233             if (!this._property.hasSetter())
    234                 valueOrGetterElement.appendChild(this._createReadOnlyIconElement());
     173            if (this.property.hasGetter())
     174                valueOrGetterElement.appendChild(this.createInteractiveGetterElement());
     175            if (!this.property.hasSetter())
     176                valueOrGetterElement.appendChild(this.createReadOnlyIconElement());
    235177            // FIXME: What if just a setter?
    236178        }
    237179
    238180        valueOrGetterElement.classList.add("value");
    239         if (this._property.wasThrown || this._getterHadError)
     181        if (this.hadError())
    240182            valueOrGetterElement.classList.add("error");
    241183
     
    251193            return this._createTitlePropertyStyle();
    252194
    253         // Fetched getter values should already have been shown as properties.
    254         console.assert(!this._getterValue);
    255 
    256195        // No API to display.
    257         var isFunction = this._property.hasValue() && this._property.value.type === "function";
    258         if (!isFunction && !this._property.hasGetter() && !this._property.hasSetter())
     196        var isFunction = this.property.hasValue() && this.property.value.type === "function";
     197        if (!isFunction && !this.property.hasGetter() && !this.property.hasSetter())
    259198            return null;
    260199
     
    264203        var nameElement = document.createElement("span");
    265204        nameElement.className = "property-name";
    266         nameElement.textContent = this._property.name;
    267         nameElement.title = this._propertyPathString(this._thisPropertyPath());
     205        nameElement.textContent = this.property.name;
     206        nameElement.title = this.propertyPathString(this.thisPropertyPath());
    268207        container.appendChild(nameElement);
    269208
     
    274213            container.appendChild(paramElement);
    275214        } else {
    276             if (this._property.hasGetter())
    277                 container.appendChild(this._createInteractiveGetterElement());
    278             if (!this._property.hasSetter())
    279                 container.appendChild(this._createReadOnlyIconElement());
     215            if (this.property.hasGetter())
     216                container.appendChild(this.createInteractiveGetterElement());
     217            if (!this.property.hasSetter())
     218                container.appendChild(this.createReadOnlyIconElement());
    280219            // FIXME: What if just a setter?
    281220        }
     
    284223    },
    285224
    286     _createInteractiveGetterElement: function()
    287     {
    288         var getterElement = document.createElement("img");
    289         getterElement.className = "getter";
    290         getterElement.title = WebInspector.UIString("Invoke getter");
    291 
    292         getterElement.addEventListener("click", function(event) {
    293             event.stopPropagation();
    294             var lastNonPrototypeObject = this._propertyPath.lastNonPrototypeObject;
    295             var getterObject = this._property.get;
    296             lastNonPrototypeObject.invokeGetter(getterObject, function(error, result, wasThrown) {
    297                 this._getterHadError = !!(error || wasThrown);
    298                 this._getterValue = result;
    299                 this._updateTitleAndIcon();
    300             }.bind(this));
    301         }.bind(this));
    302 
    303         return getterElement;
    304     },
    305 
    306     _createReadOnlyIconElement: function()
    307     {
    308         var readOnlyElement = document.createElement("img");
    309         readOnlyElement.className = "read-only";
    310         readOnlyElement.title = WebInspector.UIString("Read only");
    311         return readOnlyElement;
    312     },
    313 
    314225    _alwaysDisplayAsProperty: function()
    315226    {
    316227        // Constructor, though a function, is often better treated as an expandable object.
    317         if (this._property.name === "constructor")
     228        if (this.property.name === "constructor")
    318229            return true;
    319230
    320231        // Non-function objects are often better treated as properties.
    321         if (this._property.hasValue() && this._property.value.type !== "function")
     232        if (this.property.hasValue() && this.property.value.type !== "function")
    322233            return true;
    323234
     
    336247    _functionParameterString: function()
    337248    {
    338         var resolvedValue = this._resolvedValue();
     249        var resolvedValue = this.resolvedValue();
    339250        console.assert(resolvedValue.type === "function");
    340251
     
    379290    },
    380291
    381     _propertyPathString: function(propertyPath)
    382     {
    383         if (propertyPath.isFullPathImpossible())
    384             return WebInspector.UIString("Unable to determine path to property from root");
    385 
    386         return propertyPath.displayPath(this._propertyPathType());
    387     },
    388 
    389292    _updateChildren: function()
    390293    {
     
    392295            return;
    393296
    394         var resolvedValue = this._resolvedValue();
     297        var resolvedValue = this.resolvedValue();
    395298        if (resolvedValue.isCollectionType() && this._mode === WebInspector.ObjectTreeView.Mode.Properties)
    396299            resolvedValue.getCollectionEntries(0, 100, this._updateChildrenInternal.bind(this, this._updateEntries, this._mode));
    397         else if (this._property.name === "__proto__")
     300        else if (this.property.name === "__proto__")
    398301            resolvedValue.getOwnPropertyDescriptors(this._updateChildrenInternal.bind(this, this._updateProperties, WebInspector.ObjectTreeView.Mode.API));
    399302        else
     
    411314        }
    412315
    413         handler.call(this, list, this._resolvedValuePropertyPath(), mode);
     316        handler.call(this, list, this.resolvedValuePropertyPath(), mode);
    414317    },
    415318
     
    430333
    431334        // Show the prototype so users can see the API.
    432         var resolvedValue = this._resolvedValue();
     335        var resolvedValue = this.resolvedValue();
    433336        resolvedValue.getOwnPropertyDescriptor("__proto__", function(propertyDescriptor) {
    434337            if (propertyDescriptor)
     
    441344        properties.sort(WebInspector.ObjectTreeView.ComparePropertyDescriptors);
    442345
    443         var resolvedValue = this._resolvedValue();
     346        var resolvedValue = this.resolvedValue();
    444347        var isArray = resolvedValue.isArray();
    445348        var isPropertyMode = mode === WebInspector.ObjectTreeView.Mode.Properties || this._getterValue;
     
    447350
    448351        var prototypeName = undefined;
    449         if (this._property.name === "__proto__") {
     352        if (this.property.name === "__proto__") {
    450353            if (resolvedValue.description)
    451354                prototypeName = this._sanitizedPrototypeString(resolvedValue);
     
    472375            this.appendChild(new TreeElement(emptyMessageElement, null, false));
    473376        }
    474     },
    475 
    476     _logValue: function(value)
    477     {
    478         var resolvedValue = value || this._resolvedValue();
    479         if (!resolvedValue)
    480             return;
    481 
    482         var propertyPath = this._resolvedValuePropertyPath();
    483         var isImpossible = propertyPath.isFullPathImpossible();
    484         var text = isImpossible ? WebInspector.UIString("Selected Value") : propertyPath.displayPath(this._propertyPathType());
    485 
    486         if (!isImpossible)
    487             WebInspector.quickConsole.prompt.pushHistoryItem(text);
    488 
    489         WebInspector.consoleLogViewController.appendImmediateExecutionWithResult(text, resolvedValue);
    490     },
    491 
    492     _contextMenuHandler: function(event)
    493     {
    494         var resolvedValue = this._resolvedValue();
    495         if (!resolvedValue)
    496             return;
    497 
    498         var contextMenu = new WebInspector.ContextMenu(event);
    499         contextMenu.appendItem(WebInspector.UIString("Log Value"), this._logValue.bind(this));
    500 
    501         var propertyPath = this._resolvedValuePropertyPath();
    502         if (propertyPath && !propertyPath.isFullPathImpossible()) {
    503             contextMenu.appendItem(WebInspector.UIString("Copy Path to Property"), function() {
    504                 InspectorFrontendHost.copyText(propertyPath.displayPath(WebInspector.PropertyPath.Type.Value));
    505             }.bind(this));
    506         }
    507 
    508         contextMenu.appendSeparator();
    509 
    510         this._appendMenusItemsForObject(contextMenu, resolvedValue);
    511 
    512         if (!contextMenu.isEmpty())
    513             contextMenu.show();
    514     },
    515 
    516     _appendMenusItemsForObject: function(contextMenu, resolvedValue)
    517     {
    518         if (resolvedValue.type === "function") {
    519             // FIXME: We should better handle bound functions.
    520             if (!isFunctionStringNativeCode(resolvedValue.description)) {
    521                 contextMenu.appendItem(WebInspector.UIString("Jump to Definition"), function() {
    522                     DebuggerAgent.getFunctionDetails(resolvedValue.objectId, function(error, response) {
    523                         if (error)
    524                             return;
    525 
    526                         var location = response.location;
    527                         var sourceCode = WebInspector.debuggerManager.scriptForIdentifier(location.scriptId);
    528                         if (!sourceCode)
    529                             return;
    530 
    531                         var sourceCodeLocation = sourceCode.createSourceCodeLocation(location.lineNumber, location.columnNumber || 0);
    532                         WebInspector.resourceSidebarPanel.showSourceCodeLocation(sourceCodeLocation);
    533                     });
    534                 });
    535             }
    536             return;
    537         }
    538 
    539         if (resolvedValue.subtype === "node") {
    540             contextMenu.appendItem(WebInspector.UIString("Reveal in DOM Tree"), function() {
    541                 resolvedValue.pushNodeToFrontend(function(nodeId) {
    542                     WebInspector.domTreeManager.inspectElement(nodeId);
    543                 });
    544             });
    545             return;
    546         }
    547377    }
    548378};
  • trunk/Source/WebInspectorUI/UserInterface/Views/ObjectTreeSetIndexTreeElement.js

    r180713 r181089  
    2929
    3030    this._object = object;
    31     this._propertyPath = propertyPath;
    3231
    33     // Treat the same as an array-index just with a different character.
    34     WebInspector.GeneralTreeElement.call(this, ["object-tree-array-index"], this._titleFragment(), null, this._object, false);
     32    // Treat the same as an array-index just with different strings and widths.
     33    WebInspector.ObjectTreeBaseTreeElement.call(this, this._object, propertyPath);
    3534
    36     this.small = true;
    37     this.toggleOnClick = false;
    38     this.selectable = false;
    39     this.tooltipHandledSeparately = true;
    40     this.hasChildren = false;
     35    this.mainTitle = this._titleFragment();
     36    this.addClassName("object-tree-array-index");
    4137};
    4238
    4339WebInspector.ObjectTreeSetIndexTreeElement.prototype = {
    4440    constructor: WebInspector.ObjectTreeSetIndexTreeElement,
    45     __proto__: WebInspector.GeneralTreeElement.prototype,
     41    __proto__: WebInspector.ObjectTreeBaseTreeElement.prototype,
    4642
    4743    // Public
     
    5248    },
    5349
     50    // Protected
     51
     52    resolvedValue: function()
     53    {
     54        return this._object;
     55    },
     56
    5457    // Private
    55 
    56     _resolvedValuePropertyPath: function()
    57     {
    58         return this._propertyPath.appendSetIndex(this._object);
    59     },
    6058
    6159    _titleFragment: function()
    6260    {
    6361        var container = document.createDocumentFragment();
     62
     63        var propertyPath = this.propertyPath.appendSetIndex(this._object);
    6464
    6565        // Set bullet.
     
    7272        var valueElement = container.appendChild(document.createElement("span"));
    7373        valueElement.className = "index-value";
    74         valueElement.appendChild(WebInspector.FormattedValue.createObjectTreeOrFormattedValueForRemoteObject(this._object, this._resolvedValuePropertyPath()));
     74        valueElement.appendChild(WebInspector.FormattedValue.createObjectTreeOrFormattedValueForRemoteObject(this._object, propertyPath));
    7575
    7676        return container;
Note: See TracChangeset for help on using the changeset viewer.