Commit c8d21e4b authored by hausmann@webkit.org's avatar hausmann@webkit.org

Michael Brasser <michael.brasser@trolltech.com>

Add basic input method support.


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31903 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 9e2182bf
......@@ -638,6 +638,80 @@ void QWebPagePrivate::dropEvent(QDropEvent *ev)
#endif
}
void QWebPagePrivate::inputMethodEvent(QInputMethodEvent *ev)
{
WebCore::Frame *frame = page->focusController()->focusedOrMainFrame();
WebCore::Editor *editor = frame->editor();
if (!editor->canEdit()) {
ev->ignore();
return;
}
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);
} else if (!ev->commitString().isEmpty()) {
editor->confirmComposition(ev->commitString());
}
ev->accept();
}
/*!
This method is used by the input method to query a set of properties of the page
to be able to support complex input method operations as support for surrounding
text and reconversions.
\a property specifies which property is queried.
\sa inputMethodEvent(), QInputMethodEvent, QInputContext.
*/
QVariant QWebPage::inputMethodQuery(Qt::InputMethodQuery property) const
{
switch(property) {
case Qt::ImMicroFocus: {
Frame *frame = d->page->focusController()->focusedFrame();
if (frame) {
return QVariant(frame->selectionController()->caretRect());
}
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) {
Selection selection = frame->selectionController()->selection();
if (selection.isCaret()) {
return QVariant(selection.start().offset());
}
}
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());
}
}
return QVariant();
}
case Qt::ImCurrentSelection:
return QVariant(selectedText());
default:
return QVariant();
}
}
/*!
\enum QWebPage::WebAction
......@@ -1353,6 +1427,8 @@ bool QWebPage::event(QEvent *ev)
d->dropEvent(static_cast<QDropEvent*>(ev));
break;
#endif
case QEvent::InputMethod:
d->inputMethodEvent(static_cast<QInputMethodEvent*>(ev));
default:
return QObject::event(ev);
}
......
......@@ -195,6 +195,8 @@ public:
virtual bool event(QEvent*);
virtual bool focusNextPrevChild(bool next);
QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
Q_SIGNALS:
void loadProgressChanged(int progress);
void hoveringOverLink(const QString &link, const QString &title, const QString &textContent = QString());
......
......@@ -120,6 +120,7 @@ public:
void dragMoveEvent(QDragMoveEvent *);
void dropEvent(QDropEvent *);
void inputMethodEvent(QInputMethodEvent*);
WebCore::ChromeClientQt *chromeClient;
WebCore::ContextMenuClientQt *contextMenuClient;
......
......@@ -50,6 +50,7 @@ QWebView::QWebView(QWidget *parent)
pal.setBrush(QPalette::Background, Qt::white);
setAttribute(Qt::WA_OpaquePaintEvent);
setAttribute(Qt::WA_InputMethodEnabled);
setPalette(pal);
setAcceptDrops(true);
......@@ -554,6 +555,22 @@ bool QWebView::focusNextPrevChild(bool next)
return QWidget::focusNextPrevChild(next);
}
/*!\reimp
*/
QVariant QWebView::inputMethodQuery(Qt::InputMethodQuery property) const
{
return d->page->inputMethodQuery(property);
}
/*!\reimp
*/
void QWebView::inputMethodEvent(QInputMethodEvent *e)
{
if (d->page)
d->page->event(e);
}
/*!
\fn void QWebView::titleChanged(const QString &title)
......
......@@ -82,6 +82,8 @@ public:
Qt::TextInteractionFlags textInteractionFlags() const;
void setTextInteractionFlags(Qt::TextInteractionFlags flags);
QVariant inputMethodQuery(Qt::InputMethodQuery property) const;
/* #### QTextBrowser compatibility?
bool openLinks() const;
void setOpenLinks(bool open);
......@@ -132,6 +134,7 @@ protected:
virtual void dropEvent(QDropEvent *);
virtual void focusInEvent(QFocusEvent*);
virtual void focusOutEvent(QFocusEvent*);
virtual void inputMethodEvent(QInputMethodEvent*);
virtual bool focusNextPrevChild(bool next);
......
2008-04-15 Michael Brasser <michael.brasser@trolltech.com>
Reviewed by Simon.
Add basic input method support.
* Api/qwebpage.cpp:
(QWebPagePrivate::dropEvent):
(QWebPagePrivate::inputMethodEvent):
(QWebPage::inputMethodQuery):
(QWebPage::event):
* Api/qwebpage.h:
* Api/qwebpage_p.h:
* Api/qwebview.cpp:
(QWebView::QWebView):
(QWebView::inputMethodQuery):
(QWebView::inputMethodEvent):
* Api/qwebview.h:
* WebCoreSupport/EditorClientQt.cpp:
(WebCore::EditorClientQt::setInputMethodState):
2008-04-15 Simon Hausmann <hausmann@webkit.org>
Reviewed by Holger.
......
......@@ -541,9 +541,12 @@ bool EditorClientQt::isEditing() const
{
return m_editing;
}
void EditorClientQt::setInputMethodState(bool)
void EditorClientQt::setInputMethodState(bool active)
{
QWidget *view = m_page->view();
if (view)
view->setAttribute(Qt::WA_InputMethodEnabled, active);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment