mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Move CSSStyleDeclaration.SetPropertyPriority logic to style
This commit is contained in:
parent
c740a76410
commit
0eed39c198
3 changed files with 30 additions and 49 deletions
|
@ -242,24 +242,26 @@ impl CSSStyleDeclarationMethods for CSSStyleDeclaration {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Step 4
|
// Step 4
|
||||||
let priority = match &*priority {
|
let importance = match &*priority {
|
||||||
"" => Importance::Normal,
|
"" => Importance::Normal,
|
||||||
p if p.eq_ignore_ascii_case("important") => Importance::Important,
|
p if p.eq_ignore_ascii_case("important") => Importance::Important,
|
||||||
_ => return Ok(()),
|
_ => return Ok(()),
|
||||||
};
|
};
|
||||||
|
|
||||||
let element = self.owner.upcast::<Element>();
|
let style_attribute = self.owner.style_attribute().borrow();
|
||||||
|
if let Some(ref lock) = *style_attribute {
|
||||||
|
let mut style_attribute = lock.write();
|
||||||
|
|
||||||
// Step 5 & 6
|
// Step 5 & 6
|
||||||
match Shorthand::from_name(&property) {
|
match Shorthand::from_name(&property) {
|
||||||
Some(shorthand) => {
|
Some(shorthand) => style_attribute.set_importance(shorthand.longhands(), importance),
|
||||||
element.set_inline_style_property_priority(shorthand.longhands(), priority)
|
None => style_attribute.set_importance(&[&*property], importance),
|
||||||
}
|
}
|
||||||
None => element.set_inline_style_property_priority(&[&*property], priority),
|
|
||||||
}
|
|
||||||
|
|
||||||
let node = element.upcast::<Node>();
|
self.owner.set_style_attr(style_attribute.to_css_string());
|
||||||
node.dirty(NodeDamage::NodeStyleDamaged);
|
let node = self.owner.upcast::<Node>();
|
||||||
|
node.dirty(NodeDamage::NodeStyleDamaged);
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
//! Element nodes.
|
//! Element nodes.
|
||||||
|
|
||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use cssparser::{Color, ToCss};
|
use cssparser::Color;
|
||||||
use devtools_traits::AttrInfo;
|
use devtools_traits::AttrInfo;
|
||||||
use dom::activation::Activatable;
|
use dom::activation::Activatable;
|
||||||
use dom::attr::{Attr, AttrHelpersForLayout};
|
use dom::attr::{Attr, AttrHelpersForLayout};
|
||||||
|
@ -735,15 +735,6 @@ impl Element {
|
||||||
|
|
||||||
// this sync method is called upon modification of the style_attribute property,
|
// this sync method is called upon modification of the style_attribute property,
|
||||||
// therefore, it should not trigger subsequent mutation events
|
// therefore, it should not trigger subsequent mutation events
|
||||||
pub fn sync_property_with_attrs_style(&self) {
|
|
||||||
let style_str = if let &Some(ref declarations) = &*self.style_attribute().borrow() {
|
|
||||||
declarations.read().to_css_string()
|
|
||||||
} else {
|
|
||||||
String::new()
|
|
||||||
};
|
|
||||||
self.set_style_attr(style_str)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn set_style_attr(&self, new_value: String) {
|
pub fn set_style_attr(&self, new_value: String) {
|
||||||
let mut new_style = AttrValue::String(new_value);
|
let mut new_style = AttrValue::String(new_value);
|
||||||
|
|
||||||
|
@ -767,35 +758,6 @@ impl Element {
|
||||||
self.attrs.borrow_mut().push(JS::from_ref(&attr));
|
self.attrs.borrow_mut().push(JS::from_ref(&attr));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_inline_style_property_priority(&self,
|
|
||||||
properties: &[&str],
|
|
||||||
new_importance: Importance) {
|
|
||||||
{
|
|
||||||
let mut inline_declarations = self.style_attribute().borrow_mut();
|
|
||||||
if let &mut Some(ref mut block) = &mut *inline_declarations {
|
|
||||||
let mut block = block.write();
|
|
||||||
let block = &mut *block;
|
|
||||||
let declarations = &mut block.declarations;
|
|
||||||
for &mut (ref declaration, ref mut importance) in declarations {
|
|
||||||
if properties.iter().any(|p| declaration.name() == **p) {
|
|
||||||
match (*importance, new_importance) {
|
|
||||||
(Importance::Normal, Importance::Important) => {
|
|
||||||
block.important_count += 1;
|
|
||||||
}
|
|
||||||
(Importance::Important, Importance::Normal) => {
|
|
||||||
block.important_count -= 1;
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
*importance = new_importance;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
self.sync_property_with_attrs_style();
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn serialize(&self, traversal_scope: TraversalScope) -> Fallible<DOMString> {
|
pub fn serialize(&self, traversal_scope: TraversalScope) -> Fallible<DOMString> {
|
||||||
let mut writer = vec![];
|
let mut writer = vec![];
|
||||||
match serialize(&mut writer,
|
match serialize(&mut writer,
|
||||||
|
|
|
@ -154,6 +154,23 @@ impl PropertyDeclarationBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn set_importance(&mut self, property_names: &[&str], new_importance: Importance) {
|
||||||
|
for &mut (ref declaration, ref mut importance) in &mut self.declarations {
|
||||||
|
if property_names.iter().any(|p| declaration.matches(p)) {
|
||||||
|
match (*importance, new_importance) {
|
||||||
|
(Importance::Normal, Importance::Important) => {
|
||||||
|
self.important_count += 1;
|
||||||
|
}
|
||||||
|
(Importance::Important, Importance::Normal) => {
|
||||||
|
self.important_count -= 1;
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
*importance = new_importance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-removeproperty
|
/// https://dev.w3.org/csswg/cssom/#dom-cssstyledeclaration-removeproperty
|
||||||
pub fn remove_property(&mut self, property_name: &str) {
|
pub fn remove_property(&mut self, property_name: &str) {
|
||||||
// Step 2
|
// Step 2
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue