Log Message
Add support for the translate attribute in html elements. https://bugs.webkit.org/show_bug.cgi?id=78751
Patch by Pablo Flouret <[email protected]> on 2012-02-15 Reviewed by Adam Barth. The translate attribute is used to specify whether an element's attribute values and the values of its Text node children are to be translated when the page is localized, or whether to leave them unchanged. Details at http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#attr-translate Source/WebCore: Test: fast/dom/HTMLElement/translate.html * html/HTMLAttributeNames.in: * html/HTMLElement.cpp: (WebCore::HTMLElement::translateAttributeMode): (WebCore): (WebCore::HTMLElement::translate): (WebCore::HTMLElement::setTranslate): * html/HTMLElement.h: (HTMLElement): * html/HTMLElement.idl: LayoutTests: * fast/dom/HTMLElement/translate-expected.txt: Added. * fast/dom/HTMLElement/translate.html: Added.
Modified Paths
- trunk/LayoutTests/ChangeLog
- trunk/Source/WebCore/ChangeLog
- trunk/Source/WebCore/html/HTMLAttributeNames.in
- trunk/Source/WebCore/html/HTMLElement.cpp
- trunk/Source/WebCore/html/HTMLElement.h
- trunk/Source/WebCore/html/HTMLElement.idl
Added Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (107882 => 107883)
--- trunk/LayoutTests/ChangeLog 2012-02-16 05:29:23 UTC (rev 107882)
+++ trunk/LayoutTests/ChangeLog 2012-02-16 05:42:02 UTC (rev 107883)
@@ -1,3 +1,20 @@
+2012-02-15 Pablo Flouret <[email protected]>
+
+ Add support for the translate attribute in html elements.
+ https://bugs.webkit.org/show_bug.cgi?id=78751
+
+ Reviewed by Adam Barth.
+
+ The translate attribute is used to specify whether an element's
+ attribute values and the values of its Text node children are to be
+ translated when the page is localized, or whether to leave them
+ unchanged.
+
+ Details at http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#attr-translate
+
+ * fast/dom/HTMLElement/translate-expected.txt: Added.
+ * fast/dom/HTMLElement/translate.html: Added.
+
2012-02-15 Noel Gordon <[email protected]>
Unreviewed. compositing/culling/scrolled-within-boxshadow.html IMAGE failure.
Added: trunk/LayoutTests/fast/dom/HTMLElement/translate-expected.txt (0 => 107883)
--- trunk/LayoutTests/fast/dom/HTMLElement/translate-expected.txt (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLElement/translate-expected.txt 2012-02-16 05:42:02 UTC (rev 107883)
@@ -0,0 +1,170 @@
+Test the translate attribute.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+translate should be "yes" by default.
+PASS target.translate is true
+PASS target.getAttribute('translate') is null
+
+target.translate = false;
+PASS target.translate is false
+PASS target.getAttribute('translate') is "no"
+
+target.setAttribute("translate", "yes");
+PASS target.translate is true
+PASS target.getAttribute('translate') is "yes"
+
+target.setAttribute("translate", "no");
+PASS target.translate is false
+PASS target.getAttribute('translate') is "no"
+
+target.setAttribute("translate", "YES");
+PASS target.translate is true
+PASS target.getAttribute('translate') is "YES"
+
+target.setAttribute("translate", "NO");
+PASS target.translate is false
+PASS target.getAttribute('translate') is "NO"
+
+target.setAttribute("translate", "INVALID");
+PASS target.translate is true
+PASS target.getAttribute('translate') is "INVALID"
+
+Removing translate attribute.
+PASS target.getAttribute('translate') is null
+PASS target.translate is true
+
+Creating targetChild element as a child of target.
+PASS targetChild.translate is true
+PASS targetChild.getAttribute('translate') is null
+
+Setting target.translate = false. targetChild should inherit the translate value from its parents.
+PASS targetChild.translate is false
+PASS targetChild.getAttribute('translate') is null
+
+Setting targetChild.setAttribute('translate', 'INVALID'). Should inherit the translate value from its parents.
+PASS target.translate is false
+PASS target.getAttribute('translate') is "no"
+PASS targetChild.translate is false
+PASS targetChild.getAttribute('translate') is "INVALID"
+
+targetChild.translate = true;
+PASS targetChild.translate is true
+PASS targetChild.getAttribute('translate') is "yes"
+PASS target.translate is false
+PASS target.getAttribute('translate') is "no"
+
+
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS target.translate is initialExpectation
+PASS target.translate is lastExpectation
+PASS target.getAttribute('translate') is lastAttributeExpectation
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Added: trunk/LayoutTests/fast/dom/HTMLElement/translate.html (0 => 107883)
--- trunk/LayoutTests/fast/dom/HTMLElement/translate.html (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLElement/translate.html 2012-02-16 05:42:02 UTC (rev 107883)
@@ -0,0 +1,151 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script src=""
+</head>
+<body>
+<script>
+
+description("Test the translate attribute.");
+
+var parent = document.createElement("div");
+document.body.appendChild(parent);
+
+function testFor(initialAttribute, initialExpectation, setValue, lastExpectation, lastAttributeExpectation)
+{
+ var target = document.createElement("span");
+ parent.appendChild(target);
+
+ window.target = target;
+ window.initialExpectation = initialExpectation;
+ window.lastExpectation = lastExpectation;
+ window.lastAttributeExpectation = lastAttributeExpectation;
+
+ if (undefined !== initialAttribute)
+ target.setAttribute("translate", initialAttribute);
+ shouldBe("target.translate", "initialExpectation");
+
+ if (undefined !== setValue)
+ target.translate = setValue;
+ shouldBe("target.translate", "lastExpectation");
+ shouldBe("target.getAttribute('translate')", "lastAttributeExpectation");
+
+ parent.removeChild(target);
+}
+
+window.target = document.createElement("p");
+parent.appendChild(target);
+
+debug('translate should be "yes" by default.');
+shouldBeTrue("target.translate");
+shouldBeNull("target.getAttribute('translate')");
+
+debug('\ntarget.translate = false;');
+target.translate = false;
+shouldBeFalse("target.translate");
+shouldBeEqualToString("target.getAttribute('translate')", "no");
+
+debug('\ntarget.setAttribute("translate", "yes");');
+target.setAttribute("translate", "yes");
+shouldBeTrue("target.translate");
+shouldBeEqualToString("target.getAttribute('translate')", "yes");
+
+debug('\ntarget.setAttribute("translate", "no");');
+target.setAttribute("translate", "no");
+shouldBeFalse("target.translate");
+shouldBeEqualToString("target.getAttribute('translate')", "no");
+
+debug('\ntarget.setAttribute("translate", "YES");');
+target.setAttribute("translate", "YES");
+shouldBeTrue("target.translate");
+shouldBeEqualToString("target.getAttribute('translate')", "YES");
+
+debug('\ntarget.setAttribute("translate", "NO");');
+target.setAttribute("translate", "NO");
+shouldBeFalse("target.translate");
+shouldBeEqualToString("target.getAttribute('translate')", "NO");
+
+debug('\ntarget.setAttribute("translate", "INVALID");');
+target.setAttribute("translate", "INVALID");
+shouldBeTrue("target.translate");
+shouldBeEqualToString("target.getAttribute('translate')", "INVALID");
+
+debug("\nRemoving translate attribute.");
+target.removeAttribute("translate");
+shouldBeNull("target.getAttribute('translate')");
+shouldBeTrue("target.translate");
+
+debug("\nCreating targetChild element as a child of target.");
+window.targetChild = document.createElement("span");
+target.appendChild(targetChild);
+shouldBeTrue("targetChild.translate");
+shouldBeNull("targetChild.getAttribute('translate')");
+
+debug("\nSetting target.translate = false. targetChild should inherit the translate value from its parents.");
+target.translate = false;
+shouldBeFalse("targetChild.translate");
+shouldBeNull("targetChild.getAttribute('translate')");
+
+debug("\nSetting targetChild.setAttribute('translate', 'INVALID'). Should inherit the translate value from its parents.");
+targetChild.setAttribute("translate", "INVALID");
+shouldBeFalse("target.translate");
+shouldBeEqualToString("target.getAttribute('translate')", "no");
+shouldBeFalse("targetChild.translate");
+shouldBeEqualToString("targetChild.getAttribute('translate')", "INVALID");
+
+debug("\ntargetChild.translate = true;");
+targetChild.translate = true;
+shouldBeTrue("targetChild.translate");
+shouldBeEqualToString("targetChild.getAttribute('translate')", "yes");
+shouldBeFalse("target.translate");
+shouldBeEqualToString("target.getAttribute('translate')", "no");
+
+parent.removeChild(target);
+
+debug("\n");
+
+testFor(undefined, true, undefined, true, null);
+testFor(undefined, true, false, false, "no");
+testFor(undefined, true, true, true, "yes");
+testFor(undefined, true, 0, false, "no"); // 0 will be coerced to false
+testFor(undefined, true, 1, true, "yes"); // 0 will be coerced to true
+testFor(undefined, true, "invalid", true, "yes"); // string will be coerced to true
+testFor(undefined, true, "false", true, "yes"); // ...even if the string is "false" (as Firefox does).
+
+testFor("yes", true, undefined, true, "yes");
+testFor("yes", true, false, false, "no");
+testFor("yes", true, true, true, "yes");
+testFor("yes", true, 0, false, "no");
+testFor("yes", true, 1, true, "yes");
+testFor("yes", true, "invalid", true, "yes");
+testFor("yes", true, "false", true, "yes");
+
+testFor("no", false, undefined, false, "no");
+testFor("no", false, false, false, "no");
+testFor("no", false, true, true, "yes");
+testFor("no", false, 0, false, "no");
+testFor("no", false, 1, true, "yes");
+testFor("no", false, "invalid", true, "yes");
+testFor("no", false, "false", true, "yes");
+
+// various initial values
+testFor("", true, undefined, true, "");
+testFor("", true, 1, true, "yes");
+testFor("YES", true, undefined, true, "YES");
+testFor("YES", true, 1, true, "yes");
+testFor("NO", false, undefined, false, "NO");
+testFor("NO", false, 0, false, "no");
+testFor("invalid", true, undefined, true, "invalid");
+testFor("invalid", true, 1, true, "yes");
+testFor("no ", true, undefined, true, "no ");
+testFor("no ", true, 1, true, "yes");
+testFor("no ", true, 0, false, "no");
+testFor("0", true, undefined, true, "0");
+testFor("0", true, 0, false, "no");
+testFor("1", true, undefined, true, "1");
+testFor("1", true, 0, false, "no");
+</script>
+<script src=""
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (107882 => 107883)
--- trunk/Source/WebCore/ChangeLog 2012-02-16 05:29:23 UTC (rev 107882)
+++ trunk/Source/WebCore/ChangeLog 2012-02-16 05:42:02 UTC (rev 107883)
@@ -1,3 +1,29 @@
+2012-02-15 Pablo Flouret <[email protected]>
+
+ Add support for the translate attribute in html elements.
+ https://bugs.webkit.org/show_bug.cgi?id=78751
+
+ Reviewed by Adam Barth.
+
+ The translate attribute is used to specify whether an element's
+ attribute values and the values of its Text node children are to be
+ translated when the page is localized, or whether to leave them
+ unchanged.
+
+ Details at http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#attr-translate
+
+ Test: fast/dom/HTMLElement/translate.html
+
+ * html/HTMLAttributeNames.in:
+ * html/HTMLElement.cpp:
+ (WebCore::HTMLElement::translateAttributeMode):
+ (WebCore):
+ (WebCore::HTMLElement::translate):
+ (WebCore::HTMLElement::setTranslate):
+ * html/HTMLElement.h:
+ (HTMLElement):
+ * html/HTMLElement.idl:
+
2012-02-15 Sami Kyostila <[email protected]>
Add -webkit-overflow-scrolling CSS property
Modified: trunk/Source/WebCore/html/HTMLAttributeNames.in (107882 => 107883)
--- trunk/Source/WebCore/html/HTMLAttributeNames.in 2012-02-16 05:29:23 UTC (rev 107882)
+++ trunk/Source/WebCore/html/HTMLAttributeNames.in 2012-02-16 05:42:02 UTC (rev 107883)
@@ -304,6 +304,7 @@
title
top
topmargin
+translate
truespeed
type
usemap
Modified: trunk/Source/WebCore/html/HTMLElement.cpp (107882 => 107883)
--- trunk/Source/WebCore/html/HTMLElement.cpp 2012-02-16 05:29:23 UTC (rev 107882)
+++ trunk/Source/WebCore/html/HTMLElement.cpp 2012-02-16 05:42:02 UTC (rev 107883)
@@ -800,6 +800,42 @@
setAttribute(tabindexAttr, String::number(value));
}
+TranslateAttributeMode HTMLElement::translateAttributeMode() const
+{
+ const AtomicString& value = getAttribute(translateAttr);
+
+ if (value == nullAtom)
+ return TranslateAttributeInherit;
+ if (equalIgnoringCase(value, "yes") || equalIgnoringCase(value, ""))
+ return TranslateAttributeYes;
+ if (equalIgnoringCase(value, "no"))
+ return TranslateAttributeNo;
+
+ return TranslateAttributeInherit;
+}
+
+bool HTMLElement::translate() const
+{
+ for (const Node* n = this; n; n = n->parentNode()) {
+ if (n->isHTMLElement()) {
+ TranslateAttributeMode mode = static_cast<const HTMLElement*>(n)->translateAttributeMode();
+ if (mode != TranslateAttributeInherit) {
+ ASSERT(mode == TranslateAttributeYes || mode == TranslateAttributeNo);
+ return mode == TranslateAttributeYes;
+ }
+ }
+ }
+
+ // Default on the root element is translate=yes.
+ return true;
+}
+
+void HTMLElement::setTranslate(bool enable)
+{
+ setAttribute(translateAttr, enable ? "yes" : "no");
+}
+
+
HTMLCollection* HTMLElement::children()
{
return ensureCachedHTMLCollection(NodeChildren);
Modified: trunk/Source/WebCore/html/HTMLElement.h (107882 => 107883)
--- trunk/Source/WebCore/html/HTMLElement.h 2012-02-16 05:29:23 UTC (rev 107882)
+++ trunk/Source/WebCore/html/HTMLElement.h 2012-02-16 05:42:02 UTC (rev 107883)
@@ -35,6 +35,12 @@
class MicroDataItemValue;
#endif
+enum TranslateAttributeMode {
+ TranslateAttributeYes,
+ TranslateAttributeNo,
+ TranslateAttributeInherit
+};
+
class HTMLElement : public StyledElement {
public:
static PassRefPtr<HTMLElement> create(const QualifiedName& tagName, Document*);
@@ -68,6 +74,9 @@
bool spellcheck() const;
void setSpellcheck(bool);
+ bool translate() const;
+ void setTranslate(bool);
+
void click();
virtual void accessKeyAction(bool sendMouseEvents);
@@ -121,6 +130,8 @@
void adjustDirectionalityIfNeededAfterChildrenChanged(Node* beforeChange, int childCountDelta);
TextDirection directionality(Node** strongDirectionalityTextNode= 0) const;
+ TranslateAttributeMode translateAttributeMode() const;
+
#if ENABLE(MICRODATA)
virtual String itemValueText() const;
virtual void setItemValueText(const String&, ExceptionCode&);
Modified: trunk/Source/WebCore/html/HTMLElement.idl (107882 => 107883)
--- trunk/Source/WebCore/html/HTMLElement.idl 2012-02-16 05:29:23 UTC (rev 107882)
+++ trunk/Source/WebCore/html/HTMLElement.idl 2012-02-16 05:42:02 UTC (rev 107883)
@@ -30,6 +30,7 @@
attribute [Reflect] DOMString id;
attribute [Reflect] DOMString title;
attribute [Reflect] DOMString lang;
+ attribute boolean translate;
attribute [Reflect] DOMString dir;
attribute [Reflect=class] DOMString className;
readonly attribute DOMTokenList classList;
_______________________________________________ webkit-changes mailing list [email protected] http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes
