Title: [101268] trunk
Revision
101268
Author
rn...@webkit.org
Date
2011-11-28 11:19:37 -0800 (Mon, 28 Nov 2011)

Log Message

dir=auto should imply unicode-bidi:isolate by default
https://bugs.webkit.org/show_bug.cgi?id=63903

Reviewed by Dan Bernstein.

Source/WebCore: 

Fixed WebKit's implementation of bdo, bdi, and output elements to match HTML5 spec section 10.3.5:
http://dev.w3.org/html5/spec/Overview.html#bidirectional-text

Any element with dir=auto other than bdo, textarea, and pre should use unicode-bidi: -webkit-isolate by default.

We still don't use -webkit-isolate for non-phrasing elements by default and unicode-override -webkit-isolate for
bdo[dir=auto] so these two cases are failing in the added test.

Test: fast/css/default-bidi-css-rules.html

* css/html.css:
(bdi, output): bdi and output should both use -webkit-isolate as the default value for unicode-bidi.
(bdo): bdo should use bidi-override as the default value for unicode-bidi.
* dom/MappedAttributeEntry.h: Add eBDI, which is used by bdi and output elements.
* html/HTMLElement.cpp:
(WebCore::HTMLElement::mapToEntry): Don't share the cache for dir attribute between bdi and other elements
just like we don't share the cache for dir attribute between bdo and other elements.
(WebCore::unicodeBidiAttributeForDirAuto): Don't set bidi-override for bdo element since this is done
in the UA stylesheet now. Set unicode-bidi to -webkit-isolate for elements other than pre and textarea now that
this function is called only when dir=auto.
called when dir=auto as the name implies.
(WebCore::HTMLElement::parseMappedAttribute): Don't call unicodeBidiAttributeForDirAuto when dir is not
auto. Also set unicode-bidi to embed when dir is not auto and the element is neither bdi, bdo, nor output.
* html/HTMLOutputElement.cpp:
(WebCore::HTMLOutputElement::mapToEntry): Don't share the cache for dir between output and other elements.
* html/HTMLOutputElement.h:
* html/HTMLTagNames.in:

LayoutTests: 

Added a test to ensure WebKit implements HTML5 bidirectional text support properly:
http://dev.w3.org/html5/spec/Overview.html#bidirectional-text

* fast/css/default-bidi-css-rules-expected.txt: Added.
* fast/css/default-bidi-css-rules.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (101267 => 101268)


--- trunk/LayoutTests/ChangeLog	2011-11-28 19:13:23 UTC (rev 101267)
+++ trunk/LayoutTests/ChangeLog	2011-11-28 19:19:37 UTC (rev 101268)
@@ -1,3 +1,16 @@
+2011-11-24  Ryosuke Niwa  <rn...@webkit.org>
+
+        dir=auto should imply unicode-bidi:isolate by default
+        https://bugs.webkit.org/show_bug.cgi?id=63903
+
+        Reviewed by Dan Bernstein.
+
+        Added a test to ensure WebKit implements HTML5 bidirectional text support properly:
+        http://dev.w3.org/html5/spec/Overview.html#bidirectional-text
+
+        * fast/css/default-bidi-css-rules-expected.txt: Added.
+        * fast/css/default-bidi-css-rules.html: Added.
+
 2011-11-28  Pavel Feldman  <pfeld...@google.com>
 
         Web Inspector: console evaluation doesn't work when navigating from a page with several frames to another one

Added: trunk/LayoutTests/fast/css/default-bidi-css-rules-expected.txt (0 => 101268)


