mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
style: Don't call the before change closure with the locked declaration block.
Test Plan: No behavior change. Reviewers: xidorn Bug #: 1468665 Differential Revision: https://phabricator.services.mozilla.com/D1681
This commit is contained in:
parent
00b42fc6ef
commit
e6f9ad0edb
1 changed files with 56 additions and 38 deletions
|
@ -564,51 +564,71 @@ impl PropertyDeclarationBlock {
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns the first declaration that would be removed by removing
|
||||||
|
/// `property`.
|
||||||
|
#[inline]
|
||||||
|
pub fn first_declaration_to_remove(
|
||||||
|
&self,
|
||||||
|
property: &PropertyId,
|
||||||
|
) -> Option<usize> {
|
||||||
|
if let Some(id) = property.longhand_id() {
|
||||||
|
if !self.longhands.contains(id) {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
self.declarations.iter().position(|declaration| {
|
||||||
|
declaration.id().is_or_is_longhand_of(property)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Removes a given declaration at a given index.
|
||||||
|
#[inline]
|
||||||
|
fn remove_declaration_at(&mut self, i: usize) {
|
||||||
|
{
|
||||||
|
let id = self.declarations[i].id();
|
||||||
|
if let PropertyDeclarationId::Longhand(id) = id {
|
||||||
|
self.longhands.remove(id);
|
||||||
|
}
|
||||||
|
self.declarations_importance.remove(i);
|
||||||
|
}
|
||||||
|
self.declarations.remove(i);
|
||||||
|
}
|
||||||
|
|
||||||
/// <https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-removeproperty>
|
/// <https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-removeproperty>
|
||||||
///
|
///
|
||||||
/// Returns whether any declaration was actually removed.
|
/// `first_declaration` needs to be the result of
|
||||||
pub fn remove_property<C>(
|
/// `first_declaration_to_remove`.
|
||||||
|
#[inline]
|
||||||
|
pub fn remove_property(
|
||||||
&mut self,
|
&mut self,
|
||||||
property: &PropertyId,
|
property: &PropertyId,
|
||||||
mut before_change_callback: C,
|
first_declaration: usize,
|
||||||
) -> bool
|
) {
|
||||||
where
|
debug_assert_eq!(
|
||||||
C: FnMut(&Self),
|
Some(first_declaration),
|
||||||
{
|
self.first_declaration_to_remove(property)
|
||||||
let longhand_id = property.longhand_id();
|
);
|
||||||
if let Some(id) = longhand_id {
|
debug_assert!(self.declarations[first_declaration].id().is_or_is_longhand_of(property));
|
||||||
if !self.longhands.contains(id) {
|
|
||||||
return false
|
self.remove_declaration_at(first_declaration);
|
||||||
}
|
|
||||||
}
|
let shorthand = match property.as_shorthand() {
|
||||||
let mut removed_at_least_one = false;
|
Ok(s) => s,
|
||||||
let mut i = 0;
|
Err(_longhand_or_custom) => return,
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut i = first_declaration;
|
||||||
let mut len = self.len();
|
let mut len = self.len();
|
||||||
while i < len {
|
while i < len {
|
||||||
{
|
if !self.declarations[i].id().is_longhand_of(shorthand) {
|
||||||
let id = self.declarations[i].id();
|
i += 1;
|
||||||
if !id.is_or_is_longhand_of(property) {
|
continue;
|
||||||
i += 1;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if !removed_at_least_one {
|
|
||||||
before_change_callback(&*self);
|
|
||||||
}
|
|
||||||
removed_at_least_one = true;
|
|
||||||
if let PropertyDeclarationId::Longhand(id) = id {
|
|
||||||
self.longhands.remove(id);
|
|
||||||
}
|
|
||||||
self.declarations_importance.remove(i);
|
|
||||||
}
|
}
|
||||||
self.declarations.remove(i);
|
|
||||||
|
self.remove_declaration_at(i);
|
||||||
len -= 1;
|
len -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if longhand_id.is_some() {
|
|
||||||
debug_assert!(removed_at_least_one);
|
|
||||||
}
|
|
||||||
removed_at_least_one
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Take a declaration block known to contain a single property and serialize it.
|
/// Take a declaration block known to contain a single property and serialize it.
|
||||||
|
@ -725,9 +745,7 @@ impl PropertyDeclarationBlock {
|
||||||
|
|
||||||
builder.build()
|
builder.build()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
impl PropertyDeclarationBlock {
|
|
||||||
/// Like the method on ToCss, but without the type parameter to avoid
|
/// Like the method on ToCss, but without the type parameter to avoid
|
||||||
/// accidentally monomorphizing this large function multiple times for
|
/// accidentally monomorphizing this large function multiple times for
|
||||||
/// different writers.
|
/// different writers.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue