| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2014 Google Inc. All rights reserved. | 3 * Copyright (C) 2014 Google Inc. All rights reserved. |
| 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 * | 8 * |
| 9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
| 10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 */ | 28 */ |
| 29 | 29 |
| 30 /** | 30 /** |
| 31 * @unrestricted | 31 * @unrestricted |
| 32 */ | 32 */ |
| 33 WebInspector.PropertiesWidget = class extends WebInspector.ThrottledWidget { | 33 Elements.PropertiesWidget = class extends UI.ThrottledWidget { |
| 34 constructor() { | 34 constructor() { |
| 35 super(); | 35 super(); |
| 36 | 36 |
| 37 WebInspector.targetManager.addModelListener( | 37 SDK.targetManager.addModelListener( |
| 38 WebInspector.DOMModel, WebInspector.DOMModel.Events.AttrModified, this._
onNodeChange, this); | 38 SDK.DOMModel, SDK.DOMModel.Events.AttrModified, this._onNodeChange, this
); |
| 39 WebInspector.targetManager.addModelListener( | 39 SDK.targetManager.addModelListener( |
| 40 WebInspector.DOMModel, WebInspector.DOMModel.Events.AttrRemoved, this._o
nNodeChange, this); | 40 SDK.DOMModel, SDK.DOMModel.Events.AttrRemoved, this._onNodeChange, this)
; |
| 41 WebInspector.targetManager.addModelListener( | 41 SDK.targetManager.addModelListener( |
| 42 WebInspector.DOMModel, WebInspector.DOMModel.Events.CharacterDataModifie
d, this._onNodeChange, this); | 42 SDK.DOMModel, SDK.DOMModel.Events.CharacterDataModified, this._onNodeCha
nge, this); |
| 43 WebInspector.targetManager.addModelListener( | 43 SDK.targetManager.addModelListener( |
| 44 WebInspector.DOMModel, WebInspector.DOMModel.Events.ChildNodeCountUpdate
d, this._onNodeChange, this); | 44 SDK.DOMModel, SDK.DOMModel.Events.ChildNodeCountUpdated, this._onNodeCha
nge, this); |
| 45 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, this._set
Node, this); | 45 UI.context.addFlavorChangeListener(SDK.DOMNode, this._setNode, this); |
| 46 this._node = WebInspector.context.flavor(WebInspector.DOMNode); | 46 this._node = UI.context.flavor(SDK.DOMNode); |
| 47 this.update(); | 47 this.update(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 /** | 50 /** |
| 51 * @param {!WebInspector.Event} event | 51 * @param {!Common.Event} event |
| 52 */ | 52 */ |
| 53 _setNode(event) { | 53 _setNode(event) { |
| 54 this._node = /** @type {?WebInspector.DOMNode} */ (event.data); | 54 this._node = /** @type {?SDK.DOMNode} */ (event.data); |
| 55 this.update(); | 55 this.update(); |
| 56 } | 56 } |
| 57 | 57 |
| 58 /** | 58 /** |
| 59 * @override | 59 * @override |
| 60 * @protected | 60 * @protected |
| 61 * @return {!Promise.<?>} | 61 * @return {!Promise.<?>} |
| 62 */ | 62 */ |
| 63 doUpdate() { | 63 doUpdate() { |
| 64 if (this._lastRequestedNode) { | 64 if (this._lastRequestedNode) { |
| 65 this._lastRequestedNode.target().runtimeAgent().releaseObjectGroup( | 65 this._lastRequestedNode.target().runtimeAgent().releaseObjectGroup( |
| 66 WebInspector.PropertiesWidget._objectGroupName); | 66 Elements.PropertiesWidget._objectGroupName); |
| 67 delete this._lastRequestedNode; | 67 delete this._lastRequestedNode; |
| 68 } | 68 } |
| 69 | 69 |
| 70 if (!this._node) { | 70 if (!this._node) { |
| 71 this.element.removeChildren(); | 71 this.element.removeChildren(); |
| 72 this.sections = []; | 72 this.sections = []; |
| 73 return Promise.resolve(); | 73 return Promise.resolve(); |
| 74 } | 74 } |
| 75 | 75 |
| 76 this._lastRequestedNode = this._node; | 76 this._lastRequestedNode = this._node; |
| 77 return this._node.resolveToObjectPromise(WebInspector.PropertiesWidget._obje
ctGroupName) | 77 return this._node.resolveToObjectPromise(Elements.PropertiesWidget._objectGr
oupName) |
| 78 .then(nodeResolved.bind(this)); | 78 .then(nodeResolved.bind(this)); |
| 79 | 79 |
| 80 /** | 80 /** |
| 81 * @param {?WebInspector.RemoteObject} object | 81 * @param {?SDK.RemoteObject} object |
| 82 * @this {WebInspector.PropertiesWidget} | 82 * @this {Elements.PropertiesWidget} |
| 83 */ | 83 */ |
| 84 function nodeResolved(object) { | 84 function nodeResolved(object) { |
| 85 if (!object) | 85 if (!object) |
| 86 return; | 86 return; |
| 87 | 87 |
| 88 /** | 88 /** |
| 89 * @suppressReceiverCheck | 89 * @suppressReceiverCheck |
| 90 * @this {*} | 90 * @this {*} |
| 91 */ | 91 */ |
| 92 function protoList() { | 92 function protoList() { |
| 93 var proto = this; | 93 var proto = this; |
| 94 var result = {__proto__: null}; | 94 var result = {__proto__: null}; |
| 95 var counter = 1; | 95 var counter = 1; |
| 96 while (proto) { | 96 while (proto) { |
| 97 result[counter++] = proto; | 97 result[counter++] = proto; |
| 98 proto = proto.__proto__; | 98 proto = proto.__proto__; |
| 99 } | 99 } |
| 100 return result; | 100 return result; |
| 101 } | 101 } |
| 102 var promise = object.callFunctionPromise(protoList).then(nodePrototypesRea
dy.bind(this)); | 102 var promise = object.callFunctionPromise(protoList).then(nodePrototypesRea
dy.bind(this)); |
| 103 object.release(); | 103 object.release(); |
| 104 return promise; | 104 return promise; |
| 105 } | 105 } |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * @param {!{object: ?WebInspector.RemoteObject, wasThrown: (boolean|undefin
ed)}} result | 108 * @param {!{object: ?SDK.RemoteObject, wasThrown: (boolean|undefined)}} res
ult |
| 109 * @this {WebInspector.PropertiesWidget} | 109 * @this {Elements.PropertiesWidget} |
| 110 */ | 110 */ |
| 111 function nodePrototypesReady(result) { | 111 function nodePrototypesReady(result) { |
| 112 if (!result.object || result.wasThrown) | 112 if (!result.object || result.wasThrown) |
| 113 return; | 113 return; |
| 114 | 114 |
| 115 var promise = result.object.getOwnPropertiesPromise().then(fillSection.bin
d(this)); | 115 var promise = result.object.getOwnPropertiesPromise().then(fillSection.bin
d(this)); |
| 116 result.object.release(); | 116 result.object.release(); |
| 117 return promise; | 117 return promise; |
| 118 } | 118 } |
| 119 | 119 |
| 120 /** | 120 /** |
| 121 * @param {!{properties: ?Array.<!WebInspector.RemoteObjectProperty>, intern
alProperties: ?Array.<!WebInspector.RemoteObjectProperty>}} result | 121 * @param {!{properties: ?Array.<!SDK.RemoteObjectProperty>, internalPropert
ies: ?Array.<!SDK.RemoteObjectProperty>}} result |
| 122 * @this {WebInspector.PropertiesWidget} | 122 * @this {Elements.PropertiesWidget} |
| 123 */ | 123 */ |
| 124 function fillSection(result) { | 124 function fillSection(result) { |
| 125 if (!result || !result.properties) | 125 if (!result || !result.properties) |
| 126 return; | 126 return; |
| 127 | 127 |
| 128 var properties = result.properties; | 128 var properties = result.properties; |
| 129 var expanded = []; | 129 var expanded = []; |
| 130 var sections = this.sections || []; | 130 var sections = this.sections || []; |
| 131 for (var i = 0; i < sections.length; ++i) | 131 for (var i = 0; i < sections.length; ++i) |
| 132 expanded.push(sections[i].expanded); | 132 expanded.push(sections[i].expanded); |
| 133 | 133 |
| 134 this.element.removeChildren(); | 134 this.element.removeChildren(); |
| 135 this.sections = []; | 135 this.sections = []; |
| 136 | 136 |
| 137 // Get array of property user-friendly names. | 137 // Get array of property user-friendly names. |
| 138 for (var i = 0; i < properties.length; ++i) { | 138 for (var i = 0; i < properties.length; ++i) { |
| 139 if (!parseInt(properties[i].name, 10)) | 139 if (!parseInt(properties[i].name, 10)) |
| 140 continue; | 140 continue; |
| 141 var property = properties[i].value; | 141 var property = properties[i].value; |
| 142 var title = property.description; | 142 var title = property.description; |
| 143 title = title.replace(/Prototype$/, ''); | 143 title = title.replace(/Prototype$/, ''); |
| 144 var section = new WebInspector.ObjectPropertiesSection(property, title); | 144 var section = new Components.ObjectPropertiesSection(property, title); |
| 145 section.element.classList.add('properties-widget-section'); | 145 section.element.classList.add('properties-widget-section'); |
| 146 this.sections.push(section); | 146 this.sections.push(section); |
| 147 this.element.appendChild(section.element); | 147 this.element.appendChild(section.element); |
| 148 if (expanded[this.sections.length - 1]) | 148 if (expanded[this.sections.length - 1]) |
| 149 section.expand(); | 149 section.expand(); |
| 150 section.addEventListener(TreeOutline.Events.ElementExpanded, this._prope
rtyExpanded, this); | 150 section.addEventListener(TreeOutline.Events.ElementExpanded, this._prope
rtyExpanded, this); |
| 151 } | 151 } |
| 152 } | 152 } |
| 153 } | 153 } |
| 154 | 154 |
| 155 /** | 155 /** |
| 156 * @param {!WebInspector.Event} event | 156 * @param {!Common.Event} event |
| 157 */ | 157 */ |
| 158 _propertyExpanded(event) { | 158 _propertyExpanded(event) { |
| 159 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.DOMProp
ertiesExpanded); | 159 Host.userMetrics.actionTaken(Host.UserMetrics.Action.DOMPropertiesExpanded); |
| 160 for (var section of this.sections) { | 160 for (var section of this.sections) { |
| 161 section.removeEventListener(TreeOutline.Events.ElementExpanded, this._prop
ertyExpanded, this); | 161 section.removeEventListener(TreeOutline.Events.ElementExpanded, this._prop
ertyExpanded, this); |
| 162 } | 162 } |
| 163 } | 163 } |
| 164 | 164 |
| 165 /** | 165 /** |
| 166 * @param {!WebInspector.Event} event | 166 * @param {!Common.Event} event |
| 167 */ | 167 */ |
| 168 _onNodeChange(event) { | 168 _onNodeChange(event) { |
| 169 if (!this._node) | 169 if (!this._node) |
| 170 return; | 170 return; |
| 171 var data = event.data; | 171 var data = event.data; |
| 172 var node = /** @type {!WebInspector.DOMNode} */ (data instanceof WebInspecto
r.DOMNode ? data : data.node); | 172 var node = /** @type {!SDK.DOMNode} */ (data instanceof SDK.DOMNode ? data :
data.node); |
| 173 if (this._node !== node) | 173 if (this._node !== node) |
| 174 return; | 174 return; |
| 175 this.update(); | 175 this.update(); |
| 176 } | 176 } |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 WebInspector.PropertiesWidget._objectGroupName = 'properties-sidebar-pane'; | 179 Elements.PropertiesWidget._objectGroupName = 'properties-sidebar-pane'; |
| OLD | NEW |