* @return {?object} A SyntheticCompositionEvent.
(topLevelType, targetInst, nativeEvent, nativeEventTarget)
| 2610 | * @return {?object} A SyntheticCompositionEvent. |
| 2611 | */ |
| 2612 | function extractCompositionEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget) { |
| 2613 | var eventType = void 0; |
| 2614 | var fallbackData = void 0; |
| 2615 | |
| 2616 | if (canUseCompositionEvent) { |
| 2617 | eventType = getCompositionEventType(topLevelType); |
| 2618 | } else if (!isComposing) { |
| 2619 | if (isFallbackCompositionStart(topLevelType, nativeEvent)) { |
| 2620 | eventType = eventTypes.compositionStart; |
| 2621 | } |
| 2622 | } else if (isFallbackCompositionEnd(topLevelType, nativeEvent)) { |
| 2623 | eventType = eventTypes.compositionEnd; |
| 2624 | } |
| 2625 | |
| 2626 | if (!eventType) { |
| 2627 | return null; |
| 2628 | } |
| 2629 | |
| 2630 | if (useFallbackCompositionData) { |
| 2631 | // The current composition is stored statically and must not be |
| 2632 | // overwritten while composition continues. |
| 2633 | if (!isComposing && eventType === eventTypes.compositionStart) { |
| 2634 | isComposing = initialize(nativeEventTarget); |
| 2635 | } else if (eventType === eventTypes.compositionEnd) { |
| 2636 | if (isComposing) { |
| 2637 | fallbackData = getData(); |
| 2638 | } |
| 2639 | } |
| 2640 | } |
| 2641 | |
| 2642 | var event = SyntheticCompositionEvent.getPooled(eventType, targetInst, nativeEvent, nativeEventTarget); |
| 2643 | |
| 2644 | if (fallbackData) { |
| 2645 | // Inject data generated from fallback path into the synthetic event. |
| 2646 | // This matches the property of native CompositionEventInterface. |
| 2647 | event.data = fallbackData; |
| 2648 | } else { |
| 2649 | var customData = getDataFromCustomEvent(nativeEvent); |
| 2650 | if (customData !== null) { |
| 2651 | event.data = customData; |
| 2652 | } |
| 2653 | } |
| 2654 | |
| 2655 | accumulateTwoPhaseDispatches(event); |
| 2656 | return event; |
| 2657 | } |
| 2658 | |
| 2659 | /** |
| 2660 | * @param {TopLevelTypes} topLevelType Record from `BrowserEventConstants`. |
no test coverage detected