1 /* 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 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. 12 * 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. 24 */ 25 26 #ifndef CompositeEditCommand_h 27 #define CompositeEditCommand_h 28 29 #include "EditCommand.h" 30 #include "CSSPropertyNames.h" 31 #include <wtf/Vector.h> 32 33 namespace WebCore { 34 35 class CSSStyleDeclaration; 36 class HTMLElement; 37 class Text; 38 39 class CompositeEditCommand : public EditCommand { 40 public: 41 bool isFirstCommand(EditCommand* command) { return !m_commands.isEmpty() && m_commands.first() == command; } 42 43 protected: 44 CompositeEditCommand(Document*); 45 46 // 47 // sugary-sweet convenience functions to help create and apply edit commands in composite commands 48 // 49 void appendNode(PassRefPtr<Node>, PassRefPtr<Element> parent); 50 void applyCommandToComposite(PassRefPtr<EditCommand>); 51 void applyStyle(CSSStyleDeclaration*, EditAction = EditActionChangeAttributes); 52 void applyStyle(CSSStyleDeclaration*, const Position& start, const Position& end, EditAction = EditActionChangeAttributes); 53 void applyStyledElement(PassRefPtr<Element>); 54 void removeStyledElement(PassRefPtr<Element>); 55 void deleteSelection(bool smartDelete = false, bool mergeBlocksAfterDelete = true, bool replace = false, bool expandForSpecialElements = true); 56 void deleteSelection(const VisibleSelection&, bool smartDelete = false, bool mergeBlocksAfterDelete = true, bool replace = false, bool expandForSpecialElements = true); 57 virtual void deleteTextFromNode(PassRefPtr<Text>, unsigned offset, unsigned count); 58 void inputText(const String&, bool selectInsertedText = false); 59 void insertNodeAfter(PassRefPtr<Node>, PassRefPtr<Node> refChild); 60 void insertNodeAt(PassRefPtr<Node>, const Position&); 61 void insertNodeAtTabSpanPosition(PassRefPtr<Node>, const Position&); 62 void insertNodeBefore(PassRefPtr<Node>, PassRefPtr<Node> refChild); 63 void insertParagraphSeparator(bool useDefaultParagraphElement = false); 64 void insertLineBreak(); 65 void insertTextIntoNode(PassRefPtr<Text>, unsigned offset, const String& text); 66 void joinTextNodes(PassRefPtr<Text>, PassRefPtr<Text>); 67 void mergeIdenticalElements(PassRefPtr<Element>, PassRefPtr<Element>); 68 void rebalanceWhitespace(); 69 void rebalanceWhitespaceAt(const Position&); 70 void prepareWhitespaceAtPositionForSplit(Position&); 71 void removeCSSProperty(PassRefPtr<CSSMutableStyleDeclaration>, CSSPropertyID); 72 void removeNodeAttribute(PassRefPtr<Element>, const QualifiedName& attribute); 73 void removeChildrenInRange(PassRefPtr<Node>, unsigned from, unsigned to); 74 virtual void removeNode(PassRefPtr<Node>); 75 HTMLElement* replaceNodeWithSpanPreservingChildrenAndAttributes(PassRefPtr<Node>); 76 void removeNodePreservingChildren(PassRefPtr<Node>); 77 void removeNodeAndPruneAncestors(PassRefPtr<Node>); 78 void prune(PassRefPtr<Node>); 79 void replaceTextInNode(PassRefPtr<Text>, unsigned offset, unsigned count, const String& replacementText); 80 Position positionOutsideTabSpan(const Position&); 81 void setNodeAttribute(PassRefPtr<Element>, const QualifiedName& attribute, const AtomicString& value); 82 void splitElement(PassRefPtr<Element>, PassRefPtr<Node> atChild); 83 void splitTextNode(PassRefPtr<Text>, unsigned offset); 84 void splitTextNodeContainingElement(PassRefPtr<Text>, unsigned offset); 85 void wrapContentsInDummySpan(PassRefPtr<Element>); 86 87 void deleteInsignificantText(PassRefPtr<Text>, unsigned start, unsigned end); 88 void deleteInsignificantText(const Position& start, const Position& end); 89 void deleteInsignificantTextDownstream(const Position&); 90 91 PassRefPtr<Node> appendBlockPlaceholder(PassRefPtr<Element>); 92 PassRefPtr<Node> insertBlockPlaceholder(const Position&); 93 PassRefPtr<Node> addBlockPlaceholderIfNeeded(Element*); 94 void removePlaceholderAt(const Position&); 95 96 PassRefPtr<Node> insertNewDefaultParagraphElementAt(const Position&); 97 98 PassRefPtr<Node> moveParagraphContentsToNewBlockIfNecessary(const Position&); 99 100 void pushAnchorElementDown(Node*); 101 void pushPartiallySelectedAnchorElementsDown(); 102 103 void moveParagraph(const VisiblePosition&, const VisiblePosition&, const VisiblePosition&, bool preserveSelection = false, bool preserveStyle = true); 104 void moveParagraphs(const VisiblePosition&, const VisiblePosition&, const VisiblePosition&, bool preserveSelection = false, bool preserveStyle = true); 105 void moveParagraphWithClones(const VisiblePosition& startOfParagraphToMove, const VisiblePosition& endOfParagraphToMove, Element* blockElement, Node* outerNode); 106 void cloneParagraphUnderNewElement(Position& start, Position& end, Node* outerNode, Element* blockElement); 107 void cleanupAfterDeletion(); 108 109 bool breakOutOfEmptyListItem(); 110 bool breakOutOfEmptyMailBlockquotedParagraph(); 111 112 Position positionAvoidingSpecialElementBoundary(const Position&); 113 114 PassRefPtr<Node> splitTreeToNode(Node*, Node*, bool splitAncestor = false); 115 116 Vector<RefPtr<EditCommand> > m_commands; 117 118 private: 119 virtual void doUnapply(); 120 virtual void doReapply(); 121 }; 122 123 } // namespace WebCore 124 125 #endif // CompositeEditCommand_h 126