Changeset 181089 in webkit
- Timestamp:
- Mar 5, 2015 11:40:07 AM (9 years ago)
- Location:
- trunk/Source/WebInspectorUI
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebInspectorUI/ChangeLog
r181066 r181089 1 2015-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 1 82 2015-03-04 Joseph Pecoraro <pecoraro@apple.com> 2 83 -
trunk/Source/WebInspectorUI/UserInterface/Main.html
r180941 r181089 317 317 318 318 <script src="Views/DOMDetailsSidebarPanel.js"></script> 319 <script src="Views/ObjectTreeBaseTreeElement.js"></script> 319 320 <script src="Views/FolderizedTreeElement.js"></script> 320 321 <script src="Views/SourceCodeTreeElement.js"></script> -
trunk/Source/WebInspectorUI/UserInterface/Views/ObjectTreeArrayIndexTreeElement.js
r180891 r181089 24 24 */ 25 25 26 // FIXME: This should share more code with ObjectTreePropertyTreeElement. (getters, resolved values, context menus)27 28 26 WebInspector.ObjectTreeArrayIndexTreeElement = function(property, propertyPath) 29 27 { 30 console.assert(property instanceof WebInspector.PropertyDescriptor);31 console.assert(propertyPath instanceof WebInspector.PropertyPath);32 28 console.assert(property.isIndexProperty(), "ArrayIndexTreeElement expects numeric property names"); 33 29 34 this._property = property; 35 this._propertyPath = propertyPath; 30 WebInspector.ObjectTreeBaseTreeElement.call(this, property, propertyPath, property); 36 31 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"); 40 35 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"); 48 38 }; 49 39 50 40 WebInspector.ObjectTreeArrayIndexTreeElement.prototype = { 51 41 constructor: WebInspector.ObjectTreeArrayIndexTreeElement, 52 __proto__: WebInspector. GeneralTreeElement.prototype,42 __proto__: WebInspector.ObjectTreeBaseTreeElement.prototype, 53 43 54 // P ublic44 // Protected 55 45 56 get property()46 invokedGetter: function() 57 47 { 58 return this._property; 48 this.mainTitle = this._titleFragment(); 49 50 this.removeClassName("accessor"); 59 51 }, 60 52 61 53 // 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 },114 54 115 55 _titleFragment: function() … … 120 60 var nameElement = container.appendChild(document.createElement("span")); 121 61 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()); 124 64 125 65 // Value. … … 127 67 valueElement.className = "index-value"; 128 68 129 var resolvedValue = this. _resolvedValue();69 var resolvedValue = this.resolvedValue(); 130 70 if (resolvedValue) 131 valueElement.appendChild(WebInspector.FormattedValue.createObjectTreeOrFormattedValueForRemoteObject(resolvedValue, this. _resolvedValuePropertyPath()));71 valueElement.appendChild(WebInspector.FormattedValue.createObjectTreeOrFormattedValueForRemoteObject(resolvedValue, this.resolvedValuePropertyPath())); 132 72 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()); 137 77 // FIXME: What if just a setter? 138 78 } 139 79 140 80 valueElement.classList.add("value"); 141 if (this. _property.wasThrown || this._getterHadError)81 if (this.hadError()) 142 82 valueElement.classList.add("error"); 143 83 144 84 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 } 174 86 }; -
trunk/Source/WebInspectorUI/UserInterface/Views/ObjectTreeMapEntryTreeElement.js
r180713 r181089 27 27 { 28 28 console.assert(object instanceof WebInspector.RemoteObject); 29 console.assert(propertyPath instanceof WebInspector.PropertyPath);30 29 31 30 this._object = object; 32 this._propertyPath = propertyPath;33 31 34 32 // 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); 36 34 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"); 42 38 }; 43 39 44 40 WebInspector.ObjectTreeMapEntryTreeElement.prototype = { 45 41 constructor: WebInspector.ObjectTreeMapEntryTreeElement, 46 __proto__: WebInspector. GeneralTreeElement.prototype,42 __proto__: WebInspector.ObjectTreeBaseTreeElement.prototype, 47 43 48 44 // Public … … 53 49 }, 54 50 51 // Protected 52 53 resolvedValue: function() 54 { 55 return this._object; 56 }, 57 55 58 // 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 },64 59 65 60 _titleFragment: function() … … 73 68 nameElement.className = "index-name"; 74 69 nameElement.textContent = this.displayPropertyName(); 75 nameElement.title = this. _propertyPathString(propertyPath);70 nameElement.title = this.propertyPathString(propertyPath); 76 71 77 72 // Value. … … 89 84 WebInspector.ObjectTreeMapEntryTreeElement.call(this, object, propertyPath); 90 85 this.addClassName("key"); 91 } 86 }; 92 87 93 88 WebInspector.ObjectTreeMapKeyTreeElement.prototype = { … … 114 109 WebInspector.ObjectTreeMapEntryTreeElement.call(this, object, propertyPath); 115 110 this.addClassName("value"); 116 } 111 }; 117 112 118 113 WebInspector.ObjectTreeMapValueTreeElement.prototype = { -
trunk/Source/WebInspectorUI/UserInterface/Views/ObjectTreePropertyTreeElement.js
r181061 r181089 26 26 WebInspector.ObjectTreePropertyTreeElement = function(property, propertyPath, mode, prototypeName) 27 27 { 28 console.assert(property instanceof WebInspector.PropertyDescriptor);29 console.assert(propertyPath instanceof WebInspector.PropertyPath);30 31 this._property = property;32 28 this._mode = mode || WebInspector.ObjectTreeView.Mode.Properties; 33 this._propertyPath = propertyPath;34 29 this._prototypeName = prototypeName; 35 30 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); 42 40 } 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 52 48 this._updateTooltips(); 53 49 this._updateHasChildren(); 54 55 this.small = true;56 this.toggleOnClick = true;57 this.selectable = false;58 this.tooltipHandledSeparately = true;59 50 }; 60 51 61 52 WebInspector.ObjectTreePropertyTreeElement.prototype = { 62 53 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, 71 55 72 56 // Protected … … 89 73 }, 90 74 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(); 94 88 }, 95 89 96 90 // Private 97 91 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 132 92 _updateHasChildren: function() 133 93 { 134 var resolvedValue = this. _resolvedValue();94 var resolvedValue = this.resolvedValue(); 135 95 var valueHasChildren = (resolvedValue && resolvedValue.hasChildren); 136 var wasThrown = this. _property.wasThrown || this._getterHadError;96 var wasThrown = this.hadError(); 137 97 138 98 if (this._mode === WebInspector.ObjectTreeView.Mode.Properties) 139 99 this.hasChildren = !wasThrown && valueHasChildren; 140 100 else 141 this.hasChildren = !wasThrown && valueHasChildren && (this. _property.name === "__proto__" || this._alwaysDisplayAsProperty());101 this.hasChildren = !wasThrown && valueHasChildren && (this.property.name === "__proto__" || this._alwaysDisplayAsProperty()); 142 102 }, 143 103 … … 146 106 var attributes = []; 147 107 148 if (this. _property.configurable)108 if (this.property.configurable) 149 109 attributes.push("configurable"); 150 if (this. _property.enumerable)110 if (this.property.enumerable) 151 111 attributes.push("enumerable"); 152 if (this. _property.writable)112 if (this.property.writable) 153 113 attributes.push("writable"); 154 114 … … 156 116 }, 157 117 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 174 118 _titleFragment: function() 175 119 { 176 if (this. _property.name === "__proto__")120 if (this.property.name === "__proto__") 177 121 return this._createTitlePrototype(); 178 122 … … 185 129 _createTitlePrototype: function() 186 130 { 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__"); 189 133 190 134 var nameElement = document.createElement("span"); 191 135 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()); 194 138 return nameElement; 195 139 }, … … 202 146 var nameElement = document.createElement("span"); 203 147 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()); 206 150 207 151 // Property attributes. 208 152 if (this._mode === WebInspector.ObjectTreeView.Mode.Properties) { 209 if (!this. _property.enumerable)153 if (!this.property.enumerable) 210 154 nameElement.classList.add("not-enumerable"); 211 155 } … … 213 157 // Value / Getter Value / Getter. 214 158 var valueOrGetterElement; 215 var resolvedValue = this. _resolvedValue();159 var resolvedValue = this.resolvedValue(); 216 160 if (resolvedValue) { 217 161 if (resolvedValue.preview) { … … 219 163 valueOrGetterElement = this._previewView.element; 220 164 } else { 221 valueOrGetterElement = WebInspector.FormattedValue.createElementForRemoteObject(resolvedValue, this. _property.wasThrown || this._getterHadError);165 valueOrGetterElement = WebInspector.FormattedValue.createElementForRemoteObject(resolvedValue, this.hadError()); 222 166 223 167 // Special case a function property string. … … 225 169 valueOrGetterElement.textContent = this._functionPropertyString(); 226 170 } 227 228 // FIXME: Option+Click for Value.229 171 } else { 230 172 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()); 235 177 // FIXME: What if just a setter? 236 178 } 237 179 238 180 valueOrGetterElement.classList.add("value"); 239 if (this. _property.wasThrown || this._getterHadError)181 if (this.hadError()) 240 182 valueOrGetterElement.classList.add("error"); 241 183 … … 251 193 return this._createTitlePropertyStyle(); 252 194 253 // Fetched getter values should already have been shown as properties.254 console.assert(!this._getterValue);255 256 195 // 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()) 259 198 return null; 260 199 … … 264 203 var nameElement = document.createElement("span"); 265 204 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()); 268 207 container.appendChild(nameElement); 269 208 … … 274 213 container.appendChild(paramElement); 275 214 } 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()); 280 219 // FIXME: What if just a setter? 281 220 } … … 284 223 }, 285 224 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 314 225 _alwaysDisplayAsProperty: function() 315 226 { 316 227 // Constructor, though a function, is often better treated as an expandable object. 317 if (this. _property.name === "constructor")228 if (this.property.name === "constructor") 318 229 return true; 319 230 320 231 // 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") 322 233 return true; 323 234 … … 336 247 _functionParameterString: function() 337 248 { 338 var resolvedValue = this. _resolvedValue();249 var resolvedValue = this.resolvedValue(); 339 250 console.assert(resolvedValue.type === "function"); 340 251 … … 379 290 }, 380 291 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 389 292 _updateChildren: function() 390 293 { … … 392 295 return; 393 296 394 var resolvedValue = this. _resolvedValue();297 var resolvedValue = this.resolvedValue(); 395 298 if (resolvedValue.isCollectionType() && this._mode === WebInspector.ObjectTreeView.Mode.Properties) 396 299 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__") 398 301 resolvedValue.getOwnPropertyDescriptors(this._updateChildrenInternal.bind(this, this._updateProperties, WebInspector.ObjectTreeView.Mode.API)); 399 302 else … … 411 314 } 412 315 413 handler.call(this, list, this. _resolvedValuePropertyPath(), mode);316 handler.call(this, list, this.resolvedValuePropertyPath(), mode); 414 317 }, 415 318 … … 430 333 431 334 // Show the prototype so users can see the API. 432 var resolvedValue = this. _resolvedValue();335 var resolvedValue = this.resolvedValue(); 433 336 resolvedValue.getOwnPropertyDescriptor("__proto__", function(propertyDescriptor) { 434 337 if (propertyDescriptor) … … 441 344 properties.sort(WebInspector.ObjectTreeView.ComparePropertyDescriptors); 442 345 443 var resolvedValue = this. _resolvedValue();346 var resolvedValue = this.resolvedValue(); 444 347 var isArray = resolvedValue.isArray(); 445 348 var isPropertyMode = mode === WebInspector.ObjectTreeView.Mode.Properties || this._getterValue; … … 447 350 448 351 var prototypeName = undefined; 449 if (this. _property.name === "__proto__") {352 if (this.property.name === "__proto__") { 450 353 if (resolvedValue.description) 451 354 prototypeName = this._sanitizedPrototypeString(resolvedValue); … … 472 375 this.appendChild(new TreeElement(emptyMessageElement, null, false)); 473 376 } 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 }547 377 } 548 378 }; -
trunk/Source/WebInspectorUI/UserInterface/Views/ObjectTreeSetIndexTreeElement.js
r180713 r181089 29 29 30 30 this._object = object; 31 this._propertyPath = propertyPath;32 31 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); 35 34 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"); 41 37 }; 42 38 43 39 WebInspector.ObjectTreeSetIndexTreeElement.prototype = { 44 40 constructor: WebInspector.ObjectTreeSetIndexTreeElement, 45 __proto__: WebInspector. GeneralTreeElement.prototype,41 __proto__: WebInspector.ObjectTreeBaseTreeElement.prototype, 46 42 47 43 // Public … … 52 48 }, 53 49 50 // Protected 51 52 resolvedValue: function() 53 { 54 return this._object; 55 }, 56 54 57 // Private 55 56 _resolvedValuePropertyPath: function()57 {58 return this._propertyPath.appendSetIndex(this._object);59 },60 58 61 59 _titleFragment: function() 62 60 { 63 61 var container = document.createDocumentFragment(); 62 63 var propertyPath = this.propertyPath.appendSetIndex(this._object); 64 64 65 65 // Set bullet. … … 72 72 var valueElement = container.appendChild(document.createElement("span")); 73 73 valueElement.className = "index-value"; 74 valueElement.appendChild(WebInspector.FormattedValue.createObjectTreeOrFormattedValueForRemoteObject(this._object, this._resolvedValuePropertyPath()));74 valueElement.appendChild(WebInspector.FormattedValue.createObjectTreeOrFormattedValueForRemoteObject(this._object, propertyPath)); 75 75 76 76 return container;
Note: See TracChangeset
for help on using the changeset viewer.