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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 | 84 |
85 void TypingCommand::deleteKeyPressed(Document *document, bool smartDelete, TextG
ranularity granularity, bool killRing) | 85 void TypingCommand::deleteKeyPressed(Document *document, bool smartDelete, TextG
ranularity granularity, bool killRing) |
86 { | 86 { |
87 ASSERT(document); | 87 ASSERT(document); |
88 | 88 |
89 Frame* frame = document->frame(); | 89 Frame* frame = document->frame(); |
90 ASSERT(frame); | 90 ASSERT(frame); |
91 | 91 |
92 EditCommand* lastEditCommand = frame->editor()->lastEditCommand(); | 92 EditCommand* lastEditCommand = frame->editor()->lastEditCommand(); |
93 if (granularity == CharacterGranularity && isOpenForMoreTypingCommand(lastEd
itCommand)) { | 93 if (granularity == CharacterGranularity && isOpenForMoreTypingCommand(lastEd
itCommand)) { |
| 94 updateSelectionIfDifferentFromCurrentSelection(static_cast<TypingCommand
*>(lastEditCommand), frame); |
94 static_cast<TypingCommand*>(lastEditCommand)->deleteKeyPressed(granulari
ty, killRing); | 95 static_cast<TypingCommand*>(lastEditCommand)->deleteKeyPressed(granulari
ty, killRing); |
95 return; | 96 return; |
96 } | 97 } |
97 | 98 |
98 RefPtr<TypingCommand> typingCommand = TypingCommand::create(document, Delete
Key, "", false, granularity, killRing); | 99 RefPtr<TypingCommand> typingCommand = TypingCommand::create(document, Delete
Key, "", false, granularity, killRing); |
99 typingCommand->setSmartDelete(smartDelete); | 100 typingCommand->setSmartDelete(smartDelete); |
100 typingCommand->apply(); | 101 typingCommand->apply(); |
101 } | 102 } |
102 | 103 |
103 void TypingCommand::forwardDeleteKeyPressed(Document *document, bool smartDelete
, TextGranularity granularity, bool killRing) | 104 void TypingCommand::forwardDeleteKeyPressed(Document *document, bool smartDelete
, TextGranularity granularity, bool killRing) |
104 { | 105 { |
105 // FIXME: Forward delete in TextEdit appears to open and close a new typing
command. | 106 // FIXME: Forward delete in TextEdit appears to open and close a new typing
command. |
106 ASSERT(document); | 107 ASSERT(document); |
107 | 108 |
108 Frame* frame = document->frame(); | 109 Frame* frame = document->frame(); |
109 ASSERT(frame); | 110 ASSERT(frame); |
110 | 111 |
111 EditCommand* lastEditCommand = frame->editor()->lastEditCommand(); | 112 EditCommand* lastEditCommand = frame->editor()->lastEditCommand(); |
112 if (granularity == CharacterGranularity && isOpenForMoreTypingCommand(lastEd
itCommand)) { | 113 if (granularity == CharacterGranularity && isOpenForMoreTypingCommand(lastEd
itCommand)) { |
| 114 updateSelectionIfDifferentFromCurrentSelection(static_cast<TypingCommand
*>(lastEditCommand), frame); |
113 static_cast<TypingCommand*>(lastEditCommand)->forwardDeleteKeyPressed(gr
anularity, killRing); | 115 static_cast<TypingCommand*>(lastEditCommand)->forwardDeleteKeyPressed(gr
anularity, killRing); |
114 return; | 116 return; |
115 } | 117 } |
116 | 118 |
117 RefPtr<TypingCommand> typingCommand = TypingCommand::create(document, Forwar
dDeleteKey, "", false, granularity, killRing); | 119 RefPtr<TypingCommand> typingCommand = TypingCommand::create(document, Forwar
dDeleteKey, "", false, granularity, killRing); |
118 typingCommand->setSmartDelete(smartDelete); | 120 typingCommand->setSmartDelete(smartDelete); |
119 typingCommand->apply(); | 121 typingCommand->apply(); |
120 } | 122 } |
121 | 123 |
| 124 void TypingCommand::updateSelectionIfDifferentFromCurrentSelection(TypingCommand
* typingCommand, Frame* frame) |
| 125 { |
| 126 ASSERT(frame); |
| 127 VisibleSelection currentSelection = frame->selection()->selection(); |
| 128 if (currentSelection == typingCommand->endingSelection()) |
| 129 return; |
| 130 |
| 131 typingCommand->setStartingSelection(currentSelection); |
| 132 typingCommand->setEndingSelection(currentSelection); |
| 133 } |
| 134 |
| 135 |
122 void TypingCommand::insertText(Document* document, const String& text, bool sele
ctInsertedText, bool insertedTextIsComposition) | 136 void TypingCommand::insertText(Document* document, const String& text, bool sele
ctInsertedText, bool insertedTextIsComposition) |
123 { | 137 { |
124 ASSERT(document); | 138 ASSERT(document); |
125 | 139 |
126 Frame* frame = document->frame(); | 140 Frame* frame = document->frame(); |
127 ASSERT(frame); | 141 ASSERT(frame); |
128 | 142 |
129 insertText(document, text, frame->selection()->selection(), selectInsertedTe
xt, insertedTextIsComposition); | 143 insertText(document, text, frame->selection()->selection(), selectInsertedTe
xt, insertedTextIsComposition); |
130 } | 144 } |
131 | 145 |
| 146 // FIXME: We shouldn't need to take selectionForInsertion. It should be identica
l to SelectionController's current selection. |
132 void TypingCommand::insertText(Document* document, const String& text, const Vis
ibleSelection& selectionForInsertion, bool selectInsertedText, bool insertedText
IsComposition) | 147 void TypingCommand::insertText(Document* document, const String& text, const Vis
ibleSelection& selectionForInsertion, bool selectInsertedText, bool insertedText
IsComposition) |
133 { | 148 { |
134 #if REMOVE_MARKERS_UPON_EDITING | 149 #if REMOVE_MARKERS_UPON_EDITING |
135 if (!text.isEmpty()) | 150 if (!text.isEmpty()) |
136 document->frame()->editor()->removeSpellAndCorrectionMarkersFromWordsToB
eEdited(isSpaceOrNewline(text.characters()[0])); | 151 document->frame()->editor()->removeSpellAndCorrectionMarkersFromWordsToB
eEdited(isSpaceOrNewline(text.characters()[0])); |
137 #endif | 152 #endif |
138 | 153 |
139 ASSERT(document); | 154 ASSERT(document); |
140 | 155 |
141 RefPtr<Frame> frame = document->frame(); | 156 RefPtr<Frame> frame = document->frame(); |
(...skipping 14 matching lines...) Expand all Loading... |
156 | 171 |
157 if (newText.isEmpty()) | 172 if (newText.isEmpty()) |
158 return; | 173 return; |
159 | 174 |
160 // Set the starting and ending selection appropriately if we are using a sel
ection | 175 // Set the starting and ending selection appropriately if we are using a sel
ection |
161 // that is different from the current selection. In the future, we should c
hange EditCommand | 176 // that is different from the current selection. In the future, we should c
hange EditCommand |
162 // to deal with custom selections in a general way that can be used by all o
f the commands. | 177 // to deal with custom selections in a general way that can be used by all o
f the commands. |
163 RefPtr<EditCommand> lastEditCommand = frame->editor()->lastEditCommand(); | 178 RefPtr<EditCommand> lastEditCommand = frame->editor()->lastEditCommand(); |
164 if (isOpenForMoreTypingCommand(lastEditCommand.get())) { | 179 if (isOpenForMoreTypingCommand(lastEditCommand.get())) { |
165 TypingCommand* lastTypingCommand = static_cast<TypingCommand*>(lastEditC
ommand.get()); | 180 TypingCommand* lastTypingCommand = static_cast<TypingCommand*>(lastEditC
ommand.get()); |
166 if (changeSelection) { | 181 if (lastTypingCommand->endingSelection() != selectionForInsertion) { |
167 lastTypingCommand->setStartingSelection(selectionForInsertion); | 182 lastTypingCommand->setStartingSelection(selectionForInsertion); |
168 lastTypingCommand->setEndingSelection(selectionForInsertion); | 183 lastTypingCommand->setEndingSelection(selectionForInsertion); |
169 } | 184 } |
170 lastTypingCommand->insertText(newText, selectInsertedText); | 185 lastTypingCommand->insertText(newText, selectInsertedText); |
171 if (changeSelection) { | |
172 lastTypingCommand->setEndingSelection(currentSelection); | |
173 frame->selection()->setSelection(currentSelection); | |
174 } | |
175 return; | 186 return; |
176 } | 187 } |
177 | 188 |
178 RefPtr<TypingCommand> cmd = TypingCommand::create(document, InsertText, newT
ext, selectInsertedText); | 189 RefPtr<TypingCommand> cmd = TypingCommand::create(document, InsertText, newT
ext, selectInsertedText); |
179 if (changeSelection) { | 190 if (changeSelection) { |
180 cmd->setStartingSelection(selectionForInsertion); | 191 cmd->setStartingSelection(selectionForInsertion); |
181 cmd->setEndingSelection(selectionForInsertion); | 192 cmd->setEndingSelection(selectionForInsertion); |
182 } | 193 } |
183 applyCommand(cmd); | 194 applyCommand(cmd); |
184 if (changeSelection) { | 195 if (changeSelection) { |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 RefPtr<InsertTextCommand> command; | 375 RefPtr<InsertTextCommand> command; |
365 if (!document()->frame()->selection()->typingStyle() && !m_commands.isEmpty(
)) { | 376 if (!document()->frame()->selection()->typingStyle() && !m_commands.isEmpty(
)) { |
366 EditCommand* lastCommand = m_commands.last().get(); | 377 EditCommand* lastCommand = m_commands.last().get(); |
367 if (lastCommand->isInsertTextCommand()) | 378 if (lastCommand->isInsertTextCommand()) |
368 command = static_cast<InsertTextCommand*>(lastCommand); | 379 command = static_cast<InsertTextCommand*>(lastCommand); |
369 } | 380 } |
370 if (!command) { | 381 if (!command) { |
371 command = InsertTextCommand::create(document()); | 382 command = InsertTextCommand::create(document()); |
372 applyCommandToComposite(command); | 383 applyCommandToComposite(command); |
373 } | 384 } |
| 385 if (endingSelection() != command->endingSelection()) { |
| 386 command->setStartingSelection(endingSelection()); |
| 387 command->setEndingSelection(endingSelection()); |
| 388 } |
374 command->input(text, selectInsertedText); | 389 command->input(text, selectInsertedText); |
375 typingAddedToOpenCommand(InsertText); | 390 typingAddedToOpenCommand(InsertText); |
376 } | 391 } |
377 | 392 |
378 void TypingCommand::insertLineBreak() | 393 void TypingCommand::insertLineBreak() |
379 { | 394 { |
380 applyCommandToComposite(InsertLineBreakCommand::create(document())); | 395 applyCommandToComposite(InsertLineBreakCommand::create(document())); |
381 typingAddedToOpenCommand(InsertLineBreak); | 396 typingAddedToOpenCommand(InsertLineBreak); |
382 } | 397 } |
383 | 398 |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 ASSERT_NOT_REACHED(); | 642 ASSERT_NOT_REACHED(); |
628 m_preservesTypingStyle = false; | 643 m_preservesTypingStyle = false; |
629 } | 644 } |
630 | 645 |
631 bool TypingCommand::isTypingCommand() const | 646 bool TypingCommand::isTypingCommand() const |
632 { | 647 { |
633 return true; | 648 return true; |
634 } | 649 } |
635 | 650 |
636 } // namespace WebCore | 651 } // namespace WebCore |
OLD | NEW |