mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
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>
This commit is contained in:
parent
db83601b62
commit
a0dd2c1beb
24 changed files with 369 additions and 187 deletions
|
@ -8,7 +8,10 @@ use app_units::Au;
|
|||
use fonts::FontMetrics;
|
||||
use malloc_size_of_derive::MallocSizeOf;
|
||||
|
||||
use super::{InlineContainerState, InlineContainerStateFlags, inline_container_needs_strut};
|
||||
use super::{
|
||||
InlineContainerState, InlineContainerStateFlags, SharedInlineStyles,
|
||||
inline_container_needs_strut,
|
||||
};
|
||||
use crate::ContainingBlock;
|
||||
use crate::cell::ArcRefCell;
|
||||
use crate::context::LayoutContext;
|
||||
|
@ -20,6 +23,9 @@ use crate::style_ext::{LayoutStyle, PaddingBorderMargin};
|
|||
#[derive(Debug, MallocSizeOf)]
|
||||
pub(crate) struct InlineBox {
|
||||
pub base: LayoutBoxBase,
|
||||
/// The [`SharedInlineStyles`] for this [`InlineBox`] that are used to share styles
|
||||
/// with all [`super::TextRun`] children.
|
||||
pub(super) shared_inline_styles: SharedInlineStyles,
|
||||
/// The identifier of this inline box in the containing [`super::InlineFormattingContext`].
|
||||
pub(super) identifier: InlineBoxIdentifier,
|
||||
/// Whether or not this is the first instance of an [`InlineBox`] before a possible
|
||||
|
@ -37,6 +43,7 @@ impl InlineBox {
|
|||
pub(crate) fn new(info: &NodeAndStyleInfo) -> Self {
|
||||
Self {
|
||||
base: LayoutBoxBase::new(info.into(), info.style.clone()),
|
||||
shared_inline_styles: info.into(),
|
||||
// This will be assigned later, when the box is actually added to the IFC.
|
||||
identifier: InlineBoxIdentifier::default(),
|
||||
is_first_split: true,
|
||||
|
@ -48,6 +55,7 @@ impl InlineBox {
|
|||
pub(crate) fn split_around_block(&self) -> Self {
|
||||
Self {
|
||||
base: LayoutBoxBase::new(self.base.base_fragment_info, self.base.style.clone()),
|
||||
shared_inline_styles: self.shared_inline_styles.clone(),
|
||||
is_first_split: false,
|
||||
is_last_split: false,
|
||||
..*self
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue