From 476fdcd79ba45cbb8316444a241e82b9a43fa609 Mon Sep 17 00:00:00 2001 From: Ahmad Saleem Date: Tue, 7 Jan 2025 00:16:59 -0800 Subject: [PATCH] Sync `input` specific unicode-bidi rendering from Web Specification https://bugs.webkit.org/show_bug.cgi?id=285252 rdar://142191490 Reviewed by Aditya Keerthi. This patch aligns WebKit with Web Specification [1]: [1] https://html.spec.whatwg.org/multipage/rendering.html#bidi-rendering This patch implements `input` specific rules for directionality being `auto` and move `textarea` and `pre` rules in UA stylesheet. The rationale is that `is:` can be lead to performance concern, so did the change in C++, it also matches Blink / Chromium. Despite aligning with specification, there is still ambiguity on how to deal with `password` and `text` input types for which following issue is raised [2]. [2] https://github.com/whatwg/html/issues/10896 * Source/WebCore/css/html.css: (textarea[dir=auto i], pre[dir=auto i]): * Source/WebCore/html/HTMLElement.cpp: (WebCore::unicodeBidiAttributeForDirAuto): * LayoutTests/imported/w3c/web-platform-tests/html/rendering/bidi-rendering/unicode-bidi-ua-rules-expected.txt: Rebaselined (WebCore::HTMLElement::collectPresentationalHintsForAttribute): Canonical link: https://commits.webkit.org/288511@main --- .../bidi-rendering/unicode-bidi-ua-rules-expected.txt | 8 ++++---- Source/WebCore/css/html.css | 4 ++++ Source/WebCore/html/HTMLElement.cpp | 6 ++++-- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/LayoutTests/imported/w3c/web-platform-tests/html/rendering/bidi-rendering/unicode-bidi-ua-rules-expected.txt b/LayoutTests/imported/w3c/web-platform-tests/html/rendering/bidi-rendering/unicode-bidi-ua-rules-expected.txt index f0736425b1df3..a8f2650d4b67b 100644 --- a/LayoutTests/imported/w3c/web-platform-tests/html/rendering/bidi-rendering/unicode-bidi-ua-rules-expected.txt +++ b/LayoutTests/imported/w3c/web-platform-tests/html/rendering/bidi-rendering/unicode-bidi-ua-rules-expected.txt @@ -108,10 +108,10 @@ PASS UA stylesheet rule for unicode-bidi, for PASS UA stylesheet rule for unicode-bidi, for PASS UA stylesheet rule for unicode-bidi, for PASS UA stylesheet rule for unicode-bidi, for -FAIL UA stylesheet rule for unicode-bidi, for assert_equals: with dir=auto expected "plaintext" but got "isolate" -FAIL UA stylesheet rule for unicode-bidi, for assert_equals: with dir=auto expected "plaintext" but got "isolate" -FAIL UA stylesheet rule for unicode-bidi, for assert_equals: with dir=auto expected "plaintext" but got "isolate" -FAIL UA stylesheet rule for unicode-bidi, for assert_equals: with dir=auto expected "plaintext" but got "isolate" +PASS UA stylesheet rule for unicode-bidi, for +PASS UA stylesheet rule for unicode-bidi, for +PASS UA stylesheet rule for unicode-bidi, for +PASS UA stylesheet rule for unicode-bidi, for PASS UA stylesheet rule for unicode-bidi, for PASS UA stylesheet rule for unicode-bidi, for PASS UA stylesheet rule for unicode-bidi, for diff --git a/Source/WebCore/css/html.css b/Source/WebCore/css/html.css index b703c1673de6f..d73bc40e948ea 100644 --- a/Source/WebCore/css/html.css +++ b/Source/WebCore/css/html.css @@ -1412,6 +1412,10 @@ thead, tbody, tfoot, tr, td, th, dir, dd, dl, dt, menu, ol, ul, li, bdi, output, unicode-bidi: isolate; } +textarea[dir=auto i], pre[dir=auto i] { + unicode-bidi: plaintext; +} + input[type=tel i]:dir(ltr) { direction: ltr; } bdo, bdo[dir] { diff --git a/Source/WebCore/html/HTMLElement.cpp b/Source/WebCore/html/HTMLElement.cpp index ad68f945b8752..db04f45830dcc 100644 --- a/Source/WebCore/html/HTMLElement.cpp +++ b/Source/WebCore/html/HTMLElement.cpp @@ -130,7 +130,9 @@ String HTMLElement::nodeName() const static inline CSSValueID unicodeBidiAttributeForDirAuto(HTMLElement& element) { ASSERT(!element.hasTagName(bdoTag)); - if (element.hasTagName(preTag) || element.hasTagName(textareaTag)) + ASSERT(!element.hasTagName(preTag)); + ASSERT(!element.hasTagName(textareaTag)); + if (RefPtr input = dynamicDowncast(element); input && (input->isTelephoneField() || input->isEmailField() || input->isSearchField() || input->isURLField())) return CSSValuePlaintext; return CSSValueIsolate; } @@ -246,7 +248,7 @@ void HTMLElement::collectPresentationalHintsForAttribute(const QualifiedName& na break; case AttributeNames::dirAttr: if (equalLettersIgnoringASCIICase(value, "auto"_s)) { - if (!hasTagName(bdoTag)) + if (!hasTagName(bdoTag) && !hasTagName(preTag) && !hasTagName(textareaTag)) addPropertyToPresentationalHintStyle(style, CSSPropertyUnicodeBidi, unicodeBidiAttributeForDirAuto(*this)); } else if (equalLettersIgnoringASCIICase(value, "rtl"_s) || equalLettersIgnoringASCIICase(value, "ltr"_s)) addPropertyToPresentationalHintStyle(style, CSSPropertyDirection, value);