mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-28 07:13:20 +00:00
Bug 1418449 - Add translate attribute to HTMLElement. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D167081
This commit is contained in:
parent
41cec042e8
commit
2e0b78ffc1
@ -4842,4 +4842,11 @@ void Element::SetHTML(const nsAString& aInnerHTML,
|
||||
}
|
||||
}
|
||||
|
||||
bool Element::Translate() const {
|
||||
if (const auto* parent = Element::FromNodeOrNull(mParent)) {
|
||||
return parent->Translate();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace mozilla::dom
|
||||
|
@ -2042,6 +2042,8 @@ class Element : public FragmentOrElement {
|
||||
*/
|
||||
virtual void GetLinkTarget(nsAString& aTarget);
|
||||
|
||||
virtual bool Translate() const;
|
||||
|
||||
protected:
|
||||
enum class ReparseAttributes { No, Yes };
|
||||
/**
|
||||
|
@ -919,7 +919,8 @@ bool nsGenericHTMLElement::ParseAttribute(int32_t aNamespaceID,
|
||||
return true;
|
||||
}
|
||||
|
||||
if (aAttribute == nsGkAtoms::contenteditable) {
|
||||
if (aAttribute == nsGkAtoms::contenteditable ||
|
||||
aAttribute == nsGkAtoms::translate) {
|
||||
aResult.ParseAtom(aValue);
|
||||
return true;
|
||||
}
|
||||
@ -3077,3 +3078,15 @@ void nsGenericHTMLElement::GetAutocapitalize(nsAString& aValue) const {
|
||||
GetEnumAttr(nsGkAtoms::autocapitalize, nullptr, kDefaultAutocapitalize->tag,
|
||||
aValue);
|
||||
}
|
||||
|
||||
bool nsGenericHTMLElement::Translate() const {
|
||||
if (const nsAttrValue* attr = mAttrs.GetAttr(nsGkAtoms::translate)) {
|
||||
if (attr->IsEmptyString() || attr->Equals(nsGkAtoms::yes, eIgnoreCase)) {
|
||||
return true;
|
||||
}
|
||||
if (attr->Equals(nsGkAtoms::no, eIgnoreCase)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return nsGenericHTMLElementBase::Translate();
|
||||
}
|
||||
|
@ -75,6 +75,11 @@ class nsGenericHTMLElement : public nsGenericHTMLElementBase {
|
||||
GetHTMLAttr(nsGkAtoms::lang, aLang);
|
||||
}
|
||||
void SetLang(const nsAString& aLang) { SetHTMLAttr(nsGkAtoms::lang, aLang); }
|
||||
bool Translate() const override;
|
||||
void SetTranslate(bool aTranslate, mozilla::ErrorResult& aError) {
|
||||
SetHTMLAttr(nsGkAtoms::translate, aTranslate ? u"yes"_ns : u"no"_ns,
|
||||
aError);
|
||||
}
|
||||
void GetDir(nsAString& aDir) { GetHTMLEnumAttr(nsGkAtoms::dir, aDir); }
|
||||
void SetDir(const nsAString& aDir, mozilla::ErrorResult& aError) {
|
||||
SetHTMLAttr(nsGkAtoms::dir, aDir, aError);
|
||||
|
@ -21,7 +21,8 @@ interface HTMLElement : Element {
|
||||
attribute DOMString title;
|
||||
[CEReactions]
|
||||
attribute DOMString lang;
|
||||
// attribute boolean translate;
|
||||
[CEReactions, SetterThrows, Pure]
|
||||
attribute boolean translate;
|
||||
[CEReactions, SetterThrows, Pure]
|
||||
attribute DOMString dir;
|
||||
|
||||
|
@ -1,8 +0,0 @@
|
||||
[HTMLElement.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[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
|
@ -1,5 +0,0 @@
|
||||
[the-translate-attribute-007.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[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
|
@ -1,5 +0,0 @@
|
||||
[the-translate-attribute-008.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[If the translate attribute is set to yes, javascript will detect the translation mode of text as translate-enabled.]
|
||||
expected: FAIL
|
@ -1,5 +0,0 @@
|
||||
[the-translate-attribute-009.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[If the translate attribute is set to no, javascript will detect the translation mode of text as no-translate.]
|
||||
expected: FAIL
|
@ -1,5 +0,0 @@
|
||||
[the-translate-attribute-010.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[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
|
@ -1,5 +0,0 @@
|
||||
[the-translate-attribute-011.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[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
|
@ -1,5 +0,0 @@
|
||||
[the-translate-attribute-012.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [TIMEOUT, OK]
|
||||
[If the translate attribute is set to a null string, javascript will detect the translation mode of text as translate-enabled.]
|
||||
expected: FAIL
|
@ -1,5 +0,0 @@
|
||||
[translate-enumerated-ascii-case-insensitive.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[keyword yes]
|
||||
expected: FAIL
|
@ -1,17 +0,0 @@
|
||||
[translate-inherit-no-parent-element.html]
|
||||
expected:
|
||||
if (os == "android") and fission: [OK, TIMEOUT]
|
||||
[No parent node]
|
||||
expected: FAIL
|
||||
|
||||
[DocumentFragment parent node]
|
||||
expected: FAIL
|
||||
|
||||
[ShadowRoot parent node whose shadow host has translate=yes]
|
||||
expected: FAIL
|
||||
|
||||
[ShadowRoot parent node whose shadow host has translate=no]
|
||||
expected: FAIL
|
||||
|
||||
[Document parent node]
|
||||
expected: FAIL
|
@ -562,9 +562,6 @@ prefs: [dom.security.featurePolicy.experimental.enabled:true, dom.security.featu
|
||||
[HTMLInputElement interface: createInput("time") must inherit property "dirName" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLElement interface: document.createElement("noscript") must inherit property "translate" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("number") must inherit property "dirName" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
@ -628,9 +625,6 @@ prefs: [dom.security.featurePolicy.experimental.enabled:true, dom.security.featu
|
||||
[HTMLMediaElement interface: attribute videoTracks]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLElement interface: attribute translate]
|
||||
expected: FAIL
|
||||
|
||||
[HTMLInputElement interface: createInput("image") must inherit property "dirName" with the proper type]
|
||||
expected: FAIL
|
||||
|
||||
|
@ -0,0 +1,46 @@
|
||||
<!doctype html>
|
||||
<meta charset=utf-8>
|
||||
<title>Non-HTML elements have a translation mode</title>
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const svgContainer = document.createElement("svg");
|
||||
const foreignObject = document.createElement("foreignObject");
|
||||
svgContainer.appendChild(foreignObject);
|
||||
const div = document.createElement("div");
|
||||
foreignObject.appendChild(div);
|
||||
|
||||
assert_true(div.translate);
|
||||
}, 'Non-HTML elements default to translate-enabled');
|
||||
|
||||
test(() => {
|
||||
const outerDiv = document.createElement("div");
|
||||
outerDiv.translate = true;
|
||||
assert_true(outerDiv.translate);
|
||||
|
||||
const svgContainer = document.createElement("svg");
|
||||
outerDiv.appendChild(svgContainer);
|
||||
const foreignObject = document.createElement("foreignObject");
|
||||
svgContainer.appendChild(foreignObject);
|
||||
const div = document.createElement("div");
|
||||
foreignObject.appendChild(div);
|
||||
|
||||
assert_true(div.translate);
|
||||
}, "Non-HTML elements inherit their parent's translation-enabled state");
|
||||
|
||||
test(() => {
|
||||
const outerDiv = document.createElement("div");
|
||||
outerDiv.translate = false;
|
||||
assert_false(outerDiv.translate);
|
||||
|
||||
const svgContainer = document.createElement("svg");
|
||||
outerDiv.appendChild(svgContainer);
|
||||
const foreignObject = document.createElement("foreignObject");
|
||||
svgContainer.appendChild(foreignObject);
|
||||
const div = document.createElement("div");
|
||||
foreignObject.appendChild(div);
|
||||
|
||||
assert_false(div.translate);
|
||||
}, "Non-HTML elements inherit their parent's no-translation state");
|
||||
</script>
|
Loading…
Reference in New Issue
Block a user