Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/markers/DocumentMarker.h |
| diff --git a/third_party/WebKit/Source/core/editing/markers/DocumentMarker.h b/third_party/WebKit/Source/core/editing/markers/DocumentMarker.h |
| index 7db49d1a45320fa4724c6a664cb6a6d88e08a618..b0bbbd2390ffe02d13a483c4fa2c4dba2c967196 100644 |
| --- a/third_party/WebKit/Source/core/editing/markers/DocumentMarker.h |
| +++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarker.h |
| @@ -55,6 +55,45 @@ class CORE_EXPORT DocumentMarker : public GarbageCollected<DocumentMarker> { |
| Composition = 1 << CompositionMarkerIndex, |
| }; |
| + class MarkerTypesIterator |
| + : public std::iterator<std::forward_iterator_tag, MarkerType> { |
| + public: |
| + explicit MarkerTypesIterator(unsigned markerTypes) |
| + : m_remainingTypes(markerTypes) {} |
| + MarkerTypesIterator(const MarkerTypesIterator& other) = default; |
| + |
| + bool operator==(const MarkerTypesIterator& other) { |
| + return m_remainingTypes == other.m_remainingTypes; |
| + } |
| + bool operator!=(const MarkerTypesIterator& other) { |
| + return !operator==(other); |
| + } |
| + |
| + MarkerTypesIterator& operator++() { |
| + DCHECK(m_remainingTypes); |
| + // Turn off rightmost 1-bit (from Hacker's Delight 2-1) |
|
Xiaocheng
2017/03/22 17:57:05
nit: I prefer "least significant bit" to be more p
|
| + // Example: |
| + // 7: 7 & 6 = 6 |
| + // 6: 6 & 5 = 4 |
| + // 4: 4 & 3 = 0 |
| + m_remainingTypes &= (m_remainingTypes - 1); |
| + return *this; |
| + } |
| + |
| + MarkerType operator*() const { |
| + DCHECK(m_remainingTypes); |
| + // Isolate rightmost 1-bit (from Hacker's Delight 2-1) |
|
Xiaocheng
2017/03/22 17:57:05
nit: ditto
|
| + // Example: |
| + // 7: 7 & -7 = 1 |
| + // 6: 6 & -6 = 2 |
| + // 4: 4 & -4 = 4 |
| + return static_cast<MarkerType>(m_remainingTypes & -m_remainingTypes); |
| + } |
| + |
| + private: |
| + unsigned m_remainingTypes; |
| + }; |
| + |
| class MarkerTypes { |
| public: |
| // The constructor is intentionally implicit to allow conversion from the |
| @@ -72,6 +111,9 @@ class CORE_EXPORT DocumentMarker : public GarbageCollected<DocumentMarker> { |
| void add(const MarkerTypes& types) { m_mask |= types.m_mask; } |
| void remove(const MarkerTypes& types) { m_mask &= ~types.m_mask; } |
| + MarkerTypesIterator begin() const { return MarkerTypesIterator(m_mask); } |
| + MarkerTypesIterator end() const { return MarkerTypesIterator(0); } |
| + |
| private: |
| unsigned m_mask; |
| }; |