TextCheckerClientQt.cpp [plain text]
#include "config.h"
#include "TextCheckerClientQt.h"
#include "NotImplemented.h"
#include "QtPlatformPlugin.h"
#include <QStringList>
#include <QVector>
#include <wtf/text/WTFString.h>
static void convertToVectorList(const QStringList& list, Vector<String>& vList)
{
const int count = list.count();
vList.resize(count);
for (int i = 0; i < count; ++i)
vList.append(list.at(i));
}
namespace WebCore {
void TextCheckerClientQt::ignoreWordInSpellDocument(const String& word)
{
if (!loadSpellChecker())
return;
m_spellChecker->ignoreWordInSpellDocument(word);
}
void TextCheckerClientQt::learnWord(const String& word)
{
if (!loadSpellChecker())
return;
m_spellChecker->learnWord(word);
}
String TextCheckerClientQt::getAutoCorrectSuggestionForMisspelledWord(const String& misspelledWord)
{
if (!loadSpellChecker())
return String();
return m_spellChecker->autoCorrectSuggestionForMisspelledWord(misspelledWord);
}
void TextCheckerClientQt::checkSpellingOfString(const UChar* buffer, int length, int* misspellingLocation, int* misspellingLength)
{
if (!loadSpellChecker())
return;
const QString text = QString::fromRawData(reinterpret_cast<const QChar*>(buffer), length);
m_spellChecker->checkSpellingOfString(text, misspellingLocation, misspellingLength);
}
void TextCheckerClientQt::checkGrammarOfString(const UChar* buffer, int length, Vector<GrammarDetail>& details, int* badGrammarLocation, int* badGrammarLength)
{
if (!loadSpellChecker())
return;
const QString text = QString::fromRawData(reinterpret_cast<const QChar*>(buffer), length);
QList<QWebSpellChecker::GrammarDetail> qGrammarDetails;
m_spellChecker->checkGrammarOfString(text, qGrammarDetails, badGrammarLocation, badGrammarLength);
const int count = qGrammarDetails.count();
for (int i = 0; i < count; ++i) {
const QWebSpellChecker::GrammarDetail qGrammarDetail = qGrammarDetails.at(i);
GrammarDetail webkitGrammarDetail;
webkitGrammarDetail.location = qGrammarDetail.location;
webkitGrammarDetail.length = qGrammarDetail.length;
convertToVectorList(qGrammarDetail.guesses, webkitGrammarDetail.guesses);
webkitGrammarDetail.userDescription = qGrammarDetail.userDescription;
details.append(webkitGrammarDetail);
}
}
void TextCheckerClientQt::getGuessesForWord(const String& word, const String& context, Vector<String>& guesses)
{
if (!loadSpellChecker())
return;
QStringList guessesList;
m_spellChecker->guessesForWord(word, context, guessesList);
convertToVectorList(guessesList, guesses);
}
bool TextCheckerClientQt::isContinousSpellCheckingEnabled()
{
if (!loadSpellChecker())
return false;
return m_spellChecker->isContinousSpellCheckingEnabled();
}
void TextCheckerClientQt::toggleContinousSpellChecking()
{
if (!loadSpellChecker())
return;
m_spellChecker->toggleContinousSpellChecking();
}
bool TextCheckerClientQt::isGrammarCheckingEnabled()
{
if (!loadSpellChecker())
return false;
return m_spellChecker->isGrammarCheckingEnabled();
}
void TextCheckerClientQt::toggleGrammarChecking()
{
if (!loadSpellChecker())
return;
m_spellChecker->toggleGrammarChecking();
}
bool TextCheckerClientQt::loadSpellChecker()
{
if (m_spellChecker)
return true;
if ((m_spellChecker = m_platformPlugin.createSpellChecker()))
return true;
return false;
}
}