mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
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:
commit
4cd7321531
7 changed files with 64 additions and 17 deletions
|
@ -345,6 +345,7 @@ pub fn cascade<'a>(custom_properties: &mut Option<HashMap<&'a Name, BorrowedSpec
|
|||
DeclaredValue::Initial => {
|
||||
map.remove(&name);
|
||||
}
|
||||
DeclaredValue::Unset | // Custom properties are inherited by default.
|
||||
DeclaredValue::Inherit => {} // The inherited value is what we already have.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -245,6 +245,9 @@
|
|||
% endif
|
||||
}
|
||||
DeclaredValue::WithVariables { .. } => unreachable!(),
|
||||
% if not data.current_style_struct.inherited:
|
||||
DeclaredValue::Unset |
|
||||
% endif
|
||||
DeclaredValue::Initial => {
|
||||
// We assume that it's faster to use copy_*_from rather than
|
||||
// set_*(get_initial_value());
|
||||
|
@ -253,6 +256,9 @@
|
|||
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
|
||||
.copy_${property.ident}_from(initial_struct ${maybe_wm});
|
||||
},
|
||||
% if data.current_style_struct.inherited:
|
||||
DeclaredValue::Unset |
|
||||
% endif
|
||||
DeclaredValue::Inherit => {
|
||||
// This is a bit slow, but this is rare so it shouldn't
|
||||
// matter.
|
||||
|
@ -286,8 +292,7 @@
|
|||
match input.try(|i| CSSWideKeyword::parse(context, i)) {
|
||||
Ok(CSSWideKeyword::InheritKeyword) => Ok(DeclaredValue::Inherit),
|
||||
Ok(CSSWideKeyword::InitialKeyword) => Ok(DeclaredValue::Initial),
|
||||
Ok(CSSWideKeyword::UnsetKeyword) => Ok(DeclaredValue::${
|
||||
"Inherit" if data.current_style_struct.inherited else "Initial"}),
|
||||
Ok(CSSWideKeyword::UnsetKeyword) => Ok(DeclaredValue::Unset),
|
||||
Err(()) => {
|
||||
input.look_for_var_functions();
|
||||
let start = input.position();
|
||||
|
@ -383,6 +388,7 @@
|
|||
use properties::{longhands, PropertyDeclaration, DeclaredValue, ShorthandId};
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
use super::{SerializeFlags, ALL_INHERIT, ALL_INITIAL, ALL_UNSET};
|
||||
|
||||
pub struct Longhands {
|
||||
% for sub_property in shorthand.sub_properties:
|
||||
|
@ -441,17 +447,16 @@
|
|||
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
let mut all_inherit = true;
|
||||
let mut all_initial = true;
|
||||
let mut all_flags = SerializeFlags::all();
|
||||
let mut with_variables = false;
|
||||
% for sub_property in shorthand.sub_properties:
|
||||
match *self.${sub_property.ident} {
|
||||
DeclaredValue::Initial => all_inherit = false,
|
||||
DeclaredValue::Inherit => all_initial = false,
|
||||
DeclaredValue::Initial => all_flags &= ALL_INITIAL,
|
||||
DeclaredValue::Inherit => all_flags &= ALL_INHERIT,
|
||||
DeclaredValue::Unset => all_flags &= ALL_UNSET,
|
||||
DeclaredValue::WithVariables {..} => with_variables = true,
|
||||
DeclaredValue::Value(..) => {
|
||||
all_initial = false;
|
||||
all_inherit = false;
|
||||
all_flags = SerializeFlags::empty();
|
||||
}
|
||||
}
|
||||
% endfor
|
||||
|
@ -459,10 +464,12 @@
|
|||
if with_variables {
|
||||
// We don't serialize shorthands with variables
|
||||
dest.write_str("")
|
||||
} else if all_inherit {
|
||||
} else if all_flags == ALL_INHERIT {
|
||||
dest.write_str("inherit")
|
||||
} else if all_initial {
|
||||
} else if all_flags == ALL_INITIAL {
|
||||
dest.write_str("initial")
|
||||
} else if all_flags == ALL_UNSET {
|
||||
dest.write_str("unset")
|
||||
} else {
|
||||
self.to_css_declared(dest)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
},
|
||||
|
|
|
@ -40,6 +40,7 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style",
|
|||
},
|
||||
&DeclaredValue::Initial => DeclaredValue::Initial,
|
||||
&DeclaredValue::Inherit => DeclaredValue::Inherit,
|
||||
&DeclaredValue::Unset => DeclaredValue::Unset,
|
||||
};
|
||||
% endfor
|
||||
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
(&DeclaredValue::WithVariables { .. }, &DeclaredValue::WithVariables { .. }) => true,
|
||||
(&DeclaredValue::Initial, &DeclaredValue::Initial) => true,
|
||||
(&DeclaredValue::Inherit, &DeclaredValue::Inherit) => true,
|
||||
(&DeclaredValue::Unset, &DeclaredValue::Unset) => true,
|
||||
_ => false
|
||||
};
|
||||
|
||||
|
@ -331,6 +332,7 @@ macro_rules! try_parse_one {
|
|||
},
|
||||
(&DeclaredValue::Initial, &DeclaredValue::Initial) => true,
|
||||
(&DeclaredValue::Inherit, &DeclaredValue::Inherit) => true,
|
||||
(&DeclaredValue::Unset, &DeclaredValue::Unset) => true,
|
||||
(x, y) => { *x == *y },
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue