diff --git a/layout/html/document/src/ua.css b/layout/html/document/src/ua.css index 2f5df40ced50..00036a28cc40 100644 --- a/layout/html/document/src/ua.css +++ b/layout/html/document/src/ua.css @@ -46,6 +46,9 @@ FRAMESET { color: black; display: block; } +IFRAME { + border: 1px solid black; +} // XXX Used when PagePreview'ing PAGE { @@ -133,12 +136,22 @@ BR { INPUT { vertical-align: bottom; + font-family: "HACK"; + font-size: 100pt; } SELECT { vertical-align: bottom; + font-family: "Times New Roman"; + font-size: 10pt; +} +OPTION { + font-family: "Times New Roman"; + font-size: 10pt; } TEXTAREA { vertical-align: bottom; + font-family: "HACK"; + font-size: 100pt; } // Block tags diff --git a/layout/html/forms/src/nsForm.cpp b/layout/html/forms/src/nsForm.cpp index 6e79233a9c5c..460b4d3032dc 100644 --- a/layout/html/forms/src/nsForm.cpp +++ b/layout/html/forms/src/nsForm.cpp @@ -834,8 +834,8 @@ void nsForm::RemoveRadioGroups() for (int i = 0; i < numRadioGroups; i++) { nsInputRadioGroup* radioGroup = (nsInputRadioGroup *) mRadioGroups.ElementAt(i); delete radioGroup; - mRadioGroups.RemoveElement(radioGroup); } + mRadioGroups.Clear(); } void nsForm::Init(PRBool aReinit) @@ -861,9 +861,9 @@ void nsForm::Init(PRBool aReinit) nsInputRadioGroup* group; for (int j = 0; j < numGroups; j++) { group = (nsInputRadioGroup *) mRadioGroups.ElementAt(j); - nsString name; - group->GetName(name); - if (name.Equals(name)) { + nsString groupName; + group->GetName(groupName); + if (groupName.Equals(name)) { group->AddRadio(control); added = PR_TRUE; break; diff --git a/layout/html/forms/src/nsInputButton.cpp b/layout/html/forms/src/nsInputButton.cpp index 549e774f1d7a..b7eed640ec84 100644 --- a/layout/html/forms/src/nsInputButton.cpp +++ b/layout/html/forms/src/nsInputButton.cpp @@ -220,7 +220,7 @@ nsInputButton::GetDefaultLabel(nsString& aString) } else if (kButton_Submit == mType) { aString = "Submit Query"; } else if (kButton_Browse == mType) { - aString = "Browse..."; + aString = " Browse... "; } else { aString = " "; } @@ -544,15 +544,13 @@ nsInputButtonFrame::GetDesiredSize(nsIPresContext* aPresContext, void nsInputButtonFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView) { -printf("-------------nsInputButtonFrame::PostCreateWidget-----------\n"); nsIButton* button; if (NS_OK == GetWidget(aView, (nsIWidget **)&button)) { -printf("Before setting font\n"); - button->SetFont(GetFont(aPresContext)); -printf("After setting font\n"); + nsFont font("foo", 0, 0, 0, 0, 0); + GetFont(aPresContext, font); + button->SetFont(font); } else { -printf("Button is NULL\n"); NS_ASSERTION(0, "no widget in button control"); } @@ -561,9 +559,7 @@ printf("Button is NULL\n"); nsString value; nsContentAttr status = content->GetAttribute(nsHTMLAtoms::value, value); if (eContentAttr_HasValue == status) { -printf("Before setting SetLabel [%s]\n", value.ToNewCString()); button->SetLabel(value); -printf("After setting SetLabel\n"); } else { nsAutoString label; diff --git a/layout/html/forms/src/nsInputFrame.cpp b/layout/html/forms/src/nsInputFrame.cpp index 2bbacc96278a..7ce903da7d3e 100644 --- a/layout/html/forms/src/nsInputFrame.cpp +++ b/layout/html/forms/src/nsInputFrame.cpp @@ -455,12 +455,14 @@ nsInputFrame::GetTextSize(nsIPresContext& aPresContext, nsInputFrame* aFrame, //printf("\n GetTextSize %s", aString.ToNewCString()); nsIStyleContext* styleContext; aFrame->GetStyleContext(&aPresContext, styleContext); - const nsStyleFont* styleFont = (const nsStyleFont*)styleContext->GetStyleData(eStyleStruct_Font); + nsFont font("foo", 0, 0, 0, 0, 0); + aFrame->GetFont(&aPresContext, font); + //const nsStyleFont* styleFont = (const nsStyleFont*)styleContext->GetStyleData(eStyleStruct_Font); NS_RELEASE(styleContext); nsIDeviceContext* deviceContext = aPresContext.GetDeviceContext(); nsIFontCache* fontCache = deviceContext->GetFontCache(); - nsIFontMetrics* fontMet = fontCache->GetMetricsFor(styleFont->mFont); + nsIFontMetrics* fontMet = fontCache->GetMetricsFor(font); aSize.width = fontMet->GetWidth(aString); aSize.height = fontMet->GetHeight(); @@ -608,15 +610,58 @@ nsInputFrame::CalculateSize (nsIPresContext* aPresContext, nsInputFrame* aFrame, } -const nsFont& -nsInputFrame::GetFont(nsIPresContext* aPresContext) +const void +nsInputFrame::GetFont(nsIPresContext* aPresContext, nsFont& aFont) { const nsStyleFont* styleFont = (const nsStyleFont*)mStyleContext->GetStyleData(eStyleStruct_Font); - return styleFont->mFont; + // XXX this is a hack to determine if the font was set by ua.css. If it is "Courier New", + // and we are anything except a then assume that it was set by the backstop + // and override it to a simulated user preference value of "Times New". Of course, there is + // no way to actually set it to "Courier New" until this hack is obsoleted by fixing the style + // system. + + nsAutoString magicName("HACK"); + nscoord magicSize = 100 * 20; + nscoord size10 = 10 * 20; + nscoord size12 = 12 * 20; + nsAutoString fixedFont("Courier New"); + nsAutoString varFont("Times New Roman"); + + nscoord fontSize = styleFont->mFont.size; + nsString type; + ((nsInput*)mContent)->GetType(type); + + // get the font family + if (styleFont->mFont.name.EqualsIgnoreCase(magicName)) { + nsFont* fakeFont; + if (type.EqualsIgnoreCase("text") || type.EqualsIgnoreCase("textarea") || + type.EqualsIgnoreCase("password")) { + fakeFont = new nsFont(fixedFont, 0, 0, 240, 0, fontSize); + } + else { + fakeFont = new nsFont(varFont, 0, 0, 240, 0, fontSize); + } + aFont = *fakeFont; + delete fakeFont; + } + else { + aFont = styleFont->mFont; + } + + // get the font size + if (type.EqualsIgnoreCase("text") || type.EqualsIgnoreCase("textarea") || + type.EqualsIgnoreCase("password")) { + aFont.size = (fontSize == magicSize) ? size12 : fontSize; + } + else { + aFont.size = (fontSize == magicSize) ? size10 : fontSize; + } + + if (type.EqualsIgnoreCase("browse")) { + aFont.weight = 999; + } } - - diff --git a/layout/html/forms/src/nsInputFrame.h b/layout/html/forms/src/nsInputFrame.h index e9f801def05d..419c0a5c7b48 100644 --- a/layout/html/forms/src/nsInputFrame.h +++ b/layout/html/forms/src/nsInputFrame.h @@ -206,7 +206,7 @@ protected: nsReflowMetrics& aDesiredLayoutSize, nsSize& aDesiredWidgetSize); - const nsFont& GetFont(nsIPresContext* aPresContext); + const void GetFont(nsIPresContext* aPresContext, nsFont& aFont); /** * Get the width and height of this control based on CSS diff --git a/layout/html/forms/src/nsInputRadio.cpp b/layout/html/forms/src/nsInputRadio.cpp index 9d90cd4f382f..9e6e81305472 100644 --- a/layout/html/forms/src/nsInputRadio.cpp +++ b/layout/html/forms/src/nsInputRadio.cpp @@ -99,13 +99,12 @@ nsInputRadioFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView { nsInputRadio* content = (nsInputRadio *)mContent; PRInt32 checkedAttr; - nsContentAttr result = ((nsInput *)content)->GetAttribute(nsHTMLAtoms::checked, checkedAttr); - if ((result == eContentAttr_HasValue) && (PR_FALSE != checkedAttr)) { - nsIRadioButton* radio; - if (NS_OK == GetWidget(aView, (nsIWidget **)&radio)) { - radio->SetState(PR_TRUE); - NS_RELEASE(radio); - } + //nsContentAttr result = ((nsInput *)content)->GetAttribute(nsHTMLAtoms::checked, checkedAttr); + //if ((result == eContentAttr_HasValue) && (PR_FALSE != checkedAttr)) { + nsIRadioButton* radio; + if (NS_OK == GetWidget(aView, (nsIWidget **)&radio)) { + radio->SetState(content->mForcedChecked); + NS_RELEASE(radio); } } @@ -116,7 +115,8 @@ const nsString* nsInputRadio::kTYPE = new nsString("radio"); nsInputRadio::nsInputRadio(nsIAtom* aTag, nsIFormManager* aManager) : nsInput(aTag, aManager) { - mChecked = PR_FALSE; + mInitialChecked = PR_FALSE; + mForcedChecked = PR_FALSE; } nsInputRadio::~nsInputRadio() @@ -179,22 +179,29 @@ PRBool nsInputRadio::GetChecked(PRBool aGetInitialValue) const { if (aGetInitialValue) { - return mChecked; + return mInitialChecked; } else { - NS_ASSERTION(mWidget, "no widget for this nsInputRadio"); - return ((nsIRadioButton *)mWidget)->GetState(); + if (mWidget) { + return ((nsIRadioButton *)mWidget)->GetState(); + } + else { + return mForcedChecked; + } } } void nsInputRadio::SetChecked(PRBool aValue, PRBool aSetInitialValue) { + mForcedChecked = aValue; if (aSetInitialValue) { - mChecked = aValue; + mInitialChecked = aValue; + } + //NS_ASSERTION(mWidget, "no widget for this nsInputRadio"); + if (mWidget) { + ((nsIRadioButton *)mWidget)->SetState(aValue); } - NS_ASSERTION(mWidget, "no widget for this nsInputRadio"); - ((nsIRadioButton *)mWidget)->SetState(aValue); } nsresult @@ -221,7 +228,8 @@ void nsInputRadio::SetAttribute(nsIAtom* aAttribute, const nsString& aValue) { if (aAttribute == nsHTMLAtoms::checked) { - mChecked = PR_TRUE; + mInitialChecked = PR_TRUE; + mForcedChecked = PR_TRUE; } nsInputRadioSuper::SetAttribute(aAttribute, aValue); } @@ -231,7 +239,7 @@ nsContentAttr nsInputRadio::GetAttribute(nsIAtom* aAttribute, { aResult.Reset(); if (aAttribute == nsHTMLAtoms::checked) { - return GetCacheAttribute(mChecked, aResult, eHTMLUnit_Empty); + return GetCacheAttribute(mInitialChecked, aResult, eHTMLUnit_Empty); } else { return nsInputRadioSuper::GetAttribute(aAttribute, aResult); @@ -267,7 +275,7 @@ nsInputRadio::Reset() { nsIRadioButton* radio = (nsIRadioButton *)GetWidget(); if (nsnull != radio) { - radio->SetState(mChecked); + radio->SetState(mInitialChecked); } } diff --git a/layout/html/forms/src/nsInputRadio.h b/layout/html/forms/src/nsInputRadio.h index 2cd523888c38..bf136f7e981d 100644 --- a/layout/html/forms/src/nsInputRadio.h +++ b/layout/html/forms/src/nsInputRadio.h @@ -61,7 +61,10 @@ protected: virtual void GetType(nsString& aResult) const; - PRBool mChecked; + PRBool mInitialChecked; + PRBool mForcedChecked; + + friend class nsInputRadioFrame; }; class nsInputRadioGroup diff --git a/layout/html/forms/src/nsInputText.cpp b/layout/html/forms/src/nsInputText.cpp index b692a3857fbf..a592605d19f4 100644 --- a/layout/html/forms/src/nsInputText.cpp +++ b/layout/html/forms/src/nsInputText.cpp @@ -33,6 +33,7 @@ #include "nsString.h" #include "nsHTMLAtoms.h" #include "nsHTMLForms.h" +#include "nsFont.h" class nsInputTextFrame : public nsInputFrame { public: @@ -156,10 +157,19 @@ nsInputTextFrame::GetDesiredSize(nsIPresContext* aPresContext, PRBool widthExplicit, heightExplicit; PRInt32 ignore; if ((kInputText_Text == textType) || (kInputText_Password == textType) || - (kInputText_FileText == textType)) - { - nsInputDimensionSpec textSpec(nsHTMLAtoms::size, PR_FALSE, nsnull, - nsnull, 21, PR_FALSE, nsnull, 1); + (kInputText_FileText == textType)) { + nsHTMLValue sizeAttr; + PRInt32 width = 21; + if (eContentAttr_HasValue == ((nsInput*)mContent)->GetAttribute(nsHTMLAtoms::size, sizeAttr)) { + width = (sizeAttr.GetUnit() == eHTMLUnit_Pixel) ? sizeAttr.GetPixelValue() : sizeAttr.GetIntValue(); + if (kBackwardMode == GetMode()) { + width += 1; + } + } + nsInputDimensionSpec textSpec(nsnull, PR_FALSE, nsnull, + nsnull, width, PR_FALSE, nsnull, 1); + // nsInputDimensionSpec textSpec(nsHTMLAtoms::size, PR_FALSE, nsnull, + // nsnull, 21, PR_FALSE, nsnull, 1); CalculateSize(aPresContext, this, styleSize, textSpec, size, widthExplicit, heightExplicit, ignore); } @@ -216,12 +226,18 @@ nsInputTextFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView) { nsITextWidget* text; if (NS_OK == GetWidget(aView, (nsIWidget **)&text)) { - text->SetFont(GetFont(aPresContext)); + nsFont font("foo", 0, 0, 0, 0, 0); + GetFont(aPresContext, font); + text->SetFont(font); nsInputText* content; GetContent((nsIContent *&) content); nsAutoString valAttr; nsContentAttr valStatus = ((nsInput *)content)->GetAttribute(nsHTMLAtoms::value, valAttr); text->SetText(valAttr); + PRInt32 maxLength = content->GetMaxLength(); + if (ATTR_NOTSET != maxLength) { + text->SetMaxTextLength(maxLength); + } NS_RELEASE(text); NS_RELEASE(content); } @@ -310,7 +326,7 @@ void nsInputText::GetType(nsString& aResult) const aResult = "password"; } else if (kInputText_Area == mType) { - aResult = ""; + aResult = "textarea"; } else if (kInputText_FileText == mType) { aResult = "filetext"; diff --git a/layout/html/forms/src/nsInputText.h b/layout/html/forms/src/nsInputText.h index 23d7c11ed5a3..164f65fbef1b 100644 --- a/layout/html/forms/src/nsInputText.h +++ b/layout/html/forms/src/nsInputText.h @@ -53,6 +53,8 @@ public: nsInputTextType GetTextType() const; + PRInt32 GetMaxLength() const { return mMaxLength; } + virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsString* aValues, nsString* aNames); diff --git a/layout/html/forms/src/nsSelect.cpp b/layout/html/forms/src/nsSelect.cpp index 9fc1be4ce42c..68df7ef5f329 100644 --- a/layout/html/forms/src/nsSelect.cpp +++ b/layout/html/forms/src/nsSelect.cpp @@ -38,6 +38,7 @@ #include "nsIListBox.h" #include "nsInput.h" #include "nsHTMLForms.h" +#include "nsFont.h" static NS_DEFINE_IID(kListWidgetIID, NS_ILISTWIDGET_IID); static NS_DEFINE_IID(kComboBoxIID, NS_ICOMBOBOX_IID); @@ -313,7 +314,9 @@ nsSelectFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView) return; } - list->SetFont(GetFont(aPresContext)); + nsFont font("foo", 0, 0, 0, 0, 0); + GetFont(aPresContext, font); + list->SetFont(font); PRInt32 numChildren = select->ChildCount(); for (int i = 0; i < numChildren; i++) { diff --git a/layout/style/ua.css b/layout/style/ua.css index 2f5df40ced50..00036a28cc40 100644 --- a/layout/style/ua.css +++ b/layout/style/ua.css @@ -46,6 +46,9 @@ FRAMESET { color: black; display: block; } +IFRAME { + border: 1px solid black; +} // XXX Used when PagePreview'ing PAGE { @@ -133,12 +136,22 @@ BR { INPUT { vertical-align: bottom; + font-family: "HACK"; + font-size: 100pt; } SELECT { vertical-align: bottom; + font-family: "Times New Roman"; + font-size: 10pt; +} +OPTION { + font-family: "Times New Roman"; + font-size: 10pt; } TEXTAREA { vertical-align: bottom; + font-family: "HACK"; + font-size: 100pt; } // Block tags