* @param {TopLevelTypes} topLevelType Record from `BrowserEventConstants`. * @param {object} nativeEvent Native browser event. * @return {?string} The string corresponding to this `beforeInput` event.
(topLevelType, nativeEvent)
| 3367 | * @return {?string} The string corresponding to this `beforeInput` event. |
| 3368 | */ |
| 3369 | function getNativeBeforeInputChars(topLevelType, nativeEvent) { |
| 3370 | switch (topLevelType) { |
| 3371 | case 'topCompositionEnd': |
| 3372 | return getDataFromCustomEvent(nativeEvent); |
| 3373 | case 'topKeyPress': |
| 3374 | /** |
| 3375 | * If native `textInput` events are available, our goal is to make |
| 3376 | * use of them. However, there is a special case: the spacebar key. |
| 3377 | * In Webkit, preventing default on a spacebar `textInput` event |
| 3378 | * cancels character insertion, but it *also* causes the browser |
| 3379 | * to fall back to its default spacebar behavior of scrolling the |
| 3380 | * page. |
| 3381 | * |
| 3382 | * Tracking at: |
| 3383 | * https://code.google.com/p/chromium/issues/detail?id=355103 |
| 3384 | * |
| 3385 | * To avoid this issue, use the keypress event as if no `textInput` |
| 3386 | * event is available. |
| 3387 | */ |
| 3388 | var which = nativeEvent.which; |
| 3389 | if (which !== SPACEBAR_CODE) { |
| 3390 | return null; |
| 3391 | } |
| 3392 | |
| 3393 | hasSpaceKeypress = true; |
| 3394 | return SPACEBAR_CHAR; |
| 3395 | |
| 3396 | case 'topTextInput': |
| 3397 | // Record the characters to be added to the DOM. |
| 3398 | var chars = nativeEvent.data; |
| 3399 | |
| 3400 | // If it's a spacebar character, assume that we have already handled |
| 3401 | // it at the keypress level and bail immediately. Android Chrome |
| 3402 | // doesn't give us keycodes, so we need to blacklist it. |
| 3403 | if (chars === SPACEBAR_CHAR && hasSpaceKeypress) { |
| 3404 | return null; |
| 3405 | } |
| 3406 | |
| 3407 | return chars; |
| 3408 | |
| 3409 | default: |
| 3410 | // For other native event types, do nothing. |
| 3411 | return null; |
| 3412 | } |
| 3413 | } |
| 3414 | |
| 3415 | /** |
| 3416 | * For browsers that do not provide the `textInput` event, extract the |
no test coverage detected