OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef LineLayoutSVGInlineText_h | 5 #ifndef LineLayoutSVGInlineText_h |
6 #define LineLayoutSVGInlineText_h | 6 #define LineLayoutSVGInlineText_h |
7 | 7 |
8 #include "core/layout/api/LineLayoutText.h" | 8 #include "core/layout/api/LineLayoutText.h" |
9 #include "core/layout/svg/LayoutSVGInlineText.h" | 9 #include "core/layout/svg/LayoutSVGInlineText.h" |
10 | 10 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
56 | 56 |
57 const LayoutSVGInlineText* toSVGInlineText() const | 57 const LayoutSVGInlineText* toSVGInlineText() const |
58 { | 58 { |
59 return toLayoutSVGInlineText(layoutObject()); | 59 return toLayoutSVGInlineText(layoutObject()); |
60 } | 60 } |
61 }; | 61 }; |
62 | 62 |
63 class SVGInlineTextMetricsIterator { | 63 class SVGInlineTextMetricsIterator { |
64 DISALLOW_NEW(); | 64 DISALLOW_NEW(); |
65 public: | 65 public: |
66 SVGInlineTextMetricsIterator() { reset(nullptr); } | 66 SVGInlineTextMetricsIterator() { reset(LineLayoutSVGInlineText()); } |
67 | 67 |
68 void advanceToTextStart(LineLayoutSVGInlineText* textLineLayout, unsigned st artCharacterOffset) | 68 void advanceToTextStart(LineLayoutSVGInlineText textLineLayout, unsigned sta rtCharacterOffset) |
69 { | 69 { |
70 #if ENABLE(ASSERT) | |
71 assertCharacterOffsetFromMetricsList(); | |
72 #endif | |
70 ASSERT(textLineLayout); | 73 ASSERT(textLineLayout); |
71 if (m_textLineLayout != textLineLayout) { | 74 if (!m_textLineLayout || !m_textLineLayout.isEqual(textLineLayout)) { |
72 reset(textLineLayout); | 75 reset(textLineLayout); |
73 ASSERT(!metricsList().isEmpty()); | 76 ASSERT(!metricsList().isEmpty()); |
74 } | 77 } |
75 | 78 |
76 if (m_characterOffset == startCharacterOffset) | 79 if (m_characterOffset == startCharacterOffset) |
77 return; | 80 return; |
78 | 81 |
79 // TODO(fs): We could walk backwards through the metrics list in these c ases. | 82 // TODO(fs): We could walk backwards through the metrics list in these c ases. |
80 if (m_characterOffset > startCharacterOffset) | 83 if (m_characterOffset > startCharacterOffset) |
81 reset(textLineLayout); | 84 reset(textLineLayout); |
82 | 85 |
83 while (m_characterOffset < startCharacterOffset) | 86 while (m_characterOffset < startCharacterOffset) |
84 next(); | 87 next(); |
88 ASSERT(m_characterOffset == startCharacterOffset); | |
85 } | 89 } |
86 | 90 |
87 void next() | 91 void next() |
88 { | 92 { |
89 m_characterOffset += metrics().length(); | 93 m_characterOffset += metrics().length(); |
94 ASSERT(m_characterOffset <= m_textLineLayout.length()); | |
95 ASSERT(m_metricsListOffset < metricsList().size()); | |
90 ++m_metricsListOffset; | 96 ++m_metricsListOffset; |
91 } | 97 } |
92 | 98 |
93 const SVGTextMetrics& metrics() const | 99 const SVGTextMetrics& metrics() const |
94 { | 100 { |
95 ASSERT(m_textLineLayout && m_metricsListOffset < metricsList().size()); | 101 ASSERT(m_textLineLayout && m_metricsListOffset < metricsList().size()); |
96 return metricsList()[m_metricsListOffset]; | 102 return metricsList()[m_metricsListOffset]; |
97 } | 103 } |
98 const Vector<SVGTextMetrics>& metricsList() const { return m_textLineLayout- >layoutAttributes()->textMetricsValues(); } | 104 const Vector<SVGTextMetrics>& metricsList() const { return m_textLineLayout. layoutAttributes()->textMetricsValues(); } |
99 unsigned metricsListOffset() const { return m_metricsListOffset; } | 105 unsigned metricsListOffset() const { return m_metricsListOffset; } |
100 unsigned characterOffset() const { return m_characterOffset; } | 106 unsigned characterOffset() const { return m_characterOffset; } |
101 bool isAtEnd() const { return m_metricsListOffset == metricsList().size(); } | 107 bool isAtEnd() const { return m_metricsListOffset == metricsList().size(); } |
102 | 108 |
103 private: | 109 private: |
104 void reset(LineLayoutSVGInlineText* textLineLayout) | 110 void reset(LineLayoutSVGInlineText textLineLayout) |
105 { | 111 { |
106 m_textLineLayout = textLineLayout; | 112 m_textLineLayout = textLineLayout; |
107 m_characterOffset = 0; | 113 m_characterOffset = 0; |
108 m_metricsListOffset = 0; | 114 m_metricsListOffset = 0; |
109 } | 115 } |
110 | 116 |
111 LineLayoutSVGInlineText* m_textLineLayout; | 117 #if ENABLE(ASSERT) |
118 void assertCharacterOffsetFromMetricsList() | |
eae
2015/12/28 16:41:26
Is this really necessary? Wouldn't the length asse
| |
119 { | |
120 if (!m_textLineLayout) | |
121 return; | |
122 const Vector<SVGTextMetrics>& metricsList = this->metricsList(); | |
123 ASSERT(m_metricsListOffset <= metricsList.size()); | |
124 unsigned characterOffset = 0, metricsListOffset = 0; | |
125 for (; metricsListOffset < m_metricsListOffset; ++metricsListOffset) | |
126 characterOffset += metricsList[metricsListOffset].length(); | |
127 ASSERT(m_characterOffset == characterOffset); | |
128 | |
129 for (; metricsListOffset < metricsList.size(); ++metricsListOffset) | |
130 characterOffset += metricsList[metricsListOffset].length(); | |
131 ASSERT(characterOffset == m_textLineLayout.length()); | |
132 } | |
133 #endif | |
134 | |
135 LineLayoutSVGInlineText m_textLineLayout; | |
112 unsigned m_metricsListOffset; | 136 unsigned m_metricsListOffset; |
113 unsigned m_characterOffset; | 137 unsigned m_characterOffset; |
114 }; | 138 }; |
115 | 139 |
116 } // namespace blink | 140 } // namespace blink |
117 | 141 |
118 #endif // LineLayoutSVGInlineText_h | 142 #endif // LineLayoutSVGInlineText_h |
OLD | NEW |