mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
style: Refactor the per_pseudo map from StyleData to avoid having an option value type.
This make the layout code way clearer.
This commit is contained in:
parent
a604d605ed
commit
61e04df266
7 changed files with 52 additions and 52 deletions
|
@ -49,7 +49,7 @@ bitflags! {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TRestyleDamage for RestyleDamage {
|
impl TRestyleDamage for RestyleDamage {
|
||||||
fn compute(old: &Option<Arc<ComputedValues>>, new: &ComputedValues) -> RestyleDamage { compute_damage(old, new) }
|
fn compute(old: Option<&Arc<ComputedValues>>, new: &ComputedValues) -> RestyleDamage { compute_damage(old, new) }
|
||||||
|
|
||||||
/// Returns a bitmask that represents a flow that needs to be rebuilt and reflowed.
|
/// Returns a bitmask that represents a flow that needs to be rebuilt and reflowed.
|
||||||
///
|
///
|
||||||
|
@ -143,12 +143,11 @@ macro_rules! add_if_not_equal(
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
pub fn compute_damage(old: &Option<Arc<ComputedValues>>, new: &ComputedValues) -> RestyleDamage {
|
pub fn compute_damage(old: Option<&Arc<ComputedValues>>, new: &ComputedValues) -> RestyleDamage {
|
||||||
let old: &ComputedValues =
|
let old: &ComputedValues = match old {
|
||||||
match old.as_ref() {
|
None => return RestyleDamage::rebuild_and_reflow(),
|
||||||
None => return RestyleDamage::rebuild_and_reflow(),
|
Some(cv) => &**cv,
|
||||||
Some(cv) => &**cv,
|
};
|
||||||
};
|
|
||||||
|
|
||||||
let mut damage = RestyleDamage::empty();
|
let mut damage = RestyleDamage::empty();
|
||||||
|
|
||||||
|
|
|
@ -666,7 +666,8 @@ pub trait ThreadSafeLayoutNode<'ln> : Clone + Copy + Sized {
|
||||||
fn get_before_pseudo(&self) -> Option<Self> {
|
fn get_before_pseudo(&self) -> Option<Self> {
|
||||||
self.borrow_layout_data().unwrap()
|
self.borrow_layout_data().unwrap()
|
||||||
.style_data.per_pseudo
|
.style_data.per_pseudo
|
||||||
.get(&PseudoElement::Before).unwrap_or(&None).as_ref().map(|style| {
|
.get(&PseudoElement::Before)
|
||||||
|
.map(|style| {
|
||||||
self.with_pseudo(PseudoElementType::Before(style.get_box().display))
|
self.with_pseudo(PseudoElementType::Before(style.get_box().display))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -675,7 +676,8 @@ pub trait ThreadSafeLayoutNode<'ln> : Clone + Copy + Sized {
|
||||||
fn get_after_pseudo(&self) -> Option<Self> {
|
fn get_after_pseudo(&self) -> Option<Self> {
|
||||||
self.borrow_layout_data().unwrap()
|
self.borrow_layout_data().unwrap()
|
||||||
.style_data.per_pseudo
|
.style_data.per_pseudo
|
||||||
.get(&PseudoElement::After).unwrap_or(&None).as_ref().map(|style| {
|
.get(&PseudoElement::After)
|
||||||
|
.map(|style| {
|
||||||
self.with_pseudo(PseudoElementType::After(style.get_box().display))
|
self.with_pseudo(PseudoElementType::After(style.get_box().display))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -700,11 +702,11 @@ pub trait ThreadSafeLayoutNode<'ln> : Clone + Copy + Sized {
|
||||||
fn style(&self) -> Ref<Arc<ComputedValues>> {
|
fn style(&self) -> Ref<Arc<ComputedValues>> {
|
||||||
Ref::map(self.borrow_layout_data().unwrap(), |data| {
|
Ref::map(self.borrow_layout_data().unwrap(), |data| {
|
||||||
let style = match self.get_pseudo_element_type() {
|
let style = match self.get_pseudo_element_type() {
|
||||||
PseudoElementType::Before(_) => data.style_data.per_pseudo.get(&PseudoElement::Before).unwrap(),
|
PseudoElementType::Before(_) => data.style_data.per_pseudo.get(&PseudoElement::Before),
|
||||||
PseudoElementType::After(_) => data.style_data.per_pseudo.get(&PseudoElement::After).unwrap(),
|
PseudoElementType::After(_) => data.style_data.per_pseudo.get(&PseudoElement::After),
|
||||||
PseudoElementType::Normal => &data.style_data.style,
|
PseudoElementType::Normal => data.style_data.style.as_ref(),
|
||||||
};
|
};
|
||||||
style.as_ref().unwrap()
|
style.unwrap()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -713,24 +715,18 @@ pub trait ThreadSafeLayoutNode<'ln> : Clone + Copy + Sized {
|
||||||
/// Unlike the version on TNode, this handles pseudo-elements.
|
/// Unlike the version on TNode, this handles pseudo-elements.
|
||||||
fn unstyle(self) {
|
fn unstyle(self) {
|
||||||
let mut data = self.mutate_layout_data().unwrap();
|
let mut data = self.mutate_layout_data().unwrap();
|
||||||
let style =
|
|
||||||
match self.get_pseudo_element_type() {
|
|
||||||
PseudoElementType::Before(_) => {
|
|
||||||
match data.style_data.per_pseudo.get_mut(&PseudoElement::Before) {
|
|
||||||
None => return,
|
|
||||||
Some(style) => style,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PseudoElementType::After(_) => {
|
|
||||||
match data.style_data.per_pseudo.get_mut(&PseudoElement::After) {
|
|
||||||
None => return,
|
|
||||||
Some(style) => style,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
PseudoElementType::Normal => &mut data.style_data.style,
|
|
||||||
};
|
|
||||||
|
|
||||||
*style = None;
|
match self.get_pseudo_element_type() {
|
||||||
|
PseudoElementType::Before(_) => {
|
||||||
|
data.style_data.per_pseudo.remove(&PseudoElement::Before);
|
||||||
|
}
|
||||||
|
PseudoElementType::After(_) => {
|
||||||
|
data.style_data.per_pseudo.remove(&PseudoElement::After);
|
||||||
|
}
|
||||||
|
PseudoElementType::Normal => {
|
||||||
|
data.style_data.style = None;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_ignorable_whitespace(&self) -> bool;
|
fn is_ignorable_whitespace(&self) -> bool;
|
||||||
|
@ -953,7 +949,7 @@ impl<'ln> ThreadSafeLayoutNode<'ln> for ServoThreadSafeLayoutNode<'ln> {
|
||||||
data.per_pseudo.get(&PseudoElement::After).unwrap()
|
data.per_pseudo.get(&PseudoElement::After).unwrap()
|
||||||
};
|
};
|
||||||
|
|
||||||
return match style.as_ref().unwrap().get_box().content {
|
return match style.as_ref().get_box().content {
|
||||||
content::T::Content(ref value) if !value.is_empty() => {
|
content::T::Content(ref value) if !value.is_empty() => {
|
||||||
TextContent::GeneratedContent((*value).clone())
|
TextContent::GeneratedContent((*value).clone())
|
||||||
}
|
}
|
||||||
|
|
|
@ -979,7 +979,7 @@ pub fn update_style_for_animation<ConcreteRestyleDamage: TRestyleDamage>(animati
|
||||||
let mut new_style = (*style).clone();
|
let mut new_style = (*style).clone();
|
||||||
animation.property_animation.update(&mut *Arc::make_mut(&mut new_style), progress);
|
animation.property_animation.update(&mut *Arc::make_mut(&mut new_style), progress);
|
||||||
if let Some(damage) = damage {
|
if let Some(damage) = damage {
|
||||||
*damage = *damage | ConcreteRestyleDamage::compute(&Some((*style).clone()), &new_style);
|
*damage = *damage | ConcreteRestyleDamage::compute(Some(style), &new_style);
|
||||||
}
|
}
|
||||||
|
|
||||||
*style = new_style
|
*style = new_style
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub struct PrivateStyleData<Impl: SelectorImpl> {
|
||||||
pub style: Option<Arc<ComputedValues>>,
|
pub style: Option<Arc<ComputedValues>>,
|
||||||
|
|
||||||
/// The results of CSS styling for each pseudo-element (if any).
|
/// The results of CSS styling for each pseudo-element (if any).
|
||||||
pub per_pseudo: HashMap<Impl::PseudoElement, Option<Arc<ComputedValues>>, BuildHasherDefault<::fnv::FnvHasher>>,
|
pub per_pseudo: HashMap<Impl::PseudoElement, Arc<ComputedValues>, BuildHasherDefault<::fnv::FnvHasher>>,
|
||||||
|
|
||||||
/// Information needed during parallel traversals.
|
/// Information needed during parallel traversals.
|
||||||
pub parallel: DomParallelInfo,
|
pub parallel: DomParallelInfo,
|
||||||
|
|
|
@ -44,7 +44,7 @@ impl OpaqueNode {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TRestyleDamage : BitOr<Output=Self> + Copy {
|
pub trait TRestyleDamage : BitOr<Output=Self> + Copy {
|
||||||
fn compute(old: &Option<Arc<ComputedValues>>, new: &ComputedValues) -> Self;
|
fn compute(old: Option<&Arc<ComputedValues>>, new: &ComputedValues) -> Self;
|
||||||
fn rebuild_and_reflow() -> Self;
|
fn rebuild_and_reflow() -> Self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -370,16 +370,16 @@ trait PrivateMatchMethods<'ln>: TNode<'ln>
|
||||||
context: &SharedStyleContext<<Self::ConcreteElement as Element>::Impl>,
|
context: &SharedStyleContext<<Self::ConcreteElement as Element>::Impl>,
|
||||||
parent_style: Option<&Arc<ComputedValues>>,
|
parent_style: Option<&Arc<ComputedValues>>,
|
||||||
applicable_declarations: &[DeclarationBlock],
|
applicable_declarations: &[DeclarationBlock],
|
||||||
style: &mut Option<Arc<ComputedValues>>,
|
mut style: Option<&mut Arc<ComputedValues>>,
|
||||||
applicable_declarations_cache:
|
applicable_declarations_cache:
|
||||||
&mut ApplicableDeclarationsCache,
|
&mut ApplicableDeclarationsCache,
|
||||||
new_animations_sender: &Mutex<Sender<Animation>>,
|
new_animations_sender: &Mutex<Sender<Animation>>,
|
||||||
shareable: bool,
|
shareable: bool,
|
||||||
animate_properties: bool)
|
animate_properties: bool)
|
||||||
-> Self::ConcreteRestyleDamage {
|
-> (Self::ConcreteRestyleDamage, Arc<ComputedValues>) {
|
||||||
let mut cacheable = true;
|
let mut cacheable = true;
|
||||||
if animate_properties {
|
if animate_properties {
|
||||||
cacheable = !self.update_animations_for_cascade(context, style) && cacheable;
|
cacheable = !self.update_animations_for_cascade(context, &mut style) && cacheable;
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut this_style;
|
let mut this_style;
|
||||||
|
@ -414,7 +414,7 @@ trait PrivateMatchMethods<'ln>: TNode<'ln>
|
||||||
// Trigger transitions if necessary. This will reset `this_style` back to its old value if
|
// Trigger transitions if necessary. This will reset `this_style` back to its old value if
|
||||||
// it did trigger a transition.
|
// it did trigger a transition.
|
||||||
if animate_properties {
|
if animate_properties {
|
||||||
if let Some(ref style) = *style {
|
if let Some(ref style) = style {
|
||||||
let animations_started =
|
let animations_started =
|
||||||
animation::start_transitions_if_applicable(new_animations_sender,
|
animation::start_transitions_if_applicable(new_animations_sender,
|
||||||
self.opaque(),
|
self.opaque(),
|
||||||
|
@ -426,7 +426,7 @@ trait PrivateMatchMethods<'ln>: TNode<'ln>
|
||||||
|
|
||||||
// Calculate style difference.
|
// Calculate style difference.
|
||||||
let this_style = Arc::new(this_style);
|
let this_style = Arc::new(this_style);
|
||||||
let damage = Self::ConcreteRestyleDamage::compute(style, &*this_style);
|
let damage = Self::ConcreteRestyleDamage::compute(style.map(|s| &*s), &*this_style);
|
||||||
|
|
||||||
// Cache the resolved style if it was cacheable.
|
// Cache the resolved style if it was cacheable.
|
||||||
if cacheable {
|
if cacheable {
|
||||||
|
@ -434,14 +434,13 @@ trait PrivateMatchMethods<'ln>: TNode<'ln>
|
||||||
this_style.clone());
|
this_style.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write in the final style and return the damage done to our caller.
|
// Return the final style and the damage done to our caller.
|
||||||
*style = Some(this_style);
|
(damage, this_style)
|
||||||
damage
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_animations_for_cascade(&self,
|
fn update_animations_for_cascade(&self,
|
||||||
context: &SharedStyleContext<<Self::ConcreteElement as Element>::Impl>,
|
context: &SharedStyleContext<<Self::ConcreteElement as Element>::Impl>,
|
||||||
style: &mut Option<Arc<ComputedValues>>)
|
style: &mut Option<&mut Arc<ComputedValues>>)
|
||||||
-> bool {
|
-> bool {
|
||||||
let style = match *style {
|
let style = match *style {
|
||||||
None => return false,
|
None => return false,
|
||||||
|
@ -572,7 +571,7 @@ pub trait ElementMatchMethods<'le> : TElement<'le>
|
||||||
let node = self.as_node();
|
let node = self.as_node();
|
||||||
let style = &mut node.mutate_data().unwrap().style;
|
let style = &mut node.mutate_data().unwrap().style;
|
||||||
let damage = <<Self as TElement<'le>>::ConcreteNode as TNode<'le>>
|
let damage = <<Self as TElement<'le>>::ConcreteNode as TNode<'le>>
|
||||||
::ConcreteRestyleDamage::compute(style, &*shared_style);
|
::ConcreteRestyleDamage::compute((*style).as_ref(), &*shared_style);
|
||||||
*style = Some(shared_style);
|
*style = Some(shared_style);
|
||||||
return StyleSharingResult::StyleWasShared(i, damage)
|
return StyleSharingResult::StyleWasShared(i, damage)
|
||||||
}
|
}
|
||||||
|
@ -666,38 +665,44 @@ pub trait MatchMethods<'ln> : TNode<'ln> {
|
||||||
let cloned_parent_style = parent_style.unwrap().clone();
|
let cloned_parent_style = parent_style.unwrap().clone();
|
||||||
data.style = Some(cloned_parent_style);
|
data.style = Some(cloned_parent_style);
|
||||||
} else {
|
} else {
|
||||||
let mut damage;
|
let damage = {
|
||||||
{
|
|
||||||
let mut data_ref = self.mutate_data().unwrap();
|
let mut data_ref = self.mutate_data().unwrap();
|
||||||
let mut data = &mut *data_ref;
|
let mut data = &mut *data_ref;
|
||||||
damage = self.cascade_node_pseudo_element(
|
let (mut damage, final_style) = self.cascade_node_pseudo_element(
|
||||||
context,
|
context,
|
||||||
parent_style,
|
parent_style,
|
||||||
&applicable_declarations.normal,
|
&applicable_declarations.normal,
|
||||||
&mut data.style,
|
data.style.as_mut(),
|
||||||
applicable_declarations_cache,
|
applicable_declarations_cache,
|
||||||
new_animations_sender,
|
new_animations_sender,
|
||||||
applicable_declarations.normal_shareable,
|
applicable_declarations.normal_shareable,
|
||||||
true);
|
true);
|
||||||
|
|
||||||
|
data.style = Some(final_style);
|
||||||
|
|
||||||
<Self::ConcreteElement as Element>::Impl::each_eagerly_cascaded_pseudo_element(|pseudo| {
|
<Self::ConcreteElement as Element>::Impl::each_eagerly_cascaded_pseudo_element(|pseudo| {
|
||||||
let applicable_declarations_for_this_pseudo =
|
let applicable_declarations_for_this_pseudo =
|
||||||
applicable_declarations.per_pseudo.get(&pseudo).unwrap();
|
applicable_declarations.per_pseudo.get(&pseudo).unwrap();
|
||||||
|
|
||||||
|
|
||||||
if !applicable_declarations_for_this_pseudo.is_empty() {
|
if !applicable_declarations_for_this_pseudo.is_empty() {
|
||||||
damage = damage | self.cascade_node_pseudo_element(
|
let (new_damage, style) = self.cascade_node_pseudo_element(
|
||||||
context,
|
context,
|
||||||
Some(data.style.as_ref().unwrap()),
|
Some(data.style.as_ref().unwrap()),
|
||||||
&*applicable_declarations_for_this_pseudo,
|
&*applicable_declarations_for_this_pseudo,
|
||||||
data.per_pseudo.entry(pseudo).or_insert(None),
|
data.per_pseudo.get_mut(&pseudo),
|
||||||
applicable_declarations_cache,
|
applicable_declarations_cache,
|
||||||
new_animations_sender,
|
new_animations_sender,
|
||||||
false,
|
false,
|
||||||
false);
|
false);
|
||||||
|
data.per_pseudo.insert(pseudo, style);
|
||||||
|
|
||||||
|
damage = damage | new_damage;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
damage
|
||||||
|
};
|
||||||
|
|
||||||
// This method needs to borrow the data as mutable, so make sure data_ref goes out of
|
// This method needs to borrow the data as mutable, so make sure data_ref goes out of
|
||||||
// scope first.
|
// scope first.
|
||||||
|
|
|
@ -78,7 +78,7 @@ impl<'ln> GeckoNode<'ln> {
|
||||||
#[derive(Clone, Copy)]
|
#[derive(Clone, Copy)]
|
||||||
pub struct DummyRestyleDamage;
|
pub struct DummyRestyleDamage;
|
||||||
impl TRestyleDamage for DummyRestyleDamage {
|
impl TRestyleDamage for DummyRestyleDamage {
|
||||||
fn compute(_: &Option<Arc<ComputedValues>>, _: &ComputedValues) -> Self { DummyRestyleDamage }
|
fn compute(_: Option<&Arc<ComputedValues>>, _: &ComputedValues) -> Self { DummyRestyleDamage }
|
||||||
fn rebuild_and_reflow() -> Self { DummyRestyleDamage }
|
fn rebuild_and_reflow() -> Self { DummyRestyleDamage }
|
||||||
}
|
}
|
||||||
impl BitOr for DummyRestyleDamage {
|
impl BitOr for DummyRestyleDamage {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue