Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: Source/core/editing/CompositeEditCommand.h

Issue 1294543005: Move execCommand related files in core/editing/ related files into core/editing/commands/ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-18T14:20:58 Rebase for merging code style fixes Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 "core/CSSPropertyNames.h"
30 #include "core/editing/EditCommand.h"
31 #include "core/editing/UndoStep.h"
32 #include "wtf/Vector.h"
33
34 namespace blink {
35
36 class EditingStyle;
37 class Element;
38 class HTMLBRElement;
39 class HTMLElement;
40 class HTMLSpanElement;
41 class Text;
42
43 class EditCommandComposition final : public UndoStep {
44 public:
45 static PassRefPtrWillBeRawPtr<EditCommandComposition> create(Document*, cons t VisibleSelection&, const VisibleSelection&, EditAction);
46
47 bool belongsTo(const LocalFrame&) const override;
48 void unapply() override;
49 void reapply() override;
50 EditAction editingAction() const override { return m_editAction; }
51 void append(SimpleEditCommand*);
52
53 const VisibleSelection& startingSelection() const { return m_startingSelecti on; }
54 const VisibleSelection& endingSelection() const { return m_endingSelection; }
55 void setStartingSelection(const VisibleSelection&);
56 void setEndingSelection(const VisibleSelection&);
57 Element* startingRootEditableElement() const { return m_startingRootEditable Element.get(); }
58 Element* endingRootEditableElement() const { return m_endingRootEditableElem ent.get(); }
59
60 DECLARE_VIRTUAL_TRACE();
61
62 private:
63 EditCommandComposition(Document*, const VisibleSelection& startingSelection, const VisibleSelection& endingSelection, EditAction);
64
65 RefPtrWillBeMember<Document> m_document;
66 VisibleSelection m_startingSelection;
67 VisibleSelection m_endingSelection;
68 WillBeHeapVector<RefPtrWillBeMember<SimpleEditCommand>> m_commands;
69 RefPtrWillBeMember<Element> m_startingRootEditableElement;
70 RefPtrWillBeMember<Element> m_endingRootEditableElement;
71 EditAction m_editAction;
72 };
73
74 class CompositeEditCommand : public EditCommand {
75 public:
76 ~CompositeEditCommand() override;
77
78 void apply();
79 bool isFirstCommand(EditCommand* command) { return !m_commands.isEmpty() && m_commands.first() == command; }
80 EditCommandComposition* composition() { return m_composition.get(); }
81 EditCommandComposition* ensureComposition();
82
83 virtual bool isTypingCommand() const;
84 virtual bool preservesTypingStyle() const;
85 virtual void setShouldRetainAutocorrectionIndicator(bool);
86 virtual bool shouldStopCaretBlinking() const { return false; }
87
88 DECLARE_VIRTUAL_TRACE();
89
90 protected:
91 explicit CompositeEditCommand(Document&);
92
93 //
94 // sugary-sweet convenience functions to help create and apply edit commands in composite commands
95 //
96 void appendNode(PassRefPtrWillBeRawPtr<Node>, PassRefPtrWillBeRawPtr<Contain erNode> parent);
97 void applyCommandToComposite(PassRefPtrWillBeRawPtr<EditCommand>);
98 void applyCommandToComposite(PassRefPtrWillBeRawPtr<CompositeEditCommand>, c onst VisibleSelection&);
99 void applyStyle(const EditingStyle*, EditAction = EditActionChangeAttributes );
100 void applyStyle(const EditingStyle*, const Position& start, const Position& end, EditAction = EditActionChangeAttributes);
101 void applyStyledElement(PassRefPtrWillBeRawPtr<Element>);
102 void removeStyledElement(PassRefPtrWillBeRawPtr<Element>);
103 void deleteSelection(bool smartDelete = false, bool mergeBlocksAfterDelete = true, bool expandForSpecialElements = true, bool sanitizeMarkup = true);
104 void deleteSelection(const VisibleSelection&, bool smartDelete = false, bool mergeBlocksAfterDelete = true, bool expandForSpecialElements = true, bool sanit izeMarkup = true);
105 virtual void deleteTextFromNode(PassRefPtrWillBeRawPtr<Text>, unsigned offse t, unsigned count);
106 bool isRemovableBlock(const Node*);
107 void insertNodeAfter(PassRefPtrWillBeRawPtr<Node>, PassRefPtrWillBeRawPtr<No de> refChild);
108 void insertNodeAt(PassRefPtrWillBeRawPtr<Node>, const Position&);
109 void insertNodeAtTabSpanPosition(PassRefPtrWillBeRawPtr<Node>, const Positio n&);
110 void insertNodeBefore(PassRefPtrWillBeRawPtr<Node>, PassRefPtrWillBeRawPtr<N ode> refChild, ShouldAssumeContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysE ditable);
111 void insertParagraphSeparator(bool useDefaultParagraphElement = false, bool pasteBlockqutoeIntoUnquotedArea = false);
112 void insertTextIntoNode(PassRefPtrWillBeRawPtr<Text>, unsigned offset, const String& text);
113 void mergeIdenticalElements(PassRefPtrWillBeRawPtr<Element>, PassRefPtrWillB eRawPtr<Element>);
114 void rebalanceWhitespace();
115 void rebalanceWhitespaceAt(const Position&);
116 void rebalanceWhitespaceOnTextSubstring(PassRefPtrWillBeRawPtr<Text>, int st artOffset, int endOffset);
117 void prepareWhitespaceAtPositionForSplit(Position&);
118 void replaceCollapsibleWhitespaceWithNonBreakingSpaceIfNeeded(const VisibleP osition&);
119 bool canRebalance(const Position&) const;
120 bool shouldRebalanceLeadingWhitespaceFor(const String&) const;
121 void removeCSSProperty(PassRefPtrWillBeRawPtr<Element>, CSSPropertyID);
122 void removeElementAttribute(PassRefPtrWillBeRawPtr<Element>, const Qualified Name& attribute);
123 void removeChildrenInRange(PassRefPtrWillBeRawPtr<Node>, unsigned from, unsi gned to);
124 virtual void removeNode(PassRefPtrWillBeRawPtr<Node>, ShouldAssumeContentIsA lwaysEditable = DoNotAssumeContentIsAlwaysEditable);
125 HTMLSpanElement* replaceElementWithSpanPreservingChildrenAndAttributes(PassR efPtrWillBeRawPtr<HTMLElement>);
126 void removeNodePreservingChildren(PassRefPtrWillBeRawPtr<Node>, ShouldAssume ContentIsAlwaysEditable = DoNotAssumeContentIsAlwaysEditable);
127 void removeNodeAndPruneAncestors(PassRefPtrWillBeRawPtr<Node>, Node* exclude Node = nullptr);
128 void moveRemainingSiblingsToNewParent(Node*, Node* pastLastNodeToMove, PassR efPtrWillBeRawPtr<Element> prpNewParent);
129 void updatePositionForNodeRemovalPreservingChildren(Position&, Node&);
130 void prune(PassRefPtrWillBeRawPtr<Node>, Node* excludeNode = nullptr);
131 void replaceTextInNode(PassRefPtrWillBeRawPtr<Text>, unsigned offset, unsign ed count, const String& replacementText);
132 Position replaceSelectedTextInNode(const String&);
133 void replaceTextInNodePreservingMarkers(PassRefPtrWillBeRawPtr<Text>, unsign ed offset, unsigned count, const String& replacementText);
134 Position positionOutsideTabSpan(const Position&);
135 void setNodeAttribute(PassRefPtrWillBeRawPtr<Element>, const QualifiedName& attribute, const AtomicString& value);
136 void splitElement(PassRefPtrWillBeRawPtr<Element>, PassRefPtrWillBeRawPtr<No de> atChild);
137 void splitTextNode(PassRefPtrWillBeRawPtr<Text>, unsigned offset);
138 void splitTextNodeContainingElement(PassRefPtrWillBeRawPtr<Text>, unsigned o ffset);
139 void wrapContentsInDummySpan(PassRefPtrWillBeRawPtr<Element>);
140
141 void deleteInsignificantText(PassRefPtrWillBeRawPtr<Text>, unsigned start, u nsigned end);
142 void deleteInsignificantText(const Position& start, const Position& end);
143 void deleteInsignificantTextDownstream(const Position&);
144
145 PassRefPtrWillBeRawPtr<HTMLBRElement> appendBlockPlaceholder(PassRefPtrWillB eRawPtr<Element>);
146 PassRefPtrWillBeRawPtr<HTMLBRElement> insertBlockPlaceholder(const Position& );
147 PassRefPtrWillBeRawPtr<HTMLBRElement> addBlockPlaceholderIfNeeded(Element*);
148 void removePlaceholderAt(const Position&);
149
150 PassRefPtrWillBeRawPtr<HTMLElement> insertNewDefaultParagraphElementAt(const Position&);
151
152 PassRefPtrWillBeRawPtr<HTMLElement> moveParagraphContentsToNewBlockIfNecessa ry(const Position&);
153
154 void pushAnchorElementDown(Element*);
155
156 // FIXME: preserveSelection and preserveStyle should be enums
157 void moveParagraph(const VisiblePosition&, const VisiblePosition&, const Vis iblePosition&, bool preserveSelection = false, bool preserveStyle = true, Node* constrainingAncestor = nullptr);
158 void moveParagraphs(const VisiblePosition&, const VisiblePosition&, const Vi siblePosition&, bool preserveSelection = false, bool preserveStyle = true, Node* constrainingAncestor = nullptr);
159 void moveParagraphWithClones(const VisiblePosition& startOfParagraphToMove, const VisiblePosition& endOfParagraphToMove, HTMLElement* blockElement, Node* ou terNode);
160 void cloneParagraphUnderNewElement(const Position& start, const Position& en d, Node* outerNode, Element* blockElement);
161 void cleanupAfterDeletion(VisiblePosition destination = VisiblePosition());
162
163 bool breakOutOfEmptyListItem();
164 bool breakOutOfEmptyMailBlockquotedParagraph();
165
166 Position positionAvoidingSpecialElementBoundary(const Position&);
167
168 PassRefPtrWillBeRawPtr<Node> splitTreeToNode(Node*, Node*, bool splitAncesto r = false);
169
170 WillBeHeapVector<RefPtrWillBeMember<EditCommand>> m_commands;
171
172 private:
173 bool isCompositeEditCommand() const final { return true; }
174
175 RefPtrWillBeMember<EditCommandComposition> m_composition;
176 };
177
178 DEFINE_TYPE_CASTS(CompositeEditCommand, EditCommand, command, command->isComposi teEditCommand(), command.isCompositeEditCommand());
179
180 } // namespace blink
181
182 #endif // CompositeEditCommand_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698