Bug 473390 part 5. Move the checkbox and radio face style code out of the frame constructor and into those frames. r+sr=roc
authorBoris Zbarsky <bzbarsky@mit.edu>
Mon, 19 Jan 2009 13:31:32 -0500
changeset 23942 f40919be02bb87f08e717e8a838422fe4fc239fb
parent 23941 2ce70aa933a40cc80f6f7b4df874d4bf56af1b12
child 23943 aa3a5a9358d2efc43cb09e67b1e09da3adb2bc57
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
bugs473390
milestone1.9.2a1pre
Bug 473390 part 5. Move the checkbox and radio face style code out of the frame constructor and into those frames. r+sr=roc
layout/base/nsCSSFrameConstructor.cpp
layout/base/nsCSSFrameConstructor.h
layout/forms/nsGfxCheckboxControlFrame.cpp
layout/forms/nsGfxCheckboxControlFrame.h
layout/forms/nsGfxRadioControlFrame.cpp
layout/forms/nsGfxRadioControlFrame.h
layout/forms/nsICheckboxControlFrame.h
layout/forms/nsIRadioControlFrame.h
--- a/layout/base/nsCSSFrameConstructor.cpp
+++ b/layout/base/nsCSSFrameConstructor.cpp
@@ -2217,20 +2217,22 @@ nsCSSFrameConstructor::CreateInputFrame(
                                          aStyleDisplay, aFrameItems,
                                          aHasPseudoParent);
       aAddedToFrameList = PR_TRUE;
       aFrameHasBeenInitialized = PR_TRUE;
       return rv;
     }
 
     case NS_FORM_INPUT_CHECKBOX:
-      return ConstructCheckboxControlFrame(aFrame, aContent, aStyleContext);
+      *aFrame = NS_NewGfxCheckboxControlFrame(mPresShell, aStyleContext);
+      return *aFrame ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 
     case NS_FORM_INPUT_RADIO:
-      return ConstructRadioControlFrame(aFrame, aContent, aStyleContext);
+      *aFrame = NS_NewGfxRadioControlFrame(mPresShell, aStyleContext);
+      return *aFrame ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
 
     case NS_FORM_INPUT_FILE:
     {
       *aFrame = NS_NewFileControlFrame(mPresShell, aStyleContext);
 
       if (*aFrame) {
         // The (block-like) file control frame should have a float manager
         (*aFrame)->AddStateBits(NS_BLOCK_FLOAT_MGR);
@@ -4638,58 +4640,16 @@ nsCSSFrameConstructor::CreatePlaceholder
     return NS_OK;
   }
   else {
     return NS_ERROR_OUT_OF_MEMORY;
   }
 }
 
 nsresult
-nsCSSFrameConstructor::ConstructRadioControlFrame(nsIFrame**      aNewFrame,
-                                                  nsIContent*     aContent,
-                                                  nsStyleContext* aStyleContext)
-{
-  *aNewFrame = NS_NewGfxRadioControlFrame(mPresShell, aStyleContext);
-  if (NS_UNLIKELY(!*aNewFrame)) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  nsRefPtr<nsStyleContext> radioStyle;
-  radioStyle = mPresShell->StyleSet()->ResolvePseudoStyleFor(aContent,
-                                                             nsCSSAnonBoxes::radio,
-                                                             aStyleContext);
-  nsIRadioControlFrame* radio = do_QueryFrame(*aNewFrame);
-  if (radio) {
-    radio->SetRadioButtonFaceStyleContext(radioStyle);
-  }
-  return NS_OK;
-}
-
-nsresult
-nsCSSFrameConstructor::ConstructCheckboxControlFrame(nsIFrame**      aNewFrame,
-                                                     nsIContent*     aContent,
-                                                     nsStyleContext* aStyleContext)
-{
-  *aNewFrame = NS_NewGfxCheckboxControlFrame(mPresShell, aStyleContext);
-  if (NS_UNLIKELY(!*aNewFrame)) {
-    return NS_ERROR_OUT_OF_MEMORY;
-  }
-
-  nsRefPtr<nsStyleContext> checkboxStyle;
-  checkboxStyle = mPresShell->StyleSet()->ResolvePseudoStyleFor(aContent,
-                                                                nsCSSAnonBoxes::check, 
-                                                                aStyleContext);
-  nsICheckboxControlFrame* checkbox = do_QueryFrame(*aNewFrame);
-  if (checkbox) {
-    checkbox->SetCheckboxFaceStyleContext(checkboxStyle);
-  }
-  return NS_OK;
-}
-
-nsresult
 nsCSSFrameConstructor::ConstructButtonFrame(nsFrameConstructorState& aState,
                                             nsIContent*              aContent,
                                             nsIFrame*                aParentFrame,
                                             nsIAtom*                 aTag,
                                             nsStyleContext*          aStyleContext,
                                             nsIFrame**               aNewFrame,
                                             const nsStyleDisplay*    aStyleDisplay,
                                             nsFrameItems&            aFrameItems,
--- a/layout/base/nsCSSFrameConstructor.h
+++ b/layout/base/nsCSSFrameConstructor.h
@@ -556,25 +556,16 @@ protected:
                                             nsIContent*      aContent,
                                             nsIFrame*        aFrame,
                                             nsStyleContext*  aStyleContext,
                                             nsIFrame*        aParentFrame,
                                             nsIFrame*        aPrevInFlow,
                                             nsIFrame**       aPlaceholderFrame);
 
 private:
-  // @param OUT aNewFrame the new radio control frame
-  nsresult ConstructRadioControlFrame(nsIFrame**         aNewFrame,
-                                      nsIContent*        aContent,
-                                      nsStyleContext*    aStyleContext);
-
-  // @param OUT aNewFrame the new checkbox control frame
-  nsresult ConstructCheckboxControlFrame(nsIFrame**       aNewFrame,
-                                         nsIContent*      aContent,
-                                         nsStyleContext*  aStyleContext);
   // ConstructButtonFrame puts the new frame in aFrameItems and
   // handles the kids of the button.
   nsresult ConstructButtonFrame(nsFrameConstructorState& aState,
                                 nsIContent*              aContent,
                                 nsIFrame*                aParentFrame,
                                 nsIAtom*                 aTag,
                                 nsStyleContext*          aStyleContext,
                                 nsIFrame**               aNewFrame,
--- a/layout/forms/nsGfxCheckboxControlFrame.cpp
+++ b/layout/forms/nsGfxCheckboxControlFrame.cpp
@@ -40,16 +40,17 @@
 #include "nsCOMPtr.h"
 #include "nsCSSRendering.h"
 #ifdef ACCESSIBILITY
 #include "nsIAccessibilityService.h"
 #endif
 #include "nsIServiceManager.h"
 #include "nsIDOMHTMLInputElement.h"
 #include "nsDisplayList.h"
+#include "nsCSSAnonBoxes.h"
 
 static void
 PaintCheckMark(nsIRenderingContext& aRenderingContext,
                const nsRect& aRect)
 {
   // Points come from the coordinates on a 7X7 unit box centered at 0,0
   const PRInt32 checkPolygonX[] = { -3, -1,  3,  3, -1, -3 };
   const PRInt32 checkPolygonY[] = { -1,  1, -3, -1,  3,  1 };
@@ -92,39 +93,46 @@ nsGfxCheckboxControlFrame::~nsGfxCheckbo
 {
 }
 
 
 NS_QUERYFRAME_HEAD(nsGfxCheckboxControlFrame)
   NS_QUERYFRAME_ENTRY(nsICheckboxControlFrame)
 NS_QUERYFRAME_TAIL_INHERITING(nsFormControlFrame)
 
+NS_IMETHODIMP
+nsGfxCheckboxControlFrame::Init(nsIContent* aContent,
+                                nsIFrame* aParent,
+                                nsIFrame* aPrevInFlow)
+{
+  nsresult rv = nsFormControlFrame::Init(aContent, aParent, aPrevInFlow);
+  if (NS_SUCCEEDED(rv)) {
+    mCheckButtonFaceStyle =
+      PresContext()->PresShell()->StyleSet()->
+        ResolvePseudoStyleFor(aContent, nsCSSAnonBoxes::check,
+                              GetStyleContext());
+  }
+
+  return rv;
+}
+
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsGfxCheckboxControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
     return accService->CreateHTMLCheckboxAccessible(static_cast<nsIFrame*>(this), aAccessible);
   }
 
   return NS_ERROR_FAILURE;
 }
 #endif
 
 //--------------------------------------------------------------
