more nav4 compatibility, radio group bug fixes

This commit is contained in:
karnaze 1998-07-01 20:11:57 +00:00
Родитель 4687e1488a
Коммит 5c32434ce8
11 изменённых файлов: 144 добавлений и 45 удалений

Просмотреть файл

@ -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

Просмотреть файл

@ -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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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 <input type=text> 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;
}
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -61,7 +61,10 @@ protected:
virtual void GetType(nsString& aResult) const;
PRBool mChecked;
PRBool mInitialChecked;
PRBool mForcedChecked;
friend class nsInputRadioFrame;
};
class nsInputRadioGroup

Просмотреть файл

@ -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";

Просмотреть файл

@ -53,6 +53,8 @@ public:
nsInputTextType GetTextType() const;
PRInt32 GetMaxLength() const { return mMaxLength; }
virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames);

Просмотреть файл

@ -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++) {

Просмотреть файл

@ -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