| 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 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 bool EditCommandComposition::belongsTo(const LocalFrame& frame) const { | 100 bool EditCommandComposition::belongsTo(const LocalFrame& frame) const { |
| 101 DCHECK(m_document); | 101 DCHECK(m_document); |
| 102 return m_document->frame() == &frame; | 102 return m_document->frame() == &frame; |
| 103 } | 103 } |
| 104 | 104 |
| 105 void EditCommandComposition::unapply(EditCommandSource source) { | 105 void EditCommandComposition::unapply(EditCommandSource source) { |
| 106 DCHECK(m_document); | 106 DCHECK(m_document); |
| 107 LocalFrame* frame = m_document->frame(); | 107 LocalFrame* frame = m_document->frame(); |
| 108 DCHECK(frame); | 108 DCHECK(frame); |
| 109 | 109 |
| 110 if (!willUnapply(source)) | 110 if (!willUnapply(source, BeforeInputTiming::kHasFiredBeforeCommand)) |
| 111 return; | 111 return; |
| 112 | 112 |
| 113 // Changes to the document may have been made since the last editing operation | 113 // Changes to the document may have been made since the last editing operation |
| 114 // that require a layout, as in <rdar://problem/5658603>. Low level | 114 // that require a layout, as in <rdar://problem/5658603>. Low level |
| 115 // operations, like RemoveNodeCommand, don't require a layout because the high | 115 // operations, like RemoveNodeCommand, don't require a layout because the high |
| 116 // level operations that use them perform one if one is necessary (like for | 116 // level operations that use them perform one if one is necessary (like for |
| 117 // the creation of VisiblePositions). | 117 // the creation of VisiblePositions). |
| 118 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); | 118 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 119 | 119 |
| 120 { | 120 { |
| 121 size_t size = m_commands.size(); | 121 size_t size = m_commands.size(); |
| 122 for (size_t i = size; i; --i) | 122 for (size_t i = size; i; --i) |
| 123 m_commands[i - 1]->doUnapply(); | 123 m_commands[i - 1]->doUnapply(); |
| 124 } | 124 } |
| 125 | 125 |
| 126 frame->editor().unappliedEditing(this); | 126 frame->editor().unappliedEditing(this); |
| 127 } | 127 } |
| 128 | 128 |
| 129 void EditCommandComposition::reapply(EditCommandSource source) { | 129 void EditCommandComposition::reapply(EditCommandSource source) { |
| 130 DCHECK(m_document); | 130 DCHECK(m_document); |
| 131 LocalFrame* frame = m_document->frame(); | 131 LocalFrame* frame = m_document->frame(); |
| 132 DCHECK(frame); | 132 DCHECK(frame); |
| 133 | 133 |
| 134 if (!willReapply(source)) | 134 if (!willReapply(source, BeforeInputTiming::kHasFiredBeforeCommand)) |
| 135 return; | 135 return; |
| 136 | 136 |
| 137 // Changes to the document may have been made since the last editing operation | 137 // Changes to the document may have been made since the last editing operation |
| 138 // that require a layout, as in <rdar://problem/5658603>. Low level | 138 // that require a layout, as in <rdar://problem/5658603>. Low level |
| 139 // operations, like RemoveNodeCommand, don't require a layout because the high | 139 // operations, like RemoveNodeCommand, don't require a layout because the high |
| 140 // level operations that use them perform one if one is necessary (like for | 140 // level operations that use them perform one if one is necessary (like for |
| 141 // the creation of VisiblePositions). | 141 // the creation of VisiblePositions). |
| 142 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); | 142 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 143 | 143 |
| 144 { | 144 { |
| 145 for (const auto& command : m_commands) | 145 for (const auto& command : m_commands) |
| 146 command->doReapply(); | 146 command->doReapply(); |
| 147 } | 147 } |
| 148 | 148 |
| 149 frame->editor().reappliedEditing(this); | 149 frame->editor().reappliedEditing(this); |
| 150 } | 150 } |
| 151 | 151 |
| 152 bool EditCommandComposition::willUnapply(EditCommandSource) { | 152 bool EditCommandComposition::willUnapply(EditCommandSource, BeforeInputTiming) { |
| 153 // TODO(chongz): Fire 'beforeinput' for 'historyUndo'. | 153 // TODO(chongz): Fire 'beforeinput' for 'historyUndo'. |
| 154 return true; | 154 return true; |
| 155 } | 155 } |
| 156 | 156 |
| 157 bool EditCommandComposition::willReapply(EditCommandSource) { | 157 bool EditCommandComposition::willReapply(EditCommandSource, BeforeInputTiming) { |
| 158 // TODO(chongz): Fire 'beforeinput' for 'historyRedo'. | 158 // TODO(chongz): Fire 'beforeinput' for 'historyRedo'. |
| 159 return true; | 159 return true; |
| 160 } | 160 } |
| 161 | 161 |
| 162 void EditCommandComposition::append(SimpleEditCommand* command) { | 162 void EditCommandComposition::append(SimpleEditCommand* command) { |
| 163 m_commands.push_back(command); | 163 m_commands.push_back(command); |
| 164 } | 164 } |
| 165 | 165 |
| 166 void EditCommandComposition::append(EditCommandComposition* composition) { | 166 void EditCommandComposition::append(EditCommandComposition* composition) { |
| 167 m_commands.appendVector(composition->m_commands); | 167 m_commands.appendVector(composition->m_commands); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 189 UndoStep::trace(visitor); | 189 UndoStep::trace(visitor); |
| 190 } | 190 } |
| 191 | 191 |
| 192 CompositeEditCommand::CompositeEditCommand(Document& document) | 192 CompositeEditCommand::CompositeEditCommand(Document& document) |
| 193 : EditCommand(document) {} | 193 : EditCommand(document) {} |
| 194 | 194 |
| 195 CompositeEditCommand::~CompositeEditCommand() { | 195 CompositeEditCommand::~CompositeEditCommand() { |
| 196 DCHECK(isTopLevelCommand() || !m_composition); | 196 DCHECK(isTopLevelCommand() || !m_composition); |
| 197 } | 197 } |
| 198 | 198 |
| 199 bool CompositeEditCommand::apply(EditCommandSource source) { | 199 bool CompositeEditCommand::apply(EditCommandSource source, |
| 200 BeforeInputTiming beforeInputTiming) { |
| 200 DCHECK(!isCommandGroupWrapper()); | 201 DCHECK(!isCommandGroupWrapper()); |
| 201 if (!endingSelection().isContentRichlyEditable()) { | 202 if (!endingSelection().isContentRichlyEditable()) { |
| 202 switch (inputType()) { | 203 switch (inputType()) { |
| 203 case InputEvent::InputType::InsertText: | 204 case InputEvent::InputType::InsertText: |
| 204 case InputEvent::InputType::InsertLineBreak: | 205 case InputEvent::InputType::InsertLineBreak: |
| 205 case InputEvent::InputType::InsertParagraph: | 206 case InputEvent::InputType::InsertParagraph: |
| 206 case InputEvent::InputType::InsertFromPaste: | 207 case InputEvent::InputType::InsertFromPaste: |
| 207 case InputEvent::InputType::InsertFromDrop: | 208 case InputEvent::InputType::InsertFromDrop: |
| 208 case InputEvent::InputType::InsertReplacementText: | 209 case InputEvent::InputType::InsertReplacementText: |
| 209 case InputEvent::InputType::DeleteComposedCharacterForward: | 210 case InputEvent::InputType::DeleteComposedCharacterForward: |
| (...skipping 15 matching lines...) Expand all Loading... |
| 225 } | 226 } |
| 226 ensureComposition(); | 227 ensureComposition(); |
| 227 | 228 |
| 228 // Changes to the document may have been made since the last editing operation | 229 // Changes to the document may have been made since the last editing operation |
| 229 // that require a layout, as in <rdar://problem/5658603>. Low level | 230 // that require a layout, as in <rdar://problem/5658603>. Low level |
| 230 // operations, like RemoveNodeCommand, don't require a layout because the high | 231 // operations, like RemoveNodeCommand, don't require a layout because the high |
| 231 // level operations that use them perform one if one is necessary (like for | 232 // level operations that use them perform one if one is necessary (like for |
| 232 // the creation of VisiblePositions). | 233 // the creation of VisiblePositions). |
| 233 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 234 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 234 | 235 |
| 235 if (!willApplyEditing(source)) | 236 if (!willApplyEditing(source, beforeInputTiming)) |
| 236 return false; | 237 return false; |
| 237 | 238 |
| 238 LocalFrame* frame = document().frame(); | 239 LocalFrame* frame = document().frame(); |
| 239 DCHECK(frame); | 240 DCHECK(frame); |
| 240 EditingState editingState; | 241 EditingState editingState; |
| 241 { | 242 { |
| 242 EventQueueScope eventQueueScope; | 243 EventQueueScope eventQueueScope; |
| 243 doApply(&editingState); | 244 doApply(&editingState); |
| 244 } | 245 } |
| 245 | 246 |
| 246 // Only need to call appliedEditing for top-level commands, and TypingCommands | 247 // Only need to call appliedEditing for top-level commands, and TypingCommands |
| 247 // do it on their own (see TypingCommand::typingAddedToOpenCommand). | 248 // do it on their own (see TypingCommand::typingAddedToOpenCommand). |
| 248 if (!isTypingCommand()) | 249 if (!isTypingCommand()) |
| 249 frame->editor().appliedEditing(this); | 250 frame->editor().appliedEditing(this); |
| 250 setShouldRetainAutocorrectionIndicator(false); | 251 setShouldRetainAutocorrectionIndicator(false); |
| 251 return !editingState.isAborted(); | 252 return !editingState.isAborted(); |
| 252 } | 253 } |
| 253 | 254 |
| 254 EditCommandComposition* CompositeEditCommand::ensureComposition() { | 255 EditCommandComposition* CompositeEditCommand::ensureComposition() { |
| 255 CompositeEditCommand* command = this; | 256 CompositeEditCommand* command = this; |
| 256 while (command && command->parent()) | 257 while (command && command->parent()) |
| 257 command = command->parent(); | 258 command = command->parent(); |
| 258 if (!command->m_composition) { | 259 if (!command->m_composition) { |
| 259 command->m_composition = EditCommandComposition::create( | 260 command->m_composition = EditCommandComposition::create( |
| 260 &document(), startingSelection(), endingSelection()); | 261 &document(), startingSelection(), endingSelection()); |
| 261 } | 262 } |
| 262 return command->m_composition.get(); | 263 return command->m_composition.get(); |
| 263 } | 264 } |
| 264 | 265 |
| 265 bool CompositeEditCommand::willApplyEditing(EditCommandSource) { | 266 bool CompositeEditCommand::willApplyEditing(EditCommandSource, |
| 267 BeforeInputTiming) { |
| 266 // TODO(chongz): Move all the 'beforeinput' dispatching logic here. | 268 // TODO(chongz): Move all the 'beforeinput' dispatching logic here. |
| 267 return true; | 269 return true; |
| 268 } | 270 } |
| 269 | 271 |
| 270 bool CompositeEditCommand::preservesTypingStyle() const { | 272 bool CompositeEditCommand::preservesTypingStyle() const { |
| 271 return false; | 273 return false; |
| 272 } | 274 } |
| 273 | 275 |
| 274 bool CompositeEditCommand::isTypingCommand() const { | 276 bool CompositeEditCommand::isTypingCommand() const { |
| 275 return false; | 277 return false; |
| (...skipping 1771 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2047 return node; | 2049 return node; |
| 2048 } | 2050 } |
| 2049 | 2051 |
| 2050 DEFINE_TRACE(CompositeEditCommand) { | 2052 DEFINE_TRACE(CompositeEditCommand) { |
| 2051 visitor->trace(m_commands); | 2053 visitor->trace(m_commands); |
| 2052 visitor->trace(m_composition); | 2054 visitor->trace(m_composition); |
| 2053 EditCommand::trace(visitor); | 2055 EditCommand::trace(visitor); |
| 2054 } | 2056 } |
| 2055 | 2057 |
| 2056 } // namespace blink | 2058 } // namespace blink |
| OLD | NEW |