aboutsummaryrefslogtreecommitdiffstats
path: root/resources
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2024-08-21 07:28:54 -0700
committerGitHub <noreply@github.com>2024-08-21 14:28:54 +0000
commit56280c62425bcf9478e613d26bca8704a898b5b1 (patch)
treeb1134ef2a3be5ed4e319154026942bf482f11f99 /resources
parent65bd5a3b9982c9af453fe97134e4f91e55b1df19 (diff)
downloadservo-56280c62425bcf9478e613d26bca8704a898b5b1.tar.gz
servo-56280c62425bcf9478e613d26bca8704a898b5b1.zip
layout: Add initial support for bidirectional text (BiDi) (#33148)
This adds supports for right-to-left text assigning bidi levels to all line items when necessary. This includes support for the `dir` attribute as well as corresponding CSS properties like `unicode-bidi`. It only implements right-to-left rendering for inline layout at the moment and doesn't include support for `dir=auto`. Because of missing features, this causes quite a few tests to start failing, as references become incorrect due to right-to-left rendering being active in some cases, but not others (before it didn't exist at all). Analysis of most of the new failures: ``` - /css/css-flexbox/gap-001-rtl.html /css/css-flexbox/gap-004-rtl.html - Require implementing BiDi in Flexbox, because the start and end inline margins are opposite the order of items. - /css/CSS2/bidi-text/direction-applies-to-*.xht /css/CSS2/bidi-text/direction-applies-to-002.xht /css/CSS2/bidi-text/direction-applies-to-003.xht /css/CSS2/bidi-text/direction-applies-to-004.xht - Broken due to a bug in tables, not allocating the right amount of width for a column. - /css/css-lists/inline-list.html - This fails because we wrongly insert a soft wrap opportunity between the start of an inline box and its first content. - /css/css-text/bidi/bidi-lines-001.html /css/css-text/bidi/bidi-lines-002.html /css/CSS2/text/bidi-flag-emoji.html - We do not fully support unicode-bidi: plaintext - /css/css-text/text-align/text-align-end-010.html /css/css-text/text-align/text-align-justify-006.html /css/css-text/text-align/text-align-start-010.html /html/dom/elements/global-attributes/* - We do not support dir=auto yet. - /css/css-text/white-space/tab-bidi-001.html - Servo doesn't support tab stops - /css/CSS2/positioning/abspos-block-level-001.html /css/css-text/word-break/word-break-normal-ar-000.html - Do not yet support RTL layout in block - /css/css-text/white-space/pre-wrap-018.html - Even in RTL contexts, spaces at the end of the line must hang and not be reordered - /css/css-text/white-space/trailing-space-and-text-alignment-rtl-002.html - We are letting spaces hang with white-space: pre, but they shouldn't hang. ``` Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Rakhi Sharma <atbrakhi@igalia.com>
Diffstat (limited to 'resources')
-rw-r--r--resources/servo.css6
-rw-r--r--resources/user-agent.css82
2 files changed, 81 insertions, 7 deletions
diff --git a/resources/servo.css b/resources/servo.css
index 63172fe79b0..543167dca24 100644
--- a/resources/servo.css
+++ b/resources/servo.css
@@ -188,6 +188,12 @@ svg > * {
all: inherit;
}
+*|*::-servo-anonymous-box {
+ unicode-bidi: inherit;
+ direction: inherit;
+ writing-mode: inherit;
+}
+
/* style for text node. */
*|*::-servo-legacy-text {
text-overflow: inherit;
diff --git a/resources/user-agent.css b/resources/user-agent.css
index e7acd5fdf2c..33884f8ea0f 100644
--- a/resources/user-agent.css
+++ b/resources/user-agent.css
@@ -130,14 +130,82 @@ wbr { display-outside: break-opportunity; } /* this also has bidi implications *
nobr wbr { white-space: normal; }
-[dir]:dir(ltr), bdi:dir(ltr), input[type=tel]:dir(ltr) { direction: ltr; }
-[dir]:dir(rtl), bdi:dir(rtl) { direction: rtl; }
+/* Eventually we will want the following, but currently Servo does not
+ properly parse the :dir pseudo-selector.
+[dir=ltr i], bdi:dir(ltr), input[type=tel]:dir(ltr) { direction: ltr; }
+*/
+[dir=ltr i] { direction: ltr; }
+[dir=rtl i] { direction: rtl; }
+[dir=ltr i], [dir=rtl i], [dir=auto i] { unicode-bidi: isolate; }
+
+/* To ensure http://www.w3.org/TR/REC-html40/struct/dirlang.html#style-bidi:
+ *
+ * "When a block element that does not have a dir attribute is transformed to
+ * the style of an inline element by a style sheet, the resulting presentation
+ * should be equivalent, in terms of bidirectional formatting, to the
+ * formatting obtained by explicitly adding a dir attribute (assigned the
+ * inherited value) to the transformed element."
+ *
+ * and the rules in http://dev.w3.org/html5/spec/rendering.html#rendering
+ */
+address,
+article,
+aside,
+blockquote,
+body,
+caption,
+center,
+col,
+colgroup,
+dd,
+dir,
+div,
+dl,
+dt,
+fieldset,
+figcaption,
+figure,
+footer,
+form,
+h1,
+h2,
+h3,
+h4,
+h5,
+h6,
+header,
+hgroup,
+hr,
+html,
+legend,
+li,
+listing,
+main,
+marquee,
+menu,
+nav,
+noframes,
+ol,
+p,
+plaintext,
+pre,
+search,
+section,
+summary,
+table,
+tbody,
+td,
+tfoot,
+th,
+thead,
+tr,
+ul,
+xmp
+{
+ unicode-bidi: isolate;
+}
-address, blockquote, center, div, figure, figcaption, footer, form, header, hr,
-legend, listing, main, p, plaintext, pre, summary, xmp, article, aside, h1, h2,
-h3, h4, h5, h6, hgroup, nav, section, table, caption, colgroup, col, thead,
-tbody, tfoot, tr, td, th, dir, dd, dl, dt, menu, ol, ul, li, bdi, output,
-[dir=ltr i], [dir=rtl i], [dir=auto i] {
+bdi, output {
unicode-bidi: isolate;
}