--- trunk/LayoutTests/fast/css/default-bidi-css-rules-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/css/default-bidi-css-rules-expected.txt	2011-11-28 19:19:37 UTC (rev 101268)
@@ -0,0 +1,76 @@
+This test checks the default rules for direction and unicode-bidi CSS properties.
+
+PASS styleOf("div", {}).direction is "ltr"
+FAIL styleOf("div", {}).unicodeBidi should be -webkit-isolate. Was normal.
+PASS styleOf("div", {"dir":"ltr"}).direction is "ltr"
+PASS styleOf("div", {"dir":"ltr"}).unicodeBidi is "embed"
+PASS styleOf("div", {"dir":"rtl"}).direction is "rtl"
+PASS styleOf("div", {"dir":"rtl"}).unicodeBidi is "embed"
+PASS styleOf("div", {"dir":"auto"}).direction is "ltr"
+PASS styleOf("div", {"dir":"auto"}).unicodeBidi is "-webkit-isolate"
+PASS styleOf("div", {"dir":""}).direction is "ltr"
+PASS styleOf("div", {"dir":""}).unicodeBidi is "embed"
+PASS styleOf("span", {}).direction is "ltr"
+PASS styleOf("span", {}).unicodeBidi is "normal"
+PASS styleOf("span", {"dir":"ltr"}).direction is "ltr"
+PASS styleOf("span", {"dir":"ltr"}).unicodeBidi is "embed"
+PASS styleOf("span", {"dir":"rtl"}).direction is "rtl"
+PASS styleOf("span", {"dir":"rtl"}).unicodeBidi is "embed"
+PASS styleOf("span", {"dir":"auto"}).direction is "ltr"
+PASS styleOf("span", {"dir":"auto"}).unicodeBidi is "-webkit-isolate"
+PASS styleOf("span", {"dir":""}).direction is "ltr"
+PASS styleOf("span", {"dir":""}).unicodeBidi is "embed"
+PASS styleOf("bdi", {}).direction is "ltr"
+PASS styleOf("bdi", {}).unicodeBidi is "-webkit-isolate"
+PASS styleOf("bdi", {"dir":"ltr"}).direction is "ltr"
+PASS styleOf("bdi", {"dir":"ltr"}).unicodeBidi is "-webkit-isolate"
+PASS styleOf("bdi", {"dir":"rtl"}).direction is "rtl"
+PASS styleOf("bdi", {"dir":"rtl"}).unicodeBidi is "-webkit-isolate"
+PASS styleOf("bdi", {"dir":"auto"}).direction is "ltr"
+PASS styleOf("bdi", {"dir":"auto"}).unicodeBidi is "-webkit-isolate"
+PASS styleOf("bdi", {"dir":""}).direction is "ltr"
+PASS styleOf("bdi", {"dir":""}).unicodeBidi is "-webkit-isolate"
+PASS styleOf("output", {}).direction is "ltr"
+PASS styleOf("output", {}).unicodeBidi is "-webkit-isolate"
+PASS styleOf("output", {"dir":"ltr"}).direction is "ltr"
+PASS styleOf("output", {"dir":"ltr"}).unicodeBidi is "-webkit-isolate"
+PASS styleOf("output", {"dir":"rtl"}).direction is "rtl"
+PASS styleOf("output", {"dir":"rtl"}).unicodeBidi is "-webkit-isolate"
+PASS styleOf("output", {"dir":"auto"}).direction is "ltr"
+PASS styleOf("output", {"dir":"auto"}).unicodeBidi is "-webkit-isolate"
+PASS styleOf("output", {"dir":""}).direction is "ltr"
+PASS styleOf("output", {"dir":""}).unicodeBidi is "-webkit-isolate"
+PASS styleOf("bdo", {}).direction is "ltr"
+PASS styleOf("bdo", {}).unicodeBidi is "bidi-override"
+PASS styleOf("bdo", {"dir":"ltr"}).direction is "ltr"
+PASS styleOf("bdo", {"dir":"ltr"}).unicodeBidi is "bidi-override"
+PASS styleOf("bdo", {"dir":"rtl"}).direction is "rtl"
+PASS styleOf("bdo", {"dir":"rtl"}).unicodeBidi is "bidi-override"
+PASS styleOf("bdo", {"dir":"auto"}).direction is "ltr"
+FAIL styleOf("bdo", {"dir":"auto"}).unicodeBidi should be bidi-override -webkit-isolate. Was -webkit-isolate.
+PASS styleOf("bdo", {"dir":""}).direction is "ltr"
+PASS styleOf("bdo", {"dir":""}).unicodeBidi is "bidi-override"
+PASS styleOf("textarea", {}).direction is "ltr"
+PASS styleOf("textarea", {}).unicodeBidi is "normal"
+PASS styleOf("textarea", {"dir":"ltr"}).direction is "ltr"
+PASS styleOf("textarea", {"dir":"ltr"}).unicodeBidi is "embed"
+PASS styleOf("textarea", {"dir":"rtl"}).direction is "rtl"
+PASS styleOf("textarea", {"dir":"rtl"}).unicodeBidi is "embed"
+PASS styleOf("textarea", {"dir":"auto"}).direction is "ltr"
+PASS styleOf("textarea", {"dir":"auto"}).unicodeBidi is "-webkit-plaintext"
+PASS styleOf("textarea", {"dir":""}).direction is "ltr"
+PASS styleOf("textarea", {"dir":""}).unicodeBidi is "embed"
+PASS styleOf("pre", {}).direction is "ltr"
+PASS styleOf("pre", {}).unicodeBidi is "normal"
+PASS styleOf("pre", {"dir":"ltr"}).direction is "ltr"
+PASS styleOf("pre", {"dir":"ltr"}).unicodeBidi is "embed"
+PASS styleOf("pre", {"dir":"rtl"}).direction is "rtl"
+PASS styleOf("pre", {"dir":"rtl"}).unicodeBidi is "embed"
+PASS styleOf("pre", {"dir":"auto"}).direction is "ltr"
+PASS styleOf("pre", {"dir":"auto"}).unicodeBidi is "-webkit-plaintext"
+PASS styleOf("pre", {"dir":""}).direction is "ltr"
+PASS styleOf("pre", {"dir":""}).unicodeBidi is "embed"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/css/default-bidi-css-rules.html (0 => 101268)


