2
* Copyright (C) 2007 Apple Inc. All rights reserved.
3
* Copyright (C) 2009 Joseph Pecoraro
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
9
* 1. Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* 2. Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
15
* its contributors may be used to endorse or promote products derived
16
* from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
19
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
22
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
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
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
27
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
* @extends {WebInspector.SidebarPane}
34
WebInspector.EventListenersSidebarPane = function()
36
WebInspector.SidebarPane.call(this, WebInspector.UIString("Event Listeners"));
37
this.bodyElement.addStyleClass("events-pane");
41
this.settingsSelectElement = document.createElement("select");
42
this.settingsSelectElement.className = "select-filter";
44
var option = document.createElement("option");
46
option.label = WebInspector.UIString("All Nodes");
47
this.settingsSelectElement.appendChild(option);
49
option = document.createElement("option");
50
option.value = "selected";
51
option.label = WebInspector.UIString("Selected Node Only");
52
this.settingsSelectElement.appendChild(option);
54
var filter = WebInspector.settings.eventListenersFilter.get();
56
this.settingsSelectElement[0].selected = true;
57
else if (filter === "selected")
58
this.settingsSelectElement[1].selected = true;
59
this.settingsSelectElement.addEventListener("click", function(event) { event.consume() }, false);
60
this.settingsSelectElement.addEventListener("change", this._changeSetting.bind(this), false);
62
this.titleElement.appendChild(this.settingsSelectElement);
64
this._linkifier = new WebInspector.Linkifier();
67
WebInspector.EventListenersSidebarPane._objectGroupName = "event-listeners-sidebar-pane";
69
WebInspector.EventListenersSidebarPane.prototype = {
70
update: function(node)
72
RuntimeAgent.releaseObjectGroup(WebInspector.EventListenersSidebarPane._objectGroupName);
73
this._linkifier.reset();
75
var body = this.bodyElement;
76
body.removeChildren();
80
function callback(error, eventListeners) {
84
var selectedNodeOnly = "selected" === WebInspector.settings.eventListenersFilter.get();
85
var sectionNames = [];
87
for (var i = 0; i < eventListeners.length; ++i) {
88
var eventListener = eventListeners[i];
89
if (selectedNodeOnly && (node.id !== eventListener.nodeId))
91
eventListener.node = WebInspector.domAgent.nodeForId(eventListener.nodeId);
92
delete eventListener.nodeId; // no longer needed
93
if (/^function _inspectorCommandLineAPI_logEvent\(/.test(eventListener.handlerBody.toString()))
94
continue; // ignore event listeners generated by monitorEvent
95
var type = eventListener.type;
96
var section = sectionMap[type];
98
section = new WebInspector.EventListenersSection(type, node.id, self._linkifier);
99
sectionMap[type] = section;
100
sectionNames.push(type);
101
self.sections.push(section);
103
section.addListener(eventListener);
106
if (sectionNames.length === 0) {
107
var div = document.createElement("div");
108
div.className = "info";
109
div.textContent = WebInspector.UIString("No Event Listeners");
110
body.appendChild(div);
115
for (var i = 0; i < sectionNames.length; ++i) {
116
var section = sectionMap[sectionNames[i]];
117
body.appendChild(section.element);
122
node.eventListeners(callback);
123
this._selectedNode = node;
128
delete this._selectedNode;
131
_changeSetting: function()
133
var selectedOption = this.settingsSelectElement[this.settingsSelectElement.selectedIndex];
134
WebInspector.settings.eventListenersFilter.set(selectedOption.value);
135
this.update(this._selectedNode);
138
__proto__: WebInspector.SidebarPane.prototype
143
* @extends {WebInspector.PropertiesSection}
145
WebInspector.EventListenersSection = function(title, nodeId, linkifier)
147
this.eventListeners = [];
148
this._nodeId = nodeId;
149
this._linkifier = linkifier;
150
WebInspector.PropertiesSection.call(this, title);
152
// Changed from a Properties List
153
this.propertiesElement.parentNode.removeChild(this.propertiesElement);
154
delete this.propertiesElement;
155
delete this.propertiesTreeOutline;
157
this._eventBars = document.createElement("div");
158
this._eventBars.className = "event-bars";
159
this.element.appendChild(this._eventBars);
162
WebInspector.EventListenersSection.prototype = {
163
addListener: function(eventListener)
165
var eventListenerBar = new WebInspector.EventListenerBar(eventListener, this._nodeId, this._linkifier);
166
this._eventBars.appendChild(eventListenerBar.element);
169
__proto__: WebInspector.PropertiesSection.prototype
174
* @extends {WebInspector.ObjectPropertiesSection}
176
WebInspector.EventListenerBar = function(eventListener, nodeId, linkifier)
178
WebInspector.ObjectPropertiesSection.call(this, WebInspector.RemoteObject.fromPrimitiveValue(""));
180
this.eventListener = eventListener;
181
this._nodeId = nodeId;
182
this._setNodeTitle();
183
this._setFunctionSubtitle(linkifier);
184
this.editable = false;
185
this.element.className = "event-bar"; /* Changed from "section" */
186
this.headerElement.addStyleClass("source-code");
187
this.propertiesElement.className = "event-properties properties-tree source-code"; /* Changed from "properties" */
190
WebInspector.EventListenerBar.prototype = {
193
function updateWithNodeObject(nodeObject)
197
if (this.eventListener.type)
198
properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("type", this.eventListener.type));
199
if (typeof this.eventListener.useCapture !== "undefined")
200
properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("useCapture", this.eventListener.useCapture));
201
if (typeof this.eventListener.isAttribute !== "undefined")
202
properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("isAttribute", this.eventListener.isAttribute));
204
properties.push(new WebInspector.RemoteObjectProperty("node", nodeObject));
205
if (typeof this.eventListener.handlerBody !== "undefined")
206
properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("listenerBody", this.eventListener.handlerBody));
207
if (this.eventListener.sourceName)
208
properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("sourceName", this.eventListener.sourceName));
209
if (this.eventListener.location)
210
properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("lineNumber", this.eventListener.location.lineNumber + 1));
212
this.updateProperties(properties);
214
WebInspector.RemoteObject.resolveNode(this.eventListener.node, WebInspector.EventListenersSidebarPane._objectGroupName, updateWithNodeObject.bind(this));
217
_setNodeTitle: function()
219
var node = this.eventListener.node;
223
if (node.nodeType() === Node.DOCUMENT_NODE) {
224
this.titleElement.textContent = "document";
228
if (node.id === this._nodeId) {
229
this.titleElement.textContent = node.appropriateSelectorFor();
233
this.titleElement.removeChildren();
234
this.titleElement.appendChild(WebInspector.DOMPresentationUtils.linkifyNodeReference(this.eventListener.node));
237
_setFunctionSubtitle: function(linkifier)
239
// Requires that Function.toString() return at least the function's signature.
240
if (this.eventListener.location) {
241
this.subtitleElement.removeChildren();
243
if (this.eventListener.location.scriptId)
244
urlElement = linkifier.linkifyRawLocation(this.eventListener.location);
246
var url = this.eventListener.sourceName;
247
var lineNumber = this.eventListener.location.lineNumber;
248
var columnNumber = 0;
249
urlElement = linkifier.linkifyLocation(url, lineNumber, columnNumber);
251
this.subtitleElement.appendChild(urlElement);
253
var match = this.eventListener.handlerBody.match(/function ([^\(]+?)\(/);
255
this.subtitleElement.textContent = match[1];
257
this.subtitleElement.textContent = WebInspector.UIString("(anonymous function)");
261
__proto__: WebInspector.ObjectPropertiesSection.prototype