Skip to content

Commit 1f36172

Browse files
::first-letter should include preceding punctuation and space separators
https://bugs.webkit.org/show_bug.cgi?id=179815 Reviewed by NOBODY (OOPS!). Updating the punctuation categories that are included preceding and following the initial letter according to https://www.w3.org/TR/css-pseudo-4/#first-letter-pattern. Additionally adds narrow no-break space to spaces accepted preceding the first-letter, according to the resolution on w3c/csswg-drafts#9413 (comment) This change makes first-letter-punctuation-and-space.html pass. * LayoutTests/TestExpectations: * Source/WebCore/rendering/updating/RenderTreeBuilderFirstLetter.cpp: (WebCore::isPrecedingPunctuationForFirstLetter): (WebCore::isFollowingPunctuationForFirstLetter): (WebCore::shouldSkipForFirstLetter): (WebCore::RenderTreeBuilder::FirstLetter::createRenderers): (WebCore::isPunctuationForFirstLetter): Deleted.
1 parent 7ee1dc8 commit 1f36172

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

LayoutTests/TestExpectations

-1
Original file line numberDiff line numberDiff line change
@@ -5889,7 +5889,6 @@ webkit.org/b/230004 imported/w3c/web-platform-tests/css/css-pseudo/active-select
58895889
webkit.org/b/230004 imported/w3c/web-platform-tests/css/css-pseudo/active-selection-031.html [ ImageOnlyFailure ]
58905890
webkit.org/b/230004 imported/w3c/web-platform-tests/css/css-pseudo/active-selection-057.html [ ImageOnlyFailure ]
58915891
webkit.org/b/230004 imported/w3c/web-platform-tests/css/css-pseudo/first-letter-digraph.html [ ImageOnlyFailure ]
5892-
webkit.org/b/230004 imported/w3c/web-platform-tests/css/css-pseudo/first-letter-punctuation-and-space.html [ ImageOnlyFailure ]
58935892
webkit.org/b/230004 imported/w3c/web-platform-tests/css/css-pseudo/first-letter-punctuation-dynamic.html [ ImageOnlyFailure ]
58945893
webkit.org/b/230004 imported/w3c/web-platform-tests/css/css-pseudo/first-letter-skip-empty-span-nested.html [ ImageOnlyFailure ]
58955894
webkit.org/b/230004 imported/w3c/web-platform-tests/css/css-pseudo/first-letter-skip-empty-span.html [ ImageOnlyFailure ]

Source/WebCore/rendering/updating/RenderTreeBuilderFirstLetter.cpp

+13-7
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,23 @@ static std::optional<RenderStyle> styleForFirstLetter(const RenderElement& first
9494
return firstLetterStyle;
9595
}
9696

97-
// CSS 2.1 http://www.w3.org/TR/CSS21/selector.html#first-letter
98-
// "Punctuation (i.e, characters defined in Unicode [UNICODE] in the "open" (Ps), "close" (Pe),
99-
// "initial" (Pi). "final" (Pf) and "other" (Po) punctuation classes), that precedes or follows the first letter should be included"
100-
static inline bool isPunctuationForFirstLetter(char32_t c)
97+
// CSS Pseudo-Elements Module Level 4 https://www.w3.org/TR/css-pseudo-4/#first-letter-pattern
98+
// "All punctuation—i.e, characters that belong to the Punctuation (P*) Unicode general category [UAX44]—that precedes the first letter."
99+
static inline bool isPrecedingPunctuationForFirstLetter(char32_t c)
101100
{
102-
return U_GET_GC_MASK(c) & (U_GC_PS_MASK | U_GC_PE_MASK | U_GC_PI_MASK | U_GC_PF_MASK | U_GC_PO_MASK);
101+
return U_GET_GC_MASK(c) & (U_GC_PD_MASK | U_GC_PS_MASK | U_GC_PE_MASK | U_GC_PI_MASK | U_GC_PF_MASK | U_GC_PC_MASK | U_GC_PO_MASK);
102+
}
103+
104+
// "Any punctuation other than opening punctuation and dashes—i.e. characters that belong to the Punctuation (P*) Unicode general category,
105+
// excluding Open Punctuation (Ps) and Dash Punctuation (Pd)—that follows the first letter."
106+
static inline bool isFollowingPunctuationForFirstLetter(char32_t c)
107+
{
108+
return U_GET_GC_MASK(c) & (U_GC_PE_MASK | U_GC_PI_MASK | U_GC_PF_MASK | U_GC_PC_MASK | U_GC_PO_MASK);
103109
}
104110

105111
static inline bool shouldSkipForFirstLetter(char32_t c)
106112
{
107-
return deprecatedIsSpaceOrNewline(c) || c == noBreakSpace || isPunctuationForFirstLetter(c);
113+
return deprecatedIsSpaceOrNewline(c) || c == noBreakSpace || c == narrowNoBreakSpace || isPrecedingPunctuationForFirstLetter(c);
108114
}
109115

110116
static bool supportsFirstLetter(RenderBlock& block)
@@ -260,7 +266,7 @@ void RenderTreeBuilder::FirstLetter::createRenderers(RenderText& currentTextChil
260266

261267
numCodeUnits = numCodeUnitsInGraphemeClusters(StringView(oldText).substring(scanLength), 1);
262268

263-
if (isPunctuationForFirstLetter(c))
269+
if (isFollowingPunctuationForFirstLetter(c))
264270
length = scanLength + numCodeUnits;
265271
}
266272

0 commit comments

Comments
 (0)