| 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 |
| 59 : public std::iterator<std::forward_iterator_tag, MarkerType> { |
| 60 public: |
| 61 explicit MarkerTypesIterator(unsigned markerTypes) |
| 62 : m_remainingTypes(markerTypes) {} |
| 63 MarkerTypesIterator(const MarkerTypesIterator& other) = default; |
| 64 |
| 65 bool operator==(const MarkerTypesIterator& other) { |
| 66 return m_remainingTypes == other.m_remainingTypes; |
| 67 } |
| 68 bool operator!=(const MarkerTypesIterator& other) { |
| 69 return !operator==(other); |
| 70 } |
| 71 |
| 72 MarkerTypesIterator& operator++() { |
| 73 DCHECK(m_remainingTypes); |
| 74 // Turn off least significant 1-bit (from Hacker's Delight 2-1) |
| 75 // Example: |
| 76 // 7: 7 & 6 = 6 |
| 77 // 6: 6 & 5 = 4 |
| 78 // 4: 4 & 3 = 0 |
| 79 m_remainingTypes &= (m_remainingTypes - 1); |
| 80 return *this; |
| 81 } |
| 82 |
| 83 MarkerType operator*() const { |
| 84 DCHECK(m_remainingTypes); |
| 85 // Isolate least significant 1-bit (from Hacker's Delight 2-1) |
| 86 // Example: |
| 87 // 7: 7 & -7 = 1 |
| 88 // 6: 6 & -6 = 2 |
| 89 // 4: 4 & -4 = 4 |
| 90 return static_cast<MarkerType>(m_remainingTypes & |
| 91 (~m_remainingTypes + 1)); |
| 92 } |
| 93 |
| 94 private: |
| 95 unsigned m_remainingTypes; |
| 96 }; |
| 97 |
| 58 class MarkerTypes { | 98 class MarkerTypes { |
| 59 public: | 99 public: |
| 60 // The constructor is intentionally implicit to allow conversion from the | 100 // The constructor is intentionally implicit to allow conversion from the |
| 61 // bit-wise sum of above types | 101 // bit-wise sum of above types |
| 62 MarkerTypes(unsigned mask) : m_mask(mask) {} | 102 MarkerTypes(unsigned mask) : m_mask(mask) {} |
| 63 | 103 |
| 64 bool contains(MarkerType type) const { return m_mask & type; } | 104 bool contains(MarkerType type) const { return m_mask & type; } |
| 65 bool intersects(const MarkerTypes& types) const { | 105 bool intersects(const MarkerTypes& types) const { |
| 66 return (m_mask & types.m_mask); | 106 return (m_mask & types.m_mask); |
| 67 } | 107 } |
| 68 bool operator==(const MarkerTypes& other) const { | 108 bool operator==(const MarkerTypes& other) const { |
| 69 return m_mask == other.m_mask; | 109 return m_mask == other.m_mask; |
| 70 } | 110 } |
| 71 | 111 |
| 72 void add(const MarkerTypes& types) { m_mask |= types.m_mask; } | 112 void add(const MarkerTypes& types) { m_mask |= types.m_mask; } |
| 73 void remove(const MarkerTypes& types) { m_mask &= ~types.m_mask; } | 113 void remove(const MarkerTypes& types) { m_mask &= ~types.m_mask; } |
| 74 | 114 |
| 115 MarkerTypesIterator begin() const { return MarkerTypesIterator(m_mask); } |
| 116 MarkerTypesIterator end() const { return MarkerTypesIterator(0); } |
| 117 |
| 75 private: | 118 private: |
| 76 unsigned m_mask; | 119 unsigned m_mask; |
| 77 }; | 120 }; |
| 78 | 121 |
| 79 class AllMarkers : public MarkerTypes { | 122 class AllMarkers : public MarkerTypes { |
| 80 public: | 123 public: |
| 81 AllMarkers() : MarkerTypes(Spelling | Grammar | TextMatch | Composition) {} | 124 AllMarkers() : MarkerTypes(Spelling | Grammar | TextMatch | Composition) {} |
| 82 }; | 125 }; |
| 83 | 126 |
| 84 class MisspellingMarkers : public MarkerTypes { | 127 class MisspellingMarkers : public MarkerTypes { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 virtual bool isDescription() const { return false; } | 197 virtual bool isDescription() const { return false; } |
| 155 virtual bool isTextMatch() const { return false; } | 198 virtual bool isTextMatch() const { return false; } |
| 156 virtual bool isComposition() const { return false; } | 199 virtual bool isComposition() const { return false; } |
| 157 | 200 |
| 158 DEFINE_INLINE_VIRTUAL_TRACE() {} | 201 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 159 }; | 202 }; |
| 160 | 203 |
| 161 } // namespace blink | 204 } // namespace blink |
| 162 | 205 |
| 163 #endif // DocumentMarker_h | 206 #endif // DocumentMarker_h |
| OLD | NEW |