Skip to content

Commit

Permalink
style: remove is_servo(), as_servo() and as_servo_mut()
Browse files Browse the repository at this point in the history
This commit adds a need_index prop to the style system, and autogenerates
iterators, and a get_xxx_mod(i) function from a get_xxx_prop() and
get_xxx_at(index) functions.

This allows us to (finally!) take rid of the as_servo() hack. There are a few
unimplemented clones, but I'm just too lazy for that right now.
  • Loading branch information
emilio committed Jul 1, 2016
1 parent ba53c4e commit 30963dd
Show file tree
Hide file tree
Showing 7 changed files with 296 additions and 81 deletions.
5 changes: 0 additions & 5 deletions components/style/animation.rs
Expand Up @@ -405,11 +405,6 @@ pub fn maybe_start_animations<Impl: SelectorImplExt>(context: &SharedStyleContex
{
let mut had_animations = false;

// FIXME(emilio): Implement animations for geckolib.
if !new_style.is_servo() {
return false;
}

let box_style = new_style.get_box();
for (i, name) in box_style.animation_name_iter().enumerate() {
debug!("maybe_start_animations: name={}", name);
Expand Down
7 changes: 6 additions & 1 deletion components/style/properties/data.py
Expand Up @@ -57,7 +57,6 @@ def __init__(self, style_struct, name, animatable=None, derived_from=None, keywo
self.experimental = ("layout.%s.enabled" % name) if experimental else None
self.custom_cascade = custom_cascade
self.internal = internal
self.need_clone = need_clone
self.need_index = need_index
self.gecko_ffi_name = gecko_ffi_name or "m" + self.camel_case
self.derived_from = (derived_from or "").split()
Expand All @@ -72,6 +71,12 @@ def __init__(self, style_struct, name, animatable=None, derived_from=None, keywo
assert animatable == "True" or animatable == "False"
self.animatable = animatable == "True"

# NB: Animatable implies clone because a property animation requires a
# copy of the computed value.
#
# See components/style/helpers/animated_properties.mako.rs.
self.need_clone = need_clone or self.animatable


class Shorthand(object):
def __init__(self, name, sub_properties, experimental=False, internal=False):
Expand Down
Expand Up @@ -127,22 +127,17 @@ impl AnimatedProperty {
}
}

// NB: Transition properties need clone
pub fn from_transition_property<C: ComputedValues>(transition_property: &TransitionProperty,
old_style: &C,
new_style: &C) -> AnimatedProperty {
// TODO: Generalise this for GeckoLib, adding clone_xxx to the
// appropiate longhands.
let old_style = old_style.as_servo();
let new_style = new_style.as_servo();
match *transition_property {
TransitionProperty::All => panic!("Can't use TransitionProperty::All here."),
% for prop in data.longhands:
% if prop.animatable:
TransitionProperty::${prop.camel_case} => {
AnimatedProperty::${prop.camel_case}(
old_style.get_${prop.style_struct.ident.strip("_")}().${prop.ident}.clone(),
new_style.get_${prop.style_struct.ident.strip("_")}().${prop.ident}.clone())
old_style.get_${prop.style_struct.ident.strip("_")}().clone_${prop.ident}(),
new_style.get_${prop.style_struct.ident.strip("_")}().clone_${prop.ident}())
}
% endif
% endfor
Expand Down
15 changes: 0 additions & 15 deletions components/style/properties/properties.mako.rs
Expand Up @@ -1246,14 +1246,6 @@ pub trait ComputedValues : Debug + Clone + Send + Sync + 'static {
type Concrete${style_struct.trait_name}: style_struct_traits::${style_struct.trait_name};
% endfor

// Temporary bailout case for stuff we haven't made work with the trait
// yet - panics for non-Servo implementations.
//
// Used only for animations. Don't use it in other places.
fn is_servo(&self) -> bool;
fn as_servo<'a>(&'a self) -> &'a ServoComputedValues;
fn as_servo_mut<'a>(&'a mut self) -> &'a mut ServoComputedValues;

fn new(custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
shareable: bool,
writing_mode: WritingMode,
Expand Down Expand Up @@ -1302,13 +1294,6 @@ impl ComputedValues for ServoComputedValues {
type Concrete${style_struct.trait_name} = style_structs::${style_struct.servo_struct_name};
% endfor

#[inline]
fn is_servo(&self) -> bool { true }
#[inline]
fn as_servo<'a>(&'a self) -> &'a ServoComputedValues { self }
#[inline]
fn as_servo_mut<'a>(&'a mut self) -> &'a mut ServoComputedValues { self }

fn new(custom_properties: Option<Arc<::custom_properties::ComputedValuesMap>>,
shareable: bool,
writing_mode: WritingMode,
Expand Down
5 changes: 5 additions & 0 deletions components/style/values.rs
Expand Up @@ -1194,6 +1194,11 @@ pub mod specified {
pub fn radians(self) -> f32 {
self.0
}

#[inline]
pub fn from_radians(r: f32) -> Self {
Angle(r)
}
}

const RAD_PER_DEG: CSSFloat = PI / 180.0;
Expand Down

0 comments on commit 30963dd

Please sign in to comment.