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