mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Added sync_property_with_attrs_style method to serialize style string when inline style is changed
This commit is contained in:
parent
b4d8f3ba3a
commit
839a7559e7
1 changed files with 102 additions and 62 deletions
|
@ -698,8 +698,32 @@ impl Element {
|
|||
}
|
||||
}
|
||||
|
||||
fn sync_property_with_attrs_style(&self) {
|
||||
let mut style_str = String::new();
|
||||
|
||||
if let &Some(ref declarations) = &*self.style_attribute().borrow() {
|
||||
style_str.push_str(&declarations.serialize());
|
||||
}
|
||||
|
||||
let new_style = AttrValue::String(style_str);
|
||||
|
||||
if let Some(style_attr) = self.attrs.borrow().iter().find(|a| a.name() == &atom!("style")) {
|
||||
style_attr.set_value(new_style, self);
|
||||
return;
|
||||
}
|
||||
|
||||
self.push_new_attribute(
|
||||
atom!("style"),
|
||||
new_style,
|
||||
atom!("style"),
|
||||
ns!(),
|
||||
Some(atom!("style"))
|
||||
);
|
||||
}
|
||||
|
||||
pub fn remove_inline_style_property(&self, property: &str) {
|
||||
let mut inline_declarations = self.style_attribute.borrow_mut();
|
||||
fn remove(element: &Element, property: &str) {
|
||||
let mut inline_declarations = element.style_attribute.borrow_mut();
|
||||
if let &mut Some(ref mut declarations) = &mut *inline_declarations {
|
||||
let index = declarations.normal
|
||||
.iter()
|
||||
|
@ -719,10 +743,16 @@ impl Element {
|
|||
}
|
||||
}
|
||||
|
||||
remove(self, property);
|
||||
self.sync_property_with_attrs_style();
|
||||
}
|
||||
|
||||
pub fn update_inline_style(&self,
|
||||
property_decl: PropertyDeclaration,
|
||||
style_priority: StylePriority) {
|
||||
let mut inline_declarations = self.style_attribute().borrow_mut();
|
||||
|
||||
fn update(element: &Element, property_decl: PropertyDeclaration, style_priority: StylePriority) {
|
||||
let mut inline_declarations = element.style_attribute().borrow_mut();
|
||||
if let &mut Some(ref mut declarations) = &mut *inline_declarations {
|
||||
let existing_declarations = if style_priority == StylePriority::Important {
|
||||
&mut declarations.important
|
||||
|
@ -739,7 +769,9 @@ impl Element {
|
|||
return;
|
||||
}
|
||||
}
|
||||
existing_declarations.push(property_decl);
|
||||
|
||||
// inserting instead of pushing since the declarations are in reverse order
|
||||
existing_declarations.insert(0, property_decl);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -755,9 +787,14 @@ impl Element {
|
|||
});
|
||||
}
|
||||
|
||||
update(self, property_decl, style_priority);
|
||||
self.sync_property_with_attrs_style();
|
||||
}
|
||||
|
||||
pub fn set_inline_style_property_priority(&self,
|
||||
properties: &[&str],
|
||||
style_priority: StylePriority) {
|
||||
{
|
||||
let mut inline_declarations = self.style_attribute().borrow_mut();
|
||||
if let &mut Some(ref mut declarations) = &mut *inline_declarations {
|
||||
let (from, to) = if style_priority == StylePriority::Important {
|
||||
|
@ -783,6 +820,9 @@ impl Element {
|
|||
}
|
||||
}
|
||||
|
||||
self.sync_property_with_attrs_style();
|
||||
}
|
||||
|
||||
pub fn get_inline_style_declaration(&self,
|
||||
property: &Atom)
|
||||
-> Option<Ref<PropertyDeclaration>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue