From 380bdff5e4684901e33b1916b45406ae316a8bd5 Mon Sep 17 00:00:00 2001 From: "kenneth@webkit.org" Date: Mon, 19 Dec 2011 14:27:47 +0000 Subject: [PATCH] First stab at upstreaming our virtual keyboard code Reviewed by Simon Hausmann. Add basic implementation of inputMethodEvent * UIProcess/qt/QtWebPageEventHandler.cpp: (QtWebPageEventHandler::handleEvent): (QtWebPageEventHandler::inputMethodEvent): * UIProcess/qt/QtWebPageEventHandler.h: git-svn-id: https://svn.webkit.org/repository/webkit/trunk@103233 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebKit2/ChangeLog | 13 ++++ .../UIProcess/qt/QtWebPageEventHandler.cpp | 67 +++++++++++++++++++ .../UIProcess/qt/QtWebPageEventHandler.h | 2 + 3 files changed, 82 insertions(+) diff --git a/Source/WebKit2/ChangeLog b/Source/WebKit2/ChangeLog index 5c6d0a560e60..0c3f6f5f7d1e 100644 --- a/Source/WebKit2/ChangeLog +++ b/Source/WebKit2/ChangeLog @@ -1,3 +1,16 @@ +2011-12-19 Kenneth Rohde Christiansen + + First stab at upstreaming our virtual keyboard code + + Reviewed by Simon Hausmann. + + Add basic implementation of inputMethodEvent + + * UIProcess/qt/QtWebPageEventHandler.cpp: + (QtWebPageEventHandler::handleEvent): + (QtWebPageEventHandler::inputMethodEvent): + * UIProcess/qt/QtWebPageEventHandler.h: + 2011-12-19 Simon Hausmann [Qt][WK2] Add support for modal event loop processing for WTR diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp b/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp index 7b9748b65c1f..bba4f84e152c 100644 --- a/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp +++ b/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.cpp @@ -32,8 +32,10 @@ #include #include #include +#include #include #include +#include using namespace WebKit; using namespace WebCore; @@ -135,6 +137,9 @@ bool QtWebPageEventHandler::handleEvent(QEvent* ev) case QEvent::TouchUpdate: touchEvent(static_cast(ev)); return true; + case QEvent::InputMethod: + inputMethodEvent(static_cast(ev)); + return false; // Look at comment in qquickwebpage.cpp } // FIXME: Move all common event handling here. @@ -311,6 +316,68 @@ void QtWebPageEventHandler::setViewportInteractionEngine(QtViewportInteractionEn m_interactionEngine = engine; } +void QtWebPageEventHandler::inputMethodEvent(QInputMethodEvent* ev) +{ + QString commit = ev->commitString(); + QString composition = ev->preeditString(); + + // NOTE: We might want to handle events of one char as special + // and resend them as key events to make web site completion work. + + int cursorPositionWithinComposition = 0; + + Vector underlines; + + for (int i = 0; i < ev->attributes().size(); ++i) { + const QInputMethodEvent::Attribute& attr = ev->attributes().at(i); + switch (attr.type) { + case QInputMethodEvent::TextFormat: { + if (composition.isEmpty()) + break; + + QTextCharFormat textCharFormat = attr.value.value().toCharFormat(); + QColor qcolor = textCharFormat.underlineColor(); + Color color = makeRGBA(qcolor.red(), qcolor.green(), qcolor.blue(), qcolor.alpha()); + int start = qMin(attr.start, (attr.start + attr.length)); + int end = qMax(attr.start, (attr.start + attr.length)); + underlines.append(CompositionUnderline(start, end, color, false)); + break; + } + case QInputMethodEvent::Cursor: + if (attr.length) + cursorPositionWithinComposition = attr.start; + break; + // Selection is handled further down. + default: break; + } + } + + if (composition.isEmpty()) { + int selectionStart = -1; + int selectionLength = 0; + for (int i = 0; i < ev->attributes().size(); ++i) { + const QInputMethodEvent::Attribute& attr = ev->attributes().at(i); + if (attr.type == QInputMethodEvent::Selection) { + selectionStart = attr.start; + selectionLength = attr.length; + + ASSERT(selectionStart >= 0); + ASSERT(selectionLength >= 0); + break; + } + } + + // FIXME: Confirm the composition here. + } else { + ASSERT(cursorPositionWithinComposition >= 0); + ASSERT(replacementStart >= 0); + + // FIXME: Set the composition here. + } + + ev->accept(); +} + void QtWebPageEventHandler::touchEvent(QTouchEvent* event) { #if ENABLE(TOUCH_EVENTS) diff --git a/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h b/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h index 1e1590f1f74b..dfab4c8b9716 100644 --- a/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h +++ b/Source/WebKit2/UIProcess/qt/QtWebPageEventHandler.h @@ -28,6 +28,7 @@ #include "WebPageProxy.h" #include #include +#include #include #include @@ -85,6 +86,7 @@ private: void timerEvent(QTimerEvent*); void touchEvent(QTouchEvent*); + void inputMethodEvent(QInputMethodEvent*); QPoint m_lastClick; QBasicTimer m_clickTimer; -- 2.36.0