Source code

Revision control

Other Tools

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5
//! Flags that control the traversal process.
6
//!
7
//! We CamelCase rather than UPPER_CASING so that we can grep for the same
8
//! strings across gecko and servo.
9
#![allow(non_upper_case_globals)]
10
11
bitflags! {
12
/// Flags that control the traversal process.
13
pub struct TraversalFlags: u32 {
14
/// Traverse only elements for animation restyles.
15
const AnimationOnly = 1 << 0;
16
/// Traverse and update all elements with CSS animations since
17
/// @keyframes rules may have changed. Triggered by CSS rule changes.
18
const ForCSSRuleChanges = 1 << 1;
19
/// The final animation-only traversal, which shouldn't really care about other
20
/// style changes anymore.
21
const FinalAnimationTraversal = 1 << 2;
22
/// Allows the traversal to run in parallel if there are sufficient cores on
23
/// the machine.
24
const ParallelTraversal = 1 << 7;
25
/// Flush throttled animations. By default, we only update throttled animations
26
/// when we have other non-throttled work to do. With this flag, we
27
/// unconditionally tick and process them.
28
const FlushThrottledAnimations = 1 << 8;
29
30
}
31
}
32
33
/// Asserts that all TraversalFlags flags have a matching ServoTraversalFlags value in gecko.
34
#[cfg(feature = "gecko")]
35
#[inline]
36
pub fn assert_traversal_flags_match() {
37
use crate::gecko_bindings::structs;
38
39
macro_rules! check_traversal_flags {
40
( $( $a:ident => $b:path ),*, ) => {
41
if cfg!(debug_assertions) {
42
let mut modes = TraversalFlags::all();
43
$(
44
assert_eq!(structs::$a as usize, $b.bits() as usize, stringify!($b));
45
modes.remove($b);
46
)*
47
assert_eq!(modes, TraversalFlags::empty(), "all TraversalFlags bits should have an assertion");
48
}
49
}
50
}
51
52
check_traversal_flags! {
53
ServoTraversalFlags_AnimationOnly => TraversalFlags::AnimationOnly,
54
ServoTraversalFlags_ForCSSRuleChanges => TraversalFlags::ForCSSRuleChanges,
55
ServoTraversalFlags_FinalAnimationTraversal => TraversalFlags::FinalAnimationTraversal,
56
ServoTraversalFlags_ParallelTraversal => TraversalFlags::ParallelTraversal,
57
ServoTraversalFlags_FlushThrottledAnimations => TraversalFlags::FlushThrottledAnimations,
58
}
59
}
60
61
impl TraversalFlags {
62
/// Returns true if the traversal is for animation-only restyles.
63
#[inline]
64
pub fn for_animation_only(&self) -> bool {
65
self.contains(TraversalFlags::AnimationOnly)
66
}
67
}