2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef ReplaceSelectionCommand_h
27 #define ReplaceSelectionCommand_h
29 #include "CompositeEditCommand.h"
33 class CSSMutableStyleDeclaration;
34 class DocumentFragment;
37 class ReplacementFragment;
39 class ReplaceSelectionCommand : public CompositeEditCommand {
42 SelectReplacement = 1 << 0,
43 SmartReplace = 1 << 1,
45 PreventNesting = 1 << 3,
46 MovingParagraph = 1 << 4
49 typedef unsigned CommandOptions;
51 static PassRefPtr<ReplaceSelectionCommand> create(Document* document, PassRefPtr<DocumentFragment> fragment, CommandOptions options, EditAction action = EditActionPaste)
53 return adoptRef(new ReplaceSelectionCommand(document, fragment, options, action));
57 ReplaceSelectionCommand(Document*, PassRefPtr<DocumentFragment>, CommandOptions, EditAction);
59 virtual void doApply();
60 virtual EditAction editingAction() const;
62 void completeHTMLReplacement(const Position& lastPositionToSelect);
64 void insertNodeAfterAndUpdateNodesInserted(PassRefPtr<Node> insertChild, Node* refChild);
65 void insertNodeAtAndUpdateNodesInserted(PassRefPtr<Node>, const Position&);
66 void insertNodeBeforeAndUpdateNodesInserted(PassRefPtr<Node> insertChild, Node* refChild);
67 Node* insertAsListItems(PassRefPtr<Node>, Node* insertionNode, const Position&);
69 void updateNodesInserted(Node*);
70 bool shouldRemoveEndBR(Node*, const VisiblePosition&);
72 bool shouldMergeStart(bool, bool, bool);
73 bool shouldMergeEnd(bool selectionEndWasEndOfParagraph);
74 bool shouldMerge(const VisiblePosition&, const VisiblePosition&);
76 void mergeEndIfNeeded();
78 void removeUnrenderedTextNodesAtEnds();
80 void removeRedundantStylesAndKeepStyleSpanInline();
81 void handleStyleSpans();
82 void copyStyleToChildren(Node* parentNode, const CSSMutableStyleDeclaration* parentStyle);
83 void handlePasteAsQuotationNode();
85 virtual void removeNodePreservingChildren(Node*);
86 virtual void removeNodeAndPruneAncestors(Node*);
88 VisiblePosition positionAtStartOfInsertedContent();
89 VisiblePosition positionAtEndOfInsertedContent();
91 bool performTrivialReplace(const ReplacementFragment&);
93 RefPtr<Node> m_firstNodeInserted;
94 RefPtr<Node> m_lastLeafInserted;
95 RefPtr<EditingStyle> m_insertionStyle;
96 bool m_selectReplacement;
99 RefPtr<DocumentFragment> m_documentFragment;
100 bool m_preventNesting;
101 bool m_movingParagraph;
102 EditAction m_editAction;
103 bool m_shouldMergeEnd;
106 } // namespace WebCore
108 #endif // ReplaceSelectionCommand_h