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