Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/common/Object.js

Issue 2573323002: Revert of [DevTools] Remove methods on Common.Event. (Closed)
Patch Set: Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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}
90 */ 91 */
91 dispatchEventToListeners(eventType, eventData) { 92 dispatchEventToListeners(eventType, eventData) {
92 if (!this._listeners || !this._listeners.has(eventType)) 93 if (!this._listeners || !this._listeners.has(eventType))
93 return; 94 return false;
94 95
95 var event = new Common.Event(this, eventData); 96 var event = new Common.Event(this, eventType, eventData);
96 var listeners = this._listeners.get(eventType).slice(0); 97 var listeners = this._listeners.get(eventType).slice(0);
97 for (var i = 0; i < listeners.length; ++i) 98 for (var i = 0; i < listeners.length; ++i) {
98 listeners[i].listener.call(listeners[i].thisObject, event); 99 listeners[i].listener.call(listeners[i].thisObject, event);
100 if (event._stoppedPropagation)
101 break;
102 }
103
104 return event.defaultPrevented;
99 } 105 }
100 }; 106 };
101 107
102 /** 108 /**
103 * @unrestricted 109 * @unrestricted
104 */ 110 */
105 Common.Event = class { 111 Common.Event = class {
106 /** 112 /**
107 * @param {!Common.EventTarget} target 113 * @param {!Common.EventTarget} target
114 * @param {symbol} type
108 * @param {*=} data 115 * @param {*=} data
109 */ 116 */
110 constructor(target, data) { 117 constructor(target, type, data) {
111 this.target = target; 118 this.target = target;
119 this.type = type;
112 this.data = data; 120 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();
113 } 140 }
114 }; 141 };
115 142
116 /** 143 /**
117 * @interface 144 * @interface
118 */ 145 */
119 Common.EventTarget = function() {}; 146 Common.EventTarget = function() {};
120 147
121 /** 148 /**
122 * @param {!Array<!Common.EventTarget.EventDescriptor>} eventList 149 * @param {!Array<!Common.EventTarget.EventDescriptor>} eventList
(...skipping 27 matching lines...) Expand all
150 177
151 /** 178 /**
152 * @param {symbol} eventType 179 * @param {symbol} eventType
153 * @return {boolean} 180 * @return {boolean}
154 */ 181 */
155 hasEventListeners(eventType) {}, 182 hasEventListeners(eventType) {},
156 183
157 /** 184 /**
158 * @param {symbol} eventType 185 * @param {symbol} eventType
159 * @param {*=} eventData 186 * @param {*=} eventData
187 * @return {boolean}
160 */ 188 */
161 dispatchEventToListeners(eventType, eventData) {}, 189 dispatchEventToListeners(eventType, eventData) {},
162 }; 190 };
163 191
164 /** 192 /**
165 * @unrestricted 193 * @unrestricted
166 */ 194 */
167 Common.EventTarget.EventDescriptor = class { 195 Common.EventTarget.EventDescriptor = class {
168 /** 196 /**
169 * @param {!Common.EventTarget} eventTarget 197 * @param {!Common.EventTarget} eventTarget
170 * @param {symbol} eventType 198 * @param {symbol} eventType
171 * @param {(!Object|undefined)} receiver 199 * @param {(!Object|undefined)} receiver
172 * @param {function(?):?} method 200 * @param {function(?):?} method
173 */ 201 */
174 constructor(eventTarget, eventType, receiver, method) { 202 constructor(eventTarget, eventType, receiver, method) {
175 this.eventTarget = eventTarget; 203 this.eventTarget = eventTarget;
176 this.eventType = eventType; 204 this.eventType = eventType;
177 this.receiver = receiver; 205 this.receiver = receiver;
178 this.method = method; 206 this.method = method;
179 } 207 }
180 }; 208 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698