diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2020-02-13 08:26:28 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-13 08:26:28 -0500 |
commit | e3a2301efe911dfa232803a293f62c16ffdd3925 (patch) | |
tree | b0f4a74dade56bddf7a8c2ae2241302e5e10e3c5 | |
parent | 43c558fa597901f30f6994e2d99858f2954fdce2 (diff) | |
parent | 3f8a9f63821abff0c7a284cd4d3bb75f41ea3cd4 (diff) | |
download | servo-e3a2301efe911dfa232803a293f62c16ffdd3925.tar.gz servo-e3a2301efe911dfa232803a293f62c16ffdd3925.zip |
Auto merge of #25629 - pshaughn:reflect_translate, r=jdm
Implement "translate" attribute
This attribute is almost a straightforward enumerated one, but the getter value inherits from parents when the content attribute is absent, even when the parents are non-HTML elements. This initial commit is using LocalName::from on a static string; once html5ever has a release with "translate" in the built-in local name list, a small change will be needed.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [X] These changes fix #25628
<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because ___
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
11 files changed, 38 insertions, 44 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index c26e492d544..3c321d83f54 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -523,6 +523,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 b5cd0930def..28aa976002e 100644 --- a/components/script/dom/htmlelement.rs +++ b/components/script/dom/htmlelement.rs @@ -546,6 +546,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; diff --git a/tests/wpt/metadata/custom-elements/reactions/HTMLElement.html.ini b/tests/wpt/metadata/custom-elements/reactions/HTMLElement.html.ini index 44ad7d81adc..7a1eceb9555 100644 --- a/tests/wpt/metadata/custom-elements/reactions/HTMLElement.html.ini +++ b/tests/wpt/metadata/custom-elements/reactions/HTMLElement.html.ini @@ -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 diff --git a/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-007.html.ini b/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-007.html.ini deleted file mode 100644 index d1c210ac5b7..00000000000 --- a/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-007.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[the-translate-attribute-007.html] - type: testharness - [In the default case, ie. with no translate attribute in the page, javascript will detect the translation mode of text as translate-enabled.] - expected: FAIL - diff --git a/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-008.html.ini b/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-008.html.ini deleted file mode 100644 index 5fcf74aacb5..00000000000 --- a/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-008.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[the-translate-attribute-008.html] - type: testharness - [If the translate attribute is set to yes, javascript will detect the translation mode of text as translate-enabled.] - expected: FAIL - diff --git a/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-009.html.ini b/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-009.html.ini deleted file mode 100644 index decc9584c61..00000000000 --- a/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-009.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[the-translate-attribute-009.html] - type: testharness - [If the translate attribute is set to no, javascript will detect the translation mode of text as no-translate.] - expected: FAIL - diff --git a/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-010.html.ini b/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-010.html.ini deleted file mode 100644 index 0f0ef682cc4..00000000000 --- a/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-010.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[the-translate-attribute-010.html] - type: testharness - [If the translate attribute is set to no, javascript will detect the translation mode of elements inside that element with no translate flag as no-translate.] - expected: FAIL - diff --git a/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-011.html.ini b/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-011.html.ini deleted file mode 100644 index 64bf17a07c6..00000000000 --- a/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-011.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[the-translate-attribute-011.html] - type: testharness - [If the translate attribute is set to yes on an element inside an element with the translate attribute set to no, javascript will detect the translation mode of text in the inner element as translate-enabled.] - expected: FAIL - diff --git a/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-012.html.ini b/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-012.html.ini deleted file mode 100644 index 8863e305357..00000000000 --- a/tests/wpt/metadata/html/dom/elements/global-attributes/the-translate-attribute-012.html.ini +++ /dev/null @@ -1,5 +0,0 @@ -[the-translate-attribute-012.html] - type: testharness - [If the translate attribute is set to a null string, javascript will detect the translation mode of text as translate-enabled.] - expected: FAIL - diff --git a/tests/wpt/metadata/html/dom/idlharness.https.html.ini b/tests/wpt/metadata/html/dom/idlharness.https.html.ini index 1c094dd479f..d89851f7c65 100644 --- a/tests/wpt/metadata/html/dom/idlharness.https.html.ini +++ b/tests/wpt/metadata/html/dom/idlharness.https.html.ini @@ -2385,9 +2385,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 @@ -3726,9 +3723,6 @@ [HTMLAreaElement interface: attribute hostname] expected: FAIL - [HTMLElement interface: attribute translate] - expected: FAIL - [HTMLTableColElement interface: attribute span] expected: FAIL |