OLD | NEW |
---|---|
1 /* | 1 /* |
2 * This file is part of the DOM implementation for WebCore. | 2 * This file is part of the DOM implementation for WebCore. |
3 * | 3 * |
4 * Copyright (C) 2006 Apple Computer, Inc. | 4 * Copyright (C) 2006 Apple Computer, Inc. |
5 * | 5 * |
6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
10 * | 10 * |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 MarkerTypeIndexesCount | 48 MarkerTypeIndexesCount |
49 }; | 49 }; |
50 | 50 |
51 enum MarkerType { | 51 enum MarkerType { |
52 Spelling = 1 << SpellingMarkerIndex, | 52 Spelling = 1 << SpellingMarkerIndex, |
53 Grammar = 1 << GrammarMarkerIndex, | 53 Grammar = 1 << GrammarMarkerIndex, |
54 TextMatch = 1 << TextMatchMarkerIndex, | 54 TextMatch = 1 << TextMatchMarkerIndex, |
55 Composition = 1 << CompositionMarkerIndex, | 55 Composition = 1 << CompositionMarkerIndex, |
56 }; | 56 }; |
57 | 57 |
58 class MarkerTypesIterator { | |
yosin_UTC9
2017/03/22 04:06:26
Let's add
std::iterator<std::forward_iterator_tag
| |
59 public: | |
60 explicit MarkerTypesIterator(unsigned markerTypes) | |
61 : m_remainingTypes(markerTypes) {} | |
62 MarkerTypesIterator(const MarkerTypesIterator& other) = default; | |
63 | |
64 bool operator==(const MarkerTypesIterator& other) { | |
65 return m_remainingTypes == other.m_remainingTypes; | |
66 } | |
67 bool operator!=(const MarkerTypesIterator& other) { | |
68 return !(*this == other); | |
yosin_UTC9
2017/03/22 04:06:26
How about |!operator==(other)| to be more explicit
| |
69 } | |
70 | |
71 MarkerTypesIterator& operator++() { | |
72 DCHECK(m_remainingTypes); | |
73 m_remainingTypes &= (m_remainingTypes - 1); | |
yosin_UTC9
2017/03/22 04:06:26
Let's add a comment: turn off right most 1-bit
(f
| |
74 return *this; | |
75 } | |
76 | |
77 MarkerType operator*() const { | |
78 DCHECK(m_remainingTypes); | |
79 return static_cast<MarkerType>(m_remainingTypes & -m_remainingTypes); | |
yosin_UTC9
2017/03/22 04:06:26
Let's add comment: Isolate the right most 1-bit
(f
| |
80 } | |
81 | |
82 private: | |
83 unsigned m_remainingTypes; | |
84 }; | |
85 | |
58 class MarkerTypes { | 86 class MarkerTypes { |
59 public: | 87 public: |
60 // The constructor is intentionally implicit to allow conversion from the | 88 // The constructor is intentionally implicit to allow conversion from the |
61 // bit-wise sum of above types | 89 // bit-wise sum of above types |
62 MarkerTypes(unsigned mask) : m_mask(mask) {} | 90 MarkerTypes(unsigned mask) : m_mask(mask) {} |
63 | 91 |
64 bool contains(MarkerType type) const { return m_mask & type; } | 92 bool contains(MarkerType type) const { return m_mask & type; } |
65 bool intersects(const MarkerTypes& types) const { | 93 bool intersects(const MarkerTypes& types) const { |
66 return (m_mask & types.m_mask); | 94 return (m_mask & types.m_mask); |
67 } | 95 } |
68 bool operator==(const MarkerTypes& other) const { | 96 bool operator==(const MarkerTypes& other) const { |
69 return m_mask == other.m_mask; | 97 return m_mask == other.m_mask; |
70 } | 98 } |
71 | 99 |
72 void add(const MarkerTypes& types) { m_mask |= types.m_mask; } | 100 void add(const MarkerTypes& types) { m_mask |= types.m_mask; } |
73 void remove(const MarkerTypes& types) { m_mask &= ~types.m_mask; } | 101 void remove(const MarkerTypes& types) { m_mask &= ~types.m_mask; } |
74 | 102 |
103 MarkerTypesIterator begin() const { return MarkerTypesIterator(m_mask); } | |
104 MarkerTypesIterator end() const { return MarkerTypesIterator(0); } | |
105 | |
75 private: | 106 private: |
76 unsigned m_mask; | 107 unsigned m_mask; |
77 }; | 108 }; |
78 | 109 |
79 class AllMarkers : public MarkerTypes { | 110 class AllMarkers : public MarkerTypes { |
80 public: | 111 public: |
81 AllMarkers() : MarkerTypes(Spelling | Grammar | TextMatch | Composition) {} | 112 AllMarkers() : MarkerTypes(Spelling | Grammar | TextMatch | Composition) {} |
82 }; | 113 }; |
83 | 114 |
84 class MisspellingMarkers : public MarkerTypes { | 115 class MisspellingMarkers : public MarkerTypes { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
154 virtual bool isDescription() const { return false; } | 185 virtual bool isDescription() const { return false; } |
155 virtual bool isTextMatch() const { return false; } | 186 virtual bool isTextMatch() const { return false; } |
156 virtual bool isComposition() const { return false; } | 187 virtual bool isComposition() const { return false; } |
157 | 188 |
158 DEFINE_INLINE_VIRTUAL_TRACE() {} | 189 DEFINE_INLINE_VIRTUAL_TRACE() {} |
159 }; | 190 }; |
160 | 191 |
161 } // namespace blink | 192 } // namespace blink |
162 | 193 |
163 #endif // DocumentMarker_h | 194 #endif // DocumentMarker_h |
OLD | NEW |