Skip to content

Truly independent web browser

LibWeb: Mask rendered text for -webkit-text-security

sideshowbarker481b5db1ef4f
diff --git a/Libraries/LibWeb/CSS/Enums.json b/Libraries/LibWeb/CSS/Enums.json
index c0fdf3a95dd..c26452e9e66 100644
--- a/Libraries/LibWeb/CSS/Enums.json
+++ b/Libraries/LibWeb/CSS/Enums.json
@@ -1211,6 +1211,12 @@
"optimizelegibility",
"geometricprecision"
],
+ "text-security": [
+ "none",
+ "disc",
+ "circle",
+ "square"
+ ],
"text-transform": [
"capitalize",
"full-size-kana",
diff --git a/Libraries/LibWeb/CSS/Properties.json b/Libraries/LibWeb/CSS/Properties.json
index d128bb83968..cb821540574 100644
--- a/Libraries/LibWeb/CSS/Properties.json
+++ b/Libraries/LibWeb/CSS/Properties.json
@@ -302,6 +302,19 @@
"color"
]
},
+ "-webkit-text-security": {
+ "style-group": "InheritedTextValues",
+ "animation-type": "discrete",
+ "inherited": true,
+ "initial": "none",
+ "requires-computation": "never",
+ "valid-identifiers": [
+ "none",
+ "disc",
+ "circle",
+ "square"
+ ]
+ },
"-webkit-text-stroke": {
"affects-layout": false,
"initial": "0 currentColor",
diff --git a/Libraries/LibWeb/Rust/src/css/computed_value_types.rs b/Libraries/LibWeb/Rust/src/css/computed_value_types.rs
index 513f1095f56..e6bffc0d89d 100644
--- a/Libraries/LibWeb/Rust/src/css/computed_value_types.rs
+++ b/Libraries/LibWeb/Rust/src/css/computed_value_types.rs
@@ -573,6 +573,7 @@ pub struct InheritedTextValues {
pub text_justify: u8,
pub line_break: u8,
pub tab_size_is_number: bool,
+ pub text_security: u8,
pub letter_spacing: crate::css::css_pixels::CssPixels,
pub word_spacing: crate::css::css_pixels::CssPixels,
pub tab_size_length: crate::css::css_pixels::CssPixels,
diff --git a/Libraries/LibWeb/Rust/src/css/computed_values.rs b/Libraries/LibWeb/Rust/src/css/computed_values.rs
index f022ed74f9e..0a362cfb5b0 100644
--- a/Libraries/LibWeb/Rust/src/css/computed_values.rs
+++ b/Libraries/LibWeb/Rust/src/css/computed_values.rs
@@ -251,6 +251,7 @@ impl_computed_payload_clone_and_eq!(InheritedTextValues {
webkit_text_stroke_width => paint_only,
text_shadow,
text_transform,
+ text_security,
text_wrap_style,
text_decoration_skip_ink,
text_underline_position,
@@ -2713,6 +2714,7 @@ pub(crate) fn group_field_descriptors(group: usize) -> &'static [GroupFieldDescr
_WEBKIT_TEXT_STROKE_WIDTH @ webkit_text_stroke_width => PixelLengthF64,
TEXT_SHADOW => RequireKeyword(k::NONE),
TEXT_JUSTIFY @ text_justify => EnumKeyword(enums::keyword_to_text_justify),
+ _WEBKIT_TEXT_SECURITY @ text_security => EnumKeyword(enums::keyword_to_text_security),
TEXT_TRANSFORM @ text_transform => EnumKeyword(enums::keyword_to_text_transform),
TEXT_WRAP_STYLE @ text_wrap_style => EnumKeyword(enums::keyword_to_text_wrap_style),
TEXT_DECORATION_SKIP_INK @ text_decoration_skip_ink => EnumKeyword(enums::keyword_to_text_decoration_skip_ink),
@@ -3644,7 +3646,7 @@ const PAYLOAD_TYPED_LONGHANDS: [(u16, usize, usize, u8); 18] = {
/// The longhands whose computed value a handle of their group's payload holds as it is, by the
/// handle's offset: the group's values keep no second copy of them.
-const PAYLOAD_HANDLE_LONGHANDS: [(u16, usize, usize); 53] = {
+const PAYLOAD_HANDLE_LONGHANDS: [(u16, usize, usize); 54] = {
use crate::css::computed_value_types::{BackgroundValues, EffectsValues, FontValues, MaskValues, SVGResetValues};
use crate::css::property_metadata::property_id as p;
use std::mem::offset_of;
@@ -3654,6 +3656,11 @@ const PAYLOAD_HANDLE_LONGHANDS: [(u16, usize, usize); 53] = {
let effects = group_index::EFFECTS;
let svg_reset = group_index::SVG_RESET;
[
+ (
+ p::BLOCK_ELLIPSIS,
+ group_index::INHERITED_TEXT,
+ offset_of!(InheritedTextValues, block_ellipsis),
+ ),
(
p::BACKGROUND_IMAGE,
background,
@@ -6250,6 +6257,7 @@ impl InheritedTextValues {
webkit_text_stroke_color: crate::css::computed_value_types::StyleColor::CURRENT_COLOR,
webkit_text_stroke_width: 0.0,
text_shadow: RetainedComputedShadowList::from_vec(Vec::new()),
+ text_security: css_enums::text_security::NONE,
text_transform: enum_value(css_enums::keyword_to_text_transform(css_enums::keyword::NONE)),
text_wrap_style: enum_value(css_enums::keyword_to_text_wrap_style(css_enums::keyword::AUTO)),
text_decoration_skip_ink: enum_value(css_enums::keyword_to_text_decoration_skip_ink(
diff --git a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
index d1b6d84de5e..ea395f6dbc9 100644
--- a/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/style_invalidation.rs
@@ -543,7 +543,11 @@ fn property_invalidation(property: u16, old: ComputedValuesView<'_>, new: Comput
}
if matches!(
property,
- property_id::APPEARANCE | property_id::CONTENT | property_id::CONTENT_VISIBILITY | property_id::TEXT_TRANSFORM
+ property_id::APPEARANCE
+ | property_id::CONTENT
+ | property_id::CONTENT_VISIBILITY
+ | property_id::TEXT_TRANSFORM
+ | property_id::_WEBKIT_TEXT_SECURITY
) {
return StyleInvalidation::rebuild_layout_tree_from(REBUILD_ROOT_SELF);
}
diff --git a/Libraries/LibWeb/Rust/src/layout/rendered_text.rs b/Libraries/LibWeb/Rust/src/layout/rendered_text.rs
index 74ba846f28d..5667c2047ce 100644
--- a/Libraries/LibWeb/Rust/src/layout/rendered_text.rs
+++ b/Libraries/LibWeb/Rust/src/layout/rendered_text.rs
@@ -210,6 +210,10 @@ impl TextContent {
&self.rendered
}
+ pub(super) fn rendered_text_edits(&self) -> &[RenderedTextEdit] {
+ &self.edits
+ }
+
pub(super) fn is_password_input(&self) -> bool {
self.rendering_key
.as_ref()
@@ -525,6 +529,7 @@ fn sync_text_content(arena: &mut LayoutNodeArena, id: NodeSlotId) {
let source_range = arena.text_source_range(id, source_length);
let options = TextRenderingOptions {
text_transform: inherited.text_transform,
+ text_security: inherited.text_security,
white_space_collapse: parent_style.white_space_collapse(),
is_password_input: input.is_password_input,
dom_start_offset: source_range.start,
@@ -540,10 +545,14 @@ fn sync_text_content(arena: &mut LayoutNodeArena, id: NodeSlotId) {
.is_some_and(|content| content.rendering_key.as_ref() == Some(&key))
{
let source = input.data.to_utf16().into_owned();
- let untransformed_text_is_ascii_whitespace = source.iter().all(|unit| matches!(unit, 0x09..=0x0d | 0x20));
- let svg_source_text =
- super::node_facts::kind_is_svg_box(arena.data(parent).kind.get()).then(|| Box::from(&source[..]));
+ let masks_text =
+ options.text_security != crate::css::css_enums::text_security::NONE || options.is_password_input;
+ let untransformed_text_is_ascii_whitespace =
+ !masks_text && source.iter().all(|unit| matches!(unit, 0x09..=0x0d | 0x20));
+ let is_svg = super::node_facts::kind_is_svg_box(arena.data(parent).kind.get());
+ let svg_source_text = (is_svg && !masks_text).then(|| Box::from(&source[..]));
let rendered = render_text(source, key.locale.as_deref(), key.options);
+ let svg_source_text = svg_source_text.or_else(|| is_svg.then(|| Box::from(&rendered.text[..])));
let content = TextContent {
rendered: Arc::new(RenderedText {
svg_source_text,
@@ -870,6 +879,7 @@ mod tests {
options: TextRenderingOptions {
text_transform: text_transform::UPPERCASE,
white_space_collapse: crate::css::css_enums::white_space_collapse::PRESERVE,
+ text_security: crate::css::css_enums::text_security::NONE,
is_password_input: false,
dom_start_offset: 0,
dom_length_in_code_units: 3,
@@ -930,6 +940,7 @@ mod tests {
options: TextRenderingOptions {
text_transform: text_transform::NONE,
white_space_collapse: crate::css::css_enums::white_space_collapse::COLLAPSE,
+ text_security: crate::css::css_enums::text_security::NONE,
is_password_input: false,
dom_start_offset: 0,
dom_length_in_code_units: 5,
diff --git a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
index d9d758a6387..f6220f6332e 100644
--- a/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/svg_formatting_context.rs
@@ -44,6 +44,38 @@ pub struct FfiSvgTextCharacterCell {
pub starts_typographic_character: bool,
}
+fn svg_text_cell_for_source_span(
+ cells: &[FfiSvgTextCharacterCell],
+ start: usize,
+ end: usize,
+) -> FfiSvgTextCharacterCell {
+ if let Some((&first, others)) = cells[start..end].split_first() {
+ let mut bounds = FloatRect::new(first.x, first.y, first.width, first.height);
+ for other in others {
+ bounds = united_even_if_empty(
+ Some(bounds),
+ FloatRect::new(other.x, other.y, other.width, other.height),
+ );
+ }
+ return FfiSvgTextCharacterCell {
+ x: bounds.x,
+ y: bounds.y,
+ width: bounds.width,
+ height: bounds.height,
+ ..first
+ };
+ }
+ // A source character removed by casing has an empty cell at its position between the surrounding glyphs.
+ let mut cell = cells.get(start).copied().unwrap_or_else(|| {
+ let mut last = cells.last().copied().unwrap_or_default();
+ last.x += last.width;
+ last
+ });
+ cell.width = 0.0;
+ cell.starts_typographic_character = false;
+ cell
+}
+
/// What shaping one SVG text run yields: its glyphs, its total advance, the union of its glyph
/// cells, and the glyph cell of every one of its code units.
struct ShapedSvgText {
@@ -1663,6 +1695,46 @@ impl<'pass> SvgFormattingContext<'pass> {
Some(std::sync::Arc::from(run))
}
+ // SVG DOM indices address UTF-16 code units before text transformation. Keep the painted glyphs and their
+ // spacing, and publish the cell occupied by each source code unit of the masked run.
+ // https://svgwg.org/svg2-draft/text.html#TermAddressableCharacter
+ fn append_svg_run_dom_cells(
+ &self,
+ mut node: Node,
+ cells: Vec<FfiSvgTextCharacterCell>,
+ out: &mut Vec<FfiSvgTextCharacterCell>,
+ ) {
+ if self.style(self.parent(node)).inherited_text().text_security == crate::css::css_enums::text_security::NONE {
+ out.extend(cells);
+ return;
+ }
+ let mut cells = cells.as_slice();
+ while !node.is_invalid() && node_facts::kind_is_text(self.node_kind(node)) {
+ let content = self.run.pass.text_content(node);
+ node = self.next_sibling(node);
+ let Some(masked_text) = &content.svg_source_text else {
+ continue;
+ };
+ let (node_cells, rest) = cells.split_at(masked_text.len());
+ let mut cursor = 0;
+ for edit in content.rendered_text_edits() {
+ let start = edit.rendered_start_offset;
+ let end = start + edit.rendered_length_in_code_units;
+ out.extend_from_slice(&node_cells[cursor..start]);
+ cursor = end;
+ if edit.dom_length_in_code_units == 0 {
+ continue;
+ }
+ let mut cell = svg_text_cell_for_source_span(node_cells, start, end);
+ out.push(cell);
+ cell.starts_typographic_character = false;
+ out.extend(std::iter::repeat_n(cell, edit.dom_length_in_code_units - 1));
+ }
+ out.extend_from_slice(&node_cells[cursor..]);
+ cells = rest;
+ }
+ }
+
fn append_svg_source_text(&self, text_node: Node, out: &mut Vec<u16>) {
let content = self.run.pass.arena().text_content(text_node);
debug_assert!(content.is_some(), "SVG text child was not synced before layout");
@@ -2287,7 +2359,7 @@ impl<'pass> SvgFormattingContext<'pass> {
paint_parts.add_decoration_lines(after_child, lines_over);
contents.glyph_cells.unite(shaped.glyph_cells);
- contents.character_cells.extend(shaped.character_cells);
+ self.append_svg_run_dom_cells(child, shaped.character_cells, &mut contents.character_cells);
} else if matches!(kind, NodeKind::SVGTextBox | NodeKind::SVGTextPathBox) {
// <text> and <tspan> elements can contain more text elements, whose glyph cells count toward this
// box too.
@@ -2491,7 +2563,7 @@ impl<'pass> SvgFormattingContext<'pass> {
);
advance += shaped.advance;
runs.extend(shaped.runs);
- character_cells.extend(shaped.character_cells);
+ self.append_svg_run_dom_cells(node, shaped.character_cells, &mut character_cells);
});
// https://svgwg.org/svg2-draft/text.html#TextPathElementStartOffsetAttribute
diff --git a/Libraries/LibWeb/Rust/src/layout/text_chunker.rs b/Libraries/LibWeb/Rust/src/layout/text_chunker.rs
index 66e42f30cd0..20731a952c0 100644
--- a/Libraries/LibWeb/Rust/src/layout/text_chunker.rs
+++ b/Libraries/LibWeb/Rust/src/layout/text_chunker.rs
@@ -498,7 +498,7 @@ impl Drop for IcuSegmenterHandle {
}
pub(crate) enum GraphemeSegmenter {
- Ascii {
+ SingleCodeUnits {
length_in_code_units: usize,
},
/// Text of code points below U+0300 only, where every code unit is a grapheme cluster except for CR LF.
@@ -522,12 +522,13 @@ fn is_latin_code_unit_outside_clusters(code_unit: u16) -> bool {
impl GraphemeSegmenter {
pub(crate) fn new(text: &[u16]) -> Self {
- let Some(first_non_ascii) = text.iter().position(|unit| *unit > 0x7f) else {
- return Self::Ascii {
+ let Some(first_cluster_candidate) = text.iter().position(|&unit| !is_latin_code_unit_outside_clusters(unit))
+ else {
+ return Self::SingleCodeUnits {
length_in_code_units: text.len(),
};
};
- if text[first_non_ascii..].iter().all(|unit| *unit < 0x300) {
+ if text[first_cluster_candidate..].iter().all(|unit| *unit < 0x300) {
let line_feeds_after_carriage_returns = text
.windows(2)
.enumerate()
@@ -556,11 +557,9 @@ impl GraphemeSegmenter {
}
}
- /// Mirrors Unicode::AsciiGraphemeSegmenter for the ASCII case: every code
- /// unit index is a boundary.
pub(crate) fn next_boundary(&self, index: usize, inclusive: bool) -> Option<usize> {
match self {
- Self::Ascii { length_in_code_units } => {
+ Self::SingleCodeUnits { length_in_code_units } => {
if inclusive && index <= *length_in_code_units {
return Some(index);
}
@@ -1204,7 +1203,11 @@ impl<'text> TextChunker<'text> {
self.splits_at_orientation_changes && code_point_is_upright_in_mixed_orientation(self.current_code_point())
}
- fn next_grapheme_boundary(&self) -> usize {
+ fn next_chunk_boundary(&self) -> usize {
+ // CRLF is one grapheme, but the line feed must start its own chunk when CSS preserves line breaks.
+ if self.should_respect_linebreaks && self.text.get(self.current_index) == Some(&u16::from(b'\r')) {
+ return self.current_index + 1;
+ }
self.grapheme_segmenter
.next_boundary(self.current_index, false)
.unwrap_or(self.text.len())
@@ -1447,7 +1450,7 @@ impl<'text> TextChunker<'text> {
}
// Otherwise, commit the newline!
- self.current_index = self.next_grapheme_boundary();
+ self.current_index = self.next_chunk_boundary();
let chunk = self.try_commit_chunk(
pending.start,
self.current_index,
@@ -1471,7 +1474,7 @@ impl<'text> TextChunker<'text> {
let chunk = self.try_commit_chunk_at_cursor(&pending, false);
while self.current_index < self.text.len() && self.is_collapsible(self.current_code_point()) {
- self.current_index = self.next_grapheme_boundary();
+ self.current_index = self.next_chunk_boundary();
}
if let Some(chunk) = chunk {
@@ -1509,7 +1512,7 @@ impl<'text> TextChunker<'text> {
}
// Otherwise, commit the whitespace!
- self.current_index = self.next_grapheme_boundary();
+ self.current_index = self.next_chunk_boundary();
can_break_at_current_position = self.is_at_line_break_opportunity();
let space_font = self.font_for_space(self.current_index, code_point);
let space_font_index = self.index_of_font(space_font);
@@ -1536,7 +1539,7 @@ impl<'text> TextChunker<'text> {
}
}
- self.current_index = self.next_grapheme_boundary();
+ self.current_index = self.next_chunk_boundary();
can_break_at_current_position = self.is_at_line_break_opportunity();
}
diff --git a/Libraries/LibWeb/Rust/src/layout/text_transform.rs b/Libraries/LibWeb/Rust/src/layout/text_transform.rs
index 6559078a111..5f4394268d4 100644
--- a/Libraries/LibWeb/Rust/src/layout/text_transform.rs
+++ b/Libraries/LibWeb/Rust/src/layout/text_transform.rs
@@ -6,12 +6,13 @@
use super::rendered_text::{RenderedTextBoundary, RenderedTextEdit, rendered_text_offset_for_dom_offset};
use super::text_chunker::{code_point_at, code_unit_length_for_code_point};
-use crate::css::css_enums::{text_transform, white_space_collapse};
+use crate::css::css_enums::{text_security, text_transform, white_space_collapse};
use std::ffi::c_void;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(super) struct TextRenderingOptions {
pub text_transform: u8,
+ pub text_security: u8,
pub white_space_collapse: u8,
pub is_password_input: bool,
pub dom_start_offset: usize,
@@ -223,6 +224,40 @@ fn map_code_points(source: &[u16], mapping: impl Fn(u32) -> u32) -> TransformedT
result
}
+fn mask_graphemes(input: TransformedText, mark: u16, source_length: usize) -> TransformedText {
+ let segmenter = super::text_chunker::GraphemeSegmenter::new(&input.text);
+ let mut masked = TransformedText::default();
+ let mut edits = input.edits.iter().peekable();
+ let (mut source_end, mut transform_end) = (0, 0);
+ let (mut span_start, mut mask_start) = (0, 0);
+ let mut offset = 0;
+ while let Some(boundary) = segmenter.next_boundary(offset, false) {
+ masked.text.push(mark);
+ offset = boundary;
+ while let Some(edit) =
+ edits.next_if(|edit| edit.rendered_start_offset + edit.rendered_length_in_code_units <= boundary)
+ {
+ source_end = edit.dom_start_offset + edit.dom_length_in_code_units;
+ transform_end = edit.rendered_start_offset + edit.rendered_length_in_code_units;
+ }
+ // An expanded character can supply several marks. Keep them in one edit so all of them map to that character.
+ if edits.peek().is_some_and(|edit| edit.rendered_start_offset < boundary) {
+ continue;
+ }
+ let dom_boundary = source_end + (boundary - transform_end);
+ masked.append_edit(
+ span_start,
+ dom_boundary - span_start,
+ mask_start,
+ masked.text.len() - mask_start,
+ );
+ span_start = dom_boundary;
+ mask_start = masked.text.len();
+ }
+ masked.append_edit(span_start, source_length - span_start, mask_start, 0);
+ masked
+}
+
fn normalize_whitespace(text: &mut [u16], collapse: u8) {
let convert_newlines = matches!(
collapse,
@@ -283,6 +318,17 @@ pub(super) fn render_text(
_ => unreachable!("invalid text-transform value"),
}
};
+ if !options.is_password_input {
+ let mark = match options.text_security {
+ text_security::DISC => Some(0x2022),
+ text_security::CIRCLE => Some(0x25e6),
+ text_security::SQUARE => Some(0x25a0),
+ _ => None,
+ };
+ if let Some(mark) = mark {
+ result = mask_graphemes(result, mark, source_length);
+ }
+ }
// Transform the full source before slicing so contextual casing sees the
// same surrounding text for both ::first-letter and the remainder.
if options.dom_start_offset != 0 || options.dom_length_in_code_units != source_length {
diff --git a/Tests/LibWeb/Text/expected/SVG/masked-text-character-indices.txt b/Tests/LibWeb/Text/expected/SVG/masked-text-character-indices.txt
new file mode 100644
index 00000000000..9d94b27430f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/SVG/masked-text-character-indices.txt
@@ -0,0 +1,26 @@
+text chars: 3
+cluster shares its cell: true
+last mark has its own cell: true
+last mark index: 2
+text chars: 3
+cluster shares its cell: true
+last mark has its own cell: true
+last mark index: 2
+tspan chars: 3
+cluster shares its cell: true
+last mark has its own cell: true
+last mark index: 2
+tspan chars: 3
+cluster shares its cell: true
+last mark has its own cell: true
+last mark index: 2
+textPath chars: 3
+cluster shares its cell: true
+last mark has its own cell: true
+last mark index: 2
+textPath chars: 3
+cluster shares its cell: true
+last mark has its own cell: true
+last mark index: 2
+expansion preserves DOM length: true
+first character spans two marks: true
diff --git a/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-has-indexed-property-getter.txt b/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-has-indexed-property-getter.txt
index 631ea8e0b4c..d9a9781afbf 100644
--- a/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-has-indexed-property-getter.txt
+++ b/Tests/LibWeb/Text/expected/css/CSSStyleDeclaration-has-indexed-property-getter.txt
@@ -2,6 +2,7 @@ All properties associated with getComputedStyle(document.body):
[
"-webkit-font-smoothing",
"-webkit-text-fill-color",
+ "-webkit-text-security",
"-webkit-text-stroke-color",
"-webkit-text-stroke-width",
"accent-color",
diff --git a/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt b/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt
index eb27e03afc6..47fd5a53c8c 100644
--- a/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt
+++ b/Tests/LibWeb/Text/expected/css/CSSStyleProperties-all-supported-properties-and-default-values.txt
@@ -242,6 +242,9 @@ All supported properties and their default values exposed from CSSStylePropertie
'WebkitTextFillColor': 'rgb(0, 0, 0)'
'webkitTextFillColor': 'rgb(0, 0, 0)'
'-webkit-text-fill-color': 'rgb(0, 0, 0)'
+'WebkitTextSecurity': 'none'
+'webkitTextSecurity': 'none'
+'-webkit-text-security': 'none'
'WebkitTextStroke': '0px rgb(0, 0, 0)'
'webkitTextStroke': '0px rgb(0, 0, 0)'
'-webkit-text-stroke': '0px rgb(0, 0, 0)'
diff --git a/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt b/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt
index 4b74c760952..8baeef14f06 100644
--- a/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt
+++ b/Tests/LibWeb/Text/expected/css/getComputedStyle-print-all.txt
@@ -1,5 +1,6 @@
-webkit-font-smoothing: auto
-webkit-text-fill-color: rgb(0, 0, 0)
+-webkit-text-security: none
-webkit-text-stroke-color: rgb(0, 0, 0)
-webkit-text-stroke-width: 0px
accent-color: auto
diff --git a/Tests/LibWeb/Text/expected/css/pre-line-preserves-line-feed-after-collapsible-spaces.txt b/Tests/LibWeb/Text/expected/css/pre-line-preserves-line-feed-after-collapsible-spaces.txt
index 7c48f091a1b..eab531f2137 100644
--- a/Tests/LibWeb/Text/expected/css/pre-line-preserves-line-feed-after-collapsible-spaces.txt
+++ b/Tests/LibWeb/Text/expected/css/pre-line-preserves-line-feed-after-collapsible-spaces.txt
@@ -7,4 +7,5 @@ spaces-between-line-feeds: height 80, "two" at line 4, x 0
tab-between-line-feeds: height 60, "two" at line 3, x 0
spaces-after-line-feed: height 40, "two" at line 2, x 0
spaces-around-line-feed: height 40, "two" at line 2, x 0
+latin-crlf-pairs: height 60, "two" at line 3, x 0
crlf-pairs: height 60, "two" at line 3, x 0
diff --git a/Tests/LibWeb/Text/expected/text-security-graphemes.txt b/Tests/LibWeb/Text/expected/text-security-graphemes.txt
new file mode 100644
index 00000000000..b73d696471b
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/text-security-graphemes.txt
@@ -0,0 +1,21 @@
+disc inherited: disc
+disc glyphs match: true
+disc one mark: true
+disc one mark: true
+disc one mark: true
+circle inherited: circle
+circle glyphs match: true
+circle one mark: true
+circle one mark: true
+circle one mark: true
+square inherited: square
+square glyphs match: true
+square one mark: true
+square one mark: true
+square one mark: true
+CRLF matches 3 marks: true
+LFCR matches 4 marks: true
+two CRLFs matches 4 marks: true
+expanded text has two marks: true
+DOM text preserved: true
+none restores text: true
diff --git a/Tests/LibWeb/Text/input/SVG/masked-text-character-indices.html b/Tests/LibWeb/Text/input/SVG/masked-text-character-indices.html
new file mode 100644
index 00000000000..3ebc23637f5
--- /dev/null
+++ b/Tests/LibWeb/Text/input/SVG/masked-text-character-indices.html
@@ -0,0 +1,32 @@
+<!doctype html>
+<script src="../include.js"></script>
+<svg width="300" height="100">
+ <path id="line" d="M 0 50 H 290"></path>
+ <text id="label" y="30" style="font: 24px monospace; -webkit-text-security: disc"></text>
+</svg>
+<script>
+ test(() => {
+ const ns = "http://www.w3.org/2000/svg";
+ for (const kind of ["text", "tspan", "textPath"]) {
+ label.replaceChildren();
+ const run = kind === "text" ? label : label.appendChild(document.createElementNS(ns, kind));
+ if (kind === "textPath") run.setAttribute("href", "#line");
+ for (const group of ["e\u0301", String.fromCodePoint(0x1f600)]) {
+ run.replaceChildren(document.createTextNode(group), document.createTextNode("x"));
+ println(kind + " chars: " + run.getNumberOfChars());
+ const first = run.getExtentOfChar(0);
+ const second = run.getExtentOfChar(1);
+ println("cluster shares its cell: " + (first.x === second.x && first.width === second.width));
+ const last = run.getExtentOfChar(2);
+ println("last mark has its own cell: " + (last.x >= first.x + first.width - 0.01 && last.width > 0));
+ println("last mark index: " + run.getCharNumAtPosition(new DOMPoint(last.x + last.width / 2, last.y + last.height / 2)));
+ }
+ }
+ label.style.textTransform = "uppercase";
+ label.textContent = String.fromCodePoint(0xdf) + "x";
+ const expanded = label.getExtentOfChar(0);
+ const last = label.getExtentOfChar(1);
+ println("expansion preserves DOM length: " + (label.getNumberOfChars() === 2));
+ println("first character spans two marks: " + (Math.abs(expanded.width - 2 * last.width) < 0.1));
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/css/pre-line-preserves-line-feed-after-collapsible-spaces.html b/Tests/LibWeb/Text/input/css/pre-line-preserves-line-feed-after-collapsible-spaces.html
index 34230d28fe0..8d877a64d55 100644
--- a/Tests/LibWeb/Text/input/css/pre-line-preserves-line-feed-after-collapsible-spaces.html
+++ b/Tests/LibWeb/Text/input/css/pre-line-preserves-line-feed-after-collapsible-spaces.html
@@ -18,6 +18,7 @@
"tab-between-line-feeds": "one\t\n\t\ntwo",
"spaces-after-line-feed": "one\n two",
"spaces-around-line-feed": "one \n two",
+ "latin-crlf-pairs": "caf\u00e9\r\n\r\ntwo",
"crlf-pairs": "one\r\n\r\ntwo",
};
const host = document.getElementById("host");
diff --git a/Tests/LibWeb/Text/input/text-security-graphemes.html b/Tests/LibWeb/Text/input/text-security-graphemes.html
new file mode 100644
index 00000000000..64547ea559d
--- /dev/null
+++ b/Tests/LibWeb/Text/input/text-security-graphemes.html
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<script src="include.js"></script>
+<style>
+ #target, #reference { font: 24px serif; white-space: pre; display: inline-block; }
+</style>
+<div id="container"><span id="target"></span><span id="reference" style="-webkit-text-security: none"></span></div>
+<script>
+ test(() => {
+ for (const [mode, mark] of [["disc", "•"], ["circle", "◦"], ["square", "■"]]) {
+ container.style.webkitTextSecurity = mode;
+ target.textContent = "Wi";
+ reference.textContent = mark.repeat(2);
+ println(`${mode} inherited: ${getComputedStyle(target).webkitTextSecurity}`);
+ println(`${mode} glyphs match: ${target.offsetWidth === reference.offsetWidth}`);
+ reference.textContent = mark;
+ for (const cluster of ["e\u0301", "😀", "👩‍💻"]) {
+ target.textContent = cluster;
+ println(`${mode} one mark: ${target.offsetWidth === reference.offsetWidth}`);
+ }
+ }
+ container.style.webkitTextSecurity = "disc";
+ for (const [name, text, count] of [
+ ["CRLF", "A\r\nB", 3], ["LFCR", "A\n\rB", 4], ["two CRLFs", "A\r\n\r\nB", 4],
+ ]) {
+ target.textContent = text;
+ reference.textContent = String.fromCodePoint(0x2022).repeat(count);
+ println(`${name} matches ${count} marks: ${target.offsetWidth === reference.offsetWidth}`);
+ }
+ container.style.webkitTextSecurity = "square";
+ target.style.textTransform = "uppercase";
+ target.textContent = String.fromCodePoint(0xdf);
+ reference.textContent = String.fromCodePoint(0x25a0).repeat(2);
+ println(`expanded text has two marks: ${target.offsetWidth === reference.offsetWidth}`);
+ println(`DOM text preserved: ${target.textContent.codePointAt(0) === 0xdf}`);
+ target.style.textTransform = "none";
+ target.style.webkitTextSecurity = "none";
+ target.textContent = reference.textContent = "Wide text";
+ println(`none restores text: ${target.offsetWidth === reference.offsetWidth}`);
+ });
+</script>