Skip to content

Truly independent web browser

LibWeb: Confine the style input journal to tests

Andreas Klingb4fe056c99ce
diff --git a/Libraries/LibWeb/CSS/StyleEngineInput.cpp b/Libraries/LibWeb/CSS/StyleEngineInput.cpp
index 24bd68f40cc..6eebdb61965 100644
--- a/Libraries/LibWeb/CSS/StyleEngineInput.cpp
+++ b/Libraries/LibWeb/CSS/StyleEngineInput.cpp
@@ -2691,7 +2691,6 @@ void record_element_declarations_changed(DOM::Element& element, ElementDeclarati
// applies the delta.
style_engine->record_element_declaration_delta({
.node = element.style_node_id().value(),
- .kind = kind,
.old_block = had_declarations ? 1u : 0u,
.new_block = has_declarations ? 1u : 0u,
});
diff --git a/Libraries/LibWeb/Rust/src/css/style/bridge.rs b/Libraries/LibWeb/Rust/src/css/style/bridge.rs
index 0ba2c32cdb1..6be19fa7c6b 100644
--- a/Libraries/LibWeb/Rust/src/css/style/bridge.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/bridge.rs
@@ -46,10 +46,13 @@ use super::pipeline::rule_store::DeclarationBlockID;
use super::StyleEngine;
use super::input_types::ElementDeclarationKind;
+#[cfg(test)]
use super::input_types::InputKey;
+#[cfg(test)]
use super::input_types::InputValue;
use super::input_types::StateFact;
use super::input_types::TreeRelations;
+use super::instrumentation::Counter;
use super::pipeline::rule_store::RuleID;
use super::pipeline::rule_store::SheetID;
use super::tree::StyleNodeID;
@@ -942,7 +945,6 @@ pub enum FfiElementDeclarationKind {
#[repr(C)]
pub struct FfiElementDeclarationDelta {
pub node: u32,
- pub kind: FfiElementDeclarationKind,
pub old_block: u32,
pub new_block: u32,
}
@@ -1106,10 +1108,6 @@ impl StyleEngine {
};
self.record_input(
InputKey::ElementStyleInput(node),
- InputValue::ElementStyleInput {
- reaction: 0,
- inherited_style_groups: 0,
- },
InputValue::ElementStyleInput {
reaction: input.reaction,
inherited_style_groups: input.inherited_style_groups,
@@ -1134,11 +1132,11 @@ impl StyleEngine {
// host: the host says only that the node has one.
let new_block =
(delta.new_block != 0).then(|| DeclarationBlockID::new(self.retained.next_declaration_block_version()));
- self.record_input(
- InputKey::ElementDeclaration(node, decode_element_declaration_kind(delta.kind)),
- InputValue::ElementDeclaration(block(delta.old_block)),
- InputValue::ElementDeclaration(new_block),
- );
+ self.retained.counters.bump(Counter::RawMutationRecords);
+ self.retained.counters.bump(Counter::ElementDeclarationDeltas);
+ if block(delta.old_block) != new_block {
+ self.host.element_inputs.note_declaration(node);
+ }
}
}
}
@@ -2054,7 +2052,6 @@ mod tests {
}];
let declarations = [FfiElementDeclarationDelta {
node: nodes[1],
- kind: FfiElementDeclarationKind::InlineStyle,
old_block: 0,
new_block: 7,
}];
diff --git a/Libraries/LibWeb/Rust/src/css/style/input_types.rs b/Libraries/LibWeb/Rust/src/css/style/input_types.rs
index 1698b0e1d75..d069f69130f 100644
--- a/Libraries/LibWeb/Rust/src/css/style/input_types.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/input_types.rs
@@ -15,9 +15,7 @@ use std::collections::BTreeSet;
#[cfg(test)]
use super::index::FeatureValue;
use super::index::LocalFeatureKey;
-use super::index::StyleAtomID;
use super::instrumentation::Counter;
-use super::pipeline::rule_store::DeclarationBlockID;
use super::tree::StyleNodeID;
use super::tree::TreeScopeID;
@@ -133,13 +131,10 @@ pub enum InputKey {
TreeRelations(StyleNodeID),
LocalFeature(StyleNodeID, LocalFeatureKey),
State(StyleNodeID, StateFact),
- ElementDeclaration(StyleNodeID, ElementDeclarationKind),
/// A non-selector style input owned by the element changed. This is an edge-triggered action,
/// not retained fact state; its value says only which reaction is pending. A test records one directly.
#[cfg(test)]
ElementStyleInput(StyleNodeID),
- /// A registration made through `CSS.registerProperty()`, which has no stylesheet rule identity.
- CustomPropertyRegistration(StyleAtomID),
}
pub const STYLE_REACTION_PUBLISHED_STYLE: u8 = 1 << 0;
@@ -167,26 +162,18 @@ impl InputKey {
Self::TreeRelations(..) => Some(Counter::TreeDeltas),
Self::LocalFeature(..) => Some(Counter::LocalFeatureDeltas),
Self::State(..) => Some(Counter::StateDeltas),
- Self::ElementDeclaration(..) => Some(Counter::ElementDeclarationDeltas),
#[cfg(test)]
Self::ElementStyleInput(..) => None,
- Self::CustomPropertyRegistration(..) => Some(Counter::ProgramDeltas),
}
}
}
-/// The value of an input on one side of a mutation.
+/// The new value of an input a test records directly.
+#[cfg(test)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum InputValue {
- /// A local fact, which the host writes into the projection rather than records; a test records one directly.
- #[cfg(test)]
Feature(FeatureValue),
- /// `None` means no declaration block of that kind exists on that side.
- ElementDeclaration(Option<DeclarationBlockID>),
- #[cfg(test)]
ElementStyleInput { reaction: u8, inherited_style_groups: u8 },
- /// Whether a custom property registration is pending.
- Flag(bool),
}
/// An element style input's pending reaction, and the inherited style groups it names.
diff --git a/Libraries/LibWeb/Rust/src/css/style/inputs.rs b/Libraries/LibWeb/Rust/src/css/style/inputs.rs
index a84ba69903e..aefa7b2f35d 100644
--- a/Libraries/LibWeb/Rust/src/css/style/inputs.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/inputs.rs
@@ -426,21 +426,6 @@ impl RetainedState {
&self.tested_attribute_names
}
- /// Apply an accepted input to the authoritative fact arrangement.
- ///
- /// A fact exists in the store exactly because a mutation published it, which is what lets the
- /// evaluator distinguish "this element has no such class" from "nothing ever told me about this
- /// element".
- pub(super) fn apply_to_facts_without_settling(&mut self, key: InputKey, new: InputValue) {
- match (key, new) {
- #[cfg(test)]
- (InputKey::LocalFeature(node, feature), InputValue::Feature(value)) => {
- self.write_projection_for_test(|writes| writes.apply_feature(node, feature, value));
- }
- _ => {}
- }
- }
-
/// Write the projection as a test's host, publishing the writes to it at once and counting them.
#[cfg(test)]
pub(super) fn write_projection_for_test<R>(&mut self, write: impl FnOnce(&mut ProjectionWrites<'_>) -> R) -> R {
@@ -2094,50 +2079,6 @@ impl StyleEngine {
self.retained.projection.arrival_is_pending(node)
}
- /// Count one input, and note it for the next transaction where the projection holds no row
- /// that says it: an element's facts and relations are written into the projection, whose
- /// changes say them.
- pub(super) fn record(&mut self, key: InputKey, old: InputValue, new: InputValue) {
- let counters = &self.retained.counters;
- counters.bump(Counter::RawMutationRecords);
- if let Some(counter) = key.counter() {
- counters.bump(counter);
- }
- match (key, new) {
- (InputKey::TreeRelations(_), _) => {}
- (InputKey::LocalFeature(node, _) | InputKey::State(node, _), _) => {
- // Every fact of an arriving element is said by its arrival.
- if self.node_arrival_is_pending(node) {
- counters.bump(Counter::ArrivingNodeFactsFolded);
- }
- }
- (InputKey::ElementDeclaration(node, _), _) => {
- if old != new {
- self.host.element_inputs.note_declaration(node);
- }
- }
- #[cfg(test)]
- (
- InputKey::ElementStyleInput(node),
- InputValue::ElementStyleInput {
- reaction,
- inherited_style_groups,
- },
- ) => self.host.element_inputs.note_style_input(
- node,
- ElementStyleInput {
- reaction,
- inherited_style_groups,
- },
- ),
- #[cfg(test)]
- (InputKey::ElementStyleInput(_), _) => unreachable!("an element style input carries its reaction"),
- // A registration made through `CSS.registerProperty()` moves how the elements declaring
- // or reading its name compute, which the transaction taking the registry in finds.
- (InputKey::CustomPropertyRegistration(_), _) => self.host.program_staging.note_registration_change(),
- }
- }
-
#[cfg(test)]
pub(super) fn stage_first_child(&mut self, parent: StyleNodeID, child: Option<StyleNodeID>) {
self.retained
@@ -2348,9 +2289,37 @@ impl StyleEngine {
}
}
- pub fn record_input(&mut self, key: InputKey, old: InputValue, new: InputValue) {
- self.record(key, old, new);
- self.apply_to_facts_without_settling(key, new);
+ #[cfg(test)]
+ pub fn record_input(&mut self, key: InputKey, new: InputValue) {
+ let counters = &self.retained.counters;
+ counters.bump(Counter::RawMutationRecords);
+ if let Some(counter) = key.counter() {
+ counters.bump(counter);
+ }
+ match (key, new) {
+ (InputKey::LocalFeature(node, feature), InputValue::Feature(value)) => {
+ // Every fact of an arriving element is said by its arrival.
+ if self.node_arrival_is_pending(node) {
+ self.retained.counters.bump(Counter::ArrivingNodeFactsFolded);
+ }
+ self.retained
+ .write_projection_for_test(|writes| writes.apply_feature(node, feature, value));
+ }
+ (
+ InputKey::ElementStyleInput(node),
+ InputValue::ElementStyleInput {
+ reaction,
+ inherited_style_groups,
+ },
+ ) => self.host.element_inputs.note_style_input(
+ node,
+ ElementStyleInput {
+ reaction,
+ inherited_style_groups,
+ },
+ ),
+ _ => {}
+ }
}
/// Attach a compiled program at the end of a scope's sheet order.
@@ -2434,12 +2403,12 @@ impl StyleEngine {
/// Record a registration made through `CSS.registerProperty()`. Stylesheet registrations are
/// already represented by their `@property` rule's program input.
- pub fn record_custom_property_registration_change(&mut self, name: StyleAtomID) {
- self.record_input(
- InputKey::CustomPropertyRegistration(name),
- InputValue::Flag(false),
- InputValue::Flag(true),
- );
+ pub fn record_custom_property_registration_change(&mut self, _name: StyleAtomID) {
+ self.retained.counters.bump(Counter::RawMutationRecords);
+ self.retained.counters.bump(Counter::ProgramDeltas);
+ // A registration made through `CSS.registerProperty()` moves how the elements declaring
+ // or reading its name compute, which the transaction taking the registry in finds.
+ self.host.program_staging.note_registration_change();
}
/// Record the shadow parts an element exposes, each with the shadow host it is exposed to.
diff --git a/Libraries/LibWeb/Rust/src/css/style/mod.rs b/Libraries/LibWeb/Rust/src/css/style/mod.rs
index 9bdb446930d..8c8658bc86c 100644
--- a/Libraries/LibWeb/Rust/src/css/style/mod.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/mod.rs
@@ -175,7 +175,9 @@ use index::LocalFeatureKey;
use index::StyleAtomID;
use input_types::ElementDeclarationKind;
use input_types::ElementStyleInput;
+#[cfg(test)]
use input_types::InputKey;
+#[cfg(test)]
use input_types::InputValue;
use input_types::PendingElementInputs;
use input_types::StateFact;
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/differential_tests.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/differential_tests.rs
index f8df778bbc7..c0b42e808d5 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/differential_tests.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/differential_tests.rs
@@ -321,7 +321,6 @@ impl Workload {
let tag = atom(&mut engine, tag_name(node));
engine.record_input(
InputKey::LocalFeature(node, LocalFeatureKey::TagName),
- InputValue::Feature(FeatureValue::Absent),
InputValue::Feature(FeatureValue::Atom(tag)),
);
for _ in 0..rng.under(3) {
@@ -332,7 +331,6 @@ impl Workload {
classes[index].push(class);
engine.record_input(
InputKey::LocalFeature(node, LocalFeatureKey::Class(class_atoms[class])),
- InputValue::Feature(FeatureValue::Absent),
InputValue::Feature(FeatureValue::Present),
);
}
@@ -415,7 +413,6 @@ impl Workload {
};
self.engine.record_input(
InputKey::LocalFeature(node, LocalFeatureKey::Class(self.class_atoms[class])),
- InputValue::Feature(old),
InputValue::Feature(new),
);
format!("toggle {node:?} class{class}: {old:?} -> {new:?}")
@@ -1504,7 +1501,6 @@ fn an_input_no_rule_tests_restyles_nothing_and_one_a_rule_tests_restyles() {
// An id is tested as the value it had and the value it has.
engine.record_input(
InputKey::LocalFeature(nodes[1], LocalFeatureKey::Id),
- InputValue::Feature(FeatureValue::Atom(unnamed)),
InputValue::Feature(FeatureValue::Atom(named)),
);
run_style_update(&mut engine, nodes[0]);
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/test_support.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/test_support.rs
index 19efdcf2882..1d45e56290e 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/test_support.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/test_support.rs
@@ -126,7 +126,6 @@ pub(super) fn relations(
pub(super) fn add_feature(engine: &mut StyleEngine, node: StyleNodeID, feature: LocalFeatureKey) {
engine.record_input(
InputKey::LocalFeature(node, feature),
- InputValue::Feature(FeatureValue::Absent),
InputValue::Feature(FeatureValue::Present),
);
}
@@ -134,7 +133,6 @@ pub(super) fn add_feature(engine: &mut StyleEngine, node: StyleNodeID, feature:
pub(super) fn remove_feature(engine: &mut StyleEngine, node: StyleNodeID, feature: LocalFeatureKey) {
engine.record_input(
InputKey::LocalFeature(node, feature),
- InputValue::Feature(FeatureValue::Present),
InputValue::Feature(FeatureValue::Absent),
);
}
@@ -147,7 +145,6 @@ pub(super) fn set_atom_feature(
) {
engine.record_input(
InputKey::LocalFeature(node, feature),
- InputValue::Feature(FeatureValue::Absent),
InputValue::Feature(FeatureValue::Atom(atom)),
);
}
diff --git a/Libraries/LibWeb/Rust/src/css/style/tests.rs b/Libraries/LibWeb/Rust/src/css/style/tests.rs
index 48e5215e37c..3f6bc95aac3 100644
--- a/Libraries/LibWeb/Rust/src/css/style/tests.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/tests.rs
@@ -72,7 +72,6 @@ fn native_declaration_publication_reuses_values_and_observes_live_mutation() {
fn add_feature(engine: &mut StyleEngine, node: StyleNodeID, feature: LocalFeatureKey) {
engine.record_input(
InputKey::LocalFeature(node, feature),
- InputValue::Feature(FeatureValue::Absent),
InputValue::Feature(FeatureValue::Present),
);
}
@@ -80,7 +79,6 @@ fn add_feature(engine: &mut StyleEngine, node: StyleNodeID, feature: LocalFeatur
fn set_atom_feature(engine: &mut StyleEngine, node: StyleNodeID, feature: LocalFeatureKey, atom: StyleAtomID) {
engine.record_input(
InputKey::LocalFeature(node, feature),
- InputValue::Feature(FeatureValue::Absent),
InputValue::Feature(FeatureValue::Atom(atom)),
);
}
@@ -605,10 +603,6 @@ fn a_departed_node_routes_from_retained_facts_without_being_published() {
engine.record_input(
InputKey::ElementStyleInput(nodes[3]),
- InputValue::ElementStyleInput {
- reaction: 0,
- inherited_style_groups: 0,
- },
InputValue::ElementStyleInput {
reaction: input_types::STYLE_REACTION_RECOMPUTE_STYLE,
inherited_style_groups: 0,
@@ -640,10 +634,6 @@ fn a_shadow_root_routes_without_being_published_as_a_style_output() {
engine.record_input(
InputKey::ElementStyleInput(shadow_root),
- InputValue::ElementStyleInput {
- reaction: 0,
- inherited_style_groups: 0,
- },
InputValue::ElementStyleInput {
reaction: input_types::STYLE_REACTION_RECOMPUTE_STYLE,
inherited_style_groups: 0,