~ubuntu-branches/ubuntu/raring/qtwebkit-source/raring-proposed

« back to all changes in this revision

Viewing changes to Source/WebCore/editing/TextCheckingHelper.h

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2013-02-18 14:24:18 UTC
  • Revision ID: package-import@ubuntu.com-20130218142418-eon0jmjg3nj438uy
Tags: upstream-2.3
ImportĀ upstreamĀ versionĀ 2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
 
3
 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
 
4
 *
 
5
 * This library is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU Library General Public
 
7
 * License as published by the Free Software Foundation; either
 
8
 * version 2 of the License, or (at your option) any later version.
 
9
 *
 
10
 * This library is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
13
 * Library General Public License for more details.
 
14
 *
 
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
 
17
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
18
 * Boston, MA 02110-1301, USA.
 
19
 */
 
20
 
 
21
#ifndef TextCheckingHelper_h
 
22
#define TextCheckingHelper_h
 
23
 
 
24
#include "EditorClient.h"
 
25
#include "ExceptionCode.h"
 
26
#include "TextChecking.h"
 
27
#include <wtf/text/WTFString.h>
 
28
 
 
29
namespace WebCore {
 
30
 
 
31
class Range;
 
32
class Position;
 
33
struct TextCheckingResult;
 
34
 
 
35
class TextCheckingParagraph {
 
36
public:
 
37
    explicit TextCheckingParagraph(PassRefPtr<Range> checkingRange);
 
38
    TextCheckingParagraph(PassRefPtr<Range> checkingRange, PassRefPtr<Range> paragraphRange);
 
39
    ~TextCheckingParagraph();
 
40
 
 
41
    int rangeLength() const;
 
42
    PassRefPtr<Range> subrange(int characterOffset, int characterCount) const;
 
43
    int offsetTo(const Position&, ExceptionCode&) const;
 
44
    void expandRangeToNextEnd();
 
45
 
 
46
    int textLength() const { return text().length(); }
 
47
    String textSubstring(unsigned pos, unsigned len = UINT_MAX) const { return text().substring(pos, len); }
 
48
    const UChar* textCharacters() const { return text().characters(); }
 
49
    UChar textCharAt(int index) const { return text()[static_cast<unsigned>(index)]; }
 
50
 
 
51
    bool isEmpty() const;
 
52
    bool isTextEmpty() const { return text().isEmpty(); }
 
53
    bool isRangeEmpty() const { return checkingStart() >= checkingEnd(); }
 
54
 
 
55
    int checkingStart() const;
 
56
    int checkingEnd() const;
 
57
    int checkingLength() const;
 
58
    String checkingSubstring() const { return textSubstring(checkingStart(), checkingLength()); }
 
59
 
 
60
    bool checkingRangeMatches(int location, int length) const { return location == checkingStart() && length == checkingLength(); }
 
61
    bool isCheckingRangeCoveredBy(int location, int length) const { return location <= checkingStart() && location + length >= checkingStart() + checkingLength(); }
 
62
    bool checkingRangeCovers(int location, int length) const { return location < checkingEnd() && location + length > checkingStart(); }
 
63
    PassRefPtr<Range> paragraphRange() const;
 
64
 
 
65
private:
 
66
    void invalidateParagraphRangeValues();
 
67
    PassRefPtr<Range> checkingRange() const { return m_checkingRange; }
 
68
    PassRefPtr<Range> offsetAsRange() const;
 
69
    const String& text() const;
 
70
 
 
71
    RefPtr<Range> m_checkingRange;
 
72
    mutable RefPtr<Range> m_paragraphRange;
 
73
    mutable RefPtr<Range> m_offsetAsRange;
 
74
    mutable String m_text;
 
75
    mutable int m_checkingStart;
 
76
    mutable int m_checkingEnd;
 
77
    mutable int m_checkingLength;
 
78
};
 
79
 
 
80
class TextCheckingHelper {
 
81
    WTF_MAKE_NONCOPYABLE(TextCheckingHelper);
 
82
public:
 
83
    TextCheckingHelper(EditorClient*, PassRefPtr<Range>);
 
84
    ~TextCheckingHelper();
 
85
 
 
86
    String findFirstMisspelling(int& firstMisspellingOffset, bool markAll, RefPtr<Range>& firstMisspellingRange);
 
87
    String findFirstMisspellingOrBadGrammar(bool checkGrammar, bool& outIsSpelling, int& outFirstFoundOffset, GrammarDetail& outGrammarDetail);
 
88
    String findFirstBadGrammar(GrammarDetail& outGrammarDetail, int& outGrammarPhraseOffset, bool markAll);
 
89
    int findFirstGrammarDetail(const Vector<GrammarDetail>& grammarDetails, int badGrammarPhraseLocation, int badGrammarPhraseLength, int startOffset, int endOffset, bool markAll);
 
90
    void markAllMisspellings(RefPtr<Range>& firstMisspellingRange);
 
91
    void markAllBadGrammar();
 
92
 
 
93
    bool isUngrammatical(Vector<String>& guessesVector) const;
 
94
    Vector<String> guessesForMisspelledOrUngrammaticalRange(bool checkGrammar, bool& misspelled, bool& ungrammatical) const;
 
95
private:
 
96
    EditorClient* m_client;
 
97
    RefPtr<Range> m_range;
 
98
 
 
99
    bool unifiedTextCheckerEnabled() const;
 
100
};
 
101
 
 
102
void checkTextOfParagraph(TextCheckerClient*, const UChar* text, int length,
 
103
    TextCheckingTypeMask checkingTypes, Vector<TextCheckingResult>& results);
 
104
 
 
105
bool unifiedTextCheckerEnabled(const Frame*);
 
106
 
 
107
} // namespace WebCore
 
108
 
 
109
#endif // TextCheckingHelper_h