Skip to content

Truly independent web browser

LibWeb: Place tabs from where their line starts, after a soft wrap too

sideshowbarker412315702d13
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
index 3ff1c8bcf17..cbc15b97196 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_formatting_context.rs
@@ -1928,6 +1928,25 @@ impl<'context> InlineFormattingContext<'context> {
self.parent.intrusion_by_floats_into_rect(rect, block_start, block_end)
}
+ /// How far floats reach into the start side of a line between these block offsets. A line laid out in an
+ /// indefinite inline size, as for an intrinsic size, has no floats beside it to measure.
+ pub(crate) fn start_side_float_intrusion(
+ &self,
+ block_start: CssPixels,
+ block_end: CssPixels,
+ line_direction: u8,
+ ) -> CssPixels {
+ if !matches!(self.input.available_space.inline_size, AvailableSize::Definite(_)) {
+ return CssPixels::default();
+ }
+ let intrusion = self.intrusion_by_floats_into_containing_block(block_start, block_end);
+ if line_direction == direction::RTL {
+ intrusion.right
+ } else {
+ intrusion.left
+ }
+ }
+
pub(crate) fn leftmost_inline_offset_at(&self, block_offset: CssPixels, line_block_size: CssPixels) -> CssPixels {
self.intrusion_by_floats_into_containing_block(block_offset, block_offset + line_block_size)
.left
@@ -2833,6 +2852,14 @@ impl<'context> InlineFormattingContext<'context> {
// NB: The start edges that collapsed whitespace left for the next item come before that item too.
let pending_leading_edges =
item_state.leading_margin + item_state.leading_border + item_state.leading_padding;
+ // NB: An empty inline box after a tab is placed after where the tab ends on this line, so the tabs move
+ // there before the boxes are.
+ let start_edges_before_transfer =
+ pending_leading_edges + item.margin_start + item.border_start + item.padding_start;
+ line_builder.note_next_content(iterator.prepared_content(), &item);
+ item.place_tabs_at_line_position(iterator.prepared_content(), || {
+ line_builder.inline_position_of_next_content() + start_edges_before_transfer
+ });
if iterator.has_empty_inline_boxes() {
for empty_box in iterator.empty_inline_boxes_before_last_item() {
line_builder
@@ -3084,6 +3111,16 @@ impl<'context> InlineFormattingContext<'context> {
}
inline_level_iterator::ItemType::Text => {
line_builder.prepare_to_append_inline_content();
+ // https://drafts.csswg.org/css-text-3/#white-space-phase-2
+ // "each preserved tab is rendered as a horizontal shift that lines up the start edge of the next
+ // glyph with the next tab stop."
+ // NB: Where the item starts on its line decides where its tabs end: on the line it would join, for
+ // the measurements that decide where the line breaks, and then on the line it does join.
+ // NB: The item's start edges took the leading edges that collapsed whitespace left for it.
+ let start_edges = item.margin_start + item.border_start + item.padding_start;
+ item.place_tabs_at_line_position(iterator.prepared_content(), || {
+ line_builder.inline_position_of_next_content() + start_edges
+ });
let style = self.style(self.parent_node(item.node));
if style.text_wrap_mode() == text_wrap_mode::WRAP {
let is_whitespace = item.is_collapsible_whitespace || item.is_ascii_whitespace(self);
@@ -3120,7 +3157,12 @@ impl<'context> InlineFormattingContext<'context> {
let broke_line = if iterator.next_non_whitespace_text_allows_overflow_break(self) {
line_builder.break_if_needed_before_overflow_breakable_item(sequence_inline_size)
} else {
- line_builder.break_if_needed(sequence_inline_size)
+ // NB: The white space stays at the end of this line, so a line past floats has to
+ // fit only what follows it.
+ let after_whitespace =
+ sequence_inline_size - inline_level_iterator::inline_extent([&item]);
+ line_builder
+ .break_if_needed_sized_by(sequence_inline_size, &mut |_| after_whitespace)
};
line_builder.set_hanging_whitespace_inline_size(CssPixels::default());
line_builder.set_end_edges_of_whitespace_at_break(CssPixels::default());
@@ -3155,7 +3197,15 @@ impl<'context> InlineFormattingContext<'context> {
line_builder
.break_if_needed_before_overflow_breakable_item(unbreakable_run_inline_size);
} else {
- line_builder.break_if_needed(unbreakable_run_inline_size);
+ // NB: Lines past floats start elsewhere, which moves tabs that start the item.
+ let prepared = iterator.prepared_content();
+ line_builder.break_if_needed_sized_by(
+ unbreakable_run_inline_size,
+ &mut |position| {
+ unbreakable_run_inline_size - item.inline_size
+ + item.inline_size_with_tabs_at(prepared, position + start_edges)
+ },
+ );
}
line_builder.note_soft_wrap_opportunity();
}
@@ -3191,6 +3241,9 @@ impl<'context> InlineFormattingContext<'context> {
if self.stops_at_line_clamp_point(line_builder, &mut state_at_clamp_point) {
break;
}
+ item.place_tabs_at_line_position(iterator.prepared_content(), || {
+ line_builder.inline_position_of_next_content() + start_edges
+ });
line_builder.append_text_item(&mut item, iterator.prepared_content(), style);
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
index a9bd7bef11c..3d558b04615 100644
--- a/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
+++ b/Libraries/LibWeb/Rust/src/layout/inline_level_iterator.rs
@@ -114,6 +114,41 @@ fn glyphs_after_tab_spacers(
with_spacer
}
+/// The advance of each tab of `tab_stop`, for tabs that start `position` from the start of their line.
+fn advances_of_tabs(tab_stop: &PreparedTabStop, position: CssPixels) -> Vec<f32> {
+ let tab_inline_size = tab_stop.tab_inline_size;
+ // https://drafts.csswg.org/css-text-3/#white-space-phase-2
+ // "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();
+ }
+ // 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 mut advances = Vec::with_capacity(tab_stop.tab_count as usize);
+ let mut end = position;
+ let mut previous_end = 0.0f32;
+ for _ in 0..tab_stop.tab_count {
+ end += distance_to_tab_stop(end);
+ let end_from_start = (end - position).to_double() as f32;
+ advances.push(end_from_start - previous_end);
+ previous_end = end_from_start;
+ }
+ advances
+}
+
fn reshaped_glyph_run(
text: &[u16],
range: std::ops::Range<usize>,
@@ -251,6 +286,80 @@ fn shape_set_upright(
impl Item {
const NOT_RESOLVED_FROM_A_PREPARED_ITEM: usize = u32::MAX as usize;
+ /// Moves the tabs that start this text item to the tab stops after `line_position`, where the item starts on its
+ /// line: Resolving the item placed them as if its paragraph never wrapped. Only an item with tabs asks for that
+ /// position.
+ pub(crate) fn place_tabs_at_line_position(
+ &mut self,
+ prepared: &PreparedInlineContent,
+ line_position: impl FnOnce() -> CssPixels,
+ ) {
+ let Some((prepared_item, tab_stop)) = self.leading_tabs(prepared) else {
+ return;
+ };
+ let shape = prepared_item.shape();
+ let tab_advances = advances_of_tabs(tab_stop, line_position());
+ let inline_offset: f32 = tab_advances.iter().sum();
+ let inline_size = CssPixels::nearest_value_for_f32(shape.width() + inline_offset);
+ if inline_size == self.inline_size {
+ return;
+ }
+ let glyphs = glyphs_after_tab_spacers(&shaped_glyphs_from(shape, inline_offset), &tab_advances);
+ self.owned_glyph_run = Some(Box::new(OwnedGlyphRun {
+ glyphs,
+ width: shape.width(),
+ is_upright: false,
+ }));
+ self.inline_size = inline_size;
+ if prepared_item.has(PreparedItem::TRAILING_WHITESPACE_IS_WHOLE_ITEM) {
+ self.trailing_whitespace.inline_size = inline_size;
+ self.trailing_whitespace.ascii_inline_size = inline_size;
+ }
+ }
+
+ /// The prepared item and tab stop of the tabs that start this text item, if it starts with any that move with
+ /// where it starts on its line. Upright text keeps its tabs as they are, and only an item that still starts where
+ /// its prepared item does holds the tabs at all.
+ fn leading_tabs<'prepared>(
+ &self,
+ prepared: &'prepared PreparedInlineContent,
+ ) -> Option<(&'prepared PreparedItem, &'prepared PreparedTabStop)> {
+ if self.type_ != ItemType::Text {
+ return None;
+ }
+ let prepared_item = &prepared.items[self.prepared_item_index as usize];
+ if !prepared_item.has(PreparedItem::TAB_STOP)
+ || prepared_item.has(PreparedItem::UPRIGHT)
+ || self.offset_in_node != prepared_item.offset_in_node()
+ || self.length_in_node != prepared_item.length_in_node()
+ {
+ return None;
+ }
+ Some((prepared_item, prepared.tab_stop_of_item(self.prepared_item_index)?))
+ }
+
+ pub(crate) fn prepared_item_index(&self) -> u32 {
+ self.prepared_item_index
+ }
+
+ pub(crate) fn starts_with_tabs(&self, prepared: &PreparedInlineContent) -> bool {
+ self.leading_tabs(prepared).is_some()
+ }
+
+ /// This item's inline size with the tabs that start it placed after `line_position`, where it would start on its
+ /// line.
+ pub(crate) fn inline_size_with_tabs_at(
+ &self,
+ prepared: &PreparedInlineContent,
+ line_position: CssPixels,
+ ) -> CssPixels {
+ let Some((prepared_item, tab_stop)) = self.leading_tabs(prepared) else {
+ return self.inline_size;
+ };
+ let inline_offset: f32 = advances_of_tabs(tab_stop, line_position).iter().sum();
+ CssPixels::nearest_value_for_f32(prepared_item.shape().width() + inline_offset)
+ }
+
fn new(type_: ItemType, node: Node, prepared_item_index: usize) -> Self {
Self {
type_,
@@ -1871,6 +1980,9 @@ impl<'pass> InlineContentPreparer<'pass> {
if let Some(tab_stop) = tab_stop {
flags |= PreparedItem::TAB_STOP;
self.buffers.tab_stops.push(tab_stop);
+ self.buffers
+ .tab_stop_items
+ .push(u32::try_from(self.buffers.items.len()).expect("prepared item indices fit in 32 bits"));
}
let font_index = self.buffers.index_of_font(font);
let item = PreparedItem::text(
@@ -2379,37 +2491,10 @@ impl<'context> RunItemResolver<'_, 'context> {
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
- // "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();
- }
- // 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;
+ // NB: The tabs are placed as if the paragraph didn't wrap, and the line builder moves them once it knows
+ // where the item starts on its line.
+ tab_advances = advances_of_tabs(&tab_stop, self.accumulated_inline_size_for_tabs);
+ inline_offset = tab_advances.iter().sum();
upright_advance_after_tabs = tab_stop.upright_advance;
}
let shape = prepared_item.shape();
diff --git a/Libraries/LibWeb/Rust/src/layout/line_builder.rs b/Libraries/LibWeb/Rust/src/layout/line_builder.rs
index a42fe01c2c2..d1a559ab883 100644
--- a/Libraries/LibWeb/Rust/src/layout/line_builder.rs
+++ b/Libraries/LibWeb/Rust/src/layout/line_builder.rs
@@ -100,6 +100,12 @@ pub(crate) struct LineBuilder<'builder, 'context> {
lines_known_to_hold_no_content: Option<usize>,
text_indentation: inline_formatting_context::TextIndentation,
direction: u8,
+ /// The direction that unicode-bidi: plaintext gives a line from the first strong text of the next content, while
+ /// the line holds none yet.
+ plaintext_direction_of_next_content: Option<u8>,
+ /// The last search for the first strong text ahead: the items it covers, from where it started to where it
+ /// stopped, and the text type it found.
+ first_strong_text_ahead: Option<(std::ops::RangeInclusive<u32>, Option<u8>)>,
last_line_needs_update: bool,
is_continuation: bool,
should_advance_to_last_line_box_block_end: bool,
@@ -198,6 +204,8 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {
lines_known_to_hold_no_content: Some(0),
text_indentation: inline_formatting_context::TextIndentation::of(style, containing_inline_size),
direction: style.direction(),
+ plaintext_direction_of_next_content: None,
+ first_strong_text_ahead: None,
last_line_needs_update: false,
is_continuation: false,
should_advance_to_last_line_box_block_end: false,
@@ -369,6 +377,19 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {
forced: ForcedBreak,
forced_break: Option<inline_content::ForcedBreakPosition>,
next_size: Option<CssPixels>,
+ ) {
+ self.break_line_sized_by(forced, forced_break, next_size, None);
+ }
+
+ /// Breaks the line, as break_line() does. `size_at`, where given, is the inline size of the next content where a
+ /// line starts at the given position, for content whose size depends on that (tabs, e.g.): Each line the break
+ /// moves past floats to is checked with the size the content would have there.
+ fn break_line_sized_by(
+ &mut self,
+ forced: ForcedBreak,
+ forced_break: Option<inline_content::ForcedBreakPosition>,
+ next_size: Option<CssPixels>,
+ mut size_at: Option<&mut dyn FnMut(CssPixels) -> CssPixels>,
) {
// FIXME: Respect inline direction.
@@ -412,7 +433,14 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {
);
let available = self.available_inline_size_for_current_line;
let indent = self.line(self.line_count() - 1).indent;
- let next_too_wide = available.pixels_greater_than(next_size.unwrap_or_default() + indent);
+ let next_size_on_line = match size_at.as_mut() {
+ Some(size_at) => {
+ let position = self.inline_position_of_next_content();
+ size_at(position)
+ }
+ None => next_size.unwrap_or_default(),
+ };
+ let next_too_wide = available.pixels_greater_than(next_size_on_line + indent);
if !floats_intrude
|| (self
.context()
@@ -424,6 +452,66 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {
}
}
+ /// Where the next content on the current line starts, from the start edge of the block container's content box:
+ /// past the floats on the start side of the line's direction, any indent, and the content already on the line.
+ /// Notes `item` as the next content, for the direction that the first strong text from it on gives a line under
+ /// unicode-bidi: plaintext, which tabs that start the item are placed for.
+ pub(crate) fn note_next_content(
+ &mut self,
+ prepared: &prepared_inline_content::PreparedInlineContent,
+ item: &inline_level_iterator::Item,
+ ) {
+ self.plaintext_direction_of_next_content = None;
+ if self.containing_style().unicode_bidi() != unicode_bidi::PLAINTEXT || !item.starts_with_tabs(prepared) {
+ return;
+ }
+ let index = item.prepared_item_index();
+ let text_type = match &self.first_strong_text_ahead {
+ Some((covered, text_type)) if covered.contains(&index) => *text_type,
+ _ => {
+ let (stop, text_type) = prepared.first_strong_text_from(index);
+ self.first_strong_text_ahead = Some((index..=stop, text_type));
+ text_type
+ }
+ };
+ self.plaintext_direction_of_next_content = text_type.map(|text_type| {
+ if text_type == GLYPH_TEXT_TYPE_RTL {
+ direction::RTL
+ } else {
+ direction::LTR
+ }
+ });
+ }
+
+ fn line_holds_strong_text(&self, line_index: usize) -> bool {
+ self.line(line_index).fragments.iter().any(|fragment| {
+ fragment
+ .glyphs
+ .as_ref()
+ .is_some_and(|glyphs| matches!(glyphs.text_type, GLYPH_TEXT_TYPE_LTR | GLYPH_TEXT_TYPE_RTL))
+ })
+ }
+
+ pub(crate) fn inline_position_of_next_content(&mut self) -> CssPixels {
+ let line_index = self.ensure_last_line_index();
+ let line_block_size = self
+ .max_block_size_on_current_line
+ .max(self.containing_style().line_height())
+ .max(self.float_fit_height());
+ // NB: Under unicode-bidi: plaintext, a line takes its direction from its first strong text, which content
+ // before that text is placed for too.
+ let line_direction = match self.plaintext_direction_of_next_content {
+ Some(direction) if !self.line_holds_strong_text(line_index) => direction,
+ _ => self.line(line_index).direction,
+ };
+ let start_side_intrusion = self.context().start_side_float_intrusion(
+ self.current_block_offset,
+ self.current_block_offset + line_block_size,
+ line_direction,
+ );
+ start_side_intrusion + self.line(line_index).inline_length
+ }
+
pub(crate) fn current_line_is_empty(&mut self) -> bool {
self.line_count() == 0 || self.line(self.line_count() - 1).is_empty()
}
@@ -482,6 +570,20 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {
true
}
+ /// Breaks the line, as break_if_needed() does, before content whose inline size depends on where its line starts:
+ /// `size_at` gives that size for a line starting at a position.
+ pub(crate) fn break_if_needed_sized_by(
+ &mut self,
+ next_item_inline_size: CssPixels,
+ size_at: &mut dyn FnMut(CssPixels) -> CssPixels,
+ ) -> bool {
+ if !self.should_break(next_item_inline_size) {
+ return false;
+ }
+ self.break_line_sized_by(ForcedBreak::No, None, Some(next_item_inline_size), Some(size_at));
+ true
+ }
+
pub(crate) fn break_if_needed_before_overflow_breakable_item(&mut self, next_item_inline_size: CssPixels) -> bool {
if self.current_line_is_empty() {
return false;
@@ -728,15 +830,9 @@ impl<'builder, 'context> LineBuilder<'builder, 'context> {
) {
self.prepare_to_append_inline_content();
let line_index = self.ensure_last_line_index();
- let has_strong_direction = |text_type| matches!(text_type, GLYPH_TEXT_TYPE_LTR | GLYPH_TEXT_TYPE_RTL);
if self.containing_style().unicode_bidi() == unicode_bidi::PLAINTEXT
- && !self.line(line_index).fragments.iter().any(|fragment| {
- fragment
- .glyphs
- .as_ref()
- .is_some_and(|glyphs| has_strong_direction(glyphs.text_type))
- })
- && has_strong_direction(glyphs.text_type)
+ && !self.line_holds_strong_text(line_index)
+ && matches!(glyphs.text_type, GLYPH_TEXT_TYPE_LTR | GLYPH_TEXT_TYPE_RTL)
{
self.line_mut(line_index).direction = if glyphs.text_type == GLYPH_TEXT_TYPE_RTL {
direction::RTL
diff --git a/Libraries/LibWeb/Rust/src/layout/prepared_inline_content.rs b/Libraries/LibWeb/Rust/src/layout/prepared_inline_content.rs
index 151c953bc9d..55e38f45fa2 100644
--- a/Libraries/LibWeb/Rust/src/layout/prepared_inline_content.rs
+++ b/Libraries/LibWeb/Rust/src/layout/prepared_inline_content.rs
@@ -17,6 +17,8 @@ pub(crate) struct PreparedInlineContent {
pub(super) box_events: Box<[InlineBoxEvent]>,
pub(super) fonts: Box<[FontHandle]>,
pub(super) tab_stops: Box<[PreparedTabStop]>,
+ /// The prepared item index of each tab stop, in the same order.
+ pub(super) tab_stop_items: Box<[u32]>,
/// Prepared item indices paired with UTF-16 offsets in their text nodes, ordered by item and then offset.
pub(super) soft_wraps: Box<[(u32, u32)]>,
}
@@ -198,6 +200,7 @@ pub(crate) struct InlineContentPreparationBuffers {
pub(super) box_events: Vec<InlineBoxEvent>,
pub(super) fonts: Vec<FontHandle>,
pub(super) tab_stops: Vec<PreparedTabStop>,
+ pub(super) tab_stop_items: Vec<u32>,
pub(super) soft_wraps: Vec<(u32, u32)>,
pub(super) box_stack: Vec<Node>,
}
@@ -223,12 +226,42 @@ impl InlineContentPreparationBuffers {
box_events: self.box_events.drain(..).collect(),
fonts: self.fonts.drain(..).collect(),
tab_stops: self.tab_stops.drain(..).collect(),
+ tab_stop_items: self.tab_stop_items.drain(..).collect(),
soft_wraps: self.soft_wraps.drain(..).collect(),
}
}
}
impl PreparedInlineContent {
+ /// The tab stop of `item`, a text item that starts with tabs.
+ pub(super) fn tab_stop_of_item(&self, item: u32) -> Option<&PreparedTabStop> {
+ let index = self.tab_stop_items.binary_search(&item).ok()?;
+ self.tab_stops.get(index)
+ }
+
+ /// The first text with a strong direction from `item` on, up to the next forced break or block-level box: The
+ /// index the search stopped at (that text's item, the boundary, or the end of the items), and that text's type if
+ /// it found one. Every item from `item` to that index has the same answer.
+ pub(super) fn first_strong_text_from(&self, item: u32) -> (u32, Option<u8>) {
+ for (index, prepared_item) in self.items.iter().enumerate().skip(item as usize) {
+ let index = u32::try_from(index).expect("prepared item indices fit in 32 bits");
+ match prepared_item.type_() {
+ ItemType::ForcedBreak | ItemType::BlockLevelBox => return (index, None),
+ ItemType::Text
+ if matches!(
+ prepared_item.text_type(),
+ line_box_fragment::GLYPH_TEXT_TYPE_LTR | line_box_fragment::GLYPH_TEXT_TYPE_RTL
+ ) =>
+ {
+ return (index, Some(prepared_item.text_type()));
+ }
+ _ => {}
+ }
+ }
+ let end = u32::try_from(self.items.len()).expect("prepared item indices fit in 32 bits");
+ (end, None)
+ }
+
/// The font the text of `item`, one of this content's text items, is set in.
pub(super) fn font_of(&self, item: &PreparedItem) -> &FontHandle {
&self.fonts[usize::from(item.font_index)]
@@ -280,6 +313,7 @@ impl PreparedInlineContent {
.or_else(|| first_difference("inline box event", &self.box_events, &fresh.box_events))
.or_else(|| first_difference("font", &self.fonts, &fresh.fonts))
.or_else(|| first_difference("tab stop", &self.tab_stops, &fresh.tab_stops))
+ .or_else(|| first_difference("tab stop item", &self.tab_stop_items, &fresh.tab_stop_items))
.or_else(|| first_difference("soft wrap", &self.soft_wraps, &fresh.soft_wraps))
}
}
diff --git a/Libraries/LibWeb/Rust/src/layout/rendered_text.rs b/Libraries/LibWeb/Rust/src/layout/rendered_text.rs
index d60fa834488..f84338800d5 100644
--- a/Libraries/LibWeb/Rust/src/layout/rendered_text.rs
+++ b/Libraries/LibWeb/Rust/src/layout/rendered_text.rs
@@ -769,6 +769,7 @@ mod tests {
box_events: Box::default(),
fonts: Box::default(),
tab_stops: Box::default(),
+ tab_stop_items: Box::default(),
soft_wraps: Box::default(),
});
scratch.prepared_inline_content_memos().keep(block, prepared.clone());
diff --git a/Tests/LibWeb/Crash/Layout/tab-after-empty-padded-span-in-plaintext-block.html b/Tests/LibWeb/Crash/Layout/tab-after-empty-padded-span-in-plaintext-block.html
new file mode 100644
index 00000000000..6be15ef6f1e
--- /dev/null
+++ b/Tests/LibWeb/Crash/Layout/tab-after-empty-padded-span-in-plaintext-block.html
@@ -0,0 +1,3 @@
+<!DOCTYPE html>
+<div style="white-space: pre-wrap; unicode-bidi: plaintext; width: 200px">a <span style="padding-left: 10px"></span> b</div>
+<div style="white-space: pre-wrap; unicode-bidi: plaintext; width: 200px"><span style="padding-left: 10px"></span></div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-inheritance-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-inheritance-001-ref.html
new file mode 100644
index 00000000000..5e253df9490
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/tab-size/tab-size-inheritance-001-ref.html
@@ -0,0 +1,15 @@
+<!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 {
+ margin-left: 50px;
+ width: 20px;
+ height: 20px;
+ background: green;
+}
+</style>
+
+<p>Test passes if there is a green square and no red.
+<div></div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/break-spaces-tab-005-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/break-spaces-tab-005-ref.html
new file mode 100644
index 00000000000..086f2031bc7
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/break-spaces-tab-005-ref.html
@@ -0,0 +1,16 @@
+<!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;
+ white-space: break-spaces;
+ color: green;
+ white-space: pre;
+}
+</style>
+
+<p>Test passes if there is a green rectangle and no red.
+<div>XX<br>XX<br>XX<br>XX<br>XX<br>XX<br>XX</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/pre-tab-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/pre-tab-001-ref.html
new file mode 100644
index 00000000000..94dc1d784a4
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/reference/pre-tab-001-ref.html
@@ -0,0 +1,16 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test reference</title>
+<link rel="stylesheet" type="text/css" href="../../../../fonts/ahem.css" />
+<style>
+div {
+ font: 25px/1 Ahem;
+ width: 85px;
+ tab-size: 4;
+}
+span {
+ white-space: pre;
+ background-color: green;
+}
+</style>
+<div>X<br><span>&#x09;</span><br>X</div>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/tab-position-with-text-align-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/tab-position-with-text-align-ref.html
new file mode 100644
index 00000000000..4f88bebfa80
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/tab-position-with-text-align-ref.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Tab positions with text-align and text-indent - reference</title>
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css">
+<style>
+div {
+ font: 20px/1 Ahem;
+ white-space: pre;
+ width: 800px;
+}
+.tab { display: inline-block; }
+</style>
+</head>
+<body>
+<div style="text-align: center;">X<span class="tab" style="width: 140px;"></span>X</div>
+<div style="text-indent: 20px;">X<span class="tab" style="width: 120px;"></span>X</div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/tab-stop-with-float-001-ref.html b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/tab-stop-with-float-001-ref.html
new file mode 100644
index 00000000000..37834cc3868
--- /dev/null
+++ b/Tests/LibWeb/Ref/expected/wpt-import/css/css-text/white-space/tab-stop-with-float-001-ref.html
@@ -0,0 +1,33 @@
+<!DOCTYPE html>
+<title>Reference: tab stops with float</title>
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css">
+<script>
+const params = new URLSearchParams(window.location.search);
+let classes = ['ltr'];
+if (params.has('class')) {
+ classes = params.getAll('class').flatMap(value => value.split(','));
+}
+document.documentElement.classList.add(...classes);
+</script>
+<style>
+body {
+ margin: 0;
+}
+div {
+ font: 20px/1 Ahem;
+ white-space: pre;
+ tab-size: 4;
+ width: 400px;
+}
+.rtl div {
+ direction: rtl;
+}
+.spacer {
+ display: inline-block;
+ width: 40px;
+}
+</style>
+<p>Tab stops should align vertically in both lines.</p>
+
+<div><span class="spacer"></span>a&#9;b</div>
+<div>a&#9;b</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-inheritance-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-inheritance-001.html
new file mode 100644
index 00000000000..3b1269b984d
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-inheritance-001.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: tab-size in lengths inherit as absolute lengths</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-inheritance-001-ref.html">
+<meta name="assert" content="tab-size in lengths inherit as absolute lengths">
+<style>
+.test {
+ font-family: monospace;
+ font-size: 10px;
+ tab-size: 5em;
+}
+.test div {
+ white-space: pre;
+ font-size: 20px
+}
+.test span {
+ display: inline-block;
+ width: 20px;
+ height: 20px;
+ background: green;
+}
+.ref {
+ z-index: -1;
+ margin-left: 50px;
+ position: absolute;
+ width: 20px;
+ height: 20px;
+ background: red;
+
+ /* this is to avoid antialiasing effects at the edge */
+ box-sizing: border-box;
+ border: 2px solid white;
+}
+</style>
+
+<p>Test passes if there is a green square and no red.
+<div class=ref></div>
+<div class=test><div>&#x09;<span></span></div></div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-percent-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-percent-001.html
new file mode 100644
index 00000000000..f2d2b5735c7
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/tab-size/tab-size-percent-001.html
@@ -0,0 +1,40 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>CSS Text Test: tab-size: 100%</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 percentage 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: 0;
+ tab-size: 100%;
+ }
+ </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-005.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-005.html
new file mode 100644
index 00000000000..02b9986aa64
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-005.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: break-space tabs don't 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/break-spaces-tab-005-ref.html">
+<meta name="assert" content="a sequence of break-spaces tabs at the end of a line does not hang.">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 20px/1 Ahem;
+}
+#test {
+ white-space: break-spaces;
+ color: green;
+ width: 2ch;
+}
+#ref {
+ white-space: pre;
+ width: 2ch;
+ background: red;
+ color: green;
+ position: absolute;
+ z-index:-1;
+}
+</style>
+
+<p>Test passes if there is a green rectangle and no red.
+<div id=ref> X<br> X<br>XX<br>XX<br>XX<br>XX<br> </div>
+<div id=test>X<wbr>X&#x09;&#x09;&#x09;&#x09;&#x09;XX</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-006.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-006.html
new file mode 100644
index 00000000000..568a881875a
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/break-spaces-tab-006.html
@@ -0,0 +1,30 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: break-spaces tabs and spaces don't 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/break-spaces-tab-005-ref.html">
+<meta name="assert" content="a sequence of break-spaces tabs and spaces at the end of a line does not hang, and can wrap after each tab or space.">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 20px/1 Ahem;
+}
+#test {
+ white-space: break-spaces;
+ color: green;
+ width: 2ch;
+}
+#ref {
+ white-space: pre;
+ width: 2ch;
+ background: red;
+ color: green;
+ position: absolute;
+ z-index:-1;
+}
+</style>
+
+<p>Test passes if there is a green rectangle and no red.
+<div id=ref> X<br> X<br>XX<br>XX<br>XX<br>XX<br> </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/pre-tab-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-tab-001.html
new file mode 100644
index 00000000000..b32f510937f
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/pre-tab-001.html
@@ -0,0 +1,19 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>CSS Text level 3 Test: overflowing white-space: pre tab after a soft wrap opportunity</title>
+<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-tab-001-ref.html">
+<meta name="assert" content="A preserved tab with white-space: pre does not hang, so when it overflows the line it wraps at the soft wrap opportunity before it.">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+div {
+ font: 25px/1 Ahem;
+ width: 85px;
+ tab-size: 4;
+}
+span {
+ white-space: pre;
+ background-color: green;
+}
+</style>
+<div>X <span>&#x09;</span> X</div>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-position-with-text-align.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-position-with-text-align.html
new file mode 100644
index 00000000000..6789d9a27ba
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-position-with-text-align.html
@@ -0,0 +1,20 @@
+<!DOCTYPE html>
+<html>
+<head>
+<title>Tab positions with text-align and text-indent</title>
+<link rel="help" href="https://drafts.csswg.org/css-text/#white-space-phase-2">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/tab-position-with-text-align-ref.html">
+<style>
+div {
+ font: 20px/1 Ahem;
+ white-space: pre;
+ width: 800px;
+}
+</style>
+</head>
+<body>
+<div style="text-align: center;">X X</div>
+<div style="text-indent: 20px;">X X</div>
+</body>
+</html>
diff --git a/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-with-float-001.html b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-with-float-001.html
new file mode 100644
index 00000000000..5bce54967db
--- /dev/null
+++ b/Tests/LibWeb/Ref/input/wpt-import/css/css-text/white-space/tab-stop-with-float-001.html
@@ -0,0 +1,38 @@
+<!DOCTYPE html>
+<title>Tab stops should be anchored to the block's content edge regardless of floats</title>
+<link rel="help" href="https://drafts.csswg.org/css-text-4/#white-space-processing">
+<link rel="match" href="../../../../../expected/wpt-import/css/css-text/white-space/tab-stop-with-float-001-ref.html">
+<meta name="variant" content="?class=ltr">
+<meta name="variant" content="?class=rtl">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css">
+<script>
+const params = new URLSearchParams(window.location.search);
+let classes = ['ltr'];
+if (params.has('class')) {
+ classes = params.getAll('class').flatMap(value => value.split(','));
+}
+document.documentElement.classList.add(...classes);
+</script>
+<style>
+body {
+ margin: 0;
+}
+div {
+ font: 20px/1 Ahem;
+ white-space: pre;
+ tab-size: 4;
+ width: 400px;
+}
+.rtl div {
+ direction: rtl;
+}
+.float {
+ float: inline-start;
+ width: 40px;
+ height: 20px;
+}
+</style>
+<p>Tab stops should align vertically in both lines.</p>
+
+<div><span class="float"></span>a&#9;b</div>
+<div>a&#9;b</div>
diff --git a/Tests/LibWeb/Text/expected/css/tab-stops-on-wrapped-lines.txt b/Tests/LibWeb/Text/expected/css/tab-stops-on-wrapped-lines.txt
new file mode 100644
index 00000000000..cc88e46cd82
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/tab-stops-on-wrapped-lines.txt
@@ -0,0 +1,15 @@
+after-a-wrap-at-a-space: "b" at (80, 10)
+after-a-wrap-at-a-wbr: "b" at (80, 10)
+after-two-wraps: "b" at (80, 20)
+after-a-forced-break: "b" at (80, 10)
+in-a-padded-span: "b" at (80, 10)
+with-a-length-tab-size: "b" at (50, 10)
+after-a-text-indent: "b" at (80, 0)
+beside-a-float: "b" at (80, 0)
+beside-a-float-on-a-wrapped-line: "b" at (80, 10)
+in-a-max-content-box-with-a-float: "b" at (80, 0)
+after-hanging-white-space-beside-a-float: "b" at (61, 12)
+before-an-empty-span: "b" at (80, 10)
+before-an-empty-span: the empty span at (80, 10)
+before-rtl-text-under-plaintext: the tab is 80px wide
+vertical: "b" at (0, 80)
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-text/tab-size/tab-size-computed-value-001.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-text/tab-size/tab-size-computed-value-001.txt
new file mode 100644
index 00000000000..8cd22ccf71f
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-text/tab-size/tab-size-computed-value-001.txt
@@ -0,0 +1,16 @@
+Harness status: OK
+
+Found 11 tests
+
+11 Pass
+Pass testing tab-size: 4
+Pass testing tab-size: 0.5in
+Pass testing tab-size: 2.54cm
+Pass testing tab-size: 25.4mm
+Pass testing tab-size: 18pt
+Pass testing tab-size: 5pc
+Pass testing tab-size: 101.6Q
+Pass testing tab-size: 7px
+Pass testing tab-size: 1em
+Pass testing tab-size: 2ex
+Pass testing tab-size: 3rem
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-text/tab-size/tab-size.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-text/tab-size/tab-size.txt
new file mode 100644
index 00000000000..9fccc79b917
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-text/tab-size/tab-size.txt
@@ -0,0 +1,6 @@
+Harness status: OK
+
+Found 1 tests
+
+1 Pass
+Pass Test tab-size measurements
\ No newline at end of file
diff --git a/Tests/LibWeb/Text/input/css/tab-stops-on-wrapped-lines.html b/Tests/LibWeb/Text/input/css/tab-stops-on-wrapped-lines.html
new file mode 100644
index 00000000000..68ca63fe094
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/tab-stops-on-wrapped-lines.html
@@ -0,0 +1,63 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<script src="../include.js"></script>
+<style>
+ @font-face {
+ font-family: Ahem;
+ src: url("../../../Ref/data/fonts/Ahem.ttf");
+ }
+ body { margin: 0; font: 10px/1 Ahem; }
+ div.t { display: flow-root; white-space: pre-wrap; tab-size: 8; width: 105px; }
+ .float { float: left; width: 20px; height: 30px; }
+</style>
+<div class="t" id="after-a-wrap-at-a-space">aaaaaaaa aaa b</div>
+<div class="t" id="after-a-wrap-at-a-wbr">aaaaaaaaaa<wbr>aaa b</div>
+<div class="t" id="after-two-wraps">aaaaaaaa aaaaaaaa aa b</div>
+<div class="t" id="after-a-forced-break">aaaaaaaa
+aaa b</div>
+<div class="t" id="in-a-padded-span">aaaaaaaa <span style="padding-left: 10px">aa b</span></div>
+<div class="t" id="with-a-length-tab-size" style="tab-size: 25px">aaaaaaaa aaa b</div>
+<div class="t" id="after-a-text-indent" style="text-indent: 20px">aa b</div>
+<div class="t" id="beside-a-float"><div class="float"></div>aa b</div>
+<div class="t" id="beside-a-float-on-a-wrapped-line"><div class="float" style="margin-top: 10px"></div>aaaaaaaa aaa b</div>
+<div class="t" id="in-a-max-content-box-with-a-float" style="width: max-content"><div class="float"></div>aa b</div>
+<div class="t" id="after-hanging-white-space-beside-a-float" style="tab-size: 80px; width: 150px"><div class="float" style="width: 61px; height: 40px"></div><span style="display: inline-block; width: 89px; height: 10px"></span> b</div>
+<div class="t" id="before-an-empty-span">aaaaaaaa aaa <span class="empty"></span>b</div>
+<div class="t" id="before-rtl-text-under-plaintext" data-measures-the-tab style="unicode-bidi: plaintext; tab-size: 80px; width: 200px"><div class="float"></div> א</div>
+<div class="t" id="vertical" style="writing-mode: vertical-rl; height: 105px; width: auto">aaaaaaaa aaa b</div>
+<script>
+ // Tab stops are measured from the content edge of the line a tab is on, past any float, wherever the line starts:
+ // after a soft wrap just as after a forced break.
+ asyncTest(async done => {
+ await document.fonts.ready;
+ for (const div of document.querySelectorAll("div[id]")) {
+ if (div.hasAttribute("data-measures-the-tab")) {
+ const text = [...div.childNodes].find(node => node.nodeType === Node.TEXT_NODE);
+ const range = document.createRange();
+ range.setStart(text, 0);
+ range.setEnd(text, 1);
+ println(`${div.id}: the tab is ${Math.round(range.getBoundingClientRect().width)}px wide`);
+ continue;
+ }
+ const walker = document.createTreeWalker(div, NodeFilter.SHOW_TEXT);
+ let b = null;
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
+ const index = node.data.lastIndexOf("b");
+ if (index >= 0)
+ b = [node, index];
+ }
+ const range = document.createRange();
+ range.setStart(b[0], b[1]);
+ range.setEnd(b[0], b[1] + 1);
+ const rect = range.getBoundingClientRect();
+ const box = div.getBoundingClientRect();
+ println(`${div.id}: "b" at (${Math.round(rect.left - box.left)}, ${Math.round(rect.top - box.top)})`);
+ const empty = div.querySelector(".empty");
+ if (empty) {
+ const emptyRect = empty.getClientRects()[0];
+ println(`${div.id}: the empty span at (${Math.round(emptyRect.left - box.left)}, ${Math.round(emptyRect.top - box.top)})`);
+ }
+ }
+ done();
+ });
+</script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-text/tab-size/tab-size-computed-value-001.html b/Tests/LibWeb/Text/input/wpt-import/css/css-text/tab-size/tab-size-computed-value-001.html
new file mode 100644
index 00000000000..ddbed872f35
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-text/tab-size/tab-size-computed-value-001.html
@@ -0,0 +1,147 @@
+<!DOCTYPE html>
+
+ <meta charset="UTF-8">
+
+ <title>CSS Text Test: computed value of 'tab-size'</title>
+
+ <!--
+
+ Issue 463: [css-text] The computed value and animation type of tab-size
+ https://github.com/w3c/csswg-drafts/issues/463
+
+ -->
+
+ <link rel="author" title="Gérard Talbot" href="http://www.gtalbot.org/BrowserBugsSection/css21testsuite/">
+ <link rel="help" href="https://www.w3.org/TR/css-text-3/#tab-size-property">
+
+ <meta content="This test checks that the computed value of 'tab-size' is a number when it is specified as such or is a length (absolute or relative) when it is specified as such." name="assert">
+
+ <link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css">
+
+ <script src="../../../resources/testharness.js"></script>
+
+ <script src="../../../resources/testharnessreport.js"></script>
+
+ <style>
+ div#target
+ {
+ font-family: Ahem;
+ font-size: 20px;
+ }
+ </style>
+
+ <div id="target">A</div>
+
+ <div id="log"></div>
+
+ <script>
+ function startTesting()
+ {
+
+ var targetElement = document.getElementById("target");
+
+ function verifyComputedStyle(property_name, specified_value, expected_value)
+ {
+
+ test(function()
+ {
+
+ targetElement.style.setProperty(property_name, "initial");
+
+ /*
+ The purpose of setting the property to its initial value
+ is to act as a fallback value in case the specified value
+ fails. Since we are running 11 consecutive tests on the
+ same element, then it is necessary to 'reset' its property
+ to an initial value.
+ */
+
+ targetElement.style.setProperty(property_name, specified_value);
+
+ assert_equals(getComputedStyle(targetElement)[property_name], expected_value);
+
+ }, `testing ${property_name}: ${specified_value}`);
+ }
+
+ function compareValueCloseTo(property_name, specified_value, epsilon, expected_value)
+ {
+
+ test(function()
+ {
+
+ targetElement.style.setProperty(property_name, "initial");
+
+ targetElement.style.setProperty(property_name, specified_value);
+
+ var computedSpecifiedValue = parseFloat(getComputedStyle(targetElement)[property_name]);
+
+ assert_true(isFinite(computedSpecifiedValue)); /* We can not accept NaN as value */
+
+ targetElement.style.setProperty(property_name, expected_value);
+
+ var computedExpectedValue = parseFloat(getComputedStyle(targetElement)[property_name]);
+
+ assert_array_approx_equals(computedSpecifiedValue, computedExpectedValue, epsilon);
+
+ }, `testing ${property_name}: ${specified_value}`);
+
+ }
+
+ verifyComputedStyle("tab-size", "4", "4");
+
+ /* verifyComputedStyle(property_name, initial_value, specified_value, expected_value) */
+
+ /* absolute length units: in, cm, mm, pt, pc, Q, px */
+
+ verifyComputedStyle("tab-size", "0.5in", "48px");
+
+ verifyComputedStyle("tab-size", "2.54cm", "96px");
+
+ verifyComputedStyle("tab-size", "25.4mm", "96px");
+
+ verifyComputedStyle("tab-size", "18pt", "24px");
+
+ verifyComputedStyle("tab-size", "5pc", "80px");
+
+ verifyComputedStyle("tab-size", "101.6Q", "96px");
+
+ verifyComputedStyle("tab-size", "7px", "7px");
+
+ /* verifyComputedStyle(property_name, specified_value, expected_value) */
+
+ /* relative length units: em, ex, rem */
+
+ verifyComputedStyle("tab-size", "1em", "20px");
+
+ /* compareValueCloseTo(property_name, specified_value, epsilon, expected_value) */
+
+ compareValueCloseTo("tab-size", "2ex", 0.001, "32px");
+
+ /*
+ For this sub-test, we set the tolerance precision (epsilon)
+ to (0.001 === 1 thousandth).
+ */
+
+ verifyComputedStyle("tab-size", "3rem", "48px");
+
+ /*
+
+ NOT tested are: vw, vh, vmin, vmax and ch units
+
+ verifyComputedStyle("tab-size", "4vw", "?px");
+
+ verifyComputedStyle("tab-size", "5vh", "?px");
+
+ verifyComputedStyle("tab-size", "6vmin", "?px");
+
+ verifyComputedStyle("tab-size", "7vmax", "?px");
+
+ verifyComputedStyle("tab-size", "8ch", "?px");
+
+ */
+
+ }
+
+ startTesting();
+
+ </script>
diff --git a/Tests/LibWeb/Text/input/wpt-import/css/css-text/tab-size/tab-size.html b/Tests/LibWeb/Text/input/wpt-import/css/css-text/tab-size/tab-size.html
new file mode 100644
index 00000000000..5d5721c60cf
--- /dev/null
+++ b/Tests/LibWeb/Text/input/wpt-import/css/css-text/tab-size/tab-size.html
@@ -0,0 +1,98 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<title>Test: CSS value type of the CSS property 'tab-size'</title>
+<link rel="help" href="https://drafts.csswg.org/css-text-3/#tab-size-property">
+<link rel="stylesheet" type="text/css" href="../../../fonts/ahem.css" />
+<style>
+body {
+ font-family: Ahem;
+ font-size: 13px;
+}
+.px-tab-size {
+ tab-size: 60px;
+}
+.em-tab-size {
+ tab-size: 7em;
+}
+.int-tab-size {
+ tab-size: 9;
+}
+.fractional-tab-size {
+ tab-size: 2.5;
+}
+</style>
+<script src=../../../resources/testharness.js></script>
+<script src=../../../resources/testharnessreport.js></script>
+<div style="background-repeat: repeat-x;">
+<div><pre id="leading-px" class="px-tab-size">&Tab;<span>leading text, tab-size in px.</span></pre></div>
+<div><pre id="leading-em" class="em-tab-size">&Tab;<span>leading text, tab-size in em.</span></pre></div>
+<div><pre id="leading-int" class="int-tab-size">&Tab;<span>leading text, tab-size in spaces.</span></pre></div>
+<div><pre id="leading-fraction" class="fractional-tab-size">&Tab;<span>leading text, tab-size in fraction.</span></pre></div>
+<div><pre id="trailing-px" class="px-tab-size"><span>leading text</span>&Tab;<span>trailing text, tab-size in px.</span></pre></div>
+<div><pre id="trailing-em" class="em-tab-size"><span>leading text</span>&Tab;<span>trailing text, tab-size in em.</span></pre></div>
+<div><pre id="trailing-int" class="int-tab-size"><span>leading text</span>&Tab;<span>trailing text, tab-size in spaces.</span></pre></div>
+<div><pre id="trailing-fraction" class="fractional-tab-size"><span>leading text</span>&Tab;<span>trailing text, tab-size in fraction.</span></pre></div>
+<div><pre>Some spaces... '<span id="space-size-reference"> </span>' ... for size reference.</pre></div>
+<div><pre>A space... '<span id="one-space-size-reference"> </span>' ... for size reference.</pre></div>
+<div><pre>'<span id="leading-text-size-reference">leading text</span>', for size reference.</pre></div>
+<script>
+test(function() {
+ // Tests with a tab character at the beginning of the line.
+ var pxPre = document.getElementById('leading-px');
+ var emPre = document.getElementById('leading-em');
+ var intPre = document.getElementById('leading-int');
+ var fractionPre = document.getElementById("leading-fraction");
+
+ var pxLeadingSpan = pxPre.firstElementChild;
+ var emLeadingSpan = emPre.firstElementChild;
+ var intLeadingSpan = intPre.firstElementChild;
+ var fractionLeadingspan = fractionPre.firstElementChild;
+
+ var pxExpected = 60; // tab size in px.
+ var emExpected = 13 * 7; // (font size) * (tab size in em)
+ var intExpected = document.getElementById('space-size-reference').getBoundingClientRect().width;
+ var fractionExpected = 2.5 * document.getElementById('one-space-size-reference').getBoundingClientRect().width;
+
+ var pxTabLength = pxLeadingSpan.getBoundingClientRect().left - pxPre.getBoundingClientRect().left;
+ var emTabLength = emLeadingSpan.getBoundingClientRect().left - emPre.getBoundingClientRect().left;
+ var intTabLength = intLeadingSpan.getBoundingClientRect().left - intPre.getBoundingClientRect().left;
+ var fractionTabLength = fractionLeadingspan.getBoundingClientRect().left - fractionPre.getBoundingClientRect().left;
+
+ assert_approx_equals(pxTabLength, pxExpected, 0.02);
+ assert_approx_equals(emTabLength, emExpected, 0.02);
+ assert_approx_equals(intTabLength, intExpected, 0.02);
+ assert_approx_equals(fractionTabLength, fractionExpected, 0.02);
+
+ // Tests with a tab character after leading text.
+ var leadingTextSize = document.getElementById('leading-text-size-reference').getBoundingClientRect().width;
+ pxExpected = pxExpected - (leadingTextSize % pxExpected);
+ emExpected = emExpected - (leadingTextSize % emExpected);
+ intExpected = intExpected - (leadingTextSize % intExpected);
+ fractionExpected = fractionExpected - (leadingTextSize % fractionExpected);
+
+ pxPre = document.getElementById('trailing-px');
+ emPre = document.getElementById('trailing-em');
+ intPre = document.getElementById('trailing-int');
+ fractionPre = document.getElementById("trailing-fraction");
+
+ pxLeadingSpan = pxPre.firstElementChild;
+ emLeadingSpan = emPre.firstElementChild;
+ intLeadingSpan = intPre.firstElementChild;
+ fractionLeadingspan = fractionPre.firstElementChild;
+
+ pxTrailingSpan = pxPre.lastElementChild;
+ emTrailingSpan = emPre.lastElementChild;
+ intTrailingSpan = intPre.lastElementChild;
+ fractionTrailingSpan = fractionPre.lastElementChild;
+
+ pxTabLength = pxTrailingSpan.getBoundingClientRect().left - pxLeadingSpan.getBoundingClientRect().right;
+ emTabLength = emTrailingSpan.getBoundingClientRect().left - emLeadingSpan.getBoundingClientRect().right;
+ intTabLength = intTrailingSpan.getBoundingClientRect().left - intLeadingSpan.getBoundingClientRect().right;
+ fractionTabLength = fractionTrailingSpan.getBoundingClientRect().left - fractionLeadingspan.getBoundingClientRect().right;
+
+ assert_approx_equals(pxTabLength, pxExpected, 0.02);
+ assert_approx_equals(emTabLength, emExpected, 0.02);
+ assert_approx_equals(intTabLength, intExpected, 0.02);
+ assert_approx_equals(fractionTabLength, fractionExpected, 0.02);
+}, "Test tab-size measurements");
+</script>