| 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 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 class EditingStyle; | 37 class EditingStyle; |
| 38 class Element; | 38 class Element; |
| 39 class HTMLBRElement; | 39 class HTMLBRElement; |
| 40 class HTMLElement; | 40 class HTMLElement; |
| 41 class HTMLSpanElement; | 41 class HTMLSpanElement; |
| 42 class Text; | 42 class Text; |
| 43 | 43 |
| 44 class EditCommandComposition final : public UndoStep { | 44 class EditCommandComposition final : public UndoStep { |
| 45 public: | 45 public: |
| 46 static PassRefPtrWillBeRawPtr<EditCommandComposition> create(Document*, cons
t VisibleSelection&, const VisibleSelection&, EditAction); | 46 static RawPtr<EditCommandComposition> create(Document*, const VisibleSelecti
on&, const VisibleSelection&, EditAction); |
| 47 | 47 |
| 48 bool belongsTo(const LocalFrame&) const override; | 48 bool belongsTo(const LocalFrame&) const override; |
| 49 void unapply() override; | 49 void unapply() override; |
| 50 void reapply() override; | 50 void reapply() override; |
| 51 EditAction editingAction() const override { return m_editAction; } | 51 EditAction editingAction() const override { return m_editAction; } |
| 52 void append(SimpleEditCommand*); | 52 void append(SimpleEditCommand*); |
| 53 | 53 |
| 54 const VisibleSelection& startingSelection() const { return m_startingSelecti
on; } | 54 const VisibleSelection& startingSelection() const { return m_startingSelecti
on; } |
| 55 const VisibleSelection& endingSelection() const { return m_endingSelection;
} | 55 const VisibleSelection& endingSelection() const { return m_endingSelection;
} |
| 56 void setStartingSelection(const VisibleSelection&); | 56 void setStartingSelection(const VisibleSelection&); |
| 57 void setEndingSelection(const VisibleSelection&); | 57 void setEndingSelection(const VisibleSelection&); |
| 58 Element* startingRootEditableElement() const { return m_startingRootEditable
Element.get(); } | 58 Element* startingRootEditableElement() const { return m_startingRootEditable
Element.get(); } |
| 59 Element* endingRootEditableElement() const { return m_endingRootEditableElem
ent.get(); } | 59 Element* endingRootEditableElement() const { return m_endingRootEditableElem
ent.get(); } |
| 60 | 60 |
| 61 DECLARE_VIRTUAL_TRACE(); | 61 DECLARE_VIRTUAL_TRACE(); |
| 62 | 62 |
| 63 private: | 63 private: |
| 64 EditCommandComposition(Document*, const VisibleSelection& startingSelection,
const VisibleSelection& endingSelection, EditAction); | 64 EditCommandComposition(Document*, const VisibleSelection& startingSelection,
const VisibleSelection& endingSelection, EditAction); |
| 65 | 65 |
| 66 RefPtrWillBeMember<Document> m_document; | 66 Member<Document> m_document; |
| 67 VisibleSelection m_startingSelection; | 67 VisibleSelection m_startingSelection; |
| 68 VisibleSelection m_endingSelection; | 68 VisibleSelection m_endingSelection; |
| 69 WillBeHeapVector<RefPtrWillBeMember<SimpleEditCommand>> m_commands; | 69 HeapVector<Member<SimpleEditCommand>> m_commands; |
| 70 RefPtrWillBeMember<Element> m_startingRootEditableElement; | 70 Member<Element> m_startingRootEditableElement; |
| 71 RefPtrWillBeMember<Element> m_endingRootEditableElement; | 71 Member<Element> m_endingRootEditableElement; |
| 72 EditAction m_editAction; | 72 EditAction m_editAction; |
| 73 }; | 73 }; |
| 74 | 74 |
| 75 class CompositeEditCommand : public EditCommand { | 75 class CompositeEditCommand : public EditCommand { |
| 76 public: | 76 public: |
| 77 ~CompositeEditCommand() override; | 77 ~CompositeEditCommand() override; |
| 78 | 78 |
| 79 // Returns |false| if the command failed. e.g. It's aborted. | 79 // Returns |false| if the command failed. e.g. It's aborted. |
| 80 bool apply(); | 80 bool apply(); |
| 81 bool isFirstCommand(EditCommand* command) { return !m_commands.isEmpty() &&
m_commands.first() == command; } | 81 bool isFirstCommand(EditCommand* command) { return !m_commands.isEmpty() &&
m_commands.first() == command; } |
| 82 EditCommandComposition* composition() { return m_composition.get(); } | 82 EditCommandComposition* composition() { return m_composition.get(); } |
| 83 EditCommandComposition* ensureComposition(); | 83 EditCommandComposition* ensureComposition(); |
| 84 | 84 |
| 85 virtual bool isReplaceSelectionCommand() const; | 85 virtual bool isReplaceSelectionCommand() const; |
| 86 virtual bool isTypingCommand() const; | 86 virtual bool isTypingCommand() const; |
| 87 virtual bool preservesTypingStyle() const; | 87 virtual bool preservesTypingStyle() const; |
| 88 virtual void setShouldRetainAutocorrectionIndicator(bool); | 88 virtual void setShouldRetainAutocorrectionIndicator(bool); |
| 89 virtual bool shouldStopCaretBlinking() const { return false; } | 89 virtual bool shouldStopCaretBlinking() const { return false; } |
| 90 | 90 |
| 91 DECLARE_VIRTUAL_TRACE(); | 91 DECLARE_VIRTUAL_TRACE(); |
| 92 | 92 |
| 93 protected: | 93 protected: |
| 94 explicit CompositeEditCommand(Document&); | 94 explicit CompositeEditCommand(Document&); |
| 95 | 95 |
| 96 // | 96 // |
| 97 // sugary-sweet convenience functions to help create and apply edit commands
in composite commands | 97 // sugary-sweet convenience functions to help create and apply edit commands
in composite commands |
| 98 // | 98 // |
| 99 void appendNode(PassRefPtrWillBeRawPtr<Node>, PassRefPtrWillBeRawPtr<Contain
erNode> parent, EditingState*); | 99 void appendNode(RawPtr<Node>, RawPtr<ContainerNode> parent, EditingState*); |
| 100 void applyCommandToComposite(PassRefPtrWillBeRawPtr<EditCommand>, EditingSta
te*); | 100 void applyCommandToComposite(RawPtr<EditCommand>, EditingState*); |
| 101 void applyCommandToComposite(PassRefPtrWillBeRawPtr<CompositeEditCommand>, c
onst VisibleSelection&, EditingState*); | 101 void applyCommandToComposite(RawPtr<CompositeEditCommand>, const VisibleSele
ction&, EditingState*); |
| 102 void applyStyle(const EditingStyle*, EditingState*); | 102 void applyStyle(const EditingStyle*, EditingState*); |
| 103 void applyStyle(const EditingStyle*, const Position& start, const Position&
end, EditingState*); | 103 void applyStyle(const EditingStyle*, const Position& start, const Position&
end, EditingState*); |
| 104 void applyStyledElement(PassRefPtrWillBeRawPtr<Element>, EditingState*); | 104 void applyStyledElement(RawPtr<Element>, EditingState*); |
| 105 void removeStyledElement(PassRefPtrWillBeRawPtr<Element>, EditingState*); | 105 void removeStyledElement(RawPtr<Element>, EditingState*); |
| 106 void deleteSelection(EditingState*, bool smartDelete = false, bool mergeBloc
ksAfterDelete = true, bool expandForSpecialElements = true, bool sanitizeMarkup
= true); | 106 void deleteSelection(EditingState*, bool smartDelete = false, bool mergeBloc
ksAfterDelete = true, bool expandForSpecialElements = true, bool sanitizeMarkup
= true); |
| 107 void deleteSelection(const VisibleSelection&, EditingState*, bool smartDelet
e = false, bool mergeBlocksAfterDelete = true, bool expandForSpecialElements = t
rue, bool sanitizeMarkup = true); | 107 void deleteSelection(const VisibleSelection&, EditingState*, bool smartDelet
e = false, bool mergeBlocksAfterDelete = true, bool expandForSpecialElements = t
rue, bool sanitizeMarkup = true); |
| 108 virtual void deleteTextFromNode(PassRefPtrWillBeRawPtr<Text>, unsigned offse
t, unsigned count); | 108 virtual void deleteTextFromNode(RawPtr<Text>, unsigned offset, unsigned coun
t); |
| 109 bool isRemovableBlock(const Node*); | 109 bool isRemovableBlock(const Node*); |
| 110 void insertNodeAfter(PassRefPtrWillBeRawPtr<Node>, PassRefPtrWillBeRawPtr<No
de> refChild, EditingState*); | 110 void insertNodeAfter(RawPtr<Node>, RawPtr<Node> refChild, EditingState*); |
| 111 void insertNodeAt(PassRefPtrWillBeRawPtr<Node>, const Position&, EditingStat
e*); | 111 void insertNodeAt(RawPtr<Node>, const Position&, EditingState*); |
| 112 void insertNodeAtTabSpanPosition(PassRefPtrWillBeRawPtr<Node>, const Positio
n&, EditingState*); | 112 void insertNodeAtTabSpanPosition(RawPtr<Node>, const Position&, EditingState
*); |
| 113 void insertNodeBefore(PassRefPtrWillBeRawPtr<Node>, PassRefPtrWillBeRawPtr<N
ode> refChild, EditingState*, ShouldAssumeContentIsAlwaysEditable = DoNotAssumeC
ontentIsAlwaysEditable); | 113 void insertNodeBefore(RawPtr<Node>, RawPtr<Node> refChild, EditingState*, Sh
ouldAssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable); |
| 114 void insertParagraphSeparator(EditingState*, bool useDefaultParagraphElement
= false, bool pasteBlockqutoeIntoUnquotedArea = false); | 114 void insertParagraphSeparator(EditingState*, bool useDefaultParagraphElement
= false, bool pasteBlockqutoeIntoUnquotedArea = false); |
| 115 void insertTextIntoNode(PassRefPtrWillBeRawPtr<Text>, unsigned offset, const
String& text); | 115 void insertTextIntoNode(RawPtr<Text>, unsigned offset, const String& text); |
| 116 void mergeIdenticalElements(PassRefPtrWillBeRawPtr<Element>, PassRefPtrWillB
eRawPtr<Element>, EditingState*); | 116 void mergeIdenticalElements(RawPtr<Element>, RawPtr<Element>, EditingState*)
; |
| 117 void rebalanceWhitespace(); | 117 void rebalanceWhitespace(); |
| 118 void rebalanceWhitespaceAt(const Position&); | 118 void rebalanceWhitespaceAt(const Position&); |
| 119 void rebalanceWhitespaceOnTextSubstring(PassRefPtrWillBeRawPtr<Text>, int st
artOffset, int endOffset); | 119 void rebalanceWhitespaceOnTextSubstring(RawPtr<Text>, int startOffset, int e
ndOffset); |
| 120 void prepareWhitespaceAtPositionForSplit(Position&); | 120 void prepareWhitespaceAtPositionForSplit(Position&); |
| 121 void replaceCollapsibleWhitespaceWithNonBreakingSpaceIfNeeded(const VisibleP
osition&); | 121 void replaceCollapsibleWhitespaceWithNonBreakingSpaceIfNeeded(const VisibleP
osition&); |
| 122 bool canRebalance(const Position&) const; | 122 bool canRebalance(const Position&) const; |
| 123 bool shouldRebalanceLeadingWhitespaceFor(const String&) const; | 123 bool shouldRebalanceLeadingWhitespaceFor(const String&) const; |
| 124 void removeCSSProperty(PassRefPtrWillBeRawPtr<Element>, CSSPropertyID); | 124 void removeCSSProperty(RawPtr<Element>, CSSPropertyID); |
| 125 void removeElementAttribute(PassRefPtrWillBeRawPtr<Element>, const Qualified
Name& attribute); | 125 void removeElementAttribute(RawPtr<Element>, const QualifiedName& attribute)
; |
| 126 void removeChildrenInRange(PassRefPtrWillBeRawPtr<Node>, unsigned from, unsi
gned to, EditingState*); | 126 void removeChildrenInRange(RawPtr<Node>, unsigned from, unsigned to, Editing
State*); |
| 127 virtual void removeNode(PassRefPtrWillBeRawPtr<Node>, EditingState*, ShouldA
ssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable); | 127 virtual void removeNode(RawPtr<Node>, EditingState*, ShouldAssumeContentIsAl
waysEditable = DoNotAssumeContentIsAlwaysEditable); |
| 128 HTMLSpanElement* replaceElementWithSpanPreservingChildrenAndAttributes(PassR
efPtrWillBeRawPtr<HTMLElement>); | 128 HTMLSpanElement* replaceElementWithSpanPreservingChildrenAndAttributes(RawPt
r<HTMLElement>); |
| 129 void removeNodePreservingChildren(PassRefPtrWillBeRawPtr<Node>, EditingState
*, ShouldAssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable); | 129 void removeNodePreservingChildren(RawPtr<Node>, EditingState*, ShouldAssumeC
ontentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable); |
| 130 void removeNodeAndPruneAncestors(PassRefPtrWillBeRawPtr<Node>, EditingState*
, Node* excludeNode = nullptr); | 130 void removeNodeAndPruneAncestors(RawPtr<Node>, EditingState*, Node* excludeN
ode = nullptr); |
| 131 void moveRemainingSiblingsToNewParent(Node*, Node* pastLastNodeToMove, PassR
efPtrWillBeRawPtr<Element> prpNewParent, EditingState*); | 131 void moveRemainingSiblingsToNewParent(Node*, Node* pastLastNodeToMove, RawPt
r<Element> prpNewParent, EditingState*); |
| 132 void updatePositionForNodeRemovalPreservingChildren(Position&, Node&); | 132 void updatePositionForNodeRemovalPreservingChildren(Position&, Node&); |
| 133 void prune(PassRefPtrWillBeRawPtr<Node>, EditingState*, Node* excludeNode =
nullptr); | 133 void prune(RawPtr<Node>, EditingState*, Node* excludeNode = nullptr); |
| 134 void replaceTextInNode(PassRefPtrWillBeRawPtr<Text>, unsigned offset, unsign
ed count, const String& replacementText); | 134 void replaceTextInNode(RawPtr<Text>, unsigned offset, unsigned count, const
String& replacementText); |
| 135 Position replaceSelectedTextInNode(const String&); | 135 Position replaceSelectedTextInNode(const String&); |
| 136 void replaceTextInNodePreservingMarkers(PassRefPtrWillBeRawPtr<Text>, unsign
ed offset, unsigned count, const String& replacementText); | 136 void replaceTextInNodePreservingMarkers(RawPtr<Text>, unsigned offset, unsig
ned count, const String& replacementText); |
| 137 Position positionOutsideTabSpan(const Position&); | 137 Position positionOutsideTabSpan(const Position&); |
| 138 void setNodeAttribute(PassRefPtrWillBeRawPtr<Element>, const QualifiedName&
attribute, const AtomicString& value); | 138 void setNodeAttribute(RawPtr<Element>, const QualifiedName& attribute, const
AtomicString& value); |
| 139 void splitElement(PassRefPtrWillBeRawPtr<Element>, PassRefPtrWillBeRawPtr<No
de> atChild); | 139 void splitElement(RawPtr<Element>, RawPtr<Node> atChild); |
| 140 void splitTextNode(PassRefPtrWillBeRawPtr<Text>, unsigned offset); | 140 void splitTextNode(RawPtr<Text>, unsigned offset); |
| 141 void splitTextNodeContainingElement(PassRefPtrWillBeRawPtr<Text>, unsigned o
ffset); | 141 void splitTextNodeContainingElement(RawPtr<Text>, unsigned offset); |
| 142 void wrapContentsInDummySpan(PassRefPtrWillBeRawPtr<Element>); | 142 void wrapContentsInDummySpan(RawPtr<Element>); |
| 143 | 143 |
| 144 void deleteInsignificantText(PassRefPtrWillBeRawPtr<Text>, unsigned start, u
nsigned end); | 144 void deleteInsignificantText(RawPtr<Text>, unsigned start, unsigned end); |
| 145 void deleteInsignificantText(const Position& start, const Position& end); | 145 void deleteInsignificantText(const Position& start, const Position& end); |
| 146 void deleteInsignificantTextDownstream(const Position&); | 146 void deleteInsignificantTextDownstream(const Position&); |
| 147 | 147 |
| 148 PassRefPtrWillBeRawPtr<HTMLBRElement> appendBlockPlaceholder(PassRefPtrWillB
eRawPtr<Element>, EditingState*); | 148 RawPtr<HTMLBRElement> appendBlockPlaceholder(RawPtr<Element>, EditingState*)
; |
| 149 PassRefPtrWillBeRawPtr<HTMLBRElement> insertBlockPlaceholder(const Position&
, EditingState*); | 149 RawPtr<HTMLBRElement> insertBlockPlaceholder(const Position&, EditingState*)
; |
| 150 PassRefPtrWillBeRawPtr<HTMLBRElement> addBlockPlaceholderIfNeeded(Element*,
EditingState*); | 150 RawPtr<HTMLBRElement> addBlockPlaceholderIfNeeded(Element*, EditingState*); |
| 151 void removePlaceholderAt(const Position&); | 151 void removePlaceholderAt(const Position&); |
| 152 | 152 |
| 153 PassRefPtrWillBeRawPtr<HTMLElement> insertNewDefaultParagraphElementAt(const
Position&, EditingState*); | 153 RawPtr<HTMLElement> insertNewDefaultParagraphElementAt(const Position&, Edit
ingState*); |
| 154 | 154 |
| 155 PassRefPtrWillBeRawPtr<HTMLElement> moveParagraphContentsToNewBlockIfNecessa
ry(const Position&, EditingState*); | 155 RawPtr<HTMLElement> moveParagraphContentsToNewBlockIfNecessary(const Positio
n&, EditingState*); |
| 156 | 156 |
| 157 void pushAnchorElementDown(Element*, EditingState*); | 157 void pushAnchorElementDown(Element*, EditingState*); |
| 158 | 158 |
| 159 // FIXME: preserveSelection and preserveStyle should be enums | 159 // FIXME: preserveSelection and preserveStyle should be enums |
| 160 void moveParagraph(const VisiblePosition&, const VisiblePosition&, const Vis
iblePosition&, EditingState*, bool preserveSelection = false, bool preserveStyle
= true, Node* constrainingAncestor = nullptr); | 160 void moveParagraph(const VisiblePosition&, const VisiblePosition&, const Vis
iblePosition&, EditingState*, bool preserveSelection = false, bool preserveStyle
= true, Node* constrainingAncestor = nullptr); |
| 161 void moveParagraphs(const VisiblePosition&, const VisiblePosition&, const Vi
siblePosition&, EditingState*, bool preserveSelection = false, bool preserveStyl
e = true, Node* constrainingAncestor = nullptr); | 161 void moveParagraphs(const VisiblePosition&, const VisiblePosition&, const Vi
siblePosition&, EditingState*, bool preserveSelection = false, bool preserveStyl
e = true, Node* constrainingAncestor = nullptr); |
| 162 void moveParagraphWithClones(const VisiblePosition& startOfParagraphToMove,
const VisiblePosition& endOfParagraphToMove, HTMLElement* blockElement, Node* ou
terNode, EditingState*); | 162 void moveParagraphWithClones(const VisiblePosition& startOfParagraphToMove,
const VisiblePosition& endOfParagraphToMove, HTMLElement* blockElement, Node* ou
terNode, EditingState*); |
| 163 void cloneParagraphUnderNewElement(const Position& start, const Position& en
d, Node* outerNode, Element* blockElement, EditingState*); | 163 void cloneParagraphUnderNewElement(const Position& start, const Position& en
d, Node* outerNode, Element* blockElement, EditingState*); |
| 164 void cleanupAfterDeletion(EditingState*, VisiblePosition destination = Visib
lePosition()); | 164 void cleanupAfterDeletion(EditingState*, VisiblePosition destination = Visib
lePosition()); |
| 165 | 165 |
| 166 bool breakOutOfEmptyListItem(EditingState*); | 166 bool breakOutOfEmptyListItem(EditingState*); |
| 167 bool breakOutOfEmptyMailBlockquotedParagraph(EditingState*); | 167 bool breakOutOfEmptyMailBlockquotedParagraph(EditingState*); |
| 168 | 168 |
| 169 Position positionAvoidingSpecialElementBoundary(const Position&, EditingStat
e*); | 169 Position positionAvoidingSpecialElementBoundary(const Position&, EditingStat
e*); |
| 170 | 170 |
| 171 PassRefPtrWillBeRawPtr<Node> splitTreeToNode(Node*, Node*, bool splitAncesto
r = false); | 171 RawPtr<Node> splitTreeToNode(Node*, Node*, bool splitAncestor = false); |
| 172 | 172 |
| 173 WillBeHeapVector<RefPtrWillBeMember<EditCommand>> m_commands; | 173 HeapVector<Member<EditCommand>> m_commands; |
| 174 | 174 |
| 175 private: | 175 private: |
| 176 bool isCompositeEditCommand() const final { return true; } | 176 bool isCompositeEditCommand() const final { return true; } |
| 177 | 177 |
| 178 RefPtrWillBeMember<EditCommandComposition> m_composition; | 178 Member<EditCommandComposition> m_composition; |
| 179 }; | 179 }; |
| 180 | 180 |
| 181 DEFINE_TYPE_CASTS(CompositeEditCommand, EditCommand, command, command->isComposi
teEditCommand(), command.isCompositeEditCommand()); | 181 DEFINE_TYPE_CASTS(CompositeEditCommand, EditCommand, command, command->isComposi
teEditCommand(), command.isCompositeEditCommand()); |
| 182 | 182 |
| 183 } // namespace blink | 183 } // namespace blink |
| 184 | 184 |
| 185 #endif // CompositeEditCommand_h | 185 #endif // CompositeEditCommand_h |
| OLD | NEW |