Make DoesNotParticipateInAutoDirection return true for non-HTML elements; and make WalkDescendantsSetDirAuto consistent with SetDirOnBind. Bug 829428, r=ehsan
authorSimon Montagu <smontagu@smontagu.org>
Tue, 15 Jan 2013 00:20:08 -0800 (2013-01-15)
changeset 118862 5d19aad2dab3021ce12a03f14c227d6e35b3c6f4
parent 118861 af13d04d949e80ddfdc67a8551c394d39f73bf08
child 118863 65747e07d9dfb7648e17d83652bec7df93295a7b
push id21321
push usersmontagu@mozilla.com
push dateTue, 15 Jan 2013 08:20:32 +0000 (2013-01-15)
treeherdermozilla-inbound@5d19aad2dab3 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs829428
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Make DoesNotParticipateInAutoDirection return true for non-HTML elements; and make WalkDescendantsSetDirAuto consistent with SetDirOnBind. Bug 829428, r=ehsan
content/base/src/DirectionalityUtils.cpp
--- a/content/base/src/DirectionalityUtils.cpp
+++ b/content/base/src/DirectionalityUtils.cpp
@@ -230,20 +230,20 @@ typedef mozilla::dom::Element Element;
  * test for it separately, e.g. with DoesNotAffectDirectionOfAncestors.
  * It *does* include textarea, because even if a textarea has dir=auto, it has
  * unicode-bidi: plaintext and is handled automatically in bidi resolution.
  */
 static bool
 DoesNotParticipateInAutoDirection(const Element* aElement)
 {
   nsINodeInfo* nodeInfo = aElement->NodeInfo();
-  return (aElement->IsHTML() &&
-          (nodeInfo->Equals(nsGkAtoms::script) ||
-           nodeInfo->Equals(nsGkAtoms::style) ||
-           nodeInfo->Equals(nsGkAtoms::textarea)));
+  return (!aElement->IsHTML() ||
+          nodeInfo->Equals(nsGkAtoms::script) ||
+          nodeInfo->Equals(nsGkAtoms::style) ||
+          nodeInfo->Equals(nsGkAtoms::textarea));
 }
 
 /**
  * Returns true if aElement is one of the element whose text content should not
  * affect the direction of ancestors with dir=auto (though it may affect its own
  * direction, e.g. <bdi>)
  */
 static bool
@@ -637,31 +637,41 @@ WalkDescendantsResetAutoDirection(Elemen
     }
     child = child->GetNextNode(aElement);
   }
 }
 
 void
 WalkDescendantsSetDirAuto(Element* aElement, bool aNotify)
 {
-  bool setAncestorDirAutoFlag =
+  if (!DoesNotParticipateInAutoDirection(aElement) &&
+      !aElement->IsHTML(nsGkAtoms::bdi)) {
+
+    bool setAncestorDirAutoFlag =
 #ifdef DEBUG
-    true;
+      true;
 #else
-    !aElement->AncestorHasDirAuto();
+      !aElement->AncestorHasDirAuto();
 #endif
 
-  if (setAncestorDirAutoFlag) {
-    nsIContent* child = aElement->GetFirstChild();
-    while (child) {
-      MOZ_ASSERT(!aElement->AncestorHasDirAuto() ||
-                 child->AncestorHasDirAuto(),
-                 "AncestorHasDirAuto set on node but not its children");
-      child->SetHasDirAuto();
-      child = child->GetNextNode(aElement);
+    if (setAncestorDirAutoFlag) {
+      nsIContent* child = aElement->GetFirstChild();
+      while (child) {
+        if (child->IsElement() &&
+            DoesNotAffectDirectionOfAncestors(child->AsElement())) {
+          child = child->GetNextNonChildNode(aElement);
+          continue;
+        }
+
+        MOZ_ASSERT(!aElement->AncestorHasDirAuto() ||
+                   child->AncestorHasDirAuto(),
+                   "AncestorHasDirAuto set on node but not its children");
+        child->SetHasDirAuto();
+        child = child->GetNextNode(aElement);
+      }
     }
   }
 
   nsINode* textNode = WalkDescendantsSetDirectionFromText(aElement, aNotify);
   if (textNode) {
     nsTextNodeDirectionalityMap::AddEntryToMap(textNode, aElement);
   }
 }