stylo: Introduce ComputedValuesInner

This commit is contained in:
Manish Goregaokar 2017-07-17 11:41:44 -07:00 committed by Manish Goregaokar
parent 5d78743037
commit 04b0ae64f2
6 changed files with 125 additions and 73 deletions

View file

@ -13,7 +13,7 @@ pub type ServoWritingMode = ::logical_geometry::WritingMode;
pub type ServoFontComputationData = ::properties::FontComputationData; pub type ServoFontComputationData = ::properties::FontComputationData;
pub type ServoCustomPropertiesMap = Option<::stylearc::Arc<::custom_properties::CustomPropertiesMap>>; pub type ServoCustomPropertiesMap = Option<::stylearc::Arc<::custom_properties::CustomPropertiesMap>>;
pub type ServoRuleNode = Option<::rule_tree::StrongRuleNode>; pub type ServoRuleNode = Option<::rule_tree::StrongRuleNode>;
pub type ServoVisitedStyle = Option<::stylearc::Arc<ServoComputedValues2>>; pub type ServoVisitedStyle = Option<::stylearc::Arc<::properties::ComputedValues>>;
pub type ServoComputedValueFlags = ::properties::computed_value_flags::ComputedValueFlags; pub type ServoComputedValueFlags = ::properties::computed_value_flags::ComputedValueFlags;
pub type ServoRawOffsetArc<T> = ::stylearc::RawOffsetArc<T>; pub type ServoRawOffsetArc<T> = ::stylearc::RawOffsetArc<T>;

View file

@ -13,7 +13,7 @@ pub type ServoWritingMode = ::logical_geometry::WritingMode;
pub type ServoFontComputationData = ::properties::FontComputationData; pub type ServoFontComputationData = ::properties::FontComputationData;
pub type ServoCustomPropertiesMap = Option<::stylearc::Arc<::custom_properties::CustomPropertiesMap>>; pub type ServoCustomPropertiesMap = Option<::stylearc::Arc<::custom_properties::CustomPropertiesMap>>;
pub type ServoRuleNode = Option<::rule_tree::StrongRuleNode>; pub type ServoRuleNode = Option<::rule_tree::StrongRuleNode>;
pub type ServoVisitedStyle = Option<::stylearc::Arc<ServoComputedValues2>>; pub type ServoVisitedStyle = Option<::stylearc::Arc<::properties::ComputedValues>>;
pub type ServoComputedValueFlags = ::properties::computed_value_flags::ComputedValueFlags; pub type ServoComputedValueFlags = ::properties::computed_value_flags::ComputedValueFlags;
pub type ServoRawOffsetArc<T> = ::stylearc::RawOffsetArc<T>; pub type ServoRawOffsetArc<T> = ::stylearc::RawOffsetArc<T>;

View file

