OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (C) 2007 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2009 Joseph Pecoraro |
| 4 * |
| 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions |
| 7 * are met: |
| 8 * |
| 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. |
| 17 * |
| 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. |
| 28 */ |
| 29 |
| 30 WebInspector.EventListenersSidebarPane = function() |
| 31 { |
| 32 WebInspector.SidebarPane.call(this, WebInspector.UIString("Event Listeners")
); |
| 33 this.bodyElement.addStyleClass("events-pane"); |
| 34 |
| 35 this.sections = []; |
| 36 |
| 37 this.settingsSelectElement = document.createElement("select"); |
| 38 |
| 39 var option = document.createElement("option"); |
| 40 option.value = "all"; |
| 41 if (Preferences.eventListenersFilter === "all") |
| 42 option.selected = true; |
| 43 option.label = WebInspector.UIString("All Nodes"); |
| 44 this.settingsSelectElement.appendChild(option); |
| 45 |
| 46 option = document.createElement("option"); |
| 47 option.value = "selected"; |
| 48 if (Preferences.eventListenersFilter === "selected") |
| 49 option.selected = true; |
| 50 option.label = WebInspector.UIString("Selected Node Only"); |
| 51 this.settingsSelectElement.appendChild(option); |
| 52 |
| 53 this.settingsSelectElement.addEventListener("click", function(event) { event
.stopPropagation() }, false); |
| 54 this.settingsSelectElement.addEventListener("change", this._changeSetting.bi
nd(this), false); |
| 55 |
| 56 this.titleElement.appendChild(this.settingsSelectElement); |
| 57 } |
| 58 |
| 59 WebInspector.EventListenersSidebarPane.prototype = { |
| 60 update: function(node) |
| 61 { |
| 62 var body = this.bodyElement; |
| 63 body.removeChildren(); |
| 64 this.sections = []; |
| 65 |
| 66 var self = this; |
| 67 function callback(nodeId, eventListeners) { |
| 68 var sectionNames = []; |
| 69 var sectionMap = {}; |
| 70 for (var i = 0; i < eventListeners.length; ++i) { |
| 71 var eventListener = eventListeners[i]; |
| 72 eventListener.node = WebInspector.domAgent.nodeForId(eventListen
er.nodeId); |
| 73 delete eventListener.nodeId; // no longer needed |
| 74 if (/^function _inspectorCommandLineAPI_logEvent\(/.test(eventLi
stener.listener.toString())) |
| 75 continue; // ignore event listeners generated by monitorEven
t |
| 76 var type = eventListener.type; |
| 77 var section = sectionMap[type]; |
| 78 if (!section) { |
| 79 section = new WebInspector.EventListenersSection(type, nodeI
d); |
| 80 sectionMap[type] = section; |
| 81 sectionNames.push(type); |
| 82 self.sections.push(section); |
| 83 } |
| 84 section.addListener(eventListener); |
| 85 } |
| 86 |
| 87 if (sectionNames.length === 0) { |
| 88 var div = document.createElement("div"); |
| 89 div.className = "info"; |
| 90 div.textContent = WebInspector.UIString("No Event Listeners"); |
| 91 body.appendChild(div); |
| 92 return; |
| 93 } |
| 94 |
| 95 sectionNames.sort(); |
| 96 for (var i = 0; i < sectionNames.length; ++i) { |
| 97 var section = sectionMap[sectionNames[i]]; |
| 98 section.update(); |
| 99 body.appendChild(section.element); |
| 100 } |
| 101 } |
| 102 |
| 103 WebInspector.EventListeners.getEventListenersForNodeAsync(node, callback
); |
| 104 }, |
| 105 |
| 106 _changeSetting: function(event) |
| 107 { |
| 108 var selectedOption = this.settingsSelectElement[this.settingsSelectEleme
nt.selectedIndex]; |
| 109 Preferences.eventListenersFilter = selectedOption.value; |
| 110 |
| 111 InspectorController.setSetting("event-listeners-filter", Preferences.eve
ntListenersFilter); |
| 112 |
| 113 for (var i = 0; i < this.sections.length; ++i) |
| 114 this.sections[i].update(); |
| 115 } |
| 116 } |
| 117 |
| 118 WebInspector.EventListenersSidebarPane.prototype.__proto__ = WebInspector.Sideba
rPane.prototype; |
| 119 |
| 120 WebInspector.EventListenersSection = function(title, nodeId) |
| 121 { |
| 122 this.eventListeners = []; |
| 123 this._nodeId = nodeId; |
| 124 WebInspector.PropertiesSection.call(this, title); |
| 125 |
| 126 // Changed from a Properties List |
| 127 this.propertiesElement.parentNode.removeChild(this.propertiesElement); |
| 128 delete this.propertiesElement; |
| 129 delete this.propertiesTreeOutline; |
| 130 |
| 131 this.eventBars = document.createElement("div"); |
| 132 this.eventBars.className = "event-bars"; |
| 133 this.element.appendChild(this.eventBars); |
| 134 } |
| 135 |
| 136 WebInspector.EventListenersSection.prototype = { |
| 137 update: function() |
| 138 { |
| 139 // A Filtered Array simplifies when to create connectors |
| 140 var filteredEventListeners = this.eventListeners; |
| 141 if (Preferences.eventListenersFilter === "selected") { |
| 142 filteredEventListeners = []; |
| 143 for (var i = 0; i < this.eventListeners.length; ++i) { |
| 144 var eventListener = this.eventListeners[i]; |
| 145 if (eventListener.node.id === this._nodeId) |
| 146 filteredEventListeners.push(eventListener); |
| 147 } |
| 148 } |
| 149 |
| 150 this.eventBars.removeChildren(); |
| 151 var length = filteredEventListeners.length; |
| 152 for (var i = 0; i < length; ++i) { |
| 153 var eventListener = filteredEventListeners[i]; |
| 154 var eventListenerBar = new WebInspector.EventListenerBar(eventListen
er); |
| 155 if (i < length - 1) { |
| 156 var connector = document.createElement("div"); |
| 157 connector.className = "event-bar-connector"; |
| 158 eventListenerBar.element.appendChild(connector); |
| 159 } |
| 160 |
| 161 this.eventBars.appendChild(eventListenerBar.element); |
| 162 } |
| 163 }, |
| 164 |
| 165 addListener: function(eventListener) |
| 166 { |
| 167 this.eventListeners.push(eventListener); |
| 168 } |
| 169 } |
| 170 |
| 171 WebInspector.EventListenersSection.prototype.__proto__ = WebInspector.Properties
Section.prototype; |
| 172 |
| 173 WebInspector.EventListenerBar = function(eventListener) |
| 174 { |
| 175 this.eventListener = eventListener; |
| 176 WebInspector.ObjectPropertiesSection.call(this, null, this._getFunctionDispl
ayName(), this._getNodeDisplayName()); |
| 177 this.editable = false; |
| 178 this.element.className = "event-bar"; /* Changed from "section" */ |
| 179 this.propertiesElement.className = "event-properties"; /* Changed from "prop
erties" */ |
| 180 } |
| 181 |
| 182 WebInspector.EventListenerBar.prototype = { |
| 183 update: function() |
| 184 { |
| 185 var properties = []; |
| 186 for (var propertyName in this.eventListener) { |
| 187 // Just build properties in place - no need to reach out for injecte
d script. |
| 188 var value = this.eventListener[propertyName]; |
| 189 if (value instanceof WebInspector.DOMNode) |
| 190 value = new WebInspector.ObjectProxy(value.id, [], 0, appropriat
eSelectorForNode(value), true); |
| 191 else |
| 192 value = WebInspector.ObjectProxy.wrapPrimitiveValue(value); |
| 193 properties.push(new WebInspector.ObjectPropertyProxy(propertyName, v
alue)); |
| 194 } |
| 195 this.updateProperties(properties); |
| 196 }, |
| 197 |
| 198 _getNodeDisplayName: function() |
| 199 { |
| 200 var node = this.eventListener.node; |
| 201 if (!node) |
| 202 return ""; |
| 203 |
| 204 if (node.nodeType === Node.DOCUMENT_NODE) |
| 205 return "document"; |
| 206 |
| 207 return appropriateSelectorForNode(node); |
| 208 }, |
| 209 |
| 210 _getFunctionDisplayName: function() |
| 211 { |
| 212 // Requires that Function.toString() return at least the function's sign
ature. |
| 213 var match = this.eventListener.listener.toString().match(/function ([^\(
]+?)\(/); |
| 214 return (match ? match[1] : WebInspector.UIString("(anonymous function)")
); |
| 215 } |
| 216 } |
| 217 |
| 218 WebInspector.EventListenerBar.prototype.__proto__ = WebInspector.ObjectPropertie
sSection.prototype; |
OLD | NEW |