aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorPatrick Shaughnessy <pshaughn@comcast.net>2020-01-27 22:45:07 -0500
committerPatrick Shaughnessy <pshaughn@comcast.net>2020-02-12 20:54:41 -0500
commit3f8a9f63821abff0c7a284cd4d3bb75f41ea3cd4 (patch)
tree34ee55ecfa340f6899f294611e39b6b54bc02909 /components/script
parentd0f64d9d56979f66a0de2f239c3fc691b45535d6 (diff)
downloadservo-3f8a9f63821abff0c7a284cd4d3bb75f41ea3cd4.tar.gz
servo-3f8a9f63821abff0c7a284cd4d3bb75f41ea3cd4.zip
Translate attribute and its inheritance semantics
Diffstat (limited to 'components/script')
-rw-r--r--components/script/dom/element.rs19
-rw-r--r--components/script/dom/htmlelement.rs17
-rw-r--r--components/script/dom/webidls/HTMLElement.webidl4
3 files changed, 38 insertions, 2 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 29bdaf2f3bf..cd9fb4481ad 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -514,6 +514,25 @@ impl Element {
debug_assert!(false, "Trying to detach a non-attached shadow root");
}
}
+
+ // https://html.spec.whatwg.org/multipage/#translation-mode
+ pub fn is_translate_enabled(&self) -> bool {
+ // TODO change this to local_name! when html5ever updates
+ let name = &LocalName::from("translate");
+ if self.has_attribute(name) {
+ match &*self.get_string_attribute(name) {
+ "yes" | "" => return true,
+ "no" => return false,
+ _ => {},
+ }
+ }
+ if let Some(parent) = self.upcast::<Node>().GetParentNode() {
+ if let Some(elem) = parent.downcast::<Element>() {
+ return elem.is_translate_enabled();
+ }
+ }
+ true // whatwg/html#5239
+ }
}
#[allow(unsafe_code)]
diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs
index c5b7e6d0251..eea1d94de51 100644
--- a/components/script/dom/htmlelement.rs
+++ b/components/script/dom/htmlelement.rs
@@ -516,6 +516,23 @@ impl HTMLElementMethods for HTMLElement {
// Step 7.
Node::replace_all(Some(fragment.upcast()), self.upcast::<Node>());
}
+
+ // https://html.spec.whatwg.org/multipage/#dom-translate
+ fn Translate(&self) -> bool {
+ self.upcast::<Element>().is_translate_enabled()
+ }
+
+ // https://html.spec.whatwg.org/multipage/#dom-translate
+ fn SetTranslate(&self, yesno: bool) {
+ self.upcast::<Element>().set_string_attribute(
+ // TODO change this to local_name! when html5ever updates
+ &LocalName::from("translate"),
+ match yesno {
+ true => DOMString::from("yes"),
+ false => DOMString::from("no"),
+ },
+ );
+ }
}
fn append_text_node_to_fragment(document: &Document, fragment: &DocumentFragment, text: String) {
diff --git a/components/script/dom/webidls/HTMLElement.webidl b/components/script/dom/webidls/HTMLElement.webidl
index 1d15740f6c7..ef529dc80af 100644
--- a/components/script/dom/webidls/HTMLElement.webidl
+++ b/components/script/dom/webidls/HTMLElement.webidl
@@ -12,8 +12,8 @@ interface HTMLElement : Element {
attribute DOMString title;
[CEReactions]
attribute DOMString lang;
- // [CEReactions]
- // attribute boolean translate;
+ [CEReactions]
+ attribute boolean translate;
// [CEReactions]
// attribute DOMString dir;
readonly attribute DOMStringMap dataset;