Bug 1506687 Part 1: Make devtools Flex API return null nodes for anonymous box flex items. r=dholbert
☠☠ backed out by 9bff4fddd787 ☠ ☠
authorBrad Werth <bwerth@mozilla.com>
Thu, 15 Nov 2018 16:20:13 +0000
changeset 503067 c50af93cfc84373d529aefc2a3ccd423e48b0d1f
parent 503066 95d9fcd59dbe9d6ed4909cbf858c0a15c8d98048
child 503068 1c3baa04d4ce66c9a8b3428b3d475c73bc07f76b
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1506687
milestone65.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
Bug 1506687 Part 1: Make devtools Flex API return null nodes for anonymous box flex items. r=dholbert Differential Revision: https://phabricator.services.mozilla.com/D11782
layout/generic/nsFlexContainerFrame.cpp
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -156,59 +156,16 @@ ConvertLegacyStyleToJustifyContent(const
       return NS_STYLE_ALIGN_SPACE_BETWEEN;
   }
 
   MOZ_ASSERT_UNREACHABLE("Unrecognized mBoxPack enum value");
   // Fall back to default value of "justify-content" property:
   return NS_STYLE_ALIGN_FLEX_START;
 }
 
-// Helper-function to find the first non-anonymous-box descendent of aFrame.
-static nsIFrame*
-GetFirstNonAnonBoxDescendant(nsIFrame* aFrame)
-{
-  while (aFrame) {
-    nsAtom* pseudoTag = aFrame->Style()->GetPseudo();
-
-    // If aFrame isn't an anonymous container, then it'll do.
-    if (!pseudoTag ||                                 // No pseudotag.
-        !nsCSSAnonBoxes::IsAnonBox(pseudoTag) ||      // Pseudotag isn't anon.
-        nsCSSAnonBoxes::IsNonElement(pseudoTag)) {    // Text, not a container.
-      break;
-    }
-
-    // Otherwise, descend to its first child and repeat.
-
-    // SPECIAL CASE: if we're dealing with an anonymous table, then it might
-    // be wrapping something non-anonymous in its caption or col-group lists
-    // (instead of its principal child list), so we have to look there.
-    // (Note: For anonymous tables that have a non-anon cell *and* a non-anon
-    // column, we'll always return the column. This is fine; we're really just
-    // looking for a handle to *anything* with a meaningful content node inside
-    // the table, for use in DOM comparisons to things outside of the table.)
-    if (MOZ_UNLIKELY(aFrame->IsTableWrapperFrame())) {
-      nsIFrame* captionDescendant =
-        GetFirstNonAnonBoxDescendant(aFrame->GetChildList(kCaptionList).FirstChild());
-      if (captionDescendant) {
-        return captionDescendant;
-      }
-    } else if (MOZ_UNLIKELY(aFrame->IsTableFrame())) {
-      nsIFrame* colgroupDescendant =
-        GetFirstNonAnonBoxDescendant(aFrame->GetChildList(kColGroupList).FirstChild());
-      if (colgroupDescendant) {
-        return colgroupDescendant;
-      }
-    }
-
-    // USUAL CASE: Descend to the first child in principal list.
-    aFrame = aFrame->PrincipalChildList().FirstChild();
-  }
-  return aFrame;
-}
-
 // Indicates whether advancing along the given axis is equivalent to
 // increasing our X or Y position (as opposed to decreasing it).
 static inline bool
 AxisGrowsInPositiveDirection(AxisOrientationType aAxis)
 {
   return eAxis_LR == aAxis || eAxis_TB == aAxis;
 }
 
@@ -4821,38 +4778,30 @@ nsFlexContainerFrame::DoFlexLayout(nsPre
       // when we have real values. But we still add all the items here, so
       // we can capture computed data for each item as we proceed.
       for (const FlexItem* item = line->GetFirstItem(); item;
            item = item->getNext()) {
         nsIFrame* frame = item->Frame();
 
         // The frame may be for an element, or it may be for an
         // anonymous flex item, e.g. wrapping one or more text nodes.
-        // DevTools wants the content node for the actual child in
-        // the DOM tree, so we descend through anonymous boxes.
-        nsIFrame* targetFrame = GetFirstNonAnonBoxDescendant(frame);
-        nsIContent* content = targetFrame->GetContent();
-
-        // Skip over content that is only whitespace, which might
-        // have been broken off from a text node which is our real
-        // target.
-        while (content && content->TextIsOnlyWhitespace()) {
-          // If content is only whitespace, try the frame sibling.
-          targetFrame = targetFrame->GetNextSibling();
-          if (targetFrame) {
-            content = targetFrame->GetContent();
-          } else {
-            content = nullptr;
-          }
+        // If it's for an element, we want to return the DOM node that
+        // corresponds to it. If it's an anonymous flex item, we want
+        // to return a null DOM node.
+        nsINode* node = nullptr;
+
+        // If this frame is not an anonymous flex item, we will return its
+        // content as the DOM node for this flex item.
+        nsAtom* pseudoTag = frame->Style()->GetPseudo();
+        if (pseudoTag != nsCSSAnonBoxes::anonymousFlexItem()) {
+          node = frame->GetContent();
         }
 
-        ComputedFlexItemInfo* itemInfo =
-          lineInfo->mItems.AppendElement();
-
-        itemInfo->mNode = content;
+        ComputedFlexItemInfo* itemInfo = lineInfo->mItems.AppendElement();
+        itemInfo->mNode = node;
 
         // mMainBaseSize and itemInfo->mMainDeltaSize will
         // be filled out in ResolveFlexibleLengths().
 
         // Other FlexItem properties can be captured now.
         itemInfo->mMainMinSize = item->GetMainMinSize();
         itemInfo->mMainMaxSize = item->GetMainMaxSize();
         itemInfo->mCrossMinSize = item->GetCrossMinSize();