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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. 3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc.
4 * All right reserved. 4 * All right reserved.
5 * Copyright (C) 2010 Google Inc. All rights reserved. 5 * Copyright (C) 2010 Google Inc. All rights reserved.
6 * Copyright (C) 2013 Adobe Systems Incorporated. 6 * Copyright (C) 2013 Adobe Systems Incorporated.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after
900 wordMeasurement, start + prefixLength, 900 wordMeasurement, start + prefixLength,
901 font.getCharacterRange(run, 0, prefixLength).width()); 901 font.getCharacterRange(run, 0, prefixLength).width());
902 } 902 }
903 903
904 ALWAYS_INLINE bool BreakingContext::isBreakAtSoftHyphen() const { 904 ALWAYS_INLINE bool BreakingContext::isBreakAtSoftHyphen() const {
905 return m_lineBreak != m_resolver.position() 905 return m_lineBreak != m_resolver.position()
906 ? m_lineBreak.previousInSameNode() == softHyphenCharacter 906 ? m_lineBreak.previousInSameNode() == softHyphenCharacter
907 : m_current.previousInSameNode() == softHyphenCharacter; 907 : m_current.previousInSameNode() == softHyphenCharacter;
908 } 908 }
909 909
910 static ALWAYS_INLINE bool hasVisibleText(LineLayoutText layoutText,
911 unsigned offset) {
912 return !layoutText.containsOnlyWhitespace(offset,
913 layoutText.textLength() - offset);
914 }
915
910 inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements, 916 inline bool BreakingContext::handleText(WordMeasurements& wordMeasurements,
911 bool& hyphenated) { 917 bool& hyphenated) {
912 if (!m_current.offset()) 918 if (!m_current.offset())
913 m_appliedStartWidth = false; 919 m_appliedStartWidth = false;
914 920
915 LineLayoutText layoutText(m_current.getLineLayoutItem()); 921 LineLayoutText layoutText(m_current.getLineLayoutItem());
916 922
917 // If we have left a no-wrap inline and entered an autowrap inline while 923 // If we have left a no-wrap inline and entered an autowrap inline while
918 // ignoring spaces then we need to mark the start of the autowrap inline as a 924 // ignoring spaces then we need to mark the start of the autowrap inline as a
919 // potential linebreak now. 925 // potential linebreak now.
(...skipping 28 matching lines...) Expand all
948 954
949 // This is currently only used for word-break: break-all, specifically for the 955 // This is currently only used for word-break: break-all, specifically for the
950 // case where we have a break opportunity within a word, then a string of non- 956 // case where we have a break opportunity within a word, then a string of non-
951 // breakable content that ends up making our word wider than the current line. 957 // breakable content that ends up making our word wider than the current line.
952 // See: fast/css3-text/css3-word-break/word-break-all-wrap-with-floats.html 958 // See: fast/css3-text/css3-word-break/word-break-all-wrap-with-floats.html
953 float widthMeasurementAtLastBreakOpportunity = 0; 959 float widthMeasurementAtLastBreakOpportunity = 0;
954 960
955 Hyphenation* hyphenation = style.getHyphenation(); 961 Hyphenation* hyphenation = style.getHyphenation();
956 bool disableSoftHyphen = style.getHyphens() == HyphensNone; 962 bool disableSoftHyphen = style.getHyphens() == HyphensNone;
957 float hyphenWidth = 0; 963 float hyphenWidth = 0;
964 bool isLineEmpty = m_lineInfo.isEmpty();
958 965
959 if (layoutText.isSVGInlineText()) { 966 if (layoutText.isSVGInlineText()) {
960 breakWords = false; 967 breakWords = false;
961 breakAll = false; 968 breakAll = false;
962 keepAll = false; 969 keepAll = false;
963 } 970 }
964 971
965 // Use LineBreakType::Normal for break-all. When a word does not fit, 972 // Use LineBreakType::Normal for break-all. When a word does not fit,
966 // rewindToMidWordBreak() finds the mid-word break point. 973 // rewindToMidWordBreak() finds the mid-word break point.
967 LineBreakType lineBreakType = 974 LineBreakType lineBreakType =
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 midWordBreak = false; 1114 midWordBreak = false;
1108 if (!m_width.fitsOnLine()) { 1115 if (!m_width.fitsOnLine()) {
1109 if (canBreakMidWord) { 1116 if (canBreakMidWord) {
1110 m_width.addUncommittedWidth(-wordMeasurement.width); 1117 m_width.addUncommittedWidth(-wordMeasurement.width);
1111 if (rewindToMidWordBreak(layoutText, style, font, breakAll, 1118 if (rewindToMidWordBreak(layoutText, style, font, breakAll,
1112 wordMeasurement)) { 1119 wordMeasurement)) {
1113 lastWidthMeasurement = wordMeasurement.width + lastSpaceWordSpacing; 1120 lastWidthMeasurement = wordMeasurement.width + lastSpaceWordSpacing;
1114 midWordBreak = true; 1121 midWordBreak = true;
1115 } 1122 }
1116 m_width.addUncommittedWidth(wordMeasurement.width); 1123 m_width.addUncommittedWidth(wordMeasurement.width);
1117 } else if (hyphenation) { 1124 } else if (hyphenation &&
1125 (m_nextObject || isLineEmpty ||
1126 hasVisibleText(layoutText, m_current.offset()))) {
1118 m_width.addUncommittedWidth(-wordMeasurement.width); 1127 m_width.addUncommittedWidth(-wordMeasurement.width);
1119 DCHECK(lastSpace == static_cast<unsigned>(wordMeasurement.startOffset)); 1128 DCHECK(lastSpace == static_cast<unsigned>(wordMeasurement.startOffset));
1120 DCHECK(m_current.offset() == 1129 DCHECK(m_current.offset() ==
1121 static_cast<unsigned>(wordMeasurement.endOffset)); 1130 static_cast<unsigned>(wordMeasurement.endOffset));
1122 if (hyphenate(layoutText, style, font, *hyphenation, 1131 if (hyphenate(layoutText, style, font, *hyphenation,
1123 lastSpaceWordSpacing, wordMeasurement)) { 1132 lastSpaceWordSpacing, wordMeasurement)) {
1124 m_width.addUncommittedWidth(wordMeasurement.width); 1133 m_width.addUncommittedWidth(wordMeasurement.width);
1125 hyphenated = true; 1134 hyphenated = true;
1126 m_atEnd = true; 1135 m_atEnd = true;
1127 return false; 1136 return false;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 m_lineMidpointState.startIgnoringSpaces(m_startOfIgnoredSpaces); 1205 m_lineMidpointState.startIgnoringSpaces(m_startOfIgnoredSpaces);
1197 m_trailingObjects.updateMidpointsForTrailingObjects( 1206 m_trailingObjects.updateMidpointsForTrailingObjects(
1198 m_lineMidpointState, InlineIterator(), 1207 m_lineMidpointState, InlineIterator(),
1199 TrailingObjects::DoNotCollapseFirstSpace); 1208 TrailingObjects::DoNotCollapseFirstSpace);
1200 } 1209 }
1201 } 1210 }
1202 1211
1203 prepareForNextCharacter(layoutText, prohibitBreakInside, 1212 prepareForNextCharacter(layoutText, prohibitBreakInside,
1204 previousCharacterIsSpace); 1213 previousCharacterIsSpace);
1205 m_atStart = false; 1214 m_atStart = false;
1215 isLineEmpty = m_lineInfo.isEmpty();
1206 nextCharacter(c, lastCharacter, secondToLastCharacter); 1216 nextCharacter(c, lastCharacter, secondToLastCharacter);
1207 } 1217 }
1208 1218
1209 m_layoutTextInfo.m_lineBreakIterator.setPriorContext(lastCharacter, 1219 m_layoutTextInfo.m_lineBreakIterator.setPriorContext(lastCharacter,
1210 secondToLastCharacter); 1220 secondToLastCharacter);
1211 1221
1212 wordMeasurements.grow(wordMeasurements.size() + 1); 1222 wordMeasurements.grow(wordMeasurements.size() + 1);
1213 WordMeasurement& wordMeasurement = wordMeasurements.back(); 1223 WordMeasurement& wordMeasurement = wordMeasurements.back();
1214 wordMeasurement.layoutText = layoutText; 1224 wordMeasurement.layoutText = layoutText;
1215 1225
(...skipping 30 matching lines...) Expand all
1246 if (m_collapseWhiteSpace && m_currentCharacterIsSpace && lastWidthMeasurement) 1256 if (m_collapseWhiteSpace && m_currentCharacterIsSpace && lastWidthMeasurement)
1247 m_width.setTrailingWhitespaceWidth(lastWidthMeasurement + 1257 m_width.setTrailingWhitespaceWidth(lastWidthMeasurement +
1248 additionalWidthFromAncestors); 1258 additionalWidthFromAncestors);
1249 1259
1250 m_includeEndWidth = false; 1260 m_includeEndWidth = false;
1251 1261
1252 if (midWordBreak) { 1262 if (midWordBreak) {
1253 m_width.commit(); 1263 m_width.commit();
1254 m_atEnd = true; 1264 m_atEnd = true;
1255 } else if (!m_width.fitsOnLine()) { 1265 } else if (!m_width.fitsOnLine()) {
1256 if (hyphenation && (m_nextObject || m_lineInfo.isEmpty())) { 1266 if (hyphenation && (m_nextObject || isLineEmpty)) {
1257 m_width.addUncommittedWidth(-wordMeasurement.width); 1267 m_width.addUncommittedWidth(-wordMeasurement.width);
1258 DCHECK(lastSpace == static_cast<unsigned>(wordMeasurement.startOffset)); 1268 DCHECK(lastSpace == static_cast<unsigned>(wordMeasurement.startOffset));
1259 DCHECK(m_current.offset() == 1269 DCHECK(m_current.offset() ==
1260 static_cast<unsigned>(wordMeasurement.endOffset)); 1270 static_cast<unsigned>(wordMeasurement.endOffset));
1261 if (hyphenate(layoutText, style, font, *hyphenation, lastSpaceWordSpacing, 1271 if (hyphenate(layoutText, style, font, *hyphenation, lastSpaceWordSpacing,
1262 wordMeasurement)) { 1272 wordMeasurement)) {
1263 hyphenated = true; 1273 hyphenated = true;
1264 m_atEnd = true; 1274 m_atEnd = true;
1265 } 1275 }
1266 m_width.addUncommittedWidth(wordMeasurement.width); 1276 m_width.addUncommittedWidth(wordMeasurement.width);
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1533 1543
1534 if (style.getTextIndentType() == TextIndentHanging) 1544 if (style.getTextIndentType() == TextIndentHanging)
1535 indentText = indentText == IndentText ? DoNotIndentText : IndentText; 1545 indentText = indentText == IndentText ? DoNotIndentText : IndentText;
1536 1546
1537 return indentText; 1547 return indentText;
1538 } 1548 }
1539 1549
1540 } // namespace blink 1550 } // namespace blink
1541 1551
1542 #endif // BreakingContextInlineHeaders_h 1552 #endif // BreakingContextInlineHeaders_h
OLDNEW
« 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