Source/WebCore/ChangeLog

 12010-08-12 Lindsay Mathieson <lindsay.mathieson@gmail.com>
 2
 3 [Qt] Missing spell check support
 4 https://bugs.webkit.org/show_bug.cgi?id=44114
 5 Fixed style failure.
 6
 7 Reviewed by NOBODY (OOPS!).
 8
 9 No new tests. (OOPS!)
 10
 11 * platform/graphics/qt/GraphicsContextQt.cpp:
 12 (WebCore::drawErrorUnderline):
 13 (WebCore::GraphicsContext::drawLineForTextChecking):
 14
 152011-08-12 Lindsay Mathieson <lindsay.mathieson@gmail.com> and Dawit Alemayehu <adawit@kde.org>
 16
 17 [Qt] Missing spell check support
 18 https://bugs.webkit.org/show_bug.cgi?id=44114
 19 Implements platform plugin api for spell and grammar checking,
 20 draws error lines for same.
 21
 22 Reviewed by NOBODY (OOPS!).
 23
 24 No new tests. (OOPS!)
 25
 26 * platform/graphics/qt/GraphicsContextQt.cpp:
 27 (WebCore::drawErrorUnderline):
 28 (WebCore::GraphicsContext::drawLineForTextChecking):
 29
1302011-08-09 Vsevolod Vlasov <vsevik@chromium.org>
231
332 Web Inspector: Add "Refresh" to context menu of resources panel cookies view.

Source/WebCore/platform/graphics/qt/GraphicsContextQt.cpp

@@void GraphicsContext::drawLineForText(const FloatPoint& origin, float width, boo
900900 drawLine(IntPoint(startPoint.x(), startPoint.y()), IntPoint(endPoint.x(), endPoint.y()));
901901}
902902
903 void GraphicsContext::drawLineForTextChecking(const FloatPoint&, float, TextCheckingLineStyle)
 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 // Bottom of squiggle
 944 path.moveTo(x - halfSquare, top + halfSquare); // A
 945
 946 int i = 0;
 947 for (i = 0; i < widthUnits; i += 2) {
 948 qreal middle = x + (i + 1) * unitWidth;
 949 qreal right = x + (i + 2) * unitWidth;
 950
 951 path.lineTo(middle, bottom); // B
 952
 953 if (i + 2 == widthUnits)
 954 path.lineTo(right + halfSquare, top + halfSquare); // D
 955 else if (i + 1 != widthUnits)
 956 path.lineTo(right, top + square); // C
 957 }
 958
 959 // Top of squiggle
 960 for (i -= 2; i >= 0; i -= 2) {
 961 qreal left = x + i * unitWidth;
 962 qreal middle = x + (i + 1) * unitWidth;
 963 qreal right = x + (i + 2) * unitWidth;
 964
 965 if (i + 1 == widthUnits)
 966 path.lineTo(middle + halfSquare, bottom - halfSquare); // G
 967 else {
 968 if (i + 2 == widthUnits)
 969 path.lineTo(right, top); // E
 970
 971 path.lineTo(middle, bottom - halfSquare); // F
 972 }
 973
 974 path.lineTo(left, top); // H
 975 }
 976
 977 painter->drawPath(path);
 978}
 979
 980
 981void GraphicsContext::drawLineForTextChecking(const FloatPoint& origin, float width, TextCheckingLineStyle style)
904982{
905983 if (paintingDisabled())
906984 return;
907985
908  notImplemented();
 986 QPainter* painter = platformContext();
 987 const QPen originalPen = painter->pen();
 988
 989 switch (style) {
 990 case TextCheckingSpellingLineStyle:
 991 painter->setPen(Qt::red);
 992 break;
 993 case TextCheckingGrammarLineStyle:
 994 painter->setPen(Qt::green);
 995 break;
 996 default:
 997 return;
 998 }
 999
 1000 drawErrorUnderline(painter, origin.x(), origin.y(), width, cMisspellingLineThickness);
 1001 painter->setPen(originalPen);
9091002}
9101003
9111004FloatRect GraphicsContext::roundToDevicePixels(const FloatRect& frect, RoundingMode)

