1/*
2 * Copyright (c) 2011 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 TextChecking_h
32#define TextChecking_h
33
34#include "wtf/RefCounted.h"
35#include "wtf/Vector.h"
36#include "wtf/text/WTFString.h"
37
38namespace WebCore {
39
40enum TextCheckingType {
41    TextCheckingTypeNone        = 0,
42    TextCheckingTypeSpelling    = 1 << 1,
43    TextCheckingTypeGrammar     = 1 << 2,
44};
45
46typedef unsigned TextCheckingTypeMask;
47
48enum TextCheckingProcessType {
49    TextCheckingProcessBatch,
50    TextCheckingProcessIncremental
51};
52
53struct GrammarDetail {
54    int location;
55    int length;
56    Vector<String> guesses;
57    String userDescription;
58};
59
60struct TextCheckingResult {
61    TextCheckingType type;
62    int location;
63    int length;
64    Vector<GrammarDetail> details;
65    String replacement;
66    uint32_t hash;
67};
68
69const int unrequestedTextCheckingSequence = -1;
70
71class TextCheckingRequestData {
72    friend class SpellCheckRequest; // For access to m_sequence.
73public:
74    TextCheckingRequestData()
75        : m_sequence(unrequestedTextCheckingSequence)
76        , m_mask(TextCheckingTypeNone)
77        , m_processType(TextCheckingProcessIncremental)
78    { }
79    TextCheckingRequestData(int sequence, const String& text, TextCheckingTypeMask mask, TextCheckingProcessType processType, const Vector<uint32_t>& markers, const Vector<unsigned>& offsets)
80        : m_sequence(sequence)
81        , m_text(text)
82        , m_mask(mask)
83        , m_processType(processType)
84        , m_markers(markers)
85        , m_offsets(offsets)
86    { }
87
88    int sequence() const { return m_sequence; }
89    String text() const { return m_text; }
90    TextCheckingTypeMask mask() const { return m_mask; }
91    TextCheckingProcessType processType() const { return m_processType; }
92    const Vector<uint32_t>& markers() const { return m_markers; }
93    const Vector<unsigned>& offsets() const { return m_offsets; }
94
95private:
96    int m_sequence;
97    String m_text;
98    TextCheckingTypeMask m_mask;
99    TextCheckingProcessType m_processType;
100    Vector<uint32_t> m_markers;
101    Vector<unsigned> m_offsets;
102};
103
104class TextCheckingRequest : public RefCounted<TextCheckingRequest> {
105public:
106    virtual ~TextCheckingRequest() { }
107
108    virtual const TextCheckingRequestData& data() const = 0;
109    virtual void didSucceed(const Vector<TextCheckingResult>&) = 0;
110    virtual void didCancel() = 0;
111};
112
113}
114
115#endif // TextChecking_h
116