* @param {TopLevelTypes} topLevelType Record from `BrowserEventConstants`. * @param {object} nativeEvent Native browser event. * @return {?string} The string corresponding to this `beforeInput` event.
(topLevelType, nativeEvent)
| 3583 | * @return {?string} The string corresponding to this `beforeInput` event. |
| 3584 | */ |
| 3585 | function getNativeBeforeInputChars(topLevelType, nativeEvent) { |
| 3586 | switch (topLevelType) { |
| 3587 | case 'topCompositionEnd': |
| 3588 | return getDataFromCustomEvent(nativeEvent); |
| 3589 | case 'topKeyPress': |
| 3590 | /** |
| 3591 | * If native `textInput` events are available, our goal is to make |
| 3592 | * use of them. However, there is a special case: the spacebar key. |
| 3593 | * In Webkit, preventing default on a spacebar `textInput` event |
| 3594 | * cancels character insertion, but it *also* causes the browser |
| 3595 | * to fall back to its default spacebar behavior of scrolling the |
| 3596 | * page. |
| 3597 | * |
| 3598 | * Tracking at: |
| 3599 | * https://code.google.com/p/chromium/issues/detail?id=355103 |
| 3600 | * |
| 3601 | * To avoid this issue, use the keypress event as if no `textInput` |
| 3602 | * event is available. |
| 3603 | */ |
| 3604 | var which = nativeEvent.which; |
| 3605 | if (which !== SPACEBAR_CODE) { |
| 3606 | return null; |
| 3607 | } |
| 3608 | |
| 3609 | hasSpaceKeypress = true; |
| 3610 | return SPACEBAR_CHAR; |
| 3611 | |
| 3612 | case 'topTextInput': |
| 3613 | // Record the characters to be added to the DOM. |
| 3614 | var chars = nativeEvent.data; |
| 3615 | |
| 3616 | // If it's a spacebar character, assume that we have already handled |
| 3617 | // it at the keypress level and bail immediately. Android Chrome |
| 3618 | // doesn't give us keycodes, so we need to blacklist it. |
| 3619 | if (chars === SPACEBAR_CHAR && hasSpaceKeypress) { |
| 3620 | return null; |
| 3621 | } |
| 3622 | |
| 3623 | return chars; |
| 3624 | |
| 3625 | default: |
| 3626 | // For other native event types, do nothing. |
| 3627 | return null; |
| 3628 | } |
| 3629 | } |
| 3630 | |
| 3631 | /** |
| 3632 | * For browsers that do not provide the `textInput` event, extract the |
no test coverage detected