diff options
author | Alexandru Croitor <alexandru.croitor@qt.io> | 2016-06-10 18:08:32 +0200 |
---|---|---|
committer | Alexandru Croitor <alexandru.croitor@theqtcompany.com> | 2016-06-17 09:41:06 +0000 |
commit | 089f7968b4a730d88468211ab06208f43bb0613d (patch) | |
tree | 89fc2a0e0ee0f4856849be1d007f21a0d4c8fe79 /src | |
parent | ad568f115e9043cc0f689d2674e1df450f2631aa (diff) |
Handle IME events which contain both preedit and commit strings.
Currently if a QInputMethodEvent is received, which contains text in
both the pre-edit and commit strings, Chromium would only show the
commit string in the text input (or other html element). The IME though
still knows about the non-empty pre-edit string, which means that
if another key is pressed, Chromium will suddenly show the content of
the previous pre-edit string AND the result of the new key press.
To fix this, WebEngine will now properly set the pre-edit string as the
new composition, after confirming the previous commit string.
Change-Id: If22dd2038aca35a6fe6bb58a521f0a7124c7d468
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/render_widget_host_view_qt.cpp | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp index 15be52b97..4ba7da7fc 100644 --- a/src/core/render_widget_host_view_qt.cpp +++ b/src/core/render_widget_host_view_qt.cpp @@ -1024,6 +1024,25 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev) const QList<QInputMethodEvent::Attribute> &attributes = ev->attributes(); std::vector<blink::WebCompositionUnderline> underlines; + auto ensureValidSelectionRange = [&]() { + if (!selectionRange.IsValid()) { + // We did not receive a valid selection range, hence the range is going to mark the + // cursor position. + int newCursorPosition = + (cursorPositionInPreeditString < 0) ? preeditString.length() + : cursorPositionInPreeditString; + selectionRange.set_start(newCursorPosition); + selectionRange.set_end(newCursorPosition); + } + }; + + auto setCompositionForPreEditString = [&](){ + ensureValidSelectionRange(); + m_host->ImeSetComposition(toString16(preeditString), + underlines, + selectionRange.start(), + selectionRange.end()); + }; Q_FOREACH (const QInputMethodEvent::Attribute &attribute, attributes) { switch (attribute.type) { @@ -1053,16 +1072,19 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev) gfx::Range replacementRange = (replacementLength > 0) ? gfx::Range(replacementStart, replacementStart + replacementLength) : gfx::Range::InvalidRange(); m_host->ImeConfirmComposition(toString16(commitString), replacementRange, false); - m_imeInProgress = false; + + // We might get a commit string and a pre-edit string in a single event, which means + // we need to confirm thećlast composition, and start a new composition. + if (!preeditString.isEmpty()) { + setCompositionForPreEditString(); + m_imeInProgress = true; + } else { + m_imeInProgress = false; + } m_receivedEmptyImeText = false; + } else if (!preeditString.isEmpty()) { - if (!selectionRange.IsValid()) { - // We did not receive a valid selection range, hence the range is going to mark the cursor position. - int newCursorPosition = (cursorPositionInPreeditString < 0) ? preeditString.length() : cursorPositionInPreeditString; - selectionRange.set_start(newCursorPosition); - selectionRange.set_end(newCursorPosition); - } - m_host->ImeSetComposition(toString16(preeditString), underlines, selectionRange.start(), selectionRange.end()); + setCompositionForPreEditString(); m_imeInProgress = true; m_receivedEmptyImeText = false; } else { |