diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2009-10-01 12:43:40 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2009-10-01 12:49:15 (GMT) |
commit | 976adc629192d42882eeba33d5b398618d4445b1 (patch) | |
tree | 6bb705cbf1895252e0e37f131e2bf70294668385 /src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp | |
parent | d2d4fa3365beecc6fe1dca7bcffb8a9167fa991d (diff) | |
download | Qt-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>
Diffstat (limited to 'src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp')
-rw-r--r-- | src/3rdparty/webkit/WebKit/qt/Api/qwebpage.cpp | 163 |
1 files changed, 128 insertions, 35 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(); } } |