Auto merge of #14640 - upsuper:unset-storage, r=emilio

Store unset keyword as specified value

<!-- Please describe your changes on the following line: -->
`unset` keyword value should *not* be converted to something else during parsing. It is a specified-value time value, which should be preserved until computation.

WIP patch for seeing what tests would be broken and / or if there is necessary to add any new test.

---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [ ] These changes fix #__ (github issue number if applicable).

<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____

<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->

<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/14640)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2016-12-25 14:23:34 -08:00 committed by GitHub
commit 4cd7321531
7 changed files with 64 additions and 17 deletions

View file

@ -90,6 +90,14 @@ pub mod shorthands {
use parser::{Parse, ParserContext};
use values::specified;
bitflags! {
flags SerializeFlags: u8 {
const ALL_INHERIT = 0b001,
const ALL_INITIAL = 0b010,
const ALL_UNSET = 0b100,
}
}
pub fn parse_four_sides<F, T>(input: &mut Parser, parse_one: F) -> Result<(T, T, T, T), ()>
where F: Fn(&mut Parser) -> Result<T, ()>, T: Clone
{
@ -520,9 +528,7 @@ pub enum DeclaredValue<T> {
},
Initial,
Inherit,
// There is no Unset variant here.
// The 'unset' keyword is represented as either Initial or Inherit,
// depending on whether the property is inherited.
Unset,
}
impl<T: HasViewportPercentage> HasViewportPercentage for DeclaredValue<T> {
@ -533,7 +539,8 @@ impl<T: HasViewportPercentage> HasViewportPercentage for DeclaredValue<T> {
DeclaredValue::WithVariables { .. }
=> panic!("DeclaredValue::has_viewport_percentage without resolving variables!"),
DeclaredValue::Initial |
DeclaredValue::Inherit => false,
DeclaredValue::Inherit |
DeclaredValue::Unset => false,
}
}
}
@ -549,6 +556,7 @@ impl<T: ToCss> ToCss for DeclaredValue<T> {
DeclaredValue::WithVariables { .. } => Ok(()),
DeclaredValue::Initial => dest.write_str("initial"),
DeclaredValue::Inherit => dest.write_str("inherit"),
DeclaredValue::Unset => dest.write_str("unset"),
}
}
}
@ -817,7 +825,7 @@ impl PropertyDeclaration {
match id {
PropertyId::Custom(name) => {
let value = match input.try(|i| CSSWideKeyword::parse(context, i)) {
Ok(CSSWideKeyword::UnsetKeyword) | // Custom properties are alawys inherited
Ok(CSSWideKeyword::UnsetKeyword) => DeclaredValue::Unset,
Ok(CSSWideKeyword::InheritKeyword) => DeclaredValue::Inherit,
Ok(CSSWideKeyword::InitialKeyword) => DeclaredValue::Initial,
Err(()) => match ::custom_properties::SpecifiedValue::parse(context, input) {
@ -900,8 +908,7 @@ impl PropertyDeclaration {
Ok(CSSWideKeyword::UnsetKeyword) => {
% for sub_property in shorthand.sub_properties:
result_list.push(PropertyDeclaration::${sub_property.camel_case}(
DeclaredValue::${"Inherit" if sub_property.style_struct.inherited else "Initial"}
));
DeclaredValue::Unset));
% endfor
PropertyDeclarationParseResult::ValidOrIgnoredDeclaration
},