Bug 1279354 - Part 2: Make the nsProgressFrame code a bit more idiomatic by processing its actual child frames. r=dholbert, a=gchang
authorMats Palmgren <mats@mozilla.com>
Mon, 28 Nov 2016 23:00:20 +0100
changeset 356796 50657907876527cbca4d4b6082f117fbfb9104b8
parent 356795 806eb08f971743c68e5473c9cbdf968e07cb944d
child 356797 3020d866784aee0bfb487c2b4bbc7d377078e6d7
push id6635
push userryanvm@gmail.com
push dateWed, 30 Nov 2016 04:50:15 +0000
treeherdermozilla-beta@34c73c520f93 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert, gchang
bugs1279354
milestone51.0
Bug 1279354 - Part 2: Make the nsProgressFrame code a bit more idiomatic by processing its actual child frames. r=dholbert, a=gchang
layout/forms/nsProgressFrame.cpp
layout/forms/nsProgressFrame.h
--- a/layout/forms/nsProgressFrame.cpp
+++ b/layout/forms/nsProgressFrame.cpp
@@ -113,52 +113,54 @@ nsProgressFrame::Reflow(nsPresContext*  
                         const ReflowInput& aReflowInput,
                         nsReflowStatus&          aStatus)
 {
   MarkInReflow();
   DO_GLOBAL_REFLOW_COUNT("nsProgressFrame");
   DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
 
   NS_ASSERTION(mBarDiv, "Progress bar div must exist!");
+  NS_ASSERTION(PrincipalChildList().GetLength() == 1 &&
+               PrincipalChildList().FirstChild() == mBarDiv->GetPrimaryFrame(),
+               "unexpected child frames");
   NS_ASSERTION(!GetPrevContinuation(),
                "nsProgressFrame should not have continuations; if it does we "
                "need to call RegUnregAccessKey only for the first.");
 
   if (mState & NS_FRAME_FIRST_REFLOW) {
     nsFormControlFrame::RegUnRegAccessKey(this, true);
   }
 
-  nsIFrame* barFrame = mBarDiv->GetPrimaryFrame();
-  NS_ASSERTION(barFrame, "The progress frame should have a child with a frame!");
-
-  ReflowBarFrame(barFrame, aPresContext, aReflowInput, aStatus);
-
   aDesiredSize.SetSize(aReflowInput.GetWritingMode(),
                        aReflowInput.ComputedSizeWithBorderPadding());
   aDesiredSize.SetOverflowAreasToDesiredBounds();
-  ConsiderChildOverflow(aDesiredSize.mOverflowAreas, barFrame);
+
+  for (auto childFrame : PrincipalChildList()) {
+    ReflowChildFrame(childFrame, aPresContext, aReflowInput, aStatus);
+    ConsiderChildOverflow(aDesiredSize.mOverflowAreas, childFrame);
+  }
+
   FinishAndStoreOverflow(&aDesiredSize);
 
   aStatus = NS_FRAME_COMPLETE;
 
   NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
 }
 
 void
