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

Unified Diff: third_party/WebKit/Source/core/layout/line/BreakingContextInlineHeaders.h

Issue 2557643002: Apply hyphenation when there is only one word in a paragraph (Closed)
Patch Set: Add a static helper function Created 4 years 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
« no previous file with comments | « third_party/WebKit/Source/core/layout/api/LineLayoutText.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/layout/line/BreakingContextInlineHeaders.h
diff --git a/third_party/WebKit/Source/core/layout/line/BreakingContextInlineHeaders.h b/third_party/WebKit/Source/core/layout/line/BreakingContextInlineHeaders.h
index 42cbcaad3f377509bde9fe91a4ee1fa564aad954..48777af99223f6277a2032d6991a0510efa5b925 100644
--- a/third_party/WebKit/Source/core/layout/line/BreakingContextInlineHeaders.h
+++ b/third_party/WebKit/Source/core/layout/line/BreakingContextInlineHeaders.h
@@ -907,6 +907,12 @@ ALWAYS_INLINE bool BreakingContext::isBreakAtSoftHyphen() const {
: m_current.previousInSameNode() == softHyphenCharacter;
}
+static ALWAYS_INLINE bool hasVisibleText(LineLayoutText layoutText,
+ unsigned offset) {
+ return !layoutText.containsOnlyWhitespace(offset,
+ layoutText.textLength() - offset);
+}
+
inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements,
bool& hyphenated) {
if (!m_current.offset())
@@ -955,6 +961,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements,
Hyphenation* hyphenation = style.getHyphenation();
bool disableSoftHyphen = style.getHyphens() == HyphensNone;
float hyphenWidth = 0;
+ bool isLineEmpty = m_lineInfo.isEmpty();
if (layoutText.isSVGInlineText()) {
breakWords = false;
@@ -1114,7 +1121,9 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements,
midWordBreak = true;
}
m_width.addUncommittedWidth(wordMeasurement.width);
- } else if (hyphenation) {
+ } else if (hyphenation &&
+ (m_nextObject || isLineEmpty ||
+ hasVisibleText(layoutText, m_current.offset()))) {
m_width.addUncommittedWidth(-wordMeasurement.width);
DCHECK(lastSpace == static_cast<unsigned>(wordMeasurement.startOffset));
DCHECK(m_current.offset() ==
@@ -1203,6 +1212,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements,
prepareForNextCharacter(layoutText, prohibitBreakInside,
previousCharacterIsSpace);
m_atStart = false;
+ isLineEmpty = m_lineInfo.isEmpty();
nextCharacter(c, lastCharacter, secondToLastCharacter);
}
@@ -1253,7 +1263,7 @@ inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements,
m_width.commit();
m_atEnd = true;
} else if (!m_width.fitsOnLine()) {
- if (hyphenation && (m_nextObject || m_lineInfo.isEmpty())) {
+ if (hyphenation && (m_nextObject || isLineEmpty)) {
m_width.addUncommittedWidth(-wordMeasurement.width);
DCHECK(lastSpace == static_cast<unsigned>(wordMeasurement.startOffset));
DCHECK(m_current.offset() ==
« no previous file with comments | « third_party/WebKit/Source/core/layout/api/LineLayoutText.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698