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..c3da542c4b1d6bc23435dbc4a158846521364bed 100644 |
| --- a/third_party/WebKit/Source/core/editing/markers/DocumentMarker.h |
| +++ b/third_party/WebKit/Source/core/editing/markers/DocumentMarker.h |
| @@ -55,6 +55,34 @@ class CORE_EXPORT DocumentMarker : public GarbageCollected<DocumentMarker> { |
| Composition = 1 << CompositionMarkerIndex, |
| }; |
| + class MarkerTypesIterator { |
|
yosin_UTC9
2017/03/22 04:06:26
Let's add
std::iterator<std::forward_iterator_tag
|
| + 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 !(*this == other); |
|
yosin_UTC9
2017/03/22 04:06:26
How about |!operator==(other)| to be more explicit
|
| + } |
| + |
| + MarkerTypesIterator& operator++() { |
| + DCHECK(m_remainingTypes); |
| + 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
|
| + return *this; |
| + } |
| + |
| + MarkerType operator*() const { |
| + DCHECK(m_remainingTypes); |
| + 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
|
| + } |
| + |
| + private: |
| + unsigned m_remainingTypes; |
| + }; |
| + |
| class MarkerTypes { |
| public: |
| // The constructor is intentionally implicit to allow conversion from the |
| @@ -72,6 +100,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; |
| }; |