Changeset 83245 in webkit
- Timestamp:
- Apr 7, 2011 8:59:34 PM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r83242 r83245 1 2011-04-07 Jia Pu <jpu@apple.com> 2 3 Reviewed by Darin Adler. 4 5 [Mac] Editor::setComposition() should not trigger correction panel timer. 6 https://bugs.webkit.org/show_bug.cgi?id=58049 7 <rdar://problem/9226305> 8 9 On Mac OS X that supports autocorrection panel, typing unconfirmed composition (i.e. unconfirmed Japanese or Chinese input) 10 should not start autocorrection timer. We added a member variable, m_shouldPreventSpellChecking, to TypingCommand. 11 When this value is true, markMisspellingsAfterTyping() will not be called in TypingCommand::typingAddedToOpenCommand(). 12 m_shouldPreventSpellChecking is set to true in the TypingCommand objects created by Editor::setComposition(). 13 14 No new tests. No deterministically reproducible test case. Patch is based on static code analysis. Testing this also requires firing 15 autocorrection panel timer, which can not be easily done in automated fashion. 16 17 * editing/Editor.cpp: 18 (WebCore::Editor::deleteWithDirection): 19 (WebCore::Editor::insertTextWithoutSendingTextEvent): 20 (WebCore::Editor::confirmComposition): 21 (WebCore::Editor::setComposition): 22 * editing/EditorCommand.cpp: 23 (WebCore::executeDelete): 24 * editing/TypingCommand.cpp: 25 (WebCore::TypingCommand::TypingCommand): 26 (WebCore::TypingCommand::deleteSelection): 27 (WebCore::TypingCommand::deleteKeyPressed): 28 (WebCore::TypingCommand::forwardDeleteKeyPressed): 29 (WebCore::TypingCommand::insertText): 30 (WebCore::TypingCommand::insertLineBreak): 31 (WebCore::TypingCommand::insertParagraphSeparator): 32 (WebCore::TypingCommand::typingAddedToOpenCommand): 33 * editing/TypingCommand.h: 34 (WebCore::TypingCommand::create): 35 (WebCore::TypingCommand::setShouldPreventSpellChecking): 36 1 37 2011-04-07 John Bauman <jbauman@chromium.org> 2 38 -
trunk/Source/WebCore/editing/Editor.cpp
r83060 r83245 340 340 if (m_frame->selection()->isRange()) { 341 341 if (isTypingAction) { 342 TypingCommand::deleteKeyPressed(m_frame->document(), canSmartCopyOrDelete() , granularity);342 TypingCommand::deleteKeyPressed(m_frame->document(), canSmartCopyOrDelete() ? TypingCommand::SmartDelete : 0, granularity); 343 343 revealSelectionAfterEditingOperation(); 344 344 } else { … … 349 349 } 350 350 } else { 351 TypingCommand::Options options = 0; 352 if (canSmartCopyOrDelete()) 353 options |= TypingCommand::SmartDelete; 354 if (killRing) 355 options |= TypingCommand::KillRing; 351 356 switch (direction) { 352 357 case DirectionForward: 353 358 case DirectionRight: 354 TypingCommand::forwardDeleteKeyPressed(m_frame->document(), canSmartCopyOrDelete(), granularity, killRing);359 TypingCommand::forwardDeleteKeyPressed(m_frame->document(), options, granularity); 355 360 break; 356 361 case DirectionBackward: 357 362 case DirectionLeft: 358 TypingCommand::deleteKeyPressed(m_frame->document(), canSmartCopyOrDelete(), granularity, killRing);363 TypingCommand::deleteKeyPressed(m_frame->document(), options, granularity); 359 364 break; 360 365 } … … 1203 1208 1204 1209 // Insert the text 1205 TypingCommand:: TypingCommandOptions options = 0;1210 TypingCommand::Options options = 0; 1206 1211 if (selectInsertedText) 1207 1212 options |= TypingCommand::SelectInsertedText; … … 1630 1635 // will delete the old composition with an optimized replace operation. 1631 1636 if (text.isEmpty()) 1632 TypingCommand::deleteSelection(m_frame->document(), false);1637 TypingCommand::deleteSelection(m_frame->document(), 0); 1633 1638 1634 1639 m_compositionNode = 0; … … 1698 1703 // will delete the old composition with an optimized replace operation. 1699 1704 if (text.isEmpty()) 1700 TypingCommand::deleteSelection(m_frame->document(), false);1705 TypingCommand::deleteSelection(m_frame->document(), TypingCommand::PreventSpellChecking); 1701 1706 1702 1707 m_compositionNode = 0; … … 1704 1709 1705 1710 if (!text.isEmpty()) { 1706 TypingCommand::insertText(m_frame->document(), text, true, TypingCommand::TextCompositionUpdate);1711 TypingCommand::insertText(m_frame->document(), text, TypingCommand::SelectInsertedText | TypingCommand::PreventSpellChecking, TypingCommand::TextCompositionUpdate); 1707 1712 1708 1713 // Find out what node has the composition now. -
trunk/Source/WebCore/editing/EditorCommand.cpp
r82791 r83245 319 319 // If the current selection is a caret, delete the preceding character. IE performs forwardDelete, but we currently side with Firefox. 320 320 // Doesn't scroll to make the selection visible, or modify the kill ring (this time, siding with IE, not Firefox). 321 TypingCommand::deleteKeyPressed(frame->document(), frame->selection()->granularity() == WordGranularity );321 TypingCommand::deleteKeyPressed(frame->document(), frame->selection()->granularity() == WordGranularity ? TypingCommand::SmartDelete : 0); 322 322 return true; 323 323 } -
trunk/Source/WebCore/editing/TypingCommand.cpp
r83026 r83245 60 60 } 61 61 62 TypingCommand::TypingCommand(Document *document, ETypingCommand commandType, const String &textToInsert, TypingCommandOptions options, TextGranularity granularity, TextCompositionType compositionType)62 TypingCommand::TypingCommand(Document *document, ETypingCommand commandType, const String &textToInsert, Options options, TextGranularity granularity, TextCompositionType compositionType) 63 63 : CompositeEditCommand(document) 64 64 , m_commandType(commandType) … … 66 66 , m_openForMoreTyping(true) 67 67 , m_selectInsertedText(options & SelectInsertedText) 68 , m_smartDelete( false)68 , m_smartDelete(options & SmartDelete) 69 69 , m_granularity(granularity) 70 70 , m_compositionType(compositionType) … … 72 72 , m_openedByBackwardDelete(false) 73 73 , m_shouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator) 74 , m_shouldPreventSpellChecking(options & PreventSpellChecking) 74 75 { 75 76 updatePreservesTypingStyle(m_commandType); 76 77 } 77 78 78 void TypingCommand::deleteSelection(Document* document, bool smartDelete)79 void TypingCommand::deleteSelection(Document* document, Options options) 79 80 { 80 81 ASSERT(document); … … 88 89 EditCommand* lastEditCommand = frame->editor()->lastEditCommand(); 89 90 if (isOpenForMoreTypingCommand(lastEditCommand)) { 90 static_cast<TypingCommand*>(lastEditCommand)->deleteSelection(smartDelete);91 return;92 }93 94 RefPtr<TypingCommand> typingCommand = TypingCommand::create(document, DeleteSelection, "", 0);95 typingCommand->setSmartDelete(smartDelete); 96 typingCommand->apply();97 } 98 99 void TypingCommand::deleteKeyPressed(Document *document, bool smartDelete, TextGranularity granularity, bool killRing)91 TypingCommand* lastTypingCommand = static_cast<TypingCommand*>(lastEditCommand); 92 lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking); 93 lastTypingCommand->deleteSelection(options & SmartDelete); 94 return; 95 } 96 97 TypingCommand::create(document, DeleteSelection, "", options)->apply(); 98 } 99 100 void TypingCommand::deleteKeyPressed(Document *document, Options options, TextGranularity granularity) 100 101 { 101 102 ASSERT(document); … … 106 107 EditCommand* lastEditCommand = frame->editor()->lastEditCommand(); 107 108 if (granularity == CharacterGranularity && isOpenForMoreTypingCommand(lastEditCommand)) { 108 updateSelectionIfDifferentFromCurrentSelection(static_cast<TypingCommand*>(lastEditCommand), frame); 109 static_cast<TypingCommand*>(lastEditCommand)->deleteKeyPressed(granularity, killRing); 110 return; 111 } 112 113 TypingCommandOptions options = killRing ? KillRing : 0; 114 RefPtr<TypingCommand> typingCommand = TypingCommand::create(document, DeleteKey, "", options, granularity); 115 typingCommand->setSmartDelete(smartDelete); 116 typingCommand->apply(); 117 } 118 119 void TypingCommand::forwardDeleteKeyPressed(Document *document, bool smartDelete, TextGranularity granularity, bool killRing) 109 TypingCommand* lastTypingCommand = static_cast<TypingCommand*>(lastEditCommand); 110 updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand, frame); 111 lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking); 112 lastTypingCommand->deleteKeyPressed(granularity, options & KillRing); 113 return; 114 } 115 116 TypingCommand::create(document, DeleteKey, "", options, granularity)->apply(); 117 } 118 119 void TypingCommand::forwardDeleteKeyPressed(Document *document, Options options, TextGranularity granularity) 120 120 { 121 121 // FIXME: Forward delete in TextEdit appears to open and close a new typing command. … … 127 127 EditCommand* lastEditCommand = frame->editor()->lastEditCommand(); 128 128 if (granularity == CharacterGranularity && isOpenForMoreTypingCommand(lastEditCommand)) { 129 updateSelectionIfDifferentFromCurrentSelection(static_cast<TypingCommand*>(lastEditCommand), frame); 130 static_cast<TypingCommand*>(lastEditCommand)->forwardDeleteKeyPressed(granularity, killRing); 131 return; 132 } 133 134 TypingCommandOptions options = killRing ? KillRing : 0; 135 RefPtr<TypingCommand> typingCommand = TypingCommand::create(document, ForwardDeleteKey, "", options, granularity); 136 typingCommand->setSmartDelete(smartDelete); 137 typingCommand->apply(); 129 TypingCommand* lastTypingCommand = static_cast<TypingCommand*>(lastEditCommand); 130 updateSelectionIfDifferentFromCurrentSelection(lastTypingCommand, frame); 131 lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking); 132 lastTypingCommand->forwardDeleteKeyPressed(granularity, options & KillRing); 133 return; 134 } 135 136 TypingCommand::create(document, ForwardDeleteKey, "", options, granularity)->apply(); 138 137 } 139 138 … … 149 148 } 150 149 151 void TypingCommand::insertText(Document* document, const String& text, TypingCommandOptions options, TextCompositionType composition)150 void TypingCommand::insertText(Document* document, const String& text, Options options, TextCompositionType composition) 152 151 { 153 152 ASSERT(document); … … 165 164 166 165 // FIXME: We shouldn't need to take selectionForInsertion. It should be identical to SelectionController's current selection. 167 void TypingCommand::insertText(Document* document, const String& text, const VisibleSelection& selectionForInsertion, TypingCommandOptions options, TextCompositionType compositionType)166 void TypingCommand::insertText(Document* document, const String& text, const VisibleSelection& selectionForInsertion, Options options, TextCompositionType compositionType) 168 167 { 169 168 ASSERT(document); … … 201 200 lastTypingCommand->setCompositionType(compositionType); 202 201 lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator); 202 lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking); 203 203 lastTypingCommand->insertText(newText, options & SelectInsertedText); 204 204 return; … … 217 217 } 218 218 219 void TypingCommand::insertLineBreak(Document *document, TypingCommandOptions options)219 void TypingCommand::insertLineBreak(Document *document, Options options) 220 220 { 221 221 ASSERT(document); … … 251 251 } 252 252 253 void TypingCommand::insertParagraphSeparator(Document *document, TypingCommandOptions options)253 void TypingCommand::insertParagraphSeparator(Document *document, Options options) 254 254 { 255 255 ASSERT(document); … … 361 361 document()->frame()->editor()->appliedEditing(this); 362 362 // Since the spellchecking code may also perform corrections and other replacements, it should happen after the typing changes. 363 markMisspellingsAfterTyping(commandTypeForAddedTyping); 363 if (!m_shouldPreventSpellChecking) 364 markMisspellingsAfterTyping(commandTypeForAddedTyping); 364 365 #else 365 366 // The old spellchecking code requires that checking be done first, to prevent issues like that in 6864072, where <doesn't> is marked as misspelled. -
trunk/Source/WebCore/editing/TypingCommand.h
r80023 r83245 49 49 }; 50 50 51 enum TypingCommandOption {51 enum Option { 52 52 SelectInsertedText = 1 << 0, 53 53 KillRing = 1 << 1, 54 RetainAutocorrectionIndicator = 1 << 2 54 RetainAutocorrectionIndicator = 1 << 2, 55 PreventSpellChecking = 1 << 3, 56 SmartDelete = 1 << 4 55 57 }; 56 typedef unsigned TypingCommandOptions;58 typedef unsigned Options; 57 59 58 static void deleteSelection(Document*, bool smartDelete = false);59 static void deleteKeyPressed(Document*, bool smartDelete = false, TextGranularity = CharacterGranularity, bool killRing = false);60 static void forwardDeleteKeyPressed(Document*, bool smartDelete = false, TextGranularity = CharacterGranularity, bool killRing = false);61 static void insertText(Document*, const String&, TypingCommandOptions, TextCompositionType = TextCompositionNone);62 static void insertText(Document*, const String&, const VisibleSelection&, TypingCommandOptions, TextCompositionType = TextCompositionNone);63 static void insertLineBreak(Document*, TypingCommandOptions);64 static void insertParagraphSeparator(Document*, TypingCommandOptions);60 static void deleteSelection(Document*, Options = 0); 61 static void deleteKeyPressed(Document*, Options = 0, TextGranularity = CharacterGranularity); 62 static void forwardDeleteKeyPressed(Document*, Options = 0, TextGranularity = CharacterGranularity); 63 static void insertText(Document*, const String&, Options, TextCompositionType = TextCompositionNone); 64 static void insertText(Document*, const String&, const VisibleSelection&, Options, TextCompositionType = TextCompositionNone); 65 static void insertLineBreak(Document*, Options); 66 static void insertParagraphSeparator(Document*, Options); 65 67 static void insertParagraphSeparatorInQuotedContent(Document*); 66 68 static bool isOpenForMoreTypingCommand(const EditCommand*); … … 81 83 82 84 private: 83 static PassRefPtr<TypingCommand> create(Document* document, ETypingCommand command, const String& text = "", TypingCommandOptions options = 0, TextGranularity granularity = CharacterGranularity)85 static PassRefPtr<TypingCommand> create(Document* document, ETypingCommand command, const String& text = "", Options options = 0, TextGranularity granularity = CharacterGranularity) 84 86 { 85 87 return adoptRef(new TypingCommand(document, command, text, options, granularity, TextCompositionNone)); 86 88 } 87 89 88 static PassRefPtr<TypingCommand> create(Document* document, ETypingCommand command, const String& text, TypingCommandOptions options, TextCompositionType compositionType)90 static PassRefPtr<TypingCommand> create(Document* document, ETypingCommand command, const String& text, Options options, TextCompositionType compositionType) 89 91 { 90 92 return adoptRef(new TypingCommand(document, command, text, options, CharacterGranularity, compositionType)); 91 93 } 92 94 93 TypingCommand(Document*, ETypingCommand, const String& text, TypingCommandOptions, TextGranularity, TextCompositionType);95 TypingCommand(Document*, ETypingCommand, const String& text, Options, TextGranularity, TextCompositionType); 94 96 95 97 bool smartDelete() const { return m_smartDelete; } … … 102 104 virtual bool shouldRetainAutocorrectionIndicator() const { return m_shouldRetainAutocorrectionIndicator; } 103 105 virtual void setShouldRetainAutocorrectionIndicator(bool retain) { m_shouldRetainAutocorrectionIndicator = retain; } 106 void setShouldPreventSpellChecking(bool prevent) { m_shouldPreventSpellChecking = prevent; } 104 107 105 108 static void updateSelectionIfDifferentFromCurrentSelection(TypingCommand*, Frame*); … … 126 129 127 130 bool m_shouldRetainAutocorrectionIndicator; 131 bool m_shouldPreventSpellChecking; 128 132 }; 129 133
Note: See TracChangeset
for help on using the changeset viewer.