Home | History | Annotate | Download | only in win
      1 /*
      2  * Copyright (C) 2010 Apple Inc. All rights reserved.
      3  *
      4  * Redistribution and use in source and binary forms, with or without
      5  * modification, are permitted provided that the following conditions
      6  * are met:
      7  * 1. Redistributions of source code must retain the above copyright
      8  *    notice, this list of conditions and the following disclaimer.
      9  * 2. Redistributions in binary form must reproduce the above copyright
     10  *    notice, this list of conditions and the following disclaimer in the
     11  *    documentation and/or other materials provided with the distribution.
     12  *
     13  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
     14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
     17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
     23  * THE POSSIBILITY OF SUCH DAMAGE.
     24  */
     25 
     26 #include "config.h"
     27 #include "TextChecker.h"
     28 
     29 #include "TextCheckerState.h"
     30 #include "WebTextChecker.h"
     31 #include <WebCore/NotImplemented.h>
     32 
     33 using namespace WebCore;
     34 
     35 namespace WebKit {
     36 
     37 static TextCheckerState textCheckerState;
     38 
     39 const TextCheckerState& TextChecker::state()
     40 {
     41     static bool didInitializeState;
     42     if (didInitializeState)
     43         return textCheckerState;
     44 
     45     WebTextCheckerClient& client = WebTextChecker::shared()->client();
     46     textCheckerState.isContinuousSpellCheckingEnabled = client.continuousSpellCheckingEnabled();
     47     textCheckerState.isGrammarCheckingEnabled =  client.grammarCheckingEnabled();
     48 
     49     didInitializeState = true;
     50 
     51     return textCheckerState;
     52 }
     53 
     54 bool TextChecker::isContinuousSpellCheckingAllowed()
     55 {
     56     return WebTextChecker::shared()->client().continuousSpellCheckingAllowed();
     57 }
     58 
     59 void TextChecker::setContinuousSpellCheckingEnabled(bool isContinuousSpellCheckingEnabled)
     60 {
     61     if (state().isContinuousSpellCheckingEnabled == isContinuousSpellCheckingEnabled)
     62         return;
     63     textCheckerState.isContinuousSpellCheckingEnabled = isContinuousSpellCheckingEnabled;
     64     WebTextChecker::shared()->client().setContinuousSpellCheckingEnabled(isContinuousSpellCheckingEnabled);
     65 }
     66 
     67 void TextChecker::setGrammarCheckingEnabled(bool isGrammarCheckingEnabled)
     68 {
     69     if (state().isGrammarCheckingEnabled == isGrammarCheckingEnabled)
     70         return;
     71     textCheckerState.isGrammarCheckingEnabled = isGrammarCheckingEnabled;
     72     WebTextChecker::shared()->client().setGrammarCheckingEnabled(isGrammarCheckingEnabled);
     73 }
     74 
     75 void TextChecker::continuousSpellCheckingEnabledStateChanged(bool enabled)
     76 {
     77     textCheckerState.isContinuousSpellCheckingEnabled = enabled;
     78 }
     79 
     80 void TextChecker::grammarCheckingEnabledStateChanged(bool enabled)
     81 {
     82     textCheckerState.isGrammarCheckingEnabled = enabled;
     83 }
     84 
     85 int64_t TextChecker::uniqueSpellDocumentTag(WebPageProxy* page)
     86 {
     87     return WebTextChecker::shared()->client().uniqueSpellDocumentTag(page);
     88 }
     89 
     90 void TextChecker::closeSpellDocumentWithTag(int64_t tag)
     91 {
     92     WebTextChecker::shared()->client().closeSpellDocumentWithTag(tag);
     93 }
     94 
     95 void TextChecker::checkSpellingOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, int32_t& misspellingLocation, int32_t& misspellingLength)
     96 {
     97     WebTextChecker::shared()->client().checkSpellingOfString(spellDocumentTag, String(text, length), misspellingLocation, misspellingLength);
     98 }
     99 
    100 void TextChecker::checkGrammarOfString(int64_t spellDocumentTag, const UChar* text, uint32_t length, Vector<WebCore::GrammarDetail>& grammarDetails, int32_t& badGrammarLocation, int32_t& badGrammarLength)
    101 {
    102     WebTextChecker::shared()->client().checkGrammarOfString(spellDocumentTag, String(text, length), grammarDetails, badGrammarLocation, badGrammarLength);
    103 }
    104 
    105 bool TextChecker::spellingUIIsShowing()
    106 {
    107     return WebTextChecker::shared()->client().spellingUIIsShowing();
    108 }
    109 
    110 void TextChecker::toggleSpellingUIIsShowing()
    111 {
    112     WebTextChecker::shared()->client().toggleSpellingUIIsShowing();
    113 }
    114 
    115 void TextChecker::updateSpellingUIWithMisspelledWord(int64_t spellDocumentTag, const String& misspelledWord)
    116 {
    117     WebTextChecker::shared()->client().updateSpellingUIWithMisspelledWord(spellDocumentTag, misspelledWord);
    118 }
    119 
    120 void TextChecker::updateSpellingUIWithGrammarString(int64_t spellDocumentTag, const String& badGrammarPhrase, const GrammarDetail& grammarDetail)
    121 {
    122     WebTextChecker::shared()->client().updateSpellingUIWithGrammarString(spellDocumentTag, badGrammarPhrase, grammarDetail);
    123 }
    124 
    125 void TextChecker::getGuessesForWord(int64_t spellDocumentTag, const String& word, const String& context, Vector<String>& guesses)
    126 {
    127     WebTextChecker::shared()->client().guessesForWord(spellDocumentTag, word, guesses);
    128 }
    129 
    130 void TextChecker::learnWord(int64_t spellDocumentTag, const String& word)
    131 {
    132     WebTextChecker::shared()->client().learnWord(spellDocumentTag, word);
    133 }
    134 
    135 void TextChecker::ignoreWord(int64_t spellDocumentTag, const String& word)
    136 {
    137     WebTextChecker::shared()->client().ignoreWord(spellDocumentTag, word);
    138 }
    139 
    140 } // namespace WebKit
    141