w3c_event.js (8359B)
1 /* 2 * Copyright 2008 The Closure Compiler Authors 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /** 18 * @fileoverview Definitions for W3C's event specification. 19 * The whole file has been fully type annotated. 20 * Created from 21 * http://www.w3.org/TR/DOM-Level-2-Events/ecma-script-binding.html 22 * 23 * @externs 24 */ 25 26 27 /** 28 * @interface 29 */ 30 function EventTarget() {} 31 32 /** 33 * @param {string} type 34 * @param {EventListener|function(!Event):(boolean|undefined)} listener 35 * @param {boolean} useCapture 36 * @return {undefined} 37 */ 38 EventTarget.prototype.addEventListener = function(type, listener, useCapture) 39 {}; 40 41 /** 42 * @param {string} type 43 * @param {EventListener|function(!Event):(boolean|undefined)} listener 44 * @param {boolean} useCapture 45 * @return {undefined} 46 */ 47 EventTarget.prototype.removeEventListener = function(type, listener, useCapture) 48 {}; 49 50 /** 51 * @param {!Event} evt 52 * @return {boolean} 53 */ 54 EventTarget.prototype.dispatchEvent = function(evt) {}; 55 56 /** 57 * @interface 58 */ 59 function EventListener() {} 60 61 /** 62 * @param {!Event} evt 63 * @return {undefined} 64 */ 65 EventListener.prototype.handleEvent = function(evt) {}; 66 67 // The EventInit interface and the parameters to the Event constructor are part 68 // of DOM Level 3 (suggested) and the DOM "Living Standard" (mandated). They are 69 // included here as externs cannot be redefined. The same applies to other 70 // *EventInit interfaces and *Event constructors throughout this file. See: 71 // http://www.w3.org/TR/DOM-Level-3-Events/#event-initializers 72 // http://dom.spec.whatwg.org/#constructing-events 73 // https://dvcs.w3.org/hg/d4e/raw-file/tip/source_respec.htm#event-constructors 74 75 /** 76 * @typedef {{ 77 * bubbles: (boolean|undefined), 78 * cancelable: (boolean|undefined) 79 * }} 80 */ 81 var EventInit; 82 83 /** 84 * @constructor 85 * @param {string} type 86 * @param {EventInit=} opt_eventInitDict 87 */ 88 function Event(type, opt_eventInitDict) {} 89 90 /** 91 * @type {number} 92 * @see http://www.w3.org/TR/DOM-Level-2-Events/ecma-script-binding.html 93 */ 94 Event.AT_TARGET; 95 96 /** 97 * @type {number} 98 * @see http://www.w3.org/TR/DOM-Level-2-Events/ecma-script-binding.html 99 */ 100 Event.BUBBLING_PHASE; 101 102 /** 103 * @type {number} 104 * @see http://www.w3.org/TR/DOM-Level-2-Events/ecma-script-binding.html 105 */ 106 Event.CAPTURING_PHASE; 107 108 109 /** @type {string} */ 110 Event.prototype.type; 111 112 /** @type {EventTarget} */ 113 Event.prototype.target; 114 115 /** @type {EventTarget} */ 116 Event.prototype.currentTarget; 117 118 /** @type {number} */ 119 Event.prototype.eventPhase; 120 121 /** @type {boolean} */ 122 Event.prototype.bubbles; 123 124 /** @type {boolean} */ 125 Event.prototype.cancelable; 126 127 /** @type {number} */ 128 Event.prototype.timeStamp; 129 130 /** 131 * Present for events spawned in browsers that support shadow dom. 132 * @type {Array.<!Element>|undefined} 133 */ 134 Event.prototype.path; 135 136 /** 137 * @return {undefined} 138 */ 139 Event.prototype.stopPropagation = function() {}; 140 141 /** 142 * @return {undefined} 143 */ 144 Event.prototype.preventDefault = function() {}; 145 146 /** 147 * @param {string} eventTypeArg 148 * @param {boolean} canBubbleArg 149 * @param {boolean} cancelableArg 150 * @return {undefined} 151 */ 152 Event.prototype.initEvent = function(eventTypeArg, canBubbleArg, cancelableArg) {}; 153 154 /** 155 * @typedef {{ 156 * bubbles: (boolean|undefined), 157 * cancelable: (boolean|undefined), 158 * detail: * 159 * }} 160 */ 161 var CustomEventInit; 162 163 /** 164 * @constructor 165 * @extends {Event} 166 * @param {string} type 167 * @param {CustomEventInit=} opt_eventInitDict 168 * @see http://www.w3.org/TR/DOM-Level-3-Events/#interface-CustomEvent 169 */ 170 function CustomEvent(type, opt_eventInitDict) {} 171 172 /** 173 * @param {string} eventType 174 * @param {boolean} bubbles 175 * @param {boolean} cancelable 176 * @param {*} detail 177 */ 178 CustomEvent.prototype.initCustomEvent = function( 179 eventType, bubbles, cancelable, detail) {}; 180 181 /** 182 * @type {*} 183 */ 184 CustomEvent.prototype.detail; 185 186 /** 187 * @interface 188 */ 189 function DocumentEvent() {} 190 191 /** 192 * @param {string} eventType 193 * @return {!Event} 194 */ 195 DocumentEvent.prototype.createEvent = function(eventType) {}; 196 197 /** 198 * @typedef {{ 199 * bubbles: (boolean|undefined), 200 * cancelable: (boolean|undefined), 201 * view: (Window|undefined), 202 * detail: (number|undefined) 203 * }} 204 */ 205 var UIEventInit; 206 207 /** 208 * @constructor 209 * @extends {Event} 210 * @param {string} type 211 * @param {UIEventInit=} opt_eventInitDict 212 */ 213 function UIEvent(type, opt_eventInitDict) {} 214 215 /** @type {number} */ 216 UIEvent.prototype.detail; 217 218 /** 219 * @param {string} typeArg 220 * @param {boolean} canBubbleArg 221 * @param {boolean} cancelableArg 222 * @param {Window} viewArg 223 * @param {number} detailArg 224 * @return {undefined} 225 */ 226 UIEvent.prototype.initUIEvent = function(typeArg, canBubbleArg, cancelableArg, 227 viewArg, detailArg) {}; 228 229 /** 230 * @typedef {{ 231 * bubbles: (boolean|undefined), 232 * cancelable: (boolean|undefined), 233 * view: (Window|undefined), 234 * detail: (number|undefined), 235 * screenX: (number|undefined), 236 * screenY: (number|undefined), 237 * clientX: (number|undefined), 238 * clientY: (number|undefined), 239 * ctrlKey: (boolean|undefined), 240 * shiftKey: (boolean|undefined), 241 * altKey: (boolean|undefined), 242 * metaKey: (boolean|undefined), 243 * button: (number|undefined), 244 * buttons: (number|undefined), 245 * relatedTarget: (EventTarget|undefined) 246 * }} 247 */ 248 var MouseEventInit; 249 250 /** 251 * @constructor 252 * @extends {UIEvent} 253 * @param {string} type 254 * @param {MouseEventInit=} opt_eventInitDict 255 */ 256 function MouseEvent(type, opt_eventInitDict) {} 257 258 /** @type {number} */ 259 MouseEvent.prototype.screenX; 260 261 /** @type {number} */ 262 MouseEvent.prototype.screenY; 263 264 /** @type {number} */ 265 MouseEvent.prototype.clientX; 266 267 /** @type {number} */ 268 MouseEvent.prototype.clientY; 269 270 /** @type {boolean} */ 271 MouseEvent.prototype.ctrlKey; 272 273 /** @type {boolean} */ 274 MouseEvent.prototype.shiftKey; 275 276 /** @type {boolean} */ 277 MouseEvent.prototype.altKey; 278 279 /** @type {boolean} */ 280 MouseEvent.prototype.metaKey; 281 282 /** @type {number} */ 283 MouseEvent.prototype.button; 284 285 /** @type {EventTarget} */ 286 MouseEvent.prototype.relatedTarget; 287 288 289 /** 290 * @constructor 291 * @extends {Event} 292 */ 293 function MutationEvent() {} 294 295 /** @type {Node} */ 296 MutationEvent.prototype.relatedNode; 297 298 /** @type {string} */ 299 MutationEvent.prototype.prevValue; 300 301 /** @type {string} */ 302 MutationEvent.prototype.newValue; 303 304 /** @type {string} */ 305 MutationEvent.prototype.attrName; 306 307 /** @type {number} */ 308 MutationEvent.prototype.attrChange; 309 310 /** 311 * @param {string} typeArg 312 * @param {boolean} canBubbleArg 313 * @param {boolean} cancelableArg 314 * @param {Node} relatedNodeArg 315 * @param {string} prevValueArg 316 * @param {string} newValueArg 317 * @param {string} attrNameArg 318 * @param {number} attrChangeArg 319 * @return {undefined} 320 */ 321 MutationEvent.prototype.initMutationEvent = function(typeArg, canBubbleArg, cancelableArg, relatedNodeArg, prevValueArg, newValueArg, attrNameArg, attrChangeArg) {}; 322 323 324 // DOM3 325 /** 326 * @typedef {{ 327 * bubbles: (boolean|undefined), 328 * cancelable: (boolean|undefined), 329 * view: (Window|undefined), 330 * detail: (number|undefined), 331 * char: (string|undefined), 332 * key: (string|undefined), 333 * code: (string|undefined), 334 * location: (number|undefined), 335 * ctrlKey: (boolean|undefined), 336 * shiftKey: (boolean|undefined), 337 * altKey: (boolean|undefined), 338 * metaKey: (boolean|undefined), 339 * repeat: (boolean|undefined), 340 * locale: (string|undefined) 341 * }} 342 */ 343 var KeyboardEventInit; 344 345 /** 346 * @constructor 347 * @extends {UIEvent} 348 * @param {string} type 349 * @param {KeyboardEventInit=} opt_eventInitDict 350 */ 351 function KeyboardEvent(type, opt_eventInitDict) {} 352 353 /** @type {string} */ 354 KeyboardEvent.prototype.keyIdentifier; 355 356 /** @type {boolean} */ 357 KeyboardEvent.prototype.ctrlKey; 358 359 /** @type {boolean} */ 360 KeyboardEvent.prototype.shiftKey; 361 362 /** @type {boolean} */ 363 KeyboardEvent.prototype.altKey; 364 365 /** @type {boolean} */ 366 KeyboardEvent.prototype.metaKey; 367 368 /** 369 * @param {string} keyIdentifierArg 370 * @return {boolean} 371 */ 372 KeyboardEvent.prototype.getModifierState = function(keyIdentifierArg) {};