diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2015-08-28 13:32:38 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2015-09-02 15:45:38 +0200 |
commit | 58e1bd0e57a3c69307e35a25ed23af3dedf05c50 (patch) | |
tree | 4a37e912de8a15479cc4b97024eb47b5b77b8c9e /components/script/dom/htmltablesectionelement.rs | |
parent | 5672142042973bdb8e208357a702bb4a93b94658 (diff) | |
download | servo-58e1bd0e57a3c69307e35a25ed23af3dedf05c50.tar.gz servo-58e1bd0e57a3c69307e35a25ed23af3dedf05c50.zip |
Introduce VirtualMethods::attribute_mutated()
This replaces before_remove_attr(), after_remove_attr() and after_set_attr().
The virtual method takes the mutated attribute and an AttributeMutation value
to disambiguate between "attribute is changed", "attribute is added" and
"attribute is removed".
In the case of "attribute is changed", the mutation value contains a reference
to the old value of the mutated attribute, which is used to unregister outdated
named elements when the "id" attribute is changed on an element.
This greatly simplifies the handling of attributes, which in many cases don't
have any specific behaviour whether they are removed or changed or added. It
also fixes a few bugs where things were put in before_remove_attr() instead of
after_remove_attr() (e.g. when removing an href attribute from a base element).
A few helper functions in Element were also renamed and made private.
Diffstat (limited to 'components/script/dom/htmltablesectionelement.rs')
-rw-r--r-- | components/script/dom/htmltablesectionelement.rs | 30 |
1 files changed, 8 insertions, 22 deletions
diff --git a/components/script/dom/htmltablesectionelement.rs b/components/script/dom/htmltablesectionelement.rs index 5922ffd4b42..137d25541fa 100644 --- a/components/script/dom/htmltablesectionelement.rs +++ b/components/script/dom/htmltablesectionelement.rs @@ -7,7 +7,7 @@ use dom::bindings::codegen::Bindings::HTMLTableSectionElementBinding; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTableSectionElementDerived}; use dom::bindings::js::Root; use dom::document::Document; -use dom::element::ElementTypeId; +use dom::element::{AttributeMutation, ElementTypeId}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{Node, NodeTypeId}; @@ -61,29 +61,15 @@ impl VirtualMethods for HTMLTableSectionElement { Some(htmlelement as &VirtualMethods) } - fn after_set_attr(&self, attr: &Attr) { - if let Some(ref s) = self.super_type() { - s.after_set_attr(attr); - } - - match attr.local_name() { - &atom!("bgcolor") => { - self.background_color.set(str::parse_legacy_color(&attr.value()).ok()); - }, - _ => () - } - } - - fn before_remove_attr(&self, attr: &Attr) { - if let Some(ref s) = self.super_type() { - s.before_remove_attr(attr); - } - + fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) { + self.super_type().unwrap().attribute_mutated(attr, mutation); match attr.local_name() { - &atom!("bgcolor") => { - self.background_color.set(None); + &atom!(bgcolor) => { + self.background_color.set(mutation.new_value(attr).and_then(|value| { + str::parse_legacy_color(&value).ok() + })); }, - _ => () + _ => {}, } } } |