mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
style: Get rid of CurrentElementInfo.
It's out-of-band data I never liked, and the code has changed enough from when it was introduced, that now all of the information it stores can be local.
This commit is contained in:
parent
49fe3d1c9f
commit
6704122927
3 changed files with 13 additions and 72 deletions
|
@ -5,11 +5,11 @@
|
||||||
//! The context within which style is calculated.
|
//! The context within which style is calculated.
|
||||||
|
|
||||||
#[cfg(feature = "servo")] use animation::Animation;
|
#[cfg(feature = "servo")] use animation::Animation;
|
||||||
#[cfg(feature = "servo")] use animation::PropertyAnimation;
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use bloom::StyleBloom;
|
use bloom::StyleBloom;
|
||||||
use data::{EagerPseudoStyles, ElementData};
|
use data::{EagerPseudoStyles, ElementData};
|
||||||
use dom::{OpaqueNode, TNode, TElement, SendElement};
|
use dom::{TElement, SendElement};
|
||||||
|
#[cfg(feature = "servo")] use dom::OpaqueNode;
|
||||||
use euclid::ScaleFactor;
|
use euclid::ScaleFactor;
|
||||||
use euclid::Size2D;
|
use euclid::Size2D;
|
||||||
use fnv::FnvHashMap;
|
use fnv::FnvHashMap;
|
||||||
|
@ -285,23 +285,6 @@ impl ElementCascadeInputs {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Information about the current element being processed. We group this
|
|
||||||
/// together into a single struct within ThreadLocalStyleContext so that we can
|
|
||||||
/// instantiate and destroy it easily at the beginning and end of element
|
|
||||||
/// processing.
|
|
||||||
pub struct CurrentElementInfo {
|
|
||||||
/// The element being processed. Currently we use an OpaqueNode since we
|
|
||||||
/// only use this for identity checks, but we could use SendElement if there
|
|
||||||
/// were a good reason to.
|
|
||||||
element: OpaqueNode,
|
|
||||||
/// Whether the element is being styled for the first time.
|
|
||||||
is_initial_style: bool,
|
|
||||||
/// A Vec of possibly expired animations. Used only by Servo.
|
|
||||||
#[allow(dead_code)]
|
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
pub possibly_expired_animations: Vec<PropertyAnimation>,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Statistics gathered during the traversal. We gather statistics on each
|
/// Statistics gathered during the traversal. We gather statistics on each
|
||||||
/// thread and then combine them after the threads join via the Add
|
/// thread and then combine them after the threads join via the Add
|
||||||
/// implementation below.
|
/// implementation below.
|
||||||
|
@ -712,8 +695,6 @@ pub struct ThreadLocalStyleContext<E: TElement> {
|
||||||
pub selector_flags: SelectorFlagsMap<E>,
|
pub selector_flags: SelectorFlagsMap<E>,
|
||||||
/// Statistics about the traversal.
|
/// Statistics about the traversal.
|
||||||
pub statistics: TraversalStatistics,
|
pub statistics: TraversalStatistics,
|
||||||
/// Information related to the current element, non-None during processing.
|
|
||||||
pub current_element_info: Option<CurrentElementInfo>,
|
|
||||||
/// The struct used to compute and cache font metrics from style
|
/// The struct used to compute and cache font metrics from style
|
||||||
/// for evaluation of the font-relative em/ch units and font-size
|
/// for evaluation of the font-relative em/ch units and font-size
|
||||||
pub font_metrics_provider: E::FontMetricsProvider,
|
pub font_metrics_provider: E::FontMetricsProvider,
|
||||||
|
@ -736,7 +717,6 @@ impl<E: TElement> ThreadLocalStyleContext<E> {
|
||||||
tasks: SequentialTaskList(Vec::new()),
|
tasks: SequentialTaskList(Vec::new()),
|
||||||
selector_flags: SelectorFlagsMap::new(),
|
selector_flags: SelectorFlagsMap::new(),
|
||||||
statistics: TraversalStatistics::default(),
|
statistics: TraversalStatistics::default(),
|
||||||
current_element_info: None,
|
|
||||||
font_metrics_provider: E::FontMetricsProvider::create_from(shared),
|
font_metrics_provider: E::FontMetricsProvider::create_from(shared),
|
||||||
stack_limit_checker: StackLimitChecker::new(
|
stack_limit_checker: StackLimitChecker::new(
|
||||||
(STYLE_THREAD_STACK_SIZE_KB - STACK_SAFETY_MARGIN_KB) * 1024),
|
(STYLE_THREAD_STACK_SIZE_KB - STACK_SAFETY_MARGIN_KB) * 1024),
|
||||||
|
@ -754,55 +734,16 @@ impl<E: TElement> ThreadLocalStyleContext<E> {
|
||||||
tasks: SequentialTaskList(Vec::new()),
|
tasks: SequentialTaskList(Vec::new()),
|
||||||
selector_flags: SelectorFlagsMap::new(),
|
selector_flags: SelectorFlagsMap::new(),
|
||||||
statistics: TraversalStatistics::default(),
|
statistics: TraversalStatistics::default(),
|
||||||
current_element_info: None,
|
|
||||||
font_metrics_provider: E::FontMetricsProvider::create_from(shared),
|
font_metrics_provider: E::FontMetricsProvider::create_from(shared),
|
||||||
stack_limit_checker: StackLimitChecker::new(
|
stack_limit_checker: StackLimitChecker::new(
|
||||||
(STYLE_THREAD_STACK_SIZE_KB - STACK_SAFETY_MARGIN_KB) * 1024),
|
(STYLE_THREAD_STACK_SIZE_KB - STACK_SAFETY_MARGIN_KB) * 1024),
|
||||||
nth_index_cache: NthIndexCache::default(),
|
nth_index_cache: NthIndexCache::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "gecko")]
|
|
||||||
/// Notes when the style system starts traversing an element.
|
|
||||||
pub fn begin_element(&mut self, element: E, data: &ElementData) {
|
|
||||||
debug_assert!(self.current_element_info.is_none());
|
|
||||||
self.current_element_info = Some(CurrentElementInfo {
|
|
||||||
element: element.as_node().opaque(),
|
|
||||||
is_initial_style: !data.has_styles(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "servo")]
|
|
||||||
/// Notes when the style system starts traversing an element.
|
|
||||||
pub fn begin_element(&mut self, element: E, data: &ElementData) {
|
|
||||||
debug_assert!(self.current_element_info.is_none());
|
|
||||||
self.current_element_info = Some(CurrentElementInfo {
|
|
||||||
element: element.as_node().opaque(),
|
|
||||||
is_initial_style: !data.has_styles(),
|
|
||||||
possibly_expired_animations: Vec::new(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Notes when the style system finishes traversing an element.
|
|
||||||
pub fn end_element(&mut self, element: E) {
|
|
||||||
debug_assert!(self.current_element_info.is_some());
|
|
||||||
debug_assert!(self.current_element_info.as_ref().unwrap().element ==
|
|
||||||
element.as_node().opaque());
|
|
||||||
self.current_element_info = None;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if the current element being traversed is being styled for
|
|
||||||
/// the first time.
|
|
||||||
///
|
|
||||||
/// Panics if called while no element is being traversed.
|
|
||||||
pub fn is_initial_style(&self) -> bool {
|
|
||||||
self.current_element_info.as_ref().unwrap().is_initial_style
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<E: TElement> Drop for ThreadLocalStyleContext<E> {
|
impl<E: TElement> Drop for ThreadLocalStyleContext<E> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
debug_assert!(self.current_element_info.is_none());
|
|
||||||
debug_assert!(thread_state::get() == ThreadState::LAYOUT);
|
debug_assert!(thread_state::get() == ThreadState::LAYOUT);
|
||||||
|
|
||||||
// Apply any slow selector flags that need to be set on parents.
|
// Apply any slow selector flags that need to be set on parents.
|
||||||
|
|
|
@ -298,13 +298,11 @@ trait PrivateMatchMethods: TElement {
|
||||||
use animation;
|
use animation;
|
||||||
use dom::TNode;
|
use dom::TNode;
|
||||||
|
|
||||||
let possibly_expired_animations =
|
let mut possibly_expired_animations = vec![];
|
||||||
&mut context.thread_local.current_element_info.as_mut().unwrap()
|
|
||||||
.possibly_expired_animations;
|
|
||||||
let shared_context = context.shared;
|
let shared_context = context.shared;
|
||||||
if let Some(ref mut old) = *old_values {
|
if let Some(ref mut old) = *old_values {
|
||||||
self.update_animations_for_cascade(shared_context, old,
|
self.update_animations_for_cascade(shared_context, old,
|
||||||
possibly_expired_animations,
|
&mut possibly_expired_animations,
|
||||||
&context.thread_local.font_metrics_provider);
|
&context.thread_local.font_metrics_provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -273,6 +273,7 @@ pub trait DomTraversal<E: TElement> : Sync {
|
||||||
&self,
|
&self,
|
||||||
context: &mut StyleContext<E>,
|
context: &mut StyleContext<E>,
|
||||||
parent: E,
|
parent: E,
|
||||||
|
is_initial_style: bool,
|
||||||
parent_data: &ElementData,
|
parent_data: &ElementData,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
debug_assert!(cfg!(feature = "gecko") ||
|
debug_assert!(cfg!(feature = "gecko") ||
|
||||||
|
@ -304,7 +305,7 @@ pub trait DomTraversal<E: TElement> : Sync {
|
||||||
// happens, we may just end up doing wasted work, since Gecko
|
// happens, we may just end up doing wasted work, since Gecko
|
||||||
// recursively drops Servo ElementData when the XBL insertion parent of
|
// recursively drops Servo ElementData when the XBL insertion parent of
|
||||||
// an Element is changed.
|
// an Element is changed.
|
||||||
if cfg!(feature = "gecko") && context.thread_local.is_initial_style() &&
|
if cfg!(feature = "gecko") && is_initial_style &&
|
||||||
parent_data.styles.primary().has_moz_binding()
|
parent_data.styles.primary().has_moz_binding()
|
||||||
{
|
{
|
||||||
debug!("Parent {:?} has XBL binding, deferring traversal", parent);
|
debug!("Parent {:?} has XBL binding, deferring traversal", parent);
|
||||||
|
@ -427,7 +428,8 @@ where
|
||||||
use traversal_flags::TraversalFlags;
|
use traversal_flags::TraversalFlags;
|
||||||
|
|
||||||
let flags = context.shared.traversal_flags;
|
let flags = context.shared.traversal_flags;
|
||||||
context.thread_local.begin_element(element, data);
|
let is_initial_style = !data.has_styles();
|
||||||
|
|
||||||
context.thread_local.statistics.elements_traversed += 1;
|
context.thread_local.statistics.elements_traversed += 1;
|
||||||
debug_assert!(flags.intersects(TraversalFlags::AnimationOnly | TraversalFlags::UnstyledOnly) ||
|
debug_assert!(flags.intersects(TraversalFlags::AnimationOnly | TraversalFlags::UnstyledOnly) ||
|
||||||
!element.has_snapshot() || element.handled_snapshot(),
|
!element.has_snapshot() || element.handled_snapshot(),
|
||||||
|
@ -524,8 +526,9 @@ where
|
||||||
data.reconstructed_self() ||
|
data.reconstructed_self() ||
|
||||||
is_servo_nonincremental_layout();
|
is_servo_nonincremental_layout();
|
||||||
|
|
||||||
traverse_children = traverse_children &&
|
traverse_children =
|
||||||
!traversal.should_cull_subtree(context, element, &data);
|
traverse_children &&
|
||||||
|
!traversal.should_cull_subtree(context, element, is_initial_style, &data);
|
||||||
|
|
||||||
// Examine our children, and enqueue the appropriate ones for traversal.
|
// Examine our children, and enqueue the appropriate ones for traversal.
|
||||||
if traverse_children {
|
if traverse_children {
|
||||||
|
@ -535,6 +538,7 @@ where
|
||||||
data,
|
data,
|
||||||
propagated_hint,
|
propagated_hint,
|
||||||
child_cascade_requirement,
|
child_cascade_requirement,
|
||||||
|
is_initial_style,
|
||||||
note_child
|
note_child
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -550,8 +554,6 @@ where
|
||||||
!element.has_animation_only_dirty_descendants(),
|
!element.has_animation_only_dirty_descendants(),
|
||||||
"Should have cleared animation bits already");
|
"Should have cleared animation bits already");
|
||||||
clear_state_after_traversing(element, data, flags);
|
clear_state_after_traversing(element, data, flags);
|
||||||
|
|
||||||
context.thread_local.end_element(element);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clear_state_after_traversing<E>(
|
fn clear_state_after_traversing<E>(
|
||||||
|
@ -776,6 +778,7 @@ fn note_children<E, D, F>(
|
||||||
data: &ElementData,
|
data: &ElementData,
|
||||||
propagated_hint: RestyleHint,
|
propagated_hint: RestyleHint,
|
||||||
cascade_requirement: ChildCascadeRequirement,
|
cascade_requirement: ChildCascadeRequirement,
|
||||||
|
is_initial_style: bool,
|
||||||
mut note_child: F,
|
mut note_child: F,
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
|
@ -785,7 +788,6 @@ where
|
||||||
{
|
{
|
||||||
trace!("note_children: {:?}", element);
|
trace!("note_children: {:?}", element);
|
||||||
let flags = context.shared.traversal_flags;
|
let flags = context.shared.traversal_flags;
|
||||||
let is_initial_style = context.thread_local.is_initial_style();
|
|
||||||
|
|
||||||
// Loop over all the traversal children.
|
// Loop over all the traversal children.
|
||||||
for child_node in element.traversal_children() {
|
for child_node in element.traversal_children() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue