Commit d5bcb937 authored by kojii's avatar kojii Committed by Commit bot

Fix BreakingContext::rewindToMidWordBreak to set m_currentCharacterIsSpace

This patch fixes BreakingContext::rewindToMidWordBreak to set
m_currentCharacterIsSpace correctly when it rewinded m_current.

Not doing so sets previousCharacterIsSpace incorrectly, and can
collapse whitespaces that should not be collapsed.

BUG=639781

Review-Url: https://codereview.chromium.org/2334143002
Cr-Commit-Position: refs/heads/master@{#418776}
parent cba7c6ed
<!DOCTYPE html>
<style>
html {
font: 20px/1 Ahem;
}
figure {
width: 100%;
float: left;
}
</style>
<body>
<div>
<figure></figure>
<br>
<span>12 34</span>
</div>
<div>
<figure></figure>
<br>
<span>12 34</span>
</div>
<div>
<figure></figure>
<br>
<span>12 34</span>
</div>
</body>
<!DOCTYPE html>
<style>
html {
font: 20px/1 Ahem;
}
figure {
width: 100%;
float: left;
}
</style>
<body>
<div style="word-wrap: break-word">
<figure></figure>
<span>12 34</span>
</div>
<div style="word-break: break-word">
<figure></figure>
<span>12 34</span>
</div>
<div style="word-break: break-all">
<figure></figure>
<span>12 34</span>
</div>
</body>
...@@ -115,6 +115,7 @@ public: ...@@ -115,6 +115,7 @@ public:
} }
private: private:
void setCurrentCharacterIsSpace(UChar);
void skipTrailingWhitespace(InlineIterator&, const LineInfo&); void skipTrailingWhitespace(InlineIterator&, const LineInfo&);
bool shouldMidWordBreak(UChar, LineLayoutText, const Font&, bool shouldMidWordBreak(UChar, LineLayoutText, const Font&,
float& charWidth, float& widthFromLastBreakingOpportunity, float& charWidth, float& widthFromLastBreakingOpportunity,
...@@ -527,6 +528,11 @@ inline void nextCharacter(UChar& currentCharacter, UChar& lastCharacter, UChar& ...@@ -527,6 +528,11 @@ inline void nextCharacter(UChar& currentCharacter, UChar& lastCharacter, UChar&
lastCharacter = currentCharacter; lastCharacter = currentCharacter;
} }
ALWAYS_INLINE void BreakingContext::setCurrentCharacterIsSpace(UChar c)
{
m_currentCharacterIsSpace = c == spaceCharacter || c == tabulationCharacter || (!m_preservesNewline && (c == newlineCharacter));
}
inline float firstPositiveWidth(const WordMeasurements& wordMeasurements) inline float firstPositiveWidth(const WordMeasurements& wordMeasurements)
{ {
for (size_t i = 0; i < wordMeasurements.size(); ++i) { for (size_t i = 0; i < wordMeasurements.size(); ++i) {
...@@ -605,6 +611,7 @@ ALWAYS_INLINE bool BreakingContext::rewindToMidWordBreak( ...@@ -605,6 +611,7 @@ ALWAYS_INLINE bool BreakingContext::rewindToMidWordBreak(
wordMeasurement.width = width; wordMeasurement.width = width;
m_current.moveTo(m_current.getLineLayoutItem(), end, m_current.nextBreakablePosition()); m_current.moveTo(m_current.getLineLayoutItem(), end, m_current.nextBreakablePosition());
setCurrentCharacterIsSpace(m_current.current());
m_lineBreak.moveTo(m_current.getLineLayoutItem(), end, m_current.nextBreakablePosition()); m_lineBreak.moveTo(m_current.getLineLayoutItem(), end, m_current.nextBreakablePosition());
return true; return true;
} }
...@@ -789,7 +796,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool ...@@ -789,7 +796,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, bool
for (; m_current.offset() < layoutText.textLength(); m_current.fastIncrementInTextNode()) { for (; m_current.offset() < layoutText.textLength(); m_current.fastIncrementInTextNode()) {
bool previousCharacterIsSpace = m_currentCharacterIsSpace; bool previousCharacterIsSpace = m_currentCharacterIsSpace;
UChar c = m_current.current(); UChar c = m_current.current();
m_currentCharacterIsSpace = c == spaceCharacter || c == tabulationCharacter || (!m_preservesNewline && (c == newlineCharacter)); setCurrentCharacterIsSpace(c);
if (!m_collapseWhiteSpace || !m_currentCharacterIsSpace) { if (!m_collapseWhiteSpace || !m_currentCharacterIsSpace) {
m_lineInfo.setEmpty(false); m_lineInfo.setEmpty(false);
......
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