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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 m_endingSelection(endingSelection), | 98 m_endingSelection(endingSelection), |
99 m_startingRootEditableElement(startingSelection.rootEditableElement()), | 99 m_startingRootEditableElement(startingSelection.rootEditableElement()), |
100 m_endingRootEditableElement(endingSelection.rootEditableElement()), | 100 m_endingRootEditableElement(endingSelection.rootEditableElement()), |
101 m_inputType(inputType) {} | 101 m_inputType(inputType) {} |
102 | 102 |
103 bool EditCommandComposition::belongsTo(const LocalFrame& frame) const { | 103 bool EditCommandComposition::belongsTo(const LocalFrame& frame) const { |
104 DCHECK(m_document); | 104 DCHECK(m_document); |
105 return m_document->frame() == &frame; | 105 return m_document->frame() == &frame; |
106 } | 106 } |
107 | 107 |
108 void EditCommandComposition::unapply() { | 108 void EditCommandComposition::unapply(EditCommandSource source) { |
109 DCHECK(m_document); | 109 DCHECK(m_document); |
110 LocalFrame* frame = m_document->frame(); | 110 LocalFrame* frame = m_document->frame(); |
111 DCHECK(frame); | 111 DCHECK(frame); |
112 | 112 |
| 113 if (!willUnapply(source)) |
| 114 return; |
| 115 |
113 // Changes to the document may have been made since the last editing operation | 116 // 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 | 117 // that require a layout, as in <rdar://problem/5658603>. Low level |
115 // operations, like RemoveNodeCommand, don't require a layout because the high | 118 // 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 | 119 // level operations that use them perform one if one is necessary (like for |
117 // the creation of VisiblePositions). | 120 // the creation of VisiblePositions). |
118 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); | 121 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); |
119 | 122 |
120 { | 123 { |
121 size_t size = m_commands.size(); | 124 size_t size = m_commands.size(); |
122 for (size_t i = size; i; --i) | 125 for (size_t i = size; i; --i) |
123 m_commands[i - 1]->doUnapply(); | 126 m_commands[i - 1]->doUnapply(); |
124 } | 127 } |
125 | 128 |
126 frame->editor().unappliedEditing(this); | 129 frame->editor().unappliedEditing(this); |
127 } | 130 } |
128 | 131 |
129 void EditCommandComposition::reapply() { | 132 void EditCommandComposition::reapply(EditCommandSource source) { |
130 DCHECK(m_document); | 133 DCHECK(m_document); |
131 LocalFrame* frame = m_document->frame(); | 134 LocalFrame* frame = m_document->frame(); |
132 DCHECK(frame); | 135 DCHECK(frame); |
133 | 136 |
| 137 if (!willReapply(source)) |
| 138 return; |
| 139 |
134 // Changes to the document may have been made since the last editing operation | 140 // Changes to the document may have been made since the last editing operation |
135 // that require a layout, as in <rdar://problem/5658603>. Low level | 141 // that require a layout, as in <rdar://problem/5658603>. Low level |
136 // operations, like RemoveNodeCommand, don't require a layout because the high | 142 // operations, like RemoveNodeCommand, don't require a layout because the high |
137 // level operations that use them perform one if one is necessary (like for | 143 // level operations that use them perform one if one is necessary (like for |
138 // the creation of VisiblePositions). | 144 // the creation of VisiblePositions). |
139 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); | 145 m_document->updateStyleAndLayoutIgnorePendingStylesheets(); |
140 | 146 |
141 { | 147 { |
142 for (const auto& command : m_commands) | 148 for (const auto& command : m_commands) |
143 command->doReapply(); | 149 command->doReapply(); |
144 } | 150 } |
145 | 151 |
146 frame->editor().reappliedEditing(this); | 152 frame->editor().reappliedEditing(this); |
147 } | 153 } |
148 | 154 |
| 155 bool EditCommandComposition::willUnapply(EditCommandSource) { |
| 156 // TODO(chongz): Fire 'beforeinput' for 'historyUndo'. |
| 157 return true; |
| 158 } |
| 159 |
| 160 bool EditCommandComposition::willReapply(EditCommandSource) { |
| 161 // TODO(chongz): Fire 'beforeinput' for 'historyRedo'. |
| 162 return true; |
| 163 } |
| 164 |
149 InputEvent::InputType EditCommandComposition::inputType() const { | 165 InputEvent::InputType EditCommandComposition::inputType() const { |
150 return m_inputType; | 166 return m_inputType; |
151 } | 167 } |
152 | 168 |
153 void EditCommandComposition::append(SimpleEditCommand* command) { | 169 void EditCommandComposition::append(SimpleEditCommand* command) { |
154 m_commands.push_back(command); | 170 m_commands.push_back(command); |
155 } | 171 } |
156 | 172 |
157 void EditCommandComposition::append(EditCommandComposition* composition) { | 173 void EditCommandComposition::append(EditCommandComposition* composition) { |
158 m_commands.appendVector(composition->m_commands); | 174 m_commands.appendVector(composition->m_commands); |
(...skipping 1878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2037 return node; | 2053 return node; |
2038 } | 2054 } |
2039 | 2055 |
2040 DEFINE_TRACE(CompositeEditCommand) { | 2056 DEFINE_TRACE(CompositeEditCommand) { |
2041 visitor->trace(m_commands); | 2057 visitor->trace(m_commands); |
2042 visitor->trace(m_composition); | 2058 visitor->trace(m_composition); |
2043 EditCommand::trace(visitor); | 2059 EditCommand::trace(visitor); |
2044 } | 2060 } |
2045 | 2061 |
2046 } // namespace blink | 2062 } // namespace blink |
OLD | NEW |