Title: [179166] trunk
Revision
179166
Author
[email protected]
Date
2015-01-26 21:54:05 -0800 (Mon, 26 Jan 2015)

Log Message

Document.dir should reflect the 'dir' attribute of the root html element
https://bugs.webkit.org/show_bug.cgi?id=140922

Reviewed by Darin Adler.

Source/WebCore:

Document.dir should reflect the 'dir' content attribute of the root
<html> element as per the specification:
https://html.spec.whatwg.org/multipage/dom.html#dom-document-dir

Previously, WebKit was reflecting the 'dir' content attribute of the
body element. This patch aligns WebKit with the specification and the
behavior of other browsers (tested Firefox 28, IE11 and Chrome).

This patch is based on the following Blink revision by me:
https://src.chromium.org/viewvc/blink?revision=171734&view=revision

Test: fast/dom/document-dir-property.html

* html/HTMLDocument.cpp:
(WebCore::HTMLDocument::dir):
(WebCore::HTMLDocument::setDir):
* html/HTMLDocument.h:

LayoutTests:

Update fast/dom/document-dir-property.html to reflect the behavior
change.

* fast/dom/document-dir-property-expected.txt:
* fast/dom/document-dir-property.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (179165 => 179166)


--- trunk/LayoutTests/ChangeLog	2015-01-27 05:01:08 UTC (rev 179165)
+++ trunk/LayoutTests/ChangeLog	2015-01-27 05:54:05 UTC (rev 179166)
@@ -1,3 +1,16 @@
+2015-01-26  Chris Dumez  <[email protected]>
+
+        Document.dir should reflect the 'dir' attribute of the root html element
+        https://bugs.webkit.org/show_bug.cgi?id=140922
+
+        Reviewed by Darin Adler.
+
+        Update fast/dom/document-dir-property.html to reflect the behavior
+        change.
+
+        * fast/dom/document-dir-property-expected.txt:
+        * fast/dom/document-dir-property.html:
+
 2015-01-26  Csaba Osztrogonác  <[email protected]>
 
         [Win] Enable JSC stress tests by default

Modified: trunk/LayoutTests/fast/dom/document-dir-property-expected.txt (179165 => 179166)


--- trunk/LayoutTests/fast/dom/document-dir-property-expected.txt	2015-01-27 05:01:08 UTC (rev 179165)
+++ trunk/LayoutTests/fast/dom/document-dir-property-expected.txt	2015-01-27 05:54:05 UTC (rev 179166)
@@ -1,26 +1,31 @@
-This tests:
-Bug 9954 REGRESSION: document.dir should return empty string in <head>
-https://bugs.webkit.org/show_bug.cgi?id=9954
+document.dir should reflect the 'dir' content attribute of the <html> element and should be settable in <head>.
 
 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 
+
 Read document.dir in head
-PASS headReadDocumentDir is ''
+PASS headReadDocumentDir is ""
 
 Write document.dir in head
-PASS headWriteDocumentDir is ''
+PASS headWriteDocumentDir is "rtl"
 
 Read document.dir in body
-PASS document.dir is ''
+PASS document.dir is "rtl"
 
+Read document.documentElement.dir in body
+PASS document.documentElement.dir is "rtl"
+
 Read document.body.dir in body
-PASS document.body.dir is ''
+PASS document.body.dir is ""
 
 Write document.dir in body
-PASS document.dir is 'ltr'
+PASS document.dir is "ltr"
 
+Read document.documentElement.dir in body
+PASS document.documentElement.dir is "ltr"
+
 Read document.body.dir in body
-PASS document.body.dir is 'ltr'
+PASS document.body.dir is ""
 
 PASS successfullyParsed is true
 

Modified: trunk/LayoutTests/fast/dom/document-dir-property.html (179165 => 179166)


--- trunk/LayoutTests/fast/dom/document-dir-property.html	2015-01-27 05:01:08 UTC (rev 179165)
+++ trunk/LayoutTests/fast/dom/document-dir-property.html	2015-01-27 05:54:05 UTC (rev 179166)
@@ -7,39 +7,42 @@
 </script>
 </head>
 <body>
-<div id="description"></div>
-<div id="console"></div>
-<script src=""
+<script src=""
 <script>
