OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. |
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) |
4 * | 4 * |
5 * This library is free software; you can redistribute it and/or | 5 * This library is free software; you can redistribute it and/or |
6 * modify it under the terms of the GNU Library General Public | 6 * modify it under the terms of the GNU Library General Public |
7 * License as published by the Free Software Foundation; either | 7 * License as published by the Free Software Foundation; either |
8 * version 2 of the License, or (at your option) any later version. | 8 * version 2 of the License, or (at your option) any later version. |
9 * | 9 * |
10 * This library is distributed in the hope that it will be useful, | 10 * This library is distributed in the hope that it will be useful, |
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 * Library General Public License for more details. | 13 * Library General Public License for more details. |
14 * | 14 * |
15 * You should have received a copy of the GNU Library General Public License | 15 * You should have received a copy of the GNU Library General Public License |
16 * along with this library; see the file COPYING.LIB. If not, write to | 16 * along with this library; see the file COPYING.LIB. If not, write to |
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 * Boston, MA 02110-1301, USA. | 18 * Boston, MA 02110-1301, USA. |
19 */ | 19 */ |
20 | 20 |
21 #ifndef TextCheckingHelper_h | 21 #ifndef TextCheckingHelper_h |
22 #define TextCheckingHelper_h | 22 #define TextCheckingHelper_h |
23 | 23 |
24 #include "core/editing/EphemeralRange.h" | |
24 #include "core/editing/Position.h" | 25 #include "core/editing/Position.h" |
25 #include "platform/heap/Handle.h" | 26 #include "platform/heap/Handle.h" |
26 #include "platform/text/TextChecking.h" | 27 #include "platform/text/TextChecking.h" |
27 #include "wtf/text/WTFString.h" | 28 #include "wtf/text/WTFString.h" |
28 | 29 |
29 namespace blink { | 30 namespace blink { |
30 | 31 |
31 class ExceptionState; | 32 class ExceptionState; |
32 class LocalFrame; | 33 class LocalFrame; |
33 class Range; | 34 class Range; |
34 class SpellCheckerClient; | 35 class SpellCheckerClient; |
35 class TextCheckerClient; | 36 class TextCheckerClient; |
36 struct TextCheckingResult; | 37 struct TextCheckingResult; |
37 | 38 |
38 class TextCheckingParagraph { | 39 class TextCheckingParagraph { |
39 STACK_ALLOCATED(); | 40 STACK_ALLOCATED(); |
40 public: | 41 public: |
41 explicit TextCheckingParagraph(PassRefPtrWillBeRawPtr<Range> checkingRange); | 42 explicit TextCheckingParagraph(const EphemeralRange checkingRange); |
43 TextCheckingParagraph(const EphemeralRange checkingRange, const EphemeralRan ge paragraphRange); | |
42 TextCheckingParagraph(PassRefPtrWillBeRawPtr<Range> checkingRange, PassRefPt rWillBeRawPtr<Range> paragraphRange); | 44 TextCheckingParagraph(PassRefPtrWillBeRawPtr<Range> checkingRange, PassRefPt rWillBeRawPtr<Range> paragraphRange); |
43 ~TextCheckingParagraph(); | 45 ~TextCheckingParagraph(); |
44 | 46 |
45 int rangeLength() const; | 47 int rangeLength() const; |
46 PassRefPtrWillBeRawPtr<Range> subrange(int characterOffset, int characterCou nt) const; | 48 EphemeralRange subrange(int characterOffset, int characterCount) const; |
47 int offsetTo(const Position&, ExceptionState&) const; | 49 int offsetTo(const Position&, ExceptionState&) const; |
48 void expandRangeToNextEnd(); | 50 void expandRangeToNextEnd(); |
49 | 51 |
50 const String& text() const; | 52 const String& text() const; |
51 // Why not let clients call these functions on text() themselves? | 53 // Why not let clients call these functions on text() themselves? |
52 String textSubstring(unsigned pos, unsigned len = INT_MAX) const { return te xt().substring(pos, len); } | 54 String textSubstring(unsigned pos, unsigned len = INT_MAX) const { return te xt().substring(pos, len); } |
53 UChar textCharAt(int index) const { return text()[static_cast<unsigned>(inde x)]; } | 55 UChar textCharAt(int index) const { return text()[static_cast<unsigned>(inde x)]; } |
54 | 56 |
55 bool isEmpty() const; | 57 bool isEmpty() const; |
56 bool isTextEmpty() const { return text().isEmpty(); } | 58 bool isTextEmpty() const { return text().isEmpty(); } |
57 bool isRangeEmpty() const { return checkingStart() >= checkingEnd(); } | 59 bool isRangeEmpty() const { return checkingStart() >= checkingEnd(); } |
58 | 60 |
59 int checkingStart() const; | 61 int checkingStart() const; |
60 int checkingEnd() const; | 62 int checkingEnd() const; |
61 int checkingLength() const; | 63 int checkingLength() const; |
62 | 64 |
63 bool checkingRangeCovers(int location, int length) const { return location < checkingEnd() && location + length > checkingStart(); } | 65 bool checkingRangeCovers(int location, int length) const { return location < checkingEnd() && location + length > checkingStart(); } |
64 PassRefPtrWillBeRawPtr<Range> paragraphRange() const; | 66 EphemeralRange paragraphRange() const; |
65 PassRefPtrWillBeRawPtr<Range> checkingRange() const { return m_checkingRange ; } | 67 EphemeralRange checkingRange() const { return m_checkingRange; } |
68 void setParagraphRange(const EphemeralRange&); | |
66 | 69 |
67 private: | 70 private: |
68 void invalidateParagraphRangeValues(); | 71 void invalidateParagraphRangeValues(); |
69 PassRefPtrWillBeRawPtr<Range> offsetAsRange() const; | 72 EphemeralRange offsetAsRange() const; |
70 | 73 |
71 RefPtrWillBeMember<Range> m_checkingRange; | 74 EphemeralRange m_checkingRange; |
72 mutable RefPtrWillBeMember<Range> m_paragraphRange; | 75 mutable EphemeralRange m_paragraphRange; |
yosin_UTC9
2015/09/10 01:58:39
Good catch!
Since, |EphmeralRange| checks DOM tre
| |
73 mutable RefPtrWillBeMember<Range> m_offsetAsRange; | 76 mutable EphemeralRange m_offsetAsRange; |
74 mutable String m_text; | 77 mutable String m_text; |
75 mutable int m_checkingStart; | 78 mutable int m_checkingStart; |
76 mutable int m_checkingEnd; | 79 mutable int m_checkingEnd; |
77 mutable int m_checkingLength; | 80 mutable int m_checkingLength; |
78 }; | 81 }; |
79 | 82 |
80 class TextCheckingHelper { | 83 class TextCheckingHelper { |
81 WTF_MAKE_NONCOPYABLE(TextCheckingHelper); | 84 WTF_MAKE_NONCOPYABLE(TextCheckingHelper); |
82 STACK_ALLOCATED(); | 85 STACK_ALLOCATED(); |
83 public: | 86 public: |
84 TextCheckingHelper(SpellCheckerClient&, const Position& start, const Positio n& end); | 87 TextCheckingHelper(SpellCheckerClient&, const Position& start, const Positio n& end); |
85 ~TextCheckingHelper(); | 88 ~TextCheckingHelper(); |
86 | 89 |
87 String findFirstMisspelling(int& firstMisspellingOffset, bool markAll, RefPt rWillBeRawPtr<Range>& firstMisspellingRange); | 90 String findFirstMisspelling(int& firstMisspellingOffset, bool markAll, RefPt rWillBeRawPtr<Range>& firstMisspellingRange); |
88 String findFirstMisspellingOrBadGrammar(bool checkGrammar, bool& outIsSpelli ng, int& outFirstFoundOffset, GrammarDetail& outGrammarDetail); | 91 String findFirstMisspellingOrBadGrammar(bool checkGrammar, bool& outIsSpelli ng, int& outFirstFoundOffset, GrammarDetail& outGrammarDetail); |
89 String findFirstBadGrammar(GrammarDetail& outGrammarDetail, int& outGrammarP hraseOffset, bool markAll); | 92 String findFirstBadGrammar(GrammarDetail& outGrammarDetail, int& outGrammarP hraseOffset, bool markAll); |
90 void markAllMisspellings(RefPtrWillBeRawPtr<Range>& firstMisspellingRange); | 93 void markAllMisspellings(RefPtrWillBeRawPtr<Range>& firstMisspellingRange); |
91 void markAllBadGrammar(); | 94 void markAllBadGrammar(); |
92 | 95 |
93 private: | 96 private: |
94 SpellCheckerClient* m_client; | 97 SpellCheckerClient* m_client; |
95 Position m_start; | 98 Position m_start; |
96 Position m_end; | 99 Position m_end; |
97 | 100 |
98 int findFirstGrammarDetail(const Vector<GrammarDetail>& grammarDetails, int badGrammarPhraseLocation, int startOffset, int endOffset, bool markAll) const; | 101 int findFirstGrammarDetail(const Vector<GrammarDetail>& grammarDetails, int badGrammarPhraseLocation, int startOffset, int endOffset, bool markAll) const; |
99 bool unifiedTextCheckerEnabled() const; | 102 bool unifiedTextCheckerEnabled() const; |
100 }; | 103 }; |
101 | 104 |
102 void checkTextOfParagraph(TextCheckerClient&, const String&, TextCheckingTypeMas k, Vector<TextCheckingResult>&); | 105 void checkTextOfParagraph(TextCheckerClient&, const String&, TextCheckingTypeMas k, Vector<TextCheckingResult>&); |
103 void expandRangeToSentenceBoundary(Range&); | 106 EphemeralRange expandRangeToSentenceBoundary(const EphemeralRange&); |
104 bool unifiedTextCheckerEnabled(const LocalFrame*); | 107 bool unifiedTextCheckerEnabled(const LocalFrame*); |
105 | 108 |
106 } // namespace blink | 109 } // namespace blink |
107 | 110 |
108 #endif // TextCheckingHelper_h | 111 #endif // TextCheckingHelper_h |
OLD | NEW |