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

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: 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 {?string|!Element=} expandedTitle
lushnikov 2016/07/12 02:51:55 let's only have Element here
luoe 2016/07/13 18:06:28 Done.
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)
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 (typeof expandedTitle === "string") {
lushnikov 2016/07/12 02:51:55 this will go away once you have only Element as in
luoe 2016/07/13 18:06:28 Done.
56 this.expandedTitleElement = this.element.createChild("span");
57 this.expandedTitleElement.textContent = expandedTitle || "";
58 } else if (!!expandedTitle) {
59 this.expandedTitleElement = expandedTitle;
60 this.element.appendChild(expandedTitle);
61 }
62
63 if (this.expandedTitleElement)
64 this.expandedTitleElement.classList.add("hidden");
lushnikov 2016/07/12 02:51:55 Let's use hidden attribute here and everywhere th
luoe 2016/07/13 18:06:28 Done.
50 65
51 this.element._section = this; 66 this.element._section = this;
52 this.registerRequiredCSS("components/objectValue.css"); 67 this.registerRequiredCSS("components/objectValue.css");
53 this.registerRequiredCSS("components/objectPropertiesSection.css"); 68 this.registerRequiredCSS("components/objectPropertiesSection.css");
54 this.rootElement().childrenListElement.classList.add("source-code", "object- properties-section"); 69 this.rootElement().childrenListElement.classList.add("source-code", "object- properties-section");
55 } 70 }
56 71
57 /** @const */ 72 /** @const */
58 WebInspector.ObjectPropertiesSection._arrayLoadThreshold = 100; 73 WebInspector.ObjectPropertiesSection._arrayLoadThreshold = 100;
59 74
60 /** 75 /**
61 * @param {!WebInspector.RemoteObject} object 76 * @param {!WebInspector.RemoteObject} object
62 * @param {!WebInspector.Linkifier=} linkifier 77 * @param {!WebInspector.Linkifier=} linkifier
63 * @param {boolean=} skipProto 78 * @param {boolean=} skipProto
64 * @return {!Element} 79 * @return {!Element}
65 */ 80 */
66 WebInspector.ObjectPropertiesSection.defaultObjectPresentation = function(object , linkifier, skipProto) 81 WebInspector.ObjectPropertiesSection.defaultObjectPresentation = function(object , linkifier, skipProto)
67 { 82 {
68 var componentRoot = createElementWithClass("span", "source-code"); 83 var componentRoot = createElementWithClass("span", "source-code");
69 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(componentRoot, "components/objectValue.css"); 84 var shadowRoot = WebInspector.createShadowRootWithCoreStyles(componentRoot, "components/objectValue.css");
70 shadowRoot.appendChild(WebInspector.ObjectPropertiesSection.createValueEleme nt(object, false)); 85 shadowRoot.appendChild(WebInspector.ObjectPropertiesSection.createValueEleme nt(object, false));
71 if (!object.hasChildren) 86 if (!object.hasChildren)
72 return componentRoot; 87 return componentRoot;
73 88
74 var objectPropertiesSection = new WebInspector.ObjectPropertiesSection(objec t, componentRoot, linkifier); 89 var objectPropertiesSection = new WebInspector.ObjectPropertiesSection(objec t, componentRoot, null, linkifier);
75 objectPropertiesSection.editable = false; 90 objectPropertiesSection.editable = false;
76 if (skipProto) 91 if (skipProto)
77 objectPropertiesSection.skipProto(); 92 objectPropertiesSection.skipProto();
78 93
79 return objectPropertiesSection.element; 94 return objectPropertiesSection.element;
80 } 95 }
81 96
82 WebInspector.ObjectPropertiesSection.prototype = { 97 WebInspector.ObjectPropertiesSection.prototype = {
83 skipProto: function() 98 skipProto: function()
84 { 99 {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 this.selectable = false; 184 this.selectable = false;
170 this.toggleOnClick = true; 185 this.toggleOnClick = true;
171 this.listItemElement.classList.add("object-properties-section-root-element") ; 186 this.listItemElement.classList.add("object-properties-section-root-element") ;
172 this._linkifier = linkifier; 187 this._linkifier = linkifier;
173 } 188 }
174 189
175 WebInspector.ObjectPropertiesSection.RootElement.prototype = { 190 WebInspector.ObjectPropertiesSection.RootElement.prototype = {
176 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");
196 if (this.treeOutline.expandedTitleElement) {
197 this.treeOutline.titleElement.classList.add("hidden");
198 this.treeOutline.expandedTitleElement.classList.remove("hidden") ;
199 }
200 }
181 }, 201 },
182 202
183 oncollapse: function() 203 oncollapse: function()
184 { 204 {
185 if (this.treeOutline) 205 if (this.treeOutline) {
186 this.treeOutline.element.classList.remove("expanded"); 206 this.treeOutline.element.classList.remove("expanded");
207 if (this.treeOutline.expandedTitleElement) {
208 this.treeOutline.titleElement.classList.remove("hidden");
209 this.treeOutline.expandedTitleElement.classList.add("hidden");
210 }
211 }
187 }, 212 },
188 213
189 /** 214 /**
190 * @override 215 * @override
191 * @param {!Event} e 216 * @param {!Event} e
192 * @return {boolean} 217 * @return {boolean}
193 */ 218 */
194 ondblclick: function(e) 219 ondblclick: function(e)
195 { 220 {
196 return true; 221 return true;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 var targetValue = this.property.name !== "__proto__" ? propertyValue : t his.property.parentObject; 301 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); 302 WebInspector.ObjectPropertyTreeElement._populate(this, propertyValue, sk ipProto, this._linkifier, undefined, undefined, undefined, targetValue);
278 }, 303 },
279 304
280 /** 305 /**
281 * @override 306 * @override
282 * @return {boolean} 307 * @return {boolean}
283 */ 308 */
284 ondblclick: function(event) 309 ondblclick: function(event)
285 { 310 {
286 var editableElement = this.valueElement; 311 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)) 312 if (!this.property.value.customPreview() && inEditableElement && (this.p roperty.writable || this.property.setter))
288 this._startEditing(); 313 this._startEditing();
289 return false; 314 return false;
290 }, 315 },
291 316
292 /** 317 /**
293 * @override 318 * @override
294 */ 319 */
295 onattach: function() 320 onattach: function()
296 { 321 {
297 this.update(); 322 this.update();
298 this._updateExpandable(); 323 this._updateExpandable();
299 }, 324 },
300 325
326 /**
327 * @override
328 */
329 onexpand: function()
330 {
331 if (this.expandedValueElement) {
332 this.valueElement.classList.add("hidden");
lushnikov 2016/07/12 02:51:55 let's extract a _showExpandedValueElement(visible)
luoe 2016/07/13 18:06:28 No longer needed when children are swapped.
333 this.expandedValueElement.classList.remove("hidden");
334 }
335 },
336
337 /**
338 * @override
339 */
340 oncollapse: function()
341 {
342 if (this.expandedValueElement) {
343 this.valueElement.classList.remove("hidden");
344 this.expandedValueElement.classList.add("hidden");
345 }
346 },
347
301 update: function() 348 update: function()
302 { 349 {
303 this.nameElement = WebInspector.ObjectPropertiesSection.createNameElemen t(this.property.name); 350 this.nameElement = WebInspector.ObjectPropertiesSection.createNameElemen t(this.property.name);
304 if (!this.property.enumerable) 351 if (!this.property.enumerable)
305 this.nameElement.classList.add("object-properties-section-dimmed"); 352 this.nameElement.classList.add("object-properties-section-dimmed");
306 if (this.property.isAccessorProperty()) 353 if (this.property.isAccessorProperty())
307 this.nameElement.classList.add("properties-accessor-property-name"); 354 this.nameElement.classList.add("properties-accessor-property-name");
308 if (this.property.synthetic) 355 if (this.property.synthetic)
309 this.nameElement.classList.add("synthetic-property"); 356 this.nameElement.classList.add("synthetic-property");
310 357
311 this._updatePropertyPath(); 358 this._updatePropertyPath();
312 this.nameElement.addEventListener("contextmenu", this._contextMenuFired. bind(this, this.property), false); 359 this.nameElement.addEventListener("contextmenu", this._contextMenuFired. bind(this, this.property), false);
313 360
314 var separatorElement = createElementWithClass("span", "object-properties -section-separator"); 361 var separatorElement = createElementWithClass("span", "object-properties -section-separator");
315 separatorElement.textContent = ": "; 362 separatorElement.textContent = ": ";
316 363
317 if (this.property.value) { 364 if (this.property.value) {
318 this.valueElement = WebInspector.ObjectPropertiesSection.createValue ElementWithCustomSupport(this.property.value, this.property.wasThrown, this.list ItemElement, this._linkifier); 365 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); 366 this.valueElement.addEventListener("contextmenu", this._contextMenuF ired.bind(this, this.property), false);
320 } else if (this.property.getter) { 367 } else if (this.property.getter) {
321 this.valueElement = WebInspector.ObjectPropertyTreeElement.createRem oteObjectAccessorPropertySpan(this.property.parentObject, [this.property.name], this._onInvokeGetterClick.bind(this)); 368 this.valueElement = WebInspector.ObjectPropertyTreeElement.createRem oteObjectAccessorPropertySpan(this.property.parentObject, [this.property.name], this._onInvokeGetterClick.bind(this));
322 } else { 369 } else {
323 this.valueElement = createElementWithClass("span", "object-value-und efined"); 370 this.valueElement = createElementWithClass("span", "object-value-und efined");
324 this.valueElement.textContent = WebInspector.UIString("<unreadable>" ); 371 this.valueElement.textContent = WebInspector.UIString("<unreadable>" );
325 this.valueElement.title = WebInspector.UIString("No property getter" ); 372 this.valueElement.title = WebInspector.UIString("No property getter" );
326 } 373 }
327 374
375 var valueText = this.valueElement.textContent;
376 if (this.property.value && valueText && valueText !== this.property.valu e.description && !this.property.wasThrown)
lushnikov 2016/07/12 02:51:55 lets drop this optimization as well
luoe 2016/07/13 18:06:28 Done.
377 this.expandedValueElement = WebInspector.ObjectPropertiesSection.cre ateExpandableTitleOrValueElement(this.property.value);
378
328 this.listItemElement.removeChildren(); 379 this.listItemElement.removeChildren();
329 this.listItemElement.appendChildren(this.nameElement, separatorElement, this.valueElement); 380 this.listItemElement.appendChildren(this.nameElement, separatorElement, this.valueElement);
381 if (this.expandedValueElement)
382 this.listItemElement.appendChild(this.expandedValueElement);
330 }, 383 },
331 384
332 _updatePropertyPath: function() 385 _updatePropertyPath: function()
333 { 386 {
334 if (this.nameElement.title) 387 if (this.nameElement.title)
335 return; 388 return;
336 389
337 var useDotNotation = /^(_|\$|[A-Z])(_|\$|[A-Z]|\d)*$/i; 390 var useDotNotation = /^(_|\$|[A-Z])(_|\$|[A-Z]|\d)*$/i;
338 var isInteger = /^[1-9]\d*$/; 391 var isInteger = /^[1-9]\d*$/;
339 var name = this.property.name; 392 var name = this.property.name;
(...skipping 29 matching lines...) Expand all
369 422
370 this._editableDiv = this.listItemElement.createChild("span"); 423 this._editableDiv = this.listItemElement.createChild("span");
371 424
372 var text = this.property.value.description; 425 var text = this.property.value.description;
373 if (this.property.value.type === "string" && typeof text === "string") 426 if (this.property.value.type === "string" && typeof text === "string")
374 text = "\"" + text + "\""; 427 text = "\"" + text + "\"";
375 428
376 this._editableDiv.setTextContentTruncatedIfNeeded(text, WebInspector.UIS tring("<string is too large to edit>")); 429 this._editableDiv.setTextContentTruncatedIfNeeded(text, WebInspector.UIS tring("<string is too large to edit>"));
377 var originalContent = this._editableDiv.textContent; 430 var originalContent = this._editableDiv.textContent;
378 431
379 this.valueElement.classList.add("hidden");
380
381 // Lie about our children to prevent expanding on double click and to co llapse subproperties. 432 // Lie about our children to prevent expanding on double click and to co llapse subproperties.
382 this.setExpandable(false); 433 this.setExpandable(false);
383 this.listItemElement.classList.add("editing-sub-part"); 434 this.listItemElement.classList.add("editing-sub-part");
435 this.valueElement.classList.add("hidden");
436 if (this.expandedValueElement)
lushnikov 2016/07/12 02:51:55 i believe we'll always have expandedValueElement o
luoe 2016/07/13 18:06:28 We still need this because there are a few excepti
437 this.expandedValueElement.classList.add("hidden");
384 438
385 this._prompt = new WebInspector.ObjectPropertyPrompt(); 439 this._prompt = new WebInspector.ObjectPropertyPrompt();
386 440
387 var proxyElement = this._prompt.attachAndStartEditing(this._editableDiv, this._editingCommitted.bind(this, originalContent)); 441 var proxyElement = this._prompt.attachAndStartEditing(this._editableDiv, this._editingCommitted.bind(this, originalContent));
388 this.listItemElement.getComponentSelection().setBaseAndExtent(this._edit ableDiv, 0, this._editableDiv, 1); 442 this.listItemElement.getComponentSelection().setBaseAndExtent(this._edit ableDiv, 0, this._editableDiv, 1);
389 proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this, originalContent), false); 443 proxyElement.addEventListener("keydown", this._promptKeyDown.bind(this, originalContent), false);
390 }, 444 },
391 445
392 _editingEnded: function() 446 _editingEnded: function()
393 { 447 {
394 this._prompt.detach(); 448 this._prompt.detach();
395 delete this._prompt; 449 delete this._prompt;
396 this._editableDiv.remove(); 450 this._editableDiv.remove();
397 this._updateExpandable(); 451 this._updateExpandable();
398 this.listItemElement.scrollLeft = 0; 452 this.listItemElement.scrollLeft = 0;
399 this.listItemElement.classList.remove("editing-sub-part"); 453 this.listItemElement.classList.remove("editing-sub-part");
400 }, 454 },
401 455
402 _editingCancelled: function() 456 _editingCancelled: function()
403 { 457 {
404 this.valueElement.classList.remove("hidden"); 458 if (this.expanded && this.expandedValueElement)
459 this.expandedValueElement.classList.remove("hidden");
460 else
461 this.valueElement.classList.remove("hidden");
405 this._editingEnded(); 462 this._editingEnded();
406 }, 463 },
407 464
408 /** 465 /**
409 * @param {string} originalContent 466 * @param {string} originalContent
410 */ 467 */
411 _editingCommitted: function(originalContent) 468 _editingCommitted: function(originalContent)
412 { 469 {
413 var userInput = this._prompt.text(); 470 var userInput = this._prompt.text();
414 if (userInput === originalContent) { 471 if (userInput === originalContent) {
(...skipping 796 matching lines...) Expand 10 before | Expand all | Expand 10 after
1211 function mouseClick(event) 1268 function mouseClick(event)
1212 { 1269 {
1213 WebInspector.Revealer.reveal(value); 1270 WebInspector.Revealer.reveal(value);
1214 event.consume(true); 1271 event.consume(true);
1215 } 1272 }
1216 1273
1217 return valueElement; 1274 return valueElement;
1218 } 1275 }
1219 1276
1220 /** 1277 /**
1278 * @param {!WebInspector.RemoteObject} value
1279 * @return {boolean}
1280 */
1281 WebInspector.ObjectPropertiesSection.needsAlternateTitle = function(value)
1282 {
1283 return value && !value.customPreview() && value.hasChildren && value.subtype !== "node" && value.type !== "function";
1284 }
1285
1286 /**
1287 * @param {!WebInspector.RemoteObject} value
1288 * @return {?Element}
1289 */
1290 WebInspector.ObjectPropertiesSection.createExpandableTitleOrValueElement = funct ion(value)
1291 {
1292 if (!WebInspector.ObjectPropertiesSection.needsAlternateTitle(value))
1293 return null;
1294
1295 var valueElement = createElementWithClass("span", "value");
1296 var type = value.type;
lushnikov 2016/07/12 02:51:55 let's inline type, subtype & desct
luoe 2016/07/13 18:06:28 Done.
1297 var subtype = value.subtype;
1298 var description = value.description;
1299
1300 valueElement.setTextContentTruncatedIfNeeded(description || "");
1301 valueElement.classList.add("object-value-" + (subtype || type));
1302 valueElement.classList.add("hidden");
1303 valueElement.title = description || "";
1304 return valueElement;
1305 }
1306
1307 /**
1221 * @param {!WebInspector.RemoteObject} func 1308 * @param {!WebInspector.RemoteObject} func
1222 * @param {!Element} element 1309 * @param {!Element} element
1223 * @param {boolean} linkify 1310 * @param {boolean} linkify
1224 * @param {boolean=} includePreview 1311 * @param {boolean=} includePreview
1225 */ 1312 */
1226 WebInspector.ObjectPropertiesSection.formatObjectAsFunction = function(func, ele ment, linkify, includePreview) 1313 WebInspector.ObjectPropertiesSection.formatObjectAsFunction = function(func, ele ment, linkify, includePreview)
1227 { 1314 {
1228 func.functionDetails(didGetDetails); 1315 func.functionDetails(didGetDetails);
1229 1316
1230 /** 1317 /**
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
1384 1471
1385 result = currentName + (result ? "." + result : ""); 1472 result = currentName + (result ? "." + result : "");
1386 current = current.parent; 1473 current = current.parent;
1387 } 1474 }
1388 var treeOutlineId = treeElement.treeOutline[WebInspector.ObjectPropertie sSectionExpandController._treeOutlineId]; 1475 var treeOutlineId = treeElement.treeOutline[WebInspector.ObjectPropertie sSectionExpandController._treeOutlineId];
1389 result = treeOutlineId + (result ? ":" + result : ""); 1476 result = treeOutlineId + (result ? ":" + result : "");
1390 treeElement[WebInspector.ObjectPropertiesSectionExpandController._cached PathSymbol] = result; 1477 treeElement[WebInspector.ObjectPropertiesSectionExpandController._cached PathSymbol] = result;
1391 return result; 1478 return result;
1392 } 1479 }
1393 } 1480 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698