Skip to content

Truly independent web browser

LibWeb: Advance each tab of a run to a tab stop of its own

sideshowbarkerffd0af703bad
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
index f038d3d5a62..34844d57618 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
@@ -83,24 +83,28 @@ fn shaped_glyphs_from(
shape.with_baseline_start(baseline_start_x).into_glyphs()
}
-/// `glyphs`, the glyphs of a text item past its leading tabs, after a glyph that paints nothing standing for the
-/// `tab_count` tabs and advancing to the tab stop at `tab_advance`, so that the code units of the item's glyphs line up
-/// with those of its text.
-fn glyphs_after_tab_spacer(
+/// `glyphs`, the glyphs of a text item past its leading tabs, after a glyph for each of those tabs that paints nothing
+/// and advances to the tab's stop by the tab's entry in `tab_advances`, so that the code units of the item's glyphs line
+/// up with those of its text.
+fn glyphs_after_tab_spacers(
glyphs: &libgfx_rust::text_layout::GlyphBuffer,
- tab_count: usize,
- tab_advance: f32,
+ tab_advances: &[f32],
) -> libgfx_rust::text_layout::GlyphBuffer {
use libgfx_rust::text_layout::{DrawGlyph, GlyphBuffer, PlacedGlyph};
- let tab_count_u32 = u32::try_from(tab_count).expect("tab counts fit in 32 bits");
+ let tab_count_u32 = u32::try_from(tab_advances.len()).expect("tab counts fit in 32 bits");
let mut with_spacer = GlyphBuffer::default();
- with_spacer.push_placed(PlacedGlyph {
- glyph: DrawGlyph::new(tab_advance, 0, tab_count, false),
- x: 0.0,
- y: glyphs.placed().next().map_or(0.0, |placed| placed.y),
- cluster_start: 0,
- is_rtl: false,
- });
+ let y = glyphs.placed().next().map_or(0.0, |placed| placed.y);
+ let mut x = 0.0;
+ for (index, &tab_advance) in tab_advances.iter().enumerate() {
+ with_spacer.push_placed(PlacedGlyph {
+ glyph: DrawGlyph::new(tab_advance, 0, 1, false),
+ x,
+ y,
+ cluster_start: u32::try_from(index).expect("tab counts fit in 32 bits"),
+ is_rtl: false,
+ });
+ x += tab_advance;
+ }
for placed in glyphs.placed() {
with_spacer.push_placed(PlacedGlyph {
cluster_start: placed.cluster_start + tab_count_u32,
@@ -2197,40 +2201,54 @@ impl<'context> RunItemResolver<'_, 'context> {
let prepared = self.prepared;
let mut inline_offset = 0.0f32;
let mut upright_advance_after_tabs = None;
- let mut tab_count = 0;
+ let mut tab_advances = Vec::new();
if prepared_item.has(PreparedItem::TAB_STOP) {
let tab_stop = prepared.tab_stops[self.next_tab_stop];
self.next_tab_stop += 1;
let tab_inline_size = tab_stop.tab_inline_size;
// https://drafts.csswg.org/css-text-3/#white-space-phase-2
- // "If the tab size is zero, preserved tabs are not rendered."
- if tab_inline_size != CssPixels::default() {
- let accumulated = self.accumulated_inline_size_for_tabs;
- let mut tab_stop_distance = if accumulated > CssPixels::default() {
- accumulated.div_as_fraction(tab_inline_size).ceil() * tab_inline_size - accumulated
- } else {
- tab_inline_size
- };
- if tab_stop_distance.to_double() < f64::from(tab_stop.zero_advance) * 0.5 {
- tab_stop_distance += tab_inline_size;
+ // "each preserved tab is rendered as a horizontal shift that lines up the start edge of the next glyph with
+ // the next tab stop. If this distance is less than 0.5ch, then the subsequent tab stop is used instead."
+ // NB: So each tab of a run advances from where the tab before it ended, to a tab stop of its own.
+ let distance_to_tab_stop = |position: CssPixels| {
+ // https://drafts.csswg.org/css-text-3/#white-space-phase-2
+ // "If the tab size is zero, preserved tabs are not rendered."
+ if tab_inline_size == CssPixels::default() {
+ return CssPixels::default();
}
- tab_stop_distance = tab_stop_distance * tab_stop.tab_count as usize;
- inline_offset = tab_stop_distance.to_double() as f32;
- }
+ // NB: The next tab stop is the first one after the position, even if the position is on a tab stop.
+ let mut distance = position.div_as_fraction(tab_inline_size).ceil() * tab_inline_size - position;
+ if distance <= CssPixels::default() {
+ distance += tab_inline_size;
+ }
+ if distance.to_double() < f64::from(tab_stop.zero_advance) * 0.5 {
+ distance += tab_inline_size;
+ }
+ distance
+ };
+ let accumulated = self.accumulated_inline_size_for_tabs;
+ let mut position = accumulated;
+ let mut previous_end = 0.0f32;
+ for _ in 0..tab_stop.tab_count {
+ position += distance_to_tab_stop(position);
+ let end = (position - accumulated).to_double() as f32;
+ tab_advances.push(end - previous_end);
+ previous_end = end;
+ }
+ inline_offset = previous_end;
upright_advance_after_tabs = tab_stop.upright_advance;
- tab_count = tab_stop.tab_count as usize;
}
let shape = prepared_item.shape();
let mut width = shape.width();
let mut owned_glyph_run = None;
// NB: Tabs that tab-size: 0 doesn't render still get the spacer glyph, so that the code units of the item's
// glyphs line up with those of its text.
- if inline_offset != 0.0 || upright_advance_after_tabs.is_some() || tab_count > 0 {
+ if inline_offset != 0.0 || upright_advance_after_tabs.is_some() || !tab_advances.is_empty() {
let mut glyphs = shaped_glyphs_from(shape, inline_offset);
if let Some(advance) = upright_advance_after_tabs {
width = set_glyphs_upright(&mut glyphs, inline_offset, advance);
- } else if tab_count > 0 {
- glyphs = glyphs_after_tab_spacer(&glyphs, tab_count, inline_offset);
+ } else if !tab_advances.is_empty() {
+ glyphs = glyphs_after_tab_spacers(&glyphs, &tab_advances);
}
owned_glyph_run = Some(Box::new(OwnedGlyphRun {
glyphs,
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/bidi/reference/bidi-tab-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/bidi/reference/bidi-tab-001-ref.html
new file mode 100644
index 00000000000..a65b8cc686f
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/bidi/reference/bidi-tab-001-ref.html
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: Interaction between tabs and bidi</title>
+<link rel="author" title="Koji Ishii" href="mailto:[email protected]">
+<link rel="author" title="Florian Rivoal" href="https://florian.rivoal.net">
+<style>
+div {
+ font-family: monospace;
+ font-size: 20px;
+ line-height: 1;
+ white-space: pre;
+ width: 10ch;
+ background: blue;
+ color: blue;
+}
+span {
+ background: yellow;
+}
+</style>
+<p>The test passes if the two boxes are identical.
+
+<div dir=ltr><span dir=ltr>&#9;0</span></div>
+<div dir=rtl><span dir=rtl>&#9;0</span></div>
+<div dir=ltr><span dir=ltrl>&#9;0</span></div>
+<div dir=rtl><span dir=rtl>&#9;0</span></div>
+
+<br>
+
+<div dir=ltr><span dir=ltr>&#9;0</span></div>
+<div dir=rtl><span dir=rtl>&#9;0</span></div>
+<div dir=ltr><span dir=ltrl>&#9;0</span></div>
+<div dir=rtl><span dir=rtl>&#9;0</span></div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-min-rendered-width-1-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-min-rendered-width-1-ref.html
new file mode 100644
index 00000000000..e9ede11ed9c
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-min-rendered-width-1-ref.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>CSS Text Test: minimum rendered width of tab character</title>
+ <link rel="author" title="Jonathan Kew" href="mailto:[email protected]">
+ <link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css">
+ <style>
+ span { background-color: yellow; display: inline-block; }
+ pre { position: absolute; top: 0; font: 16px Ahem; }
+ tt { font: 16px monospace; }
+ </style>
+</head>
+<body>
+<pre>
+</pre>
+<pre>
+</pre>
+<script>
+ let pre = document.getElementsByTagName("pre")[0];
+ let test = "";
+ for (i = 7.0; i <= 8.125; i += 0.125) {
+ test += `<span style="width:${i}ch"><tt>${i}ch</tt></span>\n`;
+ }
+ pre.innerHTML = test;
+ pre = document.getElementsByTagName("pre")[1];
+ test = "";
+ for (i = 0; i < 5; i++) {
+ test += `\t<tt>foo</tt>\n`;
+ }
+ for (i = 0; i < 5; i++) {
+ test += `\t\t<tt>foo</tt>\n`;
+ }
+ pre.innerHTML = test;
+</script>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-block-ancestor-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-block-ancestor-ref.html
new file mode 100644
index 00000000000..bb1cdc93a3f
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-block-ancestor-ref.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text reference</title>
+<link rel="author" title="Jonathan Kew" href="mailto:[email protected]">
+<style>
+div {
+ font: 16px monospace;
+ white-space: pre;
+}
+b {
+ font: bold 16px monospace;
+}
+</style>
+
+<p>Test passes if the five “A” letters below are vertically aligned with each other.
+
+<div>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>A</b>
+</div>
+<div>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>A</b>
+</div>
+<div>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>A</b>
+</div>
+<div>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>A</b>
+</div>
+<div>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>A</b>
+</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-inline-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-inline-001-ref.html
new file mode 100644
index 00000000000..0f412e26dfa
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-inline-001-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test reference</title>
+<link rel="author" title="Florian Rivoal" href="https://florian.rivoal.net/">
+<style>
+div {
+ font-family: monospace;
+}
+</style>
+
+<p>Test passes if the three “A” letters below are vertically aligned with eachother.
+<div class=ref><br>
+          A<br>
+          A<br>
+          A
+</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-inline-002-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-inline-002-ref.html
new file mode 100644
index 00000000000..ade76fea77f
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-inline-002-ref.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test reference</title>
+<link rel="author" title="Florian Rivoal" href="https://florian.rivoal.net/">
+<style>
+div {
+ font-family: monospace;
+ white-space: pre;
+ font-size: 2em;
+}
+.wrong { color: orange; }
+.right { color: blue; }
+</style>
+
+<p>Test passes if the black “A” lines up vertically with the blue one, not the orange one.
+
+ <div>            A</div>
+
+<div class=right>            A</div>
+<div class=wrong>              A</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-integer-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-integer-001-ref.html
new file mode 100644
index 00000000000..db1d6b0ed5b
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-integer-001-ref.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>CSS Text Test: tab-size: 4</title>
+ <link rel="author" title="David Storey" href="mailto:[email protected]">
+ <style type="text/css">
+ .container {
+ position: absolute;
+ }
+ .green {
+ position: absolute;
+ top: 0;
+ left: 0;
+ background: green;
+ }
+ .red {
+ position: absolute;
+ top: 0;
+ left: 0;
+ background: red;
+ tab-size: 4;
+ }
+ </style>
+</head>
+<body>
+ <p>The test passes if there is no red.</p>
+ <div class="container">
+ <pre class="green"> </pre>
+ </div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-length-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-length-001-ref.html
new file mode 100644
index 00000000000..3cdcd83762c
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-length-001-ref.html
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>CSS Text Test: tab-size: length</title>
+ <link rel="author" title="David Storey" href="mailto:[email protected]">
+ <link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+ <style type="text/css">
+ .container {
+ position: absolute;
+ }
+ .test {
+ font-family: Ahem;
+ font-size: 20px;
+
+ position: absolute;
+ top: 0;
+ left: 0;
+ background: green;
+
+ }
+ </style>
+</head>
+<body>
+ <p>The test passes if there is no red.</p>
+ <div class="container">
+ <pre class="green test"> </pre>
+ </div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/break-spaces-tab-003-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/break-spaces-tab-003-ref.html
new file mode 100644
index 00000000000..67a31705406
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/break-spaces-tab-003-ref.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Test reference</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="stylesheet" type="text/css" href="../../../../fonts/ahem.css" />
+<style>
+div {
+ font: 20px/1 Ahem;
+ color: green;
+}
+</style>
+
+<p>Test passes if there are two <strong>filled green squares</strong> and <strong>no red</strong>.</p>
+<div>X<br><br><br><br><br>X</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/pre-wrap-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/pre-wrap-001-ref.html
new file mode 100644
index 00000000000..719d3408625
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/pre-wrap-001-ref.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test reference file</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="stylesheet" type="text/css" href="../../../../fonts/ahem.css" />
+<style>
+div {
+ font-size: 20px;
+ font-family: Ahem;
+ line-height: 1em;
+ color: green;
+}
+</style>
+<body>
+ <p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+ <div>XX<br>XX</div>
+</body>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/tab-stop-threshold-002-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/tab-stop-threshold-002-ref.html
new file mode 100644
index 00000000000..35c568bbcac
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/tab-stop-threshold-002-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS test reference</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<style>
+div {
+ white-space: pre;
+ font-family: monospace;
+ tab-size: 8; /* the initial value, but since we're measuring against it, we might as well be sure */
+}
+</style>
+<p>Test passes if the 4 letters bellow are vertically aligned.
+<div> P</div>
+<div> A</div>
+<div> S</div>
+<div> S</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/tab-stop-threshold-007-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/tab-stop-threshold-007-ref.html
new file mode 100644
index 00000000000..d5db29b95b7
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/tab-stop-threshold-007-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Test reference</title>
+<style>
+div {
+ white-space: pre;
+ font-family: serif;
+ font-size: 32px;
+ tab-size: 0.8ch;
+}
+span {
+ background-color: green;
+}
+</style>
+<p>Test passes if the green bar below is 2.4 times as wide as the advance of a "0" glyph, and identical to the reference.</p>
+<div><span>&#9;&#9;&#9;</span></div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/bidi/bidi-tab-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/bidi/bidi-tab-001.html
new file mode 100644
index 00000000000..7f19a92e0cf
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/bidi/bidi-tab-001.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: Interaction between tabs and bidi</title>
+<link rel="author" title="Koji Ishii" href="mailto:[email protected]">
+<link rel="author" title="Florian Rivoal" href="https://florian.rivoal.net">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-2">
+<link rel="help" href="http://unicode.org/reports/tr9/#L1">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/bidi/reference/bidi-tab-001-ref.html">
+<meta name=assert content="with unicode-bidi: plaintext, lines from bidi paragraphs with strong directionality use that direction">
+<style>
+div {
+ font-family: monospace;
+ font-size: 20px;
+ line-height: 1;
+ white-space: pre;
+ width: 10ch;
+ background: blue;
+ color: blue;
+}
+span {
+ background: yellow;
+}
+</style>
+<p>The test passes if the two boxes are identical.
+
+<div dir=ltr><span dir=ltr>&#9;0</span></div>
+<div dir=rtl><span dir=rtl>&#9;0</span></div>
+<div dir=ltr><span dir=rtl>&#9;0</span></div>
+<div dir=rtl><span dir=ltr>&#9;0</span></div>
+
+<br>
+
+<div dir=ltr><span dir=ltr>&#9;0</span></div>
+<div dir=rtl><span dir=rtl>&#9;0</span></div>
+<div dir=ltr><span dir=ltrl>&#9;0</span></div>
+<div dir=rtl><span dir=rtl>&#9;0</span></div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-min-rendered-width-1.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-min-rendered-width-1.html
new file mode 100644
index 00000000000..a3dae30de9d
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-min-rendered-width-1.html
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>CSS Text Test: minimum rendered width of tab character</title>
+ <link rel="author" title="Jonathan Kew" href="mailto:[email protected]">
+ <link rel="reviewer" title="Xidorn Quan" href="https://www.upsuper.org/">
+ <link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-2">
+ <link rel="match" href="../../../../../expected/wpt-import/css/css-text/tab-size/tab-min-rendered-width-1-ref.html">
+ <meta name="assert" content="If [rendered width of tab would be] less than 0.5ch, then the subsequent tab stop is used instead.">
+ <link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css">
+ <style>
+ span { background-color: yellow; display: inline-block; }
+ /* Using 16px Ahem means that the 'ch' unit will be evenly divisible by 8 (for the 0.125ch
+ increment used below) without running into floating-point accuracy limitations */
+ pre { position: absolute; top: 0; font: 16px Ahem; }
+ tt { font: 16px monospace; }
+ </style>
+</head>
+<body>
+<pre>
+</pre>
+<script>
+ let pre = document.getElementsByTagName("pre")[0];
+ let test = "";
+ for (i = 7.0; i <= 8.125; i += 0.125) {
+ test += `<span style="width:${i}ch"><tt>${i}ch</tt></span>&#9;<tt>foo</tt>\n`;
+ }
+ pre.innerHTML = test;
+</script>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-block-ancestor.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-block-ancestor.html
new file mode 100644
index 00000000000..34d1a6fc66f
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-block-ancestor.html
@@ -0,0 +1,48 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: tab-size based on block ancestor's space</title>
+<link rel="author" title="Jonathan Kew" href="mailto:[email protected]">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#tab-size-property">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/tab-size/tab-size-block-ancestor-ref.html">
+<meta name="assert" content="tab width is based on space character in the block ancestor">
+<style>
+div {
+ font: 16px monospace;
+ white-space: pre;
+ tab-size: 10;
+}
+.test1 span {
+ font-size: 1px;
+}
+.test2 span {
+ font-size: 10px;
+}
+.test3 span {
+ tab-size: 5;
+}
+.test4 span {
+ font-size: 10px;
+ tab-size: 2.5;
+}
+b {
+ font: bold 16px monospace;
+}
+</style>
+
+<p>Test passes if the five “A” letters below are vertically aligned with each other.
+
+<div>
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>A</b><!-- indented by 10 spaces -->
+</div>
+<div class=test1>
+<span>&#9;<b>A</b></span>
+</div>
+<div class=test2>
+<span>&#9;<b>A</b></span>
+</div>
+<div class=test3>
+<span>&#9;&#9;<b>A</b></span>
+</div>
+<div class=test4>
+<span>&#9;&#9;&#9;&#9;<b>A</b></span>
+</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-inline-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-inline-001.html
new file mode 100644
index 00000000000..f7a736a8647
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-inline-001.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: inline box tab-size</title>
+<link rel="author" title="Florian Rivoal" href="https://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#tab-size-property">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/tab-size/tab-size-inline-001-ref.html">
+<meta name="assert" content="tab-size applies to inline boxes">
+<style>
+div {
+ font-family: monospace;
+ white-space: pre;
+ tab-size: 2;
+}
+.t5 {
+ tab-size: 5;
+}
+.t10 {
+ tab-size: 10;
+}
+</style>
+
+<p>Test passes if the three “A” letters below are vertically aligned with eachother.
+
+<div>
+          A
+<span class=t5>&#x09;&#x09;A</span>
+<span class=t10>&#x09;A</span>
+</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-inline-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-inline-002.html
new file mode 100644
index 00000000000..4357a9ea33a
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-inline-002.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: inline box tab-size tab stops</title>
+<link rel="author" title="Florian Rivoal" href="https://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#tab-size-property">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-2">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/tab-size/tab-size-inline-002-ref.html">
+<meta name="assert" content="tab-stops are calculated separatey for each tab with a different tab-size, not stacked up somehow">
+<style>
+div {
+ font-family: monospace;
+ white-space: pre;
+ tab-size: 10;
+ font-size: 2em;
+}
+span {
+ tab-size: 4;
+}
+.wrong { color: orange; }
+.right { color: blue; }
+</style>
+
+<p>Test passes if the black “A” lines up vertically with the blue one, not the orange one.
+
+<div>&#x09;<span>&#x09;A</span></div>
+
+<div class=right>            A</div> <!-- 12 = n * 4, such with n such that n*4 > 10 -->
+<div class=wrong>              A</div> <!-- 14 = 10 + 4 -->
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-integer-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-integer-001.html
new file mode 100644
index 00000000000..bec8f215e19
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-integer-001.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>CSS Text Test: tab-size: 4</title>
+ <link rel="author" title="David Storey" href="mailto:[email protected]">
+ <link rel="reviewer" title="Rebecca Hauck" href="mailto:[email protected]">
+ <link rel="help" href="http://www.w3.org/TR/css-text-3/#tab-size">
+ <link rel="match" href="../../../../../expected/wpt-import/css/css-text/tab-size/tab-size-integer-001-ref.html">
+ <meta name="assert" content="Tab should be rendered as 4 times the space character’s advance width (U+0020)">
+ <style type="text/css">
+ .container {
+ position: absolute;
+ }
+ .green {
+ position: absolute;
+ top: 0;
+ left: 0;
+ background: green;
+ }
+ .red {
+ position: absolute;
+ top: 0;
+ left: 0;
+ background: red;
+ tab-size: 4;
+ }
+ </style>
+</head>
+<body>
+ <p>The test passes if there is no red.</p>
+ <div class="container">
+ <pre class="red">&#09;</pre>
+ <pre class="green"> </pre>
+ </div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-integer-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-integer-002.html
new file mode 100644
index 00000000000..81652a502f3
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-integer-002.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>CSS Text Test: tab-size: -4</title>
+ <link rel="author" title="David Storey" href="mailto:[email protected]">
+ <link rel="reviewer" title="Rebecca Hauck" href="mailto:[email protected]">
+ <link rel="help" href="http://www.w3.org/TR/css-text-3/#tab-size">
+ <link rel="match" href="../../../../../expected/wpt-import/css/css-text/tab-size/tab-size-integer-001-ref.html">
+ <meta name="assert" content="Tab-size negative values are not allowed">
+ <style type="text/css">
+ .container {
+ position: absolute;
+ }
+ .green {
+ position: absolute;
+ top: 0;
+ left: 0;
+ background: green;
+ }
+ .red {
+ position: absolute;
+ top: 0;
+ left: 0;
+ background: red;
+ tab-size: 4;
+ tab-size: -4;
+ }
+ </style>
+</head>
+<body>
+ <p>The test passes if there is no red.</p>
+ <div class="container">
+ <pre class="red">&#09;</pre>
+ <pre class="green"> </pre>
+ </div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-integer-003.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-integer-003.html
new file mode 100644
index 00000000000..1a0e1750cdc
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-integer-003.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>CSS Text Test: tab-size: 0</title>
+ <link rel="author" title="David Storey" href="mailto:[email protected]">
+ <link rel="reviewer" title="Rebecca Hauck" href="mailto:[email protected]">
+ <link rel="help" href="http://www.w3.org/TR/css-text-3/#tab-size">
+ <link rel="match" href="../../../../../expected/wpt-import/css/css-text/tab-size/tab-size-integer-001-ref.html">
+ <meta name="assert" content="Tab should be rendered as 0 times the space character’s advance width (U+0020)">
+ <style type="text/css">
+ .container {
+ position: absolute;
+ }
+ .green {
+ position: absolute;
+ top: 0;
+ left: 0;
+ background: green;
+ }
+ .red {
+ position: absolute;
+ top: 0;
+ left: 0;
+ background: red;
+ tab-size: 0;
+ }
+ </style>
+</head>
+<body>
+ <p>The test passes if there is no red.</p>
+ <div class="container">
+ <pre class="red">&#09;</pre>
+ <pre class="green"> </pre>
+ </div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-length-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-length-001.html
new file mode 100644
index 00000000000..839e6c18bb4
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-length-001.html
@@ -0,0 +1,39 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>CSS Text Test: tab-size: 1em</title>
+ <link rel="author" title="David Storey" href="mailto:[email protected]">
+ <link rel="reviewer" title="Rebecca Hauck" href="mailto:[email protected]">
+ <link rel="help" href="http://www.w3.org/TR/css-text-3/#tab-size">
+ <link rel="match" href="../../../../../expected/wpt-import/css/css-text/tab-size/tab-size-length-001-ref.html">
+ <meta name="assert" content="Tab should be rendered as 1em (20px)">
+ <link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+ <style type="text/css">
+ .container {
+ position: absolute;
+ }
+ .test {
+ font-family: Ahem;
+ font-size: 20px;
+
+ position: absolute;
+ top: 0;
+ left: 0;
+ }
+ .green {
+ background: green;
+ }
+ .red {
+ background: red;
+ tab-size: 1em;
+ }
+ </style>
+</head>
+<body>
+ <p>The test passes if there is no red.</p>
+ <div class="container">
+ <pre class="red test">&#09;</pre>
+ <pre class="green test"> </pre>
+ </div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-length-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-length-002.html
new file mode 100644
index 00000000000..7e18c9d78ad
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-length-002.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>CSS Text Test: tab-size: -1em</title>
+ <link rel="author" title="David Storey" href="mailto:[email protected]">
+ <link rel="reviewer" title="Rebecca Hauck" href="mailto:[email protected]">
+ <link rel="help" href="http://www.w3.org/TR/css-text-3/#tab-size">
+ <link rel="match" href="../../../../../expected/wpt-import/css/css-text/tab-size/tab-size-length-001-ref.html">
+ <meta name="assert" content="Tab-size negative length values are not allowed">
+ <link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+ <style type="text/css">
+ .container {
+ position: absolute;
+ }
+ .test {
+ font-family: Ahem;
+ font-size: 20px;
+
+ position: absolute;
+ top: 0;
+ left: 0;
+ }
+ .green {
+ background: green;
+ }
+ .red {
+ background: red;
+ tab-size: 1em;
+ tab-size: -1em;
+ }
+ </style>
+</head>
+<body>
+ <p>The test passes if there is no red.</p>
+ <div class="container">
+ <pre class="red test">&#09;</pre>
+ <pre class="green test"> </pre>
+ </div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-001.html
new file mode 100644
index 00000000000..fc34325dc89
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-001.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: wrapping opportunity after break-spaces tabs</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-1">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/pre-wrap-001-ref.html">
+<meta name="assert" content="There is a wrapping opportunity at the end of a sequence of tabs with white-space:break-spaces">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 20px/1 Ahem;
+}
+#test {
+ white-space: break-spaces;
+ color: green;
+ width: 16ch;
+}
+#ref {
+ color: red;
+ position: absolute;
+ z-index:-1;
+}
+</style>
+
+<p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+<div id=ref>XX<br>XX</div>
+<div id=test>XX&#x09;&#x09;XX</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-002.html
new file mode 100644
index 00000000000..985bd8598e7
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-002.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: wrapping opportunity after break-spaces tabs and space</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-1">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/pre-wrap-001-ref.html">
+<meta name="assert" content="There is a wrapping opportunity at the end of a sequence of tabs and spaces with white-space:break-spaces">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 20px/1 Ahem;
+}
+#test {
+ white-space: break-spaces;
+ color: green;
+ width: 16ch;
+}
+#ref {
+ color: red;
+ position: absolute;
+ z-index:-1;
+}
+</style>
+
+<p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+<div id=ref>XX<br>XX</div>
+<div id=test>XX &#x09; &#x09;XX</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-003.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-003.html
new file mode 100644
index 00000000000..44a3e944060
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-003.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: wrapping opportunity after each break-spaces tab</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-1">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/break-spaces-tab-003-ref.html">
+<meta name="assert" content="There is a wrapping opportunity after each tab in a sequence with white-space:break-spaces.">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 20px/1 Ahem;
+}
+#test {
+ white-space: break-spaces;
+ color: green;
+ width: 1ch;
+}
+#ref {
+ color: red;
+ position: absolute;
+ z-index:-1;
+}
+</style>
+
+<p>Test passes if there are two <strong>filled green squares</strong> and <strong>no red</strong>.</p>
+<div id=ref>X<br><br><br><br><br>X</div>
+<div id=test>X&#x09;&#x09;&#x09;&#x09;&#x09;X</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-004.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-004.html
new file mode 100644
index 00000000000..2445d5861b4
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-004.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: wrapping opportunity after each break-spaces space and tab</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-1">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/break-spaces-tab-003-ref.html">
+<meta name="assert" content="There is a wrapping opportunity after each tab and space in a sequence with white-space:break-spaces.">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 20px/1 Ahem;
+}
+#test {
+ white-space: break-spaces;
+ color: green;
+ width: 1ch;
+}
+#ref {
+ color: red;
+ position: absolute;
+ z-index:-1;
+}
+</style>
+
+<p>Test passes if there are two <strong>filled green squares</strong> and <strong>no red</strong>.</p>
+<div id=ref>X<br><br><br><br><br>X</div>
+<div id=test>X&#x09; &#x09;&#x09;X</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-001.html
new file mode 100644
index 00000000000..086757f8ab2
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-001.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: wrapping opportunity after pre-wrap tabs</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-1">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/pre-wrap-001-ref.html">
+<meta name="assert" content="There is a wrapping opportunity at the end of a sequence of tabs with white-space:pre-wrap">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 20px/1 Ahem;
+}
+#test {
+ white-space: pre-wrap;
+ color: green;
+ width: 16ch;
+}
+#ref {
+ color: red;
+ position: absolute;
+ z-index:-1;
+}
+</style>
+
+<p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+<div id=ref>XX<br>XX</div>
+<div id=test>XX&#x09;&#x09;XX</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-002.html
new file mode 100644
index 00000000000..d3f581c2ba4
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-002.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: wrapping opportunity after pre-wrap tabs and spaces</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-1">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/pre-wrap-001-ref.html">
+<meta name="assert" content="There is a wrapping opportunity at the end of a sequence of tabs and spaces with white-space:pre-wrap">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 20px/1 Ahem;
+}
+#test {
+ white-space: pre-wrap;
+ color: green;
+ width: 16ch;
+}
+#ref {
+ color: red;
+ position: absolute;
+ z-index:-1;
+}
+</style>
+
+<p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+<div id=ref>XX<br>XX</div>
+<div id=test>XX &#x09; &#x09;XX</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-003.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-003.html
new file mode 100644
index 00000000000..116a5398dbd
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-003.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: no wrapping opportunity between pre-wrap tabs</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-1">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/pre-wrap-001-ref.html">
+<meta name="assert" content="There is a wrapping opportunity at the end of a sequence of tabs with white-space:pre-wrap, but not between or before each tab.">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 20px/1 Ahem;
+}
+#test {
+ white-space: pre-wrap;
+ color: green;
+ width: 2ch;
+}
+#ref {
+ color: red;
+ position: absolute;
+ z-index:-1;
+}
+</style>
+
+<p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+<div id=ref>XX<br>XX</div>
+<div id=test>XX&#x09;&#x09;XX</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-004.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-004.html
new file mode 100644
index 00000000000..9fbb3e8c622
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-004.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: no wrapping opportunity between pre-wrap tabs and spaces</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-1">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/pre-wrap-001-ref.html">
+<meta name="assert" content="There is a wrapping opportunity at the end of a sequence of tabs and spaces with white-space:pre-wrap, but not between or before each.">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 20px/1 Ahem;
+}
+#test {
+ white-space: pre-wrap;
+ color: green;
+ width: 2ch;
+}
+#ref {
+ color: red;
+ position: absolute;
+ z-index:-1;
+}
+</style>
+
+<p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+<div id=ref>XX<br>XX</div>
+<div id=test>XX &#x09; &#x09;XX</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-005.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-005.html
new file mode 100644
index 00000000000..8399457266f
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-005.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: pre-wrap tabs hang</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-2">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/pre-wrap-001-ref.html">
+<meta name="assert" content="a sequence of pre-wrap tabs at the end of a line hangs.">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 20px/1 Ahem;
+}
+#test {
+ white-space: pre-wrap;
+ color: green;
+ width: 2ch;
+}
+#ref {
+ color: red;
+ position: absolute;
+ z-index:-1;
+}
+</style>
+
+<p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+<div id=ref>XX<br>XX</div>
+<div id=test>X<wbr>X&#x09;&#x09;XX</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-006.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-006.html
new file mode 100644
index 00000000000..d6fe7dccefe
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-wrap-tab-006.html
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: pre-wrap tabs and spaces hang</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-2">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/pre-wrap-001-ref.html">
+<meta name="assert" content="a sequence of pre-wrap tabs and spaces at the end of a line hangs.">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 20px/1 Ahem;
+}
+#test {
+ white-space: pre-wrap;
+ color: green;
+ width: 2ch;
+}
+#ref {
+ color: red;
+ position: absolute;
+ z-index:-1;
+}
+</style>
+
+<p>Test passes if there is a <strong>filled green square</strong> and <strong>no red</strong>.</p>
+<div id=ref>XX<br>XX</div>
+<div id=test>X<wbr>X&#x09; &#x09;&#x09; XX</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-threshold-002.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-threshold-002.html
new file mode 100644
index 00000000000..aa8e2b5de2a
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-threshold-002.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: the nearest tab stop is less than 0.5 ch away</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-2">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#tab-size-property">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/tab-stop-threshold-002-ref.html">
+<meta name="assert" content="A preserved tab pushes to the tab stop after the nearest one as long as we're closer to the nearest one than 0.5ch.">
+<style>
+div {
+ white-space: pre;
+ font-family: monospace;
+ tab-size: 8; /* the initial value, but since we're measuring against it, we might as well be sure */
+}
+span { display: inline-block; }
+#s1 { width: 7.6ch; }
+#s2 { width: 7.8ch; }
+#s3 { width: 7.9ch; }
+</style>
+
+<p>Test passes if the 4 letters bellow are vertically aligned.
+<div><span id=s1></span>&#9;P</div>
+<div><span id=s2></span>&#9;A</div>
+<div><span id=s3></span>&#9;S</div>
+<div> S</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-threshold-004.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-threshold-004.html
new file mode 100644
index 00000000000..6c27aaa643e
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-threshold-004.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: the nearest tab stop is less than 0.5 ch away, white-space:pre-wrap</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-2">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#tab-size-property">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/tab-stop-threshold-002-ref.html">
+<meta name="assert" content="A preserved tab pushes to the tab stop after the nearest one as long as we're closer to the nearest one than 0.5ch, under white-space:pre-wrap.">
+<style>
+div {
+ white-space: pre-wrap;
+ font-family: monospace;
+ tab-size: 8; /* the initial value, but since we're measuring against it, we might as well be sure */
+}
+span { display: inline-block; }
+#s1 { width: 7.6ch; }
+#s2 { width: 7.8ch; }
+#s3 { width: 7.9ch; }
+</style>
+
+<p>Test passes if the 4 letters bellow are vertically aligned.
+<div><span id=s1></span>&#9;P</div>
+<div><span id=s2></span>&#9;A</div>
+<div><span id=s3></span>&#9;S</div>
+<div> S</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-threshold-006.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-threshold-006.html
new file mode 100644
index 00000000000..669d17673d5
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-threshold-006.html
@@ -0,0 +1,25 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: the nearest tab stop is less than 0.5 ch away, white-space:break-spaces</title>
+<link rel="author" title="Florian Rivoal" href="http://florian.rivoal.net/">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#white-space-phase-2">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#tab-size-property">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/tab-stop-threshold-002-ref.html">
+<meta name="assert" content="A preserved tab pushes to the tab stop after the nearest one as long as we're closer to the nearest one than 0.5ch, under white-space:break-spaces.">
+<style>
+div {
+ white-space: break-spaces;
+ font-family: monospace;
+ tab-size: 8; /* the initial value, but since we're measuring against it, we might as well be sure */
+}
+span { display: inline-block; }
+#s1 { width: 7.6ch; }
+#s2 { width: 7.8ch; }
+#s3 { width: 7.9ch; }
+</style>
+
+<p>Test passes if the 4 letters bellow are vertically aligned.
+<div><span id=s1></span>&#9;P</div>
+<div><span id=s2></span>&#9;A</div>
+<div><span id=s3></span>&#9;S</div>
+<div> S</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-threshold-007.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-threshold-007.html
new file mode 100644
index 00000000000..a0fd7a76157
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-threshold-007.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text Test: the minimum tab advance is measured against the '0' glyph, not against the space</title>
+<link rel="help" href="https://drafts.csswg.org/css-text-4/#white-space-phase-2">
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#tab-size-property">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/reference/tab-stop-threshold-007-ref.html">
+<meta name="assert" content="A preserved tab whose distance to the next tab stop is less than 0.5ch advances to the subsequent tab stop, even when that distance is not less than half the advance of a space. In a proportional font a 0.4ch tab stop is wider than half a space but narrower than 0.5ch, so every tab advances two tab stops, which renders the same as a 0.8ch tab size.">
+<style>
+div {
+ white-space: pre;
+ font-family: serif;
+ font-size: 32px;
+ tab-size: 0.4ch;
+}
+span {
+ background-color: green;
+}
+</style>
+<p>Test passes if the green bar below is 2.4 times as wide as the advance of a "0" glyph, and identical to the reference.</p>
+<div><span>&#9;&#9;&#9;</span></div>
diff --git a/Tests/LibWeb/Text/expected/css/consecutive-tabs-advance-to-successive-tab-stops.txt b/Tests/LibWeb/Text/expected/css/consecutive-tabs-advance-to-successive-tab-stops.txt
new file mode 100644
index 00000000000..5d4c27768ea
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/consecutive-tabs-advance-to-successive-tab-stops.txt
@@ -0,0 +1,18 @@
+one-tab: 8.00 spaces
+two-tabs: 16.00 spaces
+three-tabs: 24.00 spaces
+text-then-two-tabs: 16.00 spaces
+longer-text-then-two-tabs: 16.00 spaces
+text-then-three-tabs: 24.00 spaces
+tab-size-4-two-tabs: 8.00 spaces
+tab-word-tab: 16.00 spaces
+tabs-in-two-nodes: 16.00 spaces
+one-tab characters: 0.00..8.00 8.00..8.72
+two-tabs characters: 0.00..8.00 8.00..16.00 16.00..16.72
+three-tabs characters: 0.00..8.00 8.00..16.00 16.00..24.00 24.00..24.72
+text-then-two-tabs characters: 0.00..1.00 1.00..8.00 8.00..16.00 16.00..16.72
+longer-text-then-two-tabs characters: 0.00..1.00 1.00..2.00 2.00..3.00 3.00..4.00 4.00..5.00 5.00..6.00 6.00..7.00 7.00..8.00 8.00..16.00 16.00..16.72
+text-then-three-tabs characters: 0.00..1.00 1.00..2.00 2.00..3.00 3.00..8.00 8.00..16.00 16.00..24.00 24.00..24.72
+tab-size-4-two-tabs characters: 0.00..1.00 1.00..2.00 2.00..4.00 4.00..8.00 8.00..8.72
+tab-word-tab characters: 0.00..1.00 1.00..8.00 8.00..8.59 8.59..16.00 16.00..16.72
+tabs-in-two-nodes characters: 0.00..1.00 1.00..8.00
diff --git a/Tests/LibWeb/Text/input/css/consecutive-tabs-advance-to-successive-tab-stops.html b/Tests/LibWeb/Text/input/css/consecutive-tabs-advance-to-successive-tab-stops.html
new file mode 100644
index 00000000000..b2cc0535fc7
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/consecutive-tabs-advance-to-successive-tab-stops.html
@@ -0,0 +1,72 @@
+<!DOCTYPE html>
+<script src="../include.js"></script>
+<style>
+ pre { font: 10px/20px Ahem; margin: 0; }
+</style>
+<div id="host"></div>
+<script>
+ test(() => {
+ // Each case is [id, tab-size, HTML]. The offset of the X is printed in units of the advance of a space, so
+ // with tab-size: 8, an X after two tabs sits at 16 whatever text comes before the tabs (if it's shorter than
+ // a tab stop).
+ const cases = [
+ ["one-tab", "8", "\tX"],
+ ["two-tabs", "8", "\t\tX"],
+ ["three-tabs", "8", "\t\t\tX"],
+ ["text-then-two-tabs", "8", "a\t\tX"],
+ ["longer-text-then-two-tabs", "8", "abcdefg\t\tX"],
+ ["text-then-three-tabs", "8", "abc\t\t\tX"],
+ ["tab-size-4-two-tabs", "4", "ab\t\tX"],
+ ["tab-word-tab", "8", "a\tb\tX"],
+ ["tabs-in-two-nodes", "8", "a\t<span>\t</span>X"],
+ ];
+ const host = document.getElementById("host");
+ for (const [id, tabSize, html] of cases) {
+ const pre = document.createElement("pre");
+ pre.style.tabSize = tabSize;
+ pre.innerHTML = html;
+ host.append(pre);
+ }
+ const space = (() => {
+ const pre = document.createElement("pre");
+ pre.textContent = " ";
+ host.append(pre);
+ const range = document.createRange();
+ range.selectNodeContents(pre.firstChild);
+ const width = range.getBoundingClientRect().width / 10;
+ pre.remove();
+ return width;
+ })();
+ const pres = host.querySelectorAll("pre");
+ cases.forEach(([id], index) => {
+ const pre = pres[index];
+ const walker = document.createTreeWalker(pre, NodeFilter.SHOW_TEXT);
+ let node;
+ while ((node = walker.nextNode())) {
+ const offset = node.data.indexOf("X");
+ if (offset < 0)
+ continue;
+ const range = document.createRange();
+ range.setStart(node, offset);
+ range.setEnd(node, offset + 1);
+ const x = range.getBoundingClientRect().left - pre.getBoundingClientRect().left;
+ println(`${id}: ${(x / space).toFixed(2)} spaces`);
+ }
+ });
+ // Each tab of a run spans its own stretch of the line, from where the character before it ends to its own
+ // tab stop.
+ cases.forEach(([id], index) => {
+ const text = pres[index].firstChild;
+ const left = pres[index].getBoundingClientRect().left;
+ const extents = [];
+ for (let offset = 0; offset < text.length; ++offset) {
+ const range = document.createRange();
+ range.setStart(text, offset);
+ range.setEnd(text, offset + 1);
+ const rect = range.getBoundingClientRect();
+ extents.push(`${((rect.left - left) / space).toFixed(2)}..${((rect.right - left) / space).toFixed(2)}`);
+ }
+ println(`${id} characters: ${extents.join(" ")}`);
+ });
+ });
+</script>