Skip to content

Truly independent web browser

LibWeb: Drive an element's values through its writer in place

Andreas Kling2e316d094d8f
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs
index 2b2167c4300..5873944bf17 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/compute.rs
@@ -151,16 +151,15 @@ impl RetainedState {
let mut font_scratch = drive::FontDriveScratch::default();
// The initial values compute from nothing: from the default groups, which hold no values.
crate::css::computed_values::with_default_seed(&self.process_style.default_groups, |seed| {
- let writer = GroupValuesWriter::seeded_for_child(
+ let mut writer = GroupValuesWriter::seeded_for_child(
seed,
seed,
std::iter::empty(),
crate::css::computed_longhand_table::LonghandTableFlags::empty(),
0,
);
- match self.engine_full_drive(subject, writer, &store, &inputs, &mut font_scratch) {
+ match self.engine_full_drive(subject, &mut writer, &store, &inputs, &mut font_scratch) {
Ok(drive::DrivenValues {
- writer,
length,
font: Some(font),
}) => {
@@ -235,7 +234,7 @@ impl RetainedState {
let mut font_scratch = drive::FontDriveScratch::default();
let held = shared.values();
let seed = crate::css::computed_values::GroupSeed::new(shared.seed_groups(), &held.value_facts);
- let writer = GroupValuesWriter::seeded_for_child(
+ let mut writer = GroupValuesWriter::seeded_for_child(
seed,
seed,
std::iter::empty(),
@@ -246,18 +245,17 @@ impl RetainedState {
let driven = self.engine_drive_with(
self,
subject,
- writer,
+ &mut writer,
Some(&selected),
&store,
&inputs,
&mut font_scratch,
);
- let (writer, length, font) = match driven {
+ let (length, font) = match driven {
Ok(drive::DrivenValues {
- writer,
length,
font: Some(font),
- }) => (writer, length, font),
+ }) => (length, font),
Err(Unanswered::Suspended(Suspension::Font)) => {
return Err(Some(Box::new(font_scratch.take_suspended_request())));
}
@@ -795,7 +793,7 @@ impl RetainedState {
};
// A container-relative length never computes directly, so only a drive resolves one.
let mut container_units = 0;
- let (mut writer, length, font, author_disables_native_appearance) = if runs_drive {
+ let (length, font, author_disables_native_appearance) = if runs_drive {
let store = WinnerStore::new(
winners
.iter()
@@ -847,7 +845,7 @@ impl RetainedState {
let driven = self.engine_drive_with(
records,
subject,
- writer,
+ &mut writer,
(!drives_everything).then_some(&selected[..]),
&store,
&inputs,
@@ -856,11 +854,7 @@ impl RetainedState {
if matches!(driven, Err(Unanswered::Suspended(Suspension::Font))) {
*suspended_font = Some(font_scratch.take_suspended_request());
}
- let drive::DrivenValues {
- mut writer,
- length,
- font,
- } = driven?;
+ let drive::DrivenValues { length, font } = driven?;
let font = font.expect("the style engine answers every row");
let scheme = u8::try_from(writer.effective_color_scheme()).ok();
// A drive of every longhand computed the winners that compute directly too.
@@ -883,7 +877,7 @@ impl RetainedState {
}
let author_disables_native_appearance = !appearance_is_none(&writer)
&& crate::css::style_compute::has_author_value_disabling_native_appearance(&store.view(self));
- (writer, length, Some(font), author_disables_native_appearance)
+ (length, Some(font), author_disables_native_appearance)
} else {
// https://drafts.csswg.org/css-fonts/#font-size-prop
// NB: The document element's font resolves against the document's initial font, as in
@@ -960,7 +954,7 @@ impl RetainedState {
| crate::css::cascaded_properties::CascadeOrigin::AuthorPresentationalHint
)
});
- (writer, length, font, author_disables_native_appearance)
+ (length, font, author_disables_native_appearance)
};
writer.set_native_appearance_disabled(author_disables_native_appearance);
let required_moved = crate::css::style_compute::REQUIRED_DRIVER_INPUTS
diff --git a/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs b/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs
index 3ded5300f72..1bbcd681b04 100644
--- a/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/pipeline/drive.rs
@@ -71,8 +71,7 @@ pub(in crate::css::style) enum MonospaceRecascade {
/// Driven values, with the length context they were driven against and the font a full drive
/// resolved.
-pub(in crate::css::style) struct DrivenValues<'a> {
- pub(in crate::css::style) writer: GroupValuesWriter<'a>,
+pub(in crate::css::style) struct DrivenValues {
pub(in crate::css::style) length: crate::css::style_compute::FfiLengthResolutionContext,
pub(in crate::css::style) font: Option<crate::css::table_group_builder::FfiFontGroupBuildInputs>,
}
@@ -416,14 +415,14 @@ impl RetainedState {
/// transformation reads. Root-input preparation finishes only the font and line-height
/// phases and preserves them for completion.
#[allow(clippy::too_many_arguments, clippy::too_many_lines)]
- pub(in crate::css::style) fn engine_full_drive<'a>(
+ pub(in crate::css::style) fn engine_full_drive(
&self,
subject: DriveSubject,
- writer: GroupValuesWriter<'a>,
+ writer: &mut GroupValuesWriter<'_>,
store: &WinnerStore,
inputs: &bridge::FfiDocumentStyleComputationInputs,
font_scratch: &mut FontDriveScratch,
- ) -> Drive<DrivenValues<'a>> {
+ ) -> Drive<DrivenValues> {
self.engine_drive_with(self, subject, writer, None, store, inputs, font_scratch)
}
@@ -432,16 +431,16 @@ impl RetainedState {
/// only those, beside the inputs every drive evaluates, and keeps the writer's values for the
/// rest.
#[allow(clippy::too_many_arguments, clippy::too_many_lines)]
- pub(in crate::css::style) fn engine_drive_with<'a>(
+ pub(in crate::css::style) fn engine_drive_with(
&self,
records: &impl DriveRecords,
subject: DriveSubject,
- writer: GroupValuesWriter<'a>,
+ writer: &mut GroupValuesWriter<'_>,
selected: Option<&[u64]>,
store: &WinnerStore,
inputs: &bridge::FfiDocumentStyleComputationInputs,
font_scratch: &mut FontDriveScratch,
- ) -> Drive<DrivenValues<'a>> {
+ ) -> Drive<DrivenValues> {
let random_base_values = store
.drive_random_base_values(self, subject.target.node())
.expect("a random function's base values are drawn before the row is driven");
@@ -665,7 +664,7 @@ impl RetainedState {
if !resuming {
self.counters.bump(Counter::EngineFullDrivesStarted);
}
- let (mut writer, mut results, mut effective_color_scheme) = match resumed {
+ let (mut results, mut effective_color_scheme) = match resumed {
Some(pending) => {
resolved_viewport_relative_length = pending.resolved_viewport_relative_length;
if !pending.root_font_complete {
@@ -675,9 +674,10 @@ impl RetainedState {
u64::from(pending.results.longhand_evaluations),
);
}
- (pending.writer, pending.results, pending.effective_color_scheme)
+ *writer = pending.writer;
+ (pending.results, pending.effective_color_scheme)
}
- None => (writer, empty_longhand_driver_results(), -1),
+ None => (empty_longhand_driver_results(), -1),
};
let drive = |counters: &Counters,
writer: &mut GroupValuesWriter<'_>,
@@ -732,7 +732,7 @@ impl RetainedState {
}
drive(
&self.counters,
- &mut writer,
+ writer,
&mut results,
&mut effective_color_scheme,
LONGHAND_DRIVE_PHASE_FONT,
@@ -759,7 +759,7 @@ impl RetainedState {
root_font_complete: false,
color_scheme_complete: false,
recascaded_font_size,
- writer: writer.detached(),
+ writer: writer.clone().detached(),
results,
effective_color_scheme,
resolved_viewport_relative_length,
@@ -798,7 +798,7 @@ impl RetainedState {
if !root_font_complete {
drive(
&self.counters,
- &mut writer,
+ writer,
&mut results,
&mut effective_color_scheme,
LONGHAND_DRIVE_PHASE_LINE_HEIGHT,
@@ -812,7 +812,7 @@ impl RetainedState {
if !color_scheme_complete {
drive(
&self.counters,
- &mut writer,
+ writer,
&mut results,
&mut effective_color_scheme,
LONGHAND_DRIVE_PHASE_COLOR_SCHEME,
@@ -849,7 +849,7 @@ impl RetainedState {
};
drive(
&self.counters,
- &mut writer,
+ writer,
&mut results,
&mut effective_color_scheme,
LONGHAND_DRIVE_PHASE_REMAINING,
@@ -868,7 +868,6 @@ impl RetainedState {
..remaining_length
};
Ok(DrivenValues {
- writer,
length,
font: Some(font),
})