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 => {
|
DeclaredValue::Initial => {
|
||||||
map.remove(&name);
|
map.remove(&name);
|
||||||
}
|
}
|
||||||
|
DeclaredValue::Unset | // Custom properties are inherited by default.
|
||||||
DeclaredValue::Inherit => {} // The inherited value is what we already have.
|
DeclaredValue::Inherit => {} // The inherited value is what we already have.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -245,6 +245,9 @@
|
||||||
% endif
|
% endif
|
||||||
}
|
}
|
||||||
DeclaredValue::WithVariables { .. } => unreachable!(),
|
DeclaredValue::WithVariables { .. } => unreachable!(),
|
||||||
|
% if not data.current_style_struct.inherited:
|
||||||
|
DeclaredValue::Unset |
|
||||||
|
% endif
|
||||||
DeclaredValue::Initial => {
|
DeclaredValue::Initial => {
|
||||||
// We assume that it's faster to use copy_*_from rather than
|
// We assume that it's faster to use copy_*_from rather than
|
||||||
// set_*(get_initial_value());
|
// set_*(get_initial_value());
|
||||||
|
@ -253,6 +256,9 @@
|
||||||
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
|
context.mutate_style().mutate_${data.current_style_struct.name_lower}()
|
||||||
.copy_${property.ident}_from(initial_struct ${maybe_wm});
|
.copy_${property.ident}_from(initial_struct ${maybe_wm});
|
||||||
},
|
},
|
||||||
|
% if data.current_style_struct.inherited:
|
||||||
|
DeclaredValue::Unset |
|
||||||
|
% endif
|
||||||
DeclaredValue::Inherit => {
|
DeclaredValue::Inherit => {
|
||||||
// This is a bit slow, but this is rare so it shouldn't
|
// This is a bit slow, but this is rare so it shouldn't
|
||||||
// matter.
|
// matter.
|
||||||
|
@ -286,8 +292,7 @@
|
||||||
match input.try(|i| CSSWideKeyword::parse(context, i)) {
|
match input.try(|i| CSSWideKeyword::parse(context, i)) {
|
||||||
Ok(CSSWideKeyword::InheritKeyword) => Ok(DeclaredValue::Inherit),
|
Ok(CSSWideKeyword::InheritKeyword) => Ok(DeclaredValue::Inherit),
|
||||||
Ok(CSSWideKeyword::InitialKeyword) => Ok(DeclaredValue::Initial),
|
Ok(CSSWideKeyword::InitialKeyword) => Ok(DeclaredValue::Initial),
|
||||||
Ok(CSSWideKeyword::UnsetKeyword) => Ok(DeclaredValue::${
|
Ok(CSSWideKeyword::UnsetKeyword) => Ok(DeclaredValue::Unset),
|
||||||
"Inherit" if data.current_style_struct.inherited else "Initial"}),
|
|
||||||
Err(()) => {
|
Err(()) => {
|
||||||
input.look_for_var_functions();
|
input.look_for_var_functions();
|
||||||
let start = input.position();
|
let start = input.position();
|
||||||
|
@ -383,6 +388,7 @@
|
||||||
use properties::{longhands, PropertyDeclaration, DeclaredValue, ShorthandId};
|
use properties::{longhands, PropertyDeclaration, DeclaredValue, ShorthandId};
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use style_traits::ToCss;
|
use style_traits::ToCss;
|
||||||
|
use super::{SerializeFlags, ALL_INHERIT, ALL_INITIAL, ALL_UNSET};
|
||||||
|
|
||||||
pub struct Longhands {
|
pub struct Longhands {
|
||||||
% for sub_property in shorthand.sub_properties:
|
% for sub_property in shorthand.sub_properties:
|
||||||
|
@ -441,17 +447,16 @@
|
||||||
|
|
||||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||||
let mut all_inherit = true;
|
let mut all_flags = SerializeFlags::all();
|
||||||
let mut all_initial = true;
|
|
||||||
let mut with_variables = false;
|
let mut with_variables = false;
|
||||||
% for sub_property in shorthand.sub_properties:
|
% for sub_property in shorthand.sub_properties:
|
||||||
match *self.${sub_property.ident} {
|
match *self.${sub_property.ident} {
|
||||||
DeclaredValue::Initial => all_inherit = false,
|
DeclaredValue::Initial => all_flags &= ALL_INITIAL,
|
||||||
DeclaredValue::Inherit => all_initial = false,
|
DeclaredValue::Inherit => all_flags &= ALL_INHERIT,
|
||||||
|
DeclaredValue::Unset => all_flags &= ALL_UNSET,
|
||||||
DeclaredValue::WithVariables {..} => with_variables = true,
|
DeclaredValue::WithVariables {..} => with_variables = true,
|
||||||
DeclaredValue::Value(..) => {
|
DeclaredValue::Value(..) => {
|
||||||
all_initial = false;
|
all_flags = SerializeFlags::empty();
|
||||||
all_inherit = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -459,10 +464,12 @@
|
||||||
if with_variables {
|
if with_variables {
|
||||||
// We don't serialize shorthands with variables
|
// We don't serialize shorthands with variables
|
||||||
dest.write_str("")
|
dest.write_str("")
|
||||||
} else if all_inherit {
|
} else if all_flags == ALL_INHERIT {
|
||||||
dest.write_str("inherit")
|
dest.write_str("inherit")
|
||||||
} else if all_initial {
|
} else if all_flags == ALL_INITIAL {
|
||||||
dest.write_str("initial")
|
dest.write_str("initial")
|
||||||
|
} else if all_flags == ALL_UNSET {
|
||||||
|
dest.write_str("unset")
|
||||||
} else {
|
} else {
|
||||||
self.to_css_declared(dest)
|
self.to_css_declared(dest)
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,6 +90,14 @@ pub mod shorthands {
|
||||||
use parser::{Parse, ParserContext};
|
use parser::{Parse, ParserContext};
|
||||||
use values::specified;
|
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), ()>
|
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
|
where F: Fn(&mut Parser) -> Result<T, ()>, T: Clone
|
||||||
{
|
{
|
||||||
|
@ -520,9 +528,7 @@ pub enum DeclaredValue<T> {
|
||||||
},
|
},
|
||||||
Initial,
|
Initial,
|
||||||
Inherit,
|
Inherit,
|
||||||
// There is no Unset variant here.
|
Unset,
|
||||||
// The 'unset' keyword is represented as either Initial or Inherit,
|
|
||||||
// depending on whether the property is inherited.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: HasViewportPercentage> HasViewportPercentage for DeclaredValue<T> {
|
impl<T: HasViewportPercentage> HasViewportPercentage for DeclaredValue<T> {
|
||||||
|
@ -533,7 +539,8 @@ impl<T: HasViewportPercentage> HasViewportPercentage for DeclaredValue<T> {
|
||||||
DeclaredValue::WithVariables { .. }
|
DeclaredValue::WithVariables { .. }
|
||||||
=> panic!("DeclaredValue::has_viewport_percentage without resolving variables!"),
|
=> panic!("DeclaredValue::has_viewport_percentage without resolving variables!"),
|
||||||
DeclaredValue::Initial |
|
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::WithVariables { .. } => Ok(()),
|
||||||
DeclaredValue::Initial => dest.write_str("initial"),
|
DeclaredValue::Initial => dest.write_str("initial"),
|
||||||
DeclaredValue::Inherit => dest.write_str("inherit"),
|
DeclaredValue::Inherit => dest.write_str("inherit"),
|
||||||
|
DeclaredValue::Unset => dest.write_str("unset"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -817,7 +825,7 @@ impl PropertyDeclaration {
|
||||||
match id {
|
match id {
|
||||||
PropertyId::Custom(name) => {
|
PropertyId::Custom(name) => {
|
||||||
let value = match input.try(|i| CSSWideKeyword::parse(context, i)) {
|
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::InheritKeyword) => DeclaredValue::Inherit,
|
||||||
Ok(CSSWideKeyword::InitialKeyword) => DeclaredValue::Initial,
|
Ok(CSSWideKeyword::InitialKeyword) => DeclaredValue::Initial,
|
||||||
Err(()) => match ::custom_properties::SpecifiedValue::parse(context, input) {
|
Err(()) => match ::custom_properties::SpecifiedValue::parse(context, input) {
|
||||||
|
@ -900,8 +908,7 @@ impl PropertyDeclaration {
|
||||||
Ok(CSSWideKeyword::UnsetKeyword) => {
|
Ok(CSSWideKeyword::UnsetKeyword) => {
|
||||||
% for sub_property in shorthand.sub_properties:
|
% for sub_property in shorthand.sub_properties:
|
||||||
result_list.push(PropertyDeclaration::${sub_property.camel_case}(
|
result_list.push(PropertyDeclaration::${sub_property.camel_case}(
|
||||||
DeclaredValue::${"Inherit" if sub_property.style_struct.inherited else "Initial"}
|
DeclaredValue::Unset));
|
||||||
));
|
|
||||||
% endfor
|
% endfor
|
||||||
PropertyDeclarationParseResult::ValidOrIgnoredDeclaration
|
PropertyDeclarationParseResult::ValidOrIgnoredDeclaration
|
||||||
},
|
},
|
||||||
|
|
|
@ -40,6 +40,7 @@ ${helpers.four_sides_shorthand("border-style", "border-%s-style",
|
||||||
},
|
},
|
||||||
&DeclaredValue::Initial => DeclaredValue::Initial,
|
&DeclaredValue::Initial => DeclaredValue::Initial,
|
||||||
&DeclaredValue::Inherit => DeclaredValue::Inherit,
|
&DeclaredValue::Inherit => DeclaredValue::Inherit,
|
||||||
|
&DeclaredValue::Unset => DeclaredValue::Unset,
|
||||||
};
|
};
|
||||||
% endfor
|
% endfor
|
||||||
|
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
(&DeclaredValue::WithVariables { .. }, &DeclaredValue::WithVariables { .. }) => true,
|
(&DeclaredValue::WithVariables { .. }, &DeclaredValue::WithVariables { .. }) => true,
|
||||||
(&DeclaredValue::Initial, &DeclaredValue::Initial) => true,
|
(&DeclaredValue::Initial, &DeclaredValue::Initial) => true,
|
||||||
(&DeclaredValue::Inherit, &DeclaredValue::Inherit) => true,
|
(&DeclaredValue::Inherit, &DeclaredValue::Inherit) => true,
|
||||||
|
(&DeclaredValue::Unset, &DeclaredValue::Unset) => true,
|
||||||
_ => false
|
_ => false
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -331,6 +332,7 @@ macro_rules! try_parse_one {
|
||||||
},
|
},
|
||||||
(&DeclaredValue::Initial, &DeclaredValue::Initial) => true,
|
(&DeclaredValue::Initial, &DeclaredValue::Initial) => true,
|
||||||
(&DeclaredValue::Inherit, &DeclaredValue::Inherit) => true,
|
(&DeclaredValue::Inherit, &DeclaredValue::Inherit) => true,
|
||||||
|
(&DeclaredValue::Unset, &DeclaredValue::Unset) => true,
|
||||||
(x, y) => { *x == *y },
|
(x, y) => { *x == *y },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -39677,6 +39677,12 @@
|
||||||
"deleted_reftests": {},
|
"deleted_reftests": {},
|
||||||
"items": {
|
"items": {
|
||||||
"testharness": {
|
"testharness": {
|
||||||
|
"css-values/unset-value-storage.html": [
|
||||||
|
{
|
||||||
|
"path": "css-values/unset-value-storage.html",
|
||||||
|
"url": "/css-values/unset-value-storage.html"
|
||||||
|
}
|
||||||
|
],
|
||||||
"cssom/CSSKeyframesRule.html": [
|
"cssom/CSSKeyframesRule.html": [
|
||||||
{
|
{
|
||||||
"path": "cssom/CSSKeyframesRule.html",
|
"path": "cssom/CSSKeyframesRule.html",
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<title>Storage of "unset" value</title>
|
||||||
|
<meta name="author" title="Xidorn Quan" href="https://www.upsuper.org">
|
||||||
|
<script src="/resources/testharness.js"></script>
|
||||||
|
<script src="/resources/testharnessreport.js"></script>
|
||||||
|
<style>
|
||||||
|
div {
|
||||||
|
color: unset;
|
||||||
|
border: unset;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<body>
|
||||||
|
<div id="log"></div>
|
||||||
|
<script>
|
||||||
|
test(function() {
|
||||||
|
let properties = ["color", "border", "border-left", "border-color", "border-right-style"];
|
||||||
|
let style = document.styleSheets[0].cssRules[0].style;
|
||||||
|
for (let prop of properties) {
|
||||||
|
assert_equals(style.getPropertyValue(prop), "unset", `${prop} is expected to be "unset"`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue