summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@nokia.com>2009-10-01 12:43:40 (GMT)
committerSimon Hausmann <simon.hausmann@nokia.com>2009-10-01 12:49:15 (GMT)
commit976adc629192d42882eeba33d5b398618d4445b1 (patch)
tree6bb705cbf1895252e0e37f131e2bf70294668385
parentd2d4fa3365beecc6fe1dca7bcffb8a9167fa991d (diff)
downloadQt-976adc629192d42882eeba33d5b398618d4445b1.zip
Qt-976adc629192d42882eeba33d5b398618d4445b1.tar.gz
Qt-976adc629192d42882eeba33d5b398618d4445b1.tar.bz2
Implementation for QWebPage::inputMethodQuery and QWebPagePrivate::inputMethodEvent
Patch by Joe Ligman <joseph.ligman@nokia.com> on 2009-10-01 Reviewed by Simon Hausmann. https://bugs.webkit.org/show_bug.cgi?id=29681 Some additional changes from axis: * Fixed surrounding text to exclude preedit string * Avoid emission of microFocusChanged during setComposition() * Api/qwebpage.cpp: (QWebPagePrivate::inputMethodEvent): (QWebPage::inputMethodQuery): * WebCoreSupport/EditorClientQt.cpp: (WebCore::EditorClientQt::respondToChangedSelection): * tests/qwebpage/tst_qwebpage.cpp: (tst_QWebPage::inputMethods): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48967 268f45cc-cd09-0410-ab3c-d52691b4dbfc Signed-off-by: Simon Hausmann <simon.hausmann@nokia.com>
-rw-r--r--src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp163
-rw-r--r--src/3rdparty/webkit/WebKit/qt/ChangeLog21
-rw-r--r--src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditorClientQt.cpp4
-rw-r--r--src/3rdparty/webkit/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp90
4 files changed, 242 insertions, 36 deletions
diff --git a/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp b/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp
index 4b6248a..000b895 100644
--- a/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp
+++ b/src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp
@@ -66,8 +66,12 @@
#include "PluginDatabase.h"
#include "ProgressTracker.h"
#include "RefPtr.h"
+#include "RenderTextControl.h"
+#include "TextIterator.h"
#include "HashMap.h"
#include "HTMLFormElement.h"
+#include "HTMLInputElement.h"
+#include "HTMLNames.h"
#include "HitTestResult.h"
#include "WindowFeatures.h"
#include "LocalizedStrings.h"
@@ -95,6 +99,7 @@
#include <QSslSocket>
#include <QStyle>
#include <QSysInfo>
+#include <QTextCharFormat>
#if QT_VERSION >= 0x040400
#include <QNetworkAccessManager>
#include <QNetworkRequest>
@@ -1087,13 +1092,53 @@ void QWebPagePrivate::inputMethodEvent(QInputMethodEvent *ev)
return;
}
+ RenderObject* renderer = 0;
+ RenderTextControl* renderTextControl = 0;
+
+ if (frame->selection()->rootEditableElement())
+ renderer = frame->selection()->rootEditableElement()->shadowAncestorNode()->renderer();
+
+ if (renderer && renderer->isTextControl())
+ renderTextControl = toRenderTextControl(renderer);
+
+ Vector<CompositionUnderline> underlines;
+
+ for (int i = 0; i < ev->attributes().size(); ++i) {
+ const QInputMethodEvent::Attribute& a = ev->attributes().at(i);
+ switch (a.type) {
+ case QInputMethodEvent::TextFormat: {
+ QTextCharFormat textCharFormat = a.value.value<QTextFormat>().toCharFormat();
+ QColor qcolor = textCharFormat.underlineColor();
+ underlines.append(CompositionUnderline(a.start, a.length, Color(makeRGBA(qcolor.red(), qcolor.green(), qcolor.blue(), qcolor.alpha())), false));
+ break;
+ }
+ case QInputMethodEvent::Cursor: {
+ frame->setCaretVisible(a.length); //if length is 0 cursor is invisible
+ if (a.length > 0) {
+ RenderObject* caretRenderer = frame->selection()->caretRenderer();
+ if (caretRenderer) {
+ QColor qcolor = a.value.value<QColor>();
+ caretRenderer->style()->setColor(Color(makeRGBA(qcolor.red(), qcolor.green(), qcolor.blue(), qcolor.alpha())));
+ }
+ }
+ break;
+ }
+#if QT_VERSION >= 0x040600
+ case QInputMethodEvent::Selection: {
+ if (renderTextControl) {
+ renderTextControl->setSelectionStart(a.start);
+ renderTextControl->setSelectionEnd(a.start + a.length);
+ }
+ break;
+ }
+#endif
+ }
+ }
+
if (!ev->commitString().isEmpty())
editor->confirmComposition(ev->commitString());
- else {
+ else if (!ev->preeditString().isEmpty()) {
QString preedit = ev->preeditString();
- // ### FIXME: use the provided QTextCharFormat (use color at least)
- Vector<CompositionUnderline> underlines;
- underlines.append(CompositionUnderline(0, preedit.length(), Color(0, 0, 0), false));
editor->setComposition(preedit, underlines, preedit.length(), 0);
}
ev->accept();
@@ -1196,41 +1241,89 @@ bool QWebPagePrivate::handleScrolling(QKeyEvent *ev, Frame *frame)
*/
QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const
{
+ Frame* frame = d->page->focusController()->focusedFrame();
+ if (!frame)
+ return QVariant();
+
+ WebCore::Editor* editor = frame->editor();
+
+ RenderObject* renderer = 0;
+ RenderTextControl* renderTextControl = 0;
+
+ if (frame->selection()->rootEditableElement())
+ renderer = frame->selection()->rootEditableElement()->shadowAncestorNode()->renderer();
+
+ if (renderer && renderer->isTextControl())
+ renderTextControl = toRenderTextControl(renderer);
+
switch (property) {
- case Qt::ImMicroFocus: {
- Frame *frame = d->page->focusController()->focusedFrame();
- if (frame)
+ case Qt::ImMicroFocus: {
return QVariant(frame->selection()->absoluteCaretBounds());
- return QVariant();
- }
- case Qt::ImFont: {
- QWebView *webView = qobject_cast<QWebView *>(d->view);
- if (webView)
- return QVariant(webView->font());
- return QVariant();
- }
- case Qt::ImCursorPosition: {
- Frame *frame = d->page->focusController()->focusedFrame();
- if (frame) {
- VisibleSelection selection = frame->selection()->selection();
- if (selection.isCaret())
- return QVariant(selection.start().deprecatedEditingOffset());
}
- return QVariant();
- }
- case Qt::ImSurroundingText: {
- Frame *frame = d->page->focusController()->focusedFrame();
- if (frame) {
- Document *document = frame->document();
- if (document->focusedNode())
- return QVariant(document->focusedNode()->nodeValue());
+ case Qt::ImFont: {
+ if (renderTextControl) {
+ RenderStyle* renderStyle = renderTextControl->style();
+ return QVariant(QFont(renderStyle->font().font()));
+ }
+ return QVariant(QFont());
}
- return QVariant();
- }
- case Qt::ImCurrentSelection:
- return QVariant(selectedText());
- default:
- return QVariant();
+ case Qt::ImCursorPosition: {
+ if (renderTextControl) {
+ if (editor->hasComposition()) {
+ RefPtr<Range> range = editor->compositionRange();
+ return QVariant(renderTextControl->selectionEnd() - TextIterator::rangeLength(range.get()));
+ }
+ return QVariant(renderTextControl->selectionEnd());
+ }
+ return QVariant();
+ }
+ case Qt::ImSurroundingText: {
+ if (renderTextControl) {
+ QString text = renderTextControl->text();
+ RefPtr<Range> range = editor->compositionRange();
+ if (range) {
+ text.remove(range->startPosition().offsetInContainerNode(), TextIterator::rangeLength(range.get()));
+ }
+ return QVariant(text);
+ }
+ return QVariant();
+ }
+ case Qt::ImCurrentSelection: {
+ if (renderTextControl) {
+ int start = renderTextControl->selectionStart();
+ int end = renderTextControl->selectionEnd();
+ if (end > start)
+ return QVariant(QString(renderTextControl->text()).mid(start,end-start));
+ }
+ return QVariant();
+
+ }
+#if QT_VERSION >= 0x040600
+ case Qt::ImAnchorPosition: {
+ if (renderTextControl) {
+ if (editor->hasComposition()) {
+ RefPtr<Range> range = editor->compositionRange();
+ return QVariant(renderTextControl->selectionStart() - TextIterator::rangeLength(range.get()));
+ }
+ return QVariant(renderTextControl->selectionStart());
+ }
+ return QVariant();
+ }
+ case Qt::ImMaximumTextLength: {
+ if (frame->selection()->isContentEditable()) {
+ if (frame->document() && frame->document()->focusedNode()) {
+ if (frame->document()->focusedNode()->hasTagName(HTMLNames::inputTag)) {
+ HTMLInputElement* inputElement = static_cast<HTMLInputElement*>(frame->document()->focusedNode());
+ return QVariant(inputElement->maxLength());
+ }
+ }
+ return QVariant(InputElement::s_maximumLength);
+ }
+ return QVariant(0);
+ }
+#endif
+ default:
+ return QVariant();
}
}
diff --git a/src/3rdparty/webkit/WebKit/qt/ChangeLog b/src/3rdparty/webkit/WebKit/qt/ChangeLog
index b252d8c..a78f573 100644
--- a/src/3rdparty/webkit/WebKit/qt/ChangeLog
+++ b/src/3rdparty/webkit/WebKit/qt/ChangeLog
@@ -1,3 +1,24 @@
+2009-10-01 Joe Ligman <joseph.ligman@nokia.com>
+
+ Reviewed by Simon Hausmann.
+
+ Implementation for QWebPage::inputMethodQuery and QWebPagePrivate::inputMethodEvent
+
+ https://bugs.webkit.org/show_bug.cgi?id=29681
+
+ Some additional changes from Kristian Amlie <kristian.amlie@nokia.com>:
+
+ * Fixed surrounding text to exclude preedit string
+ * Avoid emission of microFocusChanged during setComposition()
+
+ * Api/qwebpage.cpp:
+ (QWebPagePrivate::inputMethodEvent):
+ (QWebPage::inputMethodQuery):
+ * WebCoreSupport/EditorClientQt.cpp:
+ (WebCore::EditorClientQt::respondToChangedSelection):
+ * tests/qwebpage/tst_qwebpage.cpp:
+ (tst_QWebPage::inputMethods):
+
2009-09-29 Andras Becsi <becsi.andras@stud.u-szeged.hu>
Reviewed by Tor Arne Vestbø.
diff --git a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditorClientQt.cpp b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditorClientQt.cpp
index 40833f2..5d5df97 100644
--- a/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditorClientQt.cpp
+++ b/src/3rdparty/webkit/WebKit/qt/WebCoreSupport/EditorClientQt.cpp
@@ -220,7 +220,9 @@ void EditorClientQt::respondToChangedSelection()
m_page->d->updateEditorActions();
emit m_page->selectionChanged();
- emit m_page->microFocusChanged();
+ Frame* frame = m_page->d->page->focusController()->focusedOrMainFrame();
+ if (!frame->editor()->ignoreCompositionSelectionChange())
+ emit m_page->microFocusChanged();
}
void EditorClientQt::didEndEditing()
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 283950e..8f9a740 100644
--- a/src/3rdparty/webkit/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
+++ b/src/3rdparty/webkit/WebKit/qt/tests/qwebpage/tst_qwebpage.cpp
@@ -20,6 +20,7 @@
#include <QtTest/QtTest>
+#include <qwebelement.h>
#include <qwebpage.h>
#include <qwidget.h>
#include <qwebview.h>
@@ -114,6 +115,7 @@ private slots:
void testOptionalJSObjects();
void testEnablePersistentStorage();
void consoleOutput();
+ void inputMethods();
void crashTests_LazyInitializationOfMainFrame();
@@ -1203,6 +1205,94 @@ void tst_QWebPage::frameAt()
frameAtHelper(webPage, webPage->mainFrame(), webPage->mainFrame()->pos());
}
+void tst_QWebPage::inputMethods()
+{
+ m_view->page()->mainFrame()->setHtml("<html><body>" \
+ "<input type='text' id='input1' style='font-family: serif' value='' maxlength='20'/>" \
+ "</body></html>");
+ m_view->page()->mainFrame()->setFocus();
+
+ QList<QWebElement> inputs = m_view->page()->mainFrame()->documentElement().findAll("input");
+
+ QMouseEvent evpres(QEvent::MouseButtonPress, inputs.at(0).geometry().center(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
+ m_view->page()->event(&evpres);
+ QMouseEvent evrel(QEvent::MouseButtonRelease, inputs.at(0).geometry().center(), Qt::LeftButton, Qt::NoButton, Qt::NoModifier);
+ m_view->page()->event(&evrel);
+
+ //ImMicroFocus
+ QVariant variant = m_view->page()->inputMethodQuery(Qt::ImMicroFocus);
+ QRect focusRect = variant.toRect();
+ QVERIFY(inputs.at(0).geometry().contains(variant.toRect().topLeft()));
+
+ //ImFont
+ variant = m_view->page()->inputMethodQuery(Qt::ImFont);
+ QFont font = variant.value<QFont>();
+ QCOMPARE(QString("-webkit-serif"), font.family());
+
+ QList<QInputMethodEvent::Attribute> inputAttributes;
+
+ //Insert text.
+ {
+ QInputMethodEvent eventText("QtWebKit", inputAttributes);
+ QSignalSpy signalSpy(m_view->page(), SIGNAL(microFocusChanged()));
+ m_view->page()->event(&eventText);
+ QCOMPARE(signalSpy.count(), 0);
+ }
+
+ {
+ QInputMethodEvent eventText("", inputAttributes);
+ eventText.setCommitString(QString("QtWebKit"), 0, 0);
+ m_view->page()->event(&eventText);
+ }
+
+#if QT_VERSION >= 0x040600
+ //ImMaximumTextLength
+ variant = m_view->page()->inputMethodQuery(Qt::ImMaximumTextLength);
+ QCOMPARE(20, variant.toInt());
+
+ //Set selection
+ inputAttributes << QInputMethodEvent::Attribute(QInputMethodEvent::Selection, 3, 2, QVariant());
+ QInputMethodEvent eventSelection("",inputAttributes);
+ m_view->page()->event(&eventSelection);
+
+ //ImAnchorPosition
+ variant = m_view->page()->inputMethodQuery(Qt::ImAnchorPosition);
+ int anchorPosition = variant.toInt();
+ QCOMPARE(anchorPosition, 3);
+
+ //ImCursorPosition
+ variant = m_view->page()->inputMethodQuery(Qt::ImCursorPosition);
+ int cursorPosition = variant.toInt();
+ QCOMPARE(cursorPosition, 5);
+
+ //ImCurrentSelection
+ variant = m_view->page()->inputMethodQuery(Qt::ImCurrentSelection);
+ QString selectionValue = variant.value<QString>();
+ QCOMPARE(selectionValue, QString("eb"));
+#endif
+
+ //ImSurroundingText
+ variant = m_view->page()->inputMethodQuery(Qt::ImSurroundingText);
+ QString value = variant.value<QString>();
+ QCOMPARE(value, QString("QtWebKit"));
+
+#if QT_VERSION >= 0x040600
+ {
+ QList<QInputMethodEvent::Attribute> attributes;
+ // Clear the selection, so the next test does not clear any contents.
+ QInputMethodEvent::Attribute newSelection(QInputMethodEvent::Selection, 0, 0, QVariant());
+ attributes.append(newSelection);
+ QInputMethodEvent event("composition", attributes);
+ m_view->page()->event(&event);
+ }
+
+ // A ongoing composition should not change the surrounding text before it is committed.
+ variant = m_view->page()->inputMethodQuery(Qt::ImSurroundingText);
+ value = variant.value<QString>();
+ QCOMPARE(value, QString("QtWebKit"));
+#endif
+}
+
// import a little DRT helper function to trigger the garbage collector
void QWEBKIT_EXPORT qt_drt_garbageCollector_collect();