Chromium Code Reviews| 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 & -m_remainingTypes); | |
|
rlanday
2017/03/22 18:38:18
xiaochengh, MSVC is throwing a compiler warning on
| |
| 91 } | |
| 92 | |
| 93 private: | |
| 94 unsigned m_remainingTypes; | |
| 95 }; | |
| 96 | |
| 58 class MarkerTypes { | 97 class MarkerTypes { |
| 59 public: | 98 public: |
| 60 // The constructor is intentionally implicit to allow conversion from the | 99 // The constructor is intentionally implicit to allow conversion from the |
| 61 // bit-wise sum of above types | 100 // bit-wise sum of above types |
| 62 MarkerTypes(unsigned mask) : m_mask(mask) {} | 101 MarkerTypes(unsigned mask) : m_mask(mask) {} |
| 63 | 102 |
| 64 bool contains(MarkerType type) const { return m_mask & type; } | 103 bool contains(MarkerType type) const { return m_mask & type; } |
| 65 bool intersects(const MarkerTypes& types) const { | 104 bool intersects(const MarkerTypes& types) const { |
| 66 return (m_mask & types.m_mask); | 105 return (m_mask & types.m_mask); |
| 67 } | 106 } |
| 68 bool operator==(const MarkerTypes& other) const { | 107 bool operator==(const MarkerTypes& other) const { |
| 69 return m_mask == other.m_mask; | 108 return m_mask == other.m_mask; |
| 70 } | 109 } |
| 71 | 110 |
| 72 void add(const MarkerTypes& types) { m_mask |= types.m_mask; } | 111 void add(const MarkerTypes& types) { m_mask |= types.m_mask; } |
| 73 void remove(const MarkerTypes& types) { m_mask &= ~types.m_mask; } | 112 void remove(const MarkerTypes& types) { m_mask &= ~types.m_mask; } |
| 74 | 113 |
| 114 MarkerTypesIterator begin() const { return MarkerTypesIterator(m_mask); } | |
| 115 MarkerTypesIterator end() const { return MarkerTypesIterator(0); } | |
| 116 | |
| 75 private: | 117 private: |
| 76 unsigned m_mask; | 118 unsigned m_mask; |
| 77 }; | 119 }; |
| 78 | 120 |
| 79 class AllMarkers : public MarkerTypes { | 121 class AllMarkers : public MarkerTypes { |
| 80 public: | 122 public: |
| 81 AllMarkers() : MarkerTypes(Spelling | Grammar | TextMatch | Composition) {} | 123 AllMarkers() : MarkerTypes(Spelling | Grammar | TextMatch | Composition) {} |
| 82 }; | 124 }; |
| 83 | 125 |
| 84 class MisspellingMarkers : public MarkerTypes { | 126 class MisspellingMarkers : public MarkerTypes { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 virtual bool isDescription() const { return false; } | 196 virtual bool isDescription() const { return false; } |
| 155 virtual bool isTextMatch() const { return false; } | 197 virtual bool isTextMatch() const { return false; } |
| 156 virtual bool isComposition() const { return false; } | 198 virtual bool isComposition() const { return false; } |
| 157 | 199 |
| 158 DEFINE_INLINE_VIRTUAL_TRACE() {} | 200 DEFINE_INLINE_VIRTUAL_TRACE() {} |
| 159 }; | 201 }; |
| 160 | 202 |
| 161 } // namespace blink | 203 } // namespace blink |
| 162 | 204 |
| 163 #endif // DocumentMarker_h | 205 #endif // DocumentMarker_h |
| OLD | NEW |