Bug 1648774 Part 1: Make GetFlexFrameWithComputedInfo work for nsFieldSetFrame. r=dholbert
authorBrad Werth <bwerth@mozilla.com>
Thu, 23 Jul 2020 19:29:37 +0000
changeset 541830 9d10a11e7846939de1ce55003cced2161dc9c09f
parent 541829 ded0022e100405afa43e8bd857c142028cfe3517
child 541831 0b2ccdb92cb37a1e26ad391c8c3a99923a84c373
push id37633
push userccoroiu@mozilla.com
push dateFri, 24 Jul 2020 09:32:06 +0000
treeherdermozilla-central@141543043270 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1648774
milestone80.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 1648774 Part 1: Make GetFlexFrameWithComputedInfo work for nsFieldSetFrame. r=dholbert Differential Revision: https://phabricator.services.mozilla.com/D84626
layout/generic/nsFlexContainerFrame.cpp
layout/generic/nsGridContainerFrame.cpp
--- a/layout/generic/nsFlexContainerFrame.cpp
+++ b/layout/generic/nsFlexContainerFrame.cpp
@@ -16,16 +16,17 @@
 #include "mozilla/FloatingPoint.h"
 #include "mozilla/Logging.h"
 #include "mozilla/PresShell.h"
 #include "mozilla/WritingModes.h"
 #include "nsBlockFrame.h"
 #include "nsContentUtils.h"
 #include "nsCSSAnonBoxes.h"
 #include "nsDisplayList.h"
+#include "nsFieldSetFrame.h"
 #include "nsIFrameInlines.h"
 #include "nsLayoutUtils.h"
 #include "nsPlaceholderFrame.h"
 #include "nsPresContext.h"
 
 using namespace mozilla;
 using namespace mozilla::layout;
 
@@ -4806,20 +4807,29 @@ nsFlexContainerFrame* nsFlexContainerFra
     nsIFrame* aFrame) {
   // Prepare a lambda function that we may need to call multiple times.
   auto GetFlexContainerFrame = [](nsIFrame* aFrame) {
     // Return the aFrame's content insertion frame, iff it is
     // a flex container frame.
     nsFlexContainerFrame* flexFrame = nullptr;
 
     if (aFrame) {
-      nsIFrame* contentFrame = aFrame->GetContentInsertionFrame();
-      if (contentFrame && (contentFrame->IsFlexContainerFrame())) {
-        flexFrame = static_cast<nsFlexContainerFrame*>(contentFrame);
+      nsIFrame* inner = aFrame;
+      if (MOZ_UNLIKELY(aFrame->IsFieldSetFrame())) {
+        inner = static_cast<nsFieldSetFrame*>(aFrame)->GetInner();
       }
+      // Since "Get" methods like GetInner and GetContentInsertionFrame can
+      // return null, we check the return values before dereferencing. Our
+      // calling pattern makes this unlikely, but we're being careful.
+      nsIFrame* insertionFrame =
+          inner ? inner->GetContentInsertionFrame() : nullptr;
+      nsIFrame* possibleFlexFrame = insertionFrame ? insertionFrame : aFrame;
+      flexFrame = possibleFlexFrame->IsFlexContainerFrame()
+                      ? static_cast<nsFlexContainerFrame*>(possibleFlexFrame)
+                      : nullptr;
     }
     return flexFrame;
   };
 
   nsFlexContainerFrame* flexFrame = GetFlexContainerFrame(aFrame);
   if (flexFrame) {
     // Generate the FlexContainerInfo data, if it's not already there.
     bool reflowNeeded = !flexFrame->HasProperty(FlexContainerInfo());
--- a/layout/generic/nsGridContainerFrame.cpp
+++ b/layout/generic/nsGridContainerFrame.cpp
@@ -9613,18 +9613,22 @@ nsGridContainerFrame* nsGridContainerFra
     nsIFrame* aFrame) {
   nsGridContainerFrame* gridFrame = nullptr;
 
   if (aFrame) {
     nsIFrame* inner = aFrame;
     if (MOZ_UNLIKELY(aFrame->IsFieldSetFrame())) {
       inner = static_cast<nsFieldSetFrame*>(aFrame)->GetInner();
     }
-    inner = inner->GetContentInsertionFrame();
-    nsIFrame* possibleGridFrame = inner ? inner : aFrame;
+    // Since "Get" methods like GetInner and GetContentInsertionFrame can
+    // return null, we check the return values before dereferencing. Our
+    // calling pattern makes this unlikely, but we're being careful.
+    nsIFrame* insertionFrame =
+        inner ? inner->GetContentInsertionFrame() : nullptr;
+    nsIFrame* possibleGridFrame = insertionFrame ? insertionFrame : aFrame;
     gridFrame = possibleGridFrame->IsGridContainerFrame()
                     ? static_cast<nsGridContainerFrame*>(possibleGridFrame)
                     : nullptr;
   }
   return gridFrame;
 }
 
 nsGridContainerFrame* nsGridContainerFrame::GetGridFrameWithComputedInfo(