Changeset 83245 in webkit


Ignore:
Timestamp:
Apr 7, 2011 8:59:34 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2011-04-07 Jia Pu <jpu@apple.com>

Reviewed by Darin Adler.

[Mac] Editor::setComposition() should not trigger correction panel timer.
https://bugs.webkit.org/show_bug.cgi?id=58049

<rdar://problem/9226305>

On Mac OS X that supports autocorrection panel, typing unconfirmed composition (i.e. unconfirmed Japanese or Chinese input)
should not start autocorrection timer. We added a member variable, m_shouldPreventSpellChecking, to TypingCommand.
When this value is true, markMisspellingsAfterTyping() will not be called in TypingCommand::typingAddedToOpenCommand().
m_shouldPreventSpellChecking is set to true in the TypingCommand objects created by Editor::setComposition().

No new tests. No deterministically reproducible test case. Patch is based on static code analysis. Testing this also requires firing
autocorrection panel timer, which can not be easily done in automated fashion.

  • editing/Editor.cpp: (WebCore::Editor::deleteWithDirection): (WebCore::Editor::insertTextWithoutSendingTextEvent): (WebCore::Editor::confirmComposition): (WebCore::Editor::setComposition):
  • editing/EditorCommand.cpp: (WebCore::executeDelete):
  • editing/TypingCommand.cpp: (WebCore::TypingCommand::TypingCommand): (WebCore::TypingCommand::deleteSelection): (WebCore::TypingCommand::deleteKeyPressed): (WebCore::TypingCommand::forwardDeleteKeyPressed): (WebCore::TypingCommand::insertText): (WebCore::TypingCommand::insertLineBreak): (WebCore::TypingCommand::insertParagraphSeparator): (WebCore::TypingCommand::typingAddedToOpenCommand):
  • editing/TypingCommand.h: (WebCore::TypingCommand::create): (WebCore::TypingCommand::setShouldPreventSpellChecking):