Source/WebKit/qt/Api/qwebkitplatformplugin.h

2121#ifndef QWEBKITPLATFORMPLUGIN_H
2222#define QWEBKITPLATFORMPLUGIN_H
2323
 24#include "qwebkitglobal.h"
 25
2426/*
2527 * Warning: The contents of this file is not part of the public QtWebKit API
2628 * and may be changed from version to version or even be completely removed.

@@public Q_SLOTS:
134136};
135137#endif
136138
 139class QWEBKIT_EXPORT QWebSpellCheckerGrammarDetail {
 140public:
 141 int location;
 142 int length;
 143 QStringList guesses;
 144 QString userDescription;
 145};
 146
 147class QWEBKIT_EXPORT QWebSpellChecker : public QObject {
 148 Q_OBJECT
 149public:
 150 struct GrammarDetail {
 151 int location;
 152 int length;
 153 QStringList guesses;
 154 QString userDescription;
 155 };
 156
 157 virtual bool isContinousSpellCheckingEnabled() const = 0;
 158 virtual void toggleContinousSpellChecking() = 0;
 159
 160 virtual void learnWord(const QString& word) = 0;
 161 virtual void ignoreWordInSpellDocument(const QString& word) = 0;
 162 virtual void checkSpellingOfString(const QString& word, int* misspellingLocation, int* misspellingLength) = 0;
 163 virtual QString autoCorrectSuggestionForMisspelledWord(const QString& word) = 0;
 164 virtual void guessesForWord(const QString& word, const QString& context, QStringList& guesses) = 0;
 165
 166 virtual bool isGrammarCheckingEnabled() = 0;
 167 virtual void toggleGrammarChecking() = 0;
 168 virtual void checkGrammarOfString(const QString&, QVector<GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) = 0;
 169};
 170
137171class QWebKitPlatformPlugin {
138172public:
139173 virtual ~QWebKitPlatformPlugin() {}

@@public:
143177 Notifications,
144178 Haptics,
145179 TouchInteraction,
146  FullScreenVideoPlayer
 180 FullScreenVideoPlayer,
 181 SpellChecker
147182 };
148183
149184 virtual bool supportsExtension(Extension) const = 0;

Source/WebKit/qt/ChangeLog

 12011-08-12 Lindsay Mathieson <lindsay.mathieson@gmail.com>
 2
 3 [Qt] Missing spell check support
 4 https://bugs.webkit.org/show_bug.cgi?id=44114
 5 Fixed style failure.
 6
 7 Reviewed by NOBODY (OOPS!).
 8
 9 * Api/qwebkitplatformplugin.h:
 10 * QtWebKit.pro:
 11 * WebCoreSupport/EditorClientQt.cpp:
 12 (WebCore::EditorClientQt::isContinuousSpellCheckingEnabled):
 13 (WebCore::EditorClientQt::isGrammarCheckingEnabled):
 14 (WebCore::EditorClientQt::toggleContinuousSpellChecking):
 15 (WebCore::EditorClientQt::toggleGrammarChecking):
 16 * WebCoreSupport/EditorClientQt.h:
 17 (WebCore::EditorClientQt::textChecker):
 18 * WebCoreSupport/QtPlatformPlugin.cpp:
 19 (WebCore::QtPlatformPlugin::createSpellChecker):
 20 * WebCoreSupport/QtPlatformPlugin.h:
 21 * WebCoreSupport/TextCheckerClientQt.cpp: Added.
 22 (WebCore::TextCheckerClientQt::ignoreWordInSpellDocument):
 23 (WebCore::TextCheckerClientQt::learnWord):
 24 (WebCore::TextCheckerClientQt::getAutoCorrectSuggestionForMisspelledWord):
 25 (WebCore::TextCheckerClientQt::checkSpellingOfString):
 26 (WebCore::TextCheckerClientQt::checkGrammarOfString):
 27 (WebCore::TextCheckerClientQt::getGuessesForWord):
 28 (WebCore::TextCheckerClientQt::isContinousSpellCheckingEnabled):
 29 (WebCore::TextCheckerClientQt::toggleContinousSpellChecking):
 30 (WebCore::TextCheckerClientQt::isGrammarCheckingEnabled):
 31 (WebCore::TextCheckerClientQt::toggleGrammarChecking):
 32 (WebCore::TextCheckerClientQt::loadSpellChecker):
 33 * WebCoreSupport/TextCheckerClientQt.h: Added.
 34 (WebCore::TextCheckerClientQt::requestCheckingOfString):
 35
 362011-08-12 Lindsay Mathieson <lindsay.mathieson@gmail.com> and Dawit Alemayehu <adawit@kde.org>
 37
 38 [Qt] Missing spell check support
 39 https://bugs.webkit.org/show_bug.cgi?id=44114
 40 Implements platform plugin api for spell and grammar checking,
 41 draws error lines for same.
 42
 43 Reviewed by NOBODY (OOPS!).
 44
 45 * Api/qwebkitplatformplugin.h:
 46 * QtWebKit.pro:
 47 * WebCoreSupport/EditorClientQt.cpp:
 48 (WebCore::EditorClientQt::isContinuousSpellCheckingEnabled):
 49 (WebCore::EditorClientQt::isGrammarCheckingEnabled):
 50 (WebCore::EditorClientQt::toggleContinuousSpellChecking):
 51 (WebCore::EditorClientQt::toggleGrammarChecking):
 52 * WebCoreSupport/EditorClientQt.h:
 53 (WebCore::EditorClientQt::textChecker):
 54 * WebCoreSupport/QtPlatformPlugin.cpp:
 55 (WebCore::QtPlatformPlugin::createSpellChecker):
 56 * WebCoreSupport/QtPlatformPlugin.h:
 57 * WebCoreSupport/TextCheckerClientQt.cpp: Added.
 58 (WebCore::TextCheckerClientQt::ignoreWordInSpellDocument):
 59 (WebCore::TextCheckerClientQt::learnWord):
 60 (WebCore::TextCheckerClientQt::getAutoCorrectSuggestionForMisspelledWord):
 61 (WebCore::TextCheckerClientQt::checkSpellingOfString):
 62 (WebCore::TextCheckerClientQt::checkGrammarOfString):
 63 (WebCore::TextCheckerClientQt::getGuessesForWord):
 64 (WebCore::TextCheckerClientQt::isContinousSpellCheckingEnabled):
 65 (WebCore::TextCheckerClientQt::toggleContinousSpellChecking):
 66 (WebCore::TextCheckerClientQt::isGrammarCheckingEnabled):
 67 (WebCore::TextCheckerClientQt::toggleGrammarChecking):
 68 (WebCore::TextCheckerClientQt::loadSpellChecker):
 69 * WebCoreSupport/TextCheckerClientQt.h: Added.
 70 (WebCore::TextCheckerClientQt::requestCheckingOfString):
 71
1722011-08-05 Dawit Alemayehu <adawit@kde.org>
273
374 Reviewed by Andreas Kling.

Source/WebKit/qt/QtWebKit.pro

@@SOURCES += \
194194 $$PWD/WebCoreSupport/PopupMenuQt.cpp \
195195 $$PWD/WebCoreSupport/QtPlatformPlugin.cpp \
196196 $$PWD/WebCoreSupport/SearchPopupMenuQt.cpp \
197  $$PWD/WebCoreSupport/WebPlatformStrategies.cpp
 197 $$PWD/WebCoreSupport/WebPlatformStrategies.cpp \
 198 $$PWD/WebCoreSupport/TextCheckerClientQt.cpp
198199
199200HEADERS += \
200201 $$WEBKIT_API_HEADERS \

@@HEADERS += \
210211 $$PWD/WebCoreSupport/QtPlatformPlugin.h \
211212 $$PWD/WebCoreSupport/PopupMenuQt.h \
212213 $$PWD/WebCoreSupport/SearchPopupMenuQt.h \
213  $$PWD/WebCoreSupport/WebPlatformStrategies.h
 214 $$PWD/WebCoreSupport/WebPlatformStrategies.h \
 215 $$PWD/WebCoreSupport/TextCheckerClientQt.h
214216
215217webkit2 {
216218 HEADERS += $$WEBKIT2_API_HEADERS

Source/WebKit/qt/WebCoreSupport/EditorClientQt.cpp

5656#include <stdio.h>
5757#include <wtf/OwnPtr.h>
5858
59 #define methodDebug() qDebug("EditorClientQt: %s", __FUNCTION__);
6059
6160static QString dumpPath(WebCore::Node *node)
6261{

@@bool EditorClientQt::shouldShowDeleteInterface(HTMLElement* element)
109108
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
120119int EditorClientQt::spellCheckerDocumentTag()

@@bool EditorClientQt::isSelectTrailingWhitespaceEnabled()
344343
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
355354static const unsigned CtrlKey = 1 << 0;

@@void EditorClientQt::textDidChangeInTextArea(Element*)
567566{
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{
598571 notImplemented();

@@bool EditorClientQt::spellingUIIsShowing()
614587 return false;
615588}
616589
617 void EditorClientQt::getGuessesForWord(const String& word, const String& context, Vector<String>& guesses)
618 {
619  notImplemented();
620 }
621 
622590bool EditorClientQt::isEditing() const
623591{
624592 return m_editing;

Source/WebKit/qt/WebCoreSupport/EditorClientQt.h

3131#define EditorClientQt_h
3232
3333#include "EditorClient.h"
34 #include "TextCheckerClient.h"
3534#include "RefCounted.h"
36 
 35#include "TextCheckerClientQt.h"
3736#include <wtf/Forward.h>
3837
3938class QWebPage;
4039
4140namespace WebCore {
4241
43 class EditorClientQt : public EditorClient, public TextCheckerClient {
 42class EditorClientQt : public EditorClient {
4443public:
4544 EditorClientQt(QWebPage* page);
4645

@@public:
9796 virtual void textWillBeDeletedInTextField(Element*);
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;
116108

@@public:
118110 static bool acceptsEditing;
119111
120112private:
 113 TextCheckerClientQt m_textCheckerClient;
121114 QWebPage* m_page;
122115 bool m_editing;
123116 bool m_inUndoRedo; // our undo stack works differently - don't re-enter!

Source/WebKit/qt/WebCoreSupport/QtPlatformPlugin.cpp

@@PassOwnPtr<QWebFullScreenVideoHandler> QtPlatformPlugin::createFullScreenVideoHa
134134}
135135#endif
136136
 137PassOwnPtr<QWebSpellChecker> QtPlatformPlugin::createSpellChecker()
 138{
 139 QWebKitPlatformPlugin* p = plugin();
 140 return adoptPtr(p ? static_cast<QWebSpellChecker*>(p->createExtension(QWebKitPlatformPlugin::SpellChecker)) : 0);
 141}
 142
137143}

Source/WebKit/qt/WebCoreSupport/QtPlatformPlugin.h

@@class QWebTouchModifier;
3333#if ENABLE(VIDEO) && USE(QT_MULTIMEDIA)
3434class QWebFullScreenVideoHandler;
3535#endif
 36class QWebSpellChecker;
3637
3738namespace WebCore {
3839

@@public:
5354#if ENABLE(VIDEO) && USE(QT_MULTIMEDIA)
5455 PassOwnPtr<QWebFullScreenVideoHandler> createFullScreenVideoHandler();
5556#endif
 57 PassOwnPtr<QWebSpellChecker> createSpellChecker();
5658
5759 QWebKitPlatformPlugin* plugin();
5860

Source/WebKit/qt/WebCoreSupport/TextCheckerClientQt.cpp

 1/*
 2 * Copyright (C) 2011 Lindsay Mathieson <lindsay.mathieson@gmail.com>
 3 * Copyright (C) 2011 Dawit Alemayehu <adawit@kde.org>
 4 *
 5 * All rights reserved.
 6 *
 7 * Redistribution and use in source and binary forms, with or without
 8 * modification, are permitted provided that the following conditions
 9 * are met:
 10 * 1. Redistributions of source code must retain the above copyright
 11 * notice, this list of conditions and the following disclaimer.
 12 * 2. Redistributions in binary form must reproduce the above copyright
 13 * notice, this list of conditions and the following disclaimer in the
 14 * documentation and/or other materials provided with the distribution.
 15 *
 16 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27 */
 28
 29#include "config.h"
 30#include "TextCheckerClientQt.h"
 31
 32#include "NotImplemented.h"
 33#include "QtPlatformPlugin.h"
 34
 35#include <QStringList>
 36#include <QVector>
 37#include <wtf/text/WTFString.h>
 38
 39
 40namespace WebCore {
 41
 42void TextCheckerClientQt::ignoreWordInSpellDocument(const String& word)
 43{
 44 if (!loadSpellChecker())
 45 return;
 46
 47 m_spellChecker->ignoreWordInSpellDocument(word);
 48}
 49
 50void TextCheckerClientQt::learnWord(const String& word)
 51{
 52 if (!loadSpellChecker())
 53 return;
 54
 55 m_spellChecker->learnWord(word);
 56}
 57
 58String TextCheckerClientQt::getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord)
 59{
 60 if (!loadSpellChecker())
 61 return String();
 62
 63 return m_spellChecker->autoCorrectSuggestionForMisspelledWord(misspelledWord);
 64}
 65
 66void TextCheckerClientQt::checkSpellingOfString(const UChar* buffer, int length, int* misspellingLocation, int* misspellingLength)
 67{
 68 if (!loadSpellChecker())
 69 return;
 70
 71 const QString text = QString::fromRawData(reinterpret_cast<const QChar*>(buffer), length);
 72 m_spellChecker->checkSpellingOfString(text, misspellingLocation, misspellingLength);
 73}
 74
 75void TextCheckerClientQt::checkGrammarOfString(const UChar* buffer, int length, Vector<GrammarDetail>& details, int* badGrammarLocation, int* badGrammarLength)
 76{
 77 if (!loadSpellChecker())
 78 return;
 79
 80 const QString text = QString::fromRawData(reinterpret_cast<const QChar*>(buffer), length);
 81
 82 // Do Grammer check.
 83 QVector<QWebSpellChecker::GrammarDetail> qWebDetails;
 84 m_spellChecker->checkGrammarOfString(text, qWebDetails, badGrammarLocation, badGrammarLength);
 85
 86 // Copy qWebDetails to details.
 87 details.clear();
 88 QVector<QWebSpellChecker::GrammarDetail>::iterator qWebIt = qWebDetails.begin();
 89 QVector<QWebSpellChecker::GrammarDetail>::iterator qWebEnd = qWebDetails.end();
 90 for (; qWebIt < qWebEnd; qWebIt++) {
 91 GrammarDetail grammarDetail;
 92 grammarDetail.location = qWebIt->location;
 93 grammarDetail.length = qWebIt->length;
 94 // Copy guesses strings.
 95 QStringList::iterator guessIt = qWebIt->guesses.begin();
 96 QStringList::iterator guessEnd = qWebIt->guesses.end();
 97 for (;guessIt < guessEnd; guessIt++)
 98 grammarDetail.guesses.append(*guessIt);
 99 grammarDetail.userDescription = qWebIt->userDescription;
 100 details.append(grammarDetail);
 101 }
 102}
 103
 104void TextCheckerClientQt::getGuessesForWord(const String& word, const String& context, Vector<String>& guesses)
 105{
 106 if (!loadSpellChecker())
 107 return;
 108
 109 QStringList guessesList;
 110 m_spellChecker->guessesForWord(word, context, guessesList);
 111 const int count = guessesList.count();
 112 guesses.resize(count);
 113 for (int i = 0; i < count; ++i)
 114 guesses.append(guessesList.at(i));
 115}
 116
 117bool TextCheckerClientQt::isContinousSpellCheckingEnabled()
 118{
 119 if (!loadSpellChecker())
 120 return false;
 121
 122 return m_spellChecker->isContinousSpellCheckingEnabled();
 123}
 124
 125void TextCheckerClientQt::toggleContinousSpellChecking()
 126{
 127 if (!loadSpellChecker())
 128 return;
 129
 130 m_spellChecker->toggleContinousSpellChecking();
 131}
 132
 133bool TextCheckerClientQt::isGrammarCheckingEnabled()
 134{
 135 if (!loadSpellChecker())
 136 return false;
 137
 138 return m_spellChecker->isGrammarCheckingEnabled();
 139}
 140
 141void TextCheckerClientQt::toggleGrammarChecking()
 142{
 143 if (!loadSpellChecker())
 144 return;
 145
 146 m_spellChecker->toggleGrammarChecking();
 147}
 148
 149bool TextCheckerClientQt::loadSpellChecker()
 150{
 151 if (m_spellChecker)
 152 return true;
 153
 154 QtPlatformPlugin platformPlugin;
 155 if ((m_spellChecker = platformPlugin.createSpellChecker()))
 156 return true;
 157
 158 return false;
 159}
 160
 161}

