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

Unified Diff: Source/core/rendering/RenderBlock.cpp

Issue 198013006: Patch proposal (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add a few more test cases to first-letter-punctuation.html and update expectations Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/platform/win/fast/css/first-letter-punctuation-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/rendering/RenderBlock.cpp
diff --git a/Source/core/rendering/RenderBlock.cpp b/Source/core/rendering/RenderBlock.cpp
index fbcc31eb3c1ddbed2c55e49fdf3f75103d6adc04..c6408430e792eddf6bd38346c79cf05876604aa2 100644
--- a/Source/core/rendering/RenderBlock.cpp
+++ b/Source/core/rendering/RenderBlock.cpp
@@ -4027,9 +4027,9 @@ static inline bool isPunctuationForFirstLetter(UChar c)
|| charCategory == Punctuation_Other;
}
-static inline bool shouldSkipForFirstLetter(UChar c)
+static inline bool isSpaceForFirstLetter(UChar c)
{
- return isSpaceOrNewline(c) || c == noBreakSpace || isPunctuationForFirstLetter(c);
+ return isSpaceOrNewline(c) || c == noBreakSpace;
}
static inline RenderObject* findFirstLetterBlock(RenderBlock* start)
@@ -4108,31 +4108,34 @@ void RenderBlock::updateFirstLetterStyle(RenderObject* firstLetterBlock, RenderO
static inline unsigned firstLetterLength(const String& text)
{
unsigned length = 0;
+ unsigned textLength = text.length();
- // Account for leading spaces and punctuation.
- while (length < text.length() && shouldSkipForFirstLetter((text)[length]))
+ // Account for leading spaces first.
+ while (length < textLength && isSpaceForFirstLetter(text[length]))
length++;
- // Bail if we didn't find a letter
- if (text.length() && length == text.length())
+ // Now account for leading punctuation.
+ while (length < textLength && isPunctuationForFirstLetter(text[length]))
+ length++;
+
+ // Bail if we didn't find a letter before the end of the text or before a space.
+ if (isSpaceForFirstLetter(text[length]) || (textLength && length == textLength))
return 0;
- // Account for first letter.
+ // Account the next character for first letter.
length++;
- // Keep looking for whitespace and allowed punctuation, but avoid
- // accumulating just whitespace into the :first-letter.
- for (unsigned scanLength = length; scanLength < text.length(); ++scanLength) {
- UChar c = (text)[scanLength];
+ // Keep looking allowed punctuation for the :first-letter.
+ for (unsigned scanLength = length; scanLength < textLength; ++scanLength) {
+ UChar c = text[scanLength];
- if (!shouldSkipForFirstLetter(c))
+ if (!isPunctuationForFirstLetter(c))
break;
- if (isPunctuationForFirstLetter(c))
- length = scanLength + 1;
+ length = scanLength + 1;
}
- // FIXME: If text.length() is 0, length may still be 1!
+ // FIXME: If textLength is 0, length may still be 1!
return length;
}
« no previous file with comments | « LayoutTests/platform/win/fast/css/first-letter-punctuation-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698