コード例 #1
0
void InputMethodController::cancelComposition()
{
    if (!hasComposition())
        return;

    Editor::RevealSelectionScope revealSelectionScope(&editor());

    if (frame().selection().isNone())
        return;

    dispatchCompositionEndEvent(frame(), emptyString());
    clear();
    insertTextForConfirmedComposition(emptyString());

    // An open typing command that disagrees about current selection would cause
    // issues with typing later on.
    TypingCommand::closeTyping(m_frame);
}
コード例 #2
0
bool InputMethodController::confirmComposition(const String& text, ConfirmCompositionBehavior confirmBehavior)
{
    if (!hasComposition())
        return false;

    Optional<Editor::RevealSelectionScope> revealSelectionScope;
    if (confirmBehavior == KeepSelection)
        revealSelectionScope.emplace(&editor());

    // If the composition was set from existing text and didn't change, then
    // there's nothing to do here (and we should avoid doing anything as that
    // may clobber multi-node styled text).
    if (!m_isDirty && composingText() == text) {
        clear();
        return true;
    }

    // Select the text that will be deleted or replaced.
    selectComposition();

    if (frame().selection().isNone())
        return false;

    dispatchCompositionEndEvent(frame(), text);

    if (!frame().document())
        return false;

    // If text is empty, then delete the old composition here. If text is
    // non-empty, InsertTextCommand::input will delete the old composition with
    // an optimized replace operation.
    if (text.isEmpty())
        TypingCommand::deleteSelection(*frame().document(), 0);

    clear();

    insertTextForConfirmedComposition(text);

    return true;
}