2010-11-24 Kristian Amlie <kristian.amlie@nokia.com>
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Nov 2010 21:29:28 +0000 (21:29 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 24 Nov 2010 21:29:28 +0000 (21:29 +0000)
        Reviewed by Andreas Kling.

        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.

        https://bugs.webkit.org/show_bug.cgi?id=49787

        * Api/qwebpage.cpp:
        (QWebPagePrivate::inputMethodEvent):
        * tests/qwebpage/tst_qwebpage.cpp:
        (tst_QWebPage::inputMethods):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@72697 268f45cc-cd09-0410-ab3c-d52691b4dbfc

WebKit/qt/Api/qwebpage.cpp
WebKit/qt/ChangeLog
WebKit/qt/tests/qwebpage/tst_qwebpage.cpp

index e00b4c64d4a5174a415ab9533229d4c6afe9ba3f..94ed62aa78af419924243d8fb128f999f20b9d1a 100644 (file)
@@ -1080,7 +1080,13 @@ void QWebPagePrivate::inputMethodEvent(QInputMethodEvent *ev)
         }
     }
 
-    if (!ev->commitString().isEmpty())
+    if (node && ev->replacementLength() > 0) {
+        int cursorPos = frame->selection()->extent().offsetInContainerNode();
+        int start = cursorPos + ev->replacementStart();
+        setSelectionRange(node, start, start + ev->replacementLength());
+        // Commit regardless of whether commitString is empty, to get rid of selection.
+        editor->confirmComposition(ev->commitString());
+    } else if (!ev->commitString().isEmpty())
         editor->confirmComposition(ev->commitString());
     else if (!hasSelection && !ev->preeditString().isEmpty())
         editor->setComposition(ev->preeditString(), underlines, 0, 0);
index 993f0e09b1da89f49c6855b212d6e28ecca52b54..42faf2e9ef0285055767996f4efe06b25e51cbb7 100644 (file)
@@ -1,3 +1,19 @@
+2010-11-24  Kristian Amlie  <kristian.amlie@nokia.com>
+
+        Reviewed by Andreas Kling.
+
+        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.
+
+        https://bugs.webkit.org/show_bug.cgi?id=49787
+
+        * Api/qwebpage.cpp:
+        (QWebPagePrivate::inputMethodEvent):
+        * tests/qwebpage/tst_qwebpage.cpp:
+        (tst_QWebPage::inputMethods):
+
 2010-11-24  Andras Becsi  <abecsi@inf.u-szeged.hu>
 
         Reviewed by Kenneth Rohde Christiansen.
index 27a36c3320bcc0add6deaf157ae399a38f62980c..c27ba022ab4e3ddae8626eae694c9fcdb39bb9e6 100644 (file)
@@ -1568,6 +1568,20 @@ void tst_QWebPage::inputMethods()
     page->event(&evpres);
     page->event(&evrel);
 
+    {
+        QList<QInputMethodEvent::Attribute> 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<QString>();
+        QCOMPARE(value, QString("QtWebKit"));
+    }
+
     //Move to the start of the line
     page->triggerAction(QWebPage::MoveToStartOfLine);