-NS_IMETHODIMP
-nsGfxCheckboxControlFrame::SetCheckboxFaceStyleContext(nsStyleContext *aCheckboxFaceStyleContext)
-{
-  mCheckButtonFaceStyle = aCheckboxFaceStyleContext;
-  return NS_OK;
-}
-
-
-//--------------------------------------------------------------
 nsStyleContext*
 nsGfxCheckboxControlFrame::GetAdditionalStyleContext(PRInt32 aIndex) const
 {
   switch (aIndex) {
   case NS_GFX_CHECKBOX_CONTROL_FRAME_FACE_CONTEXT_INDEX:
     return mCheckButtonFaceStyle;
     break;
   default:
@@ -218,18 +226,20 @@ nsGfxCheckboxControlFrame::BuildDisplayL
     return NS_OK;   // we're not checked or not visible, nothing to paint.
     
   if (IsThemed())
     return NS_OK; // No need to paint the checkmark. The theme will do it.
 
   // Paint the checkmark
   if (mCheckButtonFaceStyle) {
     // This code actually works now; not sure how useful it'll be
-    // (The putpose is to allow the UA stylesheet can substitute its own
+    // (The purpose is to allow the UA stylesheet to substitute its own
     //  checkmark for the default one)
+    // XXXbz maybe we should just remove this, together with the
+    // attendant complexity
     const nsStyleBackground* myBackground = mCheckButtonFaceStyle->GetStyleBackground();
     if (!myBackground->IsTransparent())
       return aLists.Content()->AppendNewToTop(new (aBuilder)
           nsDisplayGeneric(this, PaintCheckMarkFromStyle, "CheckMarkFromStyle"));
   }
 
   return aLists.Content()->AppendNewToTop(new (aBuilder) nsDisplayCheckMark(this));
 }
--- a/layout/forms/nsGfxCheckboxControlFrame.h
+++ b/layout/forms/nsGfxCheckboxControlFrame.h
@@ -66,25 +66,28 @@ public:
                               const nsDisplayListSet& aLists);
 
 #ifdef ACCESSIBILITY
   NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
 #endif
 
 
   //nsICheckboxControlFrame methods
-  NS_IMETHOD SetCheckboxFaceStyleContext(nsStyleContext *aCheckboxFaceStyleContext);
   NS_IMETHOD OnChecked(nsPresContext* aPresContext, PRBool aChecked);
 
   virtual nsStyleContext* GetAdditionalStyleContext(PRInt32 aIndex) const;
   virtual void SetAdditionalStyleContext(PRInt32 aIndex,
                                          nsStyleContext* aStyleContext);
 
   NS_DECL_QUERYFRAME
 
+  NS_IMETHOD Init(nsIContent* aContent,
+                  nsIFrame* aParent,
+                  nsIFrame* asPrevInFlow);
+
   void PaintCheckBox(nsIRenderingContext& aRenderingContext,
                      nsPoint aPt, const nsRect& aDirtyRect);
 
   void PaintCheckBoxFromStyle(nsIRenderingContext& aRenderingContext,
                               nsPoint aPt, const nsRect& aDirtyRect);
 
 protected:
 
--- a/layout/forms/nsGfxRadioControlFrame.cpp
+++ b/layout/forms/nsGfxRadioControlFrame.cpp
@@ -40,16 +40,17 @@
 #include "nsCOMPtr.h"
 #include "nsCSSRendering.h"
 #ifdef ACCESSIBILITY
 #include "nsIAccessibilityService.h"
 #endif
 #include "nsIServiceManager.h"
 #include "nsITheme.h"
 #include "nsDisplayList.h"
+#include "nsCSSAnonBoxes.h"
 
 nsIFrame*
 NS_NewGfxRadioControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
 {
   return new (aPresShell) nsGfxRadioControlFrame(aContext);
 }
 
 nsGfxRadioControlFrame::nsGfxRadioControlFrame(nsStyleContext* aContext):
@@ -60,16 +61,32 @@ nsGfxRadioControlFrame::nsGfxRadioContro
 nsGfxRadioControlFrame::~nsGfxRadioControlFrame()
 {
 }
 
 NS_QUERYFRAME_HEAD(nsGfxRadioControlFrame)
   NS_QUERYFRAME_ENTRY(nsIRadioControlFrame)
 NS_QUERYFRAME_TAIL_INHERITING(nsFormControlFrame)
 
+NS_IMETHODIMP
+nsGfxRadioControlFrame::Init(nsIContent* aContent,
+                             nsIFrame* aParent,
+                             nsIFrame* aPrevInFlow)
+{
+  nsresult rv = nsFormControlFrame::Init(aContent, aParent, aPrevInFlow);
+  if (NS_SUCCEEDED(rv)) {
+    mRadioButtonFaceStyle =
+      PresContext()->PresShell()->StyleSet()->
+        ResolvePseudoStyleFor(aContent, nsCSSAnonBoxes::radio,
+                              GetStyleContext());
+  }
+
+  return rv;
+}
+
 #ifdef ACCESSIBILITY
 NS_IMETHODIMP nsGfxRadioControlFrame::GetAccessible(nsIAccessible** aAccessible)
 {
   nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
 
   if (accService) {
     return accService->CreateHTMLRadioButtonAccessible(static_cast<nsIFrame*>(this), aAccessible);
   }
@@ -99,24 +116,16 @@ nsGfxRadioControlFrame::SetAdditionalSty
   switch (aIndex) {
   case NS_GFX_RADIO_CONTROL_FRAME_FACE_CONTEXT_INDEX:
     mRadioButtonFaceStyle = aStyleContext;
     break;
   }
 }
 
 //--------------------------------------------------------------
-NS_IMETHODIMP
-nsGfxRadioControlFrame::SetRadioButtonFaceStyleContext(nsStyleContext *aRadioButtonFaceStyleContext)
-{
-  mRadioButtonFaceStyle = aRadioButtonFaceStyleContext;
-  return NS_OK;
-}
-
-//--------------------------------------------------------------
 void
 nsGfxRadioControlFrame::PaintRadioButtonFromStyle(
     nsIRenderingContext& aRenderingContext, nsPoint aPt, const nsRect& aDirtyRect)
 {
   const nsStyleBorder* myBorder = mRadioButtonFaceStyle->GetStyleBorder();
   // Paint the button for the radio button using CSS background rendering code
   const nsStyleBackground* myColor = mRadioButtonFaceStyle->GetStyleBackground();
   const nsStyleColor* color = mRadioButtonFaceStyle->GetStyleColor();
--- a/layout/forms/nsGfxRadioControlFrame.h
+++ b/layout/forms/nsGfxRadioControlFrame.h
@@ -58,17 +58,20 @@ private:
 
 public:
   nsGfxRadioControlFrame(nsStyleContext* aContext);
   ~nsGfxRadioControlFrame();
 
   NS_DECL_QUERYFRAME
   
   //nsIRadioControlFrame methods
-  NS_IMETHOD SetRadioButtonFaceStyleContext(nsStyleContext *aRadioButtonFaceStyleContext);
+  NS_IMETHOD Init(nsIContent* aContent,
+                  nsIFrame* aParent,
+                  nsIFrame* asPrevInFlow);
+
 #ifdef ACCESSIBILITY
   NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
 #endif
   NS_IMETHOD OnChecked(nsPresContext* aPresContext, PRBool aChecked);
 
   virtual nsStyleContext* GetAdditionalStyleContext(PRInt32 aIndex) const;
   virtual void SetAdditionalStyleContext(PRInt32 aIndex,
                                          nsStyleContext* aStyleContext);
--- a/layout/forms/nsICheckboxControlFrame.h
+++ b/layout/forms/nsICheckboxControlFrame.h
@@ -45,22 +45,16 @@ class nsPresContext;
 /** 
   * nsICheckControlFrame is the common interface radio buttons.
   * @see nsFromControlFrame and its base classes for more info
   */
 class nsICheckboxControlFrame
 {
 public:
   NS_DECLARE_FRAME_ACCESSOR(nsICheckboxControlFrame)
-
-  /**
-   * Sets the Pseudo Style Contexts for the Check button
-   */
-  NS_IMETHOD SetCheckboxFaceStyleContext(
-                 nsStyleContext* aCheckboxFaceStyleContext) = 0;
   
   /**
    * Called by content when checkbox "checked" changes
    */
   NS_IMETHOD OnChecked(nsPresContext* aPresContext, PRBool aChecked) = 0;
 };
 
 #endif
--- a/layout/forms/nsIRadioControlFrame.h
+++ b/layout/forms/nsIRadioControlFrame.h
@@ -45,22 +45,16 @@ class nsStyleContext;
   * nsIRadioControlFrame is the common interface radio buttons.
   * @see nsFormControlFrame and its base classes for more info
   */
 class nsIRadioControlFrame
 {
 public:
   NS_DECLARE_FRAME_ACCESSOR(nsIRadioControlFrame)
 
-  /**
-   * Sets the Pseudo Style Contexts for the Radio button
-   */
-
-   NS_IMETHOD SetRadioButtonFaceStyleContext(nsStyleContext *aRadioButtonFaceStyleContext) = 0;
-
    /**
     * Called by content when the radio button's state changes
     */
    NS_IMETHOD OnChecked(nsPresContext* aPresContext, PRBool aChecked) = 0;
 };
 
 #endif