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