summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2016-06-10 11:46:05 +0200
committerAlexandru Croitor <alexandru.croitor@theqtcompany.com>2016-06-17 09:41:04 +0000
commitad568f115e9043cc0f689d2674e1df450f2631aa (patch)
treece685a0bfd04cfb29ba631d37974d11fdbb0dc03 /src
parentafc9e2d9674f7ab5800df4803cc68c71d1ae691a (diff)
Fix backspace to work when removing last IME char.
Currently when composing a word using an IME, and backspace is pressed to remove the last character present in the pre-edit string, instead of the character being removed, nothing happens. In reality the character is removed, but Chromium isn't notified of it, and the change will be seen only after another key is pressed. Fix consists in notifying Chromium to cancel the IME composition when both the pre-edit string and the commit string are empty. There is still an issue with japanese, when trying to input "aaa", press space, then "b" and you don't see the "b" until you press one more key. Change-Id: Idf2ef4888caead26d19eabbbdf4f98fbee601049 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/core/render_widget_host_view_qt.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp
index ef7367e06..15be52b97 100644
--- a/src/core/render_widget_host_view_qt.cpp
+++ b/src/core/render_widget_host_view_qt.cpp
@@ -975,15 +975,16 @@ void RenderWidgetHostViewQt::handleKeyEvent(QKeyEvent *ev)
if (IsMouseLocked() && ev->key() == Qt::Key_Escape && ev->type() == QEvent::KeyRelease)
UnlockMouse();
- if (m_imeInProgress && m_receivedEmptyImeText) {
+ if (m_receivedEmptyImeText) {
// IME composition was not finished with a valid commit string.
// We're getting the composition result in a key event.
if (ev->key() != 0) {
// The key event is not a result of an IME composition. Cancel IME.
m_host->ImeCancelComposition();
- m_imeInProgress = false;
+ m_receivedEmptyImeText = false;
} else {
if (ev->type() == QEvent::KeyRelease) {
+ m_receivedEmptyImeText = false;
m_host->ImeConfirmComposition(toString16(ev->text()), gfx::Range::InvalidRange(),
false);
m_imeInProgress = false;
@@ -1065,7 +1066,26 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev)
m_imeInProgress = true;
m_receivedEmptyImeText = false;
} else {
- m_receivedEmptyImeText = true;
+ // There are so-far two known cases, when an empty QInputMethodEvent is received.
+ // First one happens when backspace is used to remove the last character in the pre-edit
+ // string, thus signaling the end of the composition.
+ // The second one happens (on Windows) when a Korean char gets composed, but instead of
+ // the event having a commit string, both strings are empty, and the actual char is received
+ // as a QKeyEvent after the QInputMethodEvent is processed.
+ // In lieu of the second case, we can't simply cancel the composition on an empty event,
+ // and then add the Korean char when QKeyEvent is received, because that leads to text
+ // flickering in the textarea (or any other element).
+ // Instead we postpone the processing of the empty QInputMethodEvent by posting it
+ // to the same focused object, and cancelling the composition on the next event loop tick.
+ if (!m_receivedEmptyImeText && m_imeInProgress) {
+ m_receivedEmptyImeText = true;
+ m_imeInProgress = false;
+ QInputMethodEvent *eventCopy = new QInputMethodEvent(*ev);
+ QGuiApplication::postEvent(qApp->focusObject(), eventCopy);
+ } else {
+ m_receivedEmptyImeText = false;
+ m_host->ImeCancelComposition();
+ }
}
}