Bug 1344135 - Return true in set_property only when declaration block is changed. r?heycam
MozReview-Commit-ID: 5TWdBITO33I
--- a/servo/components/style/properties/declaration_block.rs
+++ b/servo/components/style/properties/declaration_block.rs
@@ -166,40 +166,44 @@ impl PropertyDeclarationBlock {
Err(longhand_or_custom) => {
// Step 3
self.get(longhand_or_custom).map_or(Importance::Normal, |&(_, importance)| importance)
}
}
}
/// Adds or overrides the declaration for a given property in this block,
- /// without taking into account any kind of priority.
+ /// without taking into account any kind of priority. Returns whether the
+ /// declaration block is actually changed.
pub fn set_parsed_declaration(&mut self,
declaration: PropertyDeclaration,
- importance: Importance) {
+ importance: Importance) -> bool {
for slot in &mut *self.declarations {
if slot.0.id() == declaration.id() {
match (slot.1, importance) {
(Importance::Normal, Importance::Important) => {
self.important_count += 1;
}
(Importance::Important, Importance::Normal) => {
self.important_count -= 1;
}
- _ => {}
+ _ => if slot.0 == declaration {
+ return false;
+ }
}
*slot = (declaration, importance);
- return
+ return true;
}
}
self.declarations.push((declaration, importance));
if importance.important() {
self.important_count += 1;
}
+ true
}
/// Set the declaration importance for a given property, if found.
///
/// Returns whether any declaration was updated.
pub fn set_importance(&mut self, property: &PropertyId, new_importance: Importance) -> bool {
let mut updated_at_least_one = false;
for &mut (ref declaration, ref mut importance) in &mut self.declarations {
--- a/servo/ports/geckolib/glue.rs
+++ b/servo/ports/geckolib/glue.rs
@@ -832,20 +832,23 @@ fn set_property(declarations: RawServoDe
let value = unsafe { value.as_ref().unwrap().as_str_unchecked() };
// FIXME Needs real URL and ParserContextExtraData.
let base_url = &*DUMMY_BASE_URL;
let extra_data = ParserContextExtraData::default();
if let Ok(decls) = parse_one_declaration(property_id, value, &base_url,
Box::new(StdoutErrorReporter), extra_data) {
let mut declarations = RwLock::<PropertyDeclarationBlock>::as_arc(&declarations).write();
let importance = if is_important { Importance::Important } else { Importance::Normal };
+ let mut changed = false;
for decl in decls.into_iter() {
- declarations.set_parsed_declaration(decl.0, importance);
+ if declarations.set_parsed_declaration(decl.0, importance) {
+ changed = true;
+ }
}
- true
+ changed
} else {
false
}
}
#[no_mangle]
pub extern "C" fn Servo_DeclarationBlock_SetProperty(declarations: RawServoDeclarationBlockBorrowed,
property: *const nsACString, value: *mut nsACString,