mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Box DeclaredValue::WithVariables
This commit is contained in:
parent
43731c5757
commit
adb6d20293
6 changed files with 53 additions and 44 deletions
|
@ -361,7 +361,7 @@ pub fn cascade<'a>(custom_properties: &mut Option<HashMap<&'a Name, BorrowedSpec
|
|||
references: Some(&specified_value.references),
|
||||
});
|
||||
},
|
||||
DeclaredValue::WithVariables { .. } => unreachable!(),
|
||||
DeclaredValue::WithVariables(_) => unreachable!(),
|
||||
DeclaredValue::Initial => {
|
||||
map.remove(&name);
|
||||
}
|
||||
|
|
|
@ -196,7 +196,7 @@
|
|||
% if not property.derived_from:
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext, ParserContextExtraData};
|
||||
use properties::{CSSWideKeyword, DeclaredValue, ShorthandId};
|
||||
use properties::{CSSWideKeyword, DeclaredValue, UnparsedValue, ShorthandId};
|
||||
% endif
|
||||
use values::{Auto, Either, None_, Normal};
|
||||
use cascade_info::CascadeInfo;
|
||||
|
@ -259,7 +259,7 @@
|
|||
.set_${property.ident}(computed ${maybe_wm});
|
||||
% endif
|
||||
}
|
||||
DeclaredValue::WithVariables { .. } => unreachable!(),
|
||||
DeclaredValue::WithVariables(_) => unreachable!(),
|
||||
% if not data.current_style_struct.inherited:
|
||||
DeclaredValue::Unset |
|
||||
% endif
|
||||
|
@ -324,12 +324,12 @@
|
|||
input.reset(start);
|
||||
let (first_token_type, css) = try!(
|
||||
::custom_properties::parse_non_custom_with_var(input));
|
||||
return Ok(DeclaredValue::WithVariables {
|
||||
return Ok(DeclaredValue::WithVariables(Box::new(UnparsedValue {
|
||||
css: css.into_owned(),
|
||||
first_token_type: first_token_type,
|
||||
base_url: context.base_url.clone(),
|
||||
from_shorthand: None,
|
||||
})
|
||||
})))
|
||||
}
|
||||
specified
|
||||
}
|
||||
|
@ -421,7 +421,8 @@
|
|||
#[allow(unused_imports)]
|
||||
use cssparser::Parser;
|
||||
use parser::ParserContext;
|
||||
use properties::{longhands, PropertyDeclaration, DeclaredValue, ShorthandId};
|
||||
use properties::{DeclaredValue, PropertyDeclaration, UnparsedValue};
|
||||
use properties::{ShorthandId, longhands};
|
||||
use properties::declaration_block::Importance;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
|
@ -504,7 +505,7 @@
|
|||
DeclaredValue::Initial => all_flags &= ALL_INITIAL,
|
||||
DeclaredValue::Inherit => all_flags &= ALL_INHERIT,
|
||||
DeclaredValue::Unset => all_flags &= ALL_UNSET,
|
||||
DeclaredValue::WithVariables {..} => with_variables = true,
|
||||
DeclaredValue::WithVariables(_) => with_variables = true,
|
||||
DeclaredValue::Value(..) => {
|
||||
all_flags = SerializeFlags::empty();
|
||||
}
|
||||
|
@ -560,12 +561,12 @@
|
|||
::custom_properties::parse_non_custom_with_var(input));
|
||||
% for sub_property in shorthand.sub_properties:
|
||||
declarations.push((PropertyDeclaration::${sub_property.camel_case}(
|
||||
DeclaredValue::WithVariables {
|
||||
DeclaredValue::WithVariables(Box::new(UnparsedValue {
|
||||
css: css.clone().into_owned(),
|
||||
first_token_type: first_token_type,
|
||||
base_url: context.base_url.clone(),
|
||||
from_shorthand: Some(ShorthandId::${shorthand.camel_case}),
|
||||
}
|
||||
}))
|
||||
), Importance::Normal));
|
||||
% endfor
|
||||
Ok(())
|
||||
|
|
|
@ -297,7 +297,7 @@ impl AnimationValue {
|
|||
PropertyDeclaration::${prop.camel_case}(ref val) => {
|
||||
let computed = match *val {
|
||||
// https://bugzilla.mozilla.org/show_bug.cgi?id=1326131
|
||||
DeclaredValue::WithVariables{..} => unimplemented!(),
|
||||
DeclaredValue::WithVariables(_) => unimplemented!(),
|
||||
DeclaredValue::Value(ref val) => val.to_computed_value(context),
|
||||
% if not prop.style_struct.inherited:
|
||||
DeclaredValue::Unset |
|
||||
|
|
|
@ -260,17 +260,15 @@ mod property_bit_field {
|
|||
where F: FnOnce(&DeclaredValue<longhands::${property.ident}::SpecifiedValue>)
|
||||
% endif
|
||||
{
|
||||
if let DeclaredValue::WithVariables {
|
||||
ref css, first_token_type, ref base_url, from_shorthand
|
||||
} = *value {
|
||||
if let DeclaredValue::WithVariables(ref with_variables) = *value {
|
||||
// FIXME(heycam): A ParserContextExtraData should be built from data
|
||||
// stored in the WithVariables, in case variable expansion results in
|
||||
// a url() value.
|
||||
let extra_data = ParserContextExtraData::default();
|
||||
substitute_variables_${property.ident}_slow(css,
|
||||
first_token_type,
|
||||
base_url,
|
||||
from_shorthand,
|
||||
substitute_variables_${property.ident}_slow(&with_variables.css,
|
||||
with_variables.first_token_type,
|
||||
&with_variables.base_url,
|
||||
with_variables.from_shorthand,
|
||||
custom_properties,
|
||||
f,
|
||||
error_reporter,
|
||||
|
@ -614,17 +612,8 @@ impl ShorthandId {
|
|||
pub enum DeclaredValue<T> {
|
||||
/// A known specified value from the stylesheet.
|
||||
Value(T),
|
||||
/// A value that contained any css variables.
|
||||
WithVariables {
|
||||
/// The css serialization for this value.
|
||||
css: String,
|
||||
/// The first token type for this serialization.
|
||||
first_token_type: TokenSerializationType,
|
||||
/// The base url.
|
||||
base_url: ServoUrl,
|
||||
/// The shorthand this came from.
|
||||
from_shorthand: Option<ShorthandId>,
|
||||
},
|
||||
/// An unparsed value that contains `var()` functions.
|
||||
WithVariables(Box<UnparsedValue>),
|
||||
/// The `initial` keyword.
|
||||
Initial,
|
||||
/// The `inherit` keyword.
|
||||
|
@ -633,11 +622,25 @@ pub enum DeclaredValue<T> {
|
|||
Unset,
|
||||
}
|
||||
|
||||
/// An unparsed property value that contains `var()` functions.
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||
pub struct UnparsedValue {
|
||||
/// The css serialization for this value.
|
||||
css: String,
|
||||
/// The first token type for this serialization.
|
||||
first_token_type: TokenSerializationType,
|
||||
/// The base url.
|
||||
base_url: ServoUrl,
|
||||
/// The shorthand this came from.
|
||||
from_shorthand: Option<ShorthandId>,
|
||||
}
|
||||
|
||||
impl<T: HasViewportPercentage> HasViewportPercentage for DeclaredValue<T> {
|
||||
fn has_viewport_percentage(&self) -> bool {
|
||||
match *self {
|
||||
DeclaredValue::Value(ref v) => v.has_viewport_percentage(),
|
||||
DeclaredValue::WithVariables { .. } => {
|
||||
DeclaredValue::WithVariables(_) => {
|
||||
panic!("DeclaredValue::has_viewport_percentage without \
|
||||
resolving variables!")
|
||||
},
|
||||
|
@ -654,11 +657,13 @@ impl<T: ToCss> ToCss for DeclaredValue<T> {
|
|||
{
|
||||
match *self {
|
||||
DeclaredValue::Value(ref inner) => inner.to_css(dest),
|
||||
DeclaredValue::WithVariables { ref css, from_shorthand: None, .. } => {
|
||||
dest.write_str(css)
|
||||
}
|
||||
// https://drafts.csswg.org/css-variables/#variables-in-shorthands
|
||||
DeclaredValue::WithVariables { .. } => Ok(()),
|
||||
DeclaredValue::WithVariables(ref with_variables) => {
|
||||
// https://drafts.csswg.org/css-variables/#variables-in-shorthands
|
||||
if with_variables.from_shorthand.is_none() {
|
||||
dest.write_str(&*with_variables.css)?
|
||||
}
|
||||
Ok(())
|
||||
},
|
||||
DeclaredValue::Initial => dest.write_str("initial"),
|
||||
DeclaredValue::Inherit => dest.write_str("inherit"),
|
||||
DeclaredValue::Unset => dest.write_str("unset"),
|
||||
|
@ -959,9 +964,12 @@ impl PropertyDeclaration {
|
|||
match *self {
|
||||
% for property in data.longhands:
|
||||
PropertyDeclaration::${property.camel_case}(ref value) => match *value {
|
||||
DeclaredValue::WithVariables { ref css, from_shorthand: Some(s), .. }
|
||||
if s == shorthand => {
|
||||
Some(&**css)
|
||||
DeclaredValue::WithVariables(ref with_variables) => {
|
||||
if let Some(s) = with_variables.from_shorthand {
|
||||
if s == shorthand {
|
||||
Some(&*with_variables.css)
|
||||
} else { None }
|
||||
} else { None }
|
||||
}
|
||||
_ => None
|
||||
},
|
||||
|
@ -976,12 +984,12 @@ impl PropertyDeclaration {
|
|||
match *self {
|
||||
% for property in data.longhands:
|
||||
PropertyDeclaration::${property.camel_case}(ref value) => match *value {
|
||||
DeclaredValue::WithVariables { .. } => true,
|
||||
DeclaredValue::WithVariables(_) => true,
|
||||
_ => false,
|
||||
},
|
||||
% endfor
|
||||
PropertyDeclaration::Custom(_, ref value) => match *value {
|
||||
DeclaredValue::WithVariables { .. } => true,
|
||||
DeclaredValue::WithVariables(_) => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -997,7 +1005,7 @@ impl PropertyDeclaration {
|
|||
match *self {
|
||||
% for property in data.longhands:
|
||||
PropertyDeclaration::${property.camel_case}(ref value) => {
|
||||
matches!(*value, DeclaredValue::WithVariables { .. })
|
||||
matches!(*value, DeclaredValue::WithVariables(_))
|
||||
},
|
||||
% endfor
|
||||
PropertyDeclaration::Custom(..) => true
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
(&DeclaredValue::Value(ref x_value), &DeclaredValue::Value(ref y_container)) => {
|
||||
*x_value == y_container.0
|
||||
},
|
||||
(&DeclaredValue::WithVariables { .. }, &DeclaredValue::WithVariables { .. }) => true,
|
||||
(&DeclaredValue::WithVariables(_), &DeclaredValue::WithVariables(_)) => true,
|
||||
(&DeclaredValue::Initial, &DeclaredValue::Initial) => true,
|
||||
(&DeclaredValue::Inherit, &DeclaredValue::Inherit) => true,
|
||||
(&DeclaredValue::Unset, &DeclaredValue::Unset) => true,
|
||||
|
@ -43,8 +43,8 @@
|
|||
(&DeclaredValue::Value(ref x_value), &DeclaredValue::Value(ref y_container)) => {
|
||||
*x_value == y_container.0
|
||||
},
|
||||
(_, &DeclaredValue::WithVariables { .. }) |
|
||||
(&DeclaredValue::WithVariables { .. }, _) => {
|
||||
(_, &DeclaredValue::WithVariables(_)) |
|
||||
(&DeclaredValue::WithVariables(_), _) => {
|
||||
// We don't serialize shorthands with variables
|
||||
return dest.write_str("");
|
||||
},
|
||||
|
|
|
@ -7,7 +7,7 @@ use style::properties::{PropertyDeclaration, specified_value_sizes};
|
|||
|
||||
#[test]
|
||||
fn size_of_property_declaration() {
|
||||
let old = 72;
|
||||
let old = 48;
|
||||
let new = size_of::<PropertyDeclaration>();
|
||||
if new < old {
|
||||
panic!("Your changes have decreased the stack size of PropertyDeclaration enum from {} to {}. \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue