Skip to content

Commit

Permalink
Use IntermediateRGBA to store overflowed RGBA components during inter…
Browse files Browse the repository at this point in the history
…polation.
  • Loading branch information
Hiroyuki Ikezoe committed Apr 24, 2017
1 parent e47d30f commit d70e4aa
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 8 deletions.
6 changes: 2 additions & 4 deletions components/style/properties/data.py
Expand Up @@ -178,13 +178,11 @@ def __init__(self, style_struct, name, spec=None, animation_value_type=None, der
# really random.
if animation_value_type is None:
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.animatable = animation_value_type != "none"
self.is_animatable_with_computed_value = animation_value_type == "ComputedValue" \
or animation_value_type == "discrete"
if self.logical:
# Logical properties will be animatable (i.e. the animation type is
# discrete). For now, it is still non-animatable.
Expand Down
49 changes: 46 additions & 3 deletions components/style/properties/helpers/animated_properties.mako.rs
Expand Up @@ -384,7 +384,11 @@ pub enum AnimationValue {
% for prop in data.longhands:
% if prop.animatable:
/// ${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
% endfor
}
Expand All @@ -402,7 +406,13 @@ impl AnimationValue {
% if prop.boxed:
Box::new(longhands::${prop.ident}::SpecifiedValue::from_computed_value(from)))
% 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
Expand All @@ -426,7 +436,13 @@ impl AnimationValue {
longhands::system_font::resolve_system_font(sf, context);
}
% 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
% endfor
Expand Down Expand Up @@ -454,6 +470,9 @@ impl AnimationValue {
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))
},
% endif
Expand Down Expand Up @@ -514,7 +533,12 @@ impl AnimationValue {
% if prop.animatable:
TransitionProperty::${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}())
% else:
From::from(&computed_values.get_${prop.style_struct.ident.strip("_")}()
.clone_${prop.ident}()))
% endif
}
% endif
% endfor
Expand Down Expand Up @@ -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)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
/// Unlike RGBA, each component value may exceed the range [0.0, 1.0].
Expand Down
3 changes: 2 additions & 1 deletion components/style/properties/longhand/color.mako.rs
Expand Up @@ -8,7 +8,8 @@

<% 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">
use cssparser::RGBA;
use std::fmt;
Expand Down

0 comments on commit d70e4aa

Please sign in to comment.