OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007, 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 #include "core/layout/LayoutListItem.h" | 73 #include "core/layout/LayoutListItem.h" |
74 #include "core/layout/LayoutText.h" | 74 #include "core/layout/LayoutText.h" |
75 #include "core/layout/line/InlineTextBox.h" | 75 #include "core/layout/line/InlineTextBox.h" |
76 #include <algorithm> | 76 #include <algorithm> |
77 | 77 |
78 namespace blink { | 78 namespace blink { |
79 | 79 |
80 using namespace HTMLNames; | 80 using namespace HTMLNames; |
81 | 81 |
82 EditCommandComposition* EditCommandComposition::create(Document* document, | 82 EditCommandComposition* EditCommandComposition::create(Document* document, |
83 const VisibleSelection& startingSelection, const VisibleSelection& endingSel
ection, EditAction editAction) | 83 const VisibleSelection& startingSelection, const VisibleSelection& endingSel
ection, InputEvent::InputType inputType) |
84 { | 84 { |
85 return new EditCommandComposition(document, startingSelection, endingSelecti
on, editAction); | 85 return new EditCommandComposition(document, startingSelection, endingSelecti
on, inputType); |
86 } | 86 } |
87 | 87 |
88 EditCommandComposition::EditCommandComposition(Document* document, const Visible
Selection& startingSelection, const VisibleSelection& endingSelection, EditActio
n editAction) | 88 EditCommandComposition::EditCommandComposition(Document* document, const Visible
Selection& startingSelection, const VisibleSelection& endingSelection, InputEven
t::InputType inputType) |
89 : m_document(document) | 89 : m_document(document) |
90 , m_startingSelection(startingSelection) | 90 , m_startingSelection(startingSelection) |
91 , m_endingSelection(endingSelection) | 91 , m_endingSelection(endingSelection) |
92 , m_startingRootEditableElement(startingSelection.rootEditableElement()) | 92 , m_startingRootEditableElement(startingSelection.rootEditableElement()) |
93 , m_endingRootEditableElement(endingSelection.rootEditableElement()) | 93 , m_endingRootEditableElement(endingSelection.rootEditableElement()) |
94 , m_editAction(editAction) | 94 , m_inputType(inputType) |
95 { | 95 { |
96 } | 96 } |
97 | 97 |
98 bool EditCommandComposition::belongsTo(const LocalFrame& frame) const | 98 bool EditCommandComposition::belongsTo(const LocalFrame& frame) const |
99 { | 99 { |
100 DCHECK(m_document); | 100 DCHECK(m_document); |
101 return m_document->frame() == &frame; | 101 return m_document->frame() == &frame; |
102 } | 102 } |
103 | 103 |
104 void EditCommandComposition::unapply() | 104 void EditCommandComposition::unapply() |
(...skipping 28 matching lines...) Expand all Loading... |
133 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); | 133 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); |
134 | 134 |
135 { | 135 { |
136 for (const auto& command : m_commands) | 136 for (const auto& command : m_commands) |
137 command->doReapply(); | 137 command->doReapply(); |
138 } | 138 } |
139 | 139 |
140 frame->editor().reappliedEditing(this); | 140 frame->editor().reappliedEditing(this); |
141 } | 141 } |
142 | 142 |
| 143 InputEvent::InputType EditCommandComposition::inputType() const |
| 144 { |
| 145 return m_inputType; |
| 146 } |
| 147 |
143 void EditCommandComposition::append(SimpleEditCommand* command) | 148 void EditCommandComposition::append(SimpleEditCommand* command) |
144 { | 149 { |
145 m_commands.append(command); | 150 m_commands.append(command); |
146 } | 151 } |
147 | 152 |
148 void EditCommandComposition::setStartingSelection(const VisibleSelection& select
ion) | 153 void EditCommandComposition::setStartingSelection(const VisibleSelection& select
ion) |
149 { | 154 { |
150 m_startingSelection = selection; | 155 m_startingSelection = selection; |
151 m_startingRootEditableElement = selection.rootEditableElement(); | 156 m_startingRootEditableElement = selection.rootEditableElement(); |
152 } | 157 } |
(...skipping 21 matching lines...) Expand all Loading... |
174 } | 179 } |
175 | 180 |
176 CompositeEditCommand::~CompositeEditCommand() | 181 CompositeEditCommand::~CompositeEditCommand() |
177 { | 182 { |
178 DCHECK(isTopLevelCommand() || !m_composition); | 183 DCHECK(isTopLevelCommand() || !m_composition); |
179 } | 184 } |
180 | 185 |
181 bool CompositeEditCommand::apply() | 186 bool CompositeEditCommand::apply() |
182 { | 187 { |
183 if (!endingSelection().isContentRichlyEditable()) { | 188 if (!endingSelection().isContentRichlyEditable()) { |
184 switch (editingAction()) { | 189 switch (inputType()) { |
185 case EditActionTyping: | 190 case InputEvent::InputType::InsertText: |
186 case EditActionPaste: | 191 case InputEvent::InputType::InsertLineBreak: |
187 case EditActionDrag: | 192 case InputEvent::InputType::InsertParagraph: |
188 case EditActionSetWritingDirection: | 193 case InputEvent::InputType::DeleteComposedCharacterForward: |
189 case EditActionCut: | 194 case InputEvent::InputType::DeleteComposedCharacterBackward: |
190 case EditActionUnspecified: | 195 case InputEvent::InputType::DeleteWordBackward: |
| 196 case InputEvent::InputType::DeleteWordForward: |
| 197 case InputEvent::InputType::DeleteLineBackward: |
| 198 case InputEvent::InputType::DeleteLineForward: |
| 199 case InputEvent::InputType::DeleteContentBackward: |
| 200 case InputEvent::InputType::DeleteContentForward: |
| 201 case InputEvent::InputType::Paste: |
| 202 case InputEvent::InputType::Drag: |
| 203 case InputEvent::InputType::SetWritingDirection: |
| 204 case InputEvent::InputType::Cut: |
| 205 case InputEvent::InputType::None: |
191 break; | 206 break; |
192 default: | 207 default: |
193 NOTREACHED(); | 208 NOTREACHED(); |
194 return false; | 209 return false; |
195 } | 210 } |
196 } | 211 } |
197 ensureComposition(); | 212 ensureComposition(); |
198 | 213 |
199 // Changes to the document may have been made since the last editing operati
on that require a layout, as in <rdar://problem/5658603>. | 214 // Changes to the document may have been made since the last editing operati
on that require a layout, as in <rdar://problem/5658603>. |
200 // Low level operations, like RemoveNodeCommand, don't require a layout beca
use the high level operations that use them perform one | 215 // Low level operations, like RemoveNodeCommand, don't require a layout beca
use the high level operations that use them perform one |
(...skipping 15 matching lines...) Expand all Loading... |
216 setShouldRetainAutocorrectionIndicator(false); | 231 setShouldRetainAutocorrectionIndicator(false); |
217 return !editingState.isAborted(); | 232 return !editingState.isAborted(); |
218 } | 233 } |
219 | 234 |
220 EditCommandComposition* CompositeEditCommand::ensureComposition() | 235 EditCommandComposition* CompositeEditCommand::ensureComposition() |
221 { | 236 { |
222 CompositeEditCommand* command = this; | 237 CompositeEditCommand* command = this; |
223 while (command && command->parent()) | 238 while (command && command->parent()) |
224 command = command->parent(); | 239 command = command->parent(); |
225 if (!command->m_composition) | 240 if (!command->m_composition) |
226 command->m_composition = EditCommandComposition::create(&document(), sta
rtingSelection(), endingSelection(), editingAction()); | 241 command->m_composition = EditCommandComposition::create(&document(), sta
rtingSelection(), endingSelection(), inputType()); |
227 return command->m_composition.get(); | 242 return command->m_composition.get(); |
228 } | 243 } |
229 | 244 |
230 bool CompositeEditCommand::preservesTypingStyle() const | 245 bool CompositeEditCommand::preservesTypingStyle() const |
231 { | 246 { |
232 return false; | 247 return false; |
233 } | 248 } |
234 | 249 |
235 bool CompositeEditCommand::isTypingCommand() const | 250 bool CompositeEditCommand::isTypingCommand() const |
236 { | 251 { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 command->setStartingSelection(selection); | 286 command->setStartingSelection(selection); |
272 command->setEndingSelection(selection); | 287 command->setEndingSelection(selection); |
273 } | 288 } |
274 command->doApply(editingState); | 289 command->doApply(editingState); |
275 if (!editingState->isAborted()) | 290 if (!editingState->isAborted()) |
276 m_commands.append(command); | 291 m_commands.append(command); |
277 } | 292 } |
278 | 293 |
279 void CompositeEditCommand::applyStyle(const EditingStyle* style, EditingState* e
ditingState) | 294 void CompositeEditCommand::applyStyle(const EditingStyle* style, EditingState* e
ditingState) |
280 { | 295 { |
281 applyCommandToComposite(ApplyStyleCommand::create(document(), style, EditAct
ionChangeAttributes), editingState); | 296 applyCommandToComposite(ApplyStyleCommand::create(document(), style, InputEv
ent::InputType::ChangeAttributes), editingState); |
282 } | 297 } |
283 | 298 |
284 void CompositeEditCommand::applyStyle(const EditingStyle* style, const Position&
start, const Position& end, EditingState* editingState) | 299 void CompositeEditCommand::applyStyle(const EditingStyle* style, const Position&
start, const Position& end, EditingState* editingState) |
285 { | 300 { |
286 applyCommandToComposite(ApplyStyleCommand::create(document(), style, start,
end), editingState); | 301 applyCommandToComposite(ApplyStyleCommand::create(document(), style, start,
end), editingState); |
287 } | 302 } |
288 | 303 |
289 void CompositeEditCommand::applyStyledElement(Element* element, EditingState* ed
itingState) | 304 void CompositeEditCommand::applyStyledElement(Element* element, EditingState* ed
itingState) |
290 { | 305 { |
291 applyCommandToComposite(ApplyStyleCommand::create(element, false), editingSt
ate); | 306 applyCommandToComposite(ApplyStyleCommand::create(element, false), editingSt
ate); |
(...skipping 1331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1623 } | 1638 } |
1624 | 1639 |
1625 DEFINE_TRACE(CompositeEditCommand) | 1640 DEFINE_TRACE(CompositeEditCommand) |
1626 { | 1641 { |
1627 visitor->trace(m_commands); | 1642 visitor->trace(m_commands); |
1628 visitor->trace(m_composition); | 1643 visitor->trace(m_composition); |
1629 EditCommand::trace(visitor); | 1644 EditCommand::trace(visitor); |
1630 } | 1645 } |
1631 | 1646 |
1632 } // namespace blink | 1647 } // namespace blink |
OLD | NEW |