Title: [92480] trunk
Revision
92480
Author
[email protected]
Date
2011-08-05 07:36:33 -0700 (Fri, 05 Aug 2011)

Log Message

dir=auto needs to work on value of input and textarea elements
https://bugs.webkit.org/show_bug.cgi?id=65428

Reviewed by Darin Adler.

Source/WebCore:

Changed the directionality algorithm to evaluate the value of input elements and textarea elements when
they have the attribute dir-auto Set.
Also skip these elements when evaluating the directionality of their ancestors.

HTMLTextAreaElement::childrenChanged is not called when a user types into the textarea, so call
calculateAndAdjustDirectionality() explicitly from HTMLTextAreaElement::subtreeHasChanged().

HTMLInputElement::childrenChanged is not called when a user types into the textarea, so call
calculateAndAdjustDirectionality() explicitly from HTMLTextAreaElement::subtreeHasChanged().

Tests: fast/dom/HTMLElement/attr-dir-auto-changed-text-form-control.html
       fast/dom/HTMLElement/attr-dir-auto-text-form-control-child.html
       fast/dom/HTMLElement/attr-dir-auto-text-form-control.html

* html/HTMLElement.cpp:
(WebCore::HTMLElement::directionality):
* html/HTMLElement.h:
* html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::subtreeHasChanged):

LayoutTests:

* fast/dom/HTMLElement/attr-dir-auto-changed-text-form-control-expected.txt: Added.
* fast/dom/HTMLElement/attr-dir-auto-changed-text-form-control.html: Added.
* fast/dom/HTMLElement/attr-dir-auto-text-form-control-child-expected.txt: Added.
* fast/dom/HTMLElement/attr-dir-auto-text-form-control-child.html: Added.
* fast/dom/HTMLElement/attr-dir-auto-text-form-control-expected.txt: Added.
* fast/dom/HTMLElement/attr-dir-auto-text-form-control.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (92479 => 92480)


--- trunk/LayoutTests/ChangeLog	2011-08-05 14:17:23 UTC (rev 92479)
+++ trunk/LayoutTests/ChangeLog	2011-08-05 14:36:33 UTC (rev 92480)
@@ -1,3 +1,17 @@
+2011-08-05  Yael Aharon  <[email protected]>
+
+        dir=auto needs to work on value of input and textarea elements
+        https://bugs.webkit.org/show_bug.cgi?id=65428
+
+        Reviewed by Darin Adler.
+
+        * fast/dom/HTMLElement/attr-dir-auto-changed-text-form-control-expected.txt: Added.
+        * fast/dom/HTMLElement/attr-dir-auto-changed-text-form-control.html: Added.
+        * fast/dom/HTMLElement/attr-dir-auto-text-form-control-child-expected.txt: Added.
+        * fast/dom/HTMLElement/attr-dir-auto-text-form-control-child.html: Added.
+        * fast/dom/HTMLElement/attr-dir-auto-text-form-control-expected.txt: Added.
+        * fast/dom/HTMLElement/attr-dir-auto-text-form-control.html: Added.
+
 2011-08-05  Vsevolod Vlasov  <[email protected]>
 
         [Qt]Web Inspector: REGRESSION(r91928): It made 2 tests fail

Added: trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-change-text-form-control-expected.txt (0 => 92480)


--- trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-change-text-form-control-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-change-text-form-control-expected.txt	2011-08-05 14:36:33 UTC (rev 92480)
@@ -0,0 +1,21 @@
+Test that directionality is re-evaluated when dir attribute changes.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+
+
+
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color') is 'rgb(0, 128, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color') is 'rgb(255, 0, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color') is 'rgb(0, 128, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color') is 'rgb(255, 0, 0)'
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+
+
+

Added: trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-change-text-form-control.html (0 => 92480)


--- trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-change-text-form-control.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-change-text-form-control.html	2011-08-05 14:36:33 UTC (rev 92480)
@@ -0,0 +1,41 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<link rel="stylesheet" href=""
+<script src=""
+<style>
+.testElement {-webkit-border-start: 5px solid green; -webkit-border-end: 5px solid red; }
+</style>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></p>
+<div id="result"></div>
+
+<div id="parentDiv">
+<input type="text" id="text1" dir="auto" class="testElement" value="מקור השם עברית">
+<textarea id="text2" dir="auto" class="testElement">מקור השם עברית</textarea>
+</div>
+<script>
+
+description('Test that directionality is re-evaluated when dir attribute changes.');
+
+var el = document.getElementById("text1");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color')", "'rgb(0, 128, 0)'");
+el.setAttribute("dir", "ltr");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color')", "'rgb(255, 0, 0)'");
+
+el = document.getElementById("text2");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color')", "'rgb(0, 128, 0)'");
+el.setAttribute("dir", "ltr");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color')", "'rgb(255, 0, 0)'");
+
+el = document.getElementById("parentDiv");
+el.style.display = "none";
+
+window.successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-text-form-control-child-expected.txt (0 => 92480)


--- trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-text-form-control-child-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-text-form-control-child-expected.txt	2011-08-05 14:36:33 UTC (rev 92480)
@@ -0,0 +1,19 @@
+Test that directionality of an element with dir=auto set is not determined by the value of its child text form control.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+
+
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color') is 'rgb(255, 0, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color') is 'rgb(0, 128, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color') is 'rgb(0, 128, 0)'
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+
+
+

Added: trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-text-form-control-child.html (0 => 92480)


--- trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-text-form-control-child.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-text-form-control-child.html	2011-08-05 14:36:33 UTC (rev 92480)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<link rel="stylesheet" href=""
+<script src=""
+<style>
+.testElement {-webkit-border-start: 5px solid green; -webkit-border-end: 5px solid red; }
+</style>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></p>
+<div id="result"></div>
+<div id="parentDiv">
+Test that the direction of the div is left-to-right, ignoring its child that is a text form control.
+<div id="left-to-right" dir="auto" class="testElement">
+<input type="text" value="מקור השם עברית">Test test test
+</div>
+Test that the direction of the div is right-to-left, ignoring its child that is a text form control.
+<div id="right-to-left1" dir="auto" class="testElement">
+<input type="text" value="Test test test">מקור השם עברית
+</div>
+<div id="right-to-left2" dir="auto" class="testElement">
+<textarea>Test test test</textarea>מקור השם עברית
+</div>
+</div>
+<script>
+
+description('Test that directionality of an element with dir=auto set is not determined by the value of its child text form control.');
+
+var el = document.getElementById("left-to-right");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color')", "'rgb(255, 0, 0)'");
+el = document.getElementById("right-to-left1");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color')", "'rgb(0, 128, 0)'");
+el = document.getElementById("right-to-left2");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color')", "'rgb(0, 128, 0)'");
+document.getElementById("parentDiv").style.display = "none";
+window.successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-text-form-control-expected.txt (0 => 92480)


--- trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-text-form-control-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-text-form-control-expected.txt	2011-08-05 14:36:33 UTC (rev 92480)
@@ -0,0 +1,20 @@
+Test that directionality of a text form control with dir=auto set is determined by the value of that form control.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+
+
+
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color') is 'rgb(255, 0, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color') is 'rgb(0, 128, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color') is 'rgb(0, 128, 0)'
+PASS document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color') is 'rgb(0, 128, 0)'
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
+
+
+

Added: trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-text-form-control.html (0 => 92480)


--- trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-text-form-control.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/HTMLElement/attr-dir-auto-text-form-control.html	2011-08-05 14:36:33 UTC (rev 92480)
@@ -0,0 +1,43 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
+<link rel="stylesheet" href=""
+<script src=""
+<style>
+.testElement {-webkit-border-start: 5px solid green; -webkit-border-end: 5px solid red; }
+</style>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></p>
+<div id="result"></div>
+<div id="parentDiv">
+Test that the direction of english text is left-to-right in the text form control.
+<input type="text" id="left-to-right" dir="auto" class="testElement" value="Test test test">
+Test that the direction of hebrew text is right-to-left in the text form control.
+<input type="text" id="right-to-left1" dir="auto" class="testElement" value="מקור השם עברית">
+<textarea id="right-to-left2" dir="auto" class="testElement">מקור השם עברית</textarea>
+Test that the direction of hebrew text is right-to-left in the text form control, even if inserted dynamically.
+<textarea id="right-to-left3" dir="auto" class="testElement"></textarea>
+</div>
+<script>
+
+description('Test that directionality of a text form control with dir=auto set is determined by the value of that form control.');
+
+var el = document.getElementById("left-to-right");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color')", "'rgb(255, 0, 0)'");
+el = document.getElementById("right-to-left1");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color')", "'rgb(0, 128, 0)'");
+el = document.getElementById("right-to-left2");
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color')", "'rgb(0, 128, 0)'");
+el = document.getElementById("right-to-left3");
+el.innerText = "מקור השם עברית";
+shouldBe("document.defaultView.getComputedStyle(el, null).getPropertyValue('border-right-color')", "'rgb(0, 128, 0)'");
+
+document.getElementById("parentDiv").style.display = "none";
+window.successfullyParsed = true;
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (92479 => 92480)


--- trunk/Source/WebCore/ChangeLog	2011-08-05 14:17:23 UTC (rev 92479)
+++ trunk/Source/WebCore/ChangeLog	2011-08-05 14:36:33 UTC (rev 92480)
@@ -1,3 +1,30 @@
+2011-08-05  Yael Aharon  <[email protected]>
+
+        dir=auto needs to work on value of input and textarea elements
+        https://bugs.webkit.org/show_bug.cgi?id=65428
+
+        Reviewed by Darin Adler.
+
+        Changed the directionality algorithm to evaluate the value of input elements and textarea elements when
+        they have the attribute dir-auto Set.
+        Also skip these elements when evaluating the directionality of their ancestors.
+
+        HTMLTextAreaElement::childrenChanged is not called when a user types into the textarea, so call
+        calculateAndAdjustDirectionality() explicitly from HTMLTextAreaElement::subtreeHasChanged().
+
+        HTMLInputElement::childrenChanged is not called when a user types into the textarea, so call
+        calculateAndAdjustDirectionality() explicitly from HTMLTextAreaElement::subtreeHasChanged().
+
+        Tests: fast/dom/HTMLElement/attr-dir-auto-changed-text-form-control.html
+               fast/dom/HTMLElement/attr-dir-auto-text-form-control-child.html
+               fast/dom/HTMLElement/attr-dir-auto-text-form-control.html
+
+        * html/HTMLElement.cpp:
+        (WebCore::HTMLElement::directionality):
+        * html/HTMLElement.h:
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::HTMLTextAreaElement::subtreeHasChanged):
+
 2011-08-05  Keishi Hattori  <[email protected]>
 
         Implement <input type=color> UI behavior WebCore part

Modified: trunk/Source/WebCore/html/HTMLElement.cpp (92479 => 92480)


--- trunk/Source/WebCore/html/HTMLElement.cpp	2011-08-05 14:17:23 UTC (rev 92479)
+++ trunk/Source/WebCore/html/HTMLElement.cpp	2011-08-05 14:36:33 UTC (rev 92480)
@@ -40,6 +40,7 @@
 #include "HTMLFormElement.h"
 #include "HTMLNames.h"
 #include "HTMLParserIdioms.h"
+#include "HTMLTextFormControlElement.h"
 #include "RenderWordBreak.h"
 #include "ScriptEventListener.h"
 #include "Settings.h"
@@ -52,6 +53,7 @@
 namespace WebCore {
 
 using namespace HTMLNames;
+using namespace WTF;
 
 using std::min;
 using std::max;
@@ -871,10 +873,19 @@
 
 TextDirection HTMLElement::directionality(Node** strongDirectionalityTextNode) const
 {
+    if (HTMLTextFormControlElement* textElement = toTextFormControl(const_cast<HTMLElement*>(this))) {
+        bool hasStrongDirectionality;
+        Unicode::Direction textDirection = textElement->value().defaultWritingDirection(&hasStrongDirectionality);
+        if (hasStrongDirectionality && strongDirectionalityTextNode)
+            *strongDirectionalityTextNode = textElement;
+        return (textDirection == Unicode::LeftToRight) ? LTR : RTL;
+    }
+
     Node* node = firstChild();
     while (node) {
-        // Skip bdi, script and style elements
-        if (equalIgnoringCase(node->nodeName(), "bdi") || node->hasTagName(scriptTag) || node->hasTagName(styleTag)) {
+        // Skip bdi, script, style and text form controls.
+        if (equalIgnoringCase(node->nodeName(), "bdi") || node->hasTagName(scriptTag) || node->hasTagName(styleTag) 
+            || (node->isElementNode() && toElement(node)->isTextFormControl())) {
             node = node->traverseNextSibling(this);
             continue;
         }

Modified: trunk/Source/WebCore/html/HTMLElement.h (92479 => 92480)


--- trunk/Source/WebCore/html/HTMLElement.h	2011-08-05 14:17:23 UTC (rev 92479)
+++ trunk/Source/WebCore/html/HTMLElement.h	2011-08-05 14:36:33 UTC (rev 92480)
@@ -93,6 +93,7 @@
     unsigned parseBorderWidthAttribute(Attribute*);
 
     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
+    void calculateAndAdjustDirectionality();
 
 private:
     virtual String nodeName() const;
@@ -106,7 +107,6 @@
 
     void dirAttributeChanged(Attribute*);
     void adjustDirectionalityIfNeededAfterChildAttributeChanged(Element* child);
-    void calculateAndAdjustDirectionality();
     void adjustDirectionalityIfNeededAfterChildrenChanged(Node* beforeChange, int childCountDelta);
     TextDirection directionality(Node** strongDirectionalityTextNode= 0) const;
 };

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (92479 => 92480)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2011-08-05 14:17:23 UTC (rev 92479)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2011-08-05 14:36:33 UTC (rev 92480)
@@ -663,6 +663,9 @@
         if (Frame* frame = document()->frame())
             frame->editor()->textDidChangeInTextField(this);
     }
+    // When typing in an input field, childrenChanged is not called, so we need to force the directionality check.
+    if (isTextField())
+        calculateAndAdjustDirectionality();
 }
 
 const AtomicString& HTMLInputElement::formControlType() const

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (92479 => 92480)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2011-08-05 14:17:23 UTC (rev 92479)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2011-08-05 14:36:33 UTC (rev 92480)
@@ -255,6 +255,8 @@
 
     if (Frame* frame = document()->frame())
         frame->editor()->textDidChangeInTextArea(this);
+    // When typing in a textarea, childrenChanged is not called, so we need to force the directionality check.
+    calculateAndAdjustDirectionality();
 }
 
 void HTMLTextAreaElement::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent* event) const
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to