diff --git a/mozilla/layout/html/forms/src/nsInput.cpp b/mozilla/layout/html/forms/src/nsInput.cpp index 4efed089262..fc851f85de5 100644 --- a/mozilla/layout/html/forms/src/nsInput.cpp +++ b/mozilla/layout/html/forms/src/nsInput.cpp @@ -283,7 +283,7 @@ void nsInput::CacheAttribute(const nsString& aValue, PRInt32 aMinValue, PRInt32& void nsInput::SetAttribute(nsIAtom* aAttribute, const nsString& aValue) { if (aAttribute == nsHTMLAtoms::type) { // You cannot set the type of a form element - return; + ; } else if (aAttribute == nsHTMLAtoms::name) { CacheAttribute(aValue, mName); @@ -305,9 +305,8 @@ void nsInput::SetAttribute(nsIAtom* aAttribute, const nsString& aValue) } return; } - else { - nsInputSuper::SetAttribute(aAttribute, aValue); - } + // XXX the following is necessary so that MapAttributesInto gets called + nsInputSuper::SetAttribute(aAttribute, aValue); } nsContentAttr nsInput::GetCacheAttribute(nsString* const& aLoc, nsHTMLValue& aValue) const diff --git a/mozilla/layout/html/forms/src/nsInputCheckbox.cpp b/mozilla/layout/html/forms/src/nsInputCheckbox.cpp index 05c6d349219..f10b1a2c753 100644 --- a/mozilla/layout/html/forms/src/nsInputCheckbox.cpp +++ b/mozilla/layout/html/forms/src/nsInputCheckbox.cpp @@ -30,6 +30,7 @@ #include "nsWidgetsCID.h" #include "nsIView.h" #include "nsHTMLAtoms.h" +#include "nsIStyleContext.h" class nsInputCheckboxFrame : public nsInputFrame { public: @@ -42,8 +43,6 @@ public: virtual const nsIID& GetIID(); virtual void MouseClicked(nsIPresContext* aPresContext); - virtual PRInt32 GetPadding() const; - NS_IMETHOD SetRect(const nsRect& aRect); protected: virtual ~nsInputCheckboxFrame(); @@ -62,14 +61,6 @@ nsInputCheckboxFrame::~nsInputCheckboxFrame() { } -NS_METHOD nsInputCheckboxFrame::SetRect(const nsRect& aRect) -{ - PRInt32 padding = GetPadding(); - MoveTo(aRect.x + padding, aRect.y); - SizeTo(aRect.width - (2 * padding), aRect.height); - return NS_OK; -} - const nsIID& nsInputCheckboxFrame::GetIID() { @@ -84,11 +75,6 @@ nsInputCheckboxFrame::GetCID() return kCheckboxCID; } -PRInt32 nsInputCheckboxFrame::GetPadding() const -{ - return GetDefaultPadding(); -} - void nsInputCheckboxFrame::GetDesiredSize(nsIPresContext* aPresContext, const nsReflowState& aReflowState, @@ -98,10 +84,7 @@ nsInputCheckboxFrame::GetDesiredSize(nsIPresContext* aPresContext, float p2t = aPresContext->GetPixelsToTwips(); aDesiredWidgetSize.width = (int)(12 * p2t); aDesiredWidgetSize.height = (int)(12 * p2t); - // XXX Why is padding being added? GetDesiredSize() as defined by nsLeafFrame - // should return the size of the content area only... - PRInt32 padding = GetPadding(); - aDesiredLayoutSize.width = aDesiredWidgetSize.width + (2 * padding); + aDesiredLayoutSize.width = aDesiredWidgetSize.width; aDesiredLayoutSize.height = aDesiredWidgetSize.height; aDesiredLayoutSize.ascent = aDesiredLayoutSize.height; aDesiredLayoutSize.descent = 0; @@ -153,6 +136,34 @@ nsInputCheckbox::~nsInputCheckbox() } +void nsInputCheckbox::MapAttributesInto(nsIStyleContext* aContext, + nsIPresContext* aPresContext) +{ + float p2t = aPresContext->GetPixelsToTwips(); + nscoord pad = (int)(3 * p2t + 0.5); + + // add left and right padding around the radio button via css + nsStyleSpacing* spacing = (nsStyleSpacing*) aContext->GetData(eStyleStruct_Spacing); + if (eStyleUnit_Null == spacing->mMargin.GetLeftUnit()) { + nsStyleCoord left(pad); + spacing->mMargin.SetLeft(left); + } + if (eStyleUnit_Null == spacing->mMargin.GetRightUnit()) { + nsStyleCoord right((int)(5 * p2t + 0.5)); + spacing->mMargin.SetRight(right); + } + // add bottom padding if backward mode + // XXX why isn't this working? + nsIFormManager* formMan = GetFormManager(); + if (formMan && (kBackwardMode == formMan->GetMode())) { + if (eStyleUnit_Null == spacing->mMargin.GetBottomUnit()) { + nsStyleCoord bottom(pad); + spacing->mMargin.SetBottom(bottom); + } + nsInput::MapAttributesInto(aContext, aPresContext); + } +} + PRInt32 nsInputCheckbox::GetMaxNumValues() { @@ -219,9 +230,7 @@ void nsInputCheckbox::SetAttribute(nsIAtom* aAttribute, if (aAttribute == nsHTMLAtoms::checked) { mChecked = PR_TRUE; } - else { - nsInputCheckboxSuper::SetAttribute(aAttribute, aValue); - } + nsInputCheckboxSuper::SetAttribute(aAttribute, aValue); } nsContentAttr nsInputCheckbox::GetAttribute(nsIAtom* aAttribute, diff --git a/mozilla/layout/html/forms/src/nsInputCheckbox.h b/mozilla/layout/html/forms/src/nsInputCheckbox.h index f7d4d2e03a9..4fda1cdac0a 100644 --- a/mozilla/layout/html/forms/src/nsInputCheckbox.h +++ b/mozilla/layout/html/forms/src/nsInputCheckbox.h @@ -43,6 +43,8 @@ public: virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsString* aValues, nsString* aNames); + virtual void MapAttributesInto(nsIStyleContext* aContext, + nsIPresContext* aPresContext); virtual void Reset(); protected: diff --git a/mozilla/layout/html/forms/src/nsInputFrame.cpp b/mozilla/layout/html/forms/src/nsInputFrame.cpp index c12b9d7cf27..dbc68938877 100644 --- a/mozilla/layout/html/forms/src/nsInputFrame.cpp +++ b/mozilla/layout/html/forms/src/nsInputFrame.cpp @@ -348,16 +348,6 @@ nsInputFrame::GetWidgetInitData(nsIPresContext& aPresContext) return nsnull; } -nscoord nsInputFrame::GetDefaultPadding() const -{ - return NS_POINTS_TO_TWIPS_INT(2); // XXX should be pixels, need pres context -} - -nscoord nsInputFrame::GetPadding() const -{ - return 0; -} - void nsInputFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView) { diff --git a/mozilla/layout/html/forms/src/nsInputFrame.h b/mozilla/layout/html/forms/src/nsInputFrame.h index d1ef9c4daac..0a57db08aaf 100644 --- a/mozilla/layout/html/forms/src/nsInputFrame.h +++ b/mozilla/layout/html/forms/src/nsInputFrame.h @@ -137,8 +137,6 @@ public: */ virtual const nsIID& GetIID(); - nscoord GetDefaultPadding() const; - virtual nscoord GetPadding() const; /** * Get the widget associated with this frame * @param aView the view associated with the frame. It is a convience parm. diff --git a/mozilla/layout/html/forms/src/nsInputRadio.cpp b/mozilla/layout/html/forms/src/nsInputRadio.cpp index 217e524e3cc..61a61dbb7e8 100644 --- a/mozilla/layout/html/forms/src/nsInputRadio.cpp +++ b/mozilla/layout/html/forms/src/nsInputRadio.cpp @@ -32,6 +32,7 @@ #include "nsHTMLAtoms.h" #include "nsIFormManager.h" #include "nsIView.h" +#include "nsIStyleContext.h" class nsInputRadioFrame : public nsInputFrame { public: @@ -44,8 +45,6 @@ public: virtual const nsIID& GetIID(); virtual void MouseClicked(nsIPresContext* aPresContext); - virtual PRInt32 GetPadding() const; - NS_IMETHOD SetRect(const nsRect& aRect); protected: @@ -66,20 +65,6 @@ nsInputRadioFrame::~nsInputRadioFrame() { } - -PRInt32 nsInputRadioFrame::GetPadding() const -{ - return GetDefaultPadding(); -} - -NS_METHOD nsInputRadioFrame::SetRect(const nsRect& aRect) -{ - PRInt32 padding = GetPadding(); - MoveTo(aRect.x + padding, aRect.y); - SizeTo(aRect.width - (2 * padding), aRect.height); - return NS_OK; -} - const nsIID& nsInputRadioFrame::GetIID() { @@ -103,10 +88,7 @@ nsInputRadioFrame::GetDesiredSize(nsIPresContext* aPresContext, float p2t = aPresContext->GetPixelsToTwips(); aDesiredWidgetSize.width = (int)(12 * p2t); aDesiredWidgetSize.height = (int)(12 * p2t); - PRInt32 padding = GetPadding(); - // XXX Why is padding being added? GetDesiredSize() as defined by nsLeafFrame - // should return the size of the content area only... - aDesiredLayoutSize.width = aDesiredWidgetSize.width + (2 * padding); + aDesiredLayoutSize.width = aDesiredWidgetSize.width; aDesiredLayoutSize.height = aDesiredWidgetSize.height; aDesiredLayoutSize.ascent = aDesiredLayoutSize.height; aDesiredLayoutSize.descent = 0; @@ -141,6 +123,34 @@ nsInputRadio::~nsInputRadio() { } +void nsInputRadio::MapAttributesInto(nsIStyleContext* aContext, + nsIPresContext* aPresContext) +{ + float p2t = aPresContext->GetPixelsToTwips(); + nscoord pad = (int)(3 * p2t + 0.5); + + // add left and right padding around the radio button via css + nsStyleSpacing* spacing = (nsStyleSpacing*) aContext->GetData(eStyleStruct_Spacing); + if (eStyleUnit_Null == spacing->mMargin.GetLeftUnit()) { + nsStyleCoord left(pad); + spacing->mMargin.SetLeft(left); + } + if (eStyleUnit_Null == spacing->mMargin.GetRightUnit()) { + nsStyleCoord right((int)(5 * p2t + 0.5)); + spacing->mMargin.SetRight(right); + } + // add bottom padding if backward mode + // XXX why isn't this working? + nsIFormManager* formMan = GetFormManager(); + if (formMan && (kBackwardMode == formMan->GetMode())) { + if (eStyleUnit_Null == spacing->mMargin.GetBottomUnit()) { + nsStyleCoord bottom(pad); + spacing->mMargin.SetBottom(bottom); + } + nsInput::MapAttributesInto(aContext, aPresContext); + } +} + static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID); void @@ -213,9 +223,7 @@ void nsInputRadio::SetAttribute(nsIAtom* aAttribute, if (aAttribute == nsHTMLAtoms::checked) { mChecked = PR_TRUE; } - else { - nsInputRadioSuper::SetAttribute(aAttribute, aValue); - } + nsInputRadioSuper::SetAttribute(aAttribute, aValue); } nsContentAttr nsInputRadio::GetAttribute(nsIAtom* aAttribute, diff --git a/mozilla/layout/html/forms/src/nsInputRadio.h b/mozilla/layout/html/forms/src/nsInputRadio.h index d74d6186ac7..2cd523888c3 100644 --- a/mozilla/layout/html/forms/src/nsInputRadio.h +++ b/mozilla/layout/html/forms/src/nsInputRadio.h @@ -52,6 +52,8 @@ public: virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsString* aValues, nsString* aNames); + virtual void MapAttributesInto(nsIStyleContext* aContext, + nsIPresContext* aPresContext); virtual void Reset(); protected: diff --git a/mozilla/layout/html/forms/src/nsInputText.cpp b/mozilla/layout/html/forms/src/nsInputText.cpp index b22305a6997..10e9538f47e 100644 --- a/mozilla/layout/html/forms/src/nsInputText.cpp +++ b/mozilla/layout/html/forms/src/nsInputText.cpp @@ -323,9 +323,7 @@ void nsInputText::SetAttribute(nsIAtom* aAttribute, const nsString& aValue) else if ((aAttribute == nsHTMLAtoms::cols) && (kInputText_Area == mType)) { CacheAttribute(aValue, ATTR_NOTSET, mNumCols); } - else { - nsInputTextSuper::SetAttribute(aAttribute, aValue); - } + nsInputTextSuper::SetAttribute(aAttribute, aValue); } nsContentAttr nsInputText::GetAttribute(nsIAtom* aAttribute, diff --git a/mozilla/layout/html/forms/src/nsSelect.cpp b/mozilla/layout/html/forms/src/nsSelect.cpp index 72d372fe1f4..3b76b0e564f 100644 --- a/mozilla/layout/html/forms/src/nsSelect.cpp +++ b/mozilla/layout/html/forms/src/nsSelect.cpp @@ -75,7 +75,7 @@ protected: class nsSelect : public nsInput { public: - typedef nsInput super; + typedef nsInput nsSelectSuper; nsSelect (nsIAtom* aTag, nsIFormManager* aFormMan); virtual nsresult CreateFrame(nsIPresContext* aPresContext, @@ -112,7 +112,7 @@ protected: class nsOption : public nsInput { public: - typedef nsInput super; + typedef nsInput nsOptionSuper; nsOption (nsIAtom* aTag); @@ -366,9 +366,7 @@ void nsSelect::SetAttribute(nsIAtom* aAttribute, if (aAttribute == nsHTMLAtoms::multiple) { mMultiple = PR_TRUE; } - else { - super::SetAttribute(aAttribute, aValue); - } + nsSelectSuper::SetAttribute(aAttribute, aValue); } nsContentAttr nsSelect::GetAttribute(nsIAtom* aAttribute, @@ -379,7 +377,7 @@ nsContentAttr nsSelect::GetAttribute(nsIAtom* aAttribute, return GetCacheAttribute(mMultiple, aResult, eHTMLUnit_Empty); } else { - return super::GetAttribute(aAttribute, aResult); + return nsSelectSuper::GetAttribute(aAttribute, aResult); } } @@ -531,7 +529,7 @@ void nsOption::SetAttribute(nsIAtom* aAttribute, mSelected = PR_TRUE; } else { - super::SetAttribute(aAttribute, aValue); + nsOptionSuper::SetAttribute(aAttribute, aValue); } } @@ -543,7 +541,7 @@ nsContentAttr nsOption::GetAttribute(nsIAtom* aAttribute, return GetCacheAttribute(mSelected, aResult, eHTMLUnit_Empty); } else { - return super::GetAttribute(aAttribute, aResult); + return nsOptionSuper::GetAttribute(aAttribute, aResult); } } @@ -583,7 +581,7 @@ nsOption::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, } nsString valAttr; - nsContentAttr stat = super::GetAttribute(nsHTMLAtoms::value, valAttr); + nsContentAttr stat = nsOptionSuper::GetAttribute(nsHTMLAtoms::value, valAttr); if (eContentAttr_HasValue == stat) { aValues[0] = valAttr; aNumValues = 1;