| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 namespace WebCore { | 34 namespace WebCore { |
| 35 | 35 |
| 36 class EditingStyle; | 36 class EditingStyle; |
| 37 class Element; | 37 class Element; |
| 38 class HTMLElement; | 38 class HTMLElement; |
| 39 class Text; | 39 class Text; |
| 40 | 40 |
| 41 class EditCommandComposition FINAL : public UndoStep { | 41 class EditCommandComposition FINAL : public UndoStep { |
| 42 public: | 42 public: |
| 43 static PassRefPtr<EditCommandComposition> create(Document*, const VisibleSel
ection&, const VisibleSelection&, EditAction); | 43 static PassRefPtrWillBeRawPtr<EditCommandComposition> create(Document*, cons
t VisibleSelection&, const VisibleSelection&, EditAction); |
| 44 | 44 |
| 45 virtual bool belongsTo(const LocalFrame&) const OVERRIDE; | 45 virtual bool belongsTo(const LocalFrame&) const OVERRIDE; |
| 46 virtual void unapply() OVERRIDE; | 46 virtual void unapply() OVERRIDE; |
| 47 virtual void reapply() OVERRIDE; | 47 virtual void reapply() OVERRIDE; |
| 48 virtual EditAction editingAction() const OVERRIDE { return m_editAction; } | 48 virtual EditAction editingAction() const OVERRIDE { return m_editAction; } |
| 49 void append(SimpleEditCommand*); | 49 void append(SimpleEditCommand*); |
| 50 bool wasCreateLinkCommand() const { return m_editAction == EditActionCreateL
ink; } | 50 bool wasCreateLinkCommand() const { return m_editAction == EditActionCreateL
ink; } |
| 51 | 51 |
| 52 const VisibleSelection& startingSelection() const { return m_startingSelecti
on; } | 52 const VisibleSelection& startingSelection() const { return m_startingSelecti
on; } |
| 53 const VisibleSelection& endingSelection() const { return m_endingSelection;
} | 53 const VisibleSelection& endingSelection() const { return m_endingSelection;
} |
| 54 void setStartingSelection(const VisibleSelection&); | 54 void setStartingSelection(const VisibleSelection&); |
| 55 void setEndingSelection(const VisibleSelection&); | 55 void setEndingSelection(const VisibleSelection&); |
| 56 Element* startingRootEditableElement() const { return m_startingRootEditable
Element.get(); } | 56 Element* startingRootEditableElement() const { return m_startingRootEditable
Element.get(); } |
| 57 Element* endingRootEditableElement() const { return m_endingRootEditableElem
ent.get(); } | 57 Element* endingRootEditableElement() const { return m_endingRootEditableElem
ent.get(); } |
| 58 | 58 |
| 59 virtual void trace(Visitor*) OVERRIDE; |
| 60 |
| 59 private: | 61 private: |
| 60 EditCommandComposition(Document*, const VisibleSelection& startingSelection,
const VisibleSelection& endingSelection, EditAction); | 62 EditCommandComposition(Document*, const VisibleSelection& startingSelection,
const VisibleSelection& endingSelection, EditAction); |
| 61 | 63 |
| 62 RefPtr<Document> m_document; | 64 RefPtrWillBeMember<Document> m_document; |
| 63 VisibleSelection m_startingSelection; | 65 VisibleSelection m_startingSelection; |
| 64 VisibleSelection m_endingSelection; | 66 VisibleSelection m_endingSelection; |
| 65 Vector<RefPtr<SimpleEditCommand> > m_commands; | 67 WillBeHeapVector<RefPtrWillBeMember<SimpleEditCommand> > m_commands; |
| 66 RefPtr<Element> m_startingRootEditableElement; | 68 RefPtrWillBeMember<Element> m_startingRootEditableElement; |
| 67 RefPtr<Element> m_endingRootEditableElement; | 69 RefPtrWillBeMember<Element> m_endingRootEditableElement; |
| 68 EditAction m_editAction; | 70 EditAction m_editAction; |
| 69 }; | 71 }; |
| 70 | 72 |
| 71 class CompositeEditCommand : public EditCommand { | 73 class CompositeEditCommand : public EditCommand { |
| 72 public: | 74 public: |
| 73 virtual ~CompositeEditCommand(); | 75 virtual ~CompositeEditCommand(); |
| 74 | 76 |
| 75 void apply(); | 77 void apply(); |
| 76 bool isFirstCommand(EditCommand* command) { return !m_commands.isEmpty() &&
m_commands.first() == command; } | 78 bool isFirstCommand(EditCommand* command) { return !m_commands.isEmpty() &&
m_commands.first() == command; } |
| 77 EditCommandComposition* composition() { return m_composition.get(); } | 79 EditCommandComposition* composition() { return m_composition.get(); } |
| 78 EditCommandComposition* ensureComposition(); | 80 EditCommandComposition* ensureComposition(); |
| 79 | 81 |
| 80 virtual bool isTypingCommand() const; | 82 virtual bool isTypingCommand() const; |
| 81 virtual bool preservesTypingStyle() const; | 83 virtual bool preservesTypingStyle() const; |
| 82 virtual void setShouldRetainAutocorrectionIndicator(bool); | 84 virtual void setShouldRetainAutocorrectionIndicator(bool); |
| 83 virtual bool shouldStopCaretBlinking() const { return false; } | 85 virtual bool shouldStopCaretBlinking() const { return false; } |
| 84 | 86 |
| 87 virtual void trace(Visitor*) OVERRIDE; |
| 88 |
| 85 protected: | 89 protected: |
| 86 explicit CompositeEditCommand(Document&); | 90 explicit CompositeEditCommand(Document&); |
| 87 | 91 |
| 88 // | 92 // |
| 89 // sugary-sweet convenience functions to help create and apply edit commands
in composite commands | 93 // sugary-sweet convenience functions to help create and apply edit commands
in composite commands |
| 90 // | 94 // |
| 91 void appendNode(PassRefPtr<Node>, PassRefPtr<ContainerNode> parent); | 95 void appendNode(PassRefPtrWillBeRawPtr<Node>, PassRefPtrWillBeRawPtr<Contain
erNode> parent); |
| 92 void applyCommandToComposite(PassRefPtr<EditCommand>); | 96 void applyCommandToComposite(PassRefPtrWillBeRawPtr<EditCommand>); |
| 93 void applyCommandToComposite(PassRefPtr<CompositeEditCommand>, const Visible
Selection&); | 97 void applyCommandToComposite(PassRefPtrWillBeRawPtr<CompositeEditCommand>, c
onst VisibleSelection&); |
| 94 void applyStyle(const EditingStyle*, EditAction = EditActionChangeAttributes
); | 98 void applyStyle(const EditingStyle*, EditAction = EditActionChangeAttributes
); |
| 95 void applyStyle(const EditingStyle*, const Position& start, const Position&
end, EditAction = EditActionChangeAttributes); | 99 void applyStyle(const EditingStyle*, const Position& start, const Position&
end, EditAction = EditActionChangeAttributes); |
| 96 void applyStyledElement(PassRefPtr<Element>); | 100 void applyStyledElement(PassRefPtrWillBeRawPtr<Element>); |
| 97 void removeStyledElement(PassRefPtr<Element>); | 101 void removeStyledElement(PassRefPtrWillBeRawPtr<Element>); |
| 98 void deleteSelection(bool smartDelete = false, bool mergeBlocksAfterDelete =
true, bool expandForSpecialElements = true, bool sanitizeMarkup = true); | 102 void deleteSelection(bool smartDelete = false, bool mergeBlocksAfterDelete =
true, bool expandForSpecialElements = true, bool sanitizeMarkup = true); |
| 99 void deleteSelection(const VisibleSelection&, bool smartDelete = false, bool
mergeBlocksAfterDelete = true, bool expandForSpecialElements = true, bool sanit
izeMarkup = true); | 103 void deleteSelection(const VisibleSelection&, bool smartDelete = false, bool
mergeBlocksAfterDelete = true, bool expandForSpecialElements = true, bool sanit
izeMarkup = true); |
| 100 virtual void deleteTextFromNode(PassRefPtrWillBeRawPtr<Text>, unsigned offse
t, unsigned count); | 104 virtual void deleteTextFromNode(PassRefPtrWillBeRawPtr<Text>, unsigned offse
t, unsigned count); |
| 101 bool isRemovableBlock(const Node*); | 105 bool isRemovableBlock(const Node*); |
| 102 void insertNodeAfter(PassRefPtr<Node>, PassRefPtr<Node> refChild); | 106 void insertNodeAfter(PassRefPtrWillBeRawPtr<Node>, PassRefPtrWillBeRawPtr<No
de> refChild); |
| 103 void insertNodeAt(PassRefPtr<Node>, const Position&); | 107 void insertNodeAt(PassRefPtrWillBeRawPtr<Node>, const Position&); |
| 104 void insertNodeAtTabSpanPosition(PassRefPtr<Node>, const Position&); | 108 void insertNodeAtTabSpanPosition(PassRefPtrWillBeRawPtr<Node>, const Positio
n&); |
| 105 void insertNodeBefore(PassRefPtr<Node>, PassRefPtr<Node> refChild, ShouldAss
umeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable); | 109 void insertNodeBefore(PassRefPtrWillBeRawPtr<Node>, PassRefPtrWillBeRawPtr<N
ode> refChild, ShouldAssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysE
ditable); |
| 106 void insertParagraphSeparator(bool useDefaultParagraphElement = false, bool
pasteBlockqutoeIntoUnquotedArea = false); | 110 void insertParagraphSeparator(bool useDefaultParagraphElement = false, bool
pasteBlockqutoeIntoUnquotedArea = false); |
| 107 void insertTextIntoNode(PassRefPtrWillBeRawPtr<Text>, unsigned offset, const
String& text); | 111 void insertTextIntoNode(PassRefPtrWillBeRawPtr<Text>, unsigned offset, const
String& text); |
| 108 void mergeIdenticalElements(PassRefPtr<Element>, PassRefPtr<Element>); | 112 void mergeIdenticalElements(PassRefPtrWillBeRawPtr<Element>, PassRefPtrWillB
eRawPtr<Element>); |
| 109 void rebalanceWhitespace(); | 113 void rebalanceWhitespace(); |
| 110 void rebalanceWhitespaceAt(const Position&); | 114 void rebalanceWhitespaceAt(const Position&); |
| 111 void rebalanceWhitespaceOnTextSubstring(PassRefPtrWillBeRawPtr<Text>, int st
artOffset, int endOffset); | 115 void rebalanceWhitespaceOnTextSubstring(PassRefPtrWillBeRawPtr<Text>, int st
artOffset, int endOffset); |
| 112 void prepareWhitespaceAtPositionForSplit(Position&); | 116 void prepareWhitespaceAtPositionForSplit(Position&); |
| 113 void replaceCollapsibleWhitespaceWithNonBreakingSpaceIfNeeded(const VisibleP
osition&); | 117 void replaceCollapsibleWhitespaceWithNonBreakingSpaceIfNeeded(const VisibleP
osition&); |
| 114 bool canRebalance(const Position&) const; | 118 bool canRebalance(const Position&) const; |
| 115 bool shouldRebalanceLeadingWhitespaceFor(const String&) const; | 119 bool shouldRebalanceLeadingWhitespaceFor(const String&) const; |
| 116 void removeCSSProperty(PassRefPtr<Element>, CSSPropertyID); | 120 void removeCSSProperty(PassRefPtrWillBeRawPtr<Element>, CSSPropertyID); |
| 117 void removeNodeAttribute(PassRefPtr<Element>, const QualifiedName& attribute
); | 121 void removeNodeAttribute(PassRefPtrWillBeRawPtr<Element>, const QualifiedNam
e& attribute); |
| 118 void removeChildrenInRange(PassRefPtr<Node>, unsigned from, unsigned to); | 122 void removeChildrenInRange(PassRefPtrWillBeRawPtr<Node>, unsigned from, unsi
gned to); |
| 119 virtual void removeNode(PassRefPtr<Node>, ShouldAssumeContentIsAlwaysEditabl
e = DoNotAssumeContentIsAlwaysEditable); | 123 virtual void removeNode(PassRefPtrWillBeRawPtr<Node>, ShouldAssumeContentIsA
lwaysEditable = DoNotAssumeContentIsAlwaysEditable); |
| 120 HTMLElement* replaceElementWithSpanPreservingChildrenAndAttributes(PassRefPt
rWillBeRawPtr<HTMLElement>); | 124 HTMLElement* replaceElementWithSpanPreservingChildrenAndAttributes(PassRefPt
rWillBeRawPtr<HTMLElement>); |
| 121 void removeNodePreservingChildren(PassRefPtr<Node>, ShouldAssumeContentIsAlw
aysEditable = DoNotAssumeContentIsAlwaysEditable); | 125 void removeNodePreservingChildren(PassRefPtrWillBeRawPtr<Node>, ShouldAssume
ContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable); |
| 122 void removeNodeAndPruneAncestors(PassRefPtr<Node>, Node* excludeNode = 0); | 126 void removeNodeAndPruneAncestors(PassRefPtrWillBeRawPtr<Node>, Node* exclude
Node = 0); |
| 123 void moveRemainingSiblingsToNewParent(Node*, Node* pastLastNodeToMove, PassR
efPtr<Element> prpNewParent); | 127 void moveRemainingSiblingsToNewParent(Node*, Node* pastLastNodeToMove, PassR
efPtrWillBeRawPtr<Element> prpNewParent); |
| 124 void updatePositionForNodeRemovalPreservingChildren(Position&, Node&); | 128 void updatePositionForNodeRemovalPreservingChildren(Position&, Node&); |
| 125 void prune(PassRefPtr<Node>, Node* excludeNode = 0); | 129 void prune(PassRefPtrWillBeRawPtr<Node>, Node* excludeNode = 0); |
| 126 void replaceTextInNode(PassRefPtrWillBeRawPtr<Text>, unsigned offset, unsign
ed count, const String& replacementText); | 130 void replaceTextInNode(PassRefPtrWillBeRawPtr<Text>, unsigned offset, unsign
ed count, const String& replacementText); |
| 127 Position replaceSelectedTextInNode(const String&); | 131 Position replaceSelectedTextInNode(const String&); |
| 128 void replaceTextInNodePreservingMarkers(PassRefPtrWillBeRawPtr<Text>, unsign
ed offset, unsigned count, const String& replacementText); | 132 void replaceTextInNodePreservingMarkers(PassRefPtrWillBeRawPtr<Text>, unsign
ed offset, unsigned count, const String& replacementText); |
| 129 Position positionOutsideTabSpan(const Position&); | 133 Position positionOutsideTabSpan(const Position&); |
| 130 void setNodeAttribute(PassRefPtr<Element>, const QualifiedName& attribute, c
onst AtomicString& value); | 134 void setNodeAttribute(PassRefPtrWillBeRawPtr<Element>, const QualifiedName&
attribute, const AtomicString& value); |
| 131 void splitElement(PassRefPtr<Element>, PassRefPtr<Node> atChild); | 135 void splitElement(PassRefPtrWillBeRawPtr<Element>, PassRefPtrWillBeRawPtr<No
de> atChild); |
| 132 void splitTextNode(PassRefPtrWillBeRawPtr<Text>, unsigned offset); | 136 void splitTextNode(PassRefPtrWillBeRawPtr<Text>, unsigned offset); |
| 133 void splitTextNodeContainingElement(PassRefPtrWillBeRawPtr<Text>, unsigned o
ffset); | 137 void splitTextNodeContainingElement(PassRefPtrWillBeRawPtr<Text>, unsigned o
ffset); |
| 134 void wrapContentsInDummySpan(PassRefPtr<Element>); | 138 void wrapContentsInDummySpan(PassRefPtrWillBeRawPtr<Element>); |
| 135 | 139 |
| 136 void deleteInsignificantText(PassRefPtrWillBeRawPtr<Text>, unsigned start, u
nsigned end); | 140 void deleteInsignificantText(PassRefPtrWillBeRawPtr<Text>, unsigned start, u
nsigned end); |
| 137 void deleteInsignificantText(const Position& start, const Position& end); | 141 void deleteInsignificantText(const Position& start, const Position& end); |
| 138 void deleteInsignificantTextDownstream(const Position&); | 142 void deleteInsignificantTextDownstream(const Position&); |
| 139 | 143 |
| 140 PassRefPtr<Node> appendBlockPlaceholder(PassRefPtr<Element>); | 144 PassRefPtrWillBeRawPtr<Node> appendBlockPlaceholder(PassRefPtrWillBeRawPtr<E
lement>); |
| 141 PassRefPtr<Node> insertBlockPlaceholder(const Position&); | 145 PassRefPtrWillBeRawPtr<Node> insertBlockPlaceholder(const Position&); |
| 142 PassRefPtr<Node> addBlockPlaceholderIfNeeded(Element*); | 146 PassRefPtrWillBeRawPtr<Node> addBlockPlaceholderIfNeeded(Element*); |
| 143 void removePlaceholderAt(const Position&); | 147 void removePlaceholderAt(const Position&); |
| 144 | 148 |
| 145 PassRefPtr<Node> insertNewDefaultParagraphElementAt(const Position&); | 149 PassRefPtrWillBeRawPtr<Node> insertNewDefaultParagraphElementAt(const Positi
on&); |
| 146 | 150 |
| 147 PassRefPtr<Node> moveParagraphContentsToNewBlockIfNecessary(const Position&)
; | 151 PassRefPtrWillBeRawPtr<Node> moveParagraphContentsToNewBlockIfNecessary(cons
t Position&); |
| 148 | 152 |
| 149 void pushAnchorElementDown(Node*); | 153 void pushAnchorElementDown(Node*); |
| 150 | 154 |
| 151 // FIXME: preserveSelection and preserveStyle should be enums | 155 // FIXME: preserveSelection and preserveStyle should be enums |
| 152 void moveParagraph(const VisiblePosition&, const VisiblePosition&, const Vis
iblePosition&, bool preserveSelection = false, bool preserveStyle = true, Node*
constrainingAncestor = 0); | 156 void moveParagraph(const VisiblePosition&, const VisiblePosition&, const Vis
iblePosition&, bool preserveSelection = false, bool preserveStyle = true, Node*
constrainingAncestor = 0); |
| 153 void moveParagraphs(const VisiblePosition&, const VisiblePosition&, const Vi
siblePosition&, bool preserveSelection = false, bool preserveStyle = true, Node*
constrainingAncestor = 0); | 157 void moveParagraphs(const VisiblePosition&, const VisiblePosition&, const Vi
siblePosition&, bool preserveSelection = false, bool preserveStyle = true, Node*
constrainingAncestor = 0); |
| 154 void moveParagraphWithClones(const VisiblePosition& startOfParagraphToMove,
const VisiblePosition& endOfParagraphToMove, Element* blockElement, Node* outerN
ode); | 158 void moveParagraphWithClones(const VisiblePosition& startOfParagraphToMove,
const VisiblePosition& endOfParagraphToMove, Element* blockElement, Node* outerN
ode); |
| 155 void cloneParagraphUnderNewElement(const Position& start, const Position& en
d, Node* outerNode, Element* blockElement); | 159 void cloneParagraphUnderNewElement(const Position& start, const Position& en
d, Node* outerNode, Element* blockElement); |
| 156 void cleanupAfterDeletion(VisiblePosition destination = VisiblePosition()); | 160 void cleanupAfterDeletion(VisiblePosition destination = VisiblePosition()); |
| 157 | 161 |
| 158 bool breakOutOfEmptyListItem(); | 162 bool breakOutOfEmptyListItem(); |
| 159 bool breakOutOfEmptyMailBlockquotedParagraph(); | 163 bool breakOutOfEmptyMailBlockquotedParagraph(); |
| 160 | 164 |
| 161 Position positionAvoidingSpecialElementBoundary(const Position&); | 165 Position positionAvoidingSpecialElementBoundary(const Position&); |
| 162 | 166 |
| 163 PassRefPtr<Node> splitTreeToNode(Node*, Node*, bool splitAncestor = false); | 167 PassRefPtrWillBeRawPtr<Node> splitTreeToNode(Node*, Node*, bool splitAncesto
r = false); |
| 164 | 168 |
| 165 Vector<RefPtr<EditCommand> > m_commands; | 169 WillBeHeapVector<RefPtrWillBeMember<EditCommand> > m_commands; |
| 166 | 170 |
| 167 private: | 171 private: |
| 168 virtual bool isCompositeEditCommand() const OVERRIDE FINAL { return true; } | 172 virtual bool isCompositeEditCommand() const OVERRIDE FINAL { return true; } |
| 169 | 173 |
| 170 RefPtr<EditCommandComposition> m_composition; | 174 RefPtrWillBeMember<EditCommandComposition> m_composition; |
| 171 }; | 175 }; |
| 172 | 176 |
| 173 DEFINE_TYPE_CASTS(CompositeEditCommand, EditCommand, command, command->isComposi
teEditCommand(), command.isCompositeEditCommand()); | 177 DEFINE_TYPE_CASTS(CompositeEditCommand, EditCommand, command, command->isComposi
teEditCommand(), command.isCompositeEditCommand()); |
| 174 | 178 |
| 175 } // namespace WebCore | 179 } // namespace WebCore |
| 176 | 180 |
| 177 #endif // CompositeEditCommand_h | 181 #endif // CompositeEditCommand_h |
| OLD | NEW |