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.classList.add("events-pane");
41 var refreshButton = document.createElement("button");
42 refreshButton.className = "pane-title-button refresh";
43 refreshButton.addEventListener("click", this._refreshButtonClicked.bind(this), false);
44 refreshButton.title = WebInspector.UIString("Refresh");
45 this.titleElement.appendChild(refreshButton);
47 this.settingsSelectElement = document.createElement("select");
48 this.settingsSelectElement.className = "select-filter";
50 var option = document.createElement("option");
52 option.label = WebInspector.UIString("All Nodes");
53 this.settingsSelectElement.appendChild(option);
55 option = document.createElement("option");
56 option.value = "selected";
57 option.label = WebInspector.UIString("Selected Node Only");
58 this.settingsSelectElement.appendChild(option);
60 var filter = WebInspector.settings.eventListenersFilter.get();
62 this.settingsSelectElement[0].selected = true;
63 else if (filter === "selected")
64 this.settingsSelectElement[1].selected = true;
65 this.settingsSelectElement.addEventListener("click", function(event) { event.consume() }, false);
66 this.settingsSelectElement.addEventListener("change", this._changeSetting.bind(this), false);
68 this.titleElement.appendChild(this.settingsSelectElement);
70 this._linkifier = new WebInspector.Linkifier();
73 WebInspector.EventListenersSidebarPane._objectGroupName = "event-listeners-sidebar-pane";
75 WebInspector.EventListenersSidebarPane.prototype = {
76 update: function(node)
78 RuntimeAgent.releaseObjectGroup(WebInspector.EventListenersSidebarPane._objectGroupName);
79 this._linkifier.reset();
81 var body = this.bodyElement;
82 body.removeChildren();
86 function callback(error, eventListeners) {
90 var selectedNodeOnly = "selected" === WebInspector.settings.eventListenersFilter.get();
91 var sectionNames = [];
93 for (var i = 0; i < eventListeners.length; ++i) {
94 var eventListener = eventListeners[i];
95 if (selectedNodeOnly && (node.id !== eventListener.nodeId))
97 eventListener.node = WebInspector.domModel.nodeForId(eventListener.nodeId);
98 delete eventListener.nodeId; // no longer needed
99 if (/^function _inspectorCommandLineAPI_logEvent\(/.test(eventListener.handlerBody.toString()))
100 continue; // ignore event listeners generated by monitorEvent
101 var type = eventListener.type;
102 var section = sectionMap[type];
104 section = new WebInspector.EventListenersSection(type, node.id, self._linkifier);
105 sectionMap[type] = section;
106 sectionNames.push(type);
107 self.sections.push(section);
109 section.addListener(eventListener);
112 if (sectionNames.length === 0) {
113 var div = document.createElement("div");
114 div.className = "info";
115 div.textContent = WebInspector.UIString("No Event Listeners");
116 body.appendChild(div);
121 for (var i = 0; i < sectionNames.length; ++i) {
122 var section = sectionMap[sectionNames[i]];
123 body.appendChild(section.element);
128 node.eventListeners(WebInspector.EventListenersSidebarPane._objectGroupName, callback);
129 this._selectedNode = node;
134 delete this._selectedNode;
137 _refreshButtonClicked: function()
139 if (!this._selectedNode)
141 this.update(this._selectedNode);
144 _changeSetting: function()
146 var selectedOption = this.settingsSelectElement[this.settingsSelectElement.selectedIndex];
147 WebInspector.settings.eventListenersFilter.set(selectedOption.value);
148 this.update(this._selectedNode);
151 __proto__: WebInspector.SidebarPane.prototype
156 * @extends {WebInspector.PropertiesSection}
158 WebInspector.EventListenersSection = function(title, nodeId, linkifier)
160 this.eventListeners = [];
161 this._nodeId = nodeId;
162 this._linkifier = linkifier;
163 WebInspector.PropertiesSection.call(this, title);
165 // Changed from a Properties List
166 this.propertiesElement.remove();
167 delete this.propertiesElement;
168 delete this.propertiesTreeOutline;
170 this._eventBars = document.createElement("div");
171 this._eventBars.className = "event-bars";
172 this.element.appendChild(this._eventBars);
175 WebInspector.EventListenersSection.prototype = {
176 addListener: function(eventListener)
178 var eventListenerBar = new WebInspector.EventListenerBar(eventListener, this._nodeId, this._linkifier);
179 this._eventBars.appendChild(eventListenerBar.element);
182 __proto__: WebInspector.PropertiesSection.prototype
187 * @extends {WebInspector.ObjectPropertiesSection}
189 WebInspector.EventListenerBar = function(eventListener, nodeId, linkifier)
191 WebInspector.ObjectPropertiesSection.call(this, WebInspector.RemoteObject.fromPrimitiveValue(""));
193 this.eventListener = eventListener;
194 this._nodeId = nodeId;
195 this._setNodeTitle();
196 this._setFunctionSubtitle(linkifier);
197 this.editable = false;
198 this.element.className = "event-bar"; /* Changed from "section" */
199 this.headerElement.classList.add("source-code");
200 this.propertiesElement.className = "event-properties properties-tree source-code"; /* Changed from "properties" */
203 WebInspector.EventListenerBar.prototype = {
207 * @param {?WebInspector.RemoteObject} nodeObject
208 * @this {WebInspector.EventListenerBar}
210 function updateWithNodeObject(nodeObject)
214 properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("type", this.eventListener.type));
215 properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("useCapture", this.eventListener.useCapture));
216 properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("isAttribute", this.eventListener.isAttribute));
218 properties.push(new WebInspector.RemoteObjectProperty("node", nodeObject));
219 if (typeof this.eventListener.handler !== "undefined") {
220 var remoteObject = WebInspector.RemoteObject.fromPayload(this.eventListener.handler);
221 properties.push(new WebInspector.RemoteObjectProperty("handler", remoteObject));
223 properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("listenerBody", this.eventListener.handlerBody));
224 if (this.eventListener.sourceName)
225 properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("sourceName", this.eventListener.sourceName));
226 properties.push(WebInspector.RemoteObjectProperty.fromPrimitiveValue("lineNumber", this.eventListener.location.lineNumber + 1));
228 this.updateProperties(properties);
230 WebInspector.RemoteObject.resolveNode(this.eventListener.node, WebInspector.EventListenersSidebarPane._objectGroupName, updateWithNodeObject.bind(this));
233 _setNodeTitle: function()
235 var node = this.eventListener.node;
239 if (node.nodeType() === Node.DOCUMENT_NODE) {
240 this.titleElement.textContent = "document";
244 if (node.id === this._nodeId) {
245 this.titleElement.textContent = WebInspector.DOMPresentationUtils.simpleSelector(node);
249 this.titleElement.removeChildren();
250 this.titleElement.appendChild(WebInspector.DOMPresentationUtils.linkifyNodeReference(this.eventListener.node));
253 _setFunctionSubtitle: function(linkifier)
255 this.subtitleElement.removeChildren();
256 var urlElement = linkifier.linkifyRawLocation(this.eventListener.location);
258 var url = this.eventListener.sourceName;
259 var lineNumber = this.eventListener.location.lineNumber;
260 var columnNumber = 0;
261 urlElement = linkifier.linkifyLocation(url, lineNumber, columnNumber);
263 this.subtitleElement.appendChild(urlElement);
266 __proto__: WebInspector.ObjectPropertiesSection.prototype