* @param {string} topLevelType Record from `EventConstants`. * @param {object} nativeEvent Native browser event. * @return {?string} The string corresponding to this `beforeInput` event.
(topLevelType, nativeEvent)
| 260 | * @return {?string} The string corresponding to this `beforeInput` event. |
| 261 | */ |
| 262 | function getNativeBeforeInputChars(topLevelType, nativeEvent) { |
| 263 | switch (topLevelType) { |
| 264 | case topLevelTypes.topCompositionEnd: |
| 265 | return getDataFromCustomEvent(nativeEvent); |
| 266 | case topLevelTypes.topKeyPress: |
| 267 | /** |
| 268 | * If native `textInput` events are available, our goal is to make |
| 269 | * use of them. However, there is a special case: the spacebar key. |
| 270 | * In Webkit, preventing default on a spacebar `textInput` event |
| 271 | * cancels character insertion, but it *also* causes the browser |
| 272 | * to fall back to its default spacebar behavior of scrolling the |
| 273 | * page. |
| 274 | * |
| 275 | * Tracking at: |
| 276 | * https://code.google.com/p/chromium/issues/detail?id=355103 |
| 277 | * |
| 278 | * To avoid this issue, use the keypress event as if no `textInput` |
| 279 | * event is available. |
| 280 | */ |
| 281 | var which = nativeEvent.which; |
| 282 | if (which !== SPACEBAR_CODE) { |
| 283 | return null; |
| 284 | } |
| 285 | |
| 286 | hasSpaceKeypress = true; |
| 287 | return SPACEBAR_CHAR; |
| 288 | |
| 289 | case topLevelTypes.topTextInput: |
| 290 | // Record the characters to be added to the DOM. |
| 291 | var chars = nativeEvent.data; |
| 292 | |
| 293 | // If it's a spacebar character, assume that we have already handled |
| 294 | // it at the keypress level and bail immediately. Android Chrome |
| 295 | // doesn't give us keycodes, so we need to blacklist it. |
| 296 | if (chars === SPACEBAR_CHAR && hasSpaceKeypress) { |
| 297 | return null; |
| 298 | } |
| 299 | |
| 300 | return chars; |
| 301 | |
| 302 | default: |
| 303 | // For other native event types, do nothing. |
| 304 | return null; |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * For browsers that do not provide the `textInput` event, extract the |
no test coverage detected
searching dependent graphs…