| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2005, 2006, 2007 Apple, Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007 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 20 matching lines...) Expand all Loading... |
| 31 #include "core/editing/commands/CompositeEditCommand.h" | 31 #include "core/editing/commands/CompositeEditCommand.h" |
| 32 #include "core/frame/LocalFrame.h" | 32 #include "core/frame/LocalFrame.h" |
| 33 #include "core/layout/LayoutText.h" | 33 #include "core/layout/LayoutText.h" |
| 34 | 34 |
| 35 namespace blink { | 35 namespace blink { |
| 36 | 36 |
| 37 EditCommand::EditCommand(Document& document) | 37 EditCommand::EditCommand(Document& document) |
| 38 : m_document(&document), m_parent(nullptr) { | 38 : m_document(&document), m_parent(nullptr) { |
| 39 DCHECK(m_document); | 39 DCHECK(m_document); |
| 40 DCHECK(m_document->frame()); | 40 DCHECK(m_document->frame()); |
| 41 setStartingSelection(m_document->frame()->selection().selection()); | |
| 42 setEndingVisibleSelection(m_startingSelection); | |
| 43 } | 41 } |
| 44 | 42 |
| 45 EditCommand::~EditCommand() {} | 43 EditCommand::~EditCommand() {} |
| 46 | 44 |
| 47 InputEvent::InputType EditCommand::inputType() const { | 45 InputEvent::InputType EditCommand::inputType() const { |
| 48 return InputEvent::InputType::None; | 46 return InputEvent::InputType::None; |
| 49 } | 47 } |
| 50 | 48 |
| 51 String EditCommand::textDataForInputEvent() const { | 49 String EditCommand::textDataForInputEvent() const { |
| 52 return nullAtom; | 50 return nullAtom; |
| 53 } | 51 } |
| 54 | 52 |
| 55 static inline UndoStep* undoStepIfPossible(EditCommand* command) { | 53 // TODO(xiaochengh): Move it to CompositeEditCommand.cpp |
| 56 if (!command->isCompositeEditCommand()) | 54 void CompositeEditCommand::setStartingSelection( |
| 57 return 0; | 55 const VisibleSelection& selection) { |
| 58 return toCompositeEditCommand(command)->undoStep(); | 56 for (CompositeEditCommand* command = this;; command = command->parent()) { |
| 59 } | 57 if (UndoStep* undoStep = command->undoStep()) { |
| 60 | |
| 61 void EditCommand::setStartingSelection(const VisibleSelection& selection) { | |
| 62 for (EditCommand* command = this;; command = command->m_parent) { | |
| 63 if (UndoStep* undoStep = undoStepIfPossible(command)) { | |
| 64 DCHECK(command->isTopLevelCommand()); | 58 DCHECK(command->isTopLevelCommand()); |
| 65 undoStep->setStartingSelection(selection); | 59 undoStep->setStartingSelection(selection); |
| 66 } | 60 } |
| 67 command->m_startingSelection = selection; | 61 command->m_startingSelection = selection; |
| 68 if (!command->m_parent || command->m_parent->isFirstCommand(command)) | 62 if (!command->parent() || command->parent()->isFirstCommand(command)) |
| 69 break; | 63 break; |
| 70 } | 64 } |
| 71 } | 65 } |
| 72 | 66 |
| 67 // TODO(xiaochengh): Move it to CompositeEditCommand.cpp |
| 73 // TODO(yosin): We will make |SelectionInDOMTree| version of | 68 // TODO(yosin): We will make |SelectionInDOMTree| version of |
| 74 // |setEndingSelection()| as primary function instead of wrapper, once | 69 // |setEndingSelection()| as primary function instead of wrapper, once |
| 75 // |EditCommand| holds other than |VisibleSelection|. | 70 // |EditCommand| holds other than |VisibleSelection|. |
| 76 void EditCommand::setEndingSelection(const SelectionInDOMTree& selection) { | 71 void CompositeEditCommand::setEndingSelection( |
| 72 const SelectionInDOMTree& selection) { |
| 77 // TODO(editing-dev): The use of | 73 // TODO(editing-dev): The use of |
| 78 // updateStyleAndLayoutIgnorePendingStylesheets | 74 // updateStyleAndLayoutIgnorePendingStylesheets |
| 79 // needs to be audited. See http://crbug.com/590369 for more details. | 75 // needs to be audited. See http://crbug.com/590369 for more details. |
| 80 document().updateStyleAndLayoutIgnorePendingStylesheets(); | 76 document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 81 setEndingVisibleSelection(createVisibleSelection(selection)); | 77 setEndingVisibleSelection(createVisibleSelection(selection)); |
| 82 } | 78 } |
| 83 | 79 |
| 80 // TODO(xiaochengh): Move it to CompositeEditCommand.cpp |
| 84 // TODO(yosin): We will make |SelectionInDOMTree| version of | 81 // TODO(yosin): We will make |SelectionInDOMTree| version of |
| 85 // |setEndingSelection()| as primary function instead of wrapper. | 82 // |setEndingSelection()| as primary function instead of wrapper. |
| 86 void EditCommand::setEndingVisibleSelection(const VisibleSelection& selection) { | 83 void CompositeEditCommand::setEndingVisibleSelection( |
| 87 for (EditCommand* command = this; command; command = command->m_parent) { | 84 const VisibleSelection& selection) { |
| 88 if (UndoStep* undoStep = undoStepIfPossible(command)) { | 85 for (CompositeEditCommand* command = this; command; |
| 86 command = command->parent()) { |
| 87 if (UndoStep* undoStep = command->undoStep()) { |
| 89 DCHECK(command->isTopLevelCommand()); | 88 DCHECK(command->isTopLevelCommand()); |
| 90 undoStep->setEndingSelection(selection); | 89 undoStep->setEndingSelection(selection); |
| 91 } | 90 } |
| 92 command->m_endingSelection = selection; | 91 command->m_endingSelection = selection; |
| 93 } | 92 } |
| 94 } | 93 } |
| 95 | 94 |
| 96 bool EditCommand::isRenderedCharacter(const Position& position) { | 95 bool EditCommand::isRenderedCharacter(const Position& position) { |
| 97 if (position.isNull()) | 96 if (position.isNull()) |
| 98 return false; | 97 return false; |
| 99 DCHECK(position.isOffsetInAnchor()) << position; | 98 DCHECK(position.isOffsetInAnchor()) << position; |
| 100 if (!position.anchorNode()->isTextNode()) | 99 if (!position.anchorNode()->isTextNode()) |
| 101 return false; | 100 return false; |
| 102 | 101 |
| 103 LayoutObject* layoutObject = position.anchorNode()->layoutObject(); | 102 LayoutObject* layoutObject = position.anchorNode()->layoutObject(); |
| 104 if (!layoutObject) | 103 if (!layoutObject) |
| 105 return false; | 104 return false; |
| 106 | 105 |
| 107 return toLayoutText(layoutObject) | 106 return toLayoutText(layoutObject) |
| 108 ->isRenderedCharacter(position.offsetInContainerNode()); | 107 ->isRenderedCharacter(position.offsetInContainerNode()); |
| 109 } | 108 } |
| 110 | 109 |
| 111 void EditCommand::setParent(CompositeEditCommand* parent) { | 110 void EditCommand::setParent(CompositeEditCommand* parent) { |
| 112 DCHECK((parent && !m_parent) || (!parent && m_parent)); | 111 DCHECK((parent && !m_parent) || (!parent && m_parent)); |
| 113 DCHECK(!parent || !isCompositeEditCommand() || | 112 DCHECK(!parent || !isCompositeEditCommand() || |
| 114 !toCompositeEditCommand(this)->undoStep()); | 113 !toCompositeEditCommand(this)->undoStep()); |
| 115 m_parent = parent; | 114 m_parent = parent; |
| 115 } |
| 116 |
| 117 // TODO(xiaochengh): Move it to CompositeEditCommand.cpp |
| 118 void CompositeEditCommand::setParent(CompositeEditCommand* parent) { |
| 119 EditCommand::setParent(parent); |
| 116 if (parent) { | 120 if (parent) { |
| 117 m_startingSelection = parent->m_endingSelection; | 121 m_startingSelection = parent->m_endingSelection; |
| 118 m_endingSelection = parent->m_endingSelection; | 122 m_endingSelection = parent->m_endingSelection; |
| 119 } | 123 } |
| 120 } | 124 } |
| 121 | 125 |
| 122 void SimpleEditCommand::doReapply() { | 126 void SimpleEditCommand::doReapply() { |
| 123 EditingState editingState; | 127 EditingState editingState; |
| 124 doApply(&editingState); | 128 doApply(&editingState); |
| 125 } | 129 } |
| 126 | 130 |
| 127 DEFINE_TRACE(EditCommand) { | 131 DEFINE_TRACE(EditCommand) { |
| 128 visitor->trace(m_document); | 132 visitor->trace(m_document); |
| 129 visitor->trace(m_startingSelection); | |
| 130 visitor->trace(m_endingSelection); | |
| 131 visitor->trace(m_parent); | 133 visitor->trace(m_parent); |
| 132 } | 134 } |
| 133 | 135 |
| 134 } // namespace blink | 136 } // namespace blink |
| OLD | NEW |