--- trunk/LayoutTests/fast/css/default-bidi-css-rules.html	                        (rev 0)
+++ trunk/LayoutTests/fast/css/default-bidi-css-rules.html	2011-11-28 19:19:37 UTC (rev 101268)
@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<p>This test checks <a href="" default rules for direction and unicode-bidi CSS properties</a>.</p>
+<div id="container"></div>
+<div id="console"></div>
+<script>
+
+var container = document.getElementById('container');
+
+function styleOf(name, attributes) {
+    var element = document.createElement(name);
+    for (var name in attributes) {
+        var value = attributes[name];
+        element.setAttribute(name, value);
+    }
+    container.appendChild(element);
+    return getComputedStyle(element);
+}
+
+var tests = [
+    ['div', {}, 'ltr', '-webkit-isolate'],
+    ['div', {'dir': 'ltr'}, 'ltr', 'embed'],
+    ['div', {'dir': 'rtl'}, 'rtl', 'embed'],
+    ['div', {'dir': 'auto'}, 'ltr', '-webkit-isolate'],
+    ['div', {'dir': ''}, 'ltr', 'embed'],
+
+    ['span', {}, 'ltr', 'normal'],
+    ['span', {'dir': 'ltr'}, 'ltr', 'embed'],
+    ['span', {'dir': 'rtl'}, 'rtl', 'embed'],
+    ['span', {'dir': 'auto'}, 'ltr', '-webkit-isolate'],
+    ['span', {'dir': ''}, 'ltr', 'embed'],
+
+    ['bdi', {}, 'ltr', '-webkit-isolate'],
+    ['bdi', {'dir': 'ltr'}, 'ltr', '-webkit-isolate'],
+    ['bdi', {'dir': 'rtl'}, 'rtl', '-webkit-isolate'],
+    ['bdi', {'dir': 'auto'}, 'ltr', '-webkit-isolate'],
+    ['bdi', {'dir': ''}, 'ltr', '-webkit-isolate'],
+
+    ['output', {}, 'ltr', '-webkit-isolate'],
+    ['output', {'dir': 'ltr'}, 'ltr', '-webkit-isolate'],
+    ['output', {'dir': 'rtl'}, 'rtl', '-webkit-isolate'],
+    ['output', {'dir': 'auto'}, 'ltr', '-webkit-isolate'],
+    ['output', {'dir': ''}, 'ltr', '-webkit-isolate'],
+
+    ['bdo', {}, 'ltr', 'bidi-override'],
+    ['bdo', {'dir': 'ltr'}, 'ltr', 'bidi-override'],
+    ['bdo', {'dir': 'rtl'}, 'rtl', 'bidi-override'],
+    ['bdo', {'dir': 'auto'}, 'ltr', 'bidi-override -webkit-isolate'],
+    ['bdo', {'dir': ''}, 'ltr', 'bidi-override'],
+
+    ['textarea', {}, 'ltr', 'normal'],
+    ['textarea', {'dir': 'ltr'}, 'ltr', 'embed'],
+    ['textarea', {'dir': 'rtl'}, 'rtl', 'embed'],
+    ['textarea', {'dir': 'auto'}, 'ltr', '-webkit-plaintext'],
+    ['textarea', {'dir': ''}, 'ltr', 'embed'],
+
+    ['pre', {}, 'ltr', 'normal'],
+    ['pre', {'dir': 'ltr'}, 'ltr', 'embed'],
+    ['pre', {'dir': 'rtl'}, 'rtl', 'embed'],
+    ['pre', {'dir': 'auto'}, 'ltr', '-webkit-plaintext'],
+    ['pre', {'dir': ''}, 'ltr', 'embed'],
+].forEach(function (test) {
+    shouldBe('styleOf("' + test[0] + '", ' + JSON.stringify(test[1]) + ').direction', '"' + test[2] + '"');
+    container.innerHTML = '';
+    shouldBe('styleOf("' + test[0] + '", ' + JSON.stringify(test[1]) + ').unicodeBidi', '"' + test[3] + '"');
+    container.innerHTML = '';
+});
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (101267 => 101268)


