aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/lib.rs
diff options
context:
space:
mode:
authorMartin Robinson <mrobinson@igalia.com>2025-05-12 11:38:50 +0200
committerGitHub <noreply@github.com>2025-05-12 09:38:50 +0000
commita0dd2c1bebbc238d2fe36b1134acfbc842c1f084 (patch)
tree367a47983a81113a4c4988ff8a11cca6de6f007d /components/layout/lib.rs
parentdb83601b62b81965176e1e8272d5b434afeb0da6 (diff)
downloadservo-a0dd2c1bebbc238d2fe36b1134acfbc842c1f084.tar.gz
servo-a0dd2c1bebbc238d2fe36b1134acfbc842c1f084.zip
layout: Share styles to inline box children via `SharedInlineStyles` (#36896)
`TextRun`s use their parent style to render. Previously, these styles were cloned and stored directly in the box tree `TextRun` and resulting `TextFragment`s. This presents a problem for incremental layout. Wrapping the style in another layer of shared ownership and mutability will allow updating all `TextFragment`s during repaint-only incremental layout by simply updating the box tree styles of the original text parents. This adds a new set of borrows when accessing text styles, but also makes it so that during box tree block construction `InlineFormattingContext`s are created lazily and now `InlineFormattingContextBuilder::finish` consumes the builder, making the API make a bit more sense. This should also improve performance of box tree block construction slightly. Testing: This should not change observable behavior and thus is covered by existing WPT tests. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Oriol Brufau <obrufau@igalia.com>
Diffstat (limited to 'components/layout/lib.rs')
-rw-r--r--components/layout/lib.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/components/layout/lib.rs b/components/layout/lib.rs
index af7d432c4d8..cd992387277 100644
--- a/components/layout/lib.rs
+++ b/components/layout/lib.rs
@@ -38,6 +38,7 @@ pub use flow::BoxTree;
pub use fragment_tree::FragmentTree;
pub use layout_impl::LayoutFactoryImpl;
use malloc_size_of_derive::MallocSizeOf;
+use servo_arc::Arc as ServoArc;
use style::logical_geometry::WritingMode;
use style::properties::ComputedValues;
use style::values::computed::TextDecorationLine;
@@ -45,6 +46,16 @@ use style::values::computed::TextDecorationLine;
use crate::geom::{LogicalVec2, SizeConstraint};
use crate::style_ext::AspectRatio;
+/// At times, a style is "owned" by more than one layout object. For example, text
+/// fragments need a handle on their parent inline box's style. In order to make
+/// incremental layout easier to implement, another layer of shared ownership is added via
+/// [`SharedStyle`]. This allows updating the style in originating layout object and
+/// having all "depdendent" objects update automatically.
+///
+/// Note that this is not a cost-free data structure, so should only be
+/// used when necessary.
+pub(crate) type SharedStyle = ArcRefCell<ServoArc<ComputedValues>>;
+
/// Represents the set of constraints that we use when computing the min-content
/// and max-content inline sizes of an element.
pub(crate) struct ConstraintSpace {