-nsProgressFrame::ReflowBarFrame(nsIFrame*                aBarFrame,
-                                nsPresContext*           aPresContext,
-                                const ReflowInput& aReflowInput,
-                                nsReflowStatus&          aStatus)
+nsProgressFrame::ReflowChildFrame(nsIFrame*          aChild,
+                                  nsPresContext*     aPresContext,
+                                  const ReflowInput& aReflowInput,
+                                  nsReflowStatus&    aStatus)
 {
   bool vertical = ResolvedOrientationIsVertical();
-  WritingMode wm = aBarFrame->GetWritingMode();
+  WritingMode wm = aChild->GetWritingMode();
   LogicalSize availSize = aReflowInput.ComputedSize(wm);
   availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
-  ReflowInput reflowInput(aPresContext, aReflowInput,
-                                aBarFrame, availSize);
+  ReflowInput reflowInput(aPresContext, aReflowInput, aChild, availSize);
   nscoord size = vertical ? aReflowInput.ComputedHeight()
                           : aReflowInput.ComputedWidth();
   nscoord xoffset = aReflowInput.ComputedPhysicalBorderPadding().left;
   nscoord yoffset = aReflowInput.ComputedPhysicalBorderPadding().top;
 
   double position = static_cast<HTMLProgressElement*>(mContent)->Position();
 
   // Force the bar's size to match the current progress.
@@ -199,35 +201,36 @@ nsProgressFrame::ReflowBarFrame(nsIFrame
     // because aReflowInput.ComputedHeight() - size == 0.
     yoffset += aReflowInput.ComputedHeight() - reflowInput.ComputedHeight();
   }
 
   xoffset += reflowInput.ComputedPhysicalMargin().left;
   yoffset += reflowInput.ComputedPhysicalMargin().top;
 
   ReflowOutput barDesiredSize(aReflowInput);
-  ReflowChild(aBarFrame, aPresContext, barDesiredSize, reflowInput, xoffset,
+  ReflowChild(aChild, aPresContext, barDesiredSize, reflowInput, xoffset,
               yoffset, 0, aStatus);
-  FinishReflowChild(aBarFrame, aPresContext, barDesiredSize, &reflowInput,
+  FinishReflowChild(aChild, aPresContext, barDesiredSize, &reflowInput,
                     xoffset, yoffset, 0);
 }
 
 nsresult
 nsProgressFrame::AttributeChanged(int32_t  aNameSpaceID,
                                   nsIAtom* aAttribute,
                                   int32_t  aModType)
 {
   NS_ASSERTION(mBarDiv, "Progress bar div must exist!");
 
   if (aNameSpaceID == kNameSpaceID_None &&
       (aAttribute == nsGkAtoms::value || aAttribute == nsGkAtoms::max)) {
-    nsIFrame* barFrame = mBarDiv->GetPrimaryFrame();
-    NS_ASSERTION(barFrame, "The progress frame should have a child with a frame!");
-    PresContext()->PresShell()->FrameNeedsReflow(barFrame, nsIPresShell::eResize,
-                                                 NS_FRAME_IS_DIRTY);
+    auto shell = PresContext()->PresShell();
+    for (auto childFrame : PrincipalChildList()) {
+      shell->FrameNeedsReflow(childFrame, nsIPresShell::eResize,
+                              NS_FRAME_IS_DIRTY);
+    }
     InvalidateFrame();
   }
 
   return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
 }
 
 LogicalSize
 nsProgressFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
@@ -274,17 +277,17 @@ nscoord
 nsProgressFrame::GetPrefISize(nsRenderingContext *aRenderingContext)
 {
   return GetMinISize(aRenderingContext);
 }
 
 bool
 nsProgressFrame::ShouldUseNativeStyle() const
 {
-  nsIFrame* barFrame = mBarDiv->GetPrimaryFrame();
+  nsIFrame* barFrame = PrincipalChildList().FirstChild();
 
   // Use the native style if these conditions are satisfied:
   // - both frames use the native appearance;
   // - neither frame has author specified rules setting the border or the
   //   background.
   return StyleDisplay()->mAppearance == NS_THEME_PROGRESSBAR &&
          !PresContext()->HasAuthorSpecifiedRules(this,
                                                  NS_AUTHOR_SPECIFIED_BORDER | NS_AUTHOR_SPECIFIED_BACKGROUND) &&
--- a/layout/forms/nsProgressFrame.h
+++ b/layout/forms/nsProgressFrame.h
@@ -81,23 +81,22 @@ public:
   /**
    * Returns whether the frame and its child should use the native style.
    */
   bool ShouldUseNativeStyle() const;
 
   virtual Element* GetPseudoElement(CSSPseudoElementType aType) override;
 
 protected:
-  // Helper function which reflow the anonymous div frame.
-  void ReflowBarFrame(nsIFrame*                aBarFrame,
-                      nsPresContext*           aPresContext,
-                      const ReflowInput& aReflowInput,
-                      nsReflowStatus&          aStatus);
+  // Helper function to reflow a child frame.
+  void ReflowChildFrame(nsIFrame*          aChild,
+                        nsPresContext*     aPresContext,
+                        const ReflowInput& aReflowInput,
+                        nsReflowStatus&    aStatus);
 
   /**
    * The div used to show the progress bar.
    * @see nsProgressFrame::CreateAnonymousContent
    */
   nsCOMPtr<Element> mBarDiv;
 };
 
 #endif
-