Bug 839839 - Minor nsPlaceholderFrame code cleanup. r=dholbert
authorMats Palmgren <matspal@gmail.com>
Mon, 11 Feb 2013 03:28:50 +0100
changeset 131360 bf5d5599aa6a44204b1e4b8480e961e8542b5d58
parent 131359 167195a95601cddc60564bb110e002a3f65099fb
child 131361 f30b42547a84f97e7965b5737633ca4ef4f71746
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs839839
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
Bug 839839 - Minor nsPlaceholderFrame code cleanup. r=dholbert
layout/generic/nsPlaceholderFrame.cpp
layout/generic/nsPlaceholderFrame.h
--- a/layout/generic/nsPlaceholderFrame.cpp
+++ b/layout/generic/nsPlaceholderFrame.cpp
@@ -3,55 +3,33 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /*
  * rendering object for the point that anchors out-of-flow rendering
  * objects such as floats and absolutely positioned elements
  */
 
+#include "nsPlaceholderFrame.h"
+
+#include "nsDisplayList.h"
+#include "nsFrameManager.h"
 #include "nsLayoutUtils.h"
-#include "nsPlaceholderFrame.h"
-#include "nsLineLayout.h"
-#include "nsIContent.h"
 #include "nsPresContext.h"
 #include "nsRenderingContext.h"
-#include "nsGkAtoms.h"
-#include "nsFrameManager.h"
-#include "nsDisplayList.h"
 
 nsIFrame*
 NS_NewPlaceholderFrame(nsIPresShell* aPresShell, nsStyleContext* aContext,
                        nsFrameState aTypeBit)
 {
   return new (aPresShell) nsPlaceholderFrame(aContext, aTypeBit);
 }
 
 NS_IMPL_FRAMEARENA_HELPERS(nsPlaceholderFrame)
 
-nsPlaceholderFrame::~nsPlaceholderFrame()
-{
-}
-
-/* virtual */ nscoord
-nsPlaceholderFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
-{
-  nscoord result = 0;
-  DISPLAY_MIN_WIDTH(this, result);
-  return result;
-}
-
-/* virtual */ nscoord
-nsPlaceholderFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
-{
-  nscoord result = 0;
-  DISPLAY_PREF_WIDTH(this, result);
-  return result;
-}
-
 /* virtual */ nsSize
 nsPlaceholderFrame::GetMinSize(nsBoxLayoutState& aBoxLayoutState)
 {
   nsSize size(0, 0);
   DISPLAY_MIN_SIZE(this, size);
   return size;
 }
 
@@ -67,18 +45,18 @@ nsPlaceholderFrame::GetPrefSize(nsBoxLay
 nsPlaceholderFrame::GetMaxSize(nsBoxLayoutState& aBoxLayoutState)
 {
   nsSize size(NS_INTRINSICSIZE, NS_INTRINSICSIZE);
   DISPLAY_MAX_SIZE(this, size);
   return size;
 }
 
 /* virtual */ void
-nsPlaceholderFrame::AddInlineMinWidth(nsRenderingContext *aRenderingContext,
-                                      nsIFrame::InlineMinWidthData *aData)
+nsPlaceholderFrame::AddInlineMinWidth(nsRenderingContext* aRenderingContext,
+                                      nsIFrame::InlineMinWidthData* aData)
 {
   // Override AddInlineMinWith so that *nothing* happens.  In
   // particular, we don't want to zero out |aData->trailingWhitespace|,
   // since nsLineLayout skips placeholders when trimming trailing
   // whitespace, and we don't want to set aData->skipWhitespace to
   // false.
 
   // ...but push floats onto the list
@@ -88,18 +66,18 @@ nsPlaceholderFrame::AddInlineMinWidth(ns
                                            mOutOfFlowFrame,
                                            nsLayoutUtils::MIN_WIDTH);
     aData->floats.AppendElement(
       InlineIntrinsicWidthData::FloatInfo(mOutOfFlowFrame, floatWidth));
   }
 }
 
 /* virtual */ void
-nsPlaceholderFrame::AddInlinePrefWidth(nsRenderingContext *aRenderingContext,
-                                       nsIFrame::InlinePrefWidthData *aData)
+nsPlaceholderFrame::AddInlinePrefWidth(nsRenderingContext* aRenderingContext,
+                                       nsIFrame::InlinePrefWidthData* aData)
 {
   // Override AddInlinePrefWith so that *nothing* happens.  In
   // particular, we don't want to zero out |aData->trailingWhitespace|,
   // since nsLineLayout skips placeholders when trimming trailing
   // whitespace, and we don't want to set aData->skipWhitespace to
   // false.
 
   // ...but push floats onto the list
@@ -109,17 +87,17 @@ nsPlaceholderFrame::AddInlinePrefWidth(n
                                            mOutOfFlowFrame,
                                            nsLayoutUtils::PREF_WIDTH);
     aData->floats.AppendElement(
       InlineIntrinsicWidthData::FloatInfo(mOutOfFlowFrame, floatWidth));
   }
 }
 
 NS_IMETHODIMP
-nsPlaceholderFrame::Reflow(nsPresContext*          aPresContext,
+nsPlaceholderFrame::Reflow(nsPresContext*           aPresContext,
                            nsHTMLReflowMetrics&     aDesiredSize,
                            const nsHTMLReflowState& aReflowState,
                            nsReflowStatus&          aStatus)
 {
   DO_GLOBAL_REFLOW_COUNT("nsPlaceholderFrame");
   DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
   aDesiredSize.width = 0;
   aDesiredSize.height = 0;
@@ -127,41 +105,40 @@ nsPlaceholderFrame::Reflow(nsPresContext
   aStatus = NS_FRAME_COMPLETE;
   NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
   return NS_OK;
 }
 
 void
 nsPlaceholderFrame::DestroyFrom(nsIFrame* aDestructRoot)
 {
-  nsIPresShell* shell = PresContext()->GetPresShell();
   nsIFrame* oof = mOutOfFlowFrame;
   if (oof) {
     // Unregister out-of-flow frame
-    shell->FrameManager()->UnregisterPlaceholderFrame(this);
+    nsFrameManager* fm = PresContext()->GetPresShell()->FrameManager();
+    fm->UnregisterPlaceholderFrame(this);
     mOutOfFlowFrame = nullptr;
     // If aDestructRoot is not an ancestor of the out-of-flow frame,
     // then call RemoveFrame on it here.
     // Also destroy it here if it's a popup frame. (Bug 96291)
-    if (shell->FrameManager() &&
-        ((GetStateBits() & PLACEHOLDER_FOR_POPUP) ||
-         !nsLayoutUtils::IsProperAncestorFrame(aDestructRoot, oof))) {
+    if ((GetStateBits() & PLACEHOLDER_FOR_POPUP) ||
+        !nsLayoutUtils::IsProperAncestorFrame(aDestructRoot, oof)) {
       ChildListID listId = nsLayoutUtils::GetChildListNameFor(oof);
-      shell->FrameManager()->RemoveFrame(listId, oof);
+      fm->RemoveFrame(listId, oof);
     }
     // else oof will be destroyed by its parent
   }
 
   nsFrame::DestroyFrom(aDestructRoot);
 }
 
 nsIAtom*
 nsPlaceholderFrame::GetType() const
 {
-  return nsGkAtoms::placeholderFrame; 
+  return nsGkAtoms::placeholderFrame;
 }
 
 /* virtual */ bool
 nsPlaceholderFrame::CanContinueTextRun() const
 {
   if (!mOutOfFlowFrame) {
     return false;
   }
@@ -185,81 +162,79 @@ nsPlaceholderFrame::GetParentStyleContex
 #ifdef DEBUG
 static void
 PaintDebugPlaceholder(nsIFrame* aFrame, nsRenderingContext* aCtx,
                       const nsRect& aDirtyRect, nsPoint aPt)
 {
   aCtx->SetColor(NS_RGB(0, 255, 255));
   nscoord x = nsPresContext::CSSPixelsToAppUnits(-5);
   aCtx->FillRect(aPt.x + x, aPt.y,
-                 nsPresContext::CSSPixelsToAppUnits(13), nsPresContext::CSSPixelsToAppUnits(3));
+                 nsPresContext::CSSPixelsToAppUnits(13),
+                 nsPresContext::CSSPixelsToAppUnits(3));
   nscoord y = nsPresContext::CSSPixelsToAppUnits(-10);
   aCtx->FillRect(aPt.x, aPt.y + y,
-                 nsPresContext::CSSPixelsToAppUnits(3), nsPresContext::CSSPixelsToAppUnits(10));
+                 nsPresContext::CSSPixelsToAppUnits(3),
+                 nsPresContext::CSSPixelsToAppUnits(10));
 }
 #endif // DEBUG
 
 #if defined(DEBUG) || (defined(MOZ_REFLOW_PERF_DSP) && defined(MOZ_REFLOW_PERF))
 
 NS_IMETHODIMP
 nsPlaceholderFrame::BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                                      const nsRect&           aDirtyRect,
                                      const nsDisplayListSet& aLists)
 {
   DO_GLOBAL_REFLOW_COUNT_DSP("nsPlaceholderFrame");
   
 #ifdef DEBUG
-  if (!GetShowFrameBorders())
-    return NS_OK;
-  
-  return aLists.Outlines()->AppendNewToTop(new (aBuilder)
-      nsDisplayGeneric(aBuilder, this, PaintDebugPlaceholder, "DebugPlaceholder",
-                       nsDisplayItem::TYPE_DEBUG_PLACEHOLDER));
-#else // DEBUG
+  if (GetShowFrameBorders()) {
+    return aLists.Outlines()->AppendNewToTop(
+      new (aBuilder) nsDisplayGeneric(aBuilder, this, PaintDebugPlaceholder,
+                                      "DebugPlaceholder",
+                                      nsDisplayItem::TYPE_DEBUG_PLACEHOLDER));
+  }
+#endif
   return NS_OK;
-#endif // DEBUG
 }
 #endif // DEBUG || (MOZ_REFLOW_PERF_DSP && MOZ_REFLOW_PERF)
 
 #ifdef DEBUG
 NS_IMETHODIMP
 nsPlaceholderFrame::GetFrameName(nsAString& aResult) const
 {
   return MakeFrameName(NS_LITERAL_STRING("Placeholder"), aResult);
 }
 
 NS_IMETHODIMP
 nsPlaceholderFrame::List(FILE* out, int32_t aIndent, uint32_t aFlags) const
 {
   IndentBy(out, aIndent);
   ListTag(out);
-#ifdef DEBUG_waterson
-  fprintf(out, " [parent=%p]", static_cast<void*>(mParent));
-#endif
   if (HasView()) {
     fprintf(out, " [view=%p]", (void*)GetView());
   }
   fprintf(out, " {%d,%d,%d,%d}", mRect.x, mRect.y, mRect.width, mRect.height);
   if (0 != mState) {
     fprintf(out, " [state=%016llx]", (unsigned long long)mState);
   }
   nsIFrame* prevInFlow = GetPrevInFlow();
   nsIFrame* nextInFlow = GetNextInFlow();
-  if (nullptr != prevInFlow) {
+  if (prevInFlow) {
     fprintf(out, " prev-in-flow=%p", static_cast<void*>(prevInFlow));
   }
-  if (nullptr != nextInFlow) {
+  if (nextInFlow) {
     fprintf(out, " next-in-flow=%p", static_cast<void*>(nextInFlow));
   }
-  if (nullptr != mContent) {
+  if (mContent) {
     fprintf(out, " [content=%p]", static_cast<void*>(mContent));
   }
-  if (nullptr != mStyleContext) {
+  if (mStyleContext) {
     fprintf(out, " [sc=%p]", static_cast<void*>(mStyleContext));
   }
   if (mOutOfFlowFrame) {
     fprintf(out, " outOfFlowFrame=");
     nsFrame::ListTag(out, mOutOfFlowFrame);
   }
   fputs("\n", out);
   return NS_OK;
 }
-#endif
+#endif // DEBUG
--- a/layout/generic/nsPlaceholderFrame.h
+++ b/layout/generic/nsPlaceholderFrame.h
@@ -50,90 +50,84 @@ nsIFrame* NS_NewPlaceholderFrame(nsIPres
 #define PLACEHOLDER_FOR_POPUP    NS_FRAME_STATE_BIT(23)
 #define PLACEHOLDER_TYPE_MASK    (PLACEHOLDER_FOR_FLOAT | \
                                   PLACEHOLDER_FOR_ABSPOS | \
                                   PLACEHOLDER_FOR_FIXEDPOS | \
                                   PLACEHOLDER_FOR_POPUP)
 
 /**
  * Implementation of a frame that's used as a placeholder for a frame that
- * has been moved out of the flow
+ * has been moved out of the flow.
  */
-class nsPlaceholderFrame : public nsFrame {
+class nsPlaceholderFrame MOZ_FINAL : public nsFrame {
 public:
   NS_DECL_FRAMEARENA_HELPERS
 
   /**
    * Create a new placeholder frame.  aTypeBit must be one of the
    * PLACEHOLDER_FOR_* constants above.
    */
   friend nsIFrame* NS_NewPlaceholderFrame(nsIPresShell* aPresShell,
                                           nsStyleContext* aContext,
                                           nsFrameState aTypeBit);
-  nsPlaceholderFrame(nsStyleContext* aContext, nsFrameState aTypeBit) :
-    nsFrame(aContext)
+  nsPlaceholderFrame(nsStyleContext* aContext, nsFrameState aTypeBit)
+    : nsFrame(aContext)
   {
     NS_PRECONDITION(aTypeBit == PLACEHOLDER_FOR_FLOAT ||
                     aTypeBit == PLACEHOLDER_FOR_ABSPOS ||
                     aTypeBit == PLACEHOLDER_FOR_FIXEDPOS ||
                     aTypeBit == PLACEHOLDER_FOR_POPUP,
                     "Unexpected type bit");
     AddStateBits(aTypeBit);
   }
-  virtual ~nsPlaceholderFrame();
 
   // Get/Set the associated out of flow frame
-  nsIFrame*  GetOutOfFlowFrame() const {return mOutOfFlowFrame;}
+  nsIFrame*  GetOutOfFlowFrame() const { return mOutOfFlowFrame; }
   void       SetOutOfFlowFrame(nsIFrame* aFrame) {
                NS_ASSERTION(!aFrame || !aFrame->GetPrevContinuation(),
                             "OOF must be first continuation");
                mOutOfFlowFrame = aFrame;
              }
 
-  // nsIHTMLReflow overrides
-  // We need to override GetMinWidth and GetPrefWidth because XUL uses
+  // nsIFrame overrides
+  // We need to override GetMinSize and GetPrefSize because XUL uses
   // placeholders not within lines.
-  virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
-  virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext) MOZ_OVERRIDE;
-  virtual void AddInlineMinWidth(nsRenderingContext *aRenderingContext,
-                                 InlineMinWidthData *aData) MOZ_OVERRIDE;
-  virtual void AddInlinePrefWidth(nsRenderingContext *aRenderingContext,
-                                  InlinePrefWidthData *aData) MOZ_OVERRIDE;
+  virtual void AddInlineMinWidth(nsRenderingContext* aRenderingContext,
+                                 InlineMinWidthData* aData) MOZ_OVERRIDE;
+  virtual void AddInlinePrefWidth(nsRenderingContext* aRenderingContext,
+                                  InlinePrefWidthData* aData) MOZ_OVERRIDE;
   virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
   virtual nsSize GetPrefSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
   virtual nsSize GetMaxSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE;
+
   NS_IMETHOD Reflow(nsPresContext* aPresContext,
                     nsHTMLReflowMetrics& aDesiredSize,
                     const nsHTMLReflowState& aReflowState,
                     nsReflowStatus& aStatus) MOZ_OVERRIDE;
 
-  virtual void DestroyFrom(nsIFrame* aDestructRoot);
+  virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
 
-  // nsIFrame overrides
 #if defined(DEBUG) || (defined(MOZ_REFLOW_PERF_DSP) && defined(MOZ_REFLOW_PERF))
   NS_IMETHOD BuildDisplayList(nsDisplayListBuilder*   aBuilder,
                               const nsRect&           aDirtyRect,
-                              const nsDisplayListSet& aLists);
+                              const nsDisplayListSet& aLists) MOZ_OVERRIDE;
 #endif // DEBUG || (MOZ_REFLOW_PERF_DSP && MOZ_REFLOW_PERF)
   
 #ifdef DEBUG
   NS_IMETHOD List(FILE* out, int32_t aIndent, uint32_t aFlags = 0) const MOZ_OVERRIDE;
+  NS_IMETHOD GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
 #endif // DEBUG
 
   /**
    * Get the "type" of the frame
    *
    * @see nsGkAtoms::placeholderFrame
    */
   virtual nsIAtom* GetType() const MOZ_OVERRIDE;
 
-#ifdef DEBUG
-  NS_IMETHOD GetFrameName(nsAString& aResult) const MOZ_OVERRIDE;
-#endif
-
   virtual bool IsEmpty() MOZ_OVERRIDE { return true; }
   virtual bool IsSelfEmpty() MOZ_OVERRIDE { return true; }
 
   virtual bool CanContinueTextRun() const MOZ_OVERRIDE;
 
 #ifdef ACCESSIBILITY
   virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE
   {