Changeset 93093 in webkit


Ignore:
Timestamp:
Aug 16, 2011 6:11:23 AM (13 years ago)
Author:
benjamin.poulain@nokia.com
Message:

[Qt] Missing spell check support
https://bugs.webkit.org/show_bug.cgi?id=44114

Patch by Lindsay Mathieson <lindsay.mathieson@gmail.com> on 2011-08-16
Reviewed by Benjamin Poulain.

Source/WebCore:

Add drawErrorUnderline() from Cairo to render the line for text checking on the Qt port.

  • platform/graphics/qt/GraphicsContextQt.cpp:

(WebCore::drawErrorUnderline):
(WebCore::GraphicsContext::drawLineForTextChecking):

Source/WebKit/qt:

Added a platform plugin to allow spell and grammar check in QtWebKit.

  • Api/qwebkitplatformplugin.h:
  • QtWebKit.pro:
  • WebCoreSupport/EditorClientQt.cpp:

(WebCore::EditorClientQt::isContinuousSpellCheckingEnabled):
(WebCore::EditorClientQt::isGrammarCheckingEnabled):
(WebCore::EditorClientQt::toggleContinuousSpellChecking):
(WebCore::EditorClientQt::toggleGrammarChecking):

  • WebCoreSupport/EditorClientQt.h:

(WebCore::EditorClientQt::textChecker):

  • WebCoreSupport/QtPlatformPlugin.cpp:

(WebCore::QtPlatformPlugin::createSpellChecker):

  • WebCoreSupport/QtPlatformPlugin.h:
  • WebCoreSupport/TextCheckerClientQt.cpp: Added.

(convertToVectorList):
(WebCore::TextCheckerClientQt::ignoreWordInSpellDocument):
(WebCore::TextCheckerClientQt::learnWord):
(WebCore::TextCheckerClientQt::getAutoCorrectSuggestionForMisspelledWord):
(WebCore::TextCheckerClientQt::checkSpellingOfString):
(WebCore::TextCheckerClientQt::checkGrammarOfString):
(WebCore::TextCheckerClientQt::getGuessesForWord):
(WebCore::TextCheckerClientQt::isContinousSpellCheckingEnabled):
(WebCore::TextCheckerClientQt::toggleContinousSpellChecking):
(WebCore::TextCheckerClientQt::isGrammarCheckingEnabled):
(WebCore::TextCheckerClientQt::toggleGrammarChecking):
(WebCore::TextCheckerClientQt::loadSpellChecker):

  • WebCoreSupport/TextCheckerClientQt.h: Added.

(WebCore::TextCheckerClientQt::requestCheckingOfString):

