| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. | 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * @constructor | 27 * @constructor |
| 28 * @implements {WebInspector.EventTarget} | 28 * @implements {WebInspector.EventTarget} |
| 29 */ | 29 */ |
| 30 WebInspector.Object = function() { | 30 WebInspector.Object = function() { |
| 31 } | 31 }; |
| 32 | 32 |
| 33 WebInspector.Object.prototype = { | 33 WebInspector.Object.prototype = { |
| 34 /** | 34 /** |
| 35 * @override | 35 * @override |
| 36 * @param {string|symbol} eventType | 36 * @param {string|symbol} eventType |
| 37 * @param {function(!WebInspector.Event)} listener | 37 * @param {function(!WebInspector.Event)} listener |
| 38 * @param {!Object=} thisObject | 38 * @param {!Object=} thisObject |
| 39 * @return {!WebInspector.EventTarget.EventDescriptor} | 39 * @return {!WebInspector.EventTarget.EventDescriptor} |
| 40 */ | 40 */ |
| 41 addEventListener: function(eventType, listener, thisObject) | 41 addEventListener: function(eventType, listener, thisObject) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 var event = new WebInspector.Event(this, eventType, eventData); | 105 var event = new WebInspector.Event(this, eventType, eventData); |
| 106 var listeners = this._listeners.get(eventType).slice(0); | 106 var listeners = this._listeners.get(eventType).slice(0); |
| 107 for (var i = 0; i < listeners.length; ++i) { | 107 for (var i = 0; i < listeners.length; ++i) { |
| 108 listeners[i].listener.call(listeners[i].thisObject, event); | 108 listeners[i].listener.call(listeners[i].thisObject, event); |
| 109 if (event._stoppedPropagation) | 109 if (event._stoppedPropagation) |
| 110 break; | 110 break; |
| 111 } | 111 } |
| 112 | 112 |
| 113 return event.defaultPrevented; | 113 return event.defaultPrevented; |
| 114 } | 114 } |
| 115 } | 115 }; |
| 116 | 116 |
| 117 /** | 117 /** |
| 118 * @constructor | 118 * @constructor |
| 119 * @param {!WebInspector.EventTarget} target | 119 * @param {!WebInspector.EventTarget} target |
| 120 * @param {string|symbol} type | 120 * @param {string|symbol} type |
| 121 * @param {*=} data | 121 * @param {*=} data |
| 122 */ | 122 */ |
| 123 WebInspector.Event = function(target, type, data) | 123 WebInspector.Event = function(target, type, data) |
| 124 { | 124 { |
| 125 this.target = target; | 125 this.target = target; |
| 126 this.type = type; | 126 this.type = type; |
| 127 this.data = data; | 127 this.data = data; |
| 128 this.defaultPrevented = false; | 128 this.defaultPrevented = false; |
| 129 this._stoppedPropagation = false; | 129 this._stoppedPropagation = false; |
| 130 } | 130 }; |
| 131 | 131 |
| 132 WebInspector.Event.prototype = { | 132 WebInspector.Event.prototype = { |
| 133 stopPropagation: function() | 133 stopPropagation: function() |
| 134 { | 134 { |
| 135 this._stoppedPropagation = true; | 135 this._stoppedPropagation = true; |
| 136 }, | 136 }, |
| 137 | 137 |
| 138 preventDefault: function() | 138 preventDefault: function() |
| 139 { | 139 { |
| 140 this.defaultPrevented = true; | 140 this.defaultPrevented = true; |
| 141 }, | 141 }, |
| 142 | 142 |
| 143 /** | 143 /** |
| 144 * @param {boolean=} preventDefault | 144 * @param {boolean=} preventDefault |
| 145 */ | 145 */ |
| 146 consume: function(preventDefault) | 146 consume: function(preventDefault) |
| 147 { | 147 { |
| 148 this.stopPropagation(); | 148 this.stopPropagation(); |
| 149 if (preventDefault) | 149 if (preventDefault) |
| 150 this.preventDefault(); | 150 this.preventDefault(); |
| 151 } | 151 } |
| 152 } | 152 }; |
| 153 | 153 |
| 154 /** | 154 /** |
| 155 * @interface | 155 * @interface |
| 156 */ | 156 */ |
| 157 WebInspector.EventTarget = function() | 157 WebInspector.EventTarget = function() |
| 158 { | 158 { |
| 159 } | 159 }; |
| 160 | 160 |
| 161 /** | 161 /** |
| 162 * @param {!Array<!WebInspector.EventTarget.EventDescriptor>} eventList | 162 * @param {!Array<!WebInspector.EventTarget.EventDescriptor>} eventList |
| 163 */ | 163 */ |
| 164 WebInspector.EventTarget.removeEventListeners = function(eventList) | 164 WebInspector.EventTarget.removeEventListeners = function(eventList) |
| 165 { | 165 { |
| 166 for (var i = 0; i < eventList.length; ++i) { | 166 for (var i = 0; i < eventList.length; ++i) { |
| 167 var eventInfo = eventList[i]; | 167 var eventInfo = eventList[i]; |
| 168 eventInfo.eventTarget.removeEventListener(eventInfo.eventType, eventInfo
.method, eventInfo.receiver); | 168 eventInfo.eventTarget.removeEventListener(eventInfo.eventType, eventInfo
.method, eventInfo.receiver); |
| 169 } | 169 } |
| 170 // Do not hold references on unused event descriptors. | 170 // Do not hold references on unused event descriptors. |
| 171 eventList.splice(0, eventList.length); | 171 eventList.splice(0, eventList.length); |
| 172 } | 172 }; |
| 173 | 173 |
| 174 WebInspector.EventTarget.prototype = { | 174 WebInspector.EventTarget.prototype = { |
| 175 /** | 175 /** |
| 176 * @param {string|symbol} eventType | 176 * @param {string|symbol} eventType |
| 177 * @param {function(!WebInspector.Event)} listener | 177 * @param {function(!WebInspector.Event)} listener |
| 178 * @param {!Object=} thisObject | 178 * @param {!Object=} thisObject |
| 179 * @return {!WebInspector.EventTarget.EventDescriptor} | 179 * @return {!WebInspector.EventTarget.EventDescriptor} |
| 180 */ | 180 */ |
| 181 addEventListener: function(eventType, listener, thisObject) { }, | 181 addEventListener: function(eventType, listener, thisObject) { }, |
| 182 | 182 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 194 * @return {boolean} | 194 * @return {boolean} |
| 195 */ | 195 */ |
| 196 hasEventListeners: function(eventType) { }, | 196 hasEventListeners: function(eventType) { }, |
| 197 | 197 |
| 198 /** | 198 /** |
| 199 * @param {string|symbol} eventType | 199 * @param {string|symbol} eventType |
| 200 * @param {*=} eventData | 200 * @param {*=} eventData |
| 201 * @return {boolean} | 201 * @return {boolean} |
| 202 */ | 202 */ |
| 203 dispatchEventToListeners: function(eventType, eventData) { }, | 203 dispatchEventToListeners: function(eventType, eventData) { }, |
| 204 } | 204 }; |
| 205 | 205 |
| 206 /** | 206 /** |
| 207 * @constructor | 207 * @constructor |
| 208 * @param {!WebInspector.EventTarget} eventTarget | 208 * @param {!WebInspector.EventTarget} eventTarget |
| 209 * @param {string|symbol} eventType | 209 * @param {string|symbol} eventType |
| 210 * @param {(!Object|undefined)} receiver | 210 * @param {(!Object|undefined)} receiver |
| 211 * @param {function(?):?} method | 211 * @param {function(?):?} method |
| 212 */ | 212 */ |
| 213 WebInspector.EventTarget.EventDescriptor = function(eventTarget, eventType, rece
iver, method) | 213 WebInspector.EventTarget.EventDescriptor = function(eventTarget, eventType, rece
iver, method) |
| 214 { | 214 { |
| 215 this.eventTarget = eventTarget; | 215 this.eventTarget = eventTarget; |
| 216 this.eventType = eventType; | 216 this.eventType = eventType; |
| 217 this.receiver = receiver; | 217 this.receiver = receiver; |
| 218 this.method = method; | 218 this.method = method; |
| 219 } | 219 }; |
| OLD | NEW |