* @param {TopLevelTypes} topLevelType Record from `BrowserEventConstants`. * @param {object} nativeEvent Native browser event. * @return {?string} The string corresponding to this `beforeInput` event.
(topLevelType, nativeEvent)
| 2693 | * @return {?string} The string corresponding to this `beforeInput` event. |
| 2694 | */ |
| 2695 | function getNativeBeforeInputChars(topLevelType, nativeEvent) { |
| 2696 | switch (topLevelType) { |
| 2697 | case 'topCompositionEnd': |
| 2698 | return getDataFromCustomEvent(nativeEvent); |
| 2699 | case 'topKeyPress': |
| 2700 | /** |
| 2701 | * If native `textInput` events are available, our goal is to make |
| 2702 | * use of them. However, there is a special case: the spacebar key. |
| 2703 | * In Webkit, preventing default on a spacebar `textInput` event |
| 2704 | * cancels character insertion, but it *also* causes the browser |
| 2705 | * to fall back to its default spacebar behavior of scrolling the |
| 2706 | * page. |
| 2707 | * |
| 2708 | * Tracking at: |
| 2709 | * https://code.google.com/p/chromium/issues/detail?id=355103 |
| 2710 | * |
| 2711 | * To avoid this issue, use the keypress event as if no `textInput` |
| 2712 | * event is available. |
| 2713 | */ |
| 2714 | var which = nativeEvent.which; |
| 2715 | if (which !== SPACEBAR_CODE) { |
| 2716 | return null; |
| 2717 | } |
| 2718 | |
| 2719 | hasSpaceKeypress = true; |
| 2720 | return SPACEBAR_CHAR; |
| 2721 | |
| 2722 | case 'topTextInput': |
| 2723 | // Record the characters to be added to the DOM. |
| 2724 | var chars = nativeEvent.data; |
| 2725 | |
| 2726 | // If it's a spacebar character, assume that we have already handled |
| 2727 | // it at the keypress level and bail immediately. Android Chrome |
| 2728 | // doesn't give us keycodes, so we need to blacklist it. |
| 2729 | if (chars === SPACEBAR_CHAR && hasSpaceKeypress) { |
| 2730 | return null; |
| 2731 | } |
| 2732 | |
| 2733 | return chars; |
| 2734 | |
| 2735 | default: |
| 2736 | // For other native event types, do nothing. |
| 2737 | return null; |
| 2738 | } |
| 2739 | } |
| 2740 | |
| 2741 | /** |
| 2742 | * For browsers that do not provide the `textInput` event, extract the |
no test coverage detected