mirror of
https://github.com/servo/servo.git
synced 2025-08-05 21:50:18 +01:00
Add any_important and any_normal methods to PropertyDeclarationBlock
This commit is contained in:
parent
7ef4930472
commit
95033e1c0d
3 changed files with 25 additions and 5 deletions
|
@ -292,6 +292,26 @@ pub struct PropertyDeclarationBlock {
|
|||
pub important_count: u32,
|
||||
}
|
||||
|
||||
impl PropertyDeclarationBlock {
|
||||
/// Returns wheather this block contains any declaration with `!important`.
|
||||
///
|
||||
/// This is based on the `important_count` counter,
|
||||
/// which should be maintained whenever `declarations` is changed.
|
||||
// FIXME: make fields private and maintain it here in methods?
|
||||
pub fn any_important(&self) -> bool {
|
||||
self.important_count > 0
|
||||
}
|
||||
|
||||
/// Returns wheather this block contains any declaration without `!important`.
|
||||
///
|
||||
/// This is based on the `important_count` counter,
|
||||
/// which should be maintained whenever `declarations` is changed.
|
||||
// FIXME: make fields private and maintain it here in methods?
|
||||
pub fn any_normal(&self) -> bool {
|
||||
self.declarations.len() > self.important_count as usize
|
||||
}
|
||||
}
|
||||
|
||||
impl ToCss for PropertyDeclarationBlock {
|
||||
// https://drafts.csswg.org/cssom/#serialize-a-css-declaration-block
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
|
|
|
@ -398,7 +398,7 @@ impl Stylist {
|
|||
|
||||
// Step 4: Normal style attributes.
|
||||
if let Some(sa) = style_attribute {
|
||||
if sa.declarations.len() > sa.important_count as usize {
|
||||
if sa.any_normal() {
|
||||
relations |= AFFECTED_BY_STYLE_ATTRIBUTE;
|
||||
Push::push(
|
||||
applicable_declarations,
|
||||
|
@ -419,7 +419,7 @@ impl Stylist {
|
|||
|
||||
// Step 6: `!important` style attributes.
|
||||
if let Some(sa) = style_attribute {
|
||||
if sa.important_count > 0 {
|
||||
if sa.any_important() {
|
||||
relations |= AFFECTED_BY_STYLE_ATTRIBUTE;
|
||||
Push::push(
|
||||
applicable_declarations,
|
||||
|
@ -764,9 +764,9 @@ impl SelectorMap {
|
|||
for rule in rules.iter() {
|
||||
let block = &rule.declarations.mixed_declarations;
|
||||
let any_declaration_for_importance = if importance.important() {
|
||||
block.important_count > 0
|
||||
block.any_important()
|
||||
} else {
|
||||
block.declarations.len() > block.important_count as usize
|
||||
block.any_normal()
|
||||
};
|
||||
if any_declaration_for_importance &&
|
||||
matches_complex_selector(&*rule.selector,
|
||||
|
|
|
@ -473,7 +473,7 @@ impl<'le> TElement for GeckoElement<'le> {
|
|||
None
|
||||
} else {
|
||||
let opt_ptr = GeckoDeclarationBlock::with(declarations, |declarations| {
|
||||
// Use a raw poointer to extend the lifetime
|
||||
// Use a raw pointer to extend the lifetime
|
||||
declarations.declarations.as_ref().map(|r| r as *const Arc<_>)
|
||||
});
|
||||
opt_ptr.map(|ptr| unsafe { &*ptr })
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue