| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 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 * @implements {WebInspector.EventTarget} | 26 * @implements {Common.EventTarget} |
| 27 * @unrestricted | 27 * @unrestricted |
| 28 */ | 28 */ |
| 29 WebInspector.Object = class { | 29 Common.Object = class { |
| 30 /** | 30 /** |
| 31 * @override | 31 * @override |
| 32 * @param {string|symbol} eventType | 32 * @param {string|symbol} eventType |
| 33 * @param {function(!WebInspector.Event)} listener | 33 * @param {function(!Common.Event)} listener |
| 34 * @param {!Object=} thisObject | 34 * @param {!Object=} thisObject |
| 35 * @return {!WebInspector.EventTarget.EventDescriptor} | 35 * @return {!Common.EventTarget.EventDescriptor} |
| 36 */ | 36 */ |
| 37 addEventListener(eventType, listener, thisObject) { | 37 addEventListener(eventType, listener, thisObject) { |
| 38 if (!listener) | 38 if (!listener) |
| 39 console.assert(false); | 39 console.assert(false); |
| 40 | 40 |
| 41 if (!this._listeners) | 41 if (!this._listeners) |
| 42 this._listeners = new Map(); | 42 this._listeners = new Map(); |
| 43 if (!this._listeners.has(eventType)) | 43 if (!this._listeners.has(eventType)) |
| 44 this._listeners.set(eventType, []); | 44 this._listeners.set(eventType, []); |
| 45 this._listeners.get(eventType).push({thisObject: thisObject, listener: liste
ner}); | 45 this._listeners.get(eventType).push({thisObject: thisObject, listener: liste
ner}); |
| 46 return new WebInspector.EventTarget.EventDescriptor(this, eventType, thisObj
ect, listener); | 46 return new Common.EventTarget.EventDescriptor(this, eventType, thisObject, l
istener); |
| 47 } | 47 } |
| 48 | 48 |
| 49 /** | 49 /** |
| 50 * @override | 50 * @override |
| 51 * @param {string|symbol} eventType | 51 * @param {string|symbol} eventType |
| 52 * @param {function(!WebInspector.Event)} listener | 52 * @param {function(!Common.Event)} listener |
| 53 * @param {!Object=} thisObject | 53 * @param {!Object=} thisObject |
| 54 */ | 54 */ |
| 55 removeEventListener(eventType, listener, thisObject) { | 55 removeEventListener(eventType, listener, thisObject) { |
| 56 console.assert(listener); | 56 console.assert(listener); |
| 57 | 57 |
| 58 if (!this._listeners || !this._listeners.has(eventType)) | 58 if (!this._listeners || !this._listeners.has(eventType)) |
| 59 return; | 59 return; |
| 60 var listeners = this._listeners.get(eventType); | 60 var listeners = this._listeners.get(eventType); |
| 61 for (var i = 0; i < listeners.length; ++i) { | 61 for (var i = 0; i < listeners.length; ++i) { |
| 62 if (listeners[i].listener === listener && listeners[i].thisObject === this
Object) | 62 if (listeners[i].listener === listener && listeners[i].thisObject === this
Object) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 86 /** | 86 /** |
| 87 * @override | 87 * @override |
| 88 * @param {string|symbol} eventType | 88 * @param {string|symbol} eventType |
| 89 * @param {*=} eventData | 89 * @param {*=} eventData |
| 90 * @return {boolean} | 90 * @return {boolean} |
| 91 */ | 91 */ |
| 92 dispatchEventToListeners(eventType, eventData) { | 92 dispatchEventToListeners(eventType, eventData) { |
| 93 if (!this._listeners || !this._listeners.has(eventType)) | 93 if (!this._listeners || !this._listeners.has(eventType)) |
| 94 return false; | 94 return false; |
| 95 | 95 |
| 96 var event = new WebInspector.Event(this, eventType, eventData); | 96 var event = new Common.Event(this, eventType, eventData); |
| 97 var listeners = this._listeners.get(eventType).slice(0); | 97 var listeners = this._listeners.get(eventType).slice(0); |
| 98 for (var i = 0; i < listeners.length; ++i) { | 98 for (var i = 0; i < listeners.length; ++i) { |
| 99 listeners[i].listener.call(listeners[i].thisObject, event); | 99 listeners[i].listener.call(listeners[i].thisObject, event); |
| 100 if (event._stoppedPropagation) | 100 if (event._stoppedPropagation) |
| 101 break; | 101 break; |
| 102 } | 102 } |
| 103 | 103 |
| 104 return event.defaultPrevented; | 104 return event.defaultPrevented; |
| 105 } | 105 } |
| 106 }; | 106 }; |
| 107 | 107 |
| 108 /** | 108 /** |
| 109 * @unrestricted | 109 * @unrestricted |
| 110 */ | 110 */ |
| 111 WebInspector.Event = class { | 111 Common.Event = class { |
| 112 /** | 112 /** |
| 113 * @param {!WebInspector.EventTarget} target | 113 * @param {!Common.EventTarget} target |
| 114 * @param {string|symbol} type | 114 * @param {string|symbol} type |
| 115 * @param {*=} data | 115 * @param {*=} data |
| 116 */ | 116 */ |
| 117 constructor(target, type, data) { | 117 constructor(target, type, data) { |
| 118 this.target = target; | 118 this.target = target; |
| 119 this.type = type; | 119 this.type = type; |
| 120 this.data = data; | 120 this.data = data; |
| 121 this.defaultPrevented = false; | 121 this.defaultPrevented = false; |
| 122 this._stoppedPropagation = false; | 122 this._stoppedPropagation = false; |
| 123 } | 123 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 136 consume(preventDefault) { | 136 consume(preventDefault) { |
| 137 this.stopPropagation(); | 137 this.stopPropagation(); |
| 138 if (preventDefault) | 138 if (preventDefault) |
| 139 this.preventDefault(); | 139 this.preventDefault(); |
| 140 } | 140 } |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 /** | 143 /** |
| 144 * @interface | 144 * @interface |
| 145 */ | 145 */ |
| 146 WebInspector.EventTarget = function() {}; | 146 Common.EventTarget = function() {}; |
| 147 | 147 |
| 148 /** | 148 /** |
| 149 * @param {!Array<!WebInspector.EventTarget.EventDescriptor>} eventList | 149 * @param {!Array<!Common.EventTarget.EventDescriptor>} eventList |
| 150 */ | 150 */ |
| 151 WebInspector.EventTarget.removeEventListeners = function(eventList) { | 151 Common.EventTarget.removeEventListeners = function(eventList) { |
| 152 for (var i = 0; i < eventList.length; ++i) { | 152 for (var i = 0; i < eventList.length; ++i) { |
| 153 var eventInfo = eventList[i]; | 153 var eventInfo = eventList[i]; |
| 154 eventInfo.eventTarget.removeEventListener(eventInfo.eventType, eventInfo.met
hod, eventInfo.receiver); | 154 eventInfo.eventTarget.removeEventListener(eventInfo.eventType, eventInfo.met
hod, eventInfo.receiver); |
| 155 } | 155 } |
| 156 // Do not hold references on unused event descriptors. | 156 // Do not hold references on unused event descriptors. |
| 157 eventList.splice(0, eventList.length); | 157 eventList.splice(0, eventList.length); |
| 158 }; | 158 }; |
| 159 | 159 |
| 160 WebInspector.EventTarget.prototype = { | 160 Common.EventTarget.prototype = { |
| 161 /** | 161 /** |
| 162 * @param {string|symbol} eventType | 162 * @param {string|symbol} eventType |
| 163 * @param {function(!WebInspector.Event)} listener | 163 * @param {function(!Common.Event)} listener |
| 164 * @param {!Object=} thisObject | 164 * @param {!Object=} thisObject |
| 165 * @return {!WebInspector.EventTarget.EventDescriptor} | 165 * @return {!Common.EventTarget.EventDescriptor} |
| 166 */ | 166 */ |
| 167 addEventListener: function(eventType, listener, thisObject) {}, | 167 addEventListener: function(eventType, listener, thisObject) {}, |
| 168 | 168 |
| 169 /** | 169 /** |
| 170 * @param {string|symbol} eventType | 170 * @param {string|symbol} eventType |
| 171 * @param {function(!WebInspector.Event)} listener | 171 * @param {function(!Common.Event)} listener |
| 172 * @param {!Object=} thisObject | 172 * @param {!Object=} thisObject |
| 173 */ | 173 */ |
| 174 removeEventListener: function(eventType, listener, thisObject) {}, | 174 removeEventListener: function(eventType, listener, thisObject) {}, |
| 175 | 175 |
| 176 removeAllListeners: function() {}, | 176 removeAllListeners: function() {}, |
| 177 | 177 |
| 178 /** | 178 /** |
| 179 * @param {string|symbol} eventType | 179 * @param {string|symbol} eventType |
| 180 * @return {boolean} | 180 * @return {boolean} |
| 181 */ | 181 */ |
| 182 hasEventListeners: function(eventType) {}, | 182 hasEventListeners: function(eventType) {}, |
| 183 | 183 |
| 184 /** | 184 /** |
| 185 * @param {string|symbol} eventType | 185 * @param {string|symbol} eventType |
| 186 * @param {*=} eventData | 186 * @param {*=} eventData |
| 187 * @return {boolean} | 187 * @return {boolean} |
| 188 */ | 188 */ |
| 189 dispatchEventToListeners: function(eventType, eventData) {}, | 189 dispatchEventToListeners: function(eventType, eventData) {}, |
| 190 }; | 190 }; |
| 191 | 191 |
| 192 /** | 192 /** |
| 193 * @unrestricted | 193 * @unrestricted |
| 194 */ | 194 */ |
| 195 WebInspector.EventTarget.EventDescriptor = class { | 195 Common.EventTarget.EventDescriptor = class { |
| 196 /** | 196 /** |
| 197 * @param {!WebInspector.EventTarget} eventTarget | 197 * @param {!Common.EventTarget} eventTarget |
| 198 * @param {string|symbol} eventType | 198 * @param {string|symbol} eventType |
| 199 * @param {(!Object|undefined)} receiver | 199 * @param {(!Object|undefined)} receiver |
| 200 * @param {function(?):?} method | 200 * @param {function(?):?} method |
| 201 */ | 201 */ |
| 202 constructor(eventTarget, eventType, receiver, method) { | 202 constructor(eventTarget, eventType, receiver, method) { |
| 203 this.eventTarget = eventTarget; | 203 this.eventTarget = eventTarget; |
| 204 this.eventType = eventType; | 204 this.eventType = eventType; |
| 205 this.receiver = receiver; | 205 this.receiver = receiver; |
| 206 this.method = method; | 206 this.method = method; |
| 207 } | 207 } |
| 208 }; | 208 }; |
| OLD | NEW |