--- trunk/Source/WebCore/ChangeLog	2011-11-28 19:13:23 UTC (rev 101267)
+++ trunk/Source/WebCore/ChangeLog	2011-11-28 19:19:37 UTC (rev 101268)
@@ -1,3 +1,38 @@
+2011-11-25  Ryosuke Niwa  <rn...@webkit.org>
+
+        dir=auto should imply unicode-bidi:isolate by default
+        https://bugs.webkit.org/show_bug.cgi?id=63903
+
+        Reviewed by Dan Bernstein.
+
+        Fixed WebKit's implementation of bdo, bdi, and output elements to match HTML5 spec section 10.3.5:
+        http://dev.w3.org/html5/spec/Overview.html#bidirectional-text
+
+        Any element with dir=auto other than bdo, textarea, and pre should use unicode-bidi: -webkit-isolate by default.
+
+        We still don't use -webkit-isolate for non-phrasing elements by default and unicode-override -webkit-isolate for
+        bdo[dir=auto] so these two cases are failing in the added test.
+
+        Test: fast/css/default-bidi-css-rules.html
+
+        * css/html.css:
+        (bdi, output): bdi and output should both use -webkit-isolate as the default value for unicode-bidi.
+        (bdo): bdo should use bidi-override as the default value for unicode-bidi.
+        * dom/MappedAttributeEntry.h: Add eBDI, which is used by bdi and output elements.
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::mapToEntry): Don't share the cache for dir attribute between bdi and other elements
+        just like we don't share the cache for dir attribute between bdo and other elements.
+        (WebCore::unicodeBidiAttributeForDirAuto): Don't set bidi-override for bdo element since this is done
+        in the UA stylesheet now. Set unicode-bidi to -webkit-isolate for elements other than pre and textarea now that
+        this function is called only when dir=auto.
+        called when dir=auto as the name implies.
+        (WebCore::HTMLElement::parseMappedAttribute): Don't call unicodeBidiAttributeForDirAuto when dir is not
+        auto. Also set unicode-bidi to embed when dir is not auto and the element is neither bdi, bdo, nor output.
+        * html/HTMLOutputElement.cpp:
+        (WebCore::HTMLOutputElement::mapToEntry): Don't share the cache for dir between output and other elements.
+        * html/HTMLOutputElement.h:
+        * html/HTMLTagNames.in:
+
 2011-11-28  Jer Noble  <jer.no...@apple.com>
 
         WebAudio: AudioContext::uninitialize() can caused AudioContext deletion before deleting marked nodes.

Modified: trunk/Source/WebCore/css/html.css (101267 => 101268)


--- trunk/Source/WebCore/css/html.css	2011-11-28 19:13:23 UTC (rev 101267)
+++ trunk/Source/WebCore/css/html.css	2011-11-28 19:19:37 UTC (rev 101268)
@@ -992,10 +992,14 @@
     margin-right: 0.4em;
 }
 