Location:
trunk/Source/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r83242 r83245  
     12011-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
    1372011-04-07  John Bauman  <jbauman@chromium.org>
    238
  • trunk/Source/WebCore/editing/Editor.cpp

    r83060 r83245  
    340340    if (m_frame->selection()->isRange()) {
    341341        if (isTypingAction) {
    342             TypingCommand::deleteKeyPressed(m_frame->document(), canSmartCopyOrDelete(), granularity);
     342            TypingCommand::deleteKeyPressed(m_frame->document(), canSmartCopyOrDelete() ? TypingCommand::SmartDelete : 0, granularity);
    343343            revealSelectionAfterEditingOperation();
    344344        } else {
     
    349349        }
    350350    } else {
     351        TypingCommand::Options options = 0;
     352        if (canSmartCopyOrDelete())
     353            options |= TypingCommand::SmartDelete;
     354        if (killRing)
     355            options |= TypingCommand::KillRing;
    351356        switch (direction) {
    352357        case DirectionForward:
    353358        case DirectionRight:
    354             TypingCommand::forwardDeleteKeyPressed(m_frame->document(), canSmartCopyOrDelete(), granularity, killRing);
     359            TypingCommand::forwardDeleteKeyPressed(m_frame->document(), options, granularity);
    355360            break;
    356361        case DirectionBackward:
    357362        case DirectionLeft:
    358             TypingCommand::deleteKeyPressed(m_frame->document(), canSmartCopyOrDelete(), granularity, killRing);
     363            TypingCommand::deleteKeyPressed(m_frame->document(), options, granularity);
    359364            break;
    360365        }
     
    12031208
    12041209            // Insert the text
    1205             TypingCommand::TypingCommandOptions options = 0;
     1210            TypingCommand::Options options = 0;
    12061211            if (selectInsertedText)
    12071212                options |= TypingCommand::SelectInsertedText;
     
    16301635    // will delete the old composition with an optimized replace operation.
    16311636    if (text.isEmpty())
    1632         TypingCommand::deleteSelection(m_frame->document(), false);
     1637        TypingCommand::deleteSelection(m_frame->document(), 0);
    16331638
    16341639    m_compositionNode = 0;
     
    16981703    // will delete the old composition with an optimized replace operation.
    16991704    if (text.isEmpty())
    1700         TypingCommand::deleteSelection(m_frame->document(), false);
     1705        TypingCommand::deleteSelection(m_frame->document(), TypingCommand::PreventSpellChecking);
    17011706
    17021707    m_compositionNode = 0;
     
    17041709
    17051710    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);
    17071712
    17081713        // Find out what node has the composition now.
  • trunk/Source/WebCore/editing/EditorCommand.cpp

    r82791 r83245  
    319319        // If the current selection is a caret, delete the preceding character. IE performs forwardDelete, but we currently side with Firefox.
    320320        // 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);
    322322        return true;
    323323    }
  • trunk/Source/WebCore/editing/TypingCommand.cpp

    r83026 r83245  
    6060}
    6161
    62 TypingCommand::TypingCommand(Document *document, ETypingCommand commandType, const String &textToInsert, TypingCommandOptions options, TextGranularity granularity, TextCompositionType compositionType)
     62TypingCommand::TypingCommand(Document *document, ETypingCommand commandType, const String &textToInsert, Options options, TextGranularity granularity, TextCompositionType compositionType)
    6363    : CompositeEditCommand(document)
    6464    , m_commandType(commandType)
     
    6666    , m_openForMoreTyping(true)
    6767    , m_selectInsertedText(options & SelectInsertedText)
    68     , m_smartDelete(false)
     68    , m_smartDelete(options & SmartDelete)
    6969    , m_granularity(granularity)
    7070    , m_compositionType(compositionType)
     
    7272    , m_openedByBackwardDelete(false)
    7373    , m_shouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator)
     74    , m_shouldPreventSpellChecking(options & PreventSpellChecking)
    7475{
    7576    updatePreservesTypingStyle(m_commandType);
    7677}
    7778
    78 void TypingCommand::deleteSelection(Document* document, bool smartDelete)
     79void TypingCommand::deleteSelection(Document* document, Options options)
    7980{
    8081    ASSERT(document);
     
    8889    EditCommand* lastEditCommand = frame->editor()->lastEditCommand();
    8990    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
     100void TypingCommand::deleteKeyPressed(Document *document, Options options, TextGranularity granularity)
    100101{
    101102    ASSERT(document);
     
    106107    EditCommand* lastEditCommand = frame->editor()->lastEditCommand();
    107108    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
     119void TypingCommand::forwardDeleteKeyPressed(Document *document, Options options, TextGranularity granularity)
    120120{
    121121    // FIXME: Forward delete in TextEdit appears to open and close a new typing command.
     
    127127    EditCommand* lastEditCommand = frame->editor()->lastEditCommand();
    128128    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();
    138137}
    139138
     
    149148}
    150149
    151 void TypingCommand::insertText(Document* document, const String& text, TypingCommandOptions options, TextCompositionType composition)
     150void TypingCommand::insertText(Document* document, const String& text, Options options, TextCompositionType composition)
    152151{
    153152    ASSERT(document);
     
    165164
    166165// 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)
     166void TypingCommand::insertText(Document* document, const String& text, const VisibleSelection& selectionForInsertion, Options options, TextCompositionType compositionType)
    168167{
    169168    ASSERT(document);
     
    201200        lastTypingCommand->setCompositionType(compositionType);
    202201        lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & RetainAutocorrectionIndicator);
     202        lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellChecking);
    203203        lastTypingCommand->insertText(newText, options & SelectInsertedText);
    204204        return;
     
    217217}
    218218
    219 void TypingCommand::insertLineBreak(Document *document, TypingCommandOptions options)
     219void TypingCommand::insertLineBreak(Document *document, Options options)
    220220{
    221221    ASSERT(document);
     
    251251}
    252252
    253 void TypingCommand::insertParagraphSeparator(Document *document, TypingCommandOptions options)
     253void TypingCommand::insertParagraphSeparator(Document *document, Options options)
    254254{
    255255    ASSERT(document);
     
    361361    document()->frame()->editor()->appliedEditing(this);
    362362    // 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);
    364365#else
    365366    // 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  
    4949    };
    5050
    51     enum TypingCommandOption {
     51    enum Option {
    5252        SelectInsertedText = 1 << 0,
    5353        KillRing = 1 << 1,
    54         RetainAutocorrectionIndicator = 1 << 2
     54        RetainAutocorrectionIndicator = 1 << 2,
     55        PreventSpellChecking = 1 << 3,
     56        SmartDelete = 1 << 4
    5557    };
    56     typedef unsigned TypingCommandOptions;
     58    typedef unsigned Options;
    5759
    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);
    6567    static void insertParagraphSeparatorInQuotedContent(Document*);
    6668    static bool isOpenForMoreTypingCommand(const EditCommand*);
     
    8183
    8284private:
    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)
    8486    {
    8587        return adoptRef(new TypingCommand(document, command, text, options, granularity, TextCompositionNone));
    8688    }
    8789
    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)
    8991    {
    9092        return adoptRef(new TypingCommand(document, command, text, options, CharacterGranularity, compositionType));
    9193    }
    9294
    93     TypingCommand(Document*, ETypingCommand, const String& text, TypingCommandOptions, TextGranularity, TextCompositionType);
     95    TypingCommand(Document*, ETypingCommand, const String& text, Options, TextGranularity, TextCompositionType);
    9496
    9597    bool smartDelete() const { return m_smartDelete; }
     
    102104    virtual bool shouldRetainAutocorrectionIndicator() const { return m_shouldRetainAutocorrectionIndicator; }
    103105    virtual void setShouldRetainAutocorrectionIndicator(bool retain) { m_shouldRetainAutocorrectionIndicator = retain; }
     106    void setShouldPreventSpellChecking(bool prevent) { m_shouldPreventSpellChecking = prevent; }
    104107
    105108    static void updateSelectionIfDifferentFromCurrentSelection(TypingCommand*, Frame*);
     
    126129
    127130    bool m_shouldRetainAutocorrectionIndicator;
     131    bool m_shouldPreventSpellChecking;
    128132};
    129133
Note: See TracChangeset for help on using the changeset viewer.