Location:
trunk/Source
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r93087 r93093  
     12011-08-16  Lindsay Mathieson   <lindsay.mathieson@gmail.com>
     2
     3        [Qt] Missing spell check support
     4        https://bugs.webkit.org/show_bug.cgi?id=44114
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        Add drawErrorUnderline() from Cairo to render the line for text checking on the Qt port.
     9
     10        * platform/graphics/qt/GraphicsContextQt.cpp:
     11        (WebCore::drawErrorUnderline):
     12        (WebCore::GraphicsContext::drawLineForTextChecking):
     13
    1142011-08-15  MORITA Hajime  <morrita@google.com>
    215
  • trunk/Source/WebCore/platform/graphics/qt/GraphicsContextQt.cpp

    r91914 r93093  
    901901}
    902902
    903 void GraphicsContext::drawLineForTextChecking(const FloatPoint&, float, TextCheckingLineStyle)
    904 {
    905     if (paintingDisabled())
    906         return;
    907 
    908     notImplemented();
     903
     904/*
     905 *   NOTE: This code is completely based upon the one from
     906 *   Source/WebCore/platform/graphics/cairo/DrawErrorUnderline.{h|cpp}
     907 *
     908 *   Draws an error underline that looks like one of:
     909 *
     910 *               H       E                H
     911 *      /\      /\      /\        /\      /\               -
     912 *    A/  \    /  \    /  \     A/  \    /  \              |
     913 *     \   \  /    \  /   /D     \   \  /    \             |
     914 *      \   \/  C   \/   /        \   \/   C  \            | height = heightSquares * square
     915 *       \      /\  F   /          \  F   /\   \           |
     916 *        \    /  \    /            \    /  \   \G         |
     917 *         \  /    \  /              \  /    \  /          |
     918 *          \/      \/                \/      \/           -
     919 *          B                         B
     920 *          |---|
     921 *        unitWidth = (heightSquares - 1) * square
     922 *
     923 *  The x, y, width, height passed in give the desired bounding box;
     924 *  x/width are adjusted to make the underline a integer number of units wide.
     925*/
     926static void drawErrorUnderline(QPainter *painter, qreal x, qreal y, qreal width, qreal height)
     927{
     928    const qreal heightSquares = 2.5;
     929
     930    qreal square = height / heightSquares;
     931    qreal halfSquare = 0.5 * square;
     932
     933    qreal unitWidth = (heightSquares - 1.0) * square;
     934    int widthUnits = static_cast<int>((width + 0.5 * unitWidth) / unitWidth);
     935
     936    x += 0.5 * (width - widthUnits * unitWidth);
     937    width = widthUnits * unitWidth;
     938
     939    qreal bottom = y + height;
     940    qreal top = y;
     941
     942    QPainterPath path;
     943
     944    // Bottom of squiggle.
     945    path.moveTo(x - halfSquare, top + halfSquare); // A
     946
     947    int i = 0;
     948    for (i = 0; i < widthUnits; i += 2) {
     949        qreal middle = x + (i + 1) * unitWidth;
     950        qreal right = x + (i + 2) * unitWidth;
     951
     952        path.lineTo(middle, bottom); // B
     953
     954        if (i + 2 == widthUnits)
     955            path.lineTo(right + halfSquare, top + halfSquare); // D
     956        else if (i + 1 != widthUnits)
     957            path.lineTo(right, top + square); // C
     958    }
     959
     960    // Top of squiggle.
     961    for (i -= 2; i >= 0; i -= 2) {
     962        qreal left = x + i * unitWidth;
     963        qreal middle = x + (i + 1) * unitWidth;
     964        qreal right = x + (i + 2) * unitWidth;
     965
     966        if (i + 1 == widthUnits)
     967            path.lineTo(middle + halfSquare, bottom - halfSquare); // G
     968        else {
     969            if (i + 2 == widthUnits)
     970                path.lineTo(right, top); // E
     971
     972            path.lineTo(middle, bottom - halfSquare); // F
     973        }
     974
     975        path.lineTo(left, top); // H
     976    }
     977
     978    painter->drawPath(path);
     979}
     980
     981
     982void GraphicsContext::drawLineForTextChecking(const FloatPoint& origin, float width, TextCheckingLineStyle style)
     983{
     984    if (paintingDisabled())
     985        return;
     986
     987    QPainter* painter = platformContext();
     988    const QPen originalPen = painter->pen();
     989
     990    switch (style) {
     991    case TextCheckingSpellingLineStyle:
     992        painter->setPen(Qt::red);
     993        break;
     994    case TextCheckingGrammarLineStyle:
     995        painter->setPen(Qt::green);
     996        break;
     997    default:
     998        return;
     999    }
     1000
     1001    drawErrorUnderline(painter, origin.x(), origin.y(), width, cMisspellingLineThickness);
     1002    painter->setPen(originalPen);
    9091003}
    9101004
  • trunk/Source/WebKit/qt/Api/qwebkitplatformplugin.h

    r89958 r93093  
    2121#ifndef QWEBKITPLATFORMPLUGIN_H
    2222#define QWEBKITPLATFORMPLUGIN_H
     23
     24#include "qwebkitglobal.h"
    2325
    2426/*
     
    135137#endif
    136138
     139class QWEBKIT_EXPORT QWebSpellChecker : public QObject {
     140    Q_OBJECT
     141public:
     142    struct GrammarDetail {
     143        int location;
     144        int length;
     145        QStringList guesses;
     146        QString userDescription;
     147    };
     148
     149    virtual bool isContinousSpellCheckingEnabled() const = 0;
     150    virtual void toggleContinousSpellChecking() = 0;
     151
     152    virtual void learnWord(const QString& word) = 0;
     153    virtual void ignoreWordInSpellDocument(const QString& word) = 0;
     154    virtual void checkSpellingOfString(const QString& word, int* misspellingLocation, int* misspellingLength) = 0;
     155    virtual QString autoCorrectSuggestionForMisspelledWord(const QString& word) = 0;
     156    virtual void guessesForWord(const QString& word, const QString& context, QStringList& guesses) = 0;
     157
     158    virtual bool isGrammarCheckingEnabled() = 0;
     159    virtual void toggleGrammarChecking() = 0;
     160    virtual void checkGrammarOfString(const QString&, QList<GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) = 0;
     161};
     162
    137163class QWebKitPlatformPlugin {
    138164public:
     
    144170        Haptics,
    145171        TouchInteraction,
    146         FullScreenVideoPlayer
     172        FullScreenVideoPlayer,
     173        SpellChecker
    147174    };
    148175
  • trunk/Source/WebKit/qt/ChangeLog

    r93066 r93093  
     12011-08-16  Lindsay Mathieson   <lindsay.mathieson@gmail.com>
     2
     3        [Qt] Missing spell check support
     4        https://bugs.webkit.org/show_bug.cgi?id=44114
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        Added a platform plugin to allow spell and grammar check in QtWebKit.
     9
     10        * Api/qwebkitplatformplugin.h:
     11        * QtWebKit.pro:
     12        * WebCoreSupport/EditorClientQt.cpp:
     13        (WebCore::EditorClientQt::isContinuousSpellCheckingEnabled):
     14        (WebCore::EditorClientQt::isGrammarCheckingEnabled):
     15        (WebCore::EditorClientQt::toggleContinuousSpellChecking):
     16        (WebCore::EditorClientQt::toggleGrammarChecking):
     17        * WebCoreSupport/EditorClientQt.h:
     18        (WebCore::EditorClientQt::textChecker):
     19        * WebCoreSupport/QtPlatformPlugin.cpp:
     20        (WebCore::QtPlatformPlugin::createSpellChecker):
     21        * WebCoreSupport/QtPlatformPlugin.h:
     22        * WebCoreSupport/TextCheckerClientQt.cpp: Added.
     23        (convertToVectorList):
     24        (WebCore::TextCheckerClientQt::ignoreWordInSpellDocument):
     25        (WebCore::TextCheckerClientQt::learnWord):
     26        (WebCore::TextCheckerClientQt::getAutoCorrectSuggestionForMisspelledWord):
     27        (WebCore::TextCheckerClientQt::checkSpellingOfString):
     28        (WebCore::TextCheckerClientQt::checkGrammarOfString):
     29        (WebCore::TextCheckerClientQt::getGuessesForWord):
     30        (WebCore::TextCheckerClientQt::isContinousSpellCheckingEnabled):
     31        (WebCore::TextCheckerClientQt::toggleContinousSpellChecking):
     32        (WebCore::TextCheckerClientQt::isGrammarCheckingEnabled):
     33        (WebCore::TextCheckerClientQt::toggleGrammarChecking):
     34        (WebCore::TextCheckerClientQt::loadSpellChecker):
     35        * WebCoreSupport/TextCheckerClientQt.h: Added.
     36        (WebCore::TextCheckerClientQt::requestCheckingOfString):
     37
    1382011-08-15  Dmitry Titov  <dimich@chromium.org>
    239
  • trunk/Source/WebKit/qt/QtWebKit.pro

    r91863 r93093  
    195195    $$PWD/WebCoreSupport/QtPlatformPlugin.cpp \
    196196    $$PWD/WebCoreSupport/SearchPopupMenuQt.cpp \
     197    $$PWD/WebCoreSupport/TextCheckerClientQt.cpp \
    197198    $$PWD/WebCoreSupport/WebPlatformStrategies.cpp
    198199
     
    211212    $$PWD/WebCoreSupport/PopupMenuQt.h \
    212213    $$PWD/WebCoreSupport/SearchPopupMenuQt.h \
     214    $$PWD/WebCoreSupport/TextCheckerClientQt.h \
    213215    $$PWD/WebCoreSupport/WebPlatformStrategies.h
    214216
  • trunk/Source/WebKit/qt/WebCoreSupport/EditorClientQt.cpp

    r86798 r93093  
    5757#include <wtf/OwnPtr.h>
    5858
    59 #define methodDebug() qDebug("EditorClientQt: %s", __FUNCTION__);
    6059
    6160static QString dumpPath(WebCore::Node *node)
     
    110109bool EditorClientQt::isContinuousSpellCheckingEnabled()
    111110{
    112     return false;
     111    return m_textCheckerClient.isContinousSpellCheckingEnabled();
    113112}
    114113
    115114bool EditorClientQt::isGrammarCheckingEnabled()
    116115{
    117     return false;
     116    return m_textCheckerClient.isGrammarCheckingEnabled();
    118117}
    119118
     
    345344void EditorClientQt::toggleContinuousSpellChecking()
    346345{
    347     notImplemented();
     346    m_textCheckerClient.toggleContinousSpellChecking();
    348347}
    349348
    350349void EditorClientQt::toggleGrammarChecking()
    351350{
    352     notImplemented();
     351    return m_textCheckerClient.toggleGrammarChecking();
    353352}
    354353
     
    568567}
    569568
    570 void EditorClientQt::ignoreWordInSpellDocument(const String&)
    571 {
    572     notImplemented();
    573 }
    574 
    575 void EditorClientQt::learnWord(const String&)
    576 {
    577     notImplemented();
    578 }
    579 
    580 void EditorClientQt::checkSpellingOfString(const UChar*, int, int*, int*)
    581 {
    582     notImplemented();
    583 }
    584 
    585 String EditorClientQt::getAutoCorrectSuggestionForMisspelledWord(const String&)
    586 {
    587     notImplemented();
    588     return String();
    589 }
    590 
    591 void EditorClientQt::checkGrammarOfString(const UChar*, int, Vector<GrammarDetail>&, int*, int*)
    592 {
    593     notImplemented();
    594 }
    595 
    596569void EditorClientQt::updateSpellingUIWithGrammarString(const String&, const GrammarDetail&)
    597570{
     
    613586    notImplemented();
    614587    return false;
    615 }
    616 
    617 void EditorClientQt::getGuessesForWord(const String& word, const String& context, Vector<String>& guesses)
    618 {
    619     notImplemented();
    620588}
    621589
  • trunk/Source/WebKit/qt/WebCoreSupport/EditorClientQt.h

    r84574 r93093  
    3232
    3333#include "EditorClient.h"
    34 #include "TextCheckerClient.h"
    3534#include "RefCounted.h"
    36 
     35#include "TextCheckerClientQt.h"
    3736#include <wtf/Forward.h>
    3837
     
    4140namespace WebCore {
    4241
    43 class EditorClientQt : public EditorClient, public TextCheckerClient {
     42class EditorClientQt : public EditorClient {
    4443public:
    4544    EditorClientQt(QWebPage* page);
     
    9897    virtual void textDidChangeInTextArea(Element*);
    9998
    100     virtual void ignoreWordInSpellDocument(const String&);
    101     virtual void learnWord(const String&);
    102     virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength);
    103     virtual String getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord);
    104     virtual void checkGrammarOfString(const UChar*, int length, Vector<GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength);
    10599    virtual void updateSpellingUIWithGrammarString(const String&, const GrammarDetail&);
    106100    virtual void updateSpellingUIWithMisspelledWord(const String&);
    107101    virtual void showSpellingUI(bool show);
    108102    virtual bool spellingUIIsShowing();
    109     virtual void getGuessesForWord(const String& word, const String& context, Vector<String>& guesses);
    110103    virtual void willSetInputMethodState();
    111104    virtual void setInputMethodState(bool enabled);
    112     virtual void requestCheckingOfString(SpellChecker*, int, WebCore::TextCheckingTypeMask, const String&) {}
    113     virtual TextCheckerClient* textChecker() { return this; }
     105    virtual TextCheckerClient* textChecker() { return &m_textCheckerClient; }
    114106
    115107    bool isEditing() const;
     
    119111
    120112private:
     113    TextCheckerClientQt m_textCheckerClient;
    121114    QWebPage* m_page;
    122115    bool m_editing;
  • trunk/Source/WebKit/qt/WebCoreSupport/QtPlatformPlugin.cpp

    r86537 r93093  
    135135#endif
    136136
     137PassOwnPtr<QWebSpellChecker> QtPlatformPlugin::createSpellChecker()
     138{
     139    QWebKitPlatformPlugin* p = plugin();
     140    return adoptPtr(p ? static_cast<QWebSpellChecker*>(p->createExtension(QWebKitPlatformPlugin::SpellChecker)) : 0);
    137141}
     142
     143}
  • trunk/Source/WebKit/qt/WebCoreSupport/QtPlatformPlugin.h

    r86537 r93093  
    3434class QWebFullScreenVideoHandler;
    3535#endif
     36class QWebSpellChecker;
    3637
    3738namespace WebCore {
     
    5455    PassOwnPtr<QWebFullScreenVideoHandler> createFullScreenVideoHandler();
    5556#endif
     57    PassOwnPtr<QWebSpellChecker> createSpellChecker();
    5658
    5759    QWebKitPlatformPlugin* plugin();
Note: See TracChangeset for help on using the changeset viewer.