summaryrefslogtreecommitdiffstats
path: root/src/core/render_widget_host_view_qt.cpp
diff options
context:
space:
mode:
authorJoerg Bornemann <joerg.bornemann@theqtcompany.com>2016-02-12 10:38:44 +0100
committerJoerg Bornemann <joerg.bornemann@theqtcompany.com>2016-02-16 14:03:14 +0000
commit31efe25d14bdcf42ad15b64731314ffdad431714 (patch)
tree958f6d4d81b52eb231634957b00c2a4ad5616c09 /src/core/render_widget_host_view_qt.cpp
parentc092314bf0a4f4ab84040138366848d78a0686ad (diff)
Fix doubled characters when using IME on Windows
On Windows, when exiting the IME by pressing a cursor key or clicking into the edit field, we do not receive an QInputMethodEvent with a commitText. Instead, we get an empty QInputMethodEvent and a key{Press|Release}Event pair with a key of zero. The committed text is in the event's text property. Do not call ImeConfirmComposition for the empty QInputMethodEvent but for the later keyReleaseEvent. Do not forward those key events. Change-Id: I844aa05493aca4c388a8b1de835baf2a819558f5 Task-number: QTBUG-50252 Reviewed-by: Michael BrĂ¼ning <michael.bruning@theqtcompany.com>
Diffstat (limited to 'src/core/render_widget_host_view_qt.cpp')
-rw-r--r--src/core/render_widget_host_view_qt.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp
index 4a773bc19..b15aa94ef 100644
--- a/src/core/render_widget_host_view_qt.cpp
+++ b/src/core/render_widget_host_view_qt.cpp
@@ -253,6 +253,7 @@ RenderWidgetHostViewQt::RenderWidgetHostViewQt(content::RenderWidgetHost* widget
, m_needsDelegatedFrameAck(false)
, m_didFirstVisuallyNonEmptyLayout(false)
, m_adapterClient(0)
+ , m_imeInProgress(false)
, m_anchorPositionWithinSelection(0)
, m_cursorPositionWithinSelection(0)
, m_initPending(false)
@@ -903,6 +904,23 @@ void RenderWidgetHostViewQt::handleKeyEvent(QKeyEvent *ev)
if (IsMouseLocked() && ev->key() == Qt::Key_Escape && ev->type() == QEvent::KeyRelease)
UnlockMouse();
+ if (m_imeInProgress) {
+ // 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;
+ } else {
+ if (ev->type() == QEvent::KeyRelease) {
+ m_host->ImeConfirmComposition(toString16(ev->text()), gfx::Range::InvalidRange(),
+ false);
+ m_imeInProgress = false;
+ }
+ return;
+ }
+ }
+
content::NativeWebKeyboardEvent webEvent = WebEventFactory::toWebKeyboardEvent(ev);
if (webEvent.type == blink::WebInputEvent::RawKeyDown && !ev->text().isEmpty()) {
// Blink won't consume the RawKeyDown, but rather the Char event in this case.
@@ -959,11 +977,12 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev)
}
}
- if (preeditString.isEmpty()) {
+ if (!commitString.isEmpty()) {
gfx::Range replacementRange = (replacementLength > 0) ? gfx::Range(replacementStart, replacementStart + replacementLength)
: gfx::Range::InvalidRange();
m_host->ImeConfirmComposition(toString16(commitString), replacementRange, false);
- } else {
+ m_imeInProgress = 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;
@@ -971,6 +990,7 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev)
selectionRange.set_end(newCursorPosition);
}
m_host->ImeSetComposition(toString16(preeditString), underlines, selectionRange.start(), selectionRange.end());
+ m_imeInProgress = true;
}
}