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

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/UndoStep.cpp

Issue 2639913002: Move class EditCommandComposition to UndoStep.h/cpp (Closed)
Patch Set: Created 3 years, 11 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/UndoStep.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "core/editing/commands/UndoStep.h"
6
7 #include "core/editing/Editor.h"
8 #include "core/editing/commands/EditCommand.h"
9
10 namespace blink {
11
12 EditCommandComposition* EditCommandComposition::create(
13 Document* document,
14 const VisibleSelection& startingSelection,
15 const VisibleSelection& endingSelection,
16 InputEvent::InputType inputType) {
17 return new EditCommandComposition(document, startingSelection,
18 endingSelection, inputType);
19 }
20
21 EditCommandComposition::EditCommandComposition(
22 Document* document,
23 const VisibleSelection& startingSelection,
24 const VisibleSelection& endingSelection,
25 InputEvent::InputType inputType)
26 : m_document(document),
27 m_startingSelection(startingSelection),
28 m_endingSelection(endingSelection),
29 m_startingRootEditableElement(startingSelection.rootEditableElement()),
30 m_endingRootEditableElement(endingSelection.rootEditableElement()),
31 m_inputType(inputType) {}
32
33 void EditCommandComposition::unapply() {
34 DCHECK(m_document);
35 LocalFrame* frame = m_document->frame();
36 DCHECK(frame);
37
38 // Changes to the document may have been made since the last editing operation
39 // that require a layout, as in <rdar://problem/5658603>. Low level
40 // operations, like RemoveNodeCommand, don't require a layout because the high
41 // level operations that use them perform one if one is necessary (like for
42 // the creation of VisiblePositions).
43 m_document->updateStyleAndLayoutIgnorePendingStylesheets();
44
45 {
46 size_t size = m_commands.size();
47 for (size_t i = size; i; --i)
48 m_commands[i - 1]->doUnapply();
49 }
50
51 frame->editor().unappliedEditing(this);
52 }
53
54 void EditCommandComposition::reapply() {
55 DCHECK(m_document);
56 LocalFrame* frame = m_document->frame();
57 DCHECK(frame);
58
59 // Changes to the document may have been made since the last editing operation
60 // that require a layout, as in <rdar://problem/5658603>. Low level
61 // operations, like RemoveNodeCommand, don't require a layout because the high
62 // level operations that use them perform one if one is necessary (like for
63 // the creation of VisiblePositions).
64 m_document->updateStyleAndLayoutIgnorePendingStylesheets();
65
66 {
67 for (const auto& command : m_commands)
68 command->doReapply();
69 }
70
71 frame->editor().reappliedEditing(this);
72 }
73
74 InputEvent::InputType EditCommandComposition::inputType() const {
75 return m_inputType;
76 }
77
78 void EditCommandComposition::append(SimpleEditCommand* command) {
79 m_commands.push_back(command);
80 }
81
82 void EditCommandComposition::append(EditCommandComposition* composition) {
83 m_commands.appendVector(composition->m_commands);
84 }
85
86 void EditCommandComposition::setStartingSelection(
87 const VisibleSelection& selection) {
88 m_startingSelection = selection;
89 m_startingRootEditableElement = selection.rootEditableElement();
90 }
91
92 void EditCommandComposition::setEndingSelection(
93 const VisibleSelection& selection) {
94 m_endingSelection = selection;
95 m_endingRootEditableElement = selection.rootEditableElement();
96 }
97
98 DEFINE_TRACE(EditCommandComposition) {
99 visitor->trace(m_document);
100 visitor->trace(m_startingSelection);
101 visitor->trace(m_endingSelection);
102 visitor->trace(m_commands);
103 visitor->trace(m_startingRootEditableElement);
104 visitor->trace(m_endingRootEditableElement);
105 UndoStep::trace(visitor);
106 }
107
108 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/commands/UndoStep.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698