mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
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 -->
This commit is contained in:
commit
a77cc9950f
9 changed files with 452 additions and 226 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue