Skip to content

Commit

Permalink
Cherry-pick 274073@main (6e67536). https://bugs.webkit.org/show_bug.c…
Browse files Browse the repository at this point in the history
…gi?id=268705

    text-transform test failures due to Lithuanian rules and out-of-flow characters
    https://bugs.webkit.org/show_bug.cgi?id=268705
    rdar://122251072

    Reviewed by Tim Nguyen.

    Changed so Lithuanian won't use the fast path, and so we won't consider out of line
    characters when doing title case.

    * LayoutTests/TestExpectations: Expect 3 more tests to pass. Also took off incorrect bug
    numbers. Many tests were marked with a closed bug, which is not what bug numbers in this
    file are supposed to mean.

    * Source/WTF/wtf/text/StringImpl.cpp:
    (WTF::needsTurkishCasingRules): Tweaked style.
    (WTF::needsGreekUppercasingRules): Ditto.
    (WTF::needsLithuanianCasingRules): Added.
    (WTF::StringImpl::convertToLowercaseWithLocale): Don't use fast path for Lithuanian.
    (WTF::StringImpl::convertToUppercaseWithLocale): Ditto.

    * Source/WebCore/rendering/RenderText.cpp:
    (WebCore::RenderText::previousCharacter const): Skip renderers that are not in flow.

    Canonical link: https://commits.webkit.org/274073@main

Canonical link: https://commits.webkit.org/266719.365@webkitglib/2.42
  • Loading branch information
