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

Unified Diff: Source/platform/text/TextBreakIterator.cpp

Issue 1094863007: Implement "word-break: keep-all" in CSS3 Text (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Replace custom SA charset detecting function to already existing one Created 5 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/platform/text/TextBreakIterator.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/platform/text/TextBreakIterator.cpp
diff --git a/Source/platform/text/TextBreakIterator.cpp b/Source/platform/text/TextBreakIterator.cpp
index 53615486152a0635817b2a9629fc559783d8165a..6dce824362112a506e1f8a86fe259eaa101e0661 100644
--- a/Source/platform/text/TextBreakIterator.cpp
+++ b/Source/platform/text/TextBreakIterator.cpp
@@ -225,6 +225,53 @@ static inline int nextBreakablePositionBreakAllInternal(LazyLineBreakIterator& l
return len;
}
+static inline bool shouldKeepAfter(UChar lastCh, UChar ch, UChar nextCh)
+{
+ UChar preCh = U_MASK(u_charType(ch)) & U_GC_M_MASK ? lastCh : ch;
+ return U_MASK(u_charType(preCh)) & (U_GC_L_MASK | U_GC_N_MASK)
+ && !WTF::Unicode::hasLineBreakingPropertyComplexContext(preCh)
+ && U_MASK(u_charType(nextCh)) & (U_GC_L_MASK | U_GC_N_MASK)
+ && !WTF::Unicode::hasLineBreakingPropertyComplexContext(nextCh);
+}
+
+static inline int nextBreakablePositionKeepAllInternal(LazyLineBreakIterator& lazyBreakIterator, const UChar* str, unsigned length, int pos)
+{
+ int len = static_cast<int>(length);
+ int nextBreak = -1;
+
+ UChar lastLastCh = pos > 1 ? str[pos - 2] : static_cast<UChar>(lazyBreakIterator.secondToLastCharacter());
+ UChar lastCh = pos > 0 ? str[pos - 1] : static_cast<UChar>(lazyBreakIterator.lastCharacter());
+ unsigned priorContextLength = lazyBreakIterator.priorContextLength();
+ for (int i = pos; i < len; i++) {
+ UChar ch = str[i];
+
+ if (isBreakableSpace(ch) || shouldBreakAfter(lastLastCh, lastCh, ch))
+ return i;
+
+ if (!shouldKeepAfter(lastLastCh, lastCh, ch) && (needsLineBreakIterator(ch) || needsLineBreakIterator(lastCh))) {
+ if (nextBreak < i) {
+ // Don't break if positioned at start of primary context and there is no prior context.
+ if (i || priorContextLength) {
+ TextBreakIterator* breakIterator = lazyBreakIterator.get(priorContextLength);
+ if (breakIterator) {
+ nextBreak = breakIterator->following(i - 1 + priorContextLength);
+ if (nextBreak >= 0) {
+ nextBreak -= priorContextLength;
+ }
+ }
+ }
+ }
+ if (i == nextBreak && !isBreakableSpace(lastCh))
+ return i;
+ }
+
+ lastLastCh = lastCh;
+ lastCh = ch;
+ }
+
+ return len;
+}
+
int LazyLineBreakIterator::nextBreakablePositionIgnoringNBSP(int pos)
{
if (m_string.is8Bit())
@@ -239,5 +286,11 @@ int LazyLineBreakIterator::nextBreakablePositionBreakAll(int pos)
return nextBreakablePositionBreakAllInternal<UChar>(*this, m_string.characters16(), m_string.length(), pos);
}
+int LazyLineBreakIterator::nextBreakablePositionKeepAll(int pos)
+{
+ if (m_string.is8Bit())
+ return nextBreakablePosition<LChar>(*this, m_string.characters8(), m_string.length(), pos);
+ return nextBreakablePositionKeepAllInternal(*this, m_string.characters16(), m_string.length(), pos);
+}
} // namespace blink
« no previous file with comments | « Source/platform/text/TextBreakIterator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698