Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(180)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/components/ObjectPropertiesSection.js

Issue 2139043002: DevTools: show alternate title onexpand of object in console (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address comments Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 25 matching lines...) Expand all
36 */ 36 */
37 WebInspector.ObjectPropertiesSection = function(object, title, linkifier, emptyP laceholder, ignoreHasOwnProperty, extraProperties) 37 WebInspector.ObjectPropertiesSection = function(object, title, linkifier, emptyP laceholder, ignoreHasOwnProperty, extraProperties)
38 { 38 {
39 this._object = object; 39 this._object = object;
40 this._editable = true; 40 this._editable = true;
41 TreeOutlineInShadow.call(this); 41 TreeOutlineInShadow.call(this);
42 this.hideOverflow(); 42 this.hideOverflow();
43 this.setFocusable(false); 43 this.setFocusable(false);
44 this._objectTreeElement = new WebInspector.ObjectPropertiesSection.RootEleme nt(object, linkifier, emptyPlaceholder, ignoreHasOwnProperty, extraProperties); 44 this._objectTreeElement = new WebInspector.ObjectPropertiesSection.RootEleme nt(object, linkifier, emptyPlaceholder, ignoreHasOwnProperty, extraProperties);
45 this.appendChild(this._objectTreeElement); 45 this.appendChild(this._objectTreeElement);
46 if (typeof title === "string" || !title) 46 if (typeof title === "string" || !title) {
47 this.element.createChild("span").textContent = title || ""; 47 this.titleElement = this.element.createChild("span");
48 else 48 this.titleElement.textContent = title || "";
49 } else {
50 this.titleElement = title;
49 this.element.appendChild(title); 51 this.element.appendChild(title);
52 }
53
54 if (object.description && WebInspector.ObjectPropertiesSection.needsAlternat eTitle(object)) {
55 this.expandedTitleElement = createElement("span");
56 this.expandedTitleElement.createTextChild(object.description);
57
58 var note = this.expandedTitleElement.createChild("span", "object-state-n ote");
59 note.classList.add("info-note");
60 note.title = WebInspector.UIString("Value below was evaluated just now." );
61 }
50 62
51 this.element._section = this; 63 this.element._section = this;
52 this.registerRequiredCSS("components/objectValue.css"); 64 this.registerRequiredCSS("components/objectValue.css");
53 this.registerRequiredCSS("components/objectPropertiesSection.css"); 65 this.registerRequiredCSS("components/objectPropertiesSection.css");
54 this.rootElement().childrenListElement.classList.add("source-code", "object- properties-section"); 66 this.rootElement().childrenListElement.classList.add("source-code", "object- properties-section");
55 } 67 }
56 68
57 /** @const */ 69 /** @const */
58 WebInspector.ObjectPropertiesSection._arrayLoadThreshold = 100; 70 WebInspector.ObjectPropertiesSection._arrayLoadThreshold = 100;
59 71
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 TreeElement.call(this, contentElement); 179 TreeElement.call(this, contentElement);
168 this.setExpandable(true); 180 this.setExpandable(true);
169 this.selectable = false; 181 this.selectable = false;
170 this.toggleOnClick = true; 182 this.toggleOnClick = true;
171 this.listItemElement.classList.add("object-properties-section-root-element") ; 183 this.listItemElement.classList.add("object-properties-section-root-element") ;
172 this._linkifier = linkifier; 184 this._linkifier = linkifier;
173 } 185 }
174 186
175 WebInspector.ObjectPropertiesSection.RootElement.prototype = { 187 WebInspector.ObjectPropertiesSection.RootElement.prototype = {
176 188
189 /**
190 * @override
191 */
177 onexpand: function() 192 onexpand: function()
178 { 193 {
179 if (this.treeOutline) 194 if (this.treeOutline) {
180 this.treeOutline.element.classList.add("expanded"); 195 this.treeOutline.element.classList.add("expanded");
181 }, 196 this._toggleExpandedTitleElement();
182 197 }
183 oncollapse: function()
184 {
185 if (this.treeOutline)
186 this.treeOutline.element.classList.remove("expanded");
187 }, 198 },
188 199
189 /** 200 /**
201 * @override
202 */
203 oncollapse: function()
204 {
205 if (this.treeOutline) {
206 this.treeOutline.element.classList.remove("expanded");
207 this._toggleExpandedTitleElement();
208 }
209 },
210
211 _toggleExpandedTitleElement: function()
212 {
213 if (!this.treeOutline.expandedTitleElement)
214 return;
215 var currentTitleElement = this.treeOutline.titleElement;
lushnikov 2016/07/30 00:29:49 AFAIU this code is there for the sake of editing t
luoe 2016/07/30 01:46:37 True, we can't edit titles via double click. I'll
216 var expandedTitleElement = this.treeOutline.expandedTitleElement;
217 var copyOfChildren = Array.prototype.slice.call(currentTitleElement.chil dNodes);
218 currentTitleElement.removeChildren();
219 currentTitleElement.appendChildren.apply(currentTitleElement, expandedTi tleElement.childNodes);
220 expandedTitleElement.removeChildren();
221 expandedTitleElement.appendChildren.apply(expandedTitleElement, copyOfCh ildren);
222 },
223
224 /**
190 * @override 225 * @override
191 * @param {!Event} e 226 * @param {!Event} e
192 * @return {boolean} 227 * @return {boolean}
193 */ 228 */
194 ondblclick: function(e) 229 ondblclick: function(e)
195 { 230 {
196 return true; 231 return true;
197 }, 232 },
198 233
199 onpopulate: function() 234 onpopulate: function()
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 var targetValue = this.property.name !== "__proto__" ? propertyValue : t his.property.parentObject; 311 var targetValue = this.property.name !== "__proto__" ? propertyValue : t his.property.parentObject;
277 WebInspector.ObjectPropertyTreeElement._populate(this, propertyValue, sk ipProto, this._linkifier, undefined, undefined, undefined, targetValue); 312 WebInspector.ObjectPropertyTreeElement._populate(this, propertyValue, sk ipProto, this._linkifier, undefined, undefined, undefined, targetValue);
278 }, 313 },
279 314
280 /** 315 /**
281 * @override 316 * @override
282 * @return {boolean} 317 * @return {boolean}
283 */ 318 */
284 ondblclick: function(event) 319 ondblclick: function(event)
285 { 320 {
286 var editableElement = this.valueElement; 321 var inEditableElement = event.target.isSelfOrDescendant(this.valueElemen t) || (this.expandedValueElement && event.target.isSelfOrDescendant(this.expande dValueElement));
287 if (!this.property.value.customPreview() && (this.property.writable || t his.property.setter) && event.target.isSelfOrDescendant(editableElement)) 322 if (!this.property.value.customPreview() && inEditableElement && (this.p roperty.writable || this.property.setter))
288 this._startEditing(); 323 this._startEditing();
289 return false; 324 return false;
290 }, 325 },
291 326
292 /** 327 /**
293 * @override 328 * @override
294 */ 329 */
295 onattach: function() 330 onattach: function()
296 { 331 {
297 this.update(); 332 this.update();
298 this._updateExpandable(); 333 this._updateExpandable();
299 }, 334 },
300 335
336 /**
337 * @override
338 */
339 onexpand: function()
340 {
341 this._toggleExpandedValueElement();
342 },
343
344 /**
345 * @override
346 */
347 oncollapse: function()
348 {
349 this._toggleExpandedValueElement();
350 },
351
352 _toggleExpandedValueElement: function()
353 {
354 if (!this.expandedValueElement)
355 return;
356 var copyOfChildren = Array.prototype.slice.call(this.valueElement.childN odes);
357 this.valueElement.removeChildren();
lushnikov 2016/07/30 00:29:49 same idea as for _toggleExpandedTitleElement might
luoe 2016/07/30 01:46:37 For values, we do currently support editing them v
lushnikov 2016/08/02 17:08:07 Yes, but maybe we don't want this scenario at all?
358 this.valueElement.appendChildren.apply(this.valueElement, this.expandedV alueElement.childNodes);
359 this.expandedValueElement.removeChildren();
360 this.expandedValueElement.appendChildren.apply(this.expandedValueElement , copyOfChildren);
361 },
362
301 update: function() 363 update: function()
302 { 364 {
303 this.nameElement = WebInspector.ObjectPropertiesSection.createNameElemen t(this.property.name); 365 this.nameElement = WebInspector.ObjectPropertiesSection.createNameElemen t(this.property.name);
304 if (!this.property.enumerable) 366 if (!this.property.enumerable)
305 this.nameElement.classList.add("object-properties-section-dimmed"); 367 this.nameElement.classList.add("object-properties-section-dimmed");
306 if (this.property.isAccessorProperty()) 368 if (this.property.isAccessorProperty())
307 this.nameElement.classList.add("properties-accessor-property-name"); 369 this.nameElement.classList.add("properties-accessor-property-name");
308 if (this.property.synthetic) 370 if (this.property.synthetic)
309 this.nameElement.classList.add("synthetic-property"); 371 this.nameElement.classList.add("synthetic-property");
310 372
311 this._updatePropertyPath(); 373 this._updatePropertyPath();
312 this.nameElement.addEventListener("contextmenu", this._contextMenuFired. bind(this, this.property), false); 374 this.nameElement.addEventListener("contextmenu", this._contextMenuFired. bind(this, this.property), false);
313 375
314 var separatorElement = createElementWithClass("span", "object-properties -section-separator"); 376 var separatorElement = createElementWithClass("span", "object-properties -section-separator");
315 separatorElement.textContent = ": "; 377 separatorElement.textContent = ": ";
316 378
317 if (this.property.value) { 379 if (this.property.value) {
318 this.valueElement = WebInspector.ObjectPropertiesSection.createValue ElementWithCustomSupport(this.property.value, this.property.wasThrown, this.list ItemElement, this._linkifier); 380 this.valueElement = WebInspector.ObjectPropertiesSection.createValue ElementWithCustomSupport(this.property.value, this.property.wasThrown, this.list ItemElement, this._linkifier);
319 this.valueElement.addEventListener("contextmenu", this._contextMenuF ired.bind(this, this.property), false); 381 this.valueElement.addEventListener("contextmenu", this._contextMenuF ired.bind(this, this.property), false);
320 } else if (this.property.getter) { 382 } else if (this.property.getter) {
321 this.valueElement = WebInspector.ObjectPropertyTreeElement.createRem oteObjectAccessorPropertySpan(this.property.parentObject, [this.property.name], this._onInvokeGetterClick.bind(this)); 383 this.valueElement = WebInspector.ObjectPropertyTreeElement.createRem oteObjectAccessorPropertySpan(this.property.parentObject, [this.property.name], this._onInvokeGetterClick.bind(this));
322 } else { 384 } else {
323 this.valueElement = createElementWithClass("span", "object-value-und efined"); 385 this.valueElement = createElementWithClass("span", "object-value-und efined");
324 this.valueElement.textContent = WebInspector.UIString("<unreadable>" ); 386 this.valueElement.textContent = WebInspector.UIString("<unreadable>" );
325 this.valueElement.title = WebInspector.UIString("No property getter" ); 387 this.valueElement.title = WebInspector.UIString("No property getter" );
326 } 388 }
327 389
390 var valueText = this.valueElement.textContent;
391 if (this.property.value && valueText && !this.property.wasThrown)
392 this.expandedValueElement = WebInspector.ObjectPropertiesSection.cre ateExpandedValueElement(this.property.value);
393
328 this.listItemElement.removeChildren(); 394 this.listItemElement.removeChildren();
329 this.listItemElement.appendChildren(this.nameElement, separatorElement, this.valueElement); 395 this.listItemElement.appendChildren(this.nameElement, separatorElement, this.valueElement);
330 }, 396 },
331 397
332 _updatePropertyPath: function() 398 _updatePropertyPath: function()
333 { 399 {
334 if (this.nameElement.title) 400 if (this.nameElement.title)
335 return; 401 return;
336 402
337 var useDotNotation = /^(_|\$|[A-Z])(_|\$|[A-Z]|\d)*$/i; 403 var useDotNotation = /^(_|\$|[A-Z])(_|\$|[A-Z]|\d)*$/i;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 435
370 this._editableDiv = this.listItemElement.createChild("span"); 436 this._editableDiv = this.listItemElement.createChild("span");
371 437
372 var text = this.property.value.description; 438 var text = this.property.value.description;
373 if (this.property.value.type === "string" && typeof text === "string") 439 if (this.property.value.type === "string" && typeof text === "string")
374 text = "\"" + text + "\""; 440 text = "\"" + text + "\"";
375 441
376 this._editableDiv.setTextContentTruncatedIfNeeded(text, WebInspector.UIS tring("<string is too large to edit>")); 442 this._editableDiv.setTextContentTruncatedIfNeeded(text, WebInspector.UIS tring("<string is too large to edit>"));
377 var originalContent = this._editableDiv.textContent; 443 var originalContent = this._editableDiv.textContent;
378 444
379 this.valueElement.classList.add("hidden");
380
381 // Lie about our children to prevent expanding on double click and to co llapse subproperties. 445 // Lie about our children to prevent expanding on double click and to co llapse subproperties.
382 this.setExpandable(false); 446 this.setExpandable(false);
383 this.listItemElement.classList.add("editing-sub-part"); 447 this.listItemElement.classList.add("editing-sub-part");
448 this.valueElement.classList.add("hidden");
384 449
385 this._prompt = new WebInspector.ObjectPropertyPrompt(); 450 this._prompt = new WebInspector.ObjectPropertyPrompt();
386 451
387 var proxyElement = this._prompt.attachAndStartEditing(this._editableDiv, this._editingCommitted.bind(this, originalContent)); 452 var proxyElement = this._prompt.attachAndStartEditing(this._editableDiv, this._editingCommitted.bind(this, originalContent));
388 this.listItemElement.getComponentSelection().setBaseAndExtent(this._edit ableDiv, 0, this._editableDiv, 1); 453 this.listItemElement.getComponentSelection().setBaseAndExtent(this._edit ableDiv, 0, this._editableDiv, 1);
389 proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this, originalContent), false); 454 proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this, originalContent), false);
390 }, 455 },
391 456
392 _editingEnded: function() 457 _editingEnded: function()
393 { 458 {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 return; 526 return;
462 } 527 }
463 528
464 if (!expression) { 529 if (!expression) {
465 // The property was deleted, so remove this tree element. 530 // The property was deleted, so remove this tree element.
466 this.parent.removeChild(this); 531 this.parent.removeChild(this);
467 } else { 532 } else {
468 // Call updateSiblings since their value might be based on the v alue that just changed. 533 // Call updateSiblings since their value might be based on the v alue that just changed.
469 var parent = this.parent; 534 var parent = this.parent;
470 parent.invalidateChildren(); 535 parent.invalidateChildren();
471 parent.expand(); 536 parent.onpopulate();
472 } 537 }
473 } 538 }
474 }, 539 },
475 540
476 /** 541 /**
477 * @param {?WebInspector.RemoteObject} result 542 * @param {?WebInspector.RemoteObject} result
478 * @param {boolean=} wasThrown 543 * @param {boolean=} wasThrown
479 */ 544 */
480 _onInvokeGetterClick: function(result, wasThrown) 545 _onInvokeGetterClick: function(result, wasThrown)
481 { 546 {
(...skipping 605 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 function mouseClick(event) 1152 function mouseClick(event)
1088 { 1153 {
1089 WebInspector.Revealer.reveal(value); 1154 WebInspector.Revealer.reveal(value);
1090 event.consume(true); 1155 event.consume(true);
1091 } 1156 }
1092 1157
1093 return valueElement; 1158 return valueElement;
1094 } 1159 }
1095 1160
1096 /** 1161 /**
1162 * @param {!WebInspector.RemoteObject} object
1163 * @return {boolean}
1164 */
1165 WebInspector.ObjectPropertiesSection.needsAlternateTitle = function(object)
lushnikov 2016/07/30 00:29:49 let's make this a private method of WI.ObjectPrope
luoe 2016/07/30 01:46:37 Done.
1166 {
1167 return object && object.hasChildren && !object.customPreview() && object.sub type !== "node" && object.type !== "function" && (object.type !== "object" || ob ject.preview);
1168 }
1169
1170 /**
1171 * @param {!WebInspector.RemoteObject} value
1172 * @return {?Element}
1173 */
1174 WebInspector.ObjectPropertiesSection.createExpandedValueElement = function(value )
lushnikov 2016/07/30 00:29:49 let's make this a private method of WI.ObjectPrope
luoe 2016/07/30 01:46:37 Done.
1175 {
1176 if (!WebInspector.ObjectPropertiesSection.needsAlternateTitle(value))
1177 return null;
1178
1179 var valueElement = createElementWithClass("span", "value");
1180 valueElement.setTextContentTruncatedIfNeeded(value.description || "");
1181 valueElement.classList.add("object-value-" + (value.subtype || value.type));
1182 valueElement.title = value.description || "";
1183 return valueElement;
1184 }
1185
1186 /**
1097 * @param {!WebInspector.RemoteObject} func 1187 * @param {!WebInspector.RemoteObject} func
1098 * @param {!Element} element 1188 * @param {!Element} element
1099 * @param {boolean} linkify 1189 * @param {boolean} linkify
1100 * @param {boolean=} includePreview 1190 * @param {boolean=} includePreview
1101 */ 1191 */
1102 WebInspector.ObjectPropertiesSection.formatObjectAsFunction = function(func, ele ment, linkify, includePreview) 1192 WebInspector.ObjectPropertiesSection.formatObjectAsFunction = function(func, ele ment, linkify, includePreview)
1103 { 1193 {
1104 func.debuggerModel().functionDetailsPromise(func).then(didGetDetails); 1194 func.debuggerModel().functionDetailsPromise(func).then(didGetDetails);
1105 1195
1106 /** 1196 /**
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 1350
1261 result = currentName + (result ? "." + result : ""); 1351 result = currentName + (result ? "." + result : "");
1262 current = current.parent; 1352 current = current.parent;
1263 } 1353 }
1264 var treeOutlineId = treeElement.treeOutline[WebInspector.ObjectPropertie sSectionExpandController._treeOutlineId]; 1354 var treeOutlineId = treeElement.treeOutline[WebInspector.ObjectPropertie sSectionExpandController._treeOutlineId];
1265 result = treeOutlineId + (result ? ":" + result : ""); 1355 result = treeOutlineId + (result ? ":" + result : "");
1266 treeElement[WebInspector.ObjectPropertiesSectionExpandController._cached PathSymbol] = result; 1356 treeElement[WebInspector.ObjectPropertiesSectionExpandController._cached PathSymbol] = result;
1267 return result; 1357 return result;
1268 } 1358 }
1269 } 1359 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698