зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1738658 - Generalize resolved style code to deal with all shorthands. r=jwatt
This removes the various assumptions that the animation code does. Code size might be a concern, we can optimize if it is a problem, but let's do the obvious thing for now. Differential Revision: https://phabricator.services.mozilla.com/D130017
This commit is contained in:
Родитель
47a4e47af2
Коммит
ac72dbe343
|
@ -3084,7 +3084,10 @@ impl ComputedValues {
|
|||
///
|
||||
/// Note that the value will usually be the computed value, except for
|
||||
/// colors, where it's resolved.
|
||||
pub fn get_longhand_property_value<W>(
|
||||
///
|
||||
/// TODO(emilio): We should move all the special resolution from
|
||||
/// nsComputedDOMStyle to ToResolvedValue instead.
|
||||
pub fn get_resolved_value<W>(
|
||||
&self,
|
||||
property_id: LonghandId,
|
||||
dest: &mut CssWriter<W>
|
||||
|
@ -3110,6 +3113,31 @@ impl ComputedValues {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the given longhand's resolved value as a property declaration.
|
||||
pub fn resolved_declaration(&self, property_id: LonghandId) -> PropertyDeclaration {
|
||||
use crate::values::resolved::ToResolvedValue;
|
||||
use crate::values::computed::ToComputedValue;
|
||||
|
||||
let context = resolved::Context {
|
||||
style: self,
|
||||
};
|
||||
|
||||
match property_id {
|
||||
% for prop in data.longhands:
|
||||
LonghandId::${prop.camel_case} => {
|
||||
let value = self.clone_${prop.ident}();
|
||||
let resolved = value.to_resolved_value(&context);
|
||||
%if prop.boxed:
|
||||
let resolved = Box::new(resolved);
|
||||
%endif
|
||||
let computed = ToResolvedValue::from_resolved_value(resolved);
|
||||
let specified = ToComputedValue::from_computed_value(&computed);
|
||||
PropertyDeclaration::${prop.camel_case}(specified)
|
||||
}
|
||||
% endfor
|
||||
}
|
||||
}
|
||||
|
||||
/// Resolves the currentColor keyword.
|
||||
///
|
||||
/// Any color value from computed values (except for the 'color' property
|
||||
|
|
|
@ -4097,8 +4097,7 @@ fn dump_properties_and_rules(cv: &ComputedValues, properties: &LonghandIdSet) {
|
|||
println_stderr!(" Properties:");
|
||||
for p in properties.iter() {
|
||||
let mut v = String::new();
|
||||
cv.get_longhand_property_value(p, &mut CssWriter::new(&mut v))
|
||||
.unwrap();
|
||||
cv.get_resolved_value(p, &mut CssWriter::new(&mut v)).unwrap();
|
||||
println_stderr!(" {:?}: {}", p, v);
|
||||
}
|
||||
println_stderr!(" Rules:");
|
||||
|
@ -6467,31 +6466,15 @@ pub unsafe extern "C" fn Servo_GetPropertyValue(
|
|||
value: &mut nsACString,
|
||||
) {
|
||||
if let Ok(longhand) = LonghandId::from_nscsspropertyid(prop) {
|
||||
style
|
||||
.get_longhand_property_value(longhand, &mut CssWriter::new(value))
|
||||
.unwrap();
|
||||
style.get_resolved_value(longhand, &mut CssWriter::new(value)).unwrap();
|
||||
return;
|
||||
}
|
||||
|
||||
let shorthand =
|
||||
ShorthandId::from_nscsspropertyid(prop).expect("Not a shorthand nor a longhand?");
|
||||
let mut block = PropertyDeclarationBlock::new();
|
||||
// NOTE(emilio): We reuse the animation value machinery to avoid blowing up
|
||||
// code size, but may need to come up with something different if ever care
|
||||
// about supporting the cases that assert below. Fortunately we don't right
|
||||
// now.
|
||||
for longhand in shorthand.longhands() {
|
||||
debug_assert!(
|
||||
!longhand.is_logical(),
|
||||
"This won't quite do the right thing if we want to serialize \
|
||||
logical shorthands"
|
||||
);
|
||||
let animated = AnimationValue::from_computed_values(longhand, style).expect(
|
||||
"Somebody tried to serialize a shorthand with \
|
||||
non-animatable properties, would need more code \
|
||||
to do this",
|
||||
);
|
||||
block.push(animated.uncompute(), Importance::Normal);
|
||||
block.push(style.resolved_declaration(longhand), Importance::Normal);
|
||||
}
|
||||
block.shorthand_to_css(shorthand, value).unwrap();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче