* For browsers that do not provide the `textInput` event, extract the * appropriate string to use for SyntheticInputEvent. * * @param {string} topLevelType Record from `EventConstants`. * @param {object} nativeEvent Native browser event. * @return {?string} The fallback string for this `beforeI
(topLevelType, nativeEvent)
| 371 | * @return {?string} The fallback string for this `beforeInput` event. |
| 372 | */ |
| 373 | function getFallbackBeforeInputChars(topLevelType, nativeEvent) { |
| 374 | // If we are currently composing (IME) and using a fallback to do so, |
| 375 | // try to extract the composed characters from the fallback object. |
| 376 | if (currentComposition) { |
| 377 | if (topLevelType === topLevelTypes.topCompositionEnd || isFallbackCompositionEnd(topLevelType, nativeEvent)) { |
| 378 | var chars = currentComposition.getData(); |
| 379 | FallbackCompositionState.release(currentComposition); |
| 380 | currentComposition = null; |
| 381 | return chars; |
| 382 | } |
| 383 | return null; |
| 384 | } |
| 385 | |
| 386 | switch (topLevelType) { |
| 387 | case topLevelTypes.topPaste: |
| 388 | // If a paste event occurs after a keypress, throw out the input |
| 389 | // chars. Paste events should not lead to BeforeInput events. |
| 390 | return null; |
| 391 | case topLevelTypes.topKeyPress: |
| 392 | /** |
| 393 | * As of v27, Firefox may fire keypress events even when no character |
| 394 | * will be inserted. A few possibilities: |
| 395 | * |
| 396 | * - `which` is `0`. Arrow keys, Esc key, etc. |
| 397 | * |
| 398 | * - `which` is the pressed key code, but no char is available. |
| 399 | * Ex: 'AltGr + d` in Polish. There is no modified character for |
| 400 | * this key combination and no character is inserted into the |
| 401 | * document, but FF fires the keypress for char code `100` anyway. |
| 402 | * No `input` event will occur. |
| 403 | * |
| 404 | * - `which` is the pressed key code, but a command combination is |
| 405 | * being used. Ex: `Cmd+C`. No character is inserted, and no |
| 406 | * `input` event will occur. |
| 407 | */ |
| 408 | if (nativeEvent.which && !isKeypressCommand(nativeEvent)) { |
| 409 | return String.fromCharCode(nativeEvent.which); |
| 410 | } |
| 411 | return null; |
| 412 | case topLevelTypes.topCompositionEnd: |
| 413 | return useFallbackCompositionData ? null : nativeEvent.data; |
| 414 | default: |
| 415 | return null; |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * Extract a SyntheticInputEvent for `beforeInput`, based on either native |
no test coverage detected