style: Add a StyleBuilder struct to avoid refcount and atomic CAS during the cascade.

This should fix most of the complaints that caused
https://bugzilla.mozilla.org/show_bug.cgi?id=1360889 to be open, and also fix a
bunch of other FIXMEs across the style system.
This commit is contained in:
Emilio Cobos Álvarez 2017-04-30 13:59:10 +02:00
parent caa66a880a
commit 3b857f1c4e
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
11 changed files with 279 additions and 120 deletions

View file

@ -8,7 +8,9 @@ use context::QuirksMode;
use euclid::size::Size2D;
use font_metrics::FontMetricsProvider;
use media_queries::Device;
use properties::ComputedValues;
#[cfg(feature = "gecko")]
use properties;
use properties::{ComputedValues, StyleBuilder};
use std::fmt;
use style_traits::ToCss;
use super::{CSSFloat, CSSInteger, RGBA};
@ -53,10 +55,23 @@ pub struct Context<'a> {
/// isn't `contents`.
pub layout_parent_style: &'a ComputedValues,
/// Values access through this need to be in the properties "computed
/// Values accessed through this need to be in the properties "computed
/// early": color, text-decoration, font-size, display, position, float,
/// border-*-style, outline-style, font-family, writing-mode...
pub style: ComputedValues,
pub style: StyleBuilder<'a>,
/// A cached computed system font value, for use by gecko.
///
/// See properties/longhands/font.mako.rs
#[cfg(feature = "gecko")]
pub cached_system_font: Option<properties::longhands::system_font::ComputedSystemFont>,
/// A dummy option for servo so initializing a computed::Context isn't
/// painful.
///
/// TODO(emilio): Make constructors for Context, and drop this.
#[cfg(feature = "servo")]
pub cached_system_font: Option<()>,
/// A font metrics provider, used to access font metrics to implement
/// font-relative units.
@ -78,9 +93,9 @@ impl<'a> Context<'a> {
pub fn inherited_style(&self) -> &ComputedValues { &self.inherited_style }
/// The current style. Note that only "eager" properties should be accessed
/// from here, see the comment in the member.
pub fn style(&self) -> &ComputedValues { &self.style }
pub fn style(&self) -> &StyleBuilder { &self.style }
/// A mutable reference to the current style.
pub fn mutate_style(&mut self) -> &mut ComputedValues { &mut self.style }
pub fn mutate_style(&mut self) -> &mut StyleBuilder<'a> { &mut self.style }
}
/// A trait to represent the conversion between computed and specified values.