aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/virtualmethods.rs
diff options
context:
space:
mode:
Diffstat (limited to 'components/script/dom/virtualmethods.rs')
-rw-r--r--components/script/dom/virtualmethods.rs318
1 files changed, 168 insertions, 150 deletions
diff --git a/components/script/dom/virtualmethods.rs b/components/script/dom/virtualmethods.rs
index 8ff47f9ced5..9f175d8d621 100644
--- a/components/script/dom/virtualmethods.rs
+++ b/components/script/dom/virtualmethods.rs
@@ -1,57 +1,60 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
-use dom::attr::Attr;
-use dom::bindings::inheritance::Castable;
-use dom::bindings::inheritance::ElementTypeId;
-use dom::bindings::inheritance::HTMLElementTypeId;
-use dom::bindings::inheritance::NodeTypeId;
-use dom::bindings::inheritance::SVGElementTypeId;
-use dom::bindings::inheritance::SVGGraphicsElementTypeId;
-use dom::bindings::str::DOMString;
-use dom::document::Document;
-use dom::element::{AttributeMutation, Element};
-use dom::event::Event;
-use dom::htmlanchorelement::HTMLAnchorElement;
-use dom::htmlappletelement::HTMLAppletElement;
-use dom::htmlareaelement::HTMLAreaElement;
-use dom::htmlbaseelement::HTMLBaseElement;
-use dom::htmlbodyelement::HTMLBodyElement;
-use dom::htmlbuttonelement::HTMLButtonElement;
-use dom::htmlcanvaselement::HTMLCanvasElement;
-use dom::htmldetailselement::HTMLDetailsElement;
-use dom::htmlelement::HTMLElement;
-use dom::htmlfieldsetelement::HTMLFieldSetElement;
-use dom::htmlfontelement::HTMLFontElement;
-use dom::htmlformelement::HTMLFormElement;
-use dom::htmlheadelement::HTMLHeadElement;
-use dom::htmlhrelement::HTMLHRElement;
-use dom::htmliframeelement::HTMLIFrameElement;
-use dom::htmlimageelement::HTMLImageElement;
-use dom::htmlinputelement::HTMLInputElement;
-use dom::htmllabelelement::HTMLLabelElement;
-use dom::htmllielement::HTMLLIElement;
-use dom::htmllinkelement::HTMLLinkElement;
-use dom::htmlmediaelement::HTMLMediaElement;
-use dom::htmlmetaelement::HTMLMetaElement;
-use dom::htmlobjectelement::HTMLObjectElement;
-use dom::htmloptgroupelement::HTMLOptGroupElement;
-use dom::htmloptionelement::HTMLOptionElement;
-use dom::htmloutputelement::HTMLOutputElement;
-use dom::htmlscriptelement::HTMLScriptElement;
-use dom::htmlselectelement::HTMLSelectElement;
-use dom::htmlstyleelement::HTMLStyleElement;
-use dom::htmltablecellelement::HTMLTableCellElement;
-use dom::htmltableelement::HTMLTableElement;
-use dom::htmltablerowelement::HTMLTableRowElement;
-use dom::htmltablesectionelement::HTMLTableSectionElement;
-use dom::htmltemplateelement::HTMLTemplateElement;
-use dom::htmltextareaelement::HTMLTextAreaElement;
-use dom::htmltitleelement::HTMLTitleElement;
-use dom::node::{ChildrenMutation, CloneChildrenFlag, Node, UnbindContext};
-use dom::svgsvgelement::SVGSVGElement;
-use html5ever_atoms::LocalName;
+use crate::dom::attr::Attr;
+use crate::dom::bindings::inheritance::Castable;
+use crate::dom::bindings::inheritance::ElementTypeId;
+use crate::dom::bindings::inheritance::HTMLElementTypeId;
+use crate::dom::bindings::inheritance::HTMLMediaElementTypeId;
+use crate::dom::bindings::inheritance::NodeTypeId;
+use crate::dom::bindings::inheritance::SVGElementTypeId;
+use crate::dom::bindings::inheritance::SVGGraphicsElementTypeId;
+use crate::dom::bindings::str::DOMString;
+use crate::dom::document::Document;
+use crate::dom::element::{AttributeMutation, Element};
+use crate::dom::event::Event;
+use crate::dom::htmlanchorelement::HTMLAnchorElement;
+use crate::dom::htmlareaelement::HTMLAreaElement;
+use crate::dom::htmlbaseelement::HTMLBaseElement;
+use crate::dom::htmlbodyelement::HTMLBodyElement;
+use crate::dom::htmlbuttonelement::HTMLButtonElement;
+use crate::dom::htmlcanvaselement::HTMLCanvasElement;
+use crate::dom::htmldetailselement::HTMLDetailsElement;
+use crate::dom::htmlelement::HTMLElement;
+use crate::dom::htmlfieldsetelement::HTMLFieldSetElement;
+use crate::dom::htmlfontelement::HTMLFontElement;
+use crate::dom::htmlformelement::HTMLFormElement;
+use crate::dom::htmlheadelement::HTMLHeadElement;
+use crate::dom::htmlhrelement::HTMLHRElement;
+use crate::dom::htmliframeelement::HTMLIFrameElement;
+use crate::dom::htmlimageelement::HTMLImageElement;
+use crate::dom::htmlinputelement::HTMLInputElement;
+use crate::dom::htmllabelelement::HTMLLabelElement;
+use crate::dom::htmllielement::HTMLLIElement;
+use crate::dom::htmllinkelement::HTMLLinkElement;
+use crate::dom::htmlmediaelement::HTMLMediaElement;
+use crate::dom::htmlmetaelement::HTMLMetaElement;
+use crate::dom::htmlobjectelement::HTMLObjectElement;
+use crate::dom::htmloptgroupelement::HTMLOptGroupElement;
+use crate::dom::htmloptionelement::HTMLOptionElement;
+use crate::dom::htmloutputelement::HTMLOutputElement;
+use crate::dom::htmlscriptelement::HTMLScriptElement;
+use crate::dom::htmlselectelement::HTMLSelectElement;
+use crate::dom::htmlsourceelement::HTMLSourceElement;
+use crate::dom::htmlstyleelement::HTMLStyleElement;
+use crate::dom::htmltablecellelement::HTMLTableCellElement;
+use crate::dom::htmltableelement::HTMLTableElement;
+use crate::dom::htmltablerowelement::HTMLTableRowElement;
+use crate::dom::htmltablesectionelement::HTMLTableSectionElement;
+use crate::dom::htmltemplateelement::HTMLTemplateElement;
+use crate::dom::htmltextareaelement::HTMLTextAreaElement;
+use crate::dom::htmltitleelement::HTMLTitleElement;
+use crate::dom::htmlvideoelement::HTMLVideoElement;
+use crate::dom::node::{BindContext, ChildrenMutation, CloneChildrenFlag, Node, UnbindContext};
+use crate::dom::svgelement::SVGElement;
+use crate::dom::svgsvgelement::SVGSVGElement;
+use html5ever::LocalName;
use style::attr::AttrValue;
/// Trait to allow DOM nodes to opt-in to overriding (or adding to) common
@@ -59,17 +62,26 @@ use style::attr::AttrValue;
pub trait VirtualMethods {
/// Returns self as the superclass of the implementation for this trait,
/// if any.
- fn super_type(&self) -> Option<&VirtualMethods>;
+ fn super_type(&self) -> Option<&dyn VirtualMethods>;
/// Called when attributes of a node are mutated.
- /// https://dom.spec.whatwg.org/#attribute-is-set
- /// https://dom.spec.whatwg.org/#attribute-is-removed
+ /// <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);
}
}
+ /// Returns `true` if given attribute `attr` affects style of the
+ /// given element.
+ fn attribute_affects_presentational_hints(&self, attr: &Attr) -> bool {
+ match self.super_type() {
+ Some(s) => s.attribute_affects_presentational_hints(attr),
+ None => false,
+ }
+ }
+
/// Returns the right AttrValue variant for the attribute with name `name`
/// on this element.
fn parse_plain_attribute(&self, name: &LocalName, value: DOMString) -> AttrValue {
@@ -79,18 +91,18 @@ pub trait VirtualMethods {
}
}
- /// Called when a Node is appended to a tree, where 'tree_in_doc' indicates
+ /// Called when a Node is appended to a tree, where 'tree_connected' indicates
/// whether the tree is part of a Document.
- fn bind_to_tree(&self, tree_in_doc: bool) {
+ fn bind_to_tree(&self, context: &BindContext) {
if let Some(ref s) = self.super_type() {
- s.bind_to_tree(tree_in_doc);
+ s.bind_to_tree(context);
}
}
- /// Called when a Node is removed from a tree, where 'tree_in_doc'
+ /// Called when a Node is removed from a tree, where 'tree_connected'
/// indicates whether the tree is part of a Document.
/// Implements removing steps:
- /// https://dom.spec.whatwg.org/#concept-node-remove-ext
+ /// <https://dom.spec.whatwg.org/#concept-node-remove-ext>
fn unbind_from_tree(&self, context: &UnbindContext) {
if let Some(ref s) = self.super_type() {
s.unbind_from_tree(context);
@@ -111,16 +123,20 @@ pub trait VirtualMethods {
}
}
- /// https://dom.spec.whatwg.org/#concept-node-adopt-ext
+ /// <https://dom.spec.whatwg.org/#concept-node-adopt-ext>
fn adopting_steps(&self, old_doc: &Document) {
if let Some(ref s) = self.super_type() {
s.adopting_steps(old_doc);
}
}
- /// https://dom.spec.whatwg.org/#concept-node-clone-ext
- fn cloning_steps(&self, copy: &Node, maybe_doc: Option<&Document>,
- clone_children: CloneChildrenFlag) {
+ /// <https://dom.spec.whatwg.org/#concept-node-clone-ext>
+ fn cloning_steps(
+ &self,
+ copy: &Node,
+ maybe_doc: Option<&Document>,
+ clone_children: CloneChildrenFlag,
+ ) {
if let Some(ref s) = self.super_type() {
s.cloning_steps(copy, maybe_doc, clone_children);
}
@@ -139,126 +155,128 @@ pub trait VirtualMethods {
/// method call on the trait object will invoke the corresponding method on the
/// concrete type, propagating up the parent hierarchy unless otherwise
/// interrupted.
-pub fn vtable_for(node: &Node) -> &VirtualMethods {
+pub fn vtable_for(node: &Node) -> &dyn VirtualMethods {
match node.type_id() {
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) => {
- node.downcast::<HTMLAnchorElement>().unwrap() as &VirtualMethods
- }
- NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAppletElement)) => {
- node.downcast::<HTMLAppletElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLAnchorElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) => {
- node.downcast::<HTMLAreaElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLAreaElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBaseElement)) => {
- node.downcast::<HTMLBaseElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLBaseElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLBodyElement)) => {
- node.downcast::<HTMLBodyElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLBodyElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) => {
- node.downcast::<HTMLButtonElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLButtonElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLCanvasElement)) => {
- node.downcast::<HTMLCanvasElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLCanvasElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLDetailsElement)) => {
- node.downcast::<HTMLDetailsElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLDetailsElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFieldSetElement)) => {
- node.downcast::<HTMLFieldSetElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLFieldSetElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFontElement)) => {
- node.downcast::<HTMLFontElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLFontElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLFormElement)) => {
- node.downcast::<HTMLFormElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLFormElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLHeadElement)) => {
- node.downcast::<HTMLHeadElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLHeadElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLHRElement)) => {
- node.downcast::<HTMLHRElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLHRElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLImageElement)) => {
- node.downcast::<HTMLImageElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLImageElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLIFrameElement)) => {
- node.downcast::<HTMLIFrameElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLIFrameElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => {
- node.downcast::<HTMLInputElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLInputElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLabelElement)) => {
- node.downcast::<HTMLLabelElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLLabelElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLIElement)) => {
- node.downcast::<HTMLLIElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLLIElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
- node.downcast::<HTMLLinkElement>().unwrap() as &VirtualMethods
- }
- NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLMediaElement(_))) => {
- node.downcast::<HTMLMediaElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLLinkElement>().unwrap() as &dyn VirtualMethods
+ },
+ NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLMediaElement(
+ media_el,
+ ))) => match media_el {
+ HTMLMediaElementTypeId::HTMLVideoElement => {
+ node.downcast::<HTMLVideoElement>().unwrap() as &dyn VirtualMethods
+ },
+ _ => node.downcast::<HTMLMediaElement>().unwrap() as &dyn VirtualMethods,
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLMetaElement)) => {
- node.downcast::<HTMLMetaElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLMetaElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLObjectElement)) => {
- node.downcast::<HTMLObjectElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLObjectElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOptGroupElement)) => {
- node.downcast::<HTMLOptGroupElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLOptGroupElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOptionElement)) => {
- node.downcast::<HTMLOptionElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLOptionElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLOutputElement)) => {
- node.downcast::<HTMLOutputElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLOutputElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLScriptElement)) => {
- node.downcast::<HTMLScriptElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLScriptElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLSelectElement)) => {
- node.downcast::<HTMLSelectElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLSelectElement>().unwrap() as &dyn VirtualMethods
+ },
+ NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLSourceElement)) => {
+ node.downcast::<HTMLSourceElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLStyleElement)) => {
- node.downcast::<HTMLStyleElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLStyleElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableElement)) => {
- node.downcast::<HTMLTableElement>().unwrap() as &VirtualMethods
- }
- NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableCellElement(_))) => {
- node.downcast::<HTMLTableCellElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLTableElement>().unwrap() as &dyn VirtualMethods
+ },
+ NodeTypeId::Element(ElementTypeId::HTMLElement(
+ HTMLElementTypeId::HTMLTableCellElement,
+ )) => node.downcast::<HTMLTableCellElement>().unwrap() as &dyn VirtualMethods,
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableRowElement)) => {
- node.downcast::<HTMLTableRowElement>().unwrap() as &VirtualMethods
- }
- NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTableSectionElement)) => {
- node.downcast::<HTMLTableSectionElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLTableRowElement>().unwrap() as &dyn VirtualMethods
+ },
+ NodeTypeId::Element(ElementTypeId::HTMLElement(
+ HTMLElementTypeId::HTMLTableSectionElement,
+ )) => node.downcast::<HTMLTableSectionElement>().unwrap() as &dyn VirtualMethods,
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTemplateElement)) => {
- node.downcast::<HTMLTemplateElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLTemplateElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTextAreaElement)) => {
- node.downcast::<HTMLTextAreaElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLTextAreaElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLTitleElement)) => {
- node.downcast::<HTMLTitleElement>().unwrap() as &VirtualMethods
- }
+ node.downcast::<HTMLTitleElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::SVGElement(SVGElementTypeId::SVGGraphicsElement(
- SVGGraphicsElementTypeId::SVGSVGElement
- ))) => {
- node.downcast::<SVGSVGElement>().unwrap() as &VirtualMethods
- }
+ SVGGraphicsElementTypeId::SVGSVGElement,
+ ))) => node.downcast::<SVGSVGElement>().unwrap() as &dyn VirtualMethods,
+ NodeTypeId::Element(ElementTypeId::SVGElement(SVGElementTypeId::SVGElement)) => {
+ node.downcast::<SVGElement>().unwrap() as &dyn VirtualMethods
+ },
NodeTypeId::Element(ElementTypeId::Element) => {
- node.downcast::<Element>().unwrap() as &VirtualMethods
- }
- NodeTypeId::Element(_) => {
- node.downcast::<HTMLElement>().unwrap() as &VirtualMethods
- }
- _ => {
- node as &VirtualMethods
- }
+ node.downcast::<Element>().unwrap() as &dyn VirtualMethods
+ },
+ NodeTypeId::Element(_) => node.downcast::<HTMLElement>().unwrap() as &dyn VirtualMethods,
+ _ => node as &dyn VirtualMethods,
}
}