diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-07-02 13:27:25 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-02 13:27:25 -0700 |
commit | a77cc9950fb13ccd674a10e46c2327bfa0735dab (patch) | |
tree | 22747996c1896a36c4bb41ac15875e80a681bfca /components | |
parent | 307844a8c17aedc369388baf4d98b0f82c3b695b (diff) | |
parent | 30963dd74da5e9a0e2fd7c8d56ec23aa474e8dd3 (diff) | |
download | servo-a77cc9950fb13ccd674a10e46c2327bfa0735dab.tar.gz servo-a77cc9950fb13ccd674a10e46c2327bfa0735dab.zip |
Auto merge of #11972 - emilio:style-thingies, r=bholley
Staticize CASCADE_PROPERTIES, (temporarily) fix stylo path for animations, and introduce the long-term path to follow
<!-- Please describe your changes on the following line: -->
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
<!-- Either: -->
- [x] These changes do not require tests because refactoring + geckolib
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
@bholley: I was going to do this "the good way", but that involves quite a few properties, so I thought I'd rather unlock stylo before :)
r? @bholley
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="35" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/11972)
<!-- Reviewable:end -->
Diffstat (limited to 'components')
-rw-r--r-- | components/style/animation.rs | 63 | ||||
-rw-r--r-- | components/style/properties/data.py | 10 | ||||
-rw-r--r-- | components/style/properties/helpers.mako.rs | 2 | ||||
-rw-r--r-- | components/style/properties/helpers/animated_properties.mako.rs | 9 | ||||
-rw-r--r-- | components/style/properties/longhand/box.mako.rs | 46 | ||||
-rw-r--r-- | components/style/properties/properties.mako.rs | 186 | ||||
-rw-r--r-- | components/style/values.rs | 5 |
7 files changed, 155 insertions, 166 deletions
diff --git a/components/style/animation.rs b/components/style/animation.rs index 29cd2bfa06d..eb9dc9fd32d 100644 --- a/components/style/animation.rs +++ b/components/style/animation.rs @@ -253,10 +253,10 @@ impl PropertyAnimation { new_style: &mut C) -> Vec<PropertyAnimation> { let mut result = vec![]; - let box_style = new_style.as_servo().get_box(); - let transition_property = box_style.transition_property.0[transition_index]; - let timing_function = *box_style.transition_timing_function.0.get_mod(transition_index); - let duration = *box_style.transition_duration.0.get_mod(transition_index); + let box_style = new_style.get_box(); + let transition_property = box_style.transition_property_at(transition_index); + let timing_function = box_style.transition_timing_function_mod(transition_index); + let duration = box_style.transition_duration_mod(transition_index); if transition_property != TransitionProperty::All { @@ -333,23 +333,6 @@ impl PropertyAnimation { } } -/// Accesses an element of an array, "wrapping around" using modular arithmetic. This is needed -/// to handle [repeatable lists][lists] of differing lengths. -/// -/// [lists]: https://drafts.csswg.org/css-transitions/#animtype-repeatable-list -pub trait GetMod { - type Item; - fn get_mod(&self, i: usize) -> &Self::Item; -} - -impl<T> GetMod for Vec<T> { - type Item = T; - #[inline] - fn get_mod(&self, i: usize) -> &T { - &(*self)[i % self.len()] - } -} - /// Inserts transitions into the queue of running animations as applicable for /// the given style difference. This is called from the layout worker threads. /// Returns true if any animations were kicked off and false otherwise. @@ -362,7 +345,7 @@ pub fn start_transitions_if_applicable<Impl: SelectorImplExt>(new_animations_sen new_style: &mut Arc<Impl::ComputedValues>) -> bool { let mut had_animations = false; - for i in 0..new_style.get_box().transition_count() { + for i in 0..new_style.get_box().transition_property_count() { // Create any property animations, if applicable. let property_animations = PropertyAnimation::from_transition(i, old_style, Arc::make_mut(new_style)); for property_animation in property_animations { @@ -372,13 +355,13 @@ pub fn start_transitions_if_applicable<Impl: SelectorImplExt>(new_animations_sen property_animation.update(Arc::get_mut(new_style).unwrap(), 0.0); // Kick off the animation. + let box_style = new_style.get_box(); let now = time::precise_time_s(); - let box_style = new_style.as_servo().get_box(); let start_time = - now + (box_style.transition_delay.0.get_mod(i).seconds() as f64); + now + (box_style.transition_delay_mod(i).seconds() as f64); new_animations_sender .send(Animation::Transition(node, start_time, AnimationFrame { - duration: box_style.transition_duration.0.get_mod(i).seconds() as f64, + duration: box_style.transition_duration_mod(i).seconds() as f64, property_animation: property_animation, }, /* is_expired = */ false)).unwrap(); @@ -422,10 +405,10 @@ pub fn maybe_start_animations<Impl: SelectorImplExt>(context: &SharedStyleContex { let mut had_animations = false; - let box_style = new_style.as_servo().get_box(); - for (i, name) in box_style.animation_name.0.iter().enumerate() { + let box_style = new_style.get_box(); + for (i, name) in box_style.animation_name_iter().enumerate() { debug!("maybe_start_animations: name={}", name); - let total_duration = box_style.animation_duration.0.get_mod(i).seconds(); + let total_duration = box_style.animation_duration_mod(i).seconds(); if total_duration == 0. { continue } @@ -441,16 +424,16 @@ pub fn maybe_start_animations<Impl: SelectorImplExt>(context: &SharedStyleContex continue; } - let delay = box_style.animation_delay.0.get_mod(i).seconds(); + let delay = box_style.animation_delay_mod(i).seconds(); let now = time::precise_time_s(); let animation_start = now + delay as f64; - let duration = box_style.animation_duration.0.get_mod(i).seconds(); - let iteration_state = match *box_style.animation_iteration_count.0.get_mod(i) { + let duration = box_style.animation_duration_mod(i).seconds(); + let iteration_state = match box_style.animation_iteration_count_mod(i) { AnimationIterationCount::Infinite => KeyframesIterationState::Infinite, AnimationIterationCount::Number(n) => KeyframesIterationState::Finite(0, n), }; - let animation_direction = *box_style.animation_direction.0.get_mod(i); + let animation_direction = box_style.animation_direction_mod(i); let initial_direction = match animation_direction { AnimationDirection::normal | @@ -459,7 +442,7 @@ pub fn maybe_start_animations<Impl: SelectorImplExt>(context: &SharedStyleContex AnimationDirection::alternate_reverse => AnimationDirection::reverse, }; - let running_state = match *box_style.animation_play_state.0.get_mod(i) { + let running_state = match box_style.animation_play_state_mod(i) { AnimationPlayState::paused => KeyframesRunningState::Paused(0.), AnimationPlayState::running => KeyframesRunningState::Running, }; @@ -550,9 +533,9 @@ where Impl: SelectorImplExt, debug_assert!(!animation.steps.is_empty()); - let maybe_index = style.as_servo() - .get_box().animation_name.0.iter() - .position(|animation_name| name == animation_name); + let maybe_index = style.get_box() + .animation_name_iter() + .position(|animation_name| *name == animation_name); let index = match maybe_index { Some(index) => index, @@ -562,7 +545,7 @@ where Impl: SelectorImplExt, } }; - let total_duration = style.as_servo().get_box().animation_duration.0.get_mod(index).seconds() as f64; + let total_duration = style.get_box().animation_duration_mod(index).seconds() as f64; if total_duration == 0. { debug!("update_style_for_animation: zero duration for animation {:?}", name); return; @@ -642,9 +625,9 @@ where Impl: SelectorImplExt, // NB: The spec says that the timing function can be overwritten // from the keyframe style. - let mut timing_function = *style.as_servo().get_box().animation_timing_function.0.get_mod(index); - if !from_style.as_servo().get_box().animation_timing_function.0.is_empty() { - timing_function = from_style.as_servo().get_box().animation_timing_function.0[0]; + let mut timing_function = style.get_box().animation_timing_function_mod(index); + if from_style.get_box().animation_timing_function_count() != 0 { + timing_function = from_style.get_box().animation_timing_function_at(0); } let target_style = compute_style_for_animation_step(context, diff --git a/components/style/properties/data.py b/components/style/properties/data.py index 04da7ad225b..f7fd3eec1b7 100644 --- a/components/style/properties/data.py +++ b/components/style/properties/data.py @@ -47,7 +47,7 @@ class Keyword(object): class Longhand(object): def __init__(self, style_struct, name, animatable=None, derived_from=None, keyword=None, predefined_type=None, custom_cascade=False, experimental=False, internal=False, - need_clone=False, gecko_ffi_name=None): + need_clone=False, need_index=False, gecko_ffi_name=None): self.name = name self.keyword = keyword self.predefined_type = predefined_type @@ -57,7 +57,7 @@ class Longhand(object): 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() @@ -71,6 +71,12 @@ class Longhand(object): 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): diff --git a/components/style/properties/helpers.mako.rs b/components/style/properties/helpers.mako.rs index b704ef9784b..cd85567c856 100644 --- a/components/style/properties/helpers.mako.rs +++ b/components/style/properties/helpers.mako.rs @@ -225,6 +225,8 @@ } } + pub use self::${to_camel_case(name)} as SingleComputedValue; + define_css_keyword_enum! { ${to_camel_case(name)}: % for value in data.longhands_by_name[name].keyword.values_for(product): "${value}" => ${to_rust_ident(value)}, diff --git a/components/style/properties/helpers/animated_properties.mako.rs b/components/style/properties/helpers/animated_properties.mako.rs index 552f5b303c3..52b2e181f6a 100644 --- a/components/style/properties/helpers/animated_properties.mako.rs +++ b/components/style/properties/helpers/animated_properties.mako.rs @@ -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 diff --git a/components/style/properties/longhand/box.mako.rs b/components/style/properties/longhand/box.mako.rs index f9f2a4be97c..9ec51e960cd 100644 --- a/components/style/properties/longhand/box.mako.rs +++ b/components/style/properties/longhand/box.mako.rs @@ -7,8 +7,7 @@ <% data.new_style_struct("Box", inherited=False, - gecko_name="Display", - additional_methods=[Method("transition_count", "usize")]) %> + gecko_name="Display") %> // TODO(SimonSapin): don't parse `inline-table`, since we don't support it <%helpers:longhand name="display" @@ -285,7 +284,9 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", </%helpers:longhand> // TODO(pcwalton): Multiple transitions. -<%helpers:longhand name="transition-duration" animatable="False"> +<%helpers:longhand name="transition-duration" + need_index="True" + animatable="False"> use values::computed::ComputedValueAsSpecified; use values::specified::Time; @@ -343,7 +344,9 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", // TODO(pcwalton): Lots more timing functions. // TODO(pcwalton): Multiple transitions. -<%helpers:longhand name="transition-timing-function" animatable="False"> +<%helpers:longhand name="transition-timing-function" + need_index="True" + animatable="False"> use self::computed_value::{StartEnd, TransitionTimingFunction}; use euclid::point::Point2D; @@ -541,7 +544,9 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", } </%helpers:longhand> -<%helpers:longhand name="transition-property" animatable="False"> +<%helpers:longhand name="transition-property" + need_index="True" + animatable="False"> pub use self::computed_value::SingleComputedValue as SingleSpecifiedValue; pub use self::computed_value::T as SpecifiedValue; @@ -592,14 +597,18 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", } </%helpers:longhand> -<%helpers:longhand name="transition-delay" animatable="False"> +<%helpers:longhand name="transition-delay" + need_index="True" + animatable="False"> pub use properties::longhands::transition_duration::{SingleSpecifiedValue, SpecifiedValue}; pub use properties::longhands::transition_duration::{computed_value}; pub use properties::longhands::transition_duration::{get_initial_single_value}; pub use properties::longhands::transition_duration::{get_initial_value, parse, parse_one}; </%helpers:longhand> -<%helpers:longhand name="animation-name" animatable="False"> +<%helpers:longhand name="animation-name" + need_index="True" + animatable="False"> use values::computed::ComputedValueAsSpecified; pub mod computed_value { @@ -607,6 +616,8 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", use std::fmt; use string_cache::Atom; + pub use string_cache::Atom as SingleComputedValue; + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] pub struct T(pub Vec<Atom>); @@ -645,25 +656,33 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", impl ComputedValueAsSpecified for SpecifiedValue {} </%helpers:longhand> -<%helpers:longhand name="animation-duration" animatable="False"> +<%helpers:longhand name="animation-duration" + need_index="True" + animatable="False"> pub use super::transition_duration::computed_value; pub use super::transition_duration::{parse, get_initial_value}; pub use super::transition_duration::SpecifiedValue; </%helpers:longhand> -<%helpers:longhand name="animation-timing-function" animatable="False"> +<%helpers:longhand name="animation-timing-function" + need_index="True" + animatable="False"> pub use super::transition_timing_function::computed_value; pub use super::transition_timing_function::{parse, get_initial_value}; pub use super::transition_timing_function::SpecifiedValue; </%helpers:longhand> -<%helpers:longhand name="animation-iteration-count" animatable="False"> +<%helpers:longhand name="animation-iteration-count" + need_index="True" + animatable="False"> use values::computed::ComputedValueAsSpecified; pub mod computed_value { use cssparser::ToCss; use std::fmt; + pub use self::AnimationIterationCount as SingleComputedValue; + #[derive(Debug, Clone, PartialEq, HeapSizeOf)] pub enum AnimationIterationCount { Number(u32), @@ -728,18 +747,23 @@ ${helpers.single_keyword("overflow-x", "visible hidden scroll auto", ${helpers.keyword_list("animation-direction", "normal reverse alternate alternate-reverse", + need_index=True, animatable=False)} ${helpers.keyword_list("animation-play-state", "running paused", need_clone=True, + need_index=True, animatable=False)} ${helpers.keyword_list("animation-fill-mode", "none forwards backwards both", + need_index=True, animatable=False)} -<%helpers:longhand name="animation-delay" animatable="False"> +<%helpers:longhand name="animation-delay" + need_index="True" + animatable="False"> pub use super::transition_duration::computed_value; pub use super::transition_duration::{parse, get_initial_value}; pub use super::transition_duration::SpecifiedValue; diff --git a/components/style/properties/properties.mako.rs b/components/style/properties/properties.mako.rs index c42f973205c..1ba7dd932ea 100644 --- a/components/style/properties/properties.mako.rs +++ b/components/style/properties/properties.mako.rs @@ -1082,12 +1082,61 @@ pub mod style_struct_traits { #[allow(non_snake_case)] fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T; % endif + % if longhand.need_index: + #[allow(non_snake_case)] + fn ${longhand.ident}_count(&self) -> usize; + + #[allow(non_snake_case)] + fn ${longhand.ident}_at(&self, index: usize) + -> longhands::${longhand.ident}::computed_value::SingleComputedValue; + + #[allow(non_snake_case)] + #[inline] + fn ${longhand.ident}_iter<'a>(&'a self) + -> ${longhand.camel_case}Iter<'a, Self> { + ${longhand.camel_case}Iter { + style_struct: self, + current: 0, + max: self.${longhand.ident}_count(), + } + } + + #[allow(non_snake_case)] + #[inline] + fn ${longhand.ident}_mod(&self, index: usize) + -> longhands::${longhand.ident}::computed_value::SingleComputedValue { + self.${longhand.ident}_at(index % self.${longhand.ident}_count()) + } + % endif % endfor % for additional in style_struct.additional_methods: #[allow(non_snake_case)] ${additional.declare()} % endfor } + + % for longhand in style_struct.longhands: + % if longhand.need_index: + pub struct ${longhand.camel_case}Iter<'a, S: ${style_struct.trait_name} + 'static> { + style_struct: &'a S, + current: usize, + max: usize, + } + + impl<'a, S: ${style_struct.trait_name} + 'static> Iterator for ${longhand.camel_case}Iter<'a, S> { + type Item = longhands::${longhand.ident}::computed_value::SingleComputedValue; + + fn next(&mut self) -> Option<Self::Item> { + self.current += 1; + if self.current <= self.max { + Some(self.style_struct.${longhand.ident}_at(self.current - 1)) + } else { + None + } + } + } + % endif + % endfor % endfor } @@ -1126,65 +1175,39 @@ pub mod style_structs { impl super::style_struct_traits::${style_struct.trait_name} for ${style_struct.servo_struct_name} { % for longhand in style_struct.longhands: + #[inline] fn set_${longhand.ident}(&mut self, v: longhands::${longhand.ident}::computed_value::T) { self.${longhand.ident} = v; } + #[inline] fn copy_${longhand.ident}_from(&mut self, other: &Self) { self.${longhand.ident} = other.${longhand.ident}.clone(); } + % if longhand.need_clone: + #[inline] + fn clone_${longhand.ident}(&self) -> longhands::${longhand.ident}::computed_value::T { + self.${longhand.ident}.clone() + } + % endif + + % if longhand.need_index: + fn ${longhand.ident}_count(&self) -> usize { + self.${longhand.ident}.0.len() + } + + fn ${longhand.ident}_at(&self, index: usize) + -> longhands::${longhand.ident}::computed_value::SingleComputedValue { + self.${longhand.ident}.0[index].clone() + } + % endif % endfor % if style_struct.trait_name == "Border": % for side in ["top", "right", "bottom", "left"]: - fn clone_border_${side}_style(&self) -> longhands::border_${side}_style::computed_value::T { - self.border_${side}_style.clone() - } - fn border_${side}_has_nonzero_width(&self) -> bool { - self.border_${side}_width != ::app_units::Au(0) - } + fn border_${side}_has_nonzero_width(&self) -> bool { + self.border_${side}_width != ::app_units::Au(0) + } % endfor - % elif style_struct.trait_name == "Box": - #[inline] - fn clone_display(&self) -> longhands::display::computed_value::T { - self.display.clone() - } - #[inline] - fn clone_position(&self) -> longhands::position::computed_value::T { - self.position.clone() - } - #[inline] - fn clone_float(&self) -> longhands::float::computed_value::T { - self.float.clone() - } - #[inline] - fn clone_overflow_x(&self) -> longhands::overflow_x::computed_value::T { - self.overflow_x.clone() - } - #[inline] - fn clone_overflow_y(&self) -> longhands::overflow_y::computed_value::T { - self.overflow_y.clone() - } - #[inline] - fn clone_animation_play_state(&self) -> longhands::animation_play_state::computed_value::T { - self.animation_play_state.clone() - } - #[inline] - fn transition_count(&self) -> usize { - self.transition_property.0.len() - } - % elif style_struct.trait_name == "Color": - #[inline] - fn clone_color(&self) -> longhands::color::computed_value::T { - self.color.clone() - } % elif style_struct.trait_name == "Font": - #[inline] - fn clone_font_size(&self) -> longhands::font_size::computed_value::T { - self.font_size.clone() - } - #[inline] - fn clone_font_weight(&self) -> longhands::font_weight::computed_value::T { - self.font_weight.clone() - } fn compute_font_hash(&mut self) { // Corresponds to the fields in `gfx::font_template::FontTemplateDescriptor`. let mut hasher: FnvHasher = Default::default(); @@ -1193,43 +1216,11 @@ pub mod style_structs { self.font_family.hash(&mut hasher); self.hash = hasher.finish() } - % elif style_struct.trait_name == "InheritedBox": - #[inline] - fn clone_direction(&self) -> longhands::direction::computed_value::T { - self.direction.clone() - } - #[inline] - fn clone_writing_mode(&self) -> longhands::writing_mode::computed_value::T { - self.writing_mode.clone() - } - #[inline] - fn clone_text_orientation(&self) -> longhands::text_orientation::computed_value::T { - self.text_orientation.clone() - } - % elif style_struct.trait_name == "InheritedText" and product == "servo": - #[inline] - fn clone__servo_text_decorations_in_effect(&self) -> - longhands::_servo_text_decorations_in_effect::computed_value::T { - self._servo_text_decorations_in_effect.clone() - } % elif style_struct.trait_name == "Outline": #[inline] - fn clone_outline_style(&self) -> longhands::outline_style::computed_value::T { - self.outline_style.clone() - } - #[inline] fn outline_has_nonzero_width(&self) -> bool { self.outline_width != ::app_units::Au(0) } - % elif style_struct.trait_name == "Position": - #[inline] - fn clone_align_items(&self) -> longhands::align_items::computed_value::T { - self.align_items.clone() - } - #[inline] - fn clone_align_self(&self) -> longhands::align_self::computed_value::T { - self.align_self.clone() - } % elif style_struct.trait_name == "Text": <% text_decoration_field = 'text_decoration' if product == 'servo' else 'text_decoration_line' %> #[inline] @@ -1255,13 +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 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, @@ -1275,7 +1259,7 @@ pub trait ComputedValues : Debug + Clone + Send + Sync + 'static { fn initial_values() -> &'static Self; - fn do_cascade_property<F: FnOnce(&Vec<CascadePropertyFn<Self>>)>(f: F); + fn do_cascade_property<F: FnOnce(&[CascadePropertyFn<Self>])>(f: F); % for style_struct in data.active_style_structs(): fn clone_${style_struct.trait_name_lower}(&self) -> @@ -1310,9 +1294,6 @@ impl ComputedValues for ServoComputedValues { type Concrete${style_struct.trait_name} = style_structs::${style_struct.servo_struct_name}; % endfor - fn as_servo<'a>(&'a self) -> &'a ServoComputedValues { self } - 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, @@ -1346,8 +1327,9 @@ impl ComputedValues for ServoComputedValues { fn initial_values() -> &'static Self { &*INITIAL_SERVO_VALUES } - fn do_cascade_property<F: FnOnce(&Vec<CascadePropertyFn<Self>>)>(f: F) { - CASCADE_PROPERTY.with(|x| f(x)); + #[inline] + fn do_cascade_property<F: FnOnce(&[CascadePropertyFn<Self>])>(f: F) { + f(&CASCADE_PROPERTY) } % for style_struct in data.active_style_structs(): @@ -1747,19 +1729,11 @@ pub type CascadePropertyFn<C /*: ComputedValues */> = cacheable: &mut bool, error_reporter: &mut StdBox<ParseErrorReporter + Send>); -pub fn make_cascade_vec<C: ComputedValues>() -> Vec<CascadePropertyFn<C>> { - vec![ - % for property in data.longhands: - longhands::${property.ident}::cascade_property, - % endfor - ] -} - -// This is a thread-local rather than a lazy static to avoid atomic operations when cascading -// properties. -thread_local!(static CASCADE_PROPERTY: Vec<CascadePropertyFn<ServoComputedValues>> = { - make_cascade_vec::<ServoComputedValues>() -}); +static CASCADE_PROPERTY: [CascadePropertyFn<ServoComputedValues>; ${len(data.longhands)}] = [ + % for property in data.longhands: + longhands::${property.ident}::cascade_property, + % endfor +]; /// Performs the CSS cascade, computing new styles for an element from its parent style and /// optionally a cached related style. The arguments are: diff --git a/components/style/values.rs b/components/style/values.rs index 5dea6f3cb7a..007426be88f 100644 --- a/components/style/values.rs +++ b/components/style/values.rs @@ -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; |