-bdi {
+bdi, output {
     unicode-bidi: -webkit-isolate;
 }
 
+bdo {
+    unicode-bidi: bidi-override;
+}
+
 /* page */
 
 @page {

Modified: trunk/Source/WebCore/dom/MappedAttributeEntry.h (101267 => 101268)


--- trunk/Source/WebCore/dom/MappedAttributeEntry.h	2011-11-28 19:13:23 UTC (rev 101267)
+++ trunk/Source/WebCore/dom/MappedAttributeEntry.h	2011-11-28 19:19:37 UTC (rev 101268)
@@ -40,6 +40,7 @@
     , eTable
     , eCell
     , eCaption
+    , eBDI
     , eBDO
     , ePre
 #if ENABLE(SVG)

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (101267 => 101268)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2011-11-28 19:13:23 UTC (rev 101267)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2011-11-28 19:19:37 UTC (rev 101268)
@@ -127,7 +127,12 @@
         return false;
     }
     if (attrName == dirAttr) {
-        result = hasLocalName(bdoTag) ? eBDO : eUniversal;
+        if (hasLocalName(bdoTag))
+            result = eBDO;
+        else if (hasLocalName(bdiTag))
+            result = eBDI;
+        else
+            result = eUniversal;
         return true;
     }
 
@@ -136,11 +141,11 @@
 
 static inline int unicodeBidiAttributeForDirAuto(HTMLElement* element)
 {
-    if (element->hasLocalName(bdoTag))
-        return CSSValueBidiOverride;
     if (element->hasLocalName(preTag) || element->hasLocalName(textareaTag))
         return CSSValueWebkitPlaintext;
-    return CSSValueEmbed;
+    // FIXME: For bdo element, dir="auto" should result in "bidi-override isolate" but we don't support having multiple values in unicode-bidi yet.
+    // See https://bugs.webkit.org/show_bug.cgi?id=73164.
+    return CSSValueWebkitIsolate;
 }
 
 static unsigned parseBorderWidthAttribute(Attribute* attr)
@@ -190,10 +195,14 @@
     } else if (attr->name() == langAttr) {
         // FIXME: Implement
     } else if (attr->name() == dirAttr) {
-        if (!equalIgnoringCase(attr->value(), "auto"))
+        bool dirIsAuto = equalIgnoringCase(attr->value(), "auto");
+        if (!dirIsAuto)
             addCSSProperty(attr, CSSPropertyDirection, attr->value());
         dirAttributeChanged(attr);
-        addCSSProperty(attr, CSSPropertyUnicodeBidi, unicodeBidiAttributeForDirAuto(this));
+        if (dirIsAuto)
+            addCSSProperty(attr, CSSPropertyUnicodeBidi, unicodeBidiAttributeForDirAuto(this));
+        else if (!hasTagName(bdiTag) && !hasTagName(bdoTag) && !hasTagName(outputTag))
+            addCSSProperty(attr, CSSPropertyUnicodeBidi, CSSValueEmbed);
     } else if (attr->name() == draggableAttr) {
         const AtomicString& value = attr->value();
         if (equalIgnoringCase(value, "true")) {

Modified: trunk/Source/WebCore/html/HTMLOutputElement.cpp (101267 => 101268)


--- trunk/Source/WebCore/html/HTMLOutputElement.cpp	2011-11-28 19:13:23 UTC (rev 101267)
+++ trunk/Source/WebCore/html/HTMLOutputElement.cpp	2011-11-28 19:19:37 UTC (rev 101268)
@@ -61,6 +61,16 @@
     return Node::supportsFocus() && !disabled();
 }
 
+bool HTMLOutputElement::mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const
+{
+    if (attrName == HTMLNames::dirAttr) {
+        result = eBDI;
+        return true;
+    }
+
+    return HTMLElement::mapToEntry(attrName, result);
+}
+
 void HTMLOutputElement::parseMappedAttribute(Attribute* attr)
 {
     if (attr->name() == HTMLNames::forAttr)

Modified: trunk/Source/WebCore/html/HTMLOutputElement.h (101267 => 101268)


--- trunk/Source/WebCore/html/HTMLOutputElement.h	2011-11-28 19:13:23 UTC (rev 101267)
+++ trunk/Source/WebCore/html/HTMLOutputElement.h	2011-11-28 19:19:37 UTC (rev 101268)
@@ -55,6 +55,7 @@
 private:
     HTMLOutputElement(const QualifiedName&, Document*, HTMLFormElement*);
 
+    virtual bool mapToEntry(const QualifiedName& attrName, MappedAttributeEntry& result) const OVERRIDE;
     virtual void parseMappedAttribute(Attribute*);
     virtual const AtomicString& formControlType() const;
     virtual bool isEnumeratable() const { return true; }

Modified: trunk/Source/WebCore/html/HTMLTagNames.in (101267 => 101268)


--- trunk/Source/WebCore/html/HTMLTagNames.in	2011-11-28 19:13:23 UTC (rev 101267)
+++ trunk/Source/WebCore/html/HTMLTagNames.in	2011-11-28 19:19:37 UTC (rev 101268)
@@ -15,6 +15,7 @@
 b interfaceName=HTMLElement
 base
 basefont interfaceName=HTMLBaseFontElement
+bdi interfaceName=HTMLElement
 bdo interfaceName=HTMLElement
 bgsound interfaceName=HTMLElement
 big interfaceName=HTMLElement
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to