- Revision
- 179181
- Author
- [email protected]
- Date
- 2015-01-27 07:59:58 -0800 (Tue, 27 Jan 2015)
Log Message
HTMLElement.dir should only return known values
https://bugs.webkit.org/show_bug.cgi?id=140925
Reviewed by Darin Adler.
Source/WebCore:
HTMLElement.dir should only return known values according to the HTML
specification:
https://html.spec.whatwg.org/multipage/dom.html#dom-document-dir
Chrome and Firefox 28 match the specification. IE11's behavior is
slightly different:
- When setting an unknown 'dir' value, an exception will be thrown.
- Setting a known 'dir' value in a non-canonical case (e.g. "RTL"),
the value will be directly converted to its canonical form (e.g.
"rtl") before updating the DOM tree. (close to the spec but changing
the case upon setting).
This patch is based on the following Blink revision by me:
https://src.chromium.org/viewvc/blink?view=rev&revision=171861
Test: fast/dom/document-dir-property.html
* html/HTMLDocument.cpp:
(WebCore::HTMLDocument::dir):
(WebCore::HTMLDocument::setDir):
* html/HTMLDocument.h:
* html/HTMLElement.cpp:
(WebCore::toValidDirValue):
(WebCore::HTMLElement::dir):
(WebCore::HTMLElement::setDir):
* html/HTMLElement.h:
* html/HTMLElement.idl:
LayoutTests:
Update fast/dom/document-dir-property.html to make sure HTMLDocument.dir
and HTMLElement.dir only return known values, as per the HTML
specification.
* fast/dom/document-dir-property-expected.txt:
* fast/dom/document-dir-property.html:
Modified Paths
Diff
Modified: trunk/LayoutTests/ChangeLog (179180 => 179181)
--- trunk/LayoutTests/ChangeLog 2015-01-27 15:32:20 UTC (rev 179180)
+++ trunk/LayoutTests/ChangeLog 2015-01-27 15:59:58 UTC (rev 179181)
@@ -1,3 +1,17 @@
+2015-01-27 Chris Dumez <[email protected]>
+
+ HTMLElement.dir should only return known values
+ https://bugs.webkit.org/show_bug.cgi?id=140925
+
+ Reviewed by Darin Adler.
+
+ Update fast/dom/document-dir-property.html to make sure HTMLDocument.dir
+ and HTMLElement.dir only return known values, as per the HTML
+ specification.
+
+ * fast/dom/document-dir-property-expected.txt:
+ * fast/dom/document-dir-property.html:
+
2015-01-27 Michal Poteralski <[email protected]>
[EFL] AX: Update test expectations for test related with AXRole.
Modified: trunk/LayoutTests/fast/dom/document-dir-property-expected.txt (179180 => 179181)
--- trunk/LayoutTests/fast/dom/document-dir-property-expected.txt 2015-01-27 15:32:20 UTC (rev 179180)
+++ trunk/LayoutTests/fast/dom/document-dir-property-expected.txt 2015-01-27 15:59:58 UTC (rev 179181)
@@ -27,6 +27,26 @@
Read document.body.dir in body
PASS document.body.dir is ""
+Write non-canonical case document.dir in body
+PASS document.dir = 'RTL' did not throw exception.
+PASS document.documentElement.getAttribute('dir') is "RTL"
+PASS document.dir is "rtl"
+
+Write invalid document.dir in body
+PASS document.dir = 'WRONG' did not throw exception.
+PASS document.documentElement.getAttribute('dir') is "WRONG"
+PASS document.dir is ""
+
+Write non-canonical case document.body.dir in body
+PASS document.body.dir = 'RTL' did not throw exception.
+PASS document.body.getAttribute('dir') is "RTL"
+PASS document.body.dir is "rtl"
+
+Write invalid document.body.dir in body
+PASS document.body.dir = 'WRONG' did not throw exception.
+PASS document.body.getAttribute('dir') is "WRONG"
+PASS document.body.dir is ""
+
PASS successfullyParsed is true
TEST COMPLETE
Modified: trunk/LayoutTests/fast/dom/document-dir-property.html (179180 => 179181)
--- trunk/LayoutTests/fast/dom/document-dir-property.html 2015-01-27 15:32:20 UTC (rev 179180)
+++ trunk/LayoutTests/fast/dom/document-dir-property.html 2015-01-27 15:59:58 UTC (rev 179181)
@@ -43,6 +43,30 @@
debug("Read document.body.dir in body");
shouldBeEqualToString("document.body.dir", "");
debug("");
+
+debug("Write non-canonical case document.dir in body");
+shouldNotThrow("document.dir = 'RTL'");
+shouldBeEqualToString("document.documentElement.getAttribute('dir')", "RTL");
+shouldBeEqualToString("document.dir", "rtl");
+debug("");
+
+debug("Write invalid document.dir in body");
+shouldNotThrow("document.dir = 'WRONG'");
+shouldBeEqualToString("document.documentElement.getAttribute('dir')", "WRONG");
+shouldBeEqualToString("document.dir", "");
+debug("");
+
+debug("Write non-canonical case document.body.dir in body");
+shouldNotThrow("document.body.dir = 'RTL'");
+shouldBeEqualToString("document.body.getAttribute('dir')", "RTL");
+shouldBeEqualToString("document.body.dir", "rtl");
+debug("");
+
+debug("Write invalid document.body.dir in body");
+shouldNotThrow("document.body.dir = 'WRONG'");
+shouldBeEqualToString("document.body.getAttribute('dir')", "WRONG");
+shouldBeEqualToString("document.body.dir", "");
+debug("");
</script>
</body>
</html>
Modified: trunk/Source/WebCore/ChangeLog (179180 => 179181)
--- trunk/Source/WebCore/ChangeLog 2015-01-27 15:32:20 UTC (rev 179180)
+++ trunk/Source/WebCore/ChangeLog 2015-01-27 15:59:58 UTC (rev 179181)
@@ -1,3 +1,38 @@
+2015-01-27 Chris Dumez <[email protected]>
+
+ HTMLElement.dir should only return known values
+ https://bugs.webkit.org/show_bug.cgi?id=140925
+
+ Reviewed by Darin Adler.
+
+ HTMLElement.dir should only return known values according to the HTML
+ specification:
+ https://html.spec.whatwg.org/multipage/dom.html#dom-document-dir
+
+ Chrome and Firefox 28 match the specification. IE11's behavior is
+ slightly different:
+ - When setting an unknown 'dir' value, an exception will be thrown.
+ - Setting a known 'dir' value in a non-canonical case (e.g. "RTL"),
+ the value will be directly converted to its canonical form (e.g.
+ "rtl") before updating the DOM tree. (close to the spec but changing
+ the case upon setting).
+
+ This patch is based on the following Blink revision by me:
+ https://src.chromium.org/viewvc/blink?view=rev&revision=171861
+
+ Test: fast/dom/document-dir-property.html
+
+ * html/HTMLDocument.cpp:
+ (WebCore::HTMLDocument::dir):
+ (WebCore::HTMLDocument::setDir):
+ * html/HTMLDocument.h:
+ * html/HTMLElement.cpp:
+ (WebCore::toValidDirValue):
+ (WebCore::HTMLElement::dir):
+ (WebCore::HTMLElement::setDir):
+ * html/HTMLElement.h:
+ * html/HTMLElement.idl:
+
2015-01-26 Chris Dumez <[email protected]>
Introduce Document::body() for call sites interested in the <body> element
Modified: trunk/Source/WebCore/html/HTMLDocument.cpp (179180 => 179181)
--- trunk/Source/WebCore/html/HTMLDocument.cpp 2015-01-27 15:32:20 UTC (rev 179180)
+++ trunk/Source/WebCore/html/HTMLDocument.cpp 2015-01-27 15:59:58 UTC (rev 179181)
@@ -70,6 +70,7 @@
#include "HTMLElementFactory.h"
#include "HTMLFrameOwnerElement.h"
#include "HTMLFrameSetElement.h"
+#include "HTMLHtmlElement.h"
#include "HTMLNames.h"
#include "JSDOMBinding.h"
#include "Page.h"
@@ -106,19 +107,19 @@
return frameView ? frameView->contentsHeight() : 0;
}
-const AtomicString& HTMLDocument::dir()
+const AtomicString& HTMLDocument::dir() const
{
auto* documentElement = this->documentElement();
if (!is<HTMLHtmlElement>(*documentElement))
return nullAtom;
- return documentElement->fastGetAttribute(dirAttr);
+ return downcast<HTMLHtmlElement>(*documentElement).dir();
}
void HTMLDocument::setDir(const AtomicString& value)
{
auto* documentElement = this->documentElement();
if (is<HTMLHtmlElement>(documentElement))
- documentElement->setAttribute(dirAttr, value);
+ downcast<HTMLHtmlElement>(*documentElement).setDir(value);
}
String HTMLDocument::designMode() const
Modified: trunk/Source/WebCore/html/HTMLDocument.h (179180 => 179181)
--- trunk/Source/WebCore/html/HTMLDocument.h 2015-01-27 15:32:20 UTC (rev 179180)
+++ trunk/Source/WebCore/html/HTMLDocument.h 2015-01-27 15:59:58 UTC (rev 179181)
@@ -46,7 +46,7 @@
int width();
int height();
- const AtomicString& dir();
+ const AtomicString& dir() const;
void setDir(const AtomicString&);
String designMode() const;
Modified: trunk/Source/WebCore/html/HTMLElement.cpp (179180 => 179181)
--- trunk/Source/WebCore/html/HTMLElement.cpp 2015-01-27 15:32:20 UTC (rev 179180)
+++ trunk/Source/WebCore/html/HTMLElement.cpp 2015-01-27 15:59:58 UTC (rev 179181)
@@ -460,6 +460,35 @@
|| element.hasTagName(trTag);
}
+// Returns the conforming 'dir' value associated with the state the attribute is in (in its canonical case), if any,
+// or the empty string if the attribute is in a state that has no associated keyword value or if the attribute is
+// not in a defined state (e.g. the attribute is missing and there is no missing value default).
+// http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#limited-to-only-known-values
+static inline const AtomicString& toValidDirValue(const AtomicString& value)
+{
+ static NeverDestroyed<AtomicString> ltrValue("ltr", AtomicString::ConstructFromLiteral);
+ static NeverDestroyed<AtomicString> rtlValue("rtl", AtomicString::ConstructFromLiteral);
+ static NeverDestroyed<AtomicString> autoValue("auto", AtomicString::ConstructFromLiteral);
+
+ if (equalIgnoringCase(value, ltrValue))
+ return ltrValue;
+ if (equalIgnoringCase(value, rtlValue))
+ return rtlValue;
+ if (equalIgnoringCase(value, autoValue))
+ return autoValue;
+ return nullAtom;
+}
+
+const AtomicString& HTMLElement::dir() const
+{
+ return toValidDirValue(fastGetAttribute(dirAttr));
+}
+
+void HTMLElement::setDir(const AtomicString& value)
+{
+ setAttribute(dirAttr, value);
+}
+
void HTMLElement::setInnerText(const String& text, ExceptionCode& ec)
{
if (ieForbidsInsertHTML()) {
Modified: trunk/Source/WebCore/html/HTMLElement.h (179180 => 179181)
--- trunk/Source/WebCore/html/HTMLElement.h 2015-01-27 15:32:20 UTC (rev 179180)
+++ trunk/Source/WebCore/html/HTMLElement.h 2015-01-27 15:59:58 UTC (rev 179181)
@@ -81,6 +81,9 @@
HTMLFormElement* form() const { return virtualForm(); }
+ const AtomicString& dir() const;
+ void setDir(const AtomicString&);
+
bool hasDirectionAuto() const;
TextDirection directionalityIfhasDirAutoAttribute(bool& isAuto) const;
Modified: trunk/Source/WebCore/html/HTMLElement.idl (179180 => 179181)
--- trunk/Source/WebCore/html/HTMLElement.idl 2015-01-27 15:32:20 UTC (rev 179180)
+++ trunk/Source/WebCore/html/HTMLElement.idl 2015-01-27 15:59:58 UTC (rev 179181)
@@ -29,7 +29,7 @@
[Reflect] attribute DOMString title;
[Reflect] attribute DOMString lang;
attribute boolean translate;
- [Reflect] attribute DOMString dir;
+ attribute DOMString dir;
attribute long tabIndex;
attribute boolean draggable;