Commit 91a1db29 authored by Anders Hartvoll Ruud's avatar Anders Hartvoll Ruud Committed by Commit Bot

[css-properties-values-api] Use inherited value for substitution.

When a var()-reference produces tokens that are incompatible with the
current syntax, or the var()-reference refers to a variable that does not
exist, we currently always substitute the initial value, even for
inherited properties. This is incorrect, as the value should behave as
'unset', which means 'inherit' for inherited properties.

Note that if syntax-incompatible tokens are specified directly (not via a
var()-reference), we correctly behave as 'unset'. This is because the
var()-less case is handled by a different code path (variable.cc).

R=futhark@chromium.org

Bug: 641877
Change-Id: Ifdd5435ee77f4b8cd3998967713cb6fcb7e8d5f4
Reviewed-on: https://chromium-review.googlesource.com/1235579
Commit-Queue: Anders Ruud <andruud@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Cr-Commit-Position: refs/heads/master@{#593145}
parent 38180df3
...@@ -57,4 +57,19 @@ test(function(){ ...@@ -57,4 +57,19 @@ test(function(){
inner.style = '--initial-length-2: inherit'; inner.style = '--initial-length-2: inherit';
assert_equals(getComputedStyle(inner).getPropertyValue('--initial-length-2'), '0px'); assert_equals(getComputedStyle(inner).getPropertyValue('--initial-length-2'), '0px');
}, "Explicitly inheriting from a parent with no value results in initial value."); }, "Explicitly inheriting from a parent with no value results in initial value.");
test(function(){
CSS.registerProperty({name: '--inherited-length-4', syntax: '<length>', initialValue: '0px', inherits: true});
outer.style = '--inherited-length-4: 42px';
inner.style = '--inherited-length-4: var(--undefined)';
assert_equals(getComputedStyle(inner).getPropertyValue('--inherited-length-4'), '42px');
}, "Reference to undefined variable results in inherited value");
test(function(){
CSS.registerProperty({name: '--inherited-length-5', syntax: '<length>', initialValue: '0px', inherits: true});
outer.style = '--inherited-length-5: 42px';
inner.style = '--incompatible: nolength; --inherited-length-5: var(--incompatible)';
assert_equals(getComputedStyle(inner).getPropertyValue('--inherited-length-5'), '42px');
}, "Reference to syntax-incompatible variable results in inherited value");
</script> </script>
...@@ -107,6 +107,15 @@ scoped_refptr<CSSVariableData> CSSVariableResolver::ValueForCustomProperty( ...@@ -107,6 +107,15 @@ scoped_refptr<CSSVariableData> CSSVariableResolver::ValueForCustomProperty(
if (!parsed_value) if (!parsed_value)
new_variable_data = nullptr; new_variable_data = nullptr;
} }
// If either parsing or resolution failed, and this property inherits,
// take inherited values instead of falling back on initial.
if (registration->Inherits() && !new_variable_data) {
new_variable_data = state_.ParentStyle()->GetVariable(name, true);
parsed_value = state_.ParentStyle()->GetRegisteredVariable(name, true);
}
DCHECK(!!new_variable_data == !!parsed_value);
SetVariable(name, registration, new_variable_data); SetVariable(name, registration, new_variable_data);
SetRegisteredVariable(name, *registration, parsed_value); SetRegisteredVariable(name, *registration, parsed_value);
if (!new_variable_data) if (!new_variable_data)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment