WebKitTools/DumpRenderTree/chromium/MockSpellCheck.h
changeset 2 303757a437d3
parent 0 4f2f89ce4247
equal deleted inserted replaced
0:4f2f89ce4247 2:303757a437d3
     1 /*
       
     2  * Copyright (C) 2010 Google 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 are
       
     6  * met:
       
     7  *
       
     8  *     * Redistributions of source code must retain the above copyright
       
     9  * notice, this list of conditions and the following disclaimer.
       
    10  *     * Redistributions in binary form must reproduce the above
       
    11  * copyright notice, this list of conditions and the following disclaimer
       
    12  * in the documentation and/or other materials provided with the
       
    13  * distribution.
       
    14  *     * Neither the name of Google Inc. nor the names of its
       
    15  * contributors may be used to endorse or promote products derived from
       
    16  * this software without specific prior written permission.
       
    17  *
       
    18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
       
    19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
       
    20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
       
    21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
       
    22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
       
    23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
       
    24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
       
    25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
       
    26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
       
    27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
       
    28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    29  */
       
    30 
       
    31 #ifndef MockSpellCheck_h
       
    32 #define MockSpellCheck_h
       
    33 
       
    34 #include <wtf/HashMap.h>
       
    35 #include <wtf/text/StringHash.h>
       
    36 #include <wtf/text/WTFString.h>
       
    37 
       
    38 namespace WebKit {
       
    39 class WebString;
       
    40 }
       
    41 
       
    42 // A mock implementation of a spell-checker used for WebKit tests.
       
    43 // This class only implements the minimal functionarities required by WebKit
       
    44 // tests, i.e. this class just compares the given string with known misspelled
       
    45 // words in webkit tests and mark them as missspelled.
       
    46 // Even though this is sufficent for webkit tests, this class is not suitable
       
    47 // for any other usages.
       
    48 class MockSpellCheck {
       
    49 public:
       
    50     MockSpellCheck();
       
    51     ~MockSpellCheck();
       
    52 
       
    53     // Checks the spellings of the specified text.
       
    54     // This function returns true if the text consists of valid words, and
       
    55     // returns false if it includes invalid words.
       
    56     // When the given text includes invalid words, this function sets the
       
    57     // position of the first invalid word to misspelledOffset, and the length of
       
    58     // the first invalid word to misspelledLength, respectively.
       
    59     // For example, when the given text is "   zz zz", this function sets 3 to
       
    60     // misspelledOffset and 2 to misspelledLength, respectively.
       
    61     bool spellCheckWord(const WebKit::WebString& text,
       
    62                         int* misspelledOffset,
       
    63                         int* misspelledLength);
       
    64 
       
    65 private:
       
    66     // Initialize the internal resources if we need to initialize it.
       
    67     // Initializing this object may take long time. To prevent from hurting
       
    68     // the performance of test_shell, we initialize this object when
       
    69     // SpellCheckWord() is called for the first time.
       
    70     // To be compliant with SpellCheck:InitializeIfNeeded(), this function
       
    71     // returns true if this object is downloading a dictionary, otherwise
       
    72     // it returns false.
       
    73     bool initializeIfNeeded();
       
    74 
       
    75     // A table that consists of misspelled words.
       
    76     HashMap<WebCore::String, bool> m_misspelledWords;
       
    77 
       
    78     // A flag representing whether or not this object is initialized.
       
    79     bool m_initialized;
       
    80 };
       
    81 
       
    82 #endif // MockSpellCheck_h