style: deduplicate some code in the ComputedValues code.

This commit is contained in:
Emilio Cobos Álvarez 2017-10-01 13:15:47 +02:00
parent 2adfd84636
commit 4933a54803
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C
2 changed files with 27 additions and 52 deletions

View file

@ -253,9 +253,10 @@ impl ops::DerefMut for ComputedValues {
} }
impl ComputedValuesInner { impl ComputedValuesInner {
/// Whether we're a visited style. /// Clone the visited style. Used for inheriting parent styles in
pub fn is_style_if_visited(&self) -> bool { /// StyleBuilder::for_inheritance.
self.flags.contains(IS_STYLE_IF_VISITED) pub fn clone_visited_style(&self) -> Option<Arc<ComputedValues>> {
self.visited_style.as_ref().map(|x| x.clone_arc())
} }
#[inline] #[inline]
@ -291,37 +292,11 @@ impl ComputedValuesInner {
} }
% endfor % endfor
/// Gets a reference to the rule node. Panic if no rule node exists.
pub fn rules(&self) -> &StrongRuleNode {
self.rules.as_ref().unwrap()
}
/// Whether there is a visited style.
pub fn has_visited_style(&self) -> bool {
self.visited_style.is_some()
}
/// Gets a reference to the visited style, if any.
pub fn get_visited_style(&self) -> Option< & ComputedValues> {
self.visited_style.as_ref().map(|x| &**x)
}
/// Gets the raw visited style. Useful for memory reporting. /// Gets the raw visited style. Useful for memory reporting.
pub fn get_raw_visited_style(&self) -> &Option<RawOffsetArc<ComputedValues>> { pub fn get_raw_visited_style(&self) -> &Option<RawOffsetArc<ComputedValues>> {
&self.visited_style &self.visited_style
} }
/// Gets a reference to the visited style. Panic if no visited style exists.
pub fn visited_style(&self) -> &ComputedValues {
self.get_visited_style().unwrap()
}
/// Clone the visited style. Used for inheriting parent styles in
/// StyleBuilder::for_inheritance.
pub fn clone_visited_style(&self) -> Option<Arc<ComputedValues>> {
self.visited_style.as_ref().map(|x| x.clone_arc())
}
#[allow(non_snake_case)] #[allow(non_snake_case)]
pub fn has_moz_binding(&self) -> bool { pub fn has_moz_binding(&self) -> bool {
!self.get_box().gecko.mBinding.mPtr.mRawPtr.is_null() !self.get_box().gecko.mBinding.mPtr.mRawPtr.is_null()

View file

@ -2090,6 +2090,26 @@ pub struct ComputedValues {
} }
impl ComputedValues { impl ComputedValues {
/// Whether we're a visited style.
pub fn is_style_if_visited(&self) -> bool {
self.flags.contains(IS_STYLE_IF_VISITED)
}
/// Whether there is a visited style.
pub fn has_visited_style(&self) -> bool {
self.visited_style.is_some()
}
/// Gets a reference to the visited style, if any.
pub fn get_visited_style(&self) -> Option<<&ComputedValues> {
self.visited_style.as_ref().map(|x| &**x)
}
/// Gets a reference to the rule node. Panic if no rule node exists.
pub fn rules(&self) -> &StrongRuleNode {
self.rules.as_ref().unwrap()
}
/// Returns the visited rules, if applicable. /// Returns the visited rules, if applicable.
pub fn visited_rules(&self) -> Option<<&StrongRuleNode> { pub fn visited_rules(&self) -> Option<<&StrongRuleNode> {
self.visited_style.as_ref().and_then(|s| s.rules.as_ref()) self.visited_style.as_ref().and_then(|s| s.rules.as_ref())
@ -2216,20 +2236,9 @@ impl ComputedValuesInner {
self.rules.as_ref().unwrap() self.rules.as_ref().unwrap()
} }
/// Whether there is a visited style. /// Whether this style has a -moz-binding value. This is always false for
pub fn has_visited_style(&self) -> bool { /// Servo for obvious reasons.
self.visited_style.is_some() pub fn has_moz_binding(&self) -> bool { false }
}
/// Gets a reference to the visited style, if any.
pub fn get_visited_style(&self) -> Option< & ComputedValues> {
self.visited_style.as_ref().map(|x| &**x)
}
/// Gets a reference to the visited style. Panic if no visited style exists.
pub fn visited_style(&self) -> &ComputedValues {
self.get_visited_style().unwrap()
}
/// Clone the visited style. Used for inheriting parent styles in /// Clone the visited style. Used for inheriting parent styles in
/// StyleBuilder::for_inheritance. /// StyleBuilder::for_inheritance.
@ -2237,15 +2246,6 @@ impl ComputedValuesInner {
self.visited_style.clone() self.visited_style.clone()
} }
/// Whether this style has a -moz-binding value. This is always false for
/// Servo for obvious reasons.
pub fn has_moz_binding(&self) -> bool { false }
/// Whether we're a visited style.
pub fn is_style_if_visited(&self) -> bool {
self.flags.contains(IS_STYLE_IF_VISITED)
}
/// Returns whether this style's display value is equal to contents. /// Returns whether this style's display value is equal to contents.
/// ///
/// Since this isn't supported in Servo, this is always false for Servo. /// Since this isn't supported in Servo, this is always false for Servo.