Skip to content

Commit

Permalink
Translate attribute and its inheritance semantics
Browse files Browse the repository at this point in the history
  • Loading branch information
pshaughn committed Feb 13, 2020
1 parent d0f64d9 commit 3f8a9f6
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 44 deletions.
19 changes: 19 additions & 0 deletions components/script/dom/element.rs
Expand Up @@ -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)]
Expand Down
17 changes: 17 additions & 0 deletions components/script/dom/htmlelement.rs
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions components/script/dom/webidls/HTMLElement.webidl
Expand Up @@ -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;
Expand Down
@@ -1,11 +1,5 @@
[HTMLElement.html]
type: testharness
[translate on HTMLElement must enqueue an attributeChanged reaction when adding translate content attribute]
expected: FAIL

[translate on HTMLElement must enqueue an attributeChanged reaction when replacing an existing attribute]
expected: FAIL

[dir on HTMLElement must enqueue an attributeChanged reaction when adding dir content attribute]
expected: FAIL

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions tests/wpt/metadata/html/dom/idlharness.https.html.ini
Expand Up @@ -2424,9 +2424,6 @@
[HTMLObjectElement interface: attribute name]
expected: FAIL

[HTMLElement interface: document.createElement("noscript") must inherit property "translate" with the proper type]
expected: FAIL

[HTMLFrameElement interface: document.createElement("frame") must inherit property "contentWindow" with the proper type]
expected: FAIL

Expand Down Expand Up @@ -3765,9 +3762,6 @@
[HTMLAreaElement interface: attribute hostname]
expected: FAIL
[HTMLElement interface: attribute translate]
expected: FAIL
[HTMLTableColElement interface: attribute span]
expected: FAIL
Expand Down

0 comments on commit 3f8a9f6

Please sign in to comment.