Index: Source/core/editing/CompositionUnderlineRangeFilter.h |
diff --git a/Source/core/editing/CompositionUnderlineRangeFilter.h b/Source/core/editing/CompositionUnderlineRangeFilter.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..7725c65362fd4e350d3f184959b51ca8e13a9fa5 |
--- /dev/null |
+++ b/Source/core/editing/CompositionUnderlineRangeFilter.h |
@@ -0,0 +1,75 @@ |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#ifndef CompositionUnderlineRangeFilter_h |
+#define CompositionUnderlineRangeFilter_h |
+ |
+#include "core/editing/CompositionUnderline.h" |
+#include "wtf/NotFound.h" |
+#include "wtf/Vector.h" |
+ |
+namespace WebCore { |
+ |
+// A visitor class to yield elements of a sorted (by startOffset) list of underlines, |
+// visiting only elements that intersect with specified *inclusive* range [indexLo, indexHi]. |
+class CompositionUnderlineRangeFilter { |
+ WTF_MAKE_NONCOPYABLE(CompositionUnderlineRangeFilter); |
+public: |
+ class ConstIterator { |
+ public: |
+ ConstIterator(): m_filter(nullptr), m_index(0) { } |
+ const CompositionUnderline& operator*() |
+ { |
+ ASSERT(m_index >= 0); |
yosin_UTC9
2014/06/12 06:23:17
nit: We don't need to have this |ASSERT|, since |m
huangs
2014/06/12 23:22:10
Oops, should use
ASSERT(m_index != kNotFound);
|
+ return m_filter->m_underlines[m_index]; |
+ } |
+ ConstIterator& operator++() |
+ { |
+ if (m_index != kNotFound) |
+ m_index = m_filter->seekValidIndex(m_index + 1); |
+ return *this; |
+ } |
+ bool operator==(const ConstIterator& other) |
+ { |
+ return other.m_index == m_index && other.m_filter == m_filter; |
+ } |
+ bool operator!=(const ConstIterator& other) { return !operator==(other); } |
+ |
+ private: |
+ friend class CompositionUnderlineRangeFilter; |
+ |
+ ConstIterator(CompositionUnderlineRangeFilter* filter, size_t index) |
+ : m_filter(filter) |
+ , m_index(index) { } |
+ CompositionUnderlineRangeFilter* m_filter; |
+ size_t m_index; |
+ }; |
+ |
+ CompositionUnderlineRangeFilter(const Vector<CompositionUnderline>& underlines, size_t indexLo, size_t indexHi) |
yosin_UTC9
2014/06/12 06:23:17
nit: Let's move multiple line implementation funct
huangs
2014/06/12 23:22:09
Done.
|
+ : m_underlines(underlines) |
+ , m_indexLo(indexLo) |
+ , m_indexHi(indexHi) |
+ , m_theEnd(this, kNotFound) { } |
+ |
+ ConstIterator begin() { return ConstIterator(this, seekValidIndex(0)); } |
+ const ConstIterator& end() { return m_theEnd; } |
+ |
+private: |
+ friend class ConstIterator; |
+ |
+ // Returns |index| if |m_underlines[index]| intersects with range [m_indexLo, m_indexHi]. |
+ // Otherwise returns the index of the next intersecting interval, or END if there are none left. |
+ size_t seekValidIndex(size_t index); |
+ |
+ // Assume that elements of |m_underlines| are sorted by |.startOffset|. |
+ const Vector<CompositionUnderline>& m_underlines; |
+ // The "query range" is the inclusive range [m_indexLo, m_indexHi]. |
+ const size_t m_indexLo; |
+ const size_t m_indexHi; |
+ const ConstIterator m_theEnd; |
+}; |
+ |
+} // namespace WebCore |
+ |
+#endif |