Commit 12bc246b authored by kojii's avatar kojii Committed by Commit bot

Fix SVGInlineTextMetricsIterator not to keep a pointer to LineLayoutItem

This patch changes SVGInlineTextMetricsIterator to keep an instanace of
LineLayoutSVGInlineText, not a pointer to. LineLayoutItem and its
subclasses are oftentimes allocated on stack that keeping pointers
should be avoided.

Additional ASSERTs in this CL fail existing tests. These existing tests
cover the fix.

BUG=572399, 499321

Review URL: https://codereview.chromium.org/1547263002

Cr-Commit-Position: refs/heads/master@{#367064}
parent 6e3656f3
...@@ -63,12 +63,12 @@ private: ...@@ -63,12 +63,12 @@ private:
class SVGInlineTextMetricsIterator { class SVGInlineTextMetricsIterator {
DISALLOW_NEW(); DISALLOW_NEW();
public: public:
SVGInlineTextMetricsIterator() { reset(nullptr); } SVGInlineTextMetricsIterator() { reset(LineLayoutSVGInlineText()); }
void advanceToTextStart(LineLayoutSVGInlineText* textLineLayout, unsigned startCharacterOffset) void advanceToTextStart(LineLayoutSVGInlineText textLineLayout, unsigned startCharacterOffset)
{ {
ASSERT(textLineLayout); ASSERT(textLineLayout);
if (m_textLineLayout != textLineLayout) { if (!m_textLineLayout || !m_textLineLayout.isEqual(textLineLayout)) {
reset(textLineLayout); reset(textLineLayout);
ASSERT(!metricsList().isEmpty()); ASSERT(!metricsList().isEmpty());
} }
...@@ -82,11 +82,14 @@ public: ...@@ -82,11 +82,14 @@ public:
while (m_characterOffset < startCharacterOffset) while (m_characterOffset < startCharacterOffset)
next(); next();
ASSERT(m_characterOffset == startCharacterOffset);
} }
void next() void next()
{ {
m_characterOffset += metrics().length(); m_characterOffset += metrics().length();
ASSERT(m_characterOffset <= m_textLineLayout.length());
ASSERT(m_metricsListOffset < metricsList().size());
++m_metricsListOffset; ++m_metricsListOffset;
} }
...@@ -95,20 +98,20 @@ public: ...@@ -95,20 +98,20 @@ public:
ASSERT(m_textLineLayout && m_metricsListOffset < metricsList().size()); ASSERT(m_textLineLayout && m_metricsListOffset < metricsList().size());
return metricsList()[m_metricsListOffset]; return metricsList()[m_metricsListOffset];
} }
const Vector<SVGTextMetrics>& metricsList() const { return m_textLineLayout->layoutAttributes()->textMetricsValues(); } const Vector<SVGTextMetrics>& metricsList() const { return m_textLineLayout.layoutAttributes()->textMetricsValues(); }
unsigned metricsListOffset() const { return m_metricsListOffset; } unsigned metricsListOffset() const { return m_metricsListOffset; }
unsigned characterOffset() const { return m_characterOffset; } unsigned characterOffset() const { return m_characterOffset; }
bool isAtEnd() const { return m_metricsListOffset == metricsList().size(); } bool isAtEnd() const { return m_metricsListOffset == metricsList().size(); }
private: private:
void reset(LineLayoutSVGInlineText* textLineLayout) void reset(LineLayoutSVGInlineText textLineLayout)
{ {
m_textLineLayout = textLineLayout; m_textLineLayout = textLineLayout;
m_characterOffset = 0; m_characterOffset = 0;
m_metricsListOffset = 0; m_metricsListOffset = 0;
} }
LineLayoutSVGInlineText* m_textLineLayout; LineLayoutSVGInlineText m_textLineLayout;
unsigned m_metricsListOffset; unsigned m_metricsListOffset;
unsigned m_characterOffset; unsigned m_characterOffset;
}; };
......
...@@ -357,7 +357,7 @@ void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, Line ...@@ -357,7 +357,7 @@ void SVGTextLayoutEngine::layoutTextOnLineOrPath(SVGInlineTextBox* textBox, Line
return; return;
// Find the start of the current text box in the metrics list. // Find the start of the current text box in the metrics list.
m_visualMetricsIterator.advanceToTextStart(&textLineLayout, textBox->start()); m_visualMetricsIterator.advanceToTextStart(textLineLayout, textBox->start());
const Font& font = style.font(); const Font& font = style.font();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment