Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * Copyright (C) 2009 Joseph Pecoraro | 3 * Copyright (C) 2009 Joseph Pecoraro |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 console.assert(propertyValue); | 160 console.assert(propertyValue); |
| 161 WebInspector.ObjectPropertyTreeElement.populate(this, propertyValue); | 161 WebInspector.ObjectPropertyTreeElement.populate(this, propertyValue); |
| 162 }, | 162 }, |
| 163 | 163 |
| 164 /** | 164 /** |
| 165 * @override | 165 * @override |
| 166 * @return {boolean} | 166 * @return {boolean} |
| 167 */ | 167 */ |
| 168 ondblclick: function(event) | 168 ondblclick: function(event) |
| 169 { | 169 { |
| 170 var editableElement = this.elementAndValueToEdit().element; | 170 var editableElement = this.valueElement; |
| 171 if ((this.property.writable || this.property.setter) && event.target.isS elfOrDescendant(editableElement)) | 171 if ((this.property.writable || this.property.setter) && event.target.isS elfOrDescendant(editableElement)) |
| 172 this.startEditing(event); | 172 this.startEditing(event); |
| 173 return false; | 173 return false; |
| 174 }, | 174 }, |
| 175 | 175 |
| 176 /** | 176 /** |
| 177 * @override | 177 * @override |
| 178 */ | 178 */ |
| 179 onattach: function() | 179 onattach: function() |
| 180 { | 180 { |
| 181 this.update(); | 181 this.update(); |
| 182 }, | 182 }, |
| 183 | 183 |
| 184 update: function() | 184 update: function() |
| 185 { | 185 { |
| 186 this.nameElement = createElementWithClass("span", "name"); | 186 this.nameElement = WebInspector.ObjectPropertiesSection.createNameElemen t(this.property.name); |
| 187 var name = this.property.name; | |
| 188 if (/^\s|\s$|^$|\n/.test(name)) | |
| 189 this.nameElement.createTextChildren("\"", name.replace(/\n/g, "\u21B 5"), "\""); | |
| 190 else | |
| 191 this.nameElement.textContent = name; | |
| 192 if (!this.property.enumerable) | 187 if (!this.property.enumerable) |
| 193 this.nameElement.classList.add("dimmed"); | 188 this.nameElement.classList.add("dimmed"); |
| 194 if (this.property.isAccessorProperty()) | 189 if (this.property.isAccessorProperty()) |
| 195 this.nameElement.classList.add("properties-accessor-property-name"); | 190 this.nameElement.classList.add("properties-accessor-property-name"); |
| 196 if (this.property.symbol) | 191 if (this.property.symbol) |
| 197 this.nameElement.addEventListener("contextmenu", this._contextMenuFi red.bind(this, this.property.symbol), false); | 192 this.nameElement.addEventListener("contextmenu", this._contextMenuFi red.bind(this, this.property.symbol), false); |
| 198 | 193 |
| 194 if (!this.property.value && this.property.getter) | |
|
pfeldman
2015/02/09 13:13:52
I don't see how the old code maps to the new code.
sergeyv
2015/02/17 14:22:58
Done.
| |
| 195 this.valueElement = WebInspector.ObjectPropertyTreeElement.createRem oteObjectAccessorPropertySpan(this.property.parentObject, [this.property.name], this._onInvokeGetterClick.bind(this)); | |
| 196 else | |
| 197 this.valueElement = WebInspector.ObjectPropertiesSection.createValue Element(this.property.value, this.property.wasThrown, this.listItemElement); | |
| 198 | |
| 199 if (this.property.value) | |
| 200 this.valueElement.addEventListener("contextmenu", this._contextMenuF ired.bind(this, this.property.value), false); | |
| 201 | |
| 202 | |
| 203 if (this.property.value) | |
| 204 this.hasChildren = this.property.value.hasChildren && !this.property .wasThrown; | |
| 199 var separatorElement = createElementWithClass("span", "separator"); | 205 var separatorElement = createElementWithClass("span", "separator"); |
| 200 separatorElement.textContent = ": "; | 206 separatorElement.textContent = ": "; |
| 201 | 207 |
| 202 if (this.property.value) { | 208 this.listItemElement.removeChildren(); |
| 203 this.valueElement = createElementWithClass("span", "value"); | |
| 204 var type = this.property.value.type; | |
| 205 var subtype = this.property.value.subtype; | |
| 206 var description = this.property.value.description; | |
| 207 var prefix; | |
| 208 var valueText; | |
| 209 var suffix; | |
| 210 if (this.property.wasThrown) { | |
| 211 prefix = "[Exception: "; | |
| 212 valueText = description; | |
| 213 suffix = "]"; | |
| 214 } else if (type === "string" && typeof description === "string") { | |
| 215 // Render \n as a nice unicode cr symbol. | |
| 216 prefix = "\""; | |
| 217 valueText = description.replace(/\n/g, "\u21B5"); | |
| 218 suffix = "\""; | |
| 219 this.valueElement._originalTextContent = "\"" + description + "\ ""; | |
| 220 } else if (type === "function" && typeof description === "string") { | |
| 221 // Render function description until the first \n. | |
| 222 valueText = /.*/.exec(description)[0].replace(/\s+$/g, ""); | |
| 223 this.valueElement._originalTextContent = description; | |
| 224 } else if (type !== "object" || subtype !== "node") { | |
| 225 valueText = description; | |
| 226 } | |
| 227 if (type !== "number" || valueText.indexOf("e") === -1) { | |
| 228 this.valueElement.setTextContentTruncatedIfNeeded(valueText || " "); | |
| 229 if (prefix) | |
| 230 this.valueElement.insertBefore(createTextNode(prefix), this. valueElement.firstChild); | |
| 231 if (suffix) | |
| 232 this.valueElement.createTextChild(suffix); | |
| 233 } else { | |
| 234 var numberParts = valueText.split("e"); | |
| 235 var mantissa = this.valueElement.createChild("span", "scientific -notation-mantissa"); | |
| 236 mantissa.textContent = numberParts[0]; | |
| 237 var exponent = this.valueElement.createChild("span", "scientific -notation-exponent"); | |
| 238 exponent.textContent = "e" + numberParts[1]; | |
| 239 this.valueElement.classList.add("scientific-notation-number"); | |
| 240 this.listItemElement.classList.add("hbox"); | |
| 241 } | |
| 242 | |
| 243 if (this.property.wasThrown) | |
| 244 this.valueElement.classList.add("error"); | |
| 245 if (subtype || type) | |
| 246 this.valueElement.classList.add("console-formatted-" + (subtype || type)); | |
| 247 | |
| 248 this.valueElement.addEventListener("contextmenu", this._contextMenuF ired.bind(this, this.property.value), false); | |
| 249 if (type === "object" && subtype === "node" && description) { | |
| 250 WebInspector.DOMPresentationUtils.createSpansForNodeTitle(this.v alueElement, description); | |
| 251 this.valueElement.addEventListener("mousemove", this._mouseMove. bind(this), false); | |
| 252 this.valueElement.addEventListener("mouseleave", this._mouseLeav e.bind(this), false); | |
| 253 } else { | |
| 254 this.valueElement.title = description || ""; | |
| 255 } | |
| 256 | |
| 257 this.listItemElement.removeChildren(); | |
| 258 | |
| 259 this.hasChildren = this.property.value.hasChildren && !this.property .wasThrown; | |
| 260 } else { | |
| 261 if (this.property.getter) { | |
| 262 this.valueElement = WebInspector.ObjectPropertyTreeElement.creat eRemoteObjectAccessorPropertySpan(this.property.parentObject, [this.property.nam e], this._onInvokeGetterClick.bind(this)); | |
| 263 } else { | |
| 264 this.valueElement = createElementWithClass("span", "console-form atted-undefined"); | |
| 265 this.valueElement.textContent = WebInspector.UIString("<unreadab le>"); | |
| 266 this.valueElement.title = WebInspector.UIString("No property get ter"); | |
| 267 } | |
| 268 } | |
| 269 | |
| 270 this.listItemElement.appendChildren(this.nameElement, separatorElement, this.valueElement); | 209 this.listItemElement.appendChildren(this.nameElement, separatorElement, this.valueElement); |
| 271 }, | 210 }, |
| 272 | 211 |
| 273 _contextMenuFired: function(value, event) | 212 _contextMenuFired: function(value, event) |
| 274 { | 213 { |
| 275 var contextMenu = new WebInspector.ContextMenu(event); | 214 var contextMenu = new WebInspector.ContextMenu(event); |
| 276 this.populateContextMenu(contextMenu); | |
| 277 contextMenu.appendApplicableItems(value); | 215 contextMenu.appendApplicableItems(value); |
| 278 contextMenu.show(); | 216 contextMenu.show(); |
| 279 }, | 217 }, |
| 280 | 218 |
| 281 /** | |
| 282 * @param {!WebInspector.ContextMenu} contextMenu | |
| 283 */ | |
| 284 populateContextMenu: function(contextMenu) | |
| 285 { | |
| 286 }, | |
| 287 | |
| 288 _mouseMove: function(event) | |
| 289 { | |
| 290 this.property.value.highlightAsDOMNode(); | |
| 291 }, | |
| 292 | |
| 293 _mouseLeave: function(event) | |
| 294 { | |
| 295 this.property.value.hideDOMNodeHighlight(); | |
| 296 }, | |
| 297 | |
| 298 updateSiblings: function() | 219 updateSiblings: function() |
| 299 { | 220 { |
| 300 if (this.parent.root) | 221 if (this.parent.root) |
| 301 this.treeOutline.section.update(); | 222 this.treeOutline.section.update(); |
| 302 else | 223 else |
| 303 this.parent.shouldRefreshChildren = true; | 224 this.parent.shouldRefreshChildren = true; |
| 304 }, | 225 }, |
| 305 | 226 |
| 306 /** | 227 /** |
| 307 * @return {boolean} | |
| 308 */ | |
| 309 renderPromptAsBlock: function() | |
| 310 { | |
| 311 return false; | |
| 312 }, | |
| 313 | |
| 314 /** | |
| 315 * @return {{element: !Element, value: (string|undefined)}} | |
| 316 */ | |
| 317 elementAndValueToEdit: function() | |
| 318 { | |
| 319 return { | |
| 320 element: this.valueElement, | |
| 321 value: (typeof this.valueElement._originalTextContent === "string") ? this.valueElement._originalTextContent : undefined | |
| 322 }; | |
| 323 }, | |
| 324 | |
| 325 /** | |
| 326 * @param {!Event=} event | 228 * @param {!Event=} event |
| 327 */ | 229 */ |
| 328 startEditing: function(event) | 230 startEditing: function(event) |
| 329 { | 231 { |
| 330 var elementAndValueToEdit = this.elementAndValueToEdit(); | 232 var valueToEdit = (typeof this.valueElement._originalTextContent === "st ring") ? this.valueElement._originalTextContent : undefined; |
| 331 var elementToEdit = elementAndValueToEdit.element; | |
| 332 var valueToEdit = elementAndValueToEdit.value; | |
| 333 | 233 |
| 334 if (WebInspector.isBeingEdited(elementToEdit) || !this.treeOutline.secti on.editable || this._readOnly) | 234 if (WebInspector.isBeingEdited(this.valueElement) || !this.treeOutline.s ection.editable || this._readOnly) |
| 335 return; | 235 return; |
| 336 | 236 |
| 337 // Edit original source. | 237 // Edit original source. |
| 338 if (typeof valueToEdit !== "undefined") | 238 if (typeof valueToEdit !== "undefined") |
| 339 elementToEdit.setTextContentTruncatedIfNeeded(valueToEdit, WebInspec tor.UIString("<string is too large to edit>")); | 239 this.valueElement.setTextContentTruncatedIfNeeded(valueToEdit, WebIn spector.UIString("<string is too large to edit>")); |
| 340 | 240 |
| 341 var context = { expanded: this.expanded, elementToEdit: elementToEdit, p reviousContent: elementToEdit.textContent }; | 241 var context = { expanded: this.expanded, previousContent: this.valueElem ent.textContent }; |
| 342 | 242 |
| 343 // Lie about our children to prevent expanding on double click and to co llapse subproperties. | 243 // Lie about our children to prevent expanding on double click and to co llapse subproperties. |
| 344 this.hasChildren = false; | 244 this.hasChildren = false; |
| 345 | 245 |
| 346 this.listItemElement.classList.add("editing-sub-part"); | 246 this.listItemElement.classList.add("editing-sub-part"); |
| 347 | 247 |
| 348 this._prompt = new WebInspector.ObjectPropertyPrompt(this.renderPromptAs Block()); | 248 this._prompt = new WebInspector.ObjectPropertyPrompt(false); |
| 349 | 249 |
| 350 /** | 250 /** |
| 351 * @this {WebInspector.ObjectPropertyTreeElement} | 251 * @this {WebInspector.ObjectPropertyTreeElement} |
| 352 */ | 252 */ |
| 353 function blurListener() | 253 function blurListener() |
| 354 { | 254 { |
| 355 this.editingCommitted(null, elementToEdit.textContent, context.previ ousContent, context); | 255 this.editingCommitted(null, this.valueElement.textContent, context.p reviousContent, context); |
| 356 } | 256 } |
| 357 | 257 |
| 358 var proxyElement = this._prompt.attachAndStartEditing(elementToEdit, blu rListener.bind(this)); | 258 var proxyElement = this._prompt.attachAndStartEditing(this.valueElement, blurListener.bind(this)); |
| 359 this.listItemElement.getComponentSelection().setBaseAndExtent(elementToE dit, 0, elementToEdit, 1); | 259 this.listItemElement.getComponentSelection().setBaseAndExtent(this.value Element, 0, this.valueElement, 1); |
| 360 proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this, context), false); | 260 proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this, context), false); |
| 361 }, | 261 }, |
| 362 | 262 |
| 363 /** | 263 /** |
| 364 * @return {boolean} | 264 * @return {boolean} |
| 365 */ | 265 */ |
| 366 isEditing: function() | 266 isEditing: function() |
| 367 { | 267 { |
| 368 return !!this._prompt; | 268 return !!this._prompt; |
| 369 }, | 269 }, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 393 } | 293 } |
| 394 | 294 |
| 395 this.editingEnded(context); | 295 this.editingEnded(context); |
| 396 this.applyExpression(userInput); | 296 this.applyExpression(userInput); |
| 397 }, | 297 }, |
| 398 | 298 |
| 399 _promptKeyDown: function(context, event) | 299 _promptKeyDown: function(context, event) |
| 400 { | 300 { |
| 401 if (isEnterKey(event)) { | 301 if (isEnterKey(event)) { |
| 402 event.consume(true); | 302 event.consume(true); |
| 403 this.editingCommitted(null, context.elementToEdit.textContent, conte xt.previousContent, context); | 303 this.editingCommitted(null, this.valueElement.textContent, context.p reviousContent, context); |
| 404 return; | 304 return; |
| 405 } | 305 } |
| 406 if (event.keyIdentifier === "U+001B") { // Esc | 306 if (event.keyIdentifier === "U+001B") { // Esc |
| 407 event.consume(); | 307 event.consume(); |
| 408 this.editingCancelled(null, context); | 308 this.editingCancelled(null, context); |
| 409 return; | 309 return; |
| 410 } | 310 } |
| 411 }, | 311 }, |
| 412 | 312 |
| 413 /** | 313 /** |
| (...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1120 { | 1020 { |
| 1121 WebInspector.TextPrompt.call(this, WebInspector.ExecutionContextSelector.com pletionsForTextPromptInCurrentContext); | 1021 WebInspector.TextPrompt.call(this, WebInspector.ExecutionContextSelector.com pletionsForTextPromptInCurrentContext); |
| 1122 this.setSuggestBoxEnabled(true); | 1022 this.setSuggestBoxEnabled(true); |
| 1123 if (renderAsBlock) | 1023 if (renderAsBlock) |
| 1124 this.renderAsBlock(); | 1024 this.renderAsBlock(); |
| 1125 } | 1025 } |
| 1126 | 1026 |
| 1127 WebInspector.ObjectPropertyPrompt.prototype = { | 1027 WebInspector.ObjectPropertyPrompt.prototype = { |
| 1128 __proto__: WebInspector.TextPrompt.prototype | 1028 __proto__: WebInspector.TextPrompt.prototype |
| 1129 } | 1029 } |
| 1030 | |
| 1031 /** | |
| 1032 * @param {?string} name | |
| 1033 * @return {!Element} | |
| 1034 */ | |
| 1035 WebInspector.ObjectPropertiesSection.createNameElement = function(name) | |
| 1036 { | |
| 1037 var nameElement = createElementWithClass("span", "name"); | |
| 1038 if (/^\s|\s$|^$|\n/.test(name)) | |
| 1039 nameElement.createTextChildren("\"", name.replace(/\n/g, "\u21B5"), "\"" ); | |
|
pfeldman
2015/02/09 13:13:52
What is happening here?
| |
| 1040 else | |
| 1041 nameElement.textContent = name; | |
| 1042 return nameElement; | |
| 1043 } | |
| 1044 | |
| 1045 | |
| 1046 /** | |
| 1047 * @param {?WebInspector.RemoteObject} value | |
| 1048 * @param {boolean} wasThrown | |
| 1049 * @param {!Element} parentElement | |
| 1050 * @return {!Element} | |
| 1051 */ | |
| 1052 WebInspector.ObjectPropertiesSection.createValueElement = function(value, wasThr own, parentElement) | |
| 1053 { | |
| 1054 var valueElement; | |
| 1055 if (value) { | |
| 1056 valueElement = createElementWithClass("span", "value"); | |
| 1057 var type = value.type; | |
| 1058 var subtype = value.subtype; | |
| 1059 var description = value.description; | |
| 1060 var prefix; | |
| 1061 var valueText; | |
| 1062 var suffix; | |
| 1063 if (wasThrown) { | |
| 1064 prefix = "[Exception: "; | |
| 1065 valueText = description; | |
| 1066 suffix = "]"; | |
| 1067 } else if (type === "string" && typeof description === "string") { | |
| 1068 // Render \n as a nice unicode cr symbol. | |
| 1069 prefix = "\""; | |
| 1070 valueText = description.replace(/\n/g, "\u21B5"); | |
| 1071 suffix = "\""; | |
| 1072 valueElement._originalTextContent = "\"" + description + "\""; | |
| 1073 } else if (type === "function" && typeof description === "string") { | |
| 1074 // Render function description until the first \n. | |
| 1075 valueText = /.*/.exec(description)[0].replace(/\s+$/g, ""); | |
| 1076 valueElement._originalTextContent = description; | |
| 1077 } else if (type !== "object" || subtype !== "node") { | |
| 1078 valueText = description; | |
| 1079 } | |
| 1080 if (type !== "number" || valueText.indexOf("e") === -1) { | |
| 1081 valueElement.setTextContentTruncatedIfNeeded(valueText || ""); | |
| 1082 if (prefix) | |
| 1083 valueElement.insertBefore(createTextNode(prefix), valueElement.f irstChild); | |
| 1084 if (suffix) | |
| 1085 valueElement.createTextChild(suffix); | |
| 1086 } else { | |
| 1087 var numberParts = valueText.split("e"); | |
| 1088 var mantissa = valueElement.createChild("span", "scientific-notation -mantissa"); | |
| 1089 mantissa.textContent = numberParts[0]; | |
| 1090 var exponent = valueElement.createChild("span", "scientific-notation -exponent"); | |
| 1091 exponent.textContent = "e" + numberParts[1]; | |
| 1092 valueElement.classList.add("scientific-notation-number"); | |
| 1093 parentElement.classList.add("hbox"); | |
| 1094 } | |
| 1095 | |
| 1096 if (wasThrown) | |
| 1097 valueElement.classList.add("error"); | |
| 1098 if (subtype || type) | |
| 1099 valueElement.classList.add("console-formatted-" + (subtype || type)) ; | |
| 1100 | |
| 1101 if (type === "object" && subtype === "node" && description) { | |
| 1102 WebInspector.DOMPresentationUtils.createSpansForNodeTitle(valueEleme nt, description); | |
| 1103 valueElement.addEventListener("mousemove", mouseMove, false); | |
| 1104 valueElement.addEventListener("mouseleave", mouseLeave, false); | |
| 1105 } else { | |
| 1106 valueElement.title = description || ""; | |
| 1107 } | |
| 1108 } else { | |
| 1109 valueElement = createElementWithClass("span", "console-formatted-undefin ed"); | |
| 1110 valueElement.textContent = WebInspector.UIString("<unreadable>"); | |
| 1111 valueElement.title = WebInspector.UIString("No property getter"); | |
| 1112 } | |
| 1113 | |
| 1114 function mouseMove() | |
| 1115 { | |
| 1116 value.highlightAsDOMNode(); | |
| 1117 } | |
| 1118 | |
| 1119 function mouseLeave() | |
| 1120 { | |
| 1121 value.hideDOMNodeHighlight(); | |
| 1122 } | |
| 1123 | |
| 1124 return valueElement; | |
| 1125 } | |
| OLD | NEW |