• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the DOM implementation for WebCore.
3  *
4  * Copyright (C) 2006 Apple Computer, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public License
17  * along with this library; see the file COPYING.LIB.  If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef DocumentMarker_h
24 #define DocumentMarker_h
25 
26 #include "PlatformString.h"
27 #include <wtf/Forward.h>
28 
29 namespace WebCore {
30 
31 // A range of a node within a document that is "marked", such as the range of a misspelled word.
32 // It optionally includes a description that could be displayed in the user interface.
33 // It also optionally includes a flag specifying whether the match is active, which is ignored
34 // for all types other than type TextMatch.
35 struct DocumentMarker {
36     enum MarkerType {
37         Spelling = 1 << 0,
38         Grammar = 1 << 1,
39         TextMatch = 1 << 2,
40         // Text has been modified by spell correction, reversion of spell correction or other type of substitution.
41         // On some platforms, this prevents the text from being autocorrected again. On post Snow Leopard Mac OS X,
42         // if a Replacement marker contains non-empty description, a reversion UI will be shown.
43         Replacement = 1 << 3,
44         // Renderer needs to add underline indicating that the text has been modified by spell
45         // correction. Text with Replacement marker doesn't necessarily has CorrectionIndicator
46         // marker. For instance, after some text has been corrected, it will have both Replacement
47         // and CorrectionIndicator. However, if user further modifies such text, we would remove
48         // CorrectionIndicator marker, but retain Replacement marker.
49         CorrectionIndicator = 1 << 4,
50         // Correction suggestion has been offered, but got rejected by user.
51         RejectedCorrection = 1 << 5,
52         // Text has been modified by autocorrection. The description of this marker is the original text before autocorrection.
53         Autocorrected = 1 << 6,
54         // On some platforms, this prevents the text from being spellchecked again.
55         SpellCheckingExemption = 1 << 7,
56     };
57 
58     class MarkerTypes {
59     public:
60         // The constructor is intentionally implicit to allow conversion from the bit-wise sum of above types
MarkerTypesDocumentMarker61         MarkerTypes(unsigned mask) : m_mask(mask) { }
62 
containsDocumentMarker63         bool contains(MarkerType type) const { return m_mask & type; }
intersectsDocumentMarker64         bool intersects(const MarkerTypes& types) const { return (m_mask & types.m_mask); }
65         bool operator==(const MarkerTypes& other) const { return m_mask == other.m_mask; }
66 
addDocumentMarker67         void add(const MarkerTypes& types) { m_mask |= types.m_mask; }
removeDocumentMarker68         void remove(const MarkerTypes& types) { m_mask &= ~types.m_mask; }
69 
70     private:
71         unsigned m_mask;
72     };
73 
74     class AllMarkers : public MarkerTypes {
75     public:
AllMarkersDocumentMarker76         AllMarkers()
77             : MarkerTypes(Spelling | Grammar | TextMatch | Replacement | CorrectionIndicator | RejectedCorrection | Autocorrected | SpellCheckingExemption)
78         {
79         }
80     };
81 
82     MarkerType type;
83     unsigned startOffset;
84     unsigned endOffset;
85     String description;
86     bool activeMatch;
87 
88     bool operator==(const DocumentMarker& o) const
89     {
90         return type == o.type && startOffset == o.startOffset && endOffset == o.endOffset;
91     }
92 
93     bool operator!=(const DocumentMarker& o) const
94     {
95         return !(*this == o);
96     }
97 };
98 
99 } // namespace WebCore
100 
101 #endif // DocumentMarker_h
102