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 ServoCustomPropertiesMap = Option<::stylearc::Arc<::custom_properties::CustomPropertiesMap>>;
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 ServoRawOffsetArc<T> = ::stylearc::RawOffsetArc<T>;

View file

@ -13,7 +13,7 @@ pub type ServoWritingMode = ::logical_geometry::WritingMode;
pub type ServoFontComputationData = ::properties::FontComputationData;
pub type ServoCustomPropertiesMap = Option<::stylearc::Arc<::custom_properties::CustomPropertiesMap>>;
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 ServoRawOffsetArc<T> = ::stylearc::RawOffsetArc<T>;

View file

@ -59,9 +59,8 @@ use properties::{longhands, FontComputationData, Importance, LonghandId};
use properties::{PropertyDeclaration, PropertyDeclarationBlock, PropertyDeclarationId};
use rule_tree::StrongRuleNode;
use std::mem::{forget, transmute, zeroed};
use std::ptr;
use std::{cmp, ops, ptr};
use stylearc::{Arc, RawOffsetArc};
use std::cmp;
use values::{Auto, CustomIdent, Either, KeyframesName};
use values::computed::ToComputedValue;
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 {
ComputedValues {
ComputedValuesInner {
% for style_struct in data.style_structs:
${style_struct.gecko_name}: self.${style_struct.gecko_name}.clone(),
% endfor
@ -105,32 +109,51 @@ impl ComputedValues {
% endfor
) -> Self {
ComputedValues {
custom_properties,
writing_mode,
inner: ComputedValuesInner {
custom_properties: custom_properties,
writing_mode: writing_mode,
font_computation_data: FontComputationData::new(font_size_keyword),
flags,
rules,
rules: rules,
visited_style: visited_style,
flags: flags,
% for style_struct in data.style_structs:
${style_struct.gecko_name}: Arc::into_raw_offset(${style_struct.ident}),
% endfor
}
}
}
pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Arc<Self> {
Arc::new(ComputedValues {
inner: ComputedValuesInner {
custom_properties: None,
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
font_computation_data: FontComputationData::default_values(),
flags: ComputedValueFlags::empty(),
rules: None,
visited_style: None,
flags: ComputedValueFlags::empty(),
% for style_struct in data.style_structs:
${style_struct.gecko_name}: Arc::into_raw_offset(style_structs::${style_struct.name}::default(pres_context)),
% 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]
pub fn is_display_contents(&self) -> bool {
self.get_box().clone_display() == longhands::display::computed_value::T::contents

View file

@ -12,9 +12,7 @@
use std::borrow::Cow;
use std::collections::HashSet;
use std::fmt;
use std::mem;
use std::ops::Deref;
use std::{fmt, mem, ops};
use stylearc::{Arc, UniqueArc};
use app_units::Au;
@ -1875,19 +1873,11 @@ pub mod style_structs {
#[cfg(feature = "gecko")]
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_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():
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor
@ -1911,6 +1901,24 @@ pub struct 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")]
impl ComputedValues {
/// Construct a `ComputedValues` instance.
@ -1925,23 +1933,42 @@ impl ComputedValues {
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
% endfor
) -> Self {
let font_computation_data = FontComputationData::new(font_size_keyword);
ComputedValues {
custom_properties,
writing_mode,
font_computation_data,
flags,
rules,
visited_style,
inner: ComputedValuesInner {
custom_properties: custom_properties,
writing_mode: writing_mode,
font_computation_data: FontComputationData::new(font_size_keyword),
rules: rules,
visited_style: visited_style,
flags: flags,
% for style_struct in data.active_style_structs():
${style_struct.ident},
${style_struct.ident}: ${style_struct.ident},
% endfor
}
}
}
/// Get the initial computed 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():
/// Clone the ${style_struct.name} struct.
#[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;
fn deref(&self) -> &T {
@ -2559,12 +2586,13 @@ pub use self::lazy_static_module::INITIAL_SERVO_VALUES;
mod lazy_static_module {
use logical_geometry::WritingMode;
use stylearc::Arc;
use super::{ComputedValues, longhands, style_structs, FontComputationData};
use super::{ComputedValues, ComputedValuesInner, longhands, style_structs, FontComputationData};
use super::computed_value_flags::ComputedValueFlags;
/// The initial values for all style structs as defined by the specification.
lazy_static! {
pub static ref INITIAL_SERVO_VALUES: ComputedValues = ComputedValues {
inner: ComputedValuesInner {
% for style_struct in data.active_style_structs():
${style_struct.ident}: Arc::new(style_structs::${style_struct.name} {
% for longhand in style_struct.longhands:
@ -2577,10 +2605,11 @@ mod lazy_static_module {
% endfor
custom_properties: None,
writing_mode: WritingMode::empty(),
flags: ComputedValueFlags::empty(),
font_computation_data: FontComputationData::default_values(),
rules: 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
/// damage calculation.
#[cfg(feature = "servo")]
pub type PreExistingComputedValues = ::properties::ServoComputedValues;
pub type PreExistingComputedValues = ::properties::ComputedValues;
/// A type that represents the previous computed values needed for restyle
/// damage calculation.

View file

@ -10,7 +10,7 @@
use computed_values::display;
use heapsize::HeapSizeOf;
use matching::{StyleChange, StyleDifference};
use properties::ServoComputedValues;
use properties::ComputedValues;
use std::fmt;
bitflags! {
@ -60,8 +60,8 @@ impl HeapSizeOf for ServoRestyleDamage {
impl ServoRestyleDamage {
/// Compute the `StyleDifference` (including the appropriate restyle damage)
/// for a given style change between `old` and `new`.
pub fn compute_style_difference(old: &ServoComputedValues,
new: &ServoComputedValues)
pub fn compute_style_difference(old: &ComputedValues,
new: &ComputedValues)
-> StyleDifference {
let damage = compute_damage(old, new);
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();
// 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.