style: Add a before-change callback to remove_property.

Bug: 1466963
Reviewed-by: xidorn
MozReview-Commit-ID: 4vyN9iLT7e3
This commit is contained in:
Emilio Cobos Álvarez 2018-06-05 21:13:48 +02:00
parent 6ca324f8b5
commit 3c7fb2a217
No known key found for this signature in database
GPG key ID: 056B727BB9C1027C

View file

@ -567,7 +567,14 @@ impl PropertyDeclarationBlock {
/// <https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-removeproperty> /// <https://drafts.csswg.org/cssom/#dom-cssstyledeclaration-removeproperty>
/// ///
/// Returns whether any declaration was actually removed. /// Returns whether any declaration was actually removed.
pub fn remove_property(&mut self, property: &PropertyId) -> bool { pub fn remove_property<C>(
&mut self,
property: &PropertyId,
mut before_change_callback: C,
) -> bool
where
C: FnMut(&Self),
{
let longhand_id = property.longhand_id(); let longhand_id = property.longhand_id();
if let Some(id) = longhand_id { if let Some(id) = longhand_id {
if !self.longhands.contains(id) { if !self.longhands.contains(id) {
@ -575,23 +582,28 @@ impl PropertyDeclarationBlock {
} }
} }
let mut removed_at_least_one = false; let mut removed_at_least_one = false;
let longhands = &mut self.longhands;
let declarations_importance = &mut self.declarations_importance;
let mut i = 0; let mut i = 0;
self.declarations.retain(|declaration| { let mut len = self.len();
let id = declaration.id(); while i < len {
let remove = id.is_or_is_longhand_of(property); {
if remove { let id = self.declarations[i].id();
if !id.is_or_is_longhand_of(property) {
i += 1;
continue;
}
if !removed_at_least_one {
before_change_callback(&*self);
}
removed_at_least_one = true; removed_at_least_one = true;
if let PropertyDeclarationId::Longhand(id) = id { if let PropertyDeclarationId::Longhand(id) = id {
longhands.remove(id); self.longhands.remove(id);
} }
declarations_importance.remove(i); self.declarations_importance.remove(i);
} else {
i += 1;
} }
!remove self.declarations.remove(i);
}); len -= 1;
}
if longhand_id.is_some() { if longhand_id.is_some() {
debug_assert!(removed_at_least_one); debug_assert!(removed_at_least_one);