 import text.events.CompositionCompletionEvent;
 import text.events.FlowOperationEvent;
 import text.events.SelectionEvent;
-import text.formats.BlockProgression;
 import text.formats.CharacterFormat;
 import text.formats.ContainerFormat;
-import text.formats.Direction;
 import text.formats.ICharacterFormat;
 import text.formats.IContainerFormat;
 import text.formats.IParagraphFormat;
-import text.formats.LineBreak;
 import text.formats.ParagraphFormat;
-import text.formats.TextAlign;
-import text.formats.TextDecoration;
-import text.formats.VerticalAlign;
-import text.formats.WhitespaceCollapse;
 import text.importExport.TextFilter;
 import text.operations.ApplyCharacterFormatOperation;
 import text.operations.ApplyContainerFormatOperation;

import text.container.IContainerController;
import text.edit.EditManager;
import text.edit.ISelectionManager;
import text.edit.SelectionState;
import text.elements.FlowElement;
import text.elements.ParagraphElement;
import text.elements.SpanElement;


	/**
	 *  @private
     *  Keep this method in sync with the same method in TextGraphic.
	 */
	private function createTextFlow():TextFlow
	{
        var p:String;

		if (contentChanged || textChanged)
        {
		    if (contentChanged)
		    {
                if (content is TextFlow)
                {
                    textFlow = TextFlow(content);
                }
                else if (content is Array)
                {
                    textFlow = createEmptyTextFlow();
                    textFlow.mxmlChildren = content as Array;
                }
                else if (content is FlowElement)
                {
                    textFlow = createEmptyTextFlow();
                    textFlow.mxmlChildren = [ content ];
                }
			    else if (content is String)
			    {
				    textFlow = importMarkup(String(content));
			    }
			    else if (content == null)
			    {
				    textFlow = createEmptyTextFlow();
			    }
                else
                {
                    throw new Error("invalid content");
                }
		    }
		    else if (textChanged)
		    {
			    if (text != null && text != "")
			    {
				    textFlow = TextFilter.importFromString(text, TextFilter.PLAIN_TEXT_FORMAT);
			    }
			    else
			    {
				    textFlow = createEmptyTextFlow();
			    }
		    }

            // Build a textFlowTextFormat object which keeps track
            // of which text formats were specified on the TextFlow
            // as opposed to on the TextGraphic.
            // For example, if the 'content' were
            // <TextFlow fontSize="12">...</TextFlow>
            // then the textFlowTextFormat would be { fontSize: 12 }.
            
            var containerFormat:IContainerFormat =
                textFlow.containerFormat;
            var paragraphFormat:IParagraphFormat =
                textFlow.paragraphFormat;
            var characterFormat:ICharacterFormat =
                textFlow.characterFormat;
            
            for each (p in TextUtil.ALL_FORMAT_NAMES)
            {
                var kind:String = TextUtil.FORMAT_MAP[p];

                if (kind == TextUtil.CONTAINER &&
                    containerFormat != null &&
                    containerFormat[p] != null)
                {
                    textFlowTextFormat[p] = containerFormat[p];
                }
                else if (kind == TextUtil.PARAGRAPH &&
                         paragraphFormat != null &&
                         paragraphFormat[p] != null)
                {
                    textFlowTextFormat[p] = paragraphFormat[p];
                }
                else if (kind == TextUtil.CHARACTER &&
                         characterFormat != null &&
                         characterFormat[p] != null)
                {
                    textFlowTextFormat[p] = characterFormat[p];
                }
            }
        }

		contentChanged = false;
		textChanged = false;

        // For each attribute whose value wasn't specified by the TextFlow,
        // apply the value from the TextGraphic.
        
        for each (p in TextUtil.ALL_FORMAT_NAMES)
        {
            if (!(p in textFlowTextFormat))
            {
            	var value:* = getStyle(p);
            	if (p == "tabStops" && value === undefined)
            		value = null; // TODO Setting this to [] causes RTE during paste
            	textFlow[p] = value;
            }
         }
        
		return textFlow;
	}

