Pass TraversalFlags from C++ into Rust.

MozReview-Commit-ID: EVUzgnL5coN
This commit is contained in:
Bobby Holley 2017-07-25 18:45:37 -07:00
parent c365a39104
commit ce295f6daf
9 changed files with 107 additions and 91 deletions

View file

@ -135,7 +135,8 @@ use style::stylesheets::{Origin, Stylesheet, StylesheetInDocument, UserAgentStyl
use style::stylist::{ExtraStyleData, Stylist};
use style::thread_state;
use style::timer::Timer;
use style::traversal::{DomTraversal, TraversalDriver, TraversalFlags};
use style::traversal::{DomTraversal, TraversalDriver};
use style::traversal_flags::TraversalFlags;
/// Information needed by the layout thread.
pub struct LayoutThread {

View file

@ -34,7 +34,8 @@ use stylist::Stylist;
use thread_state;
use time;
use timer::Timer;
use traversal::{DomTraversal, TraversalFlags};
use traversal::DomTraversal;
use traversal_flags::TraversalFlags;
pub use selectors::matching::QuirksMode;

View file

@ -33,7 +33,7 @@ use std::hash::Hash;
use std::ops::Deref;
use stylist::Stylist;
use thread_state;
use traversal::TraversalFlags;
use traversal_flags::TraversalFlags;
pub use style_traits::UnsafeNode;

View file

@ -6,7 +6,7 @@
#[cfg(feature = "gecko")]
use gecko_bindings::structs::nsRestyleHint;
use traversal::TraversalFlags;
use traversal_flags::TraversalFlags;
bitflags! {
/// The kind of restyle we need to do for a given element.

View file

@ -135,6 +135,7 @@ pub mod stylesheets;
pub mod thread_state;
pub mod timer;
pub mod traversal;
pub mod traversal_flags;
#[macro_use]
#[allow(non_camel_case_types)]
pub mod values;

View file

@ -19,6 +19,7 @@ use rule_tree::{CascadeLevel, StrongRuleNode};
use selector_parser::{PseudoElement, RestyleDamage};
use selectors::matching::ElementSelectorFlags;
use servo_arc::{Arc, ArcBorrow};
use traversal_flags;
/// Represents the result of comparing an element's old and new style.
pub struct StyleDifference {
@ -172,7 +173,7 @@ trait PrivateMatchMethods: TElement {
// running or not.
// TODO: We should check which @keyframes changed/added/deleted
// and update only animations corresponding to those @keyframes.
(context.shared.traversal_flags.for_css_rule_changes() &&
(context.shared.traversal_flags.contains(traversal_flags::ForCSSRuleChanges) &&
has_new_animation_style) ||
!old_box_style.animations_equals(&new_box_style) ||
(old_display_style == display::T::none &&
@ -302,7 +303,7 @@ trait PrivateMatchMethods: TElement {
pseudo: Option<&PseudoElement>)
-> ChildCascadeRequirement {
// Don't accumulate damage if we're in a restyle for reconstruction.
if shared_context.traversal_flags.for_reconstruct() {
if shared_context.traversal_flags.contains(traversal_flags::ForReconstruct) {
return ChildCascadeRequirement::MustCascadeChildren;
}
@ -499,7 +500,7 @@ pub trait MatchMethods : TElement {
}
// Don't accumulate damage if we're in a restyle for reconstruction.
if context.shared.traversal_flags.for_reconstruct() {
if context.shared.traversal_flags.contains(traversal_flags::ForReconstruct) {
return ChildCascadeRequirement::MustCascadeChildren;
}

View file

@ -13,6 +13,7 @@ use sharing::StyleSharingTarget;
use smallvec::SmallVec;
use style_resolver::StyleResolverForElement;
use stylist::RuleInclusion;
use traversal_flags::{TraversalFlags, self};
/// A per-traversal-level chunk of data. This is sent down by the traversal, and
/// currently only holds the dom depth for the bloom filter.
@ -27,45 +28,6 @@ pub struct PerLevelTraversalData {
pub current_dom_depth: usize,
}
bitflags! {
/// Flags that control the traversal process.
pub flags TraversalFlags: u8 {
/// Traverse only unstyled children.
const UNSTYLED_CHILDREN_ONLY = 0x01,
/// Traverse only elements for animation restyles.
const ANIMATION_ONLY = 0x02,
/// Traverse without generating any change hints.
const FOR_RECONSTRUCT = 0x04,
/// Traverse triggered by CSS rule changes.
///
/// Traverse and update all elements with CSS animations since
/// @keyframes rules may have changed
const FOR_CSS_RULE_CHANGES = 0x08,
}
}
impl TraversalFlags {
/// Returns true if the traversal is for animation-only restyles.
pub fn for_animation_only(&self) -> bool {
self.contains(ANIMATION_ONLY)
}
/// Returns true if the traversal is for unstyled children.
pub fn for_unstyled_children_only(&self) -> bool {
self.contains(UNSTYLED_CHILDREN_ONLY)
}
/// Returns true if the traversal is for a frame reconstruction.
pub fn for_reconstruct(&self) -> bool {
self.contains(FOR_RECONSTRUCT)
}
/// Returns true if the traversal is triggered by CSS rule changes.
pub fn for_css_rule_changes(&self) -> bool {
self.contains(FOR_CSS_RULE_CHANGES)
}
}
/// This structure exists to enforce that callers invoke pre_traverse, and also
/// to pass information from the pre-traversal into the primary traversal.
pub struct PreTraverseToken {
@ -208,12 +170,12 @@ pub trait DomTraversal<E: TElement> : Sync {
shared_context: &SharedStyleContext,
traversal_flags: TraversalFlags
) -> PreTraverseToken {
debug_assert!(!(traversal_flags.for_reconstruct() &&
traversal_flags.for_unstyled_children_only()),
debug_assert!(!(traversal_flags.contains(traversal_flags::ForReconstruct) &&
traversal_flags.contains(traversal_flags::UnstyledChildrenOnly)),
"must not specify FOR_RECONSTRUCT in combination with \
UNSTYLED_CHILDREN_ONLY");
if traversal_flags.for_unstyled_children_only() {
if traversal_flags.contains(traversal_flags::UnstyledChildrenOnly) {
if root.borrow_data().map_or(true, |d| d.has_styles() && d.styles.is_display_none()) {
return PreTraverseToken {
traverse: false,
@ -281,7 +243,7 @@ pub trait DomTraversal<E: TElement> : Sync {
return true;
}
if traversal_flags.for_reconstruct() {
if traversal_flags.contains(traversal_flags::ForReconstruct) {
return true;
}
@ -358,7 +320,7 @@ pub trait DomTraversal<E: TElement> : Sync {
//
// We also need to traverse nodes with explicit damage and no other
// restyle data, so that this damage can be cleared.
if (cfg!(feature = "servo") || traversal_flags.for_reconstruct()) &&
if (cfg!(feature = "servo") || traversal_flags.contains(traversal_flags::ForReconstruct)) &&
!data.restyle.damage.is_empty() {
return true;
}
@ -618,7 +580,7 @@ where
!propagated_hint.is_empty() ||
context.thread_local.is_initial_style() ||
data.restyle.reconstructed_self() ||
flags.for_reconstruct() ||
flags.contains(traversal_flags::ForReconstruct) ||
is_servo_nonincremental_layout();
traverse_children = traverse_children &&
@ -639,7 +601,7 @@ where
// If we are in a restyle for reconstruction, drop the existing restyle
// data here, since we won't need to perform a post-traversal to pick up
// any change hints.
if context.shared.traversal_flags.for_reconstruct() {
if context.shared.traversal_flags.contains(traversal_flags::ForReconstruct) {
data.clear_restyle_state();
}
@ -659,7 +621,7 @@ where
// The second case is when we are in a restyle for reconstruction, where we
// won't need to perform a post-traversal to pick up any change hints.
if data.styles.is_display_none() ||
context.shared.traversal_flags.for_reconstruct() {
context.shared.traversal_flags.contains(traversal_flags::ForReconstruct) {
unsafe { element.unset_dirty_descendants(); }
}
@ -822,7 +784,7 @@ where
// If we are in a restyle for reconstruction, there is no need to
// perform a post-traversal, so we don't need to set the dirty
// descendants bit on the parent.
if !flags.for_reconstruct() && !is_initial_style {
if !flags.contains(traversal_flags::ForReconstruct) && !is_initial_style {
if flags.for_animation_only() {
unsafe { element.set_animation_only_dirty_descendants(); }
} else {

View file

@ -0,0 +1,64 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
//! Flags that control the traversal process.
//!
//! We CamelCase rather than UPPER_CASING so that we can grep for the same
//! strings across gecko and servo.
#![allow(non_upper_case_globals)]
bitflags! {
/// Flags that control the traversal process.
pub flags TraversalFlags: u32 {
/// Traverse only elements for animation restyles.
const AnimationOnly = 1 << 0,
/// Traverse and update all elements with CSS animations since
/// @keyframes rules may have changed. Triggered by CSS rule changes.
const ForCSSRuleChanges = 1 << 1,
/// Traverse only unstyled children of the root and their descendants.
const UnstyledChildrenOnly = 1 << 2,
/// FIXME(bholley): This will go away.
const ForReconstruct = 1 << 3,
/// FIXME(bholley): This will go away.
const ForNewlyBoundElement = 1 << 4,
/// FIXME(bholley): This will go away.
const ForThrottledAnimationFlush = 1 << 5,
}
}
/// Asserts that all TraversalFlags flags have a matching ServoTraversalFlags value in gecko.
#[cfg(feature = "gecko")]
#[inline]
pub fn assert_traversal_flags_match() {
use gecko_bindings::structs;
macro_rules! check_traversal_flags {
( $( $a:ident => $b:ident ),*, ) => {
if cfg!(debug_assertions) {
let mut modes = TraversalFlags::all();
$(
assert_eq!(structs::$a as usize, $b.bits() as usize, stringify!($b));
modes.remove($b);
)*
assert_eq!(modes, TraversalFlags::empty(), "all TraversalFlags bits should have an assertion");
}
}
}
check_traversal_flags! {
ServoTraversalFlags_AnimationOnly => AnimationOnly,
ServoTraversalFlags_ForCSSRuleChanges => ForCSSRuleChanges,
ServoTraversalFlags_UnstyledChildrenOnly => UnstyledChildrenOnly,
ServoTraversalFlags_ForReconstruct => ForReconstruct,
ServoTraversalFlags_ForNewlyBoundElement => ForNewlyBoundElement,
ServoTraversalFlags_ForThrottledAnimationFlush => ForThrottledAnimationFlush,
}
}
impl TraversalFlags {
/// Returns true if the traversal is for animation-only restyles.
pub fn for_animation_only(&self) -> bool {
self.contains(AnimationOnly)
}
}