Source/WebKit/qt/WebCoreSupport/TextCheckerClientQt.h

 1/*
 2 * Copyright (C) 2011 Lindsay Mathieson <lindsay.mathieson@gmail.com>
 3 * Copyright (C) 2011 Dawit Alemayehu <adawit@kde.org>
 4 *
 5 * All rights reserved.
 6 *
 7 * Redistribution and use in source and binary forms, with or without
 8 * modification, are permitted provided that the following conditions
 9 * are met:
 10 * 1. Redistributions of source code must retain the above copyright
 11 * notice, this list of conditions and the following disclaimer.
 12 * 2. Redistributions in binary form must reproduce the above copyright
 13 * notice, this list of conditions and the following disclaimer in the
 14 * documentation and/or other materials provided with the distribution.
 15 *
 16 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 27 */
 28
 29#ifndef TextCheckerClientQt_h
 30#define TextCheckerClientQt_h
 31
 32#include "TextCheckerClient.h"
 33#include "qwebkitplatformplugin.h"
 34
 35#include <wtf/Forward.h>
 36#include <wtf/OwnPtr.h>
 37
 38
 39namespace WebCore {
 40
 41class TextCheckerClientQt : public TextCheckerClient {
 42public:
 43 virtual void ignoreWordInSpellDocument(const String&);
 44 virtual void learnWord(const String&);
 45 virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength);
 46 virtual String getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord);
 47 virtual void checkGrammarOfString(const UChar*, int length, Vector<GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength);
 48 virtual void getGuessesForWord(const String& word, const String& context, Vector<String>& guesses);
 49 virtual void requestCheckingOfString(SpellChecker*, int, TextCheckingTypeMask, const String&) { }
 50
 51 virtual bool isContinousSpellCheckingEnabled();
 52 virtual void toggleContinousSpellChecking();
 53
 54 virtual bool isGrammarCheckingEnabled();
 55 virtual void toggleGrammarChecking();
 56
 57private:
 58 bool loadSpellChecker();
 59
 60private:
 61 OwnPtr<QWebSpellChecker> m_spellChecker;
 62};
 63
 64}
 65
 66#endif