aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/htmliframeelement.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/htmliframeelement.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/htmliframeelement.rs')
-rw-r--r--components/script/dom/htmliframeelement.rs45
1 files changed, 16 insertions, 29 deletions
diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs
index 6abf4f7b877..9795b0a9008 100644
--- a/components/script/dom/htmliframeelement.rs
+++ b/components/script/dom/htmliframeelement.rs
@@ -17,7 +17,7 @@ use dom::bindings::js::{Root};
use dom::bindings::utils::Reflectable;
use dom::customevent::CustomEvent;
use dom::document::Document;
-use dom::element::{ElementTypeId, self};
+use dom::element::{AttributeMutation, ElementTypeId, self};
use dom::eventtarget::{EventTarget, EventTargetTypeId};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::node::{Node, NodeTypeId, window_from_node};
@@ -354,16 +354,13 @@ impl VirtualMethods for HTMLIFrameElement {
Some(htmlelement as &VirtualMethods)
}
- fn after_set_attr(&self, attr: &Attr) {
- if let Some(ref s) = self.super_type() {
- s.after_set_attr(attr);
- }
-
+ fn attribute_mutated(&self, attr: &Attr, mutation: AttributeMutation) {
+ self.super_type().unwrap().attribute_mutated(attr, mutation);
match attr.local_name() {
- &atom!("sandbox") => {
- let mut modes = SandboxAllowance::AllowNothing as u8;
- if let Some(ref tokens) = attr.value().tokens() {
- for token in *tokens {
+ &atom!(sandbox) => {
+ self.sandbox.set(mutation.new_value(attr).map(|value| {
+ let mut modes = SandboxAllowance::AllowNothing as u8;
+ for token in value.tokens().unwrap() {
modes |= match &*token.to_ascii_lowercase() {
"allow-same-origin" => SandboxAllowance::AllowSameOrigin,
"allow-forms" => SandboxAllowance::AllowForms,
@@ -374,16 +371,17 @@ impl VirtualMethods for HTMLIFrameElement {
_ => SandboxAllowance::AllowNothing
} as u8;
}
- }
- self.sandbox.set(Some(modes));
- }
- &atom!("src") => {
- let node = NodeCast::from_ref(self);
- if node.is_in_doc() {
- self.process_the_iframe_attributes()
+ modes
+ }));
+ },
+ &atom!(src) => {
+ if let AttributeMutation::Set(_) = mutation {
+ if NodeCast::from_ref(self).is_in_doc() {
+ self.process_the_iframe_attributes();
+ }
}
},
- _ => ()
+ _ => {},
}
}
@@ -394,17 +392,6 @@ impl VirtualMethods for HTMLIFrameElement {
}
}
- fn before_remove_attr(&self, attr: &Attr) {
- if let Some(ref s) = self.super_type() {
- s.before_remove_attr(attr);
- }
-
- match attr.local_name() {
- &atom!("sandbox") => self.sandbox.set(None),
- _ => ()
- }
- }
-
fn bind_to_tree(&self, tree_in_doc: bool) {
if let Some(ref s) = self.super_type() {
s.bind_to_tree(tree_in_doc);