mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
stylo: Use ComputedValuesInner instead of ComputedValues when we don't need it
This commit is contained in:
parent
04b0ae64f2
commit
808b1f509b
38 changed files with 302 additions and 316 deletions
|
@ -110,13 +110,13 @@ impl<'a> Iterator for PropertyDeclarationIterator<'a> {
|
|||
pub struct AnimationValueIterator<'a, 'cx, 'cx_a:'cx> {
|
||||
iter: Iter<'a, (PropertyDeclaration, Importance)>,
|
||||
context: &'cx mut Context<'cx_a>,
|
||||
default_values: &'a Arc<ComputedValues>,
|
||||
default_values: &'a ComputedValuesInner,
|
||||
}
|
||||
|
||||
impl<'a, 'cx, 'cx_a:'cx> AnimationValueIterator<'a, 'cx, 'cx_a> {
|
||||
fn new(declarations: &'a PropertyDeclarationBlock,
|
||||
context: &'cx mut Context<'cx_a>,
|
||||
default_values: &'a Arc<ComputedValues>) -> AnimationValueIterator<'a, 'cx, 'cx_a> {
|
||||
default_values: &'a ComputedValuesInner) -> AnimationValueIterator<'a, 'cx, 'cx_a> {
|
||||
AnimationValueIterator {
|
||||
iter: declarations.declarations().iter(),
|
||||
context: context,
|
||||
|
@ -204,7 +204,7 @@ impl PropertyDeclarationBlock {
|
|||
/// Return an iterator of (AnimatableLonghand, AnimationValue).
|
||||
pub fn to_animation_value_iter<'a, 'cx, 'cx_a:'cx>(&'a self,
|
||||
context: &'cx mut Context<'cx_a>,
|
||||
default_values: &'a Arc<ComputedValues>)
|
||||
default_values: &'a ComputedValuesInner)
|
||||
-> AnimationValueIterator<'a, 'cx, 'cx_a> {
|
||||
AnimationValueIterator::new(self, context, default_values)
|
||||
}
|
||||
|
|
|
@ -97,7 +97,7 @@ impl Clone for ComputedValuesInner {
|
|||
}
|
||||
}
|
||||
|
||||
impl ComputedValues {
|
||||
impl ComputedValuesInner {
|
||||
pub fn new(custom_properties: Option<Arc<CustomPropertiesMap>>,
|
||||
writing_mode: WritingMode,
|
||||
font_size_keyword: Option<(longhands::font_size::KeywordSize, f32)>,
|
||||
|
@ -108,24 +108,21 @@ impl ComputedValues {
|
|||
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
|
||||
% endfor
|
||||
) -> Self {
|
||||
ComputedValues {
|
||||
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.style_structs:
|
||||
${style_struct.gecko_name}: Arc::into_raw_offset(${style_struct.ident}),
|
||||
% endfor
|
||||
}
|
||||
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.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 {
|
||||
pub fn default_values(pres_context: RawGeckoPresContextBorrowed) -> Self {
|
||||
ComputedValuesInner {
|
||||
custom_properties: None,
|
||||
writing_mode: WritingMode::empty(), // FIXME(bz): This seems dubious
|
||||
font_computation_data: FontComputationData::default_values(),
|
||||
|
@ -135,8 +132,10 @@ impl ComputedValues {
|
|||
% for style_struct in data.style_structs:
|
||||
${style_struct.gecko_name}: Arc::into_raw_offset(style_structs::${style_struct.name}::default(pres_context)),
|
||||
% endfor
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
pub fn to_outer(self) -> Arc<ComputedValues> {
|
||||
Arc::new(ComputedValues {inner: self})
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -198,12 +197,12 @@ impl ComputedValuesInner {
|
|||
}
|
||||
|
||||
/// Gets a reference to the visited style, if any.
|
||||
pub fn get_visited_style(&self) -> Option<<&Arc<ComputedValues>> {
|
||||
self.visited_style.as_ref()
|
||||
pub fn get_visited_style(&self) -> Option< & ComputedValuesInner> {
|
||||
self.visited_style.as_ref().map(|x| &***x)
|
||||
}
|
||||
|
||||
/// Gets a reference to the visited style. Panic if no visited style exists.
|
||||
pub fn visited_style(&self) -> &Arc<ComputedValues> {
|
||||
pub fn visited_style(&self) -> &ComputedValuesInner {
|
||||
self.get_visited_style().unwrap()
|
||||
}
|
||||
|
||||
|
|
|
@ -292,7 +292,7 @@
|
|||
#[allow(unused_imports)]
|
||||
use properties::{DeclaredValue, LonghandId, LonghandIdSet};
|
||||
#[allow(unused_imports)]
|
||||
use properties::{CSSWideKeyword, ComputedValues, PropertyDeclaration};
|
||||
use properties::{CSSWideKeyword, ComputedValuesInner, PropertyDeclaration};
|
||||
#[allow(unused_imports)]
|
||||
use properties::style_structs;
|
||||
#[allow(unused_imports)]
|
||||
|
@ -310,8 +310,8 @@
|
|||
${caller.body()}
|
||||
#[allow(unused_variables)]
|
||||
pub fn cascade_property(declaration: &PropertyDeclaration,
|
||||
inherited_style: &ComputedValues,
|
||||
default_style: &ComputedValues,
|
||||
inherited_style: &ComputedValuesInner,
|
||||
default_style: &ComputedValuesInner,
|
||||
context: &mut computed::Context,
|
||||
cacheable: &mut bool,
|
||||
cascade_info: &mut Option<<&mut CascadeInfo>) {
|
||||
|
|
|
@ -29,7 +29,7 @@ use smallvec::SmallVec;
|
|||
use std::cmp;
|
||||
#[cfg(feature = "gecko")] use fnv::FnvHashMap;
|
||||
use style_traits::ParseError;
|
||||
use super::ComputedValues;
|
||||
use super::ComputedValuesInner;
|
||||
#[cfg(any(feature = "gecko", feature = "testing"))]
|
||||
use values::Auto;
|
||||
use values::{CSSFloat, CustomIdent, Either};
|
||||
|
@ -394,7 +394,7 @@ impl AnimatedProperty {
|
|||
|
||||
/// Update `style` with the proper computed style corresponding to this
|
||||
/// animation at `progress`.
|
||||
pub fn update(&self, style: &mut ComputedValues, progress: f64) {
|
||||
pub fn update(&self, style: &mut ComputedValuesInner, progress: f64) {
|
||||
match *self {
|
||||
% for prop in data.longhands:
|
||||
% if prop.animatable:
|
||||
|
@ -427,8 +427,8 @@ impl AnimatedProperty {
|
|||
/// Get an animatable value from a transition-property, an old style, and a
|
||||
/// new style.
|
||||
pub fn from_animatable_longhand(property: &AnimatableLonghand,
|
||||
old_style: &ComputedValues,
|
||||
new_style: &ComputedValues)
|
||||
old_style: &ComputedValuesInner,
|
||||
new_style: &ComputedValuesInner)
|
||||
-> AnimatedProperty {
|
||||
match *property {
|
||||
% for prop in data.longhands:
|
||||
|
@ -521,7 +521,7 @@ impl AnimationValue {
|
|||
|
||||
/// Construct an AnimationValue from a property declaration
|
||||
pub fn from_declaration(decl: &PropertyDeclaration, context: &mut Context,
|
||||
initial: &ComputedValues) -> Option<Self> {
|
||||
initial: &ComputedValuesInner) -> Option<Self> {
|
||||
use properties::LonghandId;
|
||||
|
||||
match *decl {
|
||||
|
@ -593,7 +593,7 @@ impl AnimationValue {
|
|||
|
||||
/// Get an AnimationValue for an AnimatableLonghand from a given computed values.
|
||||
pub fn from_computed_values(property: &AnimatableLonghand,
|
||||
computed_values: &ComputedValues)
|
||||
computed_values: &ComputedValuesInner)
|
||||
-> Self {
|
||||
match *property {
|
||||
% for prop in data.longhands:
|
||||
|
|
|
@ -181,7 +181,7 @@
|
|||
|
||||
% if product == "servo":
|
||||
fn cascade_property_custom(_declaration: &PropertyDeclaration,
|
||||
_inherited_style: &ComputedValues,
|
||||
_inherited_style: &ComputedValuesInner,
|
||||
context: &mut computed::Context,
|
||||
_cacheable: &mut bool) {
|
||||
longhands::_servo_display_for_hypothetical_box::derive_from_display(context);
|
||||
|
|
|
@ -249,7 +249,7 @@ ${helpers.single_keyword("unicode-bidi",
|
|||
|
||||
% if product == "servo":
|
||||
fn cascade_property_custom(_declaration: &PropertyDeclaration,
|
||||
_inherited_style: &ComputedValues,
|
||||
_inherited_style: &ComputedValuesInner,
|
||||
context: &mut computed::Context,
|
||||
_cacheable: &mut bool) {
|
||||
longhands::_servo_text_decorations_in_effect::derive_from_text_decoration(context);
|
||||
|
|
|
@ -1872,6 +1872,8 @@ pub mod style_structs {
|
|||
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use gecko_properties::ComputedValues;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use gecko_properties::ComputedValuesInner;
|
||||
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
|
@ -1920,7 +1922,7 @@ pub struct ComputedValues {
|
|||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl ComputedValues {
|
||||
impl ComputedValuesInner {
|
||||
/// Construct a `ComputedValues` instance.
|
||||
pub fn new(
|
||||
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
||||
|
@ -1933,18 +1935,16 @@ impl ComputedValues {
|
|||
${style_struct.ident}: Arc<style_structs::${style_struct.name}>,
|
||||
% endfor
|
||||
) -> Self {
|
||||
ComputedValues {
|
||||
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},
|
||||
% endfor
|
||||
}
|
||||
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},
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1969,6 +1969,11 @@ impl ops::DerefMut for ComputedValues {
|
|||
|
||||
#[cfg(feature = "servo")]
|
||||
impl ComputedValuesInner {
|
||||
/// Convert to an Arc<ComputedValues>
|
||||
pub fn to_outer(self) -> Arc<ComputedValues> {
|
||||
Arc::new(ComputedValues {inner: self})
|
||||
}
|
||||
|
||||
% for style_struct in data.active_style_structs():
|
||||
/// Clone the ${style_struct.name} struct.
|
||||
#[inline]
|
||||
|
@ -2006,13 +2011,13 @@ impl ComputedValuesInner {
|
|||
}
|
||||
|
||||
/// Gets a reference to the visited style, if any.
|
||||
pub fn get_visited_style(&self) -> Option<<&Arc<ComputedValues>> {
|
||||
self.visited_style.as_ref()
|
||||
pub fn get_visited_style(&self) -> Option< & ComputedValuesInner> {
|
||||
self.visited_style.as_ref().map(|x| &***x)
|
||||
}
|
||||
|
||||
/// Gets a reference to the visited style. Panic if no visited style exists.
|
||||
pub fn visited_style(&self) -> &Arc<ComputedValues> {
|
||||
self.get_visited_style().unwrap()
|
||||
pub fn visited_style(&self) -> &ComputedValuesInner {
|
||||
self.get_visited_style().as_ref().map(|x| &**x).unwrap()
|
||||
}
|
||||
|
||||
/// Clone the visited style. Used for inheriting parent styles in
|
||||
|
@ -2441,8 +2446,8 @@ pub struct StyleBuilder<'a> {
|
|||
impl<'a> StyleBuilder<'a> {
|
||||
/// Trivially construct a `StyleBuilder`.
|
||||
fn new(
|
||||
inherited_style: &'a ComputedValues,
|
||||
reset_style: &'a ComputedValues,
|
||||
inherited_style: &'a ComputedValuesInner,
|
||||
reset_style: &'a ComputedValuesInner,
|
||||
rules: Option<StrongRuleNode>,
|
||||
custom_properties: Option<Arc<::custom_properties::CustomPropertiesMap>>,
|
||||
writing_mode: WritingMode,
|
||||
|
@ -2469,15 +2474,15 @@ impl<'a> StyleBuilder<'a> {
|
|||
|
||||
/// Creates a StyleBuilder holding only references to the structs of `s`, in
|
||||
/// order to create a derived style.
|
||||
pub fn for_derived_style(s: &'a ComputedValues) -> Self {
|
||||
pub fn for_derived_style(s: &'a ComputedValuesInner) -> Self {
|
||||
Self::for_inheritance(s, s)
|
||||
}
|
||||
|
||||
/// Inherits style from the parent element, accounting for the default
|
||||
/// computed values that need to be provided as well.
|
||||
pub fn for_inheritance(
|
||||
parent: &'a ComputedValues,
|
||||
default: &'a ComputedValues
|
||||
parent: &'a ComputedValuesInner,
|
||||
default: &'a ComputedValuesInner
|
||||
) -> Self {
|
||||
Self::new(
|
||||
parent,
|
||||
|
@ -2521,7 +2526,7 @@ impl<'a> StyleBuilder<'a> {
|
|||
}
|
||||
|
||||
/// Reset the current `${style_struct.name}` style to its default value.
|
||||
pub fn reset_${style_struct.name_lower}(&mut self, default: &'a ComputedValues) {
|
||||
pub fn reset_${style_struct.name_lower}(&mut self, default: &'a ComputedValuesInner) {
|
||||
self.${style_struct.ident} =
|
||||
StyleStructRef::Borrowed(default.${style_struct.name_lower}_arc());
|
||||
}
|
||||
|
@ -2555,8 +2560,8 @@ impl<'a> StyleBuilder<'a> {
|
|||
|
||||
|
||||
/// Turns this `StyleBuilder` into a proper `ComputedValues` instance.
|
||||
pub fn build(self) -> ComputedValues {
|
||||
ComputedValues::new(self.custom_properties,
|
||||
pub fn build(self) -> ComputedValuesInner {
|
||||
ComputedValuesInner::new(self.custom_properties,
|
||||
self.writing_mode,
|
||||
self.font_size_keyword,
|
||||
self.flags,
|
||||
|
@ -2586,30 +2591,28 @@ pub use self::lazy_static_module::INITIAL_SERVO_VALUES;
|
|||
mod lazy_static_module {
|
||||
use logical_geometry::WritingMode;
|
||||
use stylearc::Arc;
|
||||
use super::{ComputedValues, ComputedValuesInner, longhands, style_structs, FontComputationData};
|
||||
use super::{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:
|
||||
${longhand.ident}: longhands::${longhand.ident}::get_initial_value(),
|
||||
% endfor
|
||||
% if style_struct.name == "Font":
|
||||
hash: 0,
|
||||
% endif
|
||||
}),
|
||||
% endfor
|
||||
custom_properties: None,
|
||||
writing_mode: WritingMode::empty(),
|
||||
font_computation_data: FontComputationData::default_values(),
|
||||
rules: None,
|
||||
visited_style: None,
|
||||
flags: ComputedValueFlags::empty(),
|
||||
}
|
||||
pub static ref INITIAL_SERVO_VALUES: ComputedValuesInner = 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:
|
||||
${longhand.ident}: longhands::${longhand.ident}::get_initial_value(),
|
||||
% endfor
|
||||
% if style_struct.name == "Font":
|
||||
hash: 0,
|
||||
% endif
|
||||
}),
|
||||
% endfor
|
||||
custom_properties: None,
|
||||
writing_mode: WritingMode::empty(),
|
||||
font_computation_data: FontComputationData::default_values(),
|
||||
rules: None,
|
||||
visited_style: None,
|
||||
flags: ComputedValueFlags::empty(),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -2617,8 +2620,8 @@ mod lazy_static_module {
|
|||
/// A per-longhand function that performs the CSS cascade for that longhand.
|
||||
pub type CascadePropertyFn =
|
||||
extern "Rust" fn(declaration: &PropertyDeclaration,
|
||||
inherited_style: &ComputedValues,
|
||||
default_style: &ComputedValues,
|
||||
inherited_style: &ComputedValuesInner,
|
||||
default_style: &ComputedValuesInner,
|
||||
context: &mut computed::Context,
|
||||
cacheable: &mut bool,
|
||||
cascade_info: &mut Option<<&mut CascadeInfo>);
|
||||
|
@ -2679,14 +2682,14 @@ bitflags! {
|
|||
pub fn cascade(device: &Device,
|
||||
rule_node: &StrongRuleNode,
|
||||
guards: &StylesheetGuards,
|
||||
parent_style: Option<<&ComputedValues>,
|
||||
layout_parent_style: Option<<&ComputedValues>,
|
||||
parent_style: Option<<&ComputedValuesInner>,
|
||||
layout_parent_style: Option<<&ComputedValuesInner>,
|
||||
visited_style: Option<Arc<ComputedValues>>,
|
||||
cascade_info: Option<<&mut CascadeInfo>,
|
||||
font_metrics_provider: &FontMetricsProvider,
|
||||
flags: CascadeFlags,
|
||||
quirks_mode: QuirksMode)
|
||||
-> ComputedValues {
|
||||
-> ComputedValuesInner {
|
||||
debug_assert!(layout_parent_style.is_none() || parent_style.is_some());
|
||||
let (inherited_style, layout_parent_style) = match parent_style {
|
||||
Some(parent_style) => {
|
||||
|
@ -2741,14 +2744,14 @@ pub fn cascade(device: &Device,
|
|||
pub fn apply_declarations<'a, F, I>(device: &Device,
|
||||
rules: &StrongRuleNode,
|
||||
iter_declarations: F,
|
||||
inherited_style: &ComputedValues,
|
||||
layout_parent_style: &ComputedValues,
|
||||
inherited_style: &ComputedValuesInner,
|
||||
layout_parent_style: &ComputedValuesInner,
|
||||
visited_style: Option<Arc<ComputedValues>>,
|
||||
mut cascade_info: Option<<&mut CascadeInfo>,
|
||||
font_metrics_provider: &FontMetricsProvider,
|
||||
flags: CascadeFlags,
|
||||
quirks_mode: QuirksMode)
|
||||
-> ComputedValues
|
||||
-> ComputedValuesInner
|
||||
where F: Fn() -> I,
|
||||
I: Iterator<Item = (&'a PropertyDeclaration, CascadeLevel)>,
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue