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

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

Issue 2574793002: [Editing] Store |CommandSource| in |CompositeEditCommand| (Closed)
Patch Set: Created 4 years 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
OLDNEW
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 25 matching lines...) Expand all
36 #include "core/editing/EditingUtilities.h" 36 #include "core/editing/EditingUtilities.h"
37 #include "core/editing/Editor.h" 37 #include "core/editing/Editor.h"
38 #include "core/editing/PlainTextRange.h" 38 #include "core/editing/PlainTextRange.h"
39 #include "core/editing/RelocatablePosition.h" 39 #include "core/editing/RelocatablePosition.h"
40 #include "core/editing/VisibleUnits.h" 40 #include "core/editing/VisibleUnits.h"
41 #include "core/editing/commands/AppendNodeCommand.h" 41 #include "core/editing/commands/AppendNodeCommand.h"
42 #include "core/editing/commands/ApplyStyleCommand.h" 42 #include "core/editing/commands/ApplyStyleCommand.h"
43 #include "core/editing/commands/DeleteFromTextNodeCommand.h" 43 #include "core/editing/commands/DeleteFromTextNodeCommand.h"
44 #include "core/editing/commands/DeleteSelectionCommand.h" 44 #include "core/editing/commands/DeleteSelectionCommand.h"
45 #include "core/editing/commands/InsertIntoTextNodeCommand.h" 45 #include "core/editing/commands/InsertIntoTextNodeCommand.h"
46 #include "core/editing/commands/InsertLineBreakCommand.h"
47 #include "core/editing/commands/InsertNodeBeforeCommand.h" 46 #include "core/editing/commands/InsertNodeBeforeCommand.h"
48 #include "core/editing/commands/InsertParagraphSeparatorCommand.h" 47 #include "core/editing/commands/InsertParagraphSeparatorCommand.h"
49 #include "core/editing/commands/MergeIdenticalElementsCommand.h" 48 #include "core/editing/commands/MergeIdenticalElementsCommand.h"
50 #include "core/editing/commands/RemoveCSSPropertyCommand.h" 49 #include "core/editing/commands/RemoveCSSPropertyCommand.h"
51 #include "core/editing/commands/RemoveNodeCommand.h" 50 #include "core/editing/commands/RemoveNodeCommand.h"
52 #include "core/editing/commands/RemoveNodePreservingChildrenCommand.h" 51 #include "core/editing/commands/RemoveNodePreservingChildrenCommand.h"
53 #include "core/editing/commands/ReplaceNodeWithSpanCommand.h" 52 #include "core/editing/commands/ReplaceNodeWithSpanCommand.h"
54 #include "core/editing/commands/ReplaceSelectionCommand.h" 53 #include "core/editing/commands/ReplaceSelectionCommand.h"
55 #include "core/editing/commands/SetNodeAttributeCommand.h" 54 #include "core/editing/commands/SetNodeAttributeCommand.h"
56 #include "core/editing/commands/SplitElementCommand.h" 55 #include "core/editing/commands/SplitElementCommand.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 DEFINE_TRACE(EditCommandComposition) { 172 DEFINE_TRACE(EditCommandComposition) {
174 visitor->trace(m_document); 173 visitor->trace(m_document);
175 visitor->trace(m_startingSelection); 174 visitor->trace(m_startingSelection);
176 visitor->trace(m_endingSelection); 175 visitor->trace(m_endingSelection);
177 visitor->trace(m_commands); 176 visitor->trace(m_commands);
178 visitor->trace(m_startingRootEditableElement); 177 visitor->trace(m_startingRootEditableElement);
179 visitor->trace(m_endingRootEditableElement); 178 visitor->trace(m_endingRootEditableElement);
180 UndoStep::trace(visitor); 179 UndoStep::trace(visitor);
181 } 180 }
182 181
183 CompositeEditCommand::CompositeEditCommand(Document& document) 182 CompositeEditCommand::CompositeEditCommand(Document& document,
184 : EditCommand(document) {} 183 CommandSource source)
184 : EditCommand(document), m_source(source) {}
185 185
186 CompositeEditCommand::~CompositeEditCommand() { 186 CompositeEditCommand::~CompositeEditCommand() {
187 DCHECK(isTopLevelCommand() || !m_composition); 187 DCHECK(isTopLevelCommand() || !m_composition);
188 } 188 }
189 189
190 bool CompositeEditCommand::apply() { 190 bool CompositeEditCommand::apply() {
191 DCHECK(!isCommandGroupWrapper()); 191 DCHECK(!isCommandGroupWrapper());
192 if (!endingSelection().isContentRichlyEditable()) { 192 if (!endingSelection().isContentRichlyEditable()) {
193 switch (inputType()) { 193 switch (inputType()) {
194 case InputEvent::InputType::InsertText: 194 case InputEvent::InputType::InsertText:
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 CompositeEditCommand* command) { 308 CompositeEditCommand* command) {
309 ensureComposition()->append(command->ensureComposition()); 309 ensureComposition()->append(command->ensureComposition());
310 command->m_composition = nullptr; 310 command->m_composition = nullptr;
311 command->setParent(this); 311 command->setParent(this);
312 m_commands.append(command); 312 m_commands.append(command);
313 } 313 }
314 314
315 void CompositeEditCommand::applyStyle(const EditingStyle* style, 315 void CompositeEditCommand::applyStyle(const EditingStyle* style,
316 EditingState* editingState) { 316 EditingState* editingState) {
317 applyCommandToComposite( 317 applyCommandToComposite(
318 ApplyStyleCommand::create(document(), style, InputEvent::InputType::None), 318 ApplyStyleCommand::create(document(), commandSource(), style,
319 InputEvent::InputType::None),
319 editingState); 320 editingState);
320 } 321 }
321 322
322 void CompositeEditCommand::applyStyle(const EditingStyle* style, 323 void CompositeEditCommand::applyStyle(const EditingStyle* style,
323 const Position& start, 324 const Position& start,
324 const Position& end, 325 const Position& end,
325 EditingState* editingState) { 326 EditingState* editingState) {
326 applyCommandToComposite( 327 applyCommandToComposite(
327 ApplyStyleCommand::create(document(), style, start, end), editingState); 328 ApplyStyleCommand::create(document(), commandSource(), style, start, end),
329 editingState);
328 } 330 }
329 331
330 void CompositeEditCommand::applyStyledElement(Element* element, 332 void CompositeEditCommand::applyStyledElement(Element* element,
331 EditingState* editingState) { 333 EditingState* editingState) {
332 applyCommandToComposite(ApplyStyleCommand::create(element, false), 334 applyCommandToComposite(
333 editingState); 335 ApplyStyleCommand::create(commandSource(), element, false), editingState);
334 } 336 }
335 337
336 void CompositeEditCommand::removeStyledElement(Element* element, 338 void CompositeEditCommand::removeStyledElement(Element* element,
337 EditingState* editingState) { 339 EditingState* editingState) {
338 applyCommandToComposite(ApplyStyleCommand::create(element, true), 340 applyCommandToComposite(
339 editingState); 341 ApplyStyleCommand::create(commandSource(), element, true), editingState);
340 } 342 }
341 343
342 void CompositeEditCommand::insertParagraphSeparator( 344 void CompositeEditCommand::insertParagraphSeparator(
343 EditingState* editingState, 345 EditingState* editingState,
344 bool useDefaultParagraphElement, 346 bool useDefaultParagraphElement,
345 bool pasteBlockqutoeIntoUnquotedArea) { 347 bool pasteBlockqutoeIntoUnquotedArea) {
346 applyCommandToComposite(InsertParagraphSeparatorCommand::create( 348 applyCommandToComposite(
347 document(), useDefaultParagraphElement, 349 InsertParagraphSeparatorCommand::create(document(), commandSource(),
348 pasteBlockqutoeIntoUnquotedArea), 350 useDefaultParagraphElement,
349 editingState); 351 pasteBlockqutoeIntoUnquotedArea),
352 editingState);
350 } 353 }
351 354
352 bool CompositeEditCommand::isRemovableBlock(const Node* node) { 355 bool CompositeEditCommand::isRemovableBlock(const Node* node) {
353 DCHECK(node); 356 DCHECK(node);
354 if (!isHTMLDivElement(*node)) 357 if (!isHTMLDivElement(*node))
355 return false; 358 return false;
356 359
357 const HTMLDivElement& element = toHTMLDivElement(*node); 360 const HTMLDivElement& element = toHTMLDivElement(*node);
358 ContainerNode* parentNode = element.parentNode(); 361 ContainerNode* parentNode = element.parentNode();
359 if (parentNode && parentNode->firstChild() != parentNode->lastChild()) 362 if (parentNode && parentNode->firstChild() != parentNode->lastChild())
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 applyCommandToComposite( 481 applyCommandToComposite(
479 RemoveNodeCommand::create(node, shouldAssumeContentIsAlwaysEditable), 482 RemoveNodeCommand::create(node, shouldAssumeContentIsAlwaysEditable),
480 editingState); 483 editingState);
481 } 484 }
482 485
483 void CompositeEditCommand::removeNodePreservingChildren( 486 void CompositeEditCommand::removeNodePreservingChildren(
484 Node* node, 487 Node* node,
485 EditingState* editingState, 488 EditingState* editingState,
486 ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable) { 489 ShouldAssumeContentIsAlwaysEditable shouldAssumeContentIsAlwaysEditable) {
487 ABORT_EDITING_COMMAND_IF(!node->document().frame()); 490 ABORT_EDITING_COMMAND_IF(!node->document().frame());
488 applyCommandToComposite(RemoveNodePreservingChildrenCommand::create( 491 applyCommandToComposite(
489 node, shouldAssumeContentIsAlwaysEditable), 492 RemoveNodePreservingChildrenCommand::create(
490 editingState); 493 commandSource(), node, shouldAssumeContentIsAlwaysEditable),
494 editingState);
491 } 495 }
492 496
493 void CompositeEditCommand::removeNodeAndPruneAncestors( 497 void CompositeEditCommand::removeNodeAndPruneAncestors(
494 Node* node, 498 Node* node,
495 EditingState* editingState, 499 EditingState* editingState,
496 Node* excludeNode) { 500 Node* excludeNode) {
497 DCHECK_NE(node, excludeNode); 501 DCHECK_NE(node, excludeNode);
498 ContainerNode* parent = node->parentNode(); 502 ContainerNode* parent = node->parentNode();
499 removeNode(node, editingState); 503 removeNode(node, editingState);
500 if (editingState->isAborted()) 504 if (editingState->isAborted())
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 593
590 void CompositeEditCommand::wrapContentsInDummySpan(Element* element) { 594 void CompositeEditCommand::wrapContentsInDummySpan(Element* element) {
591 // WrapContentsInDummySpanCommand is never aborted. 595 // WrapContentsInDummySpanCommand is never aborted.
592 applyCommandToComposite(WrapContentsInDummySpanCommand::create(element), 596 applyCommandToComposite(WrapContentsInDummySpanCommand::create(element),
593 ASSERT_NO_EDITING_ABORT); 597 ASSERT_NO_EDITING_ABORT);
594 } 598 }
595 599
596 void CompositeEditCommand::splitTextNodeContainingElement(Text* text, 600 void CompositeEditCommand::splitTextNodeContainingElement(Text* text,
597 unsigned offset) { 601 unsigned offset) {
598 // SplitTextNodeContainingElementCommand is never aborted. 602 // SplitTextNodeContainingElementCommand is never aborted.
599 applyCommandToComposite( 603 applyCommandToComposite(SplitTextNodeContainingElementCommand::create(
600 SplitTextNodeContainingElementCommand::create(text, offset), 604 commandSource(), text, offset),
601 ASSERT_NO_EDITING_ABORT); 605 ASSERT_NO_EDITING_ABORT);
602 } 606 }
603 607
604 void CompositeEditCommand::insertTextIntoNode(Text* node, 608 void CompositeEditCommand::insertTextIntoNode(Text* node,
605 unsigned offset, 609 unsigned offset,
606 const String& text) { 610 const String& text) {
607 // InsertIntoTextNodeCommand is never aborted. 611 // InsertIntoTextNodeCommand is never aborted.
608 if (!text.isEmpty()) 612 if (!text.isEmpty())
609 applyCommandToComposite( 613 applyCommandToComposite(
610 InsertIntoTextNodeCommand::create(node, offset, text), 614 InsertIntoTextNodeCommand::create(node, offset, text),
611 ASSERT_NO_EDITING_ABORT); 615 ASSERT_NO_EDITING_ABORT);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
732 EditingState* editingState) { 736 EditingState* editingState) {
733 // insert node before, after, or at split of tab span 737 // insert node before, after, or at split of tab span
734 insertNodeAt(node, positionOutsideTabSpan(pos), editingState); 738 insertNodeAt(node, positionOutsideTabSpan(pos), editingState);
735 } 739 }
736 740
737 void CompositeEditCommand::deleteSelection(EditingState* editingState, 741 void CompositeEditCommand::deleteSelection(EditingState* editingState,
738 bool smartDelete, 742 bool smartDelete,
739 bool mergeBlocksAfterDelete, 743 bool mergeBlocksAfterDelete,
740 bool expandForSpecialElements, 744 bool expandForSpecialElements,
741 bool sanitizeMarkup) { 745 bool sanitizeMarkup) {
742 if (endingSelection().isRange()) 746 if (endingSelection().isRange()) {
743 applyCommandToComposite(DeleteSelectionCommand::create( 747 applyCommandToComposite(
744 document(), smartDelete, mergeBlocksAfterDelete, 748 DeleteSelectionCommand::create(
745 expandForSpecialElements, sanitizeMarkup), 749 document(), commandSource(), smartDelete, mergeBlocksAfterDelete,
746 editingState); 750 expandForSpecialElements, sanitizeMarkup),
751 editingState);
752 }
747 } 753 }
748 754
749 void CompositeEditCommand::deleteSelection(const VisibleSelection& selection, 755 void CompositeEditCommand::deleteSelection(const VisibleSelection& selection,
750 EditingState* editingState, 756 EditingState* editingState,
751 bool smartDelete, 757 bool smartDelete,
752 bool mergeBlocksAfterDelete, 758 bool mergeBlocksAfterDelete,
753 bool expandForSpecialElements, 759 bool expandForSpecialElements,
754 bool sanitizeMarkup) { 760 bool sanitizeMarkup) {
755 if (selection.isRange()) 761 if (selection.isRange()) {
756 applyCommandToComposite(DeleteSelectionCommand::create( 762 applyCommandToComposite(
757 selection, smartDelete, mergeBlocksAfterDelete, 763 DeleteSelectionCommand::create(
758 expandForSpecialElements, sanitizeMarkup), 764 commandSource(), selection, smartDelete, mergeBlocksAfterDelete,
759 editingState); 765 expandForSpecialElements, sanitizeMarkup),
766 editingState);
767 }
760 } 768 }
761 769
762 void CompositeEditCommand::removeCSSProperty(Element* element, 770 void CompositeEditCommand::removeCSSProperty(Element* element,
763 CSSPropertyID property) { 771 CSSPropertyID property) {
764 // RemoveCSSPropertyCommand is never aborted. 772 // RemoveCSSPropertyCommand is never aborted.
765 applyCommandToComposite( 773 applyCommandToComposite(
766 RemoveCSSPropertyCommand::create(document(), element, property), 774 RemoveCSSPropertyCommand::create(document(), element, property),
767 ASSERT_NO_EDITING_ABORT); 775 ASSERT_NO_EDITING_ABORT);
768 } 776 }
769 777
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 // We abort executing command since |destination| becomes invisible. 1668 // We abort executing command since |destination| becomes invisible.
1661 editingState->abort(); 1669 editingState->abort();
1662 return; 1670 return;
1663 } 1671 }
1664 setEndingSelection(destinationSelection); 1672 setEndingSelection(destinationSelection);
1665 ReplaceSelectionCommand::CommandOptions options = 1673 ReplaceSelectionCommand::CommandOptions options =
1666 ReplaceSelectionCommand::SelectReplacement | 1674 ReplaceSelectionCommand::SelectReplacement |
1667 ReplaceSelectionCommand::MovingParagraph; 1675 ReplaceSelectionCommand::MovingParagraph;
1668 if (shouldPreserveStyle == DoNotPreserveStyle) 1676 if (shouldPreserveStyle == DoNotPreserveStyle)
1669 options |= ReplaceSelectionCommand::MatchStyle; 1677 options |= ReplaceSelectionCommand::MatchStyle;
1670 applyCommandToComposite( 1678 applyCommandToComposite(ReplaceSelectionCommand::create(
1671 ReplaceSelectionCommand::create(document(), fragment, options), 1679 document(), commandSource(), fragment, options),
1672 editingState); 1680 editingState);
1673 if (editingState->isAborted()) 1681 if (editingState->isAborted())
1674 return; 1682 return;
1675 1683
1676 document().updateStyleAndLayoutIgnorePendingStylesheets(); 1684 document().updateStyleAndLayoutIgnorePendingStylesheets();
1677 1685
1678 document().frame()->spellChecker().markMisspellingsForMovingParagraphs( 1686 document().frame()->spellChecker().markMisspellingsForMovingParagraphs(
1679 endingSelection()); 1687 endingSelection());
1680 1688
1681 // If the selection is in an empty paragraph, restore styles from the old 1689 // If the selection is in an empty paragraph, restore styles from the old
1682 // empty paragraph to the new empty paragraph. 1690 // empty paragraph to the new empty paragraph.
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
2022 VisiblePosition::firstPositionInNode(parentElement); 2030 VisiblePosition::firstPositionInNode(parentElement);
2023 VisiblePosition positionInNode = 2031 VisiblePosition positionInNode =
2024 createVisiblePosition(firstPositionInOrBeforeNode(node)); 2032 createVisiblePosition(firstPositionInOrBeforeNode(node));
2025 if (positionInParent.deepEquivalent() != positionInNode.deepEquivalent()) 2033 if (positionInParent.deepEquivalent() != positionInNode.deepEquivalent())
2026 splitElement(parentElement, node); 2034 splitElement(parentElement, node);
2027 } 2035 }
2028 2036
2029 return node; 2037 return node;
2030 } 2038 }
2031 2039
2040 CommandSource CompositeEditCommand::commandSource() const {
2041 if (!parent())
2042 return m_source;
2043 return parent()->commandSource();
2044 }
2045
2032 DEFINE_TRACE(CompositeEditCommand) { 2046 DEFINE_TRACE(CompositeEditCommand) {
2033 visitor->trace(m_commands); 2047 visitor->trace(m_commands);
2034 visitor->trace(m_composition); 2048 visitor->trace(m_composition);
2035 EditCommand::trace(visitor); 2049 EditCommand::trace(visitor);
2036 } 2050 }
2037 2051
2038 } // namespace blink 2052 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698