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 Text; 37 38 class CompositeEditCommand : public EditCommand { 39 public: isFirstCommand(EditCommand * command)40 bool isFirstCommand(EditCommand* command) { return !m_commands.isEmpty() && m_commands.first() == command; } 41 42 protected: 43 CompositeEditCommand(Document*); 44 45 // 46 // sugary-sweet convenience functions to help create and apply edit commands in composite commands 47 // 48 void appendNode(PassRefPtr<Node>, PassRefPtr<Element> parent); 49 void applyCommandToComposite(PassRefPtr<EditCommand>); 50 void applyStyle(CSSStyleDeclaration*, EditAction = EditActionChangeAttributes); 51 void applyStyle(CSSStyleDeclaration*, const Position& start, const Position& end, EditAction = EditActionChangeAttributes); 52 void applyStyledElement(PassRefPtr<Element>); 53 void removeStyledElement(PassRefPtr<Element>); 54 void deleteSelection(bool smartDelete = false, bool mergeBlocksAfterDelete = true, bool replace = false, bool expandForSpecialElements = true); 55 void deleteSelection(const Selection&, bool smartDelete = false, bool mergeBlocksAfterDelete = true, bool replace = false, bool expandForSpecialElements = true); 56 virtual void deleteTextFromNode(PassRefPtr<Text>, unsigned offset, unsigned count); 57 void inputText(const String&, bool selectInsertedText = false); 58 void insertNodeAfter(PassRefPtr<Node>, PassRefPtr<Node> refChild); 59 void insertNodeAt(PassRefPtr<Node>, const Position&); 60 void insertNodeAtTabSpanPosition(PassRefPtr<Node>, const Position&); 61 void insertNodeBefore(PassRefPtr<Node>, PassRefPtr<Node> refChild); 62 void insertParagraphSeparator(bool useDefaultParagraphElement = false); 63 void insertLineBreak(); 64 void insertTextIntoNode(PassRefPtr<Text>, unsigned offset, const String& text); 65 void joinTextNodes(PassRefPtr<Text>, PassRefPtr<Text>); 66 void mergeIdenticalElements(PassRefPtr<Element>, PassRefPtr<Element>); 67 void rebalanceWhitespace(); 68 void rebalanceWhitespaceAt(const Position&); 69 void prepareWhitespaceAtPositionForSplit(Position&); 70 void removeCSSProperty(PassRefPtr<CSSMutableStyleDeclaration>, CSSPropertyID); 71 void removeNodeAttribute(PassRefPtr<Element>, const QualifiedName& attribute); 72 void removeChildrenInRange(PassRefPtr<Node>, unsigned from, unsigned to); 73 virtual void removeNode(PassRefPtr<Node>); 74 void removeNodePreservingChildren(PassRefPtr<Node>); 75 void removeNodeAndPruneAncestors(PassRefPtr<Node>); 76 void prune(PassRefPtr<Node>); 77 void replaceTextInNode(PassRefPtr<Text>, unsigned offset, unsigned count, const String& replacementText); 78 Position positionOutsideTabSpan(const Position&); 79 void setNodeAttribute(PassRefPtr<Element>, const QualifiedName& attribute, const AtomicString& value); 80 void splitElement(PassRefPtr<Element>, PassRefPtr<Node> atChild); 81 void splitTextNode(PassRefPtr<Text>, unsigned offset); 82 void splitTextNodeContainingElement(PassRefPtr<Text>, unsigned offset); 83 void wrapContentsInDummySpan(PassRefPtr<Element>); 84 85 void deleteInsignificantText(PassRefPtr<Text>, unsigned start, unsigned end); 86 void deleteInsignificantText(const Position& start, const Position& end); 87 void deleteInsignificantTextDownstream(const Position&); 88 89 PassRefPtr<Node> appendBlockPlaceholder(PassRefPtr<Element>); 90 PassRefPtr<Node> insertBlockPlaceholder(const Position&); 91 PassRefPtr<Node> addBlockPlaceholderIfNeeded(Element*); 92 void removePlaceholderAt(const VisiblePosition&); 93 94 PassRefPtr<Node> insertNewDefaultParagraphElementAt(const Position&); 95 96 PassRefPtr<Node> moveParagraphContentsToNewBlockIfNecessary(const Position&); 97 98 void pushAnchorElementDown(Node*); 99 void pushPartiallySelectedAnchorElementsDown(); 100 101 void moveParagraph(const VisiblePosition&, const VisiblePosition&, const VisiblePosition&, bool preserveSelection = false, bool preserveStyle = true); 102 void moveParagraphs(const VisiblePosition&, const VisiblePosition&, const VisiblePosition&, bool preserveSelection = false, bool preserveStyle = true); 103 104 bool breakOutOfEmptyListItem(); 105 bool breakOutOfEmptyMailBlockquotedParagraph(); 106 107 Position positionAvoidingSpecialElementBoundary(const Position&); 108 109 PassRefPtr<Node> splitTreeToNode(Node*, Node*, bool splitAncestor = false); 110 111 Vector<RefPtr<EditCommand> > m_commands; 112 113 private: 114 virtual void doUnapply(); 115 virtual void doReapply(); 116 }; 117 118 } // namespace WebCore 119 120 #endif // CompositeEditCommand_h 121