* @param {TopLevelTypes} topLevelType Record from `BrowserEventConstants`. * @param {object} nativeEvent Native browser event. * @return {?string} The string corresponding to this `beforeInput` event.
(topLevelType, nativeEvent)
| 3332 | * @return {?string} The string corresponding to this `beforeInput` event. |
| 3333 | */ |
| 3334 | function getNativeBeforeInputChars(topLevelType, nativeEvent) { |
| 3335 | switch (topLevelType) { |
| 3336 | case 'topCompositionEnd': |
| 3337 | return getDataFromCustomEvent(nativeEvent); |
| 3338 | case 'topKeyPress': |
| 3339 | /** |
| 3340 | * If native `textInput` events are available, our goal is to make |
| 3341 | * use of them. However, there is a special case: the spacebar key. |
| 3342 | * In Webkit, preventing default on a spacebar `textInput` event |
| 3343 | * cancels character insertion, but it *also* causes the browser |
| 3344 | * to fall back to its default spacebar behavior of scrolling the |
| 3345 | * page. |
| 3346 | * |
| 3347 | * Tracking at: |
| 3348 | * https://code.google.com/p/chromium/issues/detail?id=355103 |
| 3349 | * |
| 3350 | * To avoid this issue, use the keypress event as if no `textInput` |
| 3351 | * event is available. |
| 3352 | */ |
| 3353 | var which = nativeEvent.which; |
| 3354 | if (which !== SPACEBAR_CODE) { |
| 3355 | return null; |
| 3356 | } |
| 3357 | |
| 3358 | hasSpaceKeypress = true; |
| 3359 | return SPACEBAR_CHAR; |
| 3360 | |
| 3361 | case 'topTextInput': |
| 3362 | // Record the characters to be added to the DOM. |
| 3363 | var chars = nativeEvent.data; |
| 3364 | |
| 3365 | // If it's a spacebar character, assume that we have already handled |
| 3366 | // it at the keypress level and bail immediately. Android Chrome |
| 3367 | // doesn't give us keycodes, so we need to blacklist it. |
| 3368 | if (chars === SPACEBAR_CHAR && hasSpaceKeypress) { |
| 3369 | return null; |
| 3370 | } |
| 3371 | |
| 3372 | return chars; |
| 3373 | |
| 3374 | default: |
| 3375 | // For other native event types, do nothing. |
| 3376 | return null; |
| 3377 | } |
| 3378 | } |
| 3379 | |
| 3380 | /** |
| 3381 | * For browsers that do not provide the `textInput` event, extract the |
no test coverage detected