| 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 ASSERT(textLineLayout); | 70 ASSERT(textLineLayout); |
| 71 if (m_textLineLayout != textLineLayout) { | 71 if (!m_textLineLayout || !m_textLineLayout.isEqual(textLineLayout)) { |
| 72 reset(textLineLayout); | 72 reset(textLineLayout); |
| 73 ASSERT(!metricsList().isEmpty()); | 73 ASSERT(!metricsList().isEmpty()); |
| 74 } | 74 } |
| 75 | 75 |
| 76 if (m_characterOffset == startCharacterOffset) | 76 if (m_characterOffset == startCharacterOffset) |
| 77 return; | 77 return; |
| 78 | 78 |
| 79 // TODO(fs): We could walk backwards through the metrics list in these c
ases. | 79 // TODO(fs): We could walk backwards through the metrics list in these c
ases. |
| 80 if (m_characterOffset > startCharacterOffset) | 80 if (m_characterOffset > startCharacterOffset) |
| 81 reset(textLineLayout); | 81 reset(textLineLayout); |
| 82 | 82 |
| 83 while (m_characterOffset < startCharacterOffset) | 83 while (m_characterOffset < startCharacterOffset) |
| 84 next(); | 84 next(); |
| 85 ASSERT(m_characterOffset == startCharacterOffset); |
| 85 } | 86 } |
| 86 | 87 |
| 87 void next() | 88 void next() |
| 88 { | 89 { |
| 89 m_characterOffset += metrics().length(); | 90 m_characterOffset += metrics().length(); |
| 91 ASSERT(m_characterOffset <= m_textLineLayout.length()); |
| 92 ASSERT(m_metricsListOffset < metricsList().size()); |
| 90 ++m_metricsListOffset; | 93 ++m_metricsListOffset; |
| 91 } | 94 } |
| 92 | 95 |
| 93 const SVGTextMetrics& metrics() const | 96 const SVGTextMetrics& metrics() const |
| 94 { | 97 { |
| 95 ASSERT(m_textLineLayout && m_metricsListOffset < metricsList().size()); | 98 ASSERT(m_textLineLayout && m_metricsListOffset < metricsList().size()); |
| 96 return metricsList()[m_metricsListOffset]; | 99 return metricsList()[m_metricsListOffset]; |
| 97 } | 100 } |
| 98 const Vector<SVGTextMetrics>& metricsList() const { return m_textLineLayout-
>layoutAttributes()->textMetricsValues(); } | 101 const Vector<SVGTextMetrics>& metricsList() const { return m_textLineLayout.
layoutAttributes()->textMetricsValues(); } |
| 99 unsigned metricsListOffset() const { return m_metricsListOffset; } | 102 unsigned metricsListOffset() const { return m_metricsListOffset; } |
| 100 unsigned characterOffset() const { return m_characterOffset; } | 103 unsigned characterOffset() const { return m_characterOffset; } |
| 101 bool isAtEnd() const { return m_metricsListOffset == metricsList().size(); } | 104 bool isAtEnd() const { return m_metricsListOffset == metricsList().size(); } |
| 102 | 105 |
| 103 private: | 106 private: |
| 104 void reset(LineLayoutSVGInlineText* textLineLayout) | 107 void reset(LineLayoutSVGInlineText textLineLayout) |
| 105 { | 108 { |
| 106 m_textLineLayout = textLineLayout; | 109 m_textLineLayout = textLineLayout; |
| 107 m_characterOffset = 0; | 110 m_characterOffset = 0; |
| 108 m_metricsListOffset = 0; | 111 m_metricsListOffset = 0; |
| 109 } | 112 } |
| 110 | 113 |
| 111 LineLayoutSVGInlineText* m_textLineLayout; | 114 LineLayoutSVGInlineText m_textLineLayout; |
| 112 unsigned m_metricsListOffset; | 115 unsigned m_metricsListOffset; |
| 113 unsigned m_characterOffset; | 116 unsigned m_characterOffset; |
| 114 }; | 117 }; |
| 115 | 118 |
| 116 } // namespace blink | 119 } // namespace blink |
| 117 | 120 |
| 118 #endif // LineLayoutSVGInlineText_h | 121 #endif // LineLayoutSVGInlineText_h |
| OLD | NEW |