mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Use IntermediateRGBA to store overflowed RGBA components during interpolation.
This commit is contained in:
parent
e47d30f668
commit
d70e4aa229
3 changed files with 50 additions and 8 deletions
|
@ -178,13 +178,11 @@ class Longhand(object):
|
||||||
# really random.
|
# really random.
|
||||||
if animation_value_type is None:
|
if animation_value_type is None:
|
||||||
raise TypeError("animation_value_type should be specified for (" + name + ")")
|
raise TypeError("animation_value_type should be specified for (" + name + ")")
|
||||||
animation_value_types = ["none", "discrete", "ComputedValue"]
|
|
||||||
if animation_value_type not in animation_value_types:
|
|
||||||
raise TypeError("animation_value_type should be one of (" +
|
|
||||||
str(animation_value_types) + ")")
|
|
||||||
self.animation_value_type = animation_value_type
|
self.animation_value_type = animation_value_type
|
||||||
|
|
||||||
self.animatable = animation_value_type != "none"
|
self.animatable = animation_value_type != "none"
|
||||||
|
self.is_animatable_with_computed_value = animation_value_type == "ComputedValue" \
|
||||||
|
or animation_value_type == "discrete"
|
||||||
if self.logical:
|
if self.logical:
|
||||||
# Logical properties will be animatable (i.e. the animation type is
|
# Logical properties will be animatable (i.e. the animation type is
|
||||||
# discrete). For now, it is still non-animatable.
|
# discrete). For now, it is still non-animatable.
|
||||||
|
|
|
@ -384,7 +384,11 @@ pub enum AnimationValue {
|
||||||
% for prop in data.longhands:
|
% for prop in data.longhands:
|
||||||
% if prop.animatable:
|
% if prop.animatable:
|
||||||
/// ${prop.name}
|
/// ${prop.name}
|
||||||
${prop.camel_case}(longhands::${prop.ident}::computed_value::T),
|
% if prop.is_animatable_with_computed_value:
|
||||||
|
${prop.camel_case}(longhands::${prop.ident}::computed_value::T),
|
||||||
|
% else:
|
||||||
|
${prop.camel_case}(${prop.animation_value_type}),
|
||||||
|
% endif
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
}
|
}
|
||||||
|
@ -402,7 +406,13 @@ impl AnimationValue {
|
||||||
% if prop.boxed:
|
% if prop.boxed:
|
||||||
Box::new(longhands::${prop.ident}::SpecifiedValue::from_computed_value(from)))
|
Box::new(longhands::${prop.ident}::SpecifiedValue::from_computed_value(from)))
|
||||||
% else:
|
% else:
|
||||||
longhands::${prop.ident}::SpecifiedValue::from_computed_value(from))
|
longhands::${prop.ident}::SpecifiedValue::from_computed_value(
|
||||||
|
% if prop.is_animatable_with_computed_value:
|
||||||
|
from
|
||||||
|
% else:
|
||||||
|
&from.into()
|
||||||
|
% endif
|
||||||
|
))
|
||||||
% endif
|
% endif
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
|
@ -426,7 +436,13 @@ impl AnimationValue {
|
||||||
longhands::system_font::resolve_system_font(sf, context);
|
longhands::system_font::resolve_system_font(sf, context);
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
Some(AnimationValue::${prop.camel_case}(val.to_computed_value(context)))
|
Some(AnimationValue::${prop.camel_case}(
|
||||||
|
% if prop.is_animatable_with_computed_value:
|
||||||
|
val.to_computed_value(context)
|
||||||
|
% else:
|
||||||
|
From::from(&val.to_computed_value(context))
|
||||||
|
% endif
|
||||||
|
))
|
||||||
},
|
},
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -454,6 +470,9 @@ impl AnimationValue {
|
||||||
inherit_struct.clone_${prop.ident}()
|
inherit_struct.clone_${prop.ident}()
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
% if not prop.is_animatable_with_computed_value:
|
||||||
|
let computed = From::from(&computed);
|
||||||
|
% endif
|
||||||
Some(AnimationValue::${prop.camel_case}(computed))
|
Some(AnimationValue::${prop.camel_case}(computed))
|
||||||
},
|
},
|
||||||
% endif
|
% endif
|
||||||
|
@ -514,7 +533,12 @@ impl AnimationValue {
|
||||||
% if prop.animatable:
|
% if prop.animatable:
|
||||||
TransitionProperty::${prop.camel_case} => {
|
TransitionProperty::${prop.camel_case} => {
|
||||||
AnimationValue::${prop.camel_case}(
|
AnimationValue::${prop.camel_case}(
|
||||||
|
% if prop.is_animatable_with_computed_value:
|
||||||
computed_values.get_${prop.style_struct.ident.strip("_")}().clone_${prop.ident}())
|
computed_values.get_${prop.style_struct.ident.strip("_")}().clone_${prop.ident}())
|
||||||
|
% else:
|
||||||
|
From::from(&computed_values.get_${prop.style_struct.ident.strip("_")}()
|
||||||
|
.clone_${prop.ident}()))
|
||||||
|
% endif
|
||||||
}
|
}
|
||||||
% endif
|
% endif
|
||||||
% endfor
|
% endfor
|
||||||
|
@ -2041,6 +2065,25 @@ impl<T, U> Interpolate for Either<T, U>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl <'a> From<<&'a IntermediateRGBA> for RGBA {
|
||||||
|
fn from(extended_rgba: &IntermediateRGBA) -> RGBA {
|
||||||
|
// RGBA::from_floats clamps each component values.
|
||||||
|
RGBA::from_floats(extended_rgba.red,
|
||||||
|
extended_rgba.green,
|
||||||
|
extended_rgba.blue,
|
||||||
|
extended_rgba.alpha)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl <'a> From<<&'a RGBA> for IntermediateRGBA {
|
||||||
|
fn from(rgba: &RGBA) -> IntermediateRGBA {
|
||||||
|
IntermediateRGBA::new(rgba.red_f32(),
|
||||||
|
rgba.green_f32(),
|
||||||
|
rgba.blue_f32(),
|
||||||
|
rgba.alpha_f32())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq)]
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
||||||
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
|
||||||
/// Unlike RGBA, each component value may exceed the range [0.0, 1.0].
|
/// Unlike RGBA, each component value may exceed the range [0.0, 1.0].
|
||||||
|
|
|
@ -8,7 +8,8 @@
|
||||||
|
|
||||||
<% from data import to_rust_ident %>
|
<% from data import to_rust_ident %>
|
||||||
|
|
||||||
<%helpers:longhand name="color" need_clone="True" animation_value_type="ComputedValue"
|
<%helpers:longhand name="color" need_clone="True"
|
||||||
|
animation_value_type="IntermediateRGBA"
|
||||||
spec="https://drafts.csswg.org/css-color/#color">
|
spec="https://drafts.csswg.org/css-color/#color">
|
||||||
use cssparser::RGBA;
|
use cssparser::RGBA;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue