| 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 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 CompositeEditCommand::CompositeEditCommand(Document& document) | 82 CompositeEditCommand::CompositeEditCommand(Document& document) |
| 83 : EditCommand(document) {} | 83 : EditCommand(document) {} |
| 84 | 84 |
| 85 CompositeEditCommand::~CompositeEditCommand() { | 85 CompositeEditCommand::~CompositeEditCommand() { |
| 86 DCHECK(isTopLevelCommand() || !m_composition); | 86 DCHECK(isTopLevelCommand() || !m_undoStep); |
| 87 } | 87 } |
| 88 | 88 |
| 89 bool CompositeEditCommand::apply() { | 89 bool CompositeEditCommand::apply() { |
| 90 DCHECK(!isCommandGroupWrapper()); | 90 DCHECK(!isCommandGroupWrapper()); |
| 91 if (!endingSelection().isContentRichlyEditable()) { | 91 if (!endingSelection().isContentRichlyEditable()) { |
| 92 switch (inputType()) { | 92 switch (inputType()) { |
| 93 case InputEvent::InputType::InsertText: | 93 case InputEvent::InputType::InsertText: |
| 94 case InputEvent::InputType::InsertLineBreak: | 94 case InputEvent::InputType::InsertLineBreak: |
| 95 case InputEvent::InputType::InsertParagraph: | 95 case InputEvent::InputType::InsertParagraph: |
| 96 case InputEvent::InputType::InsertFromPaste: | 96 case InputEvent::InputType::InsertFromPaste: |
| 97 case InputEvent::InputType::InsertFromDrop: | 97 case InputEvent::InputType::InsertFromDrop: |
| 98 case InputEvent::InputType::InsertReplacementText: | 98 case InputEvent::InputType::InsertReplacementText: |
| 99 case InputEvent::InputType::DeleteComposedCharacterForward: | 99 case InputEvent::InputType::DeleteComposedCharacterForward: |
| 100 case InputEvent::InputType::DeleteComposedCharacterBackward: | 100 case InputEvent::InputType::DeleteComposedCharacterBackward: |
| 101 case InputEvent::InputType::DeleteWordBackward: | 101 case InputEvent::InputType::DeleteWordBackward: |
| 102 case InputEvent::InputType::DeleteWordForward: | 102 case InputEvent::InputType::DeleteWordForward: |
| 103 case InputEvent::InputType::DeleteLineBackward: | 103 case InputEvent::InputType::DeleteLineBackward: |
| 104 case InputEvent::InputType::DeleteLineForward: | 104 case InputEvent::InputType::DeleteLineForward: |
| 105 case InputEvent::InputType::DeleteContentBackward: | 105 case InputEvent::InputType::DeleteContentBackward: |
| 106 case InputEvent::InputType::DeleteContentForward: | 106 case InputEvent::InputType::DeleteContentForward: |
| 107 case InputEvent::InputType::DeleteByCut: | 107 case InputEvent::InputType::DeleteByCut: |
| 108 case InputEvent::InputType::DeleteByDrag: | 108 case InputEvent::InputType::DeleteByDrag: |
| 109 case InputEvent::InputType::None: | 109 case InputEvent::InputType::None: |
| 110 break; | 110 break; |
| 111 default: | 111 default: |
| 112 NOTREACHED(); | 112 NOTREACHED(); |
| 113 return false; | 113 return false; |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 ensureComposition(); | 116 ensureUndoStep(); |
| 117 | 117 |
| 118 // Changes to the document may have been made since the last editing operation | 118 // Changes to the document may have been made since the last editing operation |
| 119 // that require a layout, as in <rdar://problem/5658603>. Low level | 119 // that require a layout, as in <rdar://problem/5658603>. Low level |
| 120 // operations, like RemoveNodeCommand, don't require a layout because the high | 120 // operations, like RemoveNodeCommand, don't require a layout because the high |
| 121 // level operations that use them perform one if one is necessary (like for | 121 // level operations that use them perform one if one is necessary (like for |
| 122 // the creation of VisiblePositions). | 122 // the creation of VisiblePositions). |
| 123 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 123 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 124 | 124 |
| 125 LocalFrame* frame = document().frame(); | 125 LocalFrame* frame = document().frame(); |
| 126 DCHECK(frame); | 126 DCHECK(frame); |
| 127 EditingState editingState; | 127 EditingState editingState; |
| 128 { | 128 { |
| 129 EventQueueScope eventQueueScope; | 129 EventQueueScope eventQueueScope; |
| 130 doApply(&editingState); | 130 doApply(&editingState); |
| 131 } | 131 } |
| 132 | 132 |
| 133 // Only need to call appliedEditing for top-level commands, and TypingCommands | 133 // Only need to call appliedEditing for top-level commands, and TypingCommands |
| 134 // do it on their own (see TypingCommand::typingAddedToOpenCommand). | 134 // do it on their own (see TypingCommand::typingAddedToOpenCommand). |
| 135 if (!isTypingCommand()) | 135 if (!isTypingCommand()) |
| 136 frame->editor().appliedEditing(this); | 136 frame->editor().appliedEditing(this); |
| 137 setShouldRetainAutocorrectionIndicator(false); | 137 setShouldRetainAutocorrectionIndicator(false); |
| 138 return !editingState.isAborted(); | 138 return !editingState.isAborted(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 UndoStep* CompositeEditCommand::ensureComposition() { | 141 UndoStep* CompositeEditCommand::ensureUndoStep() { |
| 142 CompositeEditCommand* command = this; | 142 CompositeEditCommand* command = this; |
| 143 while (command && command->parent()) | 143 while (command && command->parent()) |
| 144 command = command->parent(); | 144 command = command->parent(); |
| 145 if (!command->m_composition) { | 145 if (!command->m_undoStep) { |
| 146 command->m_composition = UndoStep::create(&document(), startingSelection(), | 146 command->m_undoStep = UndoStep::create(&document(), startingSelection(), |
| 147 endingSelection(), inputType()); | 147 endingSelection(), inputType()); |
| 148 } | 148 } |
| 149 return command->m_composition.get(); | 149 return command->m_undoStep.get(); |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool CompositeEditCommand::preservesTypingStyle() const { | 152 bool CompositeEditCommand::preservesTypingStyle() const { |
| 153 return false; | 153 return false; |
| 154 } | 154 } |
| 155 | 155 |
| 156 bool CompositeEditCommand::isTypingCommand() const { | 156 bool CompositeEditCommand::isTypingCommand() const { |
| 157 return false; | 157 return false; |
| 158 } | 158 } |
| 159 | 159 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 178 void CompositeEditCommand::applyCommandToComposite(EditCommand* command, | 178 void CompositeEditCommand::applyCommandToComposite(EditCommand* command, |
| 179 EditingState* editingState) { | 179 EditingState* editingState) { |
| 180 command->setParent(this); | 180 command->setParent(this); |
| 181 command->doApply(editingState); | 181 command->doApply(editingState); |
| 182 if (editingState->isAborted()) { | 182 if (editingState->isAborted()) { |
| 183 command->setParent(nullptr); | 183 command->setParent(nullptr); |
| 184 return; | 184 return; |
| 185 } | 185 } |
| 186 if (command->isSimpleEditCommand()) { | 186 if (command->isSimpleEditCommand()) { |
| 187 command->setParent(0); | 187 command->setParent(0); |
| 188 ensureComposition()->append(toSimpleEditCommand(command)); | 188 ensureUndoStep()->append(toSimpleEditCommand(command)); |
| 189 } | 189 } |
| 190 m_commands.push_back(command); | 190 m_commands.push_back(command); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void CompositeEditCommand::applyCommandToComposite( | 193 void CompositeEditCommand::applyCommandToComposite( |
| 194 CompositeEditCommand* command, | 194 CompositeEditCommand* command, |
| 195 const VisibleSelection& selection, | 195 const VisibleSelection& selection, |
| 196 EditingState* editingState) { | 196 EditingState* editingState) { |
| 197 command->setParent(this); | 197 command->setParent(this); |
| 198 if (selection != command->endingSelection()) { | 198 if (selection != command->endingSelection()) { |
| 199 command->setStartingSelection(selection); | 199 command->setStartingSelection(selection); |
| 200 command->setEndingVisibleSelection(selection); | 200 command->setEndingVisibleSelection(selection); |
| 201 } | 201 } |
| 202 command->doApply(editingState); | 202 command->doApply(editingState); |
| 203 if (!editingState->isAborted()) | 203 if (!editingState->isAborted()) |
| 204 m_commands.push_back(command); | 204 m_commands.push_back(command); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void CompositeEditCommand::appendCommandToComposite( | 207 void CompositeEditCommand::appendCommandToUndoStep( |
| 208 CompositeEditCommand* command) { | 208 CompositeEditCommand* command) { |
| 209 ensureComposition()->append(command->ensureComposition()); | 209 ensureUndoStep()->append(command->ensureUndoStep()); |
| 210 command->m_composition = nullptr; | 210 command->m_undoStep = nullptr; |
| 211 command->setParent(this); | 211 command->setParent(this); |
| 212 m_commands.push_back(command); | 212 m_commands.push_back(command); |
| 213 } | 213 } |
| 214 | 214 |
| 215 void CompositeEditCommand::applyStyle(const EditingStyle* style, | 215 void CompositeEditCommand::applyStyle(const EditingStyle* style, |
| 216 EditingState* editingState) { | 216 EditingState* editingState) { |
| 217 applyCommandToComposite( | 217 applyCommandToComposite( |
| 218 ApplyStyleCommand::create(document(), style, InputEvent::InputType::None), | 218 ApplyStyleCommand::create(document(), style, InputEvent::InputType::None), |
| 219 editingState); | 219 editingState); |
| 220 } | 220 } |
| (...skipping 1704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1925 createVisiblePosition(firstPositionInOrBeforeNode(node)); | 1925 createVisiblePosition(firstPositionInOrBeforeNode(node)); |
| 1926 if (positionInParent.deepEquivalent() != positionInNode.deepEquivalent()) | 1926 if (positionInParent.deepEquivalent() != positionInNode.deepEquivalent()) |
| 1927 splitElement(parentElement, node); | 1927 splitElement(parentElement, node); |
| 1928 } | 1928 } |
| 1929 | 1929 |
| 1930 return node; | 1930 return node; |
| 1931 } | 1931 } |
| 1932 | 1932 |
| 1933 DEFINE_TRACE(CompositeEditCommand) { | 1933 DEFINE_TRACE(CompositeEditCommand) { |
| 1934 visitor->trace(m_commands); | 1934 visitor->trace(m_commands); |
| 1935 visitor->trace(m_composition); | 1935 visitor->trace(m_undoStep); |
| 1936 EditCommand::trace(visitor); | 1936 EditCommand::trace(visitor); |
| 1937 } | 1937 } |
| 1938 | 1938 |
| 1939 } // namespace blink | 1939 } // namespace blink |
| OLD | NEW |