| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * @constructor | 6 * @constructor |
| 7 * @param {!WebInspector.RemoteObject} object | 7 * @param {!WebInspector.RemoteObject} object |
| 8 */ | 8 */ |
| 9 WebInspector.CustomPreviewSection = function(object) | 9 WebInspector.CustomPreviewSection = function(object) |
| 10 { | 10 { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 this._header.classList.add("custom-expandable-section-header"); | 30 this._header.classList.add("custom-expandable-section-header"); |
| 31 this._header.addEventListener("click", this._onClick.bind(this), false); | 31 this._header.addEventListener("click", this._onClick.bind(this), false); |
| 32 } | 32 } |
| 33 | 33 |
| 34 this._sectionElement.appendChild(this._header); | 34 this._sectionElement.appendChild(this._header); |
| 35 } | 35 } |
| 36 | 36 |
| 37 /** | 37 /** |
| 38 * @constructor | 38 * @constructor |
| 39 * @param {!WebInspector.RemoteObject} object | 39 * @param {!WebInspector.RemoteObject} object |
| 40 * @param {boolean=} expand | |
| 41 * @return {!Element} | |
| 42 */ | 40 */ |
| 43 WebInspector.CustomPreviewSection.createInShadow = function(object, expand) | 41 WebInspector.CustomPreviewComponent = function(object) |
| 44 { | 42 { |
| 45 var customPreviewSection = new WebInspector.CustomPreviewSection(object); | 43 this._object = object; |
| 46 var element = WebInspector.CustomPreviewSection._createComponentRoot(); | 44 this._customPreviewSection = new WebInspector.CustomPreviewSection(object); |
| 47 var shadowRoot = element.createShadowRoot(); | 45 this.element = createElementWithClass("span", "source-code"); |
| 46 WebInspector.installComponentRootStyles(this.element); |
| 47 this.element.addEventListener("contextmenu", this._contextMenuEventFired.bin
d(this), false); |
| 48 |
| 49 var shadowRoot = this.element.createShadowRoot(); |
| 48 shadowRoot.appendChild(WebInspector.Widget.createStyleElement("components/cu
stomPreviewSection.css")); | 50 shadowRoot.appendChild(WebInspector.Widget.createStyleElement("components/cu
stomPreviewSection.css")); |
| 49 shadowRoot.appendChild(customPreviewSection.element()); | 51 shadowRoot.appendChild(this._customPreviewSection.element()); |
| 50 | |
| 51 if (expand && object.customPreview().hasBody) | |
| 52 customPreviewSection._loadBody(); | |
| 53 return element; | |
| 54 } | 52 } |
| 55 | 53 |
| 56 /** | 54 WebInspector.CustomPreviewComponent.prototype = { |
| 57 * @return {!Element} | 55 expandIfPossible: function() |
| 58 */ | 56 { |
| 59 WebInspector.CustomPreviewSection._createComponentRoot = function() | 57 if (this._object.customPreview().hasBody && this._customPreviewSection) |
| 60 { | 58 this._customPreviewSection._loadBody(); |
| 61 var element = createElement("span"); | 59 }, |
| 62 WebInspector.installComponentRootStyles(element); | 60 |
| 63 element.classList.add("source-code"); | 61 /** |
| 64 return element; | 62 * @param {!Event} event |
| 63 */ |
| 64 _contextMenuEventFired: function(event) |
| 65 { |
| 66 var contextMenu = new WebInspector.ContextMenu(event); |
| 67 if (this._customPreviewSection) |
| 68 contextMenu.appendItem(WebInspector.UIString.capitalize("Show as Jav
ascript ^object" ), this._disassemble.bind(this)); |
| 69 contextMenu.appendApplicableItems(this._object); |
| 70 contextMenu.show(); |
| 71 }, |
| 72 |
| 73 _disassemble: function() |
| 74 { |
| 75 this.element.shadowRoot.textContent = ""; |
| 76 this._customPreviewSection = null; |
| 77 this.element.shadowRoot.appendChild(WebInspector.ObjectPropertiesSection
.defaultObjectPresentation(this._object)); |
| 78 } |
| 65 } | 79 } |
| 66 | 80 |
| 67 WebInspector.CustomPreviewSection._tagsWhiteList = new Set(["span", "div", "ol",
"li","table", "tr", "td"]); | 81 WebInspector.CustomPreviewSection._tagsWhiteList = new Set(["span", "div", "ol",
"li","table", "tr", "td"]); |
| 68 | 82 |
| 69 WebInspector.CustomPreviewSection.prototype = { | 83 WebInspector.CustomPreviewSection.prototype = { |
| 70 | 84 |
| 71 /** | 85 /** |
| 72 * @return {!Element} | 86 * @return {!Element} |
| 73 */ | 87 */ |
| 74 element: function() | 88 element: function() |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 * @return {!Node} | 139 * @return {!Node} |
| 126 */ | 140 */ |
| 127 _layoutObjectTag: function(objectTag) | 141 _layoutObjectTag: function(objectTag) |
| 128 { | 142 { |
| 129 objectTag.shift(); | 143 objectTag.shift(); |
| 130 var attributes = objectTag.shift(); | 144 var attributes = objectTag.shift(); |
| 131 var remoteObject = this._object.target().runtimeModel.createRemoteObject
(/** @type {!RuntimeAgent.RemoteObject} */ (attributes)); | 145 var remoteObject = this._object.target().runtimeModel.createRemoteObject
(/** @type {!RuntimeAgent.RemoteObject} */ (attributes)); |
| 132 if (remoteObject.customPreview()) | 146 if (remoteObject.customPreview()) |
| 133 return (new WebInspector.CustomPreviewSection(remoteObject)).element
(); | 147 return (new WebInspector.CustomPreviewSection(remoteObject)).element
(); |
| 134 | 148 |
| 135 var header = createElement("span"); | 149 var sectionElement = WebInspector.ObjectPropertiesSection.defaultObjectP
resentation(remoteObject); |
| 136 var componentRoot = WebInspector.CustomPreviewSection._createComponentRo
ot(); | 150 sectionElement.classList.toggle("custom-expandable-section-standard-sect
ion", remoteObject.hasChildren); |
| 137 header.appendChild(componentRoot); | |
| 138 var shadowRoot = componentRoot.createShadowRoot(); | |
| 139 shadowRoot.appendChild(WebInspector.Widget.createStyleElement("component
s/objectValue.css")); | |
| 140 shadowRoot.appendChild(WebInspector.ObjectPropertiesSection.createValueE
lement(remoteObject, false)); | |
| 141 if (!remoteObject.hasChildren) | |
| 142 return header; | |
| 143 | |
| 144 var objectPropertiesSection = new WebInspector.ObjectPropertiesSection(r
emoteObject, header); | |
| 145 var sectionElement = objectPropertiesSection.element; | |
| 146 sectionElement.classList.add("custom-expandable-section-standard-section
"); | |
| 147 return sectionElement; | 151 return sectionElement; |
| 148 }, | 152 }, |
| 149 | 153 |
| 150 /** | 154 /** |
| 151 * @param {!Node} parentElement | 155 * @param {!Node} parentElement |
| 152 * @param {!Array.<*>} jsonMLTags | 156 * @param {!Array.<*>} jsonMLTags |
| 153 */ | 157 */ |
| 154 _appendJsonMLTags: function(parentElement, jsonMLTags) | 158 _appendJsonMLTags: function(parentElement, jsonMLTags) |
| 155 { | 159 { |
| 156 for (var i = 0; i < jsonMLTags.length; ++i) | 160 for (var i = 0; i < jsonMLTags.length; ++i) |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 { | 244 { |
| 241 if (!bodyJsonML) | 245 if (!bodyJsonML) |
| 242 return; | 246 return; |
| 243 | 247 |
| 244 this._cachedContent = this._renderJSONMLTag(bodyJsonML); | 248 this._cachedContent = this._renderJSONMLTag(bodyJsonML); |
| 245 this._sectionElement.appendChild(this._cachedContent); | 249 this._sectionElement.appendChild(this._cachedContent); |
| 246 this._toggleExpand(); | 250 this._toggleExpand(); |
| 247 } | 251 } |
| 248 } | 252 } |
| 249 } | 253 } |
| OLD | NEW |