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) 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 * | 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 16 matching lines...) Expand all Loading... |
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 * @constructor | 31 * @constructor |
32 * @extends {WebInspector.ElementsSidebarPane} | 32 * @extends {WebInspector.ElementsSidebarPane} |
33 */ | 33 */ |
34 WebInspector.EventListenersSidebarPane = function() | 34 WebInspector.EventListenersSidebarPane = function() |
35 { | 35 { |
36 WebInspector.ElementsSidebarPane.call(this, WebInspector.UIString("Event Lis
teners")); | 36 WebInspector.ElementsSidebarPane.call(this, WebInspector.UIString("Event Lis
teners")); |
37 this.registerRequiredCSS("components/objectValue.css"); | |
38 this.bodyElement.classList.add("events-pane"); | 37 this.bodyElement.classList.add("events-pane"); |
39 | 38 |
40 this._treeOutline = new TreeOutline(true); | |
41 this._treeOutline.element.classList.add("event-listener-tree", "outline-disc
losure", "monospace"); | |
42 this.bodyElement.appendChild(this._treeOutline.element); | |
43 | |
44 var refreshButton = this.titleElement.createChild("button", "pane-title-butt
on refresh"); | 39 var refreshButton = this.titleElement.createChild("button", "pane-title-butt
on refresh"); |
45 refreshButton.addEventListener("click", this.update.bind(this), false); | 40 refreshButton.addEventListener("click", this.update.bind(this), false); |
46 refreshButton.title = WebInspector.UIString("Refresh"); | 41 refreshButton.title = WebInspector.UIString("Refresh"); |
47 | 42 |
48 this.settingsSelectElement = this.titleElement.createChild("select", "select
-filter"); | 43 this.settingsSelectElement = this.titleElement.createChild("select", "select
-filter"); |
49 | 44 |
50 var option = this.settingsSelectElement.createChild("option"); | 45 var option = this.settingsSelectElement.createChild("option"); |
51 option.value = "all"; | 46 option.value = "all"; |
52 option.label = WebInspector.UIString("All Nodes"); | 47 option.label = WebInspector.UIString("All Nodes"); |
53 | 48 |
54 option = this.settingsSelectElement.createChild("option"); | 49 option = this.settingsSelectElement.createChild("option"); |
55 option.value = "selected"; | 50 option.value = "selected"; |
56 option.label = WebInspector.UIString("Selected Node Only"); | 51 option.label = WebInspector.UIString("Selected Node Only"); |
57 | 52 |
58 this._eventListenersFilterSetting = WebInspector.settings.createSetting("eve
ntListenersFilter", "all"); | 53 this._eventListenersFilterSetting = WebInspector.settings.createSetting("eve
ntListenersFilter", "all"); |
59 var filter = this._eventListenersFilterSetting.get(); | 54 var filter = this._eventListenersFilterSetting.get(); |
60 if (filter === "all") | 55 if (filter === "all") |
61 this.settingsSelectElement[0].selected = true; | 56 this.settingsSelectElement[0].selected = true; |
62 else if (filter === "selected") | 57 else if (filter === "selected") |
63 this.settingsSelectElement[1].selected = true; | 58 this.settingsSelectElement[1].selected = true; |
64 this.settingsSelectElement.addEventListener("click", consumeEvent, false); | 59 this.settingsSelectElement.addEventListener("click", consumeEvent, false); |
65 this.settingsSelectElement.addEventListener("change", this._changeSetting.bi
nd(this), false); | 60 this.settingsSelectElement.addEventListener("change", this._changeSetting.bi
nd(this), false); |
66 | 61 |
67 this._linkifier = new WebInspector.Linkifier(); | 62 this._eventListenersView = new WebInspector.EventListenersView(this.bodyElem
ent, WebInspector.EventListenersSidebarPane._objectGroupName); |
68 } | 63 } |
69 | 64 |
70 WebInspector.EventListenersSidebarPane._objectGroupName = "event-listeners-sideb
ar-pane"; | 65 WebInspector.EventListenersSidebarPane._objectGroupName = "event-listeners-panel
"; |
71 | 66 |
72 WebInspector.EventListenersSidebarPane.prototype = { | 67 WebInspector.EventListenersSidebarPane.prototype = { |
73 /** | 68 /** |
74 * @override | 69 * @override |
75 * @param {!WebInspector.Throttler.FinishCallback} finishCallback | 70 * @param {!WebInspector.Throttler.FinishCallback} finishCallback |
76 * @protected | 71 * @protected |
77 */ | 72 */ |
78 doUpdate: function(finishCallback) | 73 doUpdate: function(finishCallback) |
79 { | 74 { |
80 if (this._lastRequestedNode) { | 75 if (this._lastRequestedNode) { |
81 this._lastRequestedNode.target().runtimeAgent().releaseObjectGroup(W
ebInspector.EventListenersSidebarPane._objectGroupName); | 76 this._lastRequestedNode.target().runtimeAgent().releaseObjectGroup(W
ebInspector.EventListenersSidebarPane._objectGroupName); |
82 delete this._lastRequestedNode; | 77 delete this._lastRequestedNode; |
83 } | 78 } |
84 | 79 this._eventListenersView.reset(); |
85 this._linkifier.reset(); | |
86 | |
87 var body = this.bodyElement; | |
88 body.removeChildren(); | |
89 this._treeOutline.removeChildren(); | |
90 | |
91 var node = this.node(); | 80 var node = this.node(); |
92 if (!node) { | 81 if (!node) { |
| 82 this._eventListenersArivedForTest(); |
93 finishCallback(); | 83 finishCallback(); |
94 return; | 84 return; |
95 } | 85 } |
96 | 86 |
97 this._lastRequestedNode = node; | 87 var selectedNodeOnly = "selected" === this._eventListenersFilterSetting.
get(); |
98 node.eventListeners(WebInspector.EventListenersSidebarPane._objectGroupN
ame, this._onEventListeners.bind(this, finishCallback)); | 88 var promises = []; |
99 }, | 89 promises.push(this._eventListenersView.addNodeEventListeners(node)); |
100 | 90 if (!selectedNodeOnly) { |
101 /** | 91 var currentNode = node.parentNode; |
102 * @param {!WebInspector.Throttler.FinishCallback} finishCallback | 92 while (currentNode) { |
103 * @param {?Array.<!WebInspector.DOMModel.EventListener>} eventListeners | 93 promises.push(this._eventListenersView.addNodeEventListeners(cur
rentNode)); |
104 */ | 94 currentNode = currentNode.parentNode; |
105 _onEventListeners: function(finishCallback, eventListeners) | 95 } |
106 { | 96 } |
107 if (!eventListeners) { | 97 Promise.all(promises).then(mycallback.bind(this)); |
| 98 /** |
| 99 * @this {WebInspector.EventListenersSidebarPane} |
| 100 */ |
| 101 function mycallback() |
| 102 { |
| 103 this._lastRequestedNode = node; |
| 104 this._eventListenersArivedForTest(); |
108 finishCallback(); | 105 finishCallback(); |
109 return; | |
110 } | 106 } |
111 | |
112 var body = this.bodyElement; | |
113 var node = this.node(); | |
114 var selectedNodeOnly = "selected" === this._eventListenersFilterSetting.
get(); | |
115 var treeItemMap = new Map(); | |
116 eventListeners.stableSort(compareListeners); | |
117 | |
118 /** | |
119 * @param {!WebInspector.DOMModel.EventListener} a | |
120 * @param {!WebInspector.DOMModel.EventListener} b | |
121 * @return {number} | |
122 */ | |
123 function compareListeners(a, b) | |
124 { | |
125 var aType = a.payload().type; | |
126 var bType = b.payload().type; | |
127 return aType === bType ? 0 : | |
128 aType > bType ? 1 : -1; | |
129 } | |
130 | |
131 for (var i = 0; i < eventListeners.length; ++i) { | |
132 var eventListener = eventListeners[i]; | |
133 if (selectedNodeOnly && (node.id !== eventListener.payload().nodeId)
) | |
134 continue; | |
135 if (eventListener.location().script().isInternalScript()) | |
136 continue; // ignore event listeners generated by monitorEvent | |
137 var type = eventListener.payload().type; | |
138 var treeItem = treeItemMap.get(type); | |
139 if (!treeItem) { | |
140 treeItem = new WebInspector.EventListenersTreeElement(type, node
.id, this._linkifier); | |
141 treeItemMap.set(type, treeItem); | |
142 this._treeOutline.appendChild(treeItem); | |
143 } | |
144 treeItem.addListener(eventListener); | |
145 } | |
146 if (treeItemMap.size === 0) | |
147 body.createChild("div", "info").textContent = WebInspector.UIString(
"No Event Listeners"); | |
148 else | |
149 body.appendChild(this._treeOutline.element); | |
150 | |
151 finishCallback(); | |
152 }, | 107 }, |
153 | 108 |
154 _changeSetting: function() | 109 _changeSetting: function() |
155 { | 110 { |
156 var selectedOption = this.settingsSelectElement[this.settingsSelectEleme
nt.selectedIndex]; | 111 var selectedOption = this.settingsSelectElement[this.settingsSelectEleme
nt.selectedIndex]; |
157 this._eventListenersFilterSetting.set(selectedOption.value); | 112 this._eventListenersFilterSetting.set(selectedOption.value); |
158 this.update(); | 113 this.update(); |
159 }, | 114 }, |
160 | 115 |
| 116 _eventListenersArivedForTest: function() |
| 117 { |
| 118 }, |
| 119 |
161 __proto__: WebInspector.ElementsSidebarPane.prototype | 120 __proto__: WebInspector.ElementsSidebarPane.prototype |
162 } | 121 } |
163 | |
164 /** | |
165 * @constructor | |
166 * @extends {TreeElement} | |
167 */ | |
168 WebInspector.EventListenersTreeElement = function(title, nodeId, linkifier) | |
169 { | |
170 this._nodeId = nodeId; | |
171 this._linkifier = linkifier; | |
172 | |
173 TreeElement.call(this, title); | |
174 this.toggleOnClick = true; | |
175 this.selectable = false; | |
176 } | |
177 | |
178 WebInspector.EventListenersTreeElement.prototype = { | |
179 /** | |
180 * @param {!WebInspector.DOMModel.EventListener} eventListener | |
181 */ | |
182 addListener: function(eventListener) | |
183 { | |
184 var treeElement = new WebInspector.EventListenerBar(eventListener, this.
_nodeId, this._linkifier); | |
185 this.appendChild(treeElement); | |
186 }, | |
187 | |
188 __proto__: TreeElement.prototype | |
189 } | |
190 | |
191 /** | |
192 * @constructor | |
193 * @extends {TreeElement} | |
194 * @param {!WebInspector.DOMModel.EventListener} eventListener | |
195 * @param {!DOMAgent.NodeId} nodeId | |
196 * @param {!WebInspector.Linkifier} linkifier | |
197 */ | |
198 WebInspector.EventListenerBar = function(eventListener, nodeId, linkifier) | |
199 { | |
200 TreeElement.call(this, "", true); | |
201 | |
202 var target = eventListener.target(); | |
203 this._runtimeModel = target.runtimeModel; | |
204 this._eventListener = eventListener; | |
205 this._nodeId = nodeId; | |
206 this._setNodeTitle(linkifier); | |
207 this.editable = false; | |
208 } | |
209 | |
210 WebInspector.EventListenerBar.prototype = { | |
211 onpopulate: function() | |
212 { | |
213 /** | |
214 * @param {?WebInspector.RemoteObject} nodeObject | |
215 * @this {WebInspector.EventListenerBar} | |
216 */ | |
217 function updateWithNodeObject(nodeObject) | |
218 { | |
219 var properties = []; | |
220 var payload = this._eventListener.payload(); | |
221 | |
222 properties.push(this._runtimeModel.createRemotePropertyFromPrimitive
Value("useCapture", payload.useCapture)); | |
223 properties.push(this._runtimeModel.createRemotePropertyFromPrimitive
Value("attachment", payload.isAttribute ? "attribute" : "script")); | |
224 if (nodeObject) | |
225 properties.push(new WebInspector.RemoteObjectProperty("node", no
deObject)); | |
226 if (typeof payload.handler !== "undefined") { | |
227 var remoteObject = this._runtimeModel.createRemoteObject(payload
.handler); | |
228 properties.push(new WebInspector.RemoteObjectProperty("handler",
remoteObject)); | |
229 } | |
230 | |
231 WebInspector.ObjectPropertyTreeElement.populateWithProperties(this,
properties, [], true, null); | |
232 } | |
233 this._eventListener.node().resolveToObject(WebInspector.EventListenersSi
debarPane._objectGroupName, updateWithNodeObject.bind(this)); | |
234 }, | |
235 | |
236 /** | |
237 * @param {!WebInspector.Linkifier} linkifier | |
238 */ | |
239 _setNodeTitle: function(linkifier) | |
240 { | |
241 var node = this._eventListener.node(); | |
242 if (!node) | |
243 return; | |
244 | |
245 this.listItemElement.removeChildren(); | |
246 var title = this.listItemElement.createChild("span"); | |
247 var subtitle = this.listItemElement.createChild("span", "event-listener-
tree-subtitle"); | |
248 subtitle.appendChild(linkifier.linkifyRawLocation(this._eventListener.lo
cation(), this._eventListener.sourceName())); | |
249 | |
250 if (node.nodeType() === Node.DOCUMENT_NODE) { | |
251 title.textContent = "document"; | |
252 return; | |
253 } | |
254 | |
255 if (node.id === this._nodeId) { | |
256 title.textContent = WebInspector.DOMPresentationUtils.simpleSelector
(node); | |
257 return; | |
258 } | |
259 | |
260 title.appendChild(WebInspector.DOMPresentationUtils.linkifyNodeReference
(node)); | |
261 }, | |
262 | |
263 __proto__: TreeElement.prototype | |
264 } | |
OLD | NEW |