-description("This tests:<br>"
-          + "Bug 9954 REGRESSION: document.dir should return empty string in &lt;head&gt;<br>"
-          + "<a href=""
+description("document.dir should reflect the 'dir' content attribute of the &lt;html&gt; element and should be settable in &lt;head&gt;.");
 
 debug("Read document.dir in head");
-shouldBe("headReadDocumentDir", "''");
+shouldBeEqualToString("headReadDocumentDir", "");
 debug("");
 
 debug("Write document.dir in head");
-shouldBe("headWriteDocumentDir", "''");
+shouldBeEqualToString("headWriteDocumentDir", "rtl");
 debug("");
 
 debug("Read document.dir in body");
-shouldBe("document.dir", "''");
+shouldBeEqualToString("document.dir", "rtl");
 debug("");
 
+debug("Read document.documentElement.dir in body");
+shouldBeEqualToString("document.documentElement.dir", "rtl");
+debug("");
+
 debug("Read document.body.dir in body");
-shouldBe("document.body.dir", "''");
+shouldBeEqualToString("document.body.dir", "");
 debug("");
 
 debug("Write document.dir in body");
 document.dir = "ltr";
-shouldBe("document.dir", "'ltr'");
+shouldBeEqualToString("document.dir", "ltr");
 debug("");
 
+debug("Read document.documentElement.dir in body");
+shouldBeEqualToString("document.documentElement.dir", "ltr");
+debug("");
+
 debug("Read document.body.dir in body");
-shouldBe("document.body.dir", "'ltr'");
+shouldBeEqualToString("document.body.dir", "");
 debug("");
 </script>
-<script src=""
 </body>
 </html>

Modified: trunk/Source/WebCore/ChangeLog (179165 => 179166)


--- trunk/Source/WebCore/ChangeLog	2015-01-27 05:01:08 UTC (rev 179165)
+++ trunk/Source/WebCore/ChangeLog	2015-01-27 05:54:05 UTC (rev 179166)
@@ -1,3 +1,28 @@
+2015-01-26  Chris Dumez  <[email protected]>
+
+        Document.dir should reflect the 'dir' attribute of the root html element
+        https://bugs.webkit.org/show_bug.cgi?id=140922
+
+        Reviewed by Darin Adler.
+
+        Document.dir should reflect the 'dir' content attribute of the root
+        <html> element as per the specification:
+        https://html.spec.whatwg.org/multipage/dom.html#dom-document-dir
+
+        Previously, WebKit was reflecting the 'dir' content attribute of the
+        body element. This patch aligns WebKit with the specification and the
+        behavior of other browsers (tested Firefox 28, IE11 and Chrome).
+
+        This patch is based on the following Blink revision by me:
+        https://src.chromium.org/viewvc/blink?revision=171734&view=revision
+
+        Test: fast/dom/document-dir-property.html
+
+        * html/HTMLDocument.cpp:
+        (WebCore::HTMLDocument::dir):
+        (WebCore::HTMLDocument::setDir):
+        * html/HTMLDocument.h:
+
 2015-01-26  Darin Adler  <[email protected]>
 
         REGRESSION (r179101): SVGUseElement::expandUseElementsInShadowTree has an object lifetime mistake

Modified: trunk/Source/WebCore/html/HTMLDocument.cpp (179165 => 179166)


--- trunk/Source/WebCore/html/HTMLDocument.cpp	2015-01-27 05:01:08 UTC (rev 179165)
+++ trunk/Source/WebCore/html/HTMLDocument.cpp	2015-01-27 05:54:05 UTC (rev 179166)
@@ -105,17 +105,19 @@
     return frameView ? frameView->contentsHeight() : 0;
 }
 
-String HTMLDocument::dir()
+const AtomicString& HTMLDocument::dir()
 {
-    if (auto* body = bodyOrFrameset())
-        return body->fastGetAttribute(dirAttr);
-    return String();
+    auto* documentElement = this->documentElement();
+    if (!is<HTMLHtmlElement>(*documentElement))
+        return nullAtom;
+    return documentElement->fastGetAttribute(dirAttr);
 }
 
-void HTMLDocument::setDir(const String& value)
+void HTMLDocument::setDir(const AtomicString& value)
 {
-    if (auto* body = bodyOrFrameset())
-        body->setAttribute(dirAttr, value);
+    auto* documentElement = this->documentElement();
+    if (is<HTMLHtmlElement>(documentElement))
+        documentElement->setAttribute(dirAttr, value);
 }
 
 String HTMLDocument::designMode() const

Modified: trunk/Source/WebCore/html/HTMLDocument.h (179165 => 179166)


--- trunk/Source/WebCore/html/HTMLDocument.h	2015-01-27 05:01:08 UTC (rev 179165)
+++ trunk/Source/WebCore/html/HTMLDocument.h	2015-01-27 05:54:05 UTC (rev 179166)
@@ -46,8 +46,8 @@
     int width();
     int height();
 
-    String dir();
-    void setDir(const String&);
+    const AtomicString& dir();
+    void setDir(const AtomicString&);
 
     String designMode() const;
     void setDesignMode(const String&);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to