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

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

Issue 2560453002: Prioritize hyphenations over break-word/break-all (Closed)
Patch Set: Fix 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/LayoutTests/fast/text/hyphens/midword-break-priority-expected.html ('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 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 if (!m_appliedStartWidth) { 1094 if (!m_appliedStartWidth) {
1095 m_width.addUncommittedWidth( 1095 m_width.addUncommittedWidth(
1096 inlineLogicalWidthFromAncestorsIfNeeded(m_current.getLineLayoutItem(), 1096 inlineLogicalWidthFromAncestorsIfNeeded(m_current.getLineLayoutItem(),
1097 true, false) 1097 true, false)
1098 .toFloat()); 1098 .toFloat());
1099 m_appliedStartWidth = true; 1099 m_appliedStartWidth = true;
1100 } 1100 }
1101 1101
1102 midWordBreak = false; 1102 midWordBreak = false;
1103 if (!m_width.fitsOnLine()) { 1103 if (!m_width.fitsOnLine()) {
1104 if (canBreakMidWord) { 1104 if (hyphenation && (m_nextObject || isLineEmpty ||
eae 2016/12/07 07:16:20 This is pretty hard to read, how about adding a st
1105 m_width.addUncommittedWidth(-wordMeasurement.width); 1105 !layoutText.containsOnlyWhitespace(
1106 if (rewindToMidWordBreak(layoutText, style, font, breakAll, 1106 m_current.offset(),
1107 wordMeasurement)) { 1107 layoutText.textLength() - m_current.offset()))) {
1108 lastWidthMeasurement = wordMeasurement.width + lastSpaceWordSpacing;
1109 midWordBreak = true;
1110 }
1111 m_width.addUncommittedWidth(wordMeasurement.width);
1112 } else if (hyphenation &&
1113 (m_nextObject || isLineEmpty ||
1114 !layoutText.containsOnlyWhitespace(
1115 m_current.offset(),
1116 layoutText.textLength() - m_current.offset()))) {
1117 m_width.addUncommittedWidth(-wordMeasurement.width); 1108 m_width.addUncommittedWidth(-wordMeasurement.width);
1118 DCHECK(lastSpace == static_cast<unsigned>(wordMeasurement.startOffset)); 1109 DCHECK(lastSpace == static_cast<unsigned>(wordMeasurement.startOffset));
1119 DCHECK(m_current.offset() == 1110 DCHECK(m_current.offset() ==
1120 static_cast<unsigned>(wordMeasurement.endOffset)); 1111 static_cast<unsigned>(wordMeasurement.endOffset));
1121 if (hyphenate(layoutText, style, font, *hyphenation, 1112 if (hyphenate(layoutText, style, font, *hyphenation,
1122 lastSpaceWordSpacing, wordMeasurement)) { 1113 lastSpaceWordSpacing, wordMeasurement)) {
1123 m_width.addUncommittedWidth(wordMeasurement.width); 1114 m_width.addUncommittedWidth(wordMeasurement.width);
1124 hyphenated = true; 1115 hyphenated = true;
1125 m_atEnd = true; 1116 m_atEnd = true;
1126 return false; 1117 return false;
1127 } 1118 }
1128 m_width.addUncommittedWidth(wordMeasurement.width); 1119 m_width.addUncommittedWidth(wordMeasurement.width);
1129 } 1120 }
1121 if (canBreakMidWord) {
1122 m_width.addUncommittedWidth(-wordMeasurement.width);
1123 if (rewindToMidWordBreak(layoutText, style, font, breakAll,
1124 wordMeasurement)) {
1125 lastWidthMeasurement = wordMeasurement.width + lastSpaceWordSpacing;
1126 midWordBreak = true;
1127 }
1128 m_width.addUncommittedWidth(wordMeasurement.width);
1129 }
1130 } 1130 }
1131 1131
1132 // If we haven't hit a breakable position yet and already don't fit on the 1132 // If we haven't hit a breakable position yet and already don't fit on the
1133 // line try to move below any floats. 1133 // line try to move below any floats.
1134 if (!m_width.committedWidth() && m_autoWrap && !m_width.fitsOnLine() && 1134 if (!m_width.committedWidth() && m_autoWrap && !m_width.fitsOnLine() &&
1135 !widthMeasurementAtLastBreakOpportunity) { 1135 !widthMeasurementAtLastBreakOpportunity) {
1136 float availableWidthBefore = m_width.availableWidth(); 1136 float availableWidthBefore = m_width.availableWidth();
1137 m_width.fitBelowFloats(m_lineInfo.isFirstLine()); 1137 m_width.fitBelowFloats(m_lineInfo.isFirstLine());
1138 // If availableWidth changes by moving the line below floats, needs to 1138 // If availableWidth changes by moving the line below floats, needs to
1139 // measure midWordBreak again. 1139 // measure midWordBreak again.
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1210 secondToLastCharacter); 1210 secondToLastCharacter);
1211 1211
1212 wordMeasurements.grow(wordMeasurements.size() + 1); 1212 wordMeasurements.grow(wordMeasurements.size() + 1);
1213 WordMeasurement& wordMeasurement = wordMeasurements.back(); 1213 WordMeasurement& wordMeasurement = wordMeasurements.back();
1214 wordMeasurement.layoutText = layoutText; 1214 wordMeasurement.layoutText = layoutText;
1215 1215
1216 // IMPORTANT: current.offset() is > layoutText.textLength() here! 1216 // IMPORTANT: current.offset() is > layoutText.textLength() here!
1217 float lastWidthMeasurement = 0; 1217 float lastWidthMeasurement = 0;
1218 wordMeasurement.startOffset = lastSpace; 1218 wordMeasurement.startOffset = lastSpace;
1219 wordMeasurement.endOffset = m_current.offset(); 1219 wordMeasurement.endOffset = m_current.offset();
1220 midWordBreak = false;
1221 if (!m_ignoringSpaces) { 1220 if (!m_ignoringSpaces) {
1222 lastWidthMeasurement = 1221 lastWidthMeasurement =
1223 textWidth(layoutText, lastSpace, m_current.offset() - lastSpace, font, 1222 textWidth(layoutText, lastSpace, m_current.offset() - lastSpace, font,
1224 m_width.currentWidth(), m_collapseWhiteSpace, 1223 m_width.currentWidth(), m_collapseWhiteSpace,
1225 &wordMeasurement.fallbackFonts, &wordMeasurement.glyphBounds); 1224 &wordMeasurement.fallbackFonts, &wordMeasurement.glyphBounds);
1226 wordMeasurement.width = 1225 wordMeasurement.width =
1227 lastWidthMeasurement + wordSpacingForWordMeasurement; 1226 lastWidthMeasurement + wordSpacingForWordMeasurement;
1228 wordMeasurement.glyphBounds.move(wordSpacingForWordMeasurement, 0); 1227 wordMeasurement.glyphBounds.move(wordSpacingForWordMeasurement, 0);
1229
1230 if (canBreakMidWord && !m_width.fitsOnLine(lastWidthMeasurement) &&
1231 rewindToMidWordBreak(layoutText, style, font, breakAll,
1232 wordMeasurement)) {
1233 lastWidthMeasurement = wordMeasurement.width;
1234 midWordBreak = true;
1235 }
1236 } 1228 }
1237 lastWidthMeasurement += lastSpaceWordSpacing; 1229 lastWidthMeasurement += lastSpaceWordSpacing;
1238 1230
1239 LayoutUnit additionalWidthFromAncestors = 1231 LayoutUnit additionalWidthFromAncestors =
1240 inlineLogicalWidthFromAncestorsIfNeeded(m_current.getLineLayoutItem(), 1232 inlineLogicalWidthFromAncestorsIfNeeded(m_current.getLineLayoutItem(),
1241 !m_appliedStartWidth, 1233 !m_appliedStartWidth,
1242 m_includeEndWidth); 1234 m_includeEndWidth);
1243 m_width.addUncommittedWidth(lastWidthMeasurement + 1235 m_width.addUncommittedWidth(lastWidthMeasurement +
1244 additionalWidthFromAncestors); 1236 additionalWidthFromAncestors);
1245 1237
1246 if (m_collapseWhiteSpace && m_currentCharacterIsSpace && lastWidthMeasurement) 1238 if (m_collapseWhiteSpace && m_currentCharacterIsSpace && lastWidthMeasurement)
1247 m_width.setTrailingWhitespaceWidth(lastWidthMeasurement + 1239 m_width.setTrailingWhitespaceWidth(lastWidthMeasurement +
1248 additionalWidthFromAncestors); 1240 additionalWidthFromAncestors);
1249 1241
1250 m_includeEndWidth = false; 1242 m_includeEndWidth = false;
1251 1243
1252 if (midWordBreak) { 1244 if (!m_ignoringSpaces && !m_width.fitsOnLine()) {
1253 m_width.commit();
1254 m_atEnd = true;
1255 } else if (!m_width.fitsOnLine()) {
1256 if (hyphenation && (m_nextObject || isLineEmpty)) { 1245 if (hyphenation && (m_nextObject || isLineEmpty)) {
1257 m_width.addUncommittedWidth(-wordMeasurement.width); 1246 m_width.addUncommittedWidth(-wordMeasurement.width);
1258 DCHECK(lastSpace == static_cast<unsigned>(wordMeasurement.startOffset)); 1247 DCHECK_EQ(lastSpace, static_cast<unsigned>(wordMeasurement.startOffset));
1259 DCHECK(m_current.offset() == 1248 DCHECK_EQ(m_current.offset(),
1260 static_cast<unsigned>(wordMeasurement.endOffset)); 1249 static_cast<unsigned>(wordMeasurement.endOffset));
1261 if (hyphenate(layoutText, style, font, *hyphenation, lastSpaceWordSpacing, 1250 if (hyphenate(layoutText, style, font, *hyphenation, lastSpaceWordSpacing,
1262 wordMeasurement)) { 1251 wordMeasurement)) {
1263 hyphenated = true; 1252 hyphenated = true;
1264 m_atEnd = true; 1253 m_atEnd = true;
1265 } 1254 }
1266 m_width.addUncommittedWidth(wordMeasurement.width); 1255 m_width.addUncommittedWidth(wordMeasurement.width);
1267 } 1256 }
1268 if (!hyphenated && isBreakAtSoftHyphen() && !disableSoftHyphen) { 1257 if (!hyphenated && isBreakAtSoftHyphen() && !disableSoftHyphen) {
1269 hyphenated = true; 1258 hyphenated = true;
1270 m_atEnd = true; 1259 m_atEnd = true;
1271 } else if (!m_ignoringSpaces && canBreakMidWord && 1260 }
1272 m_width.committedWidth()) { 1261 if (!hyphenated && canBreakMidWord) {
1273 m_atEnd = true; 1262 m_width.addUncommittedWidth(-wordMeasurement.width);
1263 if (rewindToMidWordBreak(layoutText, style, font, breakAll,
1264 wordMeasurement)) {
1265 m_width.addUncommittedWidth(wordMeasurement.width);
1266 m_width.commit();
1267 m_atEnd = true;
1268 } else {
1269 m_width.addUncommittedWidth(wordMeasurement.width);
1270 if (m_width.committedWidth())
1271 m_atEnd = true;
1272 }
1274 } 1273 }
1275 } 1274 }
1276 return false; 1275 return false;
1277 } 1276 }
1278 1277
1279 inline void BreakingContext::prepareForNextCharacter( 1278 inline void BreakingContext::prepareForNextCharacter(
1280 const LineLayoutText& layoutText, 1279 const LineLayoutText& layoutText,
1281 bool& prohibitBreakInside, 1280 bool& prohibitBreakInside,
1282 bool previousCharacterIsSpace) { 1281 bool previousCharacterIsSpace) {
1283 if (layoutText.isSVGInlineText() && m_current.offset()) { 1282 if (layoutText.isSVGInlineText() && m_current.offset()) {
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1533 1532
1534 if (style.getTextIndentType() == TextIndentHanging) 1533 if (style.getTextIndentType() == TextIndentHanging)
1535 indentText = indentText == IndentText ? DoNotIndentText : IndentText; 1534 indentText = indentText == IndentText ? DoNotIndentText : IndentText;
1536 1535
1537 return indentText; 1536 return indentText;
1538 } 1537 }
1539 1538
1540 } // namespace blink 1539 } // namespace blink
1541 1540
1542 #endif // BreakingContextInlineHeaders_h 1541 #endif // BreakingContextInlineHeaders_h
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/text/hyphens/midword-break-priority-expected.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698