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

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: DevTools: show alternate title onexpand of object in console 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 11 matching lines...) Expand all
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */ 25 */
26 26
27 /** 27 /**
28 * @constructor 28 * @constructor
29 * @extends {TreeOutlineInShadow} 29 * @extends {TreeOutlineInShadow}
30 * @param {!WebInspector.RemoteObject} object 30 * @param {!WebInspector.RemoteObject} object
31 * @param {?string|!Element=} title 31 * @param {?string|!Element=} title
32 * @param {?Element=} expandedTitle
32 * @param {!WebInspector.Linkifier=} linkifier 33 * @param {!WebInspector.Linkifier=} linkifier
33 * @param {?string=} emptyPlaceholder 34 * @param {?string=} emptyPlaceholder
34 * @param {boolean=} ignoreHasOwnProperty 35 * @param {boolean=} ignoreHasOwnProperty
35 * @param {!Array.<!WebInspector.RemoteObjectProperty>=} extraProperties 36 * @param {!Array.<!WebInspector.RemoteObjectProperty>=} extraProperties
36 */ 37 */
37 WebInspector.ObjectPropertiesSection = function(object, title, linkifier, emptyP laceholder, ignoreHasOwnProperty, extraProperties) 38 WebInspector.ObjectPropertiesSection = function(object, title, expandedTitle, li nkifier, emptyPlaceholder, ignoreHasOwnProperty, extraProperties)
lushnikov 2016/07/20 23:54:26 Let's look if we can reduce amount of arguments he
luoe 2016/07/22 22:30:58 Good call, by moving needsAlternateTitle() into OP
38 { 39 {
39 this._object = object; 40 this._object = object;
40 this._editable = true; 41 this._editable = true;
41 TreeOutlineInShadow.call(this); 42 TreeOutlineInShadow.call(this);
42 this.hideOverflow(); 43 this.hideOverflow();
43 this.setFocusable(false); 44 this.setFocusable(false);
44 this._objectTreeElement = new WebInspector.ObjectPropertiesSection.RootEleme nt(object, linkifier, emptyPlaceholder, ignoreHasOwnProperty, extraProperties); 45 this._objectTreeElement = new WebInspector.ObjectPropertiesSection.RootEleme nt(object, linkifier, emptyPlaceholder, ignoreHasOwnProperty, extraProperties);
45 this.appendChild(this._objectTreeElement); 46 this.appendChild(this._objectTreeElement);
46 if (typeof title === "string" || !title) 47 if (typeof title === "string" || !title) {
47 this.element.createChild("span").textContent = title || ""; 48 this.titleElement = this.element.createChild("span");
48 else 49 this.titleElement.textContent = title || "";
50 } else {
51 this.titleElement = title;
49 this.element.appendChild(title); 52 this.element.appendChild(title);
53 }
54
55 if (expandedTitle)
56 this.expandedTitleElement = expandedTitle;
50 57
51 this.element._section = this; 58 this.element._section = this;
52 this.registerRequiredCSS("components/objectValue.css"); 59 this.registerRequiredCSS("components/objectValue.css");
53 this.registerRequiredCSS("components/objectPropertiesSection.css"); 60 this.registerRequiredCSS("components/objectPropertiesSection.css");
54 this.rootElement().childrenListElement.classList.add("source-code", "object- properties-section"); 61 this.rootElement().childrenListElement.classList.add("source-code", "object- properties-section");
55 } 62 }
56 63
57 /** @const */ 64 /** @const */
58 WebInspector.ObjectPropertiesSection._arrayLoadThreshold = 100; 65 WebInspector.ObjectPropertiesSection._arrayLoadThreshold = 100;
59 66
60 /** 67 /**
61 * @param {!WebInspector.RemoteObject} object 68 * @param {!WebInspector.RemoteObject} object
62 * @param {!WebInspector.Linkifier=} linkifier 69 * @param {!WebInspector.Linkifier=} linkifier
63 * @param {boolean=} skipProto 70 * @param {boolean=} skipProto
64 * @return {!Element} 71 * @return {!Element}
65 */ 72 */
66 WebInspector.ObjectPropertiesSection.defaultObjectPresentation = function(object , linkifier, skipProto) 73 WebInspector.ObjectPropertiesSection.defaultObjectPresentation = function(object , linkifier, skipProto)
67 { 74 {
68 var componentRoot = createElementWithClass("span", "source-code"); 75 var componentRoot = createElementWithClass("span", "source-code");
69 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(componentRoot, "components/objectValue.css"); 76 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(componentRoot, "components/objectValue.css");
70 shadowRoot.appendChild(WebInspector.ObjectPropertiesSection.createValueEleme nt(object, false)); 77 shadowRoot.appendChild(WebInspector.ObjectPropertiesSection.createValueEleme nt(object, false));
71 if (!object.hasChildren) 78 if (!object.hasChildren)
72 return componentRoot; 79 return componentRoot;
73 80
74 var objectPropertiesSection = new WebInspector.ObjectPropertiesSection(objec t, componentRoot, linkifier); 81 var objectPropertiesSection = new WebInspector.ObjectPropertiesSection(objec t, componentRoot, null, linkifier);
75 objectPropertiesSection.editable = false; 82 objectPropertiesSection.editable = false;
76 if (skipProto) 83 if (skipProto)
77 objectPropertiesSection.skipProto(); 84 objectPropertiesSection.skipProto();
78 85
79 return objectPropertiesSection.element; 86 return objectPropertiesSection.element;
80 } 87 }
81 88
82 WebInspector.ObjectPropertiesSection.prototype = { 89 WebInspector.ObjectPropertiesSection.prototype = {
83 skipProto: function() 90 skipProto: function()
84 { 91 {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 TreeElement.call(this, contentElement); 174 TreeElement.call(this, contentElement);
168 this.setExpandable(true); 175 this.setExpandable(true);
169 this.selectable = false; 176 this.selectable = false;
170 this.toggleOnClick = true; 177 this.toggleOnClick = true;
171 this.listItemElement.classList.add("object-properties-section-root-element") ; 178 this.listItemElement.classList.add("object-properties-section-root-element") ;
172 this._linkifier = linkifier; 179 this._linkifier = linkifier;
173 } 180 }
174 181
175 WebInspector.ObjectPropertiesSection.RootElement.prototype = { 182 WebInspector.ObjectPropertiesSection.RootElement.prototype = {
176 183
184 /**
185 * @override
186 */
177 onexpand: function() 187 onexpand: function()
178 { 188 {
179 if (this.treeOutline) 189 if (this.treeOutline) {
180 this.treeOutline.element.classList.add("expanded"); 190 this.treeOutline.element.classList.add("expanded");
181 }, 191 if (this.treeOutline.expandedTitleElement)
182 192 this.treeOutline.titleElement.swapChildren(this.treeOutline.expa ndedTitleElement);
183 oncollapse: function() 193 }
184 {
185 if (this.treeOutline)
186 this.treeOutline.element.classList.remove("expanded");
187 }, 194 },
188 195
189 /** 196 /**
197 * @override
198 */
199 oncollapse: function()
200 {
201 if (this.treeOutline) {
202 this.treeOutline.element.classList.remove("expanded");
203 if (this.treeOutline.expandedTitleElement)
204 this.treeOutline.titleElement.swapChildren(this.treeOutline.expa ndedTitleElement);
205 }
206 },
207
208 /**
190 * @override 209 * @override
191 * @param {!Event} e 210 * @param {!Event} e
192 * @return {boolean} 211 * @return {boolean}
193 */ 212 */
194 ondblclick: function(e) 213 ondblclick: function(e)
195 { 214 {
196 return true; 215 return true;
197 }, 216 },
198 217
199 onpopulate: function() 218 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; 295 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); 296 WebInspector.ObjectPropertyTreeElement._populate(this, propertyValue, sk ipProto, this._linkifier, undefined, undefined, undefined, targetValue);
278 }, 297 },
279 298
280 /** 299 /**
281 * @override 300 * @override
282 * @return {boolean} 301 * @return {boolean}
283 */ 302 */
284 ondblclick: function(event) 303 ondblclick: function(event)
285 { 304 {
286 var editableElement = this.valueElement; 305 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)) 306 if (!this.property.value.customPreview() && inEditableElement && (this.p roperty.writable || this.property.setter))
288 this._startEditing(); 307 this._startEditing();
289 return false; 308 return false;
290 }, 309 },
291 310
292 /** 311 /**
293 * @override 312 * @override
294 */ 313 */
295 onattach: function() 314 onattach: function()
296 { 315 {
297 this.update(); 316 this.update();
298 this._updateExpandable(); 317 this._updateExpandable();
299 }, 318 },
300 319
320 /**
321 * @override
322 */
323 onexpand: function()
324 {
325 if (this.expandedValueElement)
326 this.valueElement.swapChildren(this.expandedValueElement);
327 },
328
329 /**
330 * @override
331 */
332 oncollapse: function()
333 {
334 if (this.expandedValueElement)
335 this.valueElement.swapChildren(this.expandedValueElement);
336 },
337
301 update: function() 338 update: function()
302 { 339 {
303 this.nameElement = WebInspector.ObjectPropertiesSection.createNameElemen t(this.property.name); 340 this.nameElement = WebInspector.ObjectPropertiesSection.createNameElemen t(this.property.name);
304 if (!this.property.enumerable) 341 if (!this.property.enumerable)
305 this.nameElement.classList.add("object-properties-section-dimmed"); 342 this.nameElement.classList.add("object-properties-section-dimmed");
306 if (this.property.isAccessorProperty()) 343 if (this.property.isAccessorProperty())
307 this.nameElement.classList.add("properties-accessor-property-name"); 344 this.nameElement.classList.add("properties-accessor-property-name");
308 if (this.property.synthetic) 345 if (this.property.synthetic)
309 this.nameElement.classList.add("synthetic-property"); 346 this.nameElement.classList.add("synthetic-property");
310 347
311 this._updatePropertyPath(); 348 this._updatePropertyPath();
312 this.nameElement.addEventListener("contextmenu", this._contextMenuFired. bind(this, this.property), false); 349 this.nameElement.addEventListener("contextmenu", this._contextMenuFired. bind(this, this.property), false);
313 350
314 var separatorElement = createElementWithClass("span", "object-properties -section-separator"); 351 var separatorElement = createElementWithClass("span", "object-properties -section-separator");
315 separatorElement.textContent = ": "; 352 separatorElement.textContent = ": ";
316 353
317 if (this.property.value) { 354 if (this.property.value) {
318 this.valueElement = WebInspector.ObjectPropertiesSection.createValue ElementWithCustomSupport(this.property.value, this.property.wasThrown, this.list ItemElement, this._linkifier); 355 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); 356 this.valueElement.addEventListener("contextmenu", this._contextMenuF ired.bind(this, this.property), false);
320 } else if (this.property.getter) { 357 } else if (this.property.getter) {
321 this.valueElement = WebInspector.ObjectPropertyTreeElement.createRem oteObjectAccessorPropertySpan(this.property.parentObject, [this.property.name], this._onInvokeGetterClick.bind(this)); 358 this.valueElement = WebInspector.ObjectPropertyTreeElement.createRem oteObjectAccessorPropertySpan(this.property.parentObject, [this.property.name], this._onInvokeGetterClick.bind(this));
322 } else { 359 } else {
323 this.valueElement = createElementWithClass("span", "object-value-und efined"); 360 this.valueElement = createElementWithClass("span", "object-value-und efined");
324 this.valueElement.textContent = WebInspector.UIString("<unreadable>" ); 361 this.valueElement.textContent = WebInspector.UIString("<unreadable>" );
325 this.valueElement.title = WebInspector.UIString("No property getter" ); 362 this.valueElement.title = WebInspector.UIString("No property getter" );
326 } 363 }
327 364
365 var valueText = this.valueElement.textContent;
366 if (this.property.value && valueText && !this.property.wasThrown)
367 this.expandedValueElement = WebInspector.ObjectPropertiesSection.cre ateExpandableValueElement(this.property.value);
368
328 this.listItemElement.removeChildren(); 369 this.listItemElement.removeChildren();
329 this.listItemElement.appendChildren(this.nameElement, separatorElement, this.valueElement); 370 this.listItemElement.appendChildren(this.nameElement, separatorElement, this.valueElement);
330 }, 371 },
331 372
332 _updatePropertyPath: function() 373 _updatePropertyPath: function()
333 { 374 {
334 if (this.nameElement.title) 375 if (this.nameElement.title)
335 return; 376 return;
336 377
337 var useDotNotation = /^(_|\$|[A-Z])(_|\$|[A-Z]|\d)*$/i; 378 var useDotNotation = /^(_|\$|[A-Z])(_|\$|[A-Z]|\d)*$/i;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 410
370 this._editableDiv = this.listItemElement.createChild("span"); 411 this._editableDiv = this.listItemElement.createChild("span");
371 412
372 var text = this.property.value.description; 413 var text = this.property.value.description;
373 if (this.property.value.type === "string" && typeof text === "string") 414 if (this.property.value.type === "string" && typeof text === "string")
374 text = "\"" + text + "\""; 415 text = "\"" + text + "\"";
375 416
376 this._editableDiv.setTextContentTruncatedIfNeeded(text, WebInspector.UIS tring("<string is too large to edit>")); 417 this._editableDiv.setTextContentTruncatedIfNeeded(text, WebInspector.UIS tring("<string is too large to edit>"));
377 var originalContent = this._editableDiv.textContent; 418 var originalContent = this._editableDiv.textContent;
378 419
379 this.valueElement.classList.add("hidden");
380
381 // Lie about our children to prevent expanding on double click and to co llapse subproperties. 420 // Lie about our children to prevent expanding on double click and to co llapse subproperties.
382 this.setExpandable(false); 421 this.setExpandable(false);
383 this.listItemElement.classList.add("editing-sub-part"); 422 this.listItemElement.classList.add("editing-sub-part");
423 this.valueElement.classList.add("hidden");
384 424
385 this._prompt = new WebInspector.ObjectPropertyPrompt(); 425 this._prompt = new WebInspector.ObjectPropertyPrompt();
386 426
387 var proxyElement = this._prompt.attachAndStartEditing(this._editableDiv, this._editingCommitted.bind(this, originalContent)); 427 var proxyElement = this._prompt.attachAndStartEditing(this._editableDiv, this._editingCommitted.bind(this, originalContent));
388 this.listItemElement.getComponentSelection().setBaseAndExtent(this._edit ableDiv, 0, this._editableDiv, 1); 428 this.listItemElement.getComponentSelection().setBaseAndExtent(this._edit ableDiv, 0, this._editableDiv, 1);
389 proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this, originalContent), false); 429 proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this, originalContent), false);
390 }, 430 },
391 431
392 _editingEnded: function() 432 _editingEnded: function()
393 { 433 {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 return; 501 return;
462 } 502 }
463 503
464 if (!expression) { 504 if (!expression) {
465 // The property was deleted, so remove this tree element. 505 // The property was deleted, so remove this tree element.
466 this.parent.removeChild(this); 506 this.parent.removeChild(this);
467 } else { 507 } else {
468 // Call updateSiblings since their value might be based on the v alue that just changed. 508 // Call updateSiblings since their value might be based on the v alue that just changed.
469 var parent = this.parent; 509 var parent = this.parent;
470 parent.invalidateChildren(); 510 parent.invalidateChildren();
471 parent.expand(); 511 parent.onpopulate();
472 } 512 }
473 }; 513 };
474 }, 514 },
475 515
476 /** 516 /**
477 * @param {?WebInspector.RemoteObject} result 517 * @param {?WebInspector.RemoteObject} result
478 * @param {boolean=} wasThrown 518 * @param {boolean=} wasThrown
479 */ 519 */
480 _onInvokeGetterClick: function(result, wasThrown) 520 _onInvokeGetterClick: function(result, wasThrown)
481 { 521 {
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 function mouseClick(event) 1251 function mouseClick(event)
1212 { 1252 {
1213 WebInspector.Revealer.reveal(value); 1253 WebInspector.Revealer.reveal(value);
1214 event.consume(true); 1254 event.consume(true);
1215 } 1255 }
1216 1256
1217 return valueElement; 1257 return valueElement;
1218 } 1258 }
1219 1259
1220 /** 1260 /**
1261 * @param {!WebInspector.RemoteObject} value
1262 * @return {boolean}
1263 */
1264 WebInspector.ObjectPropertiesSection.needsAlternateTitle = function(value)
1265 {
1266 return value && !value.customPreview() && value.hasChildren && value.subtype !== "node" && value.type !== "function";
1267 }
1268
1269 /**
1270 * @param {!WebInspector.RemoteObject} value
1271 * @return {?Element}
1272 */
1273 WebInspector.ObjectPropertiesSection.createExpandableValueElement = function(val ue)
1274 {
1275 if (!WebInspector.ObjectPropertiesSection.needsAlternateTitle(value))
1276 return null;
1277
1278 var valueElement = createElementWithClass("span", "value");
1279 valueElement.setTextContentTruncatedIfNeeded(value.description || "");
1280 valueElement.classList.add("object-value-" + (value.subtype || value.type));
1281 valueElement.title = value.description || "";
1282 return valueElement;
1283 }
1284
1285 /**
1221 * @param {!WebInspector.RemoteObject} func 1286 * @param {!WebInspector.RemoteObject} func
1222 * @param {!Element} element 1287 * @param {!Element} element
1223 * @param {boolean} linkify 1288 * @param {boolean} linkify
1224 * @param {boolean=} includePreview 1289 * @param {boolean=} includePreview
1225 */ 1290 */
1226 WebInspector.ObjectPropertiesSection.formatObjectAsFunction = function(func, ele ment, linkify, includePreview) 1291 WebInspector.ObjectPropertiesSection.formatObjectAsFunction = function(func, ele ment, linkify, includePreview)
1227 { 1292 {
1228 func.functionDetails(didGetDetails); 1293 func.functionDetails(didGetDetails);
1229 1294
1230 /** 1295 /**
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 1449
1385 result = currentName + (result ? "." + result : ""); 1450 result = currentName + (result ? "." + result : "");
1386 current = current.parent; 1451 current = current.parent;
1387 } 1452 }
1388 var treeOutlineId = treeElement.treeOutline[WebInspector.ObjectPropertie sSectionExpandController._treeOutlineId]; 1453 var treeOutlineId = treeElement.treeOutline[WebInspector.ObjectPropertie sSectionExpandController._treeOutlineId];
1389 result = treeOutlineId + (result ? ":" + result : ""); 1454 result = treeOutlineId + (result ? ":" + result : "");
1390 treeElement[WebInspector.ObjectPropertiesSectionExpandController._cached PathSymbol] = result; 1455 treeElement[WebInspector.ObjectPropertiesSectionExpandController._cached PathSymbol] = result;
1391 return result; 1456 return result;
1392 } 1457 }
1393 } 1458 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698