From f234f248fa8f0d2bb74a14f5ee3cb489f256c0f2 Mon Sep 17 00:00:00 2001 From: axis Date: Fri, 19 Nov 2010 11:15:55 +0100 Subject: Fixed handling of QInputMethodEvents with nonzero replacementLength. These types of events replace text that is already in the widget, but WebKit did not check for replacementLength at all. RevBy: Janne Koskinen Task: QT-4303 Task: https://bugs.webkit.org/show_bug.cgi?id=49787 AutoTest: Included --- src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp | 10 ++++++++-- .../webkit/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp | 14 ++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp b/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp index ff92f0b..d9a2cbe 100644 --- a/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp +++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp @@ -1257,9 +1257,15 @@ void QWebPagePrivate::inputMethodEvent(QInputMethodEvent *ev) } } - if (!ev->commitString().isEmpty()) + if (renderTextControl && ev->replacementLength() > 0) { + renderTextControl->setSelectionStart(qMax(renderTextControl->selectionStart() + ev->replacementStart(), 0)); + renderTextControl->setSelectionEnd(qMin(renderTextControl->selectionStart() + ev->replacementLength(), static_cast(renderTextControl->text().length()))); + // Commit regardless of whether commitString is empty, to get rid of selection. editor->confirmComposition(ev->commitString()); - else if (!ev->preeditString().isEmpty()) { + } else if (!ev->commitString().isEmpty()) { + editor->confirmComposition(ev->commitString()); + } + if (!ev->preeditString().isEmpty()) { QString preedit = ev->preeditString(); editor->setComposition(preedit, underlines, preedit.length(), 0); } diff --git a/src/3rdparty/webkit/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp b/src/3rdparty/webkit/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp index 55ee42a..b566365 100644 --- a/src/3rdparty/webkit/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp +++ b/src/3rdparty/webkit/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp @@ -1494,6 +1494,20 @@ void tst_QWebPage::inputMethods() QCOMPARE(value, QString("QtWebKit")); #endif + { + QList attributes; + QInputMethodEvent event(QString(), attributes); + event.setCommitString("XXX", 0, 0); + page->event(&event); + event.setCommitString(QString(), -2, 2); // Erase two characters. + page->event(&event); + event.setCommitString(QString(), -1, 1); // Erase one character. + page->event(&event); + variant = page->inputMethodQuery(Qt::ImSurroundingText); + value = variant.value(); + QCOMPARE(value, QString("QtWebKit")); + } + //ImhHiddenText QMouseEvent evpresPassword(QEvent::MouseButtonPress, inputs.at(1).geometry().center(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier); page->event(&evpresPassword); -- cgit v0.12