* @param {TopLevelTypes} topLevelType Record from `BrowserEventConstants`. * @param {object} nativeEvent Native browser event. * @return {?string} The string corresponding to this `beforeInput` event.
(topLevelType, nativeEvent)
| 3470 | * @return {?string} The string corresponding to this `beforeInput` event. |
| 3471 | */ |
| 3472 | function getNativeBeforeInputChars(topLevelType, nativeEvent) { |
| 3473 | switch (topLevelType) { |
| 3474 | case 'topCompositionEnd': |
| 3475 | return getDataFromCustomEvent(nativeEvent); |
| 3476 | case 'topKeyPress': |
| 3477 | /** |
| 3478 | * If native `textInput` events are available, our goal is to make |
| 3479 | * use of them. However, there is a special case: the spacebar key. |
| 3480 | * In Webkit, preventing default on a spacebar `textInput` event |
| 3481 | * cancels character insertion, but it *also* causes the browser |
| 3482 | * to fall back to its default spacebar behavior of scrolling the |
| 3483 | * page. |
| 3484 | * |
| 3485 | * Tracking at: |
| 3486 | * https://code.google.com/p/chromium/issues/detail?id=355103 |
| 3487 | * |
| 3488 | * To avoid this issue, use the keypress event as if no `textInput` |
| 3489 | * event is available. |
| 3490 | */ |
| 3491 | var which = nativeEvent.which; |
| 3492 | if (which !== SPACEBAR_CODE) { |
| 3493 | return null; |
| 3494 | } |
| 3495 | |
| 3496 | hasSpaceKeypress = true; |
| 3497 | return SPACEBAR_CHAR; |
| 3498 | |
| 3499 | case 'topTextInput': |
| 3500 | // Record the characters to be added to the DOM. |
| 3501 | var chars = nativeEvent.data; |
| 3502 | |
| 3503 | // If it's a spacebar character, assume that we have already handled |
| 3504 | // it at the keypress level and bail immediately. Android Chrome |
| 3505 | // doesn't give us keycodes, so we need to blacklist it. |
| 3506 | if (chars === SPACEBAR_CHAR && hasSpaceKeypress) { |
| 3507 | return null; |
| 3508 | } |
| 3509 | |
| 3510 | return chars; |
| 3511 | |
| 3512 | default: |
| 3513 | // For other native event types, do nothing. |
| 3514 | return null; |
| 3515 | } |
| 3516 | } |
| 3517 | |
| 3518 | /** |
| 3519 | * For browsers that do not provide the `textInput` event, extract the |
no test coverage detected