darinadler authored and aperezdc committed Mar 14, 2024
1 parent 2ffb54b commit d74eb4f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 42 deletions.
34 changes: 16 additions & 18 deletions LayoutTests/TestExpectations
Original file line number Diff line number Diff line change
Expand Up @@ -2770,8 +2770,8 @@ webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/boundary-shapin
webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/boundary-shaping/boundary-shaping-004.html [ ImageOnlyFailure ]
webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/boundary-shaping/boundary-shaping-005.html [ ImageOnlyFailure ]
webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/boundary-shaping/boundary-shaping-010.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/hanging-punctuation/hanging-punctuation-first-001.xht [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/hanging-punctuation/hanging-punctuation-last-001.xht [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/hanging-punctuation/hanging-punctuation-first-001.xht [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/hanging-punctuation/hanging-punctuation-last-001.xht [ ImageOnlyFailure ]
webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/hyphens/hyphens-auto-001.html [ ImageOnlyFailure ]
webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/hyphens/hyphens-auto-010.html [ ImageOnlyFailure ]
webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/hyphens/hyphens-auto-inline-010.html [ ImageOnlyFailure ]
Expand Down Expand Up @@ -2825,24 +2825,22 @@ webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/shaping/shaping
webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/shaping/shaping-025.html [ ImageOnlyFailure ]
webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/shaping/shaping_lig-000.html [ ImageOnlyFailure ]
webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/tab-size/tab-size-spacing-001.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-001.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-002.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-003.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-004.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-005.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-006.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-001.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-002.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-003.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-004.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-005.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/text-align/text-align-justifyall-006.html [ ImageOnlyFailure ]
webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/text-encoding/shaping-join-003.html [ ImageOnlyFailure ]
webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/text-encoding/shaping-tatweel-002.html [ ImageOnlyFailure ]
webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/text-encoding/shaping-tatweel-003.html [ ImageOnlyFailure ]
webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/text-indent/text-indent-tab-positions-001.html [ ImageOnlyFailure ]
webkit.org/b/240837 imported/w3c/web-platform-tests/css/css-text/text-indent/anonymous-flex-item-001.html [ ImageOnlyFailure ]
webkit.org/b/240837 imported/w3c/web-platform-tests/css/css-text/text-indent/anonymous-grid-item-001.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-capitalize-026.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-capitalize-028.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-tailoring-001.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-upperlower-006.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-upperlower-039.html [ ImageOnlyFailure ]
webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-capitalize-033.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-capitalize-026.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-capitalize-028.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-tailoring-001.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-upperlower-006.html [ ImageOnlyFailure ]
webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-shaping-003.html [ ImageOnlyFailure ]
webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-shaping-002.html [ ImageOnlyFailure ]
webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/text-transform/text-transform-shaping-001.html [ ImageOnlyFailure ]
Expand Down Expand Up @@ -2947,14 +2945,14 @@ webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/word-boundary/w
webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/word-boundary/word-boundary-127.html [ ImageOnlyFailure ]
webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/word-boundary/word-boundary-128.html [ ImageOnlyFailure ]
webkit.org/b/214290 imported/w3c/web-platform-tests/css/css-text/word-boundary/word-boundary-129.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-004.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-004.html [ ImageOnlyFailure ]
webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-020.html [ ImageOnlyFailure ]
webkit.org/b/197430 imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-023.html [ ImageOnlyFailure ]
webkit.org/b/197430 imported/w3c/web-platform-tests/css/css-text/word-break/word-break-break-all-024.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/word-break/word-break-keep-all-003.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/word-break/word-break-keep-all-003.html [ ImageOnlyFailure ]
webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/word-break/word-break-keep-all-006.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/word-break/word-break-normal-my-000.html [ ImageOnlyFailure ]
webkit.org/b/183258 imported/w3c/web-platform-tests/css/css-text/word-break/word-break-normal-tdd-000.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/word-break/word-break-normal-my-000.html [ ImageOnlyFailure ]
imported/w3c/web-platform-tests/css/css-text/word-break/word-break-normal-tdd-000.html [ ImageOnlyFailure ]
webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/writing-system/writing-system-segment-break-001.html [ ImageOnlyFailure ]
webkit.org/b/195275 imported/w3c/web-platform-tests/css/css-text/writing-system/writing-system-text-transform-001.html [ ImageOnlyFailure ]
# <rdar://problem/50383285>
Expand Down
52 changes: 29 additions & 23 deletions Source/WTF/wtf/text/StringImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -517,56 +517,62 @@ Ref<StringImpl> StringImpl::convertToUppercaseWithoutLocale()
return newImpl;
}

static inline bool needsTurkishCasingRules(const AtomString& localeIdentifier)
static inline bool needsTurkishCasingRules(const AtomString& locale)
{
// Either "tr" or "az" locale, with ASCII case insensitive comparison and allowing for an ignored subtag.
UChar first = localeIdentifier[0];
UChar second = localeIdentifier[1];
UChar first = locale[0];
UChar second = locale[1];
return ((isASCIIAlphaCaselessEqual(first, 't') && isASCIIAlphaCaselessEqual(second, 'r'))
|| (isASCIIAlphaCaselessEqual(first, 'a') && isASCIIAlphaCaselessEqual(second, 'z')))
&& (localeIdentifier.length() == 2 || localeIdentifier[2] == '-');
&& (locale.length() == 2 || locale[2] == '-');
}

static inline bool needsGreekUppercasingRules(const AtomString& localeIdentifier)
static inline bool needsGreekUppercasingRules(const AtomString& locale)
{
// The "el" locale, with ASCII case insensitive comparison and allowing for an ignored subtag.
UChar first = localeIdentifier[0];
UChar second = localeIdentifier[1];
return (isASCIIAlphaCaselessEqual(first, 'e') && isASCIIAlphaCaselessEqual(second, 'l'))
&& (localeIdentifier.length() == 2 || localeIdentifier[2] == '-');
return isASCIIAlphaCaselessEqual(locale[0], 'e') && isASCIIAlphaCaselessEqual(locale[1], 'l')
&& (locale.length() == 2 || locale[2] == '-');
}

static inline bool needsLithuanianCasingRules(const AtomString& locale)
{
// The "lt" locale, with ASCII case insensitive comparison and allowing for an ignored subtag.
return isASCIIAlphaCaselessEqual(locale[0], 'l') && isASCIIAlphaCaselessEqual(locale[1], 't')
&& (locale.length() == 2 || locale[2] == '-');
}

Ref<StringImpl> StringImpl::convertToLowercaseWithLocale(const AtomString& localeIdentifier)
{
// Use the more-optimized code path most of the time.
// Assuming here that the only locale-specific lowercasing is the Turkish casing rules.
// FIXME: Could possibly optimize further by looking for the specific sequences
// that have locale-specific lowercasing. There are only three of them.
if (!needsTurkishCasingRules(localeIdentifier))
const char* locale;
if (needsTurkishCasingRules(localeIdentifier)) {
// Passing in the hardcoded locale "tr" is more efficient than
// allocating memory just to turn localeIdentifier into a C string, and we assume
// there is no difference between the lowercasing for "tr" and "az" locales.
// FIXME: Could optimize further by looking for the three sequences that have locale-specific lowercasing.
locale = "tr";
} else if (needsLithuanianCasingRules(localeIdentifier))
locale = "lt";
else
return convertToLowercaseWithoutLocale();

// FIXME: Could share more code with the main StringImpl::lower by factoring out
// this last part into a shared function that takes a locale string, since this is
// just like the end of that function.
// FIXME: Could share more code with convertToLowercaseWithoutLocale.

if (m_length > MaxLength)
CRASH();
int length = m_length;

// Below, we pass in the hardcoded locale "tr". Passing that is more efficient than
// allocating memory just to turn localeIdentifier into a C string, and we assume
// there is no difference between the uppercasing for "tr" and "az" locales.
auto upconvertedCharacters = StringView(*this).upconvertedCharacters();
const UChar* source16 = upconvertedCharacters;
UChar* data16;
auto newString = createUninitialized(length, data16);
UErrorCode status = U_ZERO_ERROR;
int realLength = u_strToLower(data16, length, source16, length, "tr", &status);
int realLength = u_strToLower(data16, length, source16, length, locale, &status);
if (U_SUCCESS(status) && realLength == length)
return newString;
newString = createUninitialized(realLength, data16);
status = U_ZERO_ERROR;
u_strToLower(data16, realLength, source16, length, "tr", &status);
u_strToLower(data16, realLength, source16, length, locale, &status);
if (U_FAILURE(status))
return *this;
return newString;
Expand All @@ -575,8 +581,6 @@ Ref<StringImpl> StringImpl::convertToLowercaseWithLocale(const AtomString& local
Ref<StringImpl> StringImpl::convertToUppercaseWithLocale(const AtomString& localeIdentifier)
{
// Use the more-optimized code path most of the time.
// Assuming here that the only locale-specific lowercasing is the Turkish casing rules,
// and that the only affected character is lowercase "i".
const char* locale;
if (needsTurkishCasingRules(localeIdentifier) && find('i') != notFound) {
// Passing in the hardcoded locale "tr" is more efficient than
Expand All @@ -585,6 +589,8 @@ Ref<StringImpl> StringImpl::convertToUppercaseWithLocale(const AtomString& local
locale = "tr";
} else if (needsGreekUppercasingRules(localeIdentifier))
locale = "el";
else if (needsLithuanianCasingRules(localeIdentifier))
locale = "lt";
else
return convertToUppercaseWithoutLocale();

Expand Down
3 changes: 2 additions & 1 deletion Source/WebCore/rendering/RenderText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1435,9 +1435,10 @@ static inline bool isInlineFlowOrEmptyText(const RenderObject& renderer)

UChar RenderText::previousCharacter() const
{
// find previous text renderer if one exists
const RenderObject* previousText = this;
while ((previousText = previousText->previousInPreOrder())) {
if (!previousText->isInFlow())
continue;
if (!isInlineFlowOrEmptyText(*previousText))
break;
}
Expand Down

0 comments on commit d74eb4f

Please sign in to comment.