aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/virtualmethods.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2015-08-28 13:32:38 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2015-09-02 15:45:38 +0200
commit58e1bd0e57a3c69307e35a25ed23af3dedf05c50 (patch)
tree4a37e912de8a15479cc4b97024eb47b5b77b8c9e /components/script/dom/virtualmethods.rs
parent5672142042973bdb8e208357a702bb4a93b94658 (diff)
downloadservo-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/virtualmethods.rs')
-rw-r--r--components/script/dom/virtualmethods.rs29
1 files changed, 7 insertions, 22 deletions
diff --git a/components/script/dom/virtualmethods.rs b/components/script/dom/virtualmethods.rs
index 589a2b2461c..6812703ffe6 100644
--- a/components/script/dom/virtualmethods.rs
+++ b/components/script/dom/virtualmethods.rs
@@ -33,7 +33,7 @@ use dom::bindings::codegen::InheritTypes::HTMLTableSectionElementCast;
use dom::bindings::codegen::InheritTypes::HTMLTextAreaElementCast;
use dom::bindings::codegen::InheritTypes::HTMLTitleElementCast;
use dom::document::Document;
-use dom::element::ElementTypeId;
+use dom::element::{AttributeMutation, ElementTypeId};
use dom::event::Event;
use dom::htmlelement::HTMLElementTypeId;
use dom::node::NodeTypeId;
@@ -50,27 +50,12 @@ pub trait VirtualMethods {
/// if any.
fn super_type(&self) -> Option<&VirtualMethods>;
- /// Called when changing or adding attributes, after the attribute's value
- /// has been updated.
- fn after_set_attr(&self, attr: &Attr) {
- if let Some(ref s) = self.super_type() {
- s.after_set_attr(attr);
- }
- }
-
- /// Called when changing or removing attributes, before any modification
- /// has taken place.
- fn before_remove_attr(&self, attr: &Attr) {
- if let Some(ref s) = self.super_type() {
- s.before_remove_attr(attr);
- }
- }
-
- /// Called when changing or removing attributes, after all modification
- /// has taken place.
- fn after_remove_attr(&self, name: &Atom) {
- if let Some(ref s) = self.super_type() {
- s.after_remove_attr(name);
+ /// Called when attributes of a node are mutated.
+ /// https://dom.spec.whatwg.org/#attribute-is-set
+ /// https://dom.spec.whatwg.org/#attribute-is-removed
+ fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
+ if let Some(s) = self.super_type() {
+ s.attribute_mutated(attr, mutation);
}
}