| 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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 #include "core/layout/LayoutBlock.h" | 72 #include "core/layout/LayoutBlock.h" |
| 73 #include "core/layout/LayoutListItem.h" | 73 #include "core/layout/LayoutListItem.h" |
| 74 #include "core/layout/LayoutText.h" | 74 #include "core/layout/LayoutText.h" |
| 75 #include "core/layout/line/InlineTextBox.h" | 75 #include "core/layout/line/InlineTextBox.h" |
| 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 EditCommandComposition* EditCommandComposition::create( | |
| 83 Document* document, | |
| 84 const VisibleSelection& startingSelection, | |
| 85 const VisibleSelection& endingSelection, | |
| 86 InputEvent::InputType inputType) { | |
| 87 return new EditCommandComposition(document, startingSelection, | |
| 88 endingSelection, inputType); | |
| 89 } | |
| 90 | |
| 91 EditCommandComposition::EditCommandComposition( | |
| 92 Document* document, | |
| 93 const VisibleSelection& startingSelection, | |
| 94 const VisibleSelection& endingSelection, | |
| 95 InputEvent::InputType inputType) | |
| 96 : m_document(document), | |
| 97 m_startingSelection(startingSelection), | |
| 98 m_endingSelection(endingSelection), | |
| 99 m_startingRootEditableElement(startingSelection.rootEditableElement()), | |
| 100 m_endingRootEditableElement(endingSelection.rootEditableElement()), | |
| 101 m_inputType(inputType) {} | |
| 102 | |
| 103 void EditCommandComposition::unapply() { | |
| 104 DCHECK(m_document); | |
| 105 LocalFrame* frame = m_document->frame(); | |
| 106 DCHECK(frame); | |
| 107 | |
| 108 // Changes to the document may have been made since the last editing operation | |
| 109 // that require a layout, as in <rdar://problem/5658603>. Low level | |
| 110 // operations, like RemoveNodeCommand, don't require a layout because the high | |
| 111 // level operations that use them perform one if one is necessary (like for | |
| 112 // the creation of VisiblePositions). | |
| 113 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 114 | |
| 115 { | |
| 116 size_t size = m_commands.size(); | |
| 117 for (size_t i = size; i; --i) | |
| 118 m_commands[i - 1]->doUnapply(); | |
| 119 } | |
| 120 | |
| 121 frame->editor().unappliedEditing(this); | |
| 122 } | |
| 123 | |
| 124 void EditCommandComposition::reapply() { | |
| 125 DCHECK(m_document); | |
| 126 LocalFrame* frame = m_document->frame(); | |
| 127 DCHECK(frame); | |
| 128 | |
| 129 // Changes to the document may have been made since the last editing operation | |
| 130 // that require a layout, as in <rdar://problem/5658603>. Low level | |
| 131 // operations, like RemoveNodeCommand, don't require a layout because the high | |
| 132 // level operations that use them perform one if one is necessary (like for | |
| 133 // the creation of VisiblePositions). | |
| 134 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 135 | |
| 136 { | |
| 137 for (const auto& command : m_commands) | |
| 138 command->doReapply(); | |
| 139 } | |
| 140 | |
| 141 frame->editor().reappliedEditing(this); | |
| 142 } | |
| 143 | |
| 144 InputEvent::InputType EditCommandComposition::inputType() const { | |
| 145 return m_inputType; | |
| 146 } | |
| 147 | |
| 148 void EditCommandComposition::append(SimpleEditCommand* command) { | |
| 149 m_commands.push_back(command); | |
| 150 } | |
| 151 | |
| 152 void EditCommandComposition::append(EditCommandComposition* composition) { | |
| 153 m_commands.appendVector(composition->m_commands); | |
| 154 } | |
| 155 | |
| 156 void EditCommandComposition::setStartingSelection( | |
| 157 const VisibleSelection& selection) { | |
| 158 m_startingSelection = selection; | |
| 159 m_startingRootEditableElement = selection.rootEditableElement(); | |
| 160 } | |
| 161 | |
| 162 void EditCommandComposition::setEndingSelection( | |
| 163 const VisibleSelection& selection) { | |
| 164 m_endingSelection = selection; | |
| 165 m_endingRootEditableElement = selection.rootEditableElement(); | |
| 166 } | |
| 167 | |
| 168 DEFINE_TRACE(EditCommandComposition) { | |
| 169 visitor->trace(m_document); | |
| 170 visitor->trace(m_startingSelection); | |
| 171 visitor->trace(m_endingSelection); | |
| 172 visitor->trace(m_commands); | |
| 173 visitor->trace(m_startingRootEditableElement); | |
| 174 visitor->trace(m_endingRootEditableElement); | |
| 175 UndoStep::trace(visitor); | |
| 176 } | |
| 177 | |
| 178 CompositeEditCommand::CompositeEditCommand(Document& document) | 82 CompositeEditCommand::CompositeEditCommand(Document& document) |
| 179 : EditCommand(document) {} | 83 : EditCommand(document) {} |
| 180 | 84 |
| 181 CompositeEditCommand::~CompositeEditCommand() { | 85 CompositeEditCommand::~CompositeEditCommand() { |
| 182 DCHECK(isTopLevelCommand() || !m_composition); | 86 DCHECK(isTopLevelCommand() || !m_composition); |
| 183 } | 87 } |
| 184 | 88 |
| 185 bool CompositeEditCommand::apply() { | 89 bool CompositeEditCommand::apply() { |
| 186 DCHECK(!isCommandGroupWrapper()); | 90 DCHECK(!isCommandGroupWrapper()); |
| 187 if (!endingSelection().isContentRichlyEditable()) { | 91 if (!endingSelection().isContentRichlyEditable()) { |
| (...skipping 1837 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2025 return node; | 1929 return node; |
| 2026 } | 1930 } |
| 2027 | 1931 |
| 2028 DEFINE_TRACE(CompositeEditCommand) { | 1932 DEFINE_TRACE(CompositeEditCommand) { |
| 2029 visitor->trace(m_commands); | 1933 visitor->trace(m_commands); |
| 2030 visitor->trace(m_composition); | 1934 visitor->trace(m_composition); |
| 2031 EditCommand::trace(visitor); | 1935 EditCommand::trace(visitor); |
| 2032 } | 1936 } |
| 2033 | 1937 |
| 2034 } // namespace blink | 1938 } // namespace blink |
| OLD | NEW |