| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 * @return {boolean} | 80 * @return {boolean} |
| 81 */ | 81 */ |
| 82 hasEventListeners(eventType) { | 82 hasEventListeners(eventType) { |
| 83 return this._listeners && this._listeners.has(eventType); | 83 return this._listeners && this._listeners.has(eventType); |
| 84 } | 84 } |
| 85 | 85 |
| 86 /** | 86 /** |
| 87 * @override | 87 * @override |
| 88 * @param {symbol} eventType | 88 * @param {symbol} eventType |
| 89 * @param {*=} eventData | 89 * @param {*=} eventData |
| 90 * @return {boolean} | |
| 91 */ | 90 */ |
| 92 dispatchEventToListeners(eventType, eventData) { | 91 dispatchEventToListeners(eventType, eventData) { |
| 93 if (!this._listeners || !this._listeners.has(eventType)) | 92 if (!this._listeners || !this._listeners.has(eventType)) |
| 94 return false; | 93 return; |
| 95 | 94 |
| 96 var event = new Common.Event(this, eventType, eventData); | 95 var event = new Common.Event(this, eventData); |
| 97 var listeners = this._listeners.get(eventType).slice(0); | 96 var listeners = this._listeners.get(eventType).slice(0); |
| 98 for (var i = 0; i < listeners.length; ++i) { | 97 for (var i = 0; i < listeners.length; ++i) |
| 99 listeners[i].listener.call(listeners[i].thisObject, event); | 98 listeners[i].listener.call(listeners[i].thisObject, event); |
| 100 if (event._stoppedPropagation) | |
| 101 break; | |
| 102 } | |
| 103 | |
| 104 return event.defaultPrevented; | |
| 105 } | 99 } |
| 106 }; | 100 }; |
| 107 | 101 |
| 108 /** | 102 /** |
| 109 * @unrestricted | 103 * @unrestricted |
| 110 */ | 104 */ |
| 111 Common.Event = class { | 105 Common.Event = class { |
| 112 /** | 106 /** |
| 113 * @param {!Common.EventTarget} target | 107 * @param {!Common.EventTarget} target |
| 114 * @param {symbol} type | |
| 115 * @param {*=} data | 108 * @param {*=} data |
| 116 */ | 109 */ |
| 117 constructor(target, type, data) { | 110 constructor(target, data) { |
| 118 this.target = target; | 111 this.target = target; |
| 119 this.type = type; | |
| 120 this.data = data; | 112 this.data = data; |
| 121 this.defaultPrevented = false; | |
| 122 this._stoppedPropagation = false; | |
| 123 } | |
| 124 | |
| 125 stopPropagation() { | |
| 126 this._stoppedPropagation = true; | |
| 127 } | |
| 128 | |
| 129 preventDefault() { | |
| 130 this.defaultPrevented = true; | |
| 131 } | |
| 132 | |
| 133 /** | |
| 134 * @param {boolean=} preventDefault | |
| 135 */ | |
| 136 consume(preventDefault) { | |
| 137 this.stopPropagation(); | |
| 138 if (preventDefault) | |
| 139 this.preventDefault(); | |
| 140 } | 113 } |
| 141 }; | 114 }; |
| 142 | 115 |
| 143 /** | 116 /** |
| 144 * @interface | 117 * @interface |
| 145 */ | 118 */ |
| 146 Common.EventTarget = function() {}; | 119 Common.EventTarget = function() {}; |
| 147 | 120 |
| 148 /** | 121 /** |
| 149 * @param {!Array<!Common.EventTarget.EventDescriptor>} eventList | 122 * @param {!Array<!Common.EventTarget.EventDescriptor>} eventList |
| (...skipping 27 matching lines...) Expand all Loading... |
| 177 | 150 |
| 178 /** | 151 /** |
| 179 * @param {symbol} eventType | 152 * @param {symbol} eventType |
| 180 * @return {boolean} | 153 * @return {boolean} |
| 181 */ | 154 */ |
| 182 hasEventListeners(eventType) {}, | 155 hasEventListeners(eventType) {}, |
| 183 | 156 |
| 184 /** | 157 /** |
| 185 * @param {symbol} eventType | 158 * @param {symbol} eventType |
| 186 * @param {*=} eventData | 159 * @param {*=} eventData |
| 187 * @return {boolean} | |
| 188 */ | 160 */ |
| 189 dispatchEventToListeners(eventType, eventData) {}, | 161 dispatchEventToListeners(eventType, eventData) {}, |
| 190 }; | 162 }; |
| 191 | 163 |
| 192 /** | 164 /** |
| 193 * @unrestricted | 165 * @unrestricted |
| 194 */ | 166 */ |
| 195 Common.EventTarget.EventDescriptor = class { | 167 Common.EventTarget.EventDescriptor = class { |
| 196 /** | 168 /** |
| 197 * @param {!Common.EventTarget} eventTarget | 169 * @param {!Common.EventTarget} eventTarget |
| 198 * @param {symbol} eventType | 170 * @param {symbol} eventType |
| 199 * @param {(!Object|undefined)} receiver | 171 * @param {(!Object|undefined)} receiver |
| 200 * @param {function(?):?} method | 172 * @param {function(?):?} method |
| 201 */ | 173 */ |
| 202 constructor(eventTarget, eventType, receiver, method) { | 174 constructor(eventTarget, eventType, receiver, method) { |
| 203 this.eventTarget = eventTarget; | 175 this.eventTarget = eventTarget; |
| 204 this.eventType = eventType; | 176 this.eventType = eventType; |
| 205 this.receiver = receiver; | 177 this.receiver = receiver; |
| 206 this.method = method; | 178 this.method = method; |
| 207 } | 179 } |
| 208 }; | 180 }; |
| OLD | NEW |