Truly independent web browser
LibWeb: Inherit `::first-letter` style from the element containing it
Tim Ledbetterdf8879c8aba6
diff --git a/Libraries/LibWeb/CSS/UpdateStyle.cpp b/Libraries/LibWeb/CSS/UpdateStyle.cppindex 1bb76510d25..e5d12d12408 100644--- a/Libraries/LibWeb/CSS/UpdateStyle.cpp+++ b/Libraries/LibWeb/CSS/UpdateStyle.cpp@@ -27,6 +27,7 @@#include <LibWeb/HTML/LocalNavigable.h>#include <LibWeb/HTML/NavigableContainer.h>#include <LibWeb/Layout/Box.h>+#include <LibWeb/Layout/NodeArena.h>#include <LibWeb/Selection/Selection.h>namespace Web::CSS {@@ -768,6 +769,8 @@ static void update_style(Layout::BegunRead const& read, DOM::Document& document,document.set_has_completed_style_update();apply_document_style_invalidation_after_style_change(document, application.invalidation);document.sample_animation_effects_needing_style_update();+ if (auto* arena = document.layout_node_arena_if_created())+ Layout::RustFFI::render_state_refresh_first_letter_styles(arena->host());}// Records what update_style() records before it takes the document's style transaction, and lets the transaction flydiff --git a/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs b/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rsindex 76ef9bdf28c..bf27182e504 100644--- a/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs+++ b/Libraries/LibWeb/Rust/src/css/style/publication/pseudo.rs@@ -1189,6 +1189,119 @@ impl RetainedState {Ok((old_record, record))}+ fn refresh_stale_first_letter_winners(&mut self, node: StyleNodeID) {+ let first_letter =+ tree::PseudoElementTarget::new(tree::PseudoElementKind(u16::from(pseudo_kind::FIRST_LETTER)));+ let program_version = self.program.version();+ let current = self+ .current_winner_groups()+ .pseudo_state(node, first_letter)+ .is_some_and(|(version, _, priority_current)| version == program_version && priority_current);+ if current {+ return;+ }+ let republication = WinnerRepublication::for_flush();+ if self+ .republish_pseudo_winners_from_retained_answer(node, republication)+ .is_none()+ {+ self.rematch_driven_winners(node, republication);+ }+ }++ fn first_letter_record_inheriting_from(+ &mut self,+ node: StyleNodeID,+ parent: StyleNodeID,+ font_scratch: &mut drive::FontDriveScratch,+ ) -> Drive<computed::FinalStyleRecordID> {+ let kind = pseudo_kind::FIRST_LETTER;+ let program_version = self.program.version();+ let state = self+ .current_winner_groups()+ .pseudo_state(+ node,+ tree::PseudoElementTarget::new(tree::PseudoElementKind(u16::from(kind))),+ )+ .filter(|&(version, _, priority_current)| version == program_version && priority_current)+ .map(|(_, state, _)| state)+ .or_refused()?;+ let facts = self.computed_group_sets.adjustment_facts(node);+ let mut inputs = self.document_style_computation_inputs;+ if facts & bridge::element_adjustment_fact::IS_DOCUMENT_ELEMENT != 0 {+ let element_record = self.computed_group_sets.assigned_style_record(node).or_refused()?;+ self.root_font_inputs_from_record(element_record)+ .or_refused()?+ .apply_to(&mut inputs);+ }+ if self.declares_registered_custom_property(node, Some(kind), &inputs) {+ return Err(Unanswered::Refused);+ }+ let parent_record = self.computed_group_sets.assigned_style_record(parent).or_refused()?;+ let parent_environment = self.held_custom_property_environment(parent)?;+ let environment =+ self.engine_custom_property_environment_of(node, Some(kind), parent_environment, &inputs, None)?;+ let mut substituted = false;+ let store = self.cascaded_store_for_state(+ node,+ state,+ Some(kind),+ custom_property_cascade::SubstitutionEnvironment {+ own: environment,+ inherited: parent_environment,+ },+ &mut substituted,+ )?;+ let target = computed::ComputedStyleTarget::new(node, kind);+ let subject = DriveSubject {+ target,+ parent: Some(parent),+ facts: facts & PSEUDO_ELEMENT_ADJUSTMENT_FACTS,+ };+ let FullDrive::Driven(DrivenTable {+ table, length, font, ..+ }) = self.engine_full_drive(+ subject,+ None,+ &store,+ &inputs,+ font_scratch,+ FontDriveGoal::Complete,+ None,+ )?+ else {+ unreachable!("a complete drive that waits for no registered context answers with its table");+ };+ let font = font.expect("a full drive resolves the font");+ let registry = self.table_counter_style_environment_identity(target, &table);+ let (record, _) = self.assemble_and_publish_engine_record(+ None,+ Some(parent_record),+ table,+ &length,+ &font,+ environment,+ 0,+ registry,+ None,+ &mut EngineComputabilityScratch::default(),+ )?;+ Ok(record)+ }++ pub(crate) fn first_letter_inheritance_parent_style(+ &self,+ node: StyleNodeID,+ text: StyleNodeID,+ ) -> Option<(u64, u64)> {+ let parent = self.tree.inheritance_parent(text).filter(|&parent| parent != node)?;+ let sets = &self.computed_group_sets;+ Some((+ sets.assigned_style_record(parent)?.raw(),+ sets.custom_property_environment_identity(parent).unwrap_or(0),+ ))+ }+/// Whether the node holds a match answer its pseudo-elements' winners are proven from: the/// one this transaction published, or the retained one./// The synthetic pseudo-elements a published answer has rules for, where it can say.@@ -1454,6 +1567,39 @@ impl StyleEngine {}settled}++ pub(crate) fn first_letter_record_inheriting_from_text_parent(+ &mut self,+ node: StyleNodeID,+ text: StyleNodeID,+ ) -> Option<u64> {+ let parent = self+ .retained+ .tree+ .inheritance_parent(text)+ .filter(|&parent| parent != node)?;+ let font_environment_generation = self+ .retained+ .document_style_computation_inputs+ .font_environment_generation;+ if let Some(resolver) = &mut self.retained.font_resolution {+ resolver.prepare(font_environment_generation);+ }+ self.retained.refresh_stale_first_letter_winners(node);+ let mut font_scratch = drive::FontDriveScratch::default();+ loop {+ match self+ .retained+ .first_letter_record_inheriting_from(node, parent, &mut font_scratch)+ {+ Err(Unanswered::Suspended(Suspension::Font)) => {+ let request = font_scratch.take_suspended_request();+ self.refill_font_request(node, request);+ }+ attempt => return attempt.ok().map(computed::FinalStyleRecordID::raw),+ }+ }+ }}fn synthetic_pseudo_bit(pseudo: Option<tree::PseudoElementTarget>) -> u64 {diff --git a/Libraries/LibWeb/Rust/src/css/style/tree.rs b/Libraries/LibWeb/Rust/src/css/style/tree.rsindex 4cff4bc5dcb..807dd80b47c 100644--- a/Libraries/LibWeb/Rust/src/css/style/tree.rs+++ b/Libraries/LibWeb/Rust/src/css/style/tree.rs@@ -1698,7 +1698,10 @@ impl StyleNodeTree {if let Some(slot) = self.assigned_slot_of(node) {return Some(slot);}- let parent = self.parent(node)?;+ let parent = match node.text_index() {+ Some(_) => self.text_parent(node)?,+ None => self.parent(node)?,+ };Some(self.host_of(parent).unwrap_or(parent))}diff --git a/Libraries/LibWeb/Rust/src/layout/layout_changes.rs b/Libraries/LibWeb/Rust/src/layout/layout_changes.rsindex ede602f2d2f..25b46d32e08 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_changes.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_changes.rs@@ -346,6 +346,8 @@ pub(crate) enum LayoutWrite<'a> {ReinheritAnonymousDescendants { node: NodeSlotId },/// The anonymous boxes that give the text of a `display: contents` element its style take it again.ReinheritDisplayContentsText { element: StyleNodeID },+ /// Each `::first-letter` box whose element containing the letter took another style takes its style again.+ RefreshFirstLetterStyles,/// The viewport and the boxes of the root element and its body take the styles viewport propagation gives them.PropagateRootStylesToViewport,/// Prepares every row of the subtree the row heads for leaving the layout tree.@@ -403,6 +405,10 @@ impl LayoutWrite<'_> {arena.reinherit_display_contents_text(host_calls, element);false}+ Self::RefreshFirstLetterStyles => {+ arena.refresh_first_letter_styles(host_calls);+ false+ }Self::PropagateRootStylesToViewport => {let viewport = arena.bound_viewport_row();if !viewport.is_invalid() {diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rsindex 805521d1779..820a9a277af 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena.rs@@ -26,8 +26,8 @@ use crate::layout::ComputedValuesView;use crate::layout::CssPixels;use crate::layout::node_data::{AncestorFact, DomPaintFact, FfiStylePayloads, GENERATED_FOR_AFTER, GENERATED_FOR_BEFORE,- GENERATED_FOR_LAST_SYNTHETIC, GENERATED_FOR_MARKER, MAX_NODE_SLOT_COUNT, NodeData, NodeFlag, NodeKind, NodeSlotId,- StylePayloadsRef, pseudo_kind_of,+ GENERATED_FOR_FIRST_LETTER, GENERATED_FOR_LAST_SYNTHETIC, GENERATED_FOR_MARKER, MAX_NODE_SLOT_COUNT, NodeData,+ NodeFlag, NodeKind, NodeSlotId, StylePayloadsRef, pseudo_kind_of,};use crate::layout::node_facts::ReplacedContentFacts;use crate::layout::tree_mutation::HostCalls;@@ -1146,6 +1146,10 @@ pub(crate) struct LayoutNodeArena {position_options_in_use: HashMap<NodeSlotId, super::abspos_inputs::PositionOptionChoice>,/// https://drafts.csswg.org/css-anchor-position-1/#last-successful-position-optionlast_successful_position_options: HashMap<NodeSlotId, super::abspos_inputs::PositionOptionChoice>,+ /// The style record and custom property environment of the element containing the letter, as each+ /// `::first-letter` box's style was last derived from them.+ first_letter_parent_styles: HashMap<NodeSlotId, (u64, u64)>,+ first_letter_styles_derived: std::sync::Arc<std::sync::atomic::AtomicBool>,pub(crate) inline_boxes_lifted_out_of: HashMap<NodeSlotId, NodeSlotId>,pub(crate) out_of_flow_positioning_contained: HashMap<NodeSlotId, u32>,/// Attribution of pending updates for partial relayout. Invariant: every update recorded@@ -1253,6 +1257,8 @@ impl LayoutNodeArena {confined_abspos_layout_inputs: HashMap::default(),position_options_in_use: (HashMap::default()),last_successful_position_options: (HashMap::default()),+ first_letter_parent_styles: HashMap::default(),+ first_letter_styles_derived: std::sync::Arc::default(),inline_boxes_lifted_out_of: HashMap::default(),out_of_flow_positioning_contained: HashMap::default(),pending_updates_escape_partial_relayout: false,@@ -2789,6 +2795,10 @@ impl LayoutNodeArena {fork.chunks_by_address.sort_unstable_by_key(|address| address.start);fork.style_engine = ArenaStyleEngine(engine);fork.svg_paint_resources.detach_enrolled_flag_for_fork();+ fork.first_letter_styles_derived = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(+ self.first_letter_styles_derived+ .load(std::sync::atomic::Ordering::Relaxed),+ ));fork}@@ -2797,6 +2807,10 @@ impl LayoutNodeArena {self.svg_paint_resources.share_enrolled_flag(flag);}+ pub(crate) fn share_first_letter_styles_derived(&mut self, flag: std::sync::Arc<std::sync::atomic::AtomicBool>) {+ self.first_letter_styles_derived = flag;+ }+/// Gives the row at `index` the style record `record`, answering the one it held. A row whose record changes no/// longer holds the image resources it was owed for the old one.fn replace_style_record(&mut self, index: usize, record: u64) -> u64 {@@ -3445,6 +3459,99 @@ impl LayoutNodeArena {self.with_style_engine(|engine| LayoutStyle::anonymous(engine, parent, kind, overrides).intern(engine))}+ pub(crate) fn derive_first_letter_style_record(+ &mut self,+ originating: StyleNodeID,+ text: StyleNodeID,+ ) -> Option<DerivedStyleRecord> {+ self.with_style_engine(|engine| {+ let record = engine.first_letter_record_inheriting_from_text_parent(originating, text)?;+ Some(DerivedStyleRecord::pin(engine, record))+ })+ }++ pub(crate) fn note_first_letter_parent_style(+ &mut self,+ slot: NodeSlotId,+ originating: StyleNodeID,+ text: StyleNodeID,+ ) {+ let parent_style =+ self.with_style_store(|engine| engine.first_letter_inheritance_parent_style(originating, text));+ let Some(parent_style) = parent_style else {+ self.first_letter_parent_styles.remove(&slot);+ return;+ };+ self.first_letter_parent_styles.insert(slot, parent_style);+ self.first_letter_styles_derived+ .store(true, std::sync::atomic::Ordering::Relaxed);+ }++ pub(crate) fn refresh_first_letter_styles(&mut self, host_calls: HostCalls<'_>) {+ let noted: smallvec::SmallVec<[(NodeSlotId, (u64, u64)); 4]> = self+ .first_letter_parent_styles+ .iter()+ .map(|(&slot, &parent_style)| (slot, parent_style))+ .collect();+ for (slot, noted_parent_style) in noted {+ if !self.slot_is_live(slot) {+ self.first_letter_parent_styles.remove(&slot);+ continue;+ }+ let parent_style = self+ .node_style_node(slot)+ .zip(self.node_style_node(self.data(slot).first_child.get()))+ .and_then(|(originating, text)| {+ self.with_style_store(|engine| engine.first_letter_inheritance_parent_style(originating, text))+ });+ if parent_style != Some(noted_parent_style) {+ self.reinherit_first_letter_box(host_calls, slot);+ }+ }+ }++ fn reinherit_first_letter_box(&mut self, host_calls: HostCalls<'_>, slot: NodeSlotId) {+ let data = self.data(slot);+ if data.generated_for.get() != GENERATED_FOR_FIRST_LETTER+ || !super::node_facts::has_flag(data, NodeFlag::IsPseudoElementPrincipalBox)+ {+ return;+ }+ let kind = data.kind.get();+ let Some(originating) = self.node_style_node(slot) else {+ return;+ };+ let Some(text) = self.node_style_node(data.first_child.get()) else {+ return;+ };+ let derived = self.derive_first_letter_style_record(originating, text);+ self.note_first_letter_parent_style(slot, originating, text);+ let Some(derived) = derived else {+ return;+ };+ if derived.record == self.node_style_record(slot) {+ self.with_style_engine(|engine| engine.unpin_layout_style_record(derived.record));+ return;+ }+ let derived_kind = self+ .with_style_store(|engine| engine.published_record_view(derived.record).map(|view| view.display()))+ .and_then(super::tree_builder::node_kind_for_display);+ if derived_kind != Some(kind) {+ self.with_style_engine(|engine| engine.unpin_layout_style_record(derived.record));+ self.mark_layout_tree_update(+ Some(originating),+ super::tree_update_marks::FfiLayoutTreeUpdateMark::style_change(0),+ );+ return;+ }+ if self.apply_reinherited_style_record(host_calls, slot, derived) {+ self.set_needs_layout_update(slot, true);+ }+ if self.owe_style_image_resources_once(slot) {+ self.notify_shell_of_style_change(host_calls, slot, true);+ }+ }+/// `record` with its display replaced by `display`, pinned for a row of the arena.pub(crate) fn derive_style_record_with_display(&mut self,@@ -3548,6 +3655,7 @@ impl LayoutNodeArena {if self.node_style_record(node) == 0 {return;}+ self.reinherit_first_letter_box(host_calls, node);if self.is_display_contents_pseudo_element_box_holding_its_published_display(node) {self.make_display_contents_pseudo_element_box_inline(host_calls, node);}@@ -3626,6 +3734,8 @@ impl LayoutNodeArena {self.apply_reinherited_style_record(host_calls, child, derived);self.reinherit_anonymous_children(host_calls, child, derived.record);}+ } else {+ self.reinherit_first_letter_box(host_calls, child);}child = next_sibling;}diff --git a/Libraries/LibWeb/Rust/src/layout/layout_node_arena/main_thread_entries.rs b/Libraries/LibWeb/Rust/src/layout/layout_node_arena/main_thread_entries.rsindex c897b8ed022..1970141fcd2 100644--- a/Libraries/LibWeb/Rust/src/layout/layout_node_arena/main_thread_entries.rs+++ b/Libraries/LibWeb/Rust/src/layout/layout_node_arena/main_thread_entries.rs@@ -146,6 +146,15 @@ pub extern "C" fn render_state_reinherit_display_contents_text(host: &DocumentHohost.queue_change(crate::render_state::ArenaChange::ReinheritDisplayContentsText(element));}+/// Each `::first-letter` box whose element containing the letter took another style takes its style again, which its+/// layout node hears of once the host has its next job back.+#[unsafe(no_mangle)]+pub extern "C" fn render_state_refresh_first_letter_styles(host: &DocumentHost) {+ if host.first_letter_styles_may_be_derived() {+ host.queue_change(crate::render_state::ArenaChange::RefreshFirstLetterStyles);+ }+}+/// The viewport and the boxes of the root element and its body take the styles viewport propagation gives them, which/// their layout nodes hear of before the host goes on.///diff --git a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs b/Libraries/LibWeb/Rust/src/layout/tree_builder.rsindex 432fdac6c53..8cbd2db964d 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_builder.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_builder.rs@@ -164,7 +164,7 @@ fn apply_replaced_display_adjustment(}/// The kind of box a computed display asks for, or none for a display that generates no box.-fn node_kind_for_display(display: FfiDisplay) -> Option<NodeKind> {+pub(crate) fn node_kind_for_display(display: FfiDisplay) -> Option<NodeKind> {if display.is_none() || display.is_contents() {return None;}@@ -4984,7 +4984,8 @@ fn create_first_letter_boxes(host: &mut TreeBuilderHost<'_>, element: StyleNodeIhost.stamp_generated_text_box(&source[letter_end..]),)};- if let Some(text) = host.arena().node_style_node(first_letter_slice) {+ let text = host.arena().node_style_node(first_letter_slice);+ if let Some(text) = text {for slice in [first_letter_slice, remainder_slice] {host.stamp_text_row_facts(slice, text);}@@ -4994,15 +4995,22 @@ fn create_first_letter_boxes(host: &mut TreeBuilderHost<'_>, element: StyleNodeIlet first_letter_slice = host.created(first_letter_slice);let remainder_slice = host.created(remainder_slice);+ let derived = text.and_then(|text| host.arena_mut().derive_first_letter_style_record(element, text));let wrapper_kind = host.arena().with_style_store(|engine| {- engine- .pseudo_published_style_view(element, pseudo_kind_of(GENERATED_FOR_FIRST_LETTER))- .map(|view| view.display())+ match derived {+ Some(derived) => engine.published_record_view(derived.record),+ None => engine.pseudo_published_style_view(element, pseudo_kind_of(GENERATED_FOR_FIRST_LETTER)),+ }+ .map(|view| view.display())}).and_then(node_kind_for_display);let Some(wrapper_kind) = wrapper_kind else {+ if let Some(derived) = derived {+ host.arena_mut()+ .with_style_engine(|engine| engine.unpin_layout_style_record(derived.record));+ }// A `::first-letter` whose display generates no box leaves the text it matched alone.host.free_unplaced(first_letter_slice);host.free_unplaced(remainder_slice);@@ -5021,6 +5029,14 @@ fn create_first_letter_boxes(host: &mut TreeBuilderHost<'_>, element: StyleNodeIlet wrapper_slot = host.arena.allocate_unbound();host.arena_mut().stamp_pseudo_element_row(wrapper_slot, wrapper_kind, element, GENERATED_FOR_FIRST_LETTER);+ if let Some(derived) = derived {+ host.arena_mut()+ .replace_arena_pinned_style_record(wrapper_slot, derived);+ }+ if let Some(text) = text {+ host.arena_mut()+ .note_first_letter_parent_style(wrapper_slot, element, text);+ }host.note_style_of_built_row(wrapper_slot, None);host.arena_mut().owe_image_resources(wrapper_slot,diff --git a/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs b/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rsindex fc82ab2656e..eae24e9c6ef 100644--- a/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs+++ b/Libraries/LibWeb/Rust/src/layout/tree_update_marks.rs@@ -295,6 +295,15 @@ impl FfiLayoutTreeUpdateMark {is_child_list_insertion: false,is_structural_boundary_self_rebuild: true,};++ /// The mark a style change makes for the next layout tree build, which may reuse a box as `reuse_reason` says.+ pub(crate) const fn style_change(reuse_reason: u8) -> Self {+ Self {+ reuse_reason,+ is_child_list_insertion: false,+ is_structural_boundary_self_rebuild: false,+ }+ }}impl LayoutNodeArena {diff --git a/Libraries/LibWeb/Rust/src/render_state.rs b/Libraries/LibWeb/Rust/src/render_state.rsindex 858364c6eab..91883f6a618 100644--- a/Libraries/LibWeb/Rust/src/render_state.rs+++ b/Libraries/LibWeb/Rust/src/render_state.rs@@ -66,6 +66,9 @@ impl RenderState {arena.arena_mut().share_svg_paint_resources_enrolled(shared.svg_paint_resources_enrolled);+ arena+ .arena_mut()+ .share_first_letter_styles_derived(shared.first_letter_styles_derived);arena.arena_mut().set_style_engine(engine);Self {arena,@@ -358,6 +361,8 @@ pub(crate) enum ArenaChange {ReinheritAnonymousDescendants(crate::layout::node_data::NodeSlotId),/// The anonymous boxes that give the text of a `display: contents` element its style take it again.ReinheritDisplayContentsText(crate::css::style::tree::StyleNodeID),+ /// The `::first-letter` boxes whose element containing the letter took another style take their style again.+ RefreshFirstLetterStyles,/// A removed node's box leaves its parent's box in place, or the parent is marked for a rebuild, as the render state/// finds the boxes (see [`crate::layout::box_removal`]), which owes the host what it pays once the job that applies/// it is done.@@ -416,6 +421,11 @@ impl ArenaChange {.apply(arena).host_work,),+ Self::RefreshFirstLetterStyles => owed.push(+ crate::layout::layout_changes::LayoutWrite::RefreshFirstLetterStyles+ .apply(arena)+ .host_work,+ ),Self::RemoveBox(removal) => removal.apply(arena, owed),Self::Paint(change) => change.apply(arena),Self::Style(change) => change.apply(state.engine_mut()),@@ -442,6 +452,7 @@ impl ArenaChange {| Self::DetachForRemoval(_)| Self::ReinheritAnonymousDescendants(_)| Self::ReinheritDisplayContentsText(_)+ | Self::RefreshFirstLetterStyles| Self::RemoveBox(_) => false,}}@@ -458,6 +469,7 @@ impl ArenaChange {Self::DetachForRemoval(_)| Self::ReinheritAnonymousDescendants(_)| Self::ReinheritDisplayContentsText(_)+ | Self::RefreshFirstLetterStyles| Self::RemoveBox(_)| Self::Rule(_) => (true, true),};@@ -475,7 +487,9 @@ impl ArenaChange {Self::Layout(change) => change.row_write(),Self::Paint(change) => change.row_write(),Self::DetachForRemoval(_) | Self::RemoveBox(_) => RowWrite::Identities,- Self::ReinheritAnonymousDescendants(_) | Self::ReinheritDisplayContentsText(_) => RowWrite::NamedStyles,+ Self::ReinheritAnonymousDescendants(_)+ | Self::ReinheritDisplayContentsText(_)+ | Self::RefreshFirstLetterStyles => RowWrite::NamedStyles,Self::Style(_) | Self::Engine(_) | Self::Rule(_) => RowWrite::None,}}@@ -586,7 +600,9 @@ impl ChangeQueue {ArenaChange::Layout(crate::layout::layout_changes::LayoutChange::SetNodeStyle { node, .. }) => {self.styled_rows.borrow_mut().insert(*node);}- ArenaChange::ReinheritAnonymousDescendants(_) | ArenaChange::ReinheritDisplayContentsText(_) => {+ ArenaChange::ReinheritAnonymousDescendants(_)+ | ArenaChange::ReinheritDisplayContentsText(_)+ | ArenaChange::RefreshFirstLetterStyles => {self.restyles_anonymous_rows.set(true);}_ => {}diff --git a/Libraries/LibWeb/Rust/src/render_state/clock.rs b/Libraries/LibWeb/Rust/src/render_state/clock.rsindex 795b88abea6..5750f6188c4 100644--- a/Libraries/LibWeb/Rust/src/render_state/clock.rs+++ b/Libraries/LibWeb/Rust/src/render_state/clock.rs@@ -821,15 +821,6 @@ enum TickRebuild {Again,}-/// The mark a style change makes for the next layout tree build, which may reuse a box as `reuse_reason` says.-fn style_change_mark(reuse_reason: u8) -> FfiLayoutTreeUpdateMark {- FfiLayoutTreeUpdateMark {- reuse_reason,- is_child_list_insertion: false,- is_structural_boundary_self_rebuild: false,- }-}-/// How many times a tick lays out again what the containers it resized restyled, as the host's layout update/// stabilizes them.const SIZE_QUERY_ROUND_LIMIT: usize = 8;@@ -945,7 +936,10 @@ impl Lane {TickRebuild::PseudoElements => {let in_place = build_keeps_box(arena, node, PSEUDO_ELEMENT_CHANGE);if in_place {- arena.mark_layout_tree_update(Some(node), style_change_mark(PSEUDO_ELEMENT_CHANGE));+ arena.mark_layout_tree_update(+ Some(node),+ FfiLayoutTreeUpdateMark::style_change(PSEUDO_ELEMENT_CHANGE),+ );}in_place}@@ -972,7 +966,7 @@ impl Lane {restore_samples_for_build(arena, ticked, None, restyles, |arena, inner, _| {box_holds(arena, row, inner)})?;- arena.mark_layout_tree_update(Some(node), style_change_mark(0));+ arena.mark_layout_tree_update(Some(node), FfiLayoutTreeUpdateMark::style_change(0));}in_place}@@ -1080,7 +1074,7 @@ fn mark_region_for_tree_build(restore_samples_for_build(arena, ticked, Some(resampled), restyles, |arena, inner, _| {box_holds(arena, row, inner)})?;- arena.mark_layout_tree_update(Some(root), style_change_mark(0));+ arena.mark_layout_tree_update(Some(root), FfiLayoutTreeUpdateMark::style_change(0));Ok(())}diff --git a/Libraries/LibWeb/Rust/src/render_state/document_host.rs b/Libraries/LibWeb/Rust/src/render_state/document_host.rsindex eafaa58a2f1..ae49f96a527 100644--- a/Libraries/LibWeb/Rust/src/render_state/document_host.rs+++ b/Libraries/LibWeb/Rust/src/render_state/document_host.rs@@ -948,6 +948,10 @@ impl DocumentHost {self.shared.svg_paint_resources_enrolled.load(Ordering::Relaxed)}+ pub(crate) fn first_letter_styles_may_be_derived(&self) -> bool {+ self.shared.first_letter_styles_derived.load(Ordering::Relaxed)+ }+/// Whether some element may have random base values to keep, which only then is worth asking the render state.pub(crate) fn element_random_base_values_may_exist(&self) -> bool {self.shared.element_random_base_values_exist.load(Ordering::Relaxed)diff --git a/Libraries/LibWeb/Rust/src/render_state/owner.rs b/Libraries/LibWeb/Rust/src/render_state/owner.rsindex 55962c3be74..44bfbe746dc 100644--- a/Libraries/LibWeb/Rust/src/render_state/owner.rs+++ b/Libraries/LibWeb/Rust/src/render_state/owner.rs@@ -43,6 +43,9 @@ pub(crate) struct SharedWithHost {pub(super) element_random_base_values_exist: Arc<AtomicBool>,/// The flag the state's arena raises while any row has enrolled an SVG paint resource.pub(super) svg_paint_resources_enrolled: Arc<AtomicBool>,+ /// The flag the state's arena raises once any `::first-letter` box takes a style derived from the element+ /// containing its letter, and never lowers.+ pub(super) first_letter_styles_derived: Arc<AtomicBool>,/// The flag the state's style engine raises while it keeps any row's container effects for the host.pub(super) container_effects_held: Arc<AtomicBool>,/// The versions the state's style engine mints declaration blocks from, which the host mints from as well.diff --git a/Tests/LibWeb/Ref/expected/first-letter-inherits-from-letter-parent-after-rule-insertion-ref.html b/Tests/LibWeb/Ref/expected/first-letter-inherits-from-letter-parent-after-rule-insertion-ref.htmlnew file mode 100644index 00000000000..df10128c0ec--- /dev/null+++ b/Tests/LibWeb/Ref/expected/first-letter-inherits-from-letter-parent-after-rule-insertion-ref.html@@ -0,0 +1,5 @@+<!DOCTYPE html>+<style>+ h1 { font-size: 40px; margin: 0; }+</style>+<div><div><h1><span>S</span>ample text</h1></div></div>diff --git a/Tests/LibWeb/Ref/expected/first-letter-inherits-from-letter-parent-ref.html b/Tests/LibWeb/Ref/expected/first-letter-inherits-from-letter-parent-ref.htmlnew file mode 100644index 00000000000..fba630acdf1--- /dev/null+++ b/Tests/LibWeb/Ref/expected/first-letter-inherits-from-letter-parent-ref.html@@ -0,0 +1,7 @@+<!DOCTYPE html>+<div><span style="font-size: 40px"><span style="color: green">S</span>ample text</span></div>+<div><span style="font-size: 40px"><span style="color: green; font-size: 20px">S</span>ample text</span></div>+<div><span style="font-size: 40px"><span style="color: green; float: right">S</span>ample text</span></div>+<div><span style="font-size: 40px"><span style="color: green; background-color: blue">S</span>ample text</span></div>+<div><span style="font-size: 40px"><span style="color: green; font-size: 20px">S</span>ample text</span></div>+<div><span style="font-size: 40px"><span style="color: green; text-decoration: underline">S</span>ample text</span></div>diff --git a/Tests/LibWeb/Ref/input/first-letter-inherits-from-letter-parent-after-rule-insertion.html b/Tests/LibWeb/Ref/input/first-letter-inherits-from-letter-parent-after-rule-insertion.htmlnew file mode 100644index 00000000000..41ed5764928--- /dev/null+++ b/Tests/LibWeb/Ref/input/first-letter-inherits-from-letter-parent-after-rule-insertion.html@@ -0,0 +1,19 @@+<!DOCTYPE html>+<html class="reftest-wait">+<link rel="match" href="../expected/first-letter-inherits-from-letter-parent-after-rule-insertion-ref.html">+<style>+ .wrapper::first-letter { margin-left: 0; }+ h1 { font-size: 40px; margin: 0; }+</style>+<div><div class="wrapper"><h1 id="heading">Sample text</h1></div></div>+<script>+ const nextFrame = () => new Promise(resolve => requestAnimationFrame(resolve));+ (async () => {+ await nextFrame();+ await nextFrame();+ document.head.appendChild(document.createElement("style")).sheet.insertRule(".unrelated > div > * { order: 1; }");+ document.getElementById("heading").append(document.createComment(""));+ document.documentElement.classList.remove("reftest-wait");+ })();+</script>+</html>diff --git a/Tests/LibWeb/Ref/input/first-letter-inherits-from-letter-parent.html b/Tests/LibWeb/Ref/input/first-letter-inherits-from-letter-parent.htmlnew file mode 100644index 00000000000..d506e4e2e60--- /dev/null+++ b/Tests/LibWeb/Ref/input/first-letter-inherits-from-letter-parent.html@@ -0,0 +1,32 @@+<!DOCTYPE html>+<html class="reftest-wait">+<link rel="match" href="../expected/first-letter-inherits-from-letter-parent-ref.html">+<style>+ div::first-letter { color: green; font-size: var(--size); float: var(--float); background-color: var(--background); }+ div.underlined::first-letter { text-decoration: underline; }+ span { font-size: 40px; }+</style>+<div><span>Sample text</span></div>+<div><span id="resized-letter-parent">Sample text</span></div>+<div><span id="refloated-letter-parent">Sample text</span></div>+<div id="restyled-originating-element"><span>Sample text</span></div>+<div id="resized-originating-element" style="font-size: 40px"><span style="display: contents">Sample text</span></div>+<div id="restyled-first-letter"><span>Sample text</span></div>+<script>+ const nextFrame = () => new Promise(resolve => requestAnimationFrame(resolve));+ (async () => {+ await nextFrame();+ await nextFrame();+ document.getElementById("refloated-letter-parent").style.setProperty("--float", "right");+ await nextFrame();+ await nextFrame();+ document.getElementById("restyled-originating-element").style.setProperty("--background", "blue");+ document.getElementById("resized-originating-element").style.setProperty("--size", "20px");+ document.getElementById("restyled-first-letter").classList.add("underlined");+ await nextFrame();+ await nextFrame();+ document.getElementById("resized-letter-parent").style.setProperty("--size", "20px");+ document.documentElement.classList.remove("reftest-wait");+ })();+</script>+</html>