Set AncestorHasDirAuto on descendants of a node being bound to an element with HasDirAuto or AncestorHasDirAuto. Bug 827190, r=ehsan, a=bajaj
authorSimon Montagu <smontagu@smontagu.org>
Sun, 13 Jan 2013 08:08:58 -0800
changeset 127349 2d7dc501efcdffc8164e4d1527ffc21d76006996
parent 127348 4172406f5df4f186be4a24c3538cb61cbb04b310
child 127350 1a6a636b116bdb75bbe76094c2f320272aebe4ec
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan, bajaj
bugs827190
milestone20.0a2
Set AncestorHasDirAuto on descendants of a node being bound to an element with HasDirAuto or AncestorHasDirAuto. Bug 827190, r=ehsan, a=bajaj
content/base/src/DirectionalityUtils.cpp
--- a/content/base/src/DirectionalityUtils.cpp
+++ b/content/base/src/DirectionalityUtils.cpp
@@ -899,20 +899,36 @@ SetDirOnBind(mozilla::dom::Element* aEle
 {
   // Set the AncestorHasDirAuto flag, unless this element shouldn't affect
   // ancestors that have dir=auto
   if (!DoesNotParticipateInAutoDirection(aElement) &&
       !aElement->IsHTML(nsGkAtoms::bdi) &&
       aParent && aParent->NodeOrAncestorHasDirAuto()) {
     aElement->SetAncestorHasDirAuto();
 
-    // if we are binding an element to the tree that already has descendants,
-    // and the parent has NodeHasDirAuto or NodeAncestorHasDirAuto, we may
-    // need to reset the direction of an ancestor with dir=auto
-    if (aElement->GetFirstChild()) {
+    nsIContent* child = aElement->GetFirstChild();
+    if (child) {
+      // If we are binding an element to the tree that already has descendants,
+      // and the parent has NodeHasDirAuto or NodeAncestorHasDirAuto, we need
+      // to set NodeAncestorHasDirAuto on all the element's descendants, except
+      // for nodes that don't affect the direction of their ancestors.
+      do {
+        if (child->IsElement() &&
+            (DoesNotParticipateInAutoDirection(child->AsElement()) ||
+             child->NodeInfo()->Equals(nsGkAtoms::bdi) ||
+             child->HasFixedDir())) {
+          child = child->GetNextNonChildNode(aElement);
+          continue;
+        }
+
+        child->SetAncestorHasDirAuto();
+        child = child->GetNextNode(aElement);
+      } while (child);
+
+      // We may also need to reset the direction of an ancestor with dir=auto
       WalkAncestorsResetAutoDirection(aElement, true);
     }
   }
 
   if (!aElement->HasDirAuto()) {
     // if the element doesn't have dir=auto, set its own directionality from
     // the dir attribute or by inheriting from its ancestors.
     RecomputeDirectionality(aElement, false);