* @return {?object} A SyntheticCompositionEvent.
(topLevelType, targetInst, nativeEvent, nativeEventTarget)
| 2641 | * @return {?object} A SyntheticCompositionEvent. |
| 2642 | */ |
| 2643 | function extractCompositionEvent(topLevelType, targetInst, nativeEvent, nativeEventTarget) { |
| 2644 | var eventType = void 0; |
| 2645 | var fallbackData = void 0; |
| 2646 | |
| 2647 | if (canUseCompositionEvent) { |
| 2648 | eventType = getCompositionEventType(topLevelType); |
| 2649 | } else if (!isComposing) { |
| 2650 | if (isFallbackCompositionStart(topLevelType, nativeEvent)) { |
| 2651 | eventType = eventTypes.compositionStart; |
| 2652 | } |
| 2653 | } else if (isFallbackCompositionEnd(topLevelType, nativeEvent)) { |
| 2654 | eventType = eventTypes.compositionEnd; |
| 2655 | } |
| 2656 | |
| 2657 | if (!eventType) { |
| 2658 | return null; |
| 2659 | } |
| 2660 | |
| 2661 | if (useFallbackCompositionData) { |
| 2662 | // The current composition is stored statically and must not be |
| 2663 | // overwritten while composition continues. |
| 2664 | if (!isComposing && eventType === eventTypes.compositionStart) { |
| 2665 | isComposing = initialize(nativeEventTarget); |
| 2666 | } else if (eventType === eventTypes.compositionEnd) { |
| 2667 | if (isComposing) { |
| 2668 | fallbackData = getData(); |
| 2669 | } |
| 2670 | } |
| 2671 | } |
| 2672 | |
| 2673 | var event = SyntheticCompositionEvent.getPooled(eventType, targetInst, nativeEvent, nativeEventTarget); |
| 2674 | |
| 2675 | if (fallbackData) { |
| 2676 | // Inject data generated from fallback path into the synthetic event. |
| 2677 | // This matches the property of native CompositionEventInterface. |
| 2678 | event.data = fallbackData; |
| 2679 | } else { |
| 2680 | var customData = getDataFromCustomEvent(nativeEvent); |
| 2681 | if (customData !== null) { |
| 2682 | event.data = customData; |
| 2683 | } |
| 2684 | } |
| 2685 | |
| 2686 | accumulateTwoPhaseDispatches(event); |
| 2687 | return event; |
| 2688 | } |
| 2689 | |
| 2690 | /** |
| 2691 | * @param {TopLevelTypes} topLevelType Record from `BrowserEventConstants`. |
no test coverage detected