Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(890)

Unified Diff: Source/core/editing/CompositionUnderlineRangeFilter.h

Issue 313233002: Adding backgroundColor to WebCompositionUnderline and using it for InlineTextBox drawing. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Renaming to CompositionUnderlineRangeFilter and using .begin(), .end(); adding unit test. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..a7c42336fcfbba9de07407f39372c75041837fd2
--- /dev/null
+++ b/Source/core/editing/CompositionUnderlineRangeFilter.h
@@ -0,0 +1,77 @@
+// 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/Vector.h"
+
+namespace WebCore {
+
+// A visitor class to yield elements of a sorted (by startOffset) list of underlines,
+// visiting only elements that inersect with specified *inclusive* range [indexLo, indexHi].
huangs 2014/06/06 23:38:32 TYPO: inersect
huangs 2014/06/09 06:07:13 Done.
+class CompositionUnderlineRangeFilter {
+ WTF_MAKE_NONCOPYABLE(CompositionUnderlineRangeFilter);
+public:
+ class ConstIterator {
+ public:
+ enum {
+ END = -0x7FFFFFFF
yosin_UTC9 2014/06/09 01:49:56 nit: better to use kNotFound in wtf/NotFound.h, or
huangs 2014/06/09 06:07:13 Ah neat. Using kNotFound. Note the change in oper
+ };
+ ConstIterator(): m_filter(nullptr), m_index(0) { }
+ const CompositionUnderline& operator*()
+ {
+ ASSERT(m_index >= 0);
+ return m_filter->m_underlines[m_index];
+ }
+ ConstIterator& operator++()
+ {
+ 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 CompositionUnderlineRangeFilter;
+
+ ConstIterator(CompositionUnderlineRangeFilter* filter, int index)
yosin_UTC9 2014/06/09 01:49:56 nit: We should use |size_t| rather than |int|. Som
huangs 2014/06/09 06:07:13 Done.
+ : m_filter(filter)
+ , m_index(index) { }
+ CompositionUnderlineRangeFilter* m_filter;
+ int m_index;
+ };
+
+ CompositionUnderlineRangeFilter(const Vector<CompositionUnderline>& underlines, size_t indexLo, size_t indexHi)
+ : m_underlines(underlines)
+ , m_indexLo(indexLo)
+ , m_indexHi(indexHi)
+ , m_theEnd(this, ConstIterator::END)
+ , m_nextIndex(0) { }
huangs 2014/06/06 23:38:32 Delete m_nextIndex.
huangs 2014/06/09 06:07:13 Done.
+
+ ConstIterator begin() { return ConstIterator(this, seekValidIndex(0)); }
+ const ConstIterator& end() { return m_theEnd; }
+
+private:
+ friend 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.
+ int seekValidIndex(int index);
+
+ // Assume that elements of |m_underlines| are sorted by |.startOffset|.
+ const Vector<CompositionUnderline>& m_underlines;
+ const size_t m_indexLo;
+ const size_t m_indexHi;
+ const ConstIterator m_theEnd;
+ size_t m_nextIndex;
+};
+
+} // namespace WebCore
+
+#endif

Powered by Google App Engine
This is Rietveld 408576698