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: Source/platform/text/TextBreakIterator.h

Issue 1094863007: Implement "word-break: keep-all" in CSS3 Text (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fix layout test failure on mac 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006 Lars Knoll <lars@trolltech.com> 2 * Copyright (C) 2006 Lars Knoll <lars@trolltech.com>
3 * Copyright (C) 2007, 2011, 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2007, 2011, 2012 Apple Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 PLATFORM_EXPORT void releaseLineBreakIterator(TextBreakIterator*); 47 PLATFORM_EXPORT void releaseLineBreakIterator(TextBreakIterator*);
48 PLATFORM_EXPORT TextBreakIterator* sentenceBreakIterator(const UChar*, int lengt h); 48 PLATFORM_EXPORT TextBreakIterator* sentenceBreakIterator(const UChar*, int lengt h);
49 49
50 PLATFORM_EXPORT bool isWordTextBreak(TextBreakIterator*); 50 PLATFORM_EXPORT bool isWordTextBreak(TextBreakIterator*);
51 51
52 const int TextBreakDone = -1; 52 const int TextBreakDone = -1;
53 53
54 enum class LineBreakType { 54 enum class LineBreakType {
55 Normal, 55 Normal,
56 BreakAll, // word-break:break-all allows breaks between letters/numbers 56 BreakAll, // word-break:break-all allows breaks between letters/numbers
57 KeepAll, // word-break:keep-all doesn't allow breaks between all kind of let ters/numbers except some south east asians'.
57 }; 58 };
58 59
59 class PLATFORM_EXPORT LazyLineBreakIterator { 60 class PLATFORM_EXPORT LazyLineBreakIterator {
60 public: 61 public:
61 LazyLineBreakIterator() 62 LazyLineBreakIterator()
62 : m_iterator(0) 63 : m_iterator(0)
63 , m_cachedPriorContext(0) 64 , m_cachedPriorContext(0)
64 , m_cachedPriorContextLength(0) 65 , m_cachedPriorContextLength(0)
65 { 66 {
66 resetPriorContext(); 67 resetPriorContext();
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 m_string = string; 159 m_string = string;
159 m_locale = locale; 160 m_locale = locale;
160 m_iterator = 0; 161 m_iterator = 0;
161 m_cachedPriorContext = 0; 162 m_cachedPriorContext = 0;
162 m_cachedPriorContextLength = 0; 163 m_cachedPriorContextLength = 0;
163 } 164 }
164 165
165 inline bool isBreakable(int pos, int& nextBreakable, LineBreakType lineBreak Type = LineBreakType::Normal) 166 inline bool isBreakable(int pos, int& nextBreakable, LineBreakType lineBreak Type = LineBreakType::Normal)
166 { 167 {
167 if (pos > nextBreakable) { 168 if (pos > nextBreakable) {
168 nextBreakable = lineBreakType == LineBreakType::BreakAll 169 switch (lineBreakType) {
169 ? nextBreakablePositionBreakAll(pos) 170 case LineBreakType::BreakAll:
170 : nextBreakablePositionIgnoringNBSP(pos); 171 nextBreakable = nextBreakablePositionBreakAll(pos);
172 break;
173 case LineBreakType::KeepAll:
174 nextBreakable = nextBreakablePositionKeepAll(pos);
175 break;
176 default:
177 nextBreakable = nextBreakablePositionIgnoringNBSP(pos);
178 }
171 } 179 }
172 return pos == nextBreakable; 180 return pos == nextBreakable;
173 } 181 }
174 182
175 private: 183 private:
176 int nextBreakablePositionIgnoringNBSP(int pos); 184 int nextBreakablePositionIgnoringNBSP(int pos);
177 int nextBreakablePositionBreakAll(int pos); 185 int nextBreakablePositionBreakAll(int pos);
186 int nextBreakablePositionKeepAll(int pos);
178 187
179 static const unsigned priorContextCapacity = 2; 188 static const unsigned priorContextCapacity = 2;
180 String m_string; 189 String m_string;
181 AtomicString m_locale; 190 AtomicString m_locale;
182 TextBreakIterator* m_iterator; 191 TextBreakIterator* m_iterator;
183 UChar m_priorContext[priorContextCapacity]; 192 UChar m_priorContext[priorContextCapacity];
184 const UChar* m_cachedPriorContext; 193 const UChar* m_cachedPriorContext;
185 unsigned m_cachedPriorContextLength; 194 unsigned m_cachedPriorContextLength;
186 }; 195 };
187 196
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 }; 252 };
244 253
245 // Counts the number of grapheme clusters. A surrogate pair or a sequence 254 // Counts the number of grapheme clusters. A surrogate pair or a sequence
246 // of a non-combining character and following combining characters is 255 // of a non-combining character and following combining characters is
247 // counted as 1 grapheme cluster. 256 // counted as 1 grapheme cluster.
248 PLATFORM_EXPORT unsigned numGraphemeClusters(const String&); 257 PLATFORM_EXPORT unsigned numGraphemeClusters(const String&);
249 258
250 } 259 }
251 260
252 #endif 261 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698