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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutText.cpp

Issue 2715153003: Implement 'normal', 'strict', and 'loose' of the 'line-break' property (Closed)
Patch Set: Rebase Created 3 years, 9 months 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
OLDNEW
1 /* 1 /*
2 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org) 3 * (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
5 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) 5 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net)
6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) 6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com)
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 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
996 } 996 }
997 997
998 static float minWordFragmentWidthForBreakAll(LayoutText* layoutText, 998 static float minWordFragmentWidthForBreakAll(LayoutText* layoutText,
999 const ComputedStyle& style, 999 const ComputedStyle& style,
1000 const Font& font, 1000 const Font& font,
1001 TextDirection textDirection, 1001 TextDirection textDirection,
1002 int start, 1002 int start,
1003 int length, 1003 int length,
1004 EWordBreak breakAllOrBreakWord) { 1004 EWordBreak breakAllOrBreakWord) {
1005 DCHECK_GT(length, 0); 1005 DCHECK_GT(length, 0);
1006 LazyLineBreakIterator breakIterator(layoutText->text(), style.locale()); 1006 LazyLineBreakIterator breakIterator(layoutText->text(),
1007 localeForLineBreakIterator(style));
1007 int nextBreakable = -1; 1008 int nextBreakable = -1;
1008 float min = std::numeric_limits<float>::max(); 1009 float min = std::numeric_limits<float>::max();
1009 int end = start + length; 1010 int end = start + length;
1010 for (int i = start; i < end;) { 1011 for (int i = start; i < end;) {
1011 int fragmentLength; 1012 int fragmentLength;
1012 if (breakAllOrBreakWord == EWordBreak::BreakAllWordBreak) { 1013 if (breakAllOrBreakWord == EWordBreak::BreakAllWordBreak) {
1013 breakIterator.isBreakable(i + 1, nextBreakable, LineBreakType::BreakAll); 1014 breakIterator.isBreakable(i + 1, nextBreakable, LineBreakType::BreakAll);
1014 fragmentLength = (nextBreakable > i ? nextBreakable : length) - i; 1015 fragmentLength = (nextBreakable > i ? nextBreakable : length) - i;
1015 } else { 1016 } else {
1016 fragmentLength = U16_LENGTH(layoutText->codepointAt(i)); 1017 fragmentLength = U16_LENGTH(layoutText->codepointAt(i));
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 if (fragmentWidth <= minimumFragmentWidthToConsider) 1065 if (fragmentWidth <= minimumFragmentWidthToConsider)
1065 continue; 1066 continue;
1066 1067
1067 maxFragmentWidth = std::max(maxFragmentWidth, fragmentWidth); 1068 maxFragmentWidth = std::max(maxFragmentWidth, fragmentWidth);
1068 end = start; 1069 end = start;
1069 } 1070 }
1070 suffixStart = hyphenLocations.front(); 1071 suffixStart = hyphenLocations.front();
1071 return maxFragmentWidth + layoutText->hyphenWidth(font, textDirection); 1072 return maxFragmentWidth + layoutText->hyphenWidth(font, textDirection);
1072 } 1073 }
1073 1074
1075 AtomicString localeForLineBreakIterator(const ComputedStyle& style) {
1076 LineBreakIteratorMode mode = LineBreakIteratorMode::Default;
1077 switch (style.getLineBreak()) {
1078 default:
1079 NOTREACHED();
1080 // Fall through.
1081 case LineBreakAuto:
1082 case LineBreakAfterWhiteSpace:
1083 return style.locale();
1084 case LineBreakNormal:
1085 mode = LineBreakIteratorMode::Normal;
1086 break;
1087 case LineBreakStrict:
1088 mode = LineBreakIteratorMode::Strict;
1089 break;
1090 case LineBreakLoose:
1091 mode = LineBreakIteratorMode::Loose;
1092 break;
1093 }
1094 if (const LayoutLocale* locale = style.getFontDescription().locale())
1095 return locale->localeWithBreakKeyword(mode);
1096 return style.locale();
1097 }
1098
1074 void LayoutText::computePreferredLogicalWidths( 1099 void LayoutText::computePreferredLogicalWidths(
1075 float leadWidth, 1100 float leadWidth,
1076 HashSet<const SimpleFontData*>& fallbackFonts, 1101 HashSet<const SimpleFontData*>& fallbackFonts,
1077 FloatRect& glyphBounds) { 1102 FloatRect& glyphBounds) {
1078 ASSERT(m_hasTab || preferredLogicalWidthsDirty() || 1103 ASSERT(m_hasTab || preferredLogicalWidthsDirty() ||
1079 !m_knownToHaveNoOverflowAndNoFallbackFonts); 1104 !m_knownToHaveNoOverflowAndNoFallbackFonts);
1080 1105
1081 m_minWidth = 0; 1106 m_minWidth = 0;
1082 m_maxWidth = 0; 1107 m_maxWidth = 0;
1083 m_firstLineMinWidth = 0; 1108 m_firstLineMinWidth = 0;
1084 m_lastLineLineMinWidth = 0; 1109 m_lastLineLineMinWidth = 0;
1085 1110
1086 if (isBR()) 1111 if (isBR())
1087 return; 1112 return;
1088 1113
1089 float currMinWidth = 0; 1114 float currMinWidth = 0;
1090 float currMaxWidth = 0; 1115 float currMaxWidth = 0;
1091 m_hasBreakableChar = false; 1116 m_hasBreakableChar = false;
1092 m_hasBreak = false; 1117 m_hasBreak = false;
1093 m_hasTab = false; 1118 m_hasTab = false;
1094 m_hasBreakableStart = false; 1119 m_hasBreakableStart = false;
1095 m_hasBreakableEnd = false; 1120 m_hasBreakableEnd = false;
1096 m_hasEndWhiteSpace = false; 1121 m_hasEndWhiteSpace = false;
1097 1122
1098 const ComputedStyle& styleToUse = styleRef(); 1123 const ComputedStyle& styleToUse = styleRef();
1099 const Font& f = styleToUse.font(); // FIXME: This ignores first-line. 1124 const Font& f = styleToUse.font(); // FIXME: This ignores first-line.
1100 float wordSpacing = styleToUse.wordSpacing(); 1125 float wordSpacing = styleToUse.wordSpacing();
1101 int len = textLength(); 1126 int len = textLength();
1102 LazyLineBreakIterator breakIterator(m_text, styleToUse.locale()); 1127 LazyLineBreakIterator breakIterator(m_text,
1128 localeForLineBreakIterator(styleToUse));
1103 bool needsWordSpacing = false; 1129 bool needsWordSpacing = false;
1104 bool ignoringSpaces = false; 1130 bool ignoringSpaces = false;
1105 bool isSpace = false; 1131 bool isSpace = false;
1106 bool firstWord = true; 1132 bool firstWord = true;
1107 bool firstLine = true; 1133 bool firstLine = true;
1108 int nextBreakable = -1; 1134 int nextBreakable = -1;
1109 int lastWordBoundary = 0; 1135 int lastWordBoundary = 0;
1110 float cachedWordTrailingSpaceWidth[2] = {0, 0}; // LTR, RTL 1136 float cachedWordTrailingSpaceWidth[2] = {0, 0}; // LTR, RTL
1111 1137
1112 EWordBreak breakAllOrBreakWord = EWordBreak::NormalWordBreak; 1138 EWordBreak breakAllOrBreakWord = EWordBreak::NormalWordBreak;
(...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after
2028 LayoutRect rect = LayoutRect( 2054 LayoutRect rect = LayoutRect(
2029 IntRect(firstRunX(), firstRunY(), linesBox.width(), linesBox.height())); 2055 IntRect(firstRunX(), firstRunY(), linesBox.width(), linesBox.height()));
2030 LayoutBlock* block = containingBlock(); 2056 LayoutBlock* block = containingBlock();
2031 if (block && hasTextBoxes()) 2057 if (block && hasTextBoxes())
2032 block->adjustChildDebugRect(rect); 2058 block->adjustChildDebugRect(rect);
2033 2059
2034 return rect; 2060 return rect;
2035 } 2061 }
2036 2062
2037 } // namespace blink 2063 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698