@ -59,9 +59,8 @@ use properties::{longhands, FontComputationData, Importance, LonghandId};
use properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyDeclarationId}; use properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyDeclarationId};
use rule_tree::StrongRuleNode; use rule_tree::StrongRuleNode;
use std::mem::{forget, transmute, zeroed}; use std::mem::{forget, transmute, zeroed};
use std::ptr; use std::{cmp, ops, ptr};
use stylearc::{Arc, RawOffsetArc}; use stylearc::{Arc, RawOffsetArc};
use std::cmp;
use values::{Auto, CustomIdent, Either, KeyframesName}; use values::{Auto, CustomIdent, Either, KeyframesName};
use values::computed::ToComputedValue; use values::computed::ToComputedValue;
use values::computed::effects::{BoxShadow, Filter, SimpleShadow}; use values::computed::effects::{BoxShadow, Filter, SimpleShadow};
@ -75,11 +74,16 @@ pub mod style_structs {
} }
pub use ::gecko_bindings::structs::mozilla::ServoComputedValues2 as ComputedValues; pub use ::gecko_bindings::structs::mozilla::ServoComputedValues2 as ComputedValuesInner;
impl Clone for ComputedValues { #[derive(Clone, Debug)]
pub struct ComputedValues {
pub inner: ComputedValuesInner
}
impl Clone for ComputedValuesInner {
fn clone(&self) -> Self { fn clone(&self) -> Self {
ComputedValues { ComputedValuesInner {
% for style_struct in data.style_structs: % for style_struct in data.style_structs:
${style_struct.gecko_name}: self.${style_struct.gecko_name}.clone(), ${style_struct.gecko_name}: self.${style_struct.gecko_name}.clone(),
% endfor % endfor
@ -105,32 +109,51 @@ impl ComputedValues {
% endfor % endfor
) -> Self { ) -> Self {
ComputedValues { ComputedValues {
custom_properties, inner: ComputedValuesInner {
writing_mode, custom_properties: custom_properties,
writing_mode: writing_mode,
font_computation_data: FontComputationData::new(font_size_keyword), font_computation_data: FontComputationData::new(font_size_keyword),
flags, rules: rules,
rules,
visited_style: visited_style, visited_style: visited_style,
flags: flags,
% for style_struct in data.style_structs: % for style_struct in data.style_structs:
${style_struct.gecko_name}: Arc::into_raw_offset(${style_struct.ident}), ${style_struct.gecko_name}: Arc::into_raw_offset(${style_struct.ident}),
% endfor % endfor
} }
} }
}
pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> { pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
Arc::new(ComputedValues { Arc::new(ComputedValues {
inner: ComputedValuesInner {
custom_properties: None, custom_properties: None,
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
font_computation_data: FontComputationData::default_values(), font_computation_data: FontComputationData::default_values(),
flags: ComputedValueFlags::empty(),
rules: None, rules: None,
visited_style: None, visited_style: None,
flags: ComputedValueFlags::empty(),
% for style_struct in data.style_structs: % for style_struct in data.style_structs:
${style_struct.gecko_name}: Arc::into_raw_offset(style_structs::${style_struct.name}::default(pres_context)), ${style_struct.gecko_name}: Arc::into_raw_offset(style_structs::${style_struct.name}::default(pres_context)),
% endfor % endfor
}
}) })
} }
}
impl ops::Deref for ComputedValues {
type Target = ComputedValuesInner;
fn deref(&self) -> &ComputedValuesInner {
&self.inner
}
}
impl ops::DerefMut for ComputedValues {
fn deref_mut(&mut self) -> &mut ComputedValuesInner {
&mut self.inner
}
}
impl ComputedValuesInner {
#[inline] #[inline]
pub fn is_display_contents(&self) -> bool { pub fn is_display_contents(&self) -> bool {
self.get_box().clone_display() == longhands::display::computed_value::T::contents self.get_box().clone_display() == longhands::display::computed_value::T::contents

View file

@ -12,9 +12,7 @@
use std::borrow::Cow; use std::borrow::Cow;
use std::collections::HashSet; use std::collections::HashSet;
use std::fmt; use std::{fmt, mem, ops};
use std::mem;
use std::ops::Deref;
use stylearc::{Arc, UniqueArc}; use stylearc::{Arc, UniqueArc};
use app_units::Au; use app_units::Au;
@ -113,7 +111,7 @@ pub struct FontComputationData {
} }
impl FontComputationData{ impl FontComputationData {
/// Assigns values for variables in struct FontComputationData /// Assigns values for variables in struct FontComputationData
pub fn new(font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>) -> Self { pub fn new(font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>) -> Self {
FontComputationData { FontComputationData {
@ -1875,19 +1873,11 @@ pub mod style_structs {
#[cfg(feature = "gecko")] #[cfg(feature = "gecko")]
pub use gecko_properties::ComputedValues; pub use gecko_properties::ComputedValues;
/// A legacy alias for a servo-version of ComputedValues. Should go away soon.
#[cfg(feature = "servo")]
pub type ServoComputedValues = ComputedValues;
/// The struct that Servo uses to represent computed values.
///
/// This struct contains an immutable atomically-reference-counted pointer to
/// every kind of style struct.
///
/// When needed, the structs may be copied in order to get mutated.
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
#[cfg_attr(feature = "servo", derive(Clone, Debug))] #[cfg_attr(feature = "servo", derive(Clone, Debug))]
pub struct ComputedValues { /// Actual data of ComputedValues, to match up with Gecko
pub struct ComputedValuesInner {
% for style_struct in data.active_style_structs(): % for style_struct in data.active_style_structs():
${style_struct.ident}: Arc<style_structs::${style_struct.name}>, ${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor % endfor
@ -1911,6 +1901,24 @@ pub struct ComputedValues {
visited_style: Option<Arc<ComputedValues>>, visited_style: Option<Arc<ComputedValues>>,
} }
/// The struct that Servo uses to represent computed values.
///
/// This struct contains an immutable atomically-reference-counted pointer to
/// every kind of style struct.
///
/// When needed, the structs may be copied in order to get mutated.
#[cfg(feature = "servo")]
#[cfg_attr(feature = "servo", derive(Clone, Debug))]
pub struct ComputedValues {
/// The actual computed values
///
/// In Gecko the outer ComputedValues is actually a style context,
/// whereas ComputedValuesInner is the core set of computed values.
///
/// We maintain this distinction in servo to reduce the amount of special casing.
pub inner: ComputedValuesInner,
}
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
impl ComputedValues { impl ComputedValues {
/// Construct a `ComputedValues` instance. /// Construct a `ComputedValues` instance.
@ -1925,23 +1933,42 @@ impl ComputedValues {
${style_struct.ident}: Arc<style_structs::${style_struct.name}>, ${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor % endfor
) -> Self { ) -> Self {
let font_computation_data = FontComputationData::new(font_size_keyword);
ComputedValues { ComputedValues {
custom_properties, inner: ComputedValuesInner {
writing_mode, custom_properties: custom_properties,
font_computation_data, writing_mode: writing_mode,
flags, font_computation_data: FontComputationData::new(font_size_keyword),
rules, rules: rules,
visited_style, visited_style: visited_style,
flags: flags,
% for style_struct in data.active_style_structs(): % for style_struct in data.active_style_structs():
${style_struct.ident}, ${style_struct.ident}: ${style_struct.ident},
% endfor % endfor
} }
} }
}
/// Get the initial computed values. /// Get the initial computed values.
pub fn initial_values() -> &'static Self { &*INITIAL_SERVO_VALUES } pub fn initial_values() -> &'static Self { &*INITIAL_SERVO_VALUES }
}
#[cfg(feature = "servo")]
impl ops::Deref for ComputedValues {
type Target = ComputedValuesInner;
fn deref(&self) -> &ComputedValuesInner {
&self.inner
}
}
#[cfg(feature = "servo")]
impl ops::DerefMut for ComputedValues {
fn deref_mut(&mut self) -> &mut ComputedValuesInner {
&mut self.inner
}
}
#[cfg(feature = "servo")]
impl ComputedValuesInner {
% for style_struct in data.active_style_structs(): % for style_struct in data.active_style_structs():
/// Clone the ${style_struct.name} struct. /// Clone the ${style_struct.name} struct.
#[inline] #[inline]
@ -2372,7 +2399,7 @@ impl<'a, T: 'a> StyleStructRef<'a, T>
} }
} }
impl<'a, T: 'a> Deref for StyleStructRef<'a, T> { impl<'a, T: 'a> ops::Deref for StyleStructRef<'a, T> {
type Target = T; type Target = T;
fn deref(&self) -> &T { fn deref(&self) -> &T {
@ -2559,12 +2586,13 @@ pub use self::lazy_static_module::INITIAL_SERVO_VALUES;
mod lazy_static_module { mod lazy_static_module {
use logical_geometry::WritingMode; use logical_geometry::WritingMode;
use stylearc::Arc; use stylearc::Arc;
use super::{ComputedValues, longhands, style_structs, FontComputationData}; use super::{ComputedValues, ComputedValuesInner, longhands, style_structs, FontComputationData};
use super::computed_value_flags::ComputedValueFlags; use super::computed_value_flags::ComputedValueFlags;
/// The initial values for all style structs as defined by the specification. /// The initial values for all style structs as defined by the specification.
lazy_static! { lazy_static! {
pub static ref INITIAL_SERVO_VALUES: ComputedValues = ComputedValues { pub static ref INITIAL_SERVO_VALUES: ComputedValues = ComputedValues {
inner: ComputedValuesInner {
% for style_struct in data.active_style_structs(): % for style_struct in data.active_style_structs():
${style_struct.ident}: Arc::new(style_structs::${style_struct.name} { ${style_struct.ident}: Arc::new(style_structs::${style_struct.name} {
% for longhand in style_struct.longhands: % for longhand in style_struct.longhands:
@ -2577,10 +2605,11 @@ mod lazy_static_module {
% endfor % endfor
custom_properties: None, custom_properties: None,
writing_mode: WritingMode::empty(), writing_mode: WritingMode::empty(),
flags: ComputedValueFlags::empty(),
font_computation_data: FontComputationData::default_values(), font_computation_data: FontComputationData::default_values(),
rules: None, rules: None,
visited_style: None, visited_style: None,
flags: ComputedValueFlags::empty(),
}
}; };
} }
} }

View file

@ -38,7 +38,7 @@ pub use gecko::restyle_damage::GeckoRestyleDamage as RestyleDamage;
/// A type that represents the previous computed values needed for restyle /// A type that represents the previous computed values needed for restyle
/// damage calculation. /// damage calculation.
#[cfg(feature = "servo")] #[cfg(feature = "servo")]
pub type PreExistingComputedValues = ::properties::ServoComputedValues; pub type PreExistingComputedValues = ::properties::ComputedValues;
/// A type that represents the previous computed values needed for restyle /// A type that represents the previous computed values needed for restyle
/// damage calculation. /// damage calculation.

View file

@ -10,7 +10,7 @@
use computed_values::display; use computed_values::display;
use heapsize::HeapSizeOf; use heapsize::HeapSizeOf;
use matching::{StyleChange, StyleDifference}; use matching::{StyleChange, StyleDifference};
use properties::ServoComputedValues; use properties::ComputedValues;
use std::fmt; use std::fmt;
bitflags! { bitflags! {
@ -60,8 +60,8 @@ impl HeapSizeOf for ServoRestyleDamage {
impl ServoRestyleDamage { impl ServoRestyleDamage {
/// Compute the `StyleDifference` (including the appropriate restyle damage) /// Compute the `StyleDifference` (including the appropriate restyle damage)
/// for a given style change between `old` and `new`. /// for a given style change between `old` and `new`.
pub fn compute_style_difference(old: &ServoComputedValues, pub fn compute_style_difference(old: &ComputedValues,
new: &ServoComputedValues) new: &ComputedValues)
-> StyleDifference { -> StyleDifference {
let damage = compute_damage(old, new); let damage = compute_damage(old, new);
let change = if damage.is_empty() { StyleChange::Unchanged } else { StyleChange::Changed }; let change = if damage.is_empty() { StyleChange::Unchanged } else { StyleChange::Changed };
@ -182,11 +182,11 @@ macro_rules! add_if_not_equal(
}) })
); );
fn compute_damage(old: &ServoComputedValues, new: &ServoComputedValues) -> ServoRestyleDamage { fn compute_damage(old: &ComputedValues, new: &ComputedValues) -> ServoRestyleDamage {
let mut damage = ServoRestyleDamage::empty(); let mut damage = ServoRestyleDamage::empty();
// This should check every CSS property, as enumerated in the fields of // This should check every CSS property, as enumerated in the fields of
// http://doc.servo.org/style/properties/struct.ServoComputedValues.html // http://doc.servo.org/style/properties/struct.ComputedValues.html
// FIXME: Test somehow that every property is included. // FIXME: Test somehow that every property is included.