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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 #include "core/editing/commands/MergeIdenticalElementsCommand.h" | 49 #include "core/editing/commands/MergeIdenticalElementsCommand.h" |
50 #include "core/editing/commands/RemoveCSSPropertyCommand.h" | 50 #include "core/editing/commands/RemoveCSSPropertyCommand.h" |
51 #include "core/editing/commands/RemoveNodeCommand.h" | 51 #include "core/editing/commands/RemoveNodeCommand.h" |
52 #include "core/editing/commands/RemoveNodePreservingChildrenCommand.h" | 52 #include "core/editing/commands/RemoveNodePreservingChildrenCommand.h" |
53 #include "core/editing/commands/ReplaceNodeWithSpanCommand.h" | 53 #include "core/editing/commands/ReplaceNodeWithSpanCommand.h" |
54 #include "core/editing/commands/ReplaceSelectionCommand.h" | 54 #include "core/editing/commands/ReplaceSelectionCommand.h" |
55 #include "core/editing/commands/SetNodeAttributeCommand.h" | 55 #include "core/editing/commands/SetNodeAttributeCommand.h" |
56 #include "core/editing/commands/SplitElementCommand.h" | 56 #include "core/editing/commands/SplitElementCommand.h" |
57 #include "core/editing/commands/SplitTextNodeCommand.h" | 57 #include "core/editing/commands/SplitTextNodeCommand.h" |
58 #include "core/editing/commands/SplitTextNodeContainingElementCommand.h" | 58 #include "core/editing/commands/SplitTextNodeContainingElementCommand.h" |
59 #include "core/editing/commands/TypingCommand.h" | |
59 #include "core/editing/commands/WrapContentsInDummySpanCommand.h" | 60 #include "core/editing/commands/WrapContentsInDummySpanCommand.h" |
60 #include "core/editing/iterators/TextIterator.h" | 61 #include "core/editing/iterators/TextIterator.h" |
61 #include "core/editing/markers/DocumentMarkerController.h" | 62 #include "core/editing/markers/DocumentMarkerController.h" |
62 #include "core/editing/serializers/Serialization.h" | 63 #include "core/editing/serializers/Serialization.h" |
63 #include "core/editing/spellcheck/SpellChecker.h" | 64 #include "core/editing/spellcheck/SpellChecker.h" |
64 #include "core/events/ScopedEventQueue.h" | 65 #include "core/events/ScopedEventQueue.h" |
65 #include "core/frame/LocalFrame.h" | 66 #include "core/frame/LocalFrame.h" |
66 #include "core/html/HTMLBRElement.h" | 67 #include "core/html/HTMLBRElement.h" |
67 #include "core/html/HTMLDivElement.h" | 68 #include "core/html/HTMLDivElement.h" |
68 #include "core/html/HTMLElement.h" | 69 #include "core/html/HTMLElement.h" |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
142 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); | 143 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); |
143 | 144 |
144 { | 145 { |
145 for (const auto& command : m_commands) | 146 for (const auto& command : m_commands) |
146 command->doReapply(); | 147 command->doReapply(); |
147 } | 148 } |
148 | 149 |
149 frame->editor().reappliedEditing(this); | 150 frame->editor().reappliedEditing(this); |
150 } | 151 } |
151 | 152 |
152 bool EditCommandComposition::willUnapply(EditCommandSource) { | 153 bool EditCommandComposition::willUnapply(EditCommandSource source) { |
153 // TODO(chongz): Fire 'beforeinput' for 'historyUndo'. | 154 return dispatchBeforeInputEvent(source, m_document->frame(), m_document, |
chongz
2016/12/20 23:27:52
Added to cover undo command from "EditorCommand.cp
| |
154 return true; | 155 InputEvent::InputType::HistoryUndo, nullAtom, |
156 nullptr, InputEvent::IsCancelable, | |
157 InputEvent::NotComposing, nullptr); | |
155 } | 158 } |
156 | 159 |
157 bool EditCommandComposition::willReapply(EditCommandSource) { | 160 bool EditCommandComposition::willReapply(EditCommandSource source) { |
158 // TODO(chongz): Fire 'beforeinput' for 'historyRedo'. | 161 return dispatchBeforeInputEvent(source, m_document->frame(), m_document, |
chongz
2016/12/20 23:27:52
Added to cover redo command from "EditorCommand.cp
| |
159 return true; | 162 InputEvent::InputType::HistoryRedo, nullAtom, |
163 nullptr, InputEvent::IsCancelable, | |
164 InputEvent::NotComposing, nullptr); | |
160 } | 165 } |
161 | 166 |
162 void EditCommandComposition::append(SimpleEditCommand* command) { | 167 void EditCommandComposition::append(SimpleEditCommand* command) { |
163 m_commands.push_back(command); | 168 m_commands.push_back(command); |
164 } | 169 } |
165 | 170 |
166 void EditCommandComposition::append(EditCommandComposition* composition) { | 171 void EditCommandComposition::append(EditCommandComposition* composition) { |
167 m_commands.appendVector(composition->m_commands); | 172 m_commands.appendVector(composition->m_commands); |
168 } | 173 } |
169 | 174 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
218 case InputEvent::InputType::DeleteByDrag: | 223 case InputEvent::InputType::DeleteByDrag: |
219 case InputEvent::InputType::None: | 224 case InputEvent::InputType::None: |
220 break; | 225 break; |
221 default: | 226 default: |
222 NOTREACHED(); | 227 NOTREACHED(); |
223 return false; | 228 return false; |
224 } | 229 } |
225 } | 230 } |
226 ensureComposition(); | 231 ensureComposition(); |
227 | 232 |
233 // Covers the initial TypingCommand and other top-level commands. | |
234 // TypingCommand::willAddTypingToOpenCommand() also calls willApplyEditing(). | |
235 if (!willApplyEditing(source)) | |
236 return false; | |
237 | |
228 // Changes to the document may have been made since the last editing operation | 238 // 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 | 239 // that require a layout, as in <rdar://problem/5658603>. Low level |
230 // operations, like RemoveNodeCommand, don't require a layout because the high | 240 // 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 | 241 // level operations that use them perform one if one is necessary (like for |
232 // the creation of VisiblePositions). | 242 // the creation of VisiblePositions). |
233 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 243 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
234 | 244 |
235 if (!willApplyEditing(source)) | |
236 return false; | |
237 | |
238 LocalFrame* frame = document().frame(); | 245 LocalFrame* frame = document().frame(); |
239 DCHECK(frame); | 246 DCHECK(frame); |
240 EditingState editingState; | 247 EditingState editingState; |
241 { | 248 { |
242 EventQueueScope eventQueueScope; | 249 EventQueueScope eventQueueScope; |
243 doApply(&editingState); | 250 doApply(&editingState); |
244 } | 251 } |
245 | 252 |
246 // Only need to call appliedEditing for top-level commands, and TypingCommands | 253 // Only need to call appliedEditing for top-level commands, and TypingCommands |
247 // do it on their own (see TypingCommand::typingAddedToOpenCommand). | 254 // do it on their own (see TypingCommand::typingAddedToOpenCommand). |
248 if (!isTypingCommand()) | 255 if (!isTypingCommand()) |
249 frame->editor().appliedEditing(this); | 256 frame->editor().appliedEditing(this); |
250 setShouldRetainAutocorrectionIndicator(false); | 257 setShouldRetainAutocorrectionIndicator(false); |
251 return !editingState.isAborted(); | 258 return !editingState.isAborted(); |
252 } | 259 } |
253 | 260 |
254 EditCommandComposition* CompositeEditCommand::ensureComposition() { | 261 EditCommandComposition* CompositeEditCommand::ensureComposition() { |
255 CompositeEditCommand* command = this; | 262 CompositeEditCommand* command = this; |
256 while (command && command->parent()) | 263 while (command && command->parent()) |
257 command = command->parent(); | 264 command = command->parent(); |
258 if (!command->m_composition) { | 265 if (!command->m_composition) { |
259 command->m_composition = EditCommandComposition::create( | 266 command->m_composition = EditCommandComposition::create( |
260 &document(), startingSelection(), endingSelection()); | 267 &document(), startingSelection(), endingSelection()); |
261 } | 268 } |
262 return command->m_composition.get(); | 269 return command->m_composition.get(); |
263 } | 270 } |
264 | 271 |
265 bool CompositeEditCommand::willApplyEditing(EditCommandSource) { | 272 bool CompositeEditCommand::willApplyEditing(EditCommandSource source) { |
266 // TODO(chongz): Move all the 'beforeinput' dispatching logic here. | 273 // TODO(chongz): Remove the following code after we have ensured it's OK to |
267 return true; | 274 // fire 'beforeinput' after 'compositionupdate'. |
275 // https://crbug.com/675820 | |
276 if (isTypingCommand() && (toTypingCommand(this)->compositionType() == | |
277 TypingCommand::TextCompositionUpdate || | |
278 toTypingCommand(this)->compositionType() == | |
279 TypingCommand::TextCompositionConfirm)) | |
280 return true; | |
281 return dispatchBeforeInputEvent( | |
chongz
2016/12/20 23:27:52
Covers all hot keys, context menu, cut&paste, drag
| |
282 source, document().frame(), eventTargetNodeForDocument(&document()), | |
283 inputType(), textDataForInputEvent(), dataTransferForInputEvent(), | |
284 isCancelableFromCommand(this), isComposingFromCommand(this), | |
285 targetRangesForInputEvent()); | |
286 } | |
287 | |
288 InputEvent::InputType CompositeEditCommand::inputType() const { | |
289 return InputEvent::InputType::None; | |
290 } | |
291 | |
292 String CompositeEditCommand::textDataForInputEvent() const { | |
293 return nullAtom; | |
294 } | |
295 | |
296 DataTransfer* CompositeEditCommand::dataTransferForInputEvent() const { | |
297 return nullptr; | |
298 } | |
299 | |
300 RangeVector* CompositeEditCommand::targetRangesForInputEvent() const { | |
301 if (!document().frame()->editor().canEditRichly()) | |
302 return nullptr; | |
303 return new RangeVector(1, document().frame()->selection().firstRange()); | |
chongz
2016/12/20 23:27:52
New implementation, also fixes https://crbug.com/6
Xiaocheng
2016/12/21 02:56:39
What are the ranges used by the current implementa
chongz
2016/12/21 23:59:24
Reverted and will fix in another patch.
We used
| |
268 } | 304 } |
269 | 305 |
270 bool CompositeEditCommand::preservesTypingStyle() const { | 306 bool CompositeEditCommand::preservesTypingStyle() const { |
271 return false; | 307 return false; |
272 } | 308 } |
273 | 309 |
274 bool CompositeEditCommand::isTypingCommand() const { | 310 bool CompositeEditCommand::isTypingCommand() const { |
275 return false; | 311 return false; |
276 } | 312 } |
277 | 313 |
(...skipping 1769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2047 return node; | 2083 return node; |
2048 } | 2084 } |
2049 | 2085 |
2050 DEFINE_TRACE(CompositeEditCommand) { | 2086 DEFINE_TRACE(CompositeEditCommand) { |
2051 visitor->trace(m_commands); | 2087 visitor->trace(m_commands); |
2052 visitor->trace(m_composition); | 2088 visitor->trace(m_composition); |
2053 EditCommand::trace(visitor); | 2089 EditCommand::trace(visitor); |
2054 } | 2090 } |
2055 | 2091 |
2056 } // namespace blink | 2092 } // namespace blink |
OLD | NEW |