added <input type=image>, fixed bug where multiple submit buttons sent data

This commit is contained in:
karnaze
1998-05-01 23:18:44 +00:00
parent dec31ddd5b
commit 76cb15e29d
21 changed files with 403 additions and 344 deletions

View File

@@ -69,10 +69,18 @@ public:
* @param aNumValues the actual number of values set (out parm) * @param aNumValues the actual number of values set (out parm)
* @param aValues an array of nsString which contains the values (out parm * @param aValues an array of nsString which contains the values (out parm
* that is allocated by the caller) * that is allocated by the caller)
* @param aNames an array of nsString which contains the names (out parm
* that is allocated by the caller)
* @return PR_TRUE if any values were set, PR_FALSE otherwise * @return PR_TRUE if any values were set, PR_FALSE otherwise
*/ */
virtual PRBool GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues) = 0; nsString* aValues, nsString* aNames) = 0;
/**
* Return true if this control should have its data submitted
* @param aSubmitter the submit button or text field that caused the submit
*/
virtual PRBool IsSuccessful(nsIFormControl* aSubmitter) const = 0;
/** /**
* Set this control back to its initial value * Set this control back to its initial value

View File

@@ -63,8 +63,10 @@ public:
* method attributes. This in response to a submit button being clicked. * method attributes. This in response to a submit button being clicked.
* @param aPresContext the presentation context * @param aPresContext the presentation context
* @param aFrame the frame of the submit button * @param aFrame the frame of the submit button
* @param aSubmitter the control that caused the submit
*/ */
virtual void OnSubmit(nsIPresContext* aPresContext, nsIFrame* aFrame) = 0; virtual void OnSubmit(nsIPresContext* aPresContext, nsIFrame* aFrame,
nsIFormControl* aSubmitter) = 0;
/** /**
* This is tbd and is in repsonse to a tab key being entered in one * This is tbd and is in repsonse to a tab key being entered in one

View File

@@ -31,7 +31,6 @@ CPPSRCS = \
nsInputCheckbox.cpp \ nsInputCheckbox.cpp \
nsInputFile.cpp \ nsInputFile.cpp \
nsInputFrame.cpp \ nsInputFrame.cpp \
nsInputImage.cpp \
nsInputRadio.cpp \ nsInputRadio.cpp \
nsInputText.cpp \ nsInputText.cpp \
nsSelect.cpp \ nsSelect.cpp \

View File

@@ -25,13 +25,13 @@ MODULE=raptor
REQUIRES=xpcom raptor REQUIRES=xpcom raptor
CPPSRCS=nsForm.cpp nsInput.cpp nsInputButton.cpp nsInputCheckbox.cpp \ CPPSRCS=nsForm.cpp nsInput.cpp nsInputButton.cpp nsInputCheckbox.cpp \
nsInputFile.cpp nsInputFrame.cpp nsInputImage.cpp \ nsInputFile.cpp nsInputFrame.cpp \
nsInputRadio.cpp nsInputText.cpp nsSelect.cpp nsInputRadio.cpp nsInputText.cpp nsSelect.cpp
CPP_OBJS=.\$(OBJDIR)\nsForm.obj .\$(OBJDIR)\nsInput.obj \ CPP_OBJS=.\$(OBJDIR)\nsForm.obj .\$(OBJDIR)\nsInput.obj \
.\$(OBJDIR)\nsInputButton.obj .\$(OBJDIR)\nsInputCheckbox.obj \ .\$(OBJDIR)\nsInputButton.obj .\$(OBJDIR)\nsInputCheckbox.obj \
.\$(OBJDIR)\nsInputFile.obj .\$(OBJDIR)\nsInputFrame.obj \ .\$(OBJDIR)\nsInputFile.obj .\$(OBJDIR)\nsInputFrame.obj \
.\$(OBJDIR)\nsInputImage.obj .\$(OBJDIR)\nsInputRadio.obj \ .\$(OBJDIR)\nsInputRadio.obj \
.\$(OBJDIR)\nsInputText.obj .\$(OBJDIR)\nsSelect.obj .\$(OBJDIR)\nsInputText.obj .\$(OBJDIR)\nsSelect.obj
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \ LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor \

View File

@@ -111,7 +111,8 @@ public:
virtual void OnReturn(); virtual void OnReturn();
// callback for submit button controls. // callback for submit button controls.
virtual void OnSubmit(nsIPresContext* aPresContext, nsIFrame* aFrame); virtual void OnSubmit(nsIPresContext* aPresContext, nsIFrame* aFrame,
nsIFormControl* aSubmitter);
// callback for tabs on controls that can gain focus. This will // callback for tabs on controls that can gain focus. This will
// eventually need to be handled at the document level to support // eventually need to be handled at the document level to support
@@ -257,7 +258,8 @@ nsForm::OnReturn()
} }
void void
nsForm::OnSubmit(nsIPresContext* aPresContext, nsIFrame* aFrame) nsForm::OnSubmit(nsIPresContext* aPresContext, nsIFrame* aFrame,
nsIFormControl* aSubmitter)
{ {
printf("\n YYYYYYYYYYYYY \n"); printf("\n YYYYYYYYYYYYY \n");
// right now we only do "get" // right now we only do "get"
@@ -274,22 +276,22 @@ nsForm::OnSubmit(nsIPresContext* aPresContext, nsIFrame* aFrame)
// collect and encode the data from the children controls // collect and encode the data from the children controls
for (PRInt32 childX = 0; childX < numChildren; childX++) { for (PRInt32 childX = 0; childX < numChildren; childX++) {
nsIFormControl* child = (nsIFormControl*) mChildren.ElementAt(childX); nsIFormControl* child = (nsIFormControl*) mChildren.ElementAt(childX);
nsString childName; if (child->IsSuccessful(aSubmitter)) {
if (PR_TRUE == child->GetName(childName)) {
PRInt32 numValues = 0; PRInt32 numValues = 0;
PRInt32 maxNumValues = child->GetMaxNumValues(); PRInt32 maxNumValues = child->GetMaxNumValues();
if (maxNumValues <= 0) { if (maxNumValues <= 0) {
continue; continue;
} }
nsString* names = new nsString[maxNumValues];
nsString* values = new nsString[maxNumValues]; nsString* values = new nsString[maxNumValues];
if (PR_TRUE == child->GetValues(maxNumValues, numValues, values)) { if (PR_TRUE == child->GetNamesValues(maxNumValues, numValues, values, names)) {
for (int valueX = 0; valueX < numValues; valueX++) { for (int valueX = 0; valueX < numValues; valueX++) {
if (PR_TRUE == firstTime) { if (PR_TRUE == firstTime) {
firstTime = PR_FALSE; firstTime = PR_FALSE;
} else { } else {
data += "&"; data += "&";
} }
nsString* convName = EscapeURLString(childName); nsString* convName = EscapeURLString(names[valueX]);
data += *convName; data += *convName;
delete convName; delete convName;
data += "="; data += "=";

View File

@@ -49,7 +49,11 @@ nsInput::nsInput(nsIAtom* aTag, nsIFormManager* aManager)
mFormMan->AddFormControl(&mControl); mFormMan->AddFormControl(&mControl);
} }
mSize = ATTR_NOTSET; mSize = ATTR_NOTSET;
mAlign = ATTR_NOTSET; mAlign = nsnull;
mWidth = ATTR_NOTSET;
mHeight= ATTR_NOTSET;
mLastClickPoint.x = -1;
mLastClickPoint.y = -1;
} }
nsInput::~nsInput() nsInput::~nsInput()
@@ -68,10 +72,17 @@ nsInput::~nsInput()
} }
} }
void nsInput::SetClickPoint(nscoord aX, nscoord aY)
{
mLastClickPoint.x = aX;
mLastClickPoint.y = aY;
}
void nsInput::MapAttributesInto(nsIStyleContext* aContext, void nsInput::MapAttributesInto(nsIStyleContext* aContext,
nsIPresContext* aPresContext) nsIPresContext* aPresContext)
{ {
#if 0 #if 0
XXX
if (ATTR_NOTSET != mAlign) { if (ATTR_NOTSET != mAlign) {
nsStyleDisplay* display = (nsStyleDisplay*) nsStyleDisplay* display = (nsStyleDisplay*)
aContext->GetData(kStyleDisplaySID); aContext->GetData(kStyleDisplaySID);
@@ -106,6 +117,16 @@ nsresult nsInput::QueryInterface(REFNSIID aIID, void** aInstancePtr)
return nsHTMLContainer::QueryInterface(aIID, aInstancePtr); return nsHTMLContainer::QueryInterface(aIID, aInstancePtr);
} }
PRBool nsInput::IsSuccessful(nsIFormControl* aSubmitter) const
{
if (nsnull == mName) {
return PR_FALSE;
}
else {
return PR_TRUE;
}
}
nsrefcnt nsInput::Release() nsrefcnt nsInput::Release()
{ {
--mRefCnt; --mRefCnt;
@@ -222,7 +243,8 @@ nsInput::GetMaxNumValues()
} }
PRBool PRBool
nsInput::GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsString* aValues) nsInput::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames)
{ {
aNumValues = 0; aNumValues = 0;
return PR_FALSE; return PR_FALSE;
@@ -256,6 +278,12 @@ void nsInput::SetAttribute(nsIAtom* aAttribute, const nsString& aValue)
else if (aAttribute == nsHTMLAtoms::size) { else if (aAttribute == nsHTMLAtoms::size) {
CacheAttribute(aValue, ATTR_NOTSET, mSize); CacheAttribute(aValue, ATTR_NOTSET, mSize);
} }
else if (aAttribute == nsHTMLAtoms::width) {
CacheAttribute(aValue, ATTR_NOTSET, mWidth);
}
else if (aAttribute == nsHTMLAtoms::height) {
CacheAttribute(aValue, ATTR_NOTSET, mHeight);
}
else if (aAttribute == nsHTMLAtoms::value) { else if (aAttribute == nsHTMLAtoms::value) {
CacheAttribute(aValue, mValue); CacheAttribute(aValue, mValue);
} }
@@ -263,7 +291,7 @@ void nsInput::SetAttribute(nsIAtom* aAttribute, const nsString& aValue)
CacheAttribute(aValue, ATTR_NOTSET, mAlign); CacheAttribute(aValue, ATTR_NOTSET, mAlign);
} }
else { else {
super::SetAttribute(aAttribute, aValue); nsInputSuper::SetAttribute(aAttribute, aValue);
} }
} }
@@ -300,24 +328,10 @@ nsContentAttr nsInput::GetCacheAttribute(PRInt32 aLoc, nsHTMLValue& aValue, nsHT
else { else {
aValue.SetIntValue(aLoc, aUnit); aValue.SetIntValue(aLoc, aUnit);
} }
return eContentAttr_HasValue;
}
}
#if 0
// Replaced by using eHTMLUnit_Empty in above method
nsContentAttr nsInput::GetCacheAttribute(PRBool aLoc, nsHTMLValue& aValue) const
{
aValue.Reset();
if (aLoc) {
aValue.Set(1);
return eContentAttr_HasValue; return eContentAttr_HasValue;
} }
else {
return eContentAttr_NotThere;
}
} }
#endif
nsContentAttr nsInput::GetAttribute(nsIAtom* aAttribute, nsString& aValue) const nsContentAttr nsInput::GetAttribute(nsIAtom* aAttribute, nsString& aValue) const
{ {
@@ -356,22 +370,6 @@ nsContentAttr nsInput::GetAttribute(nsIAtom* aAttribute, PRInt32& aValue) const
} }
} }
#if 0
nsContentAttr nsInput::GetAttribute(nsIAtom* aAttribute, PRBool& aValue) const
{
PRInt32 intVal;
nsContentAttr result = GetAttribute(aAttribute, intVal);
if ((eContentAttr_HasValue == result) && (intVal > 0)) {
aValue = PR_TRUE;
return eContentAttr_HasValue;
}
else {
aValue = PR_FALSE;
return eContentAttr_NoValue;
}
}
#endif
nsContentAttr nsInput::GetAttribute(nsIAtom* aAttribute, nsContentAttr nsInput::GetAttribute(nsIAtom* aAttribute,
nsHTMLValue& aValue) const nsHTMLValue& aValue) const
{ {
@@ -392,6 +390,12 @@ nsContentAttr nsInput::GetAttribute(nsIAtom* aAttribute,
else if (aAttribute == nsHTMLAtoms::size) { else if (aAttribute == nsHTMLAtoms::size) {
return GetCacheAttribute(mSize, aValue, eHTMLUnit_Pixel); // XXX pixel or percent?? return GetCacheAttribute(mSize, aValue, eHTMLUnit_Pixel); // XXX pixel or percent??
} }
else if (aAttribute == nsHTMLAtoms::width) {
return GetCacheAttribute(mWidth, aValue, eHTMLUnit_Pixel); // XXX pixel or percent??
}
else if (aAttribute == nsHTMLAtoms::height) {
return GetCacheAttribute(mHeight, aValue, eHTMLUnit_Pixel); // XXX pixel or percent??
}
else if (aAttribute == nsHTMLAtoms::value) { else if (aAttribute == nsHTMLAtoms::value) {
return GetCacheAttribute(mValue, aValue); return GetCacheAttribute(mValue, aValue);
} }
@@ -399,7 +403,7 @@ nsContentAttr nsInput::GetAttribute(nsIAtom* aAttribute,
return GetCacheAttribute(mAlign, aValue, eHTMLUnit_Enumerated); return GetCacheAttribute(mAlign, aValue, eHTMLUnit_Enumerated);
} }
else { else {
return super::GetAttribute(aAttribute, aValue); return nsInputSuper::GetAttribute(aAttribute, aValue);
} }
} }
@@ -450,11 +454,10 @@ PRInt32 nsInput::AggInputControl::GetMaxNumValues()
return GET_OUTER()->GetMaxNumValues(); return GET_OUTER()->GetMaxNumValues();
} }
PRBool nsInput::AggInputControl::GetValues(PRInt32 aMaxNumValues, PRBool nsInput::AggInputControl::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
PRInt32& aNumValues, nsString* aValues, nsString* aNames)
nsString* aValues)
{ {
return GET_OUTER()->GetValues(aMaxNumValues, aNumValues, aValues); return GET_OUTER()->GetNamesValues(aMaxNumValues, aNumValues, aValues, aNames);
} }
void nsInput::AggInputControl::Reset() void nsInput::AggInputControl::Reset()
@@ -492,3 +495,7 @@ void nsInput::AggInputControl::GetType(nsString& aName) const
GET_OUTER()->GetType(aName); GET_OUTER()->GetType(aName);
} }
PRBool nsInput::AggInputControl::IsSuccessful(nsIFormControl* aSubmitter) const
{
return GET_OUTER()->IsSuccessful(aSubmitter);
}

View File

@@ -21,11 +21,13 @@
#include "nsHTMLContainer.h" #include "nsHTMLContainer.h"
#include "nsIFormControl.h" #include "nsIFormControl.h"
#include "nsPoint.h"
class nsIFormManager; class nsIFormManager;
class nsIWidget; class nsIWidget;
class nsIView; class nsIView;
class nsIPresContext; class nsIPresContext;
/** /**
* nsInput represents an html Input element. This is a base class for * nsInput represents an html Input element. This is a base class for
* the various Input types (button, checkbox, file, hidden, password, * the various Input types (button, checkbox, file, hidden, password,
@@ -33,7 +35,7 @@ class nsIPresContext;
*/ */
class nsInput : public nsHTMLContainer { class nsInput : public nsHTMLContainer {
public: public:
typedef nsHTMLContainer super; typedef nsHTMLContainer nsInputSuper;
/** /**
* main constructor * main constructor
* @param aTag the html tag associated with this object * @param aTag the html tag associated with this object
@@ -80,11 +82,13 @@ public:
/** /**
* @see nsIFormControl GetFormManager * @see nsIFormControl GetFormManager
*/ */
virtual PRBool GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues); nsString* aValues, nsString* aNames);
virtual PRBool IsHidden(); virtual PRBool IsHidden();
virtual PRBool IsSuccessful(nsIFormControl* aSubmitter) const;
/** /**
* @see nsIFormControl GetFormManager * @see nsIFormControl GetFormManager
*/ */
@@ -110,9 +114,6 @@ public:
virtual nsContentAttr GetAttribute(nsIAtom* aAttribute, nsString& aValue) const; virtual nsContentAttr GetAttribute(nsIAtom* aAttribute, nsString& aValue) const;
virtual nsContentAttr GetAttribute(nsIAtom* aAttribute, PRInt32& aValue) const; virtual nsContentAttr GetAttribute(nsIAtom* aAttribute, PRInt32& aValue) const;
#if 0
virtual nsContentAttr GetAttribute(nsIAtom* aAttribute, PRBool& aValue) const;
#endif
/** /**
* Set the named attribute of this input * Set the named attribute of this input
@@ -150,6 +151,7 @@ public:
virtual void GetType(nsString& aResult) const = 0; virtual void GetType(nsString& aResult) const = 0;
virtual PRBool GetChecked(PRBool aGetInitialValue) const; virtual PRBool GetChecked(PRBool aGetInitialValue) const;
virtual void SetChecked(PRBool aState, PRBool aSetInitialValue); virtual void SetChecked(PRBool aState, PRBool aSetInitialValue);
virtual void SetClickPoint(nscoord aX, nscoord aY);
protected: protected:
virtual ~nsInput(); virtual ~nsInput();
@@ -159,20 +161,20 @@ protected:
*/ */
nsIWidget* mWidget; nsIWidget* mWidget;
nsIFormManager* mFormMan; nsIFormManager* mFormMan;
nsPoint mLastClickPoint;
void CacheAttribute(const nsString& aValue, nsString*& aLoc); void CacheAttribute(const nsString& aValue, nsString*& aLoc);
void CacheAttribute(const nsString& aValue, PRInt32 aMinValue, PRInt32& aLoc); void CacheAttribute(const nsString& aValue, PRInt32 aMinValue, PRInt32& aLoc);
nsContentAttr GetCacheAttribute(nsString* const& aLoc, nsHTMLValue& aValue) const; nsContentAttr GetCacheAttribute(nsString* const& aLoc, nsHTMLValue& aValue) const;
nsContentAttr GetCacheAttribute(PRInt32 aLoc, nsHTMLValue& aValue, nsHTMLUnit aUnit) const; nsContentAttr GetCacheAttribute(PRInt32 aLoc, nsHTMLValue& aValue, nsHTMLUnit aUnit) const;
#if 0
nsContentAttr GetCacheAttribute(PRBool aLoc, nsHTMLValue& aValue) const;
#endif
// Attributes common to all html form elements // Attributes common to all html form elements
nsString* mName; nsString* mName;
nsString* mValue; nsString* mValue;
PRInt32 mSize; PRInt32 mSize;
PRInt32 mAlign; PRInt32 mAlign;
PRInt32 mWidth;
PRInt32 mHeight;
// Aggregator class and instance variable used to aggregate in the // Aggregator class and instance variable used to aggregate in the
// nsIFormControl interface to nsInput w/o using multiple // nsIFormControl interface to nsInput w/o using multiple
@@ -189,14 +191,15 @@ protected:
virtual PRBool GetName(nsString& aName) const; virtual PRBool GetName(nsString& aName) const;
virtual void GetType(nsString& aType) const; virtual void GetType(nsString& aType) const;
virtual PRInt32 GetMaxNumValues(); virtual PRInt32 GetMaxNumValues();
virtual PRBool GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues); nsString* aValues, nsString* aNames);
virtual void Reset(); virtual void Reset();
virtual void SetFormManager(nsIFormManager* aFormMan, PRBool aDecrementRef = PR_TRUE); virtual void SetFormManager(nsIFormManager* aFormMan, PRBool aDecrementRef = PR_TRUE);
virtual nsIFormManager* GetFormManager() const; virtual nsIFormManager* GetFormManager() const;
virtual nsrefcnt GetRefCount() const; virtual nsrefcnt GetRefCount() const;
virtual PRBool GetChecked(PRBool aGetInitialValue) const; virtual PRBool GetChecked(PRBool aGetInitialValue) const;
virtual void SetChecked(PRBool aState, PRBool aSetInitialValue); virtual void SetChecked(PRBool aState, PRBool aSetInitialValue);
virtual PRBool IsSuccessful(nsIFormControl* aSubmitter) const;
}; };
AggInputControl mControl; AggInputControl mControl;
}; };

View File

@@ -39,19 +39,29 @@
#include "nsIFontCache.h" #include "nsIFontCache.h"
#include "nsIFontMetrics.h" #include "nsIFontMetrics.h"
#include "nsIFormManager.h" #include "nsIFormManager.h"
#include "nsIImage.h"
#include "nsHTMLForms.h"
enum nsInputButtonType { enum nsButtonTagType {
kButton_InputButton, kButtonTag_Button,
kButton_Button, kButtonTag_Input
kButton_InputReset,
kButton_InputSubmit,
kButton_InputHidden
}; };
enum nsButtonType {
kButton_Button,
kButton_Reset,
kButton_Submit,
kButton_Image,
kButton_Hidden
};
static NS_DEFINE_IID(kIFormControlIID, NS_IFORMCONTROL_IID);
class nsInputButton : public nsInput { class nsInputButton : public nsInput {
public: public:
typedef nsInput nsInputButtonSuper;
nsInputButton (nsIAtom* aTag, nsIFormManager* aManager, nsInputButton (nsIAtom* aTag, nsIFormManager* aManager,
nsInputButtonType aType); nsButtonType aType);
virtual nsIFrame* CreateFrame(nsIPresContext* aPresContext, virtual nsIFrame* CreateFrame(nsIPresContext* aPresContext,
PRInt32 aIndexInParent, PRInt32 aIndexInParent,
@@ -59,28 +69,44 @@ public:
virtual void GetDefaultLabel(nsString& aLabel); virtual void GetDefaultLabel(nsString& aLabel);
nsInputButtonType GetButtonType() { return mType; } nsButtonType GetButtonType() { return mType; }
nsButtonTagType GetButtonTagType() { return mTagType; }
virtual PRInt32 GetMaxNumValues(); virtual PRInt32 GetMaxNumValues();
virtual PRBool GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsString* aValues); virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames);
virtual PRBool IsHidden(); virtual PRBool IsHidden();
virtual PRBool IsSuccessful(nsIFormControl* aSubmitter) const;
protected: protected:
virtual ~nsInputButton(); virtual ~nsInputButton();
virtual void GetType(nsString& aResult) const; virtual void GetType(nsString& aResult) const;
nsInputButtonType mType; nsButtonType mType;
nsButtonTagType mTagType;
}; };
class nsInputButtonFrame : public nsInputFrame { class nsInputButtonFrame : public nsInputFrame {
public: public:
typedef nsInputFrame nsInputButtonFrameSuper;
nsInputButtonFrame(nsIContent* aContent, nsInputButtonFrame(nsIContent* aContent,
PRInt32 aIndexInParent, PRInt32 aIndexInParent,
nsIFrame* aParentFrame); nsIFrame* aParentFrame);
NS_IMETHOD Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect);
NS_IMETHOD ResizeReflow(nsIPresContext* aPresContext,
nsReflowMetrics& aDesiredSize,
const nsSize& aMaxSize,
nsSize* aMaxElementSize,
ReflowStatus& aStatus);
virtual void PostCreateWidget(nsIPresContext* aPresContext, nsIView* aView); virtual void PostCreateWidget(nsIPresContext* aPresContext, nsIView* aView);
virtual void MouseClicked(nsIPresContext* aPresContext); virtual void MouseClicked(nsIPresContext* aPresContext);
@@ -89,7 +115,10 @@ public:
virtual const nsIID& GetIID(); virtual const nsIID& GetIID();
nsInputButtonType GetButtonType() const; nsButtonType GetButtonType() const;
nsButtonTagType GetButtonTagType() const;
nsIImage* GetImage(nsIPresContext& aPresContext);
protected: protected:
@@ -105,9 +134,12 @@ protected:
// nsInputButton Implementation // nsInputButton Implementation
nsInputButton::nsInputButton(nsIAtom* aTag, nsIFormManager* aManager, nsInputButton::nsInputButton(nsIAtom* aTag, nsIFormManager* aManager,
nsInputButtonType aType) nsButtonType aType)
: nsInput(aTag, aManager), mType(aType) : nsInput(aTag, aManager), mType(aType)
{ {
nsAutoString tagName;
aTag->ToString(tagName);
mTagType = (tagName.EqualsIgnoreCase("input")) ? kButtonTag_Input : kButtonTag_Button;
} }
nsInputButton::~nsInputButton() nsInputButton::~nsInputButton()
@@ -117,10 +149,18 @@ nsInputButton::~nsInputButton()
} }
} }
PRBool nsInputButton::IsSuccessful(nsIFormControl* aSubmitter) const
{
if ((void*)&mControl == (void*)aSubmitter) {
return nsInputButtonSuper::IsSuccessful(aSubmitter);
}
return PR_FALSE;
}
PRBool PRBool
nsInputButton::IsHidden() nsInputButton::IsHidden()
{ {
if (kButton_InputHidden == mType) { if (kButton_Hidden == mType) {
return PR_TRUE; return PR_TRUE;
} }
else { else {
@@ -131,16 +171,27 @@ nsInputButton::IsHidden()
void nsInputButton::GetType(nsString& aResult) const void nsInputButton::GetType(nsString& aResult) const
{ {
aResult.SetLength(0); aResult.SetLength(0);
if (kButtonTag_Button == mTagType) {
aResult.Append("button");
return;
}
switch (mType) { switch (mType) {
case kButton_InputButton:
case kButton_Button: case kButton_Button:
aResult.Append("button"); aResult.Append("button");
break; break;
case kButton_InputReset: case kButton_Reset:
aResult.Append("reset"); aResult.Append("reset");
break; break;
case kButton_Image:
aResult.Append("image");
break;
case kButton_Hidden:
aResult.Append("hidden");
break;
case kButton_Submit:
default: default:
case kButton_InputSubmit:
aResult.Append("submit"); aResult.Append("submit");
break; break;
} }
@@ -149,9 +200,9 @@ void nsInputButton::GetType(nsString& aResult) const
void void
nsInputButton::GetDefaultLabel(nsString& aString) nsInputButton::GetDefaultLabel(nsString& aString)
{ {
if (kButton_InputReset == mType) { if (kButton_Reset == mType) {
aString = "Reset"; aString = "Reset";
} else if (kButton_InputSubmit == mType) { } else if (kButton_Submit == mType) {
aString = "Submit"; aString = "Submit";
} else { } else {
aString = "noname"; aString = "noname";
@@ -163,7 +214,7 @@ nsInputButton::CreateFrame(nsIPresContext* aPresContext,
PRInt32 aIndexInParent, PRInt32 aIndexInParent,
nsIFrame* aParentFrame) nsIFrame* aParentFrame)
{ {
if (kButton_InputHidden == mType) { if (kButton_Hidden == mType) {
nsIFrame* frame; nsIFrame* frame;
nsFrame::NewFrame(&frame, this, aIndexInParent, aParentFrame); nsFrame::NewFrame(&frame, this, aIndexInParent, aParentFrame);
return frame; return frame;
@@ -177,8 +228,10 @@ nsInputButton::CreateFrame(nsIPresContext* aPresContext,
PRInt32 PRInt32
nsInputButton::GetMaxNumValues() nsInputButton::GetMaxNumValues()
{ {
if ((kButton_InputSubmit == mType) || (kButton_InputHidden)) { if ((kButton_Submit == mType) || (kButton_Hidden == mType)) {
return 1; return 1;
} else if ((kButton_Image == mType) && (kButtonTag_Input == mTagType)) {
return 2;
} else { } else {
return 0; return 0;
} }
@@ -186,21 +239,36 @@ nsInputButton::GetMaxNumValues()
PRBool PRBool
nsInputButton::GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsInputButton::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues) nsString* aValues, nsString* aNames)
{ {
if (aMaxNumValues <= 0) { if ((aMaxNumValues <= 0) || (nsnull == mName)) {
return PR_FALSE; return PR_FALSE;
} }
if ((kButton_InputSubmit != mType) && (kButton_InputHidden != mType)) { if ((kButton_Image == mType) && (kButtonTag_Input == mTagType)) {
aNumValues = 0; char buf[20];
return PR_FALSE; aNumValues = 2;
}
if (nsnull != mValue) {
aValues[0].SetLength(0); aValues[0].SetLength(0);
aValues[0].Append(*mValue); sprintf(&buf[0], "%d", mLastClickPoint.x);
aValues[0].Append(&buf[0]);
aNames[0] = *mName;
aNames[0].Append(".x");
aValues[1].SetLength(0);
sprintf(&buf[0], "%d", mLastClickPoint.y);
aValues[1].Append(&buf[0]);
aNames[1] = *mName;
aNames[1].Append(".y");
return PR_TRUE;
}
else if ((kButton_Submit == mType) || (kButton_Hidden == mType) && (nsnull != mValue)) {
aValues[0] = *mValue;
aNames[0] = *mName;
aNumValues = 1; aNumValues = 1;
return PR_TRUE; return PR_TRUE;
} else { } else {
@@ -223,46 +291,141 @@ nsInputButtonFrame::~nsInputButtonFrame()
{ {
} }
nsInputButtonType nsButtonType
nsInputButtonFrame::GetButtonType() const nsInputButtonFrame::GetButtonType() const
{ {
nsInputButton* button = (nsInputButton *)mContent; nsInputButton* button = (nsInputButton *)mContent;
return button->GetButtonType(); return button->GetButtonType();
} }
nsButtonTagType
nsInputButtonFrame::GetButtonTagType() const
{
nsInputButton* button = (nsInputButton *)mContent;
return button->GetButtonTagType();
}
nsIImage* nsInputButtonFrame::GetImage(nsIPresContext& aPresContext)
{
if (kButton_Image != GetButtonType()) {
return nsnull;
}
nsAutoString src;
if (eContentAttr_HasValue == mContent->GetAttribute("SRC", src)) {
return aPresContext.LoadImage(src, this);
}
return nsnull;
}
NS_METHOD nsInputButtonFrame::Paint(nsIPresContext& aPresContext,
nsIRenderingContext& aRenderingContext,
const nsRect& aDirtyRect)
{
// let super do processing if there is no image
if (kButton_Image != GetButtonType()) {
return nsInputButtonFrameSuper::Paint(aPresContext, aRenderingContext, aDirtyRect);
}
nsIImage* image = GetImage(aPresContext);
if (nsnull == image) {
return NS_OK;
}
// First paint background and borders
nsLeafFrame::Paint(aPresContext, aRenderingContext, aDirtyRect);
// Now render the image into our inner area (the area without the
nsRect inner;
GetInnerArea(&aPresContext, inner);
aRenderingContext.DrawImage(image, inner);
return NS_OK;
}
void void
nsInputButtonFrame::MouseClicked(nsIPresContext* aPresContext) nsInputButtonFrame::MouseClicked(nsIPresContext* aPresContext)
{ {
nsInputButton* button = (nsInputButton *)mContent; nsInputButton* button = (nsInputButton *)mContent;
nsIFormManager* formMan = button->GetFormManager(); nsIFormManager* formMan = button->GetFormManager();
if (nsnull != formMan) { if (nsnull != formMan) {
if (kButton_InputReset == button->GetButtonType()) { nsButtonType butType = button->GetButtonType();
nsButtonTagType butTagType = button->GetButtonTagType();
if (kButton_Reset == butType) {
formMan->OnReset(); formMan->OnReset();
} else if (kButton_InputSubmit == button->GetButtonType()) { } else if ((kButton_Submit == butType) ||
((kButton_Image == butType) && (kButtonTag_Input == butTagType))) {
//NS_ADDREF(this); //NS_ADDREF(this);
formMan->OnSubmit(aPresContext, this); nsIFormControl* control;
mContent->QueryInterface(kIFormControlIID, (void**)&control);
formMan->OnSubmit(aPresContext, this, control);
//NS_RELEASE(this); //NS_RELEASE(this);
} }
NS_RELEASE(formMan); NS_RELEASE(formMan);
} }
} }
NS_METHOD
nsInputButtonFrame::ResizeReflow(nsIPresContext* aPresContext,
nsReflowMetrics& aDesiredSize,
const nsSize& aMaxSize,
nsSize* aMaxElementSize,
ReflowStatus& aStatus)
{
if ((kButtonTag_Input == GetButtonTagType()) && (kButton_Image == GetButtonType())) {
nsSize ignore;
GetDesiredSize(aPresContext, aMaxSize, aDesiredSize, ignore);
AddBordersAndPadding(aPresContext, aDesiredSize);
if (nsnull != aMaxElementSize) {
aMaxElementSize->width = aDesiredSize.width;
aMaxElementSize->height = aDesiredSize.height;
}
mCacheBounds.width = aDesiredSize.width;
mCacheBounds.height = aDesiredSize.height;
aStatus = frComplete;
return NS_OK;
}
else {
return nsInputButtonFrameSuper::
ResizeReflow(aPresContext, aDesiredSize, aMaxSize, aMaxElementSize, aStatus);
}
}
void void
nsInputButtonFrame::GetDesiredSize(nsIPresContext* aPresContext, nsInputButtonFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsSize& aMaxSize, const nsSize& aMaxSize,
nsReflowMetrics& aDesiredLayoutSize, nsReflowMetrics& aDesiredLayoutSize,
nsSize& aDesiredWidgetSize) nsSize& aDesiredWidgetSize)
{ {
if (kButton_InputHidden == GetButtonType()) {
if (kButton_Hidden == GetButtonType()) { // there is no physical rep
aDesiredLayoutSize.width = 0; aDesiredLayoutSize.width = 0;
aDesiredLayoutSize.height = 0; aDesiredLayoutSize.height = 0;
aDesiredWidgetSize.width = 0;
aDesiredWidgetSize.height = 0;
return;
} }
else {
nsSize styleSize; nsSize styleSize;
GetStyleSize(*aPresContext, aMaxSize, styleSize); GetStyleSize(*aPresContext, aMaxSize, styleSize);
if (kButton_Image == GetButtonType()) { // there is an image
float p2t = aPresContext->GetPixelsToTwips();
if ((0 < styleSize.width) && (0 < styleSize.height)) {
// Use dimensions from style attributes
aDesiredLayoutSize.width = nscoord(styleSize.width * p2t);
aDesiredLayoutSize.height = nscoord(styleSize.height * p2t);
} else {
nsIImage* image = GetImage(*aPresContext);
if (nsnull == image) {
// XXX Here is where we trigger a resize-reflow later on; or block
// layout or whatever our policy wants to be
aDesiredLayoutSize.width = nscoord(50 * p2t);
aDesiredLayoutSize.height = nscoord(50 * p2t);
} else {
aDesiredLayoutSize.width = nscoord(image->GetWidth() * p2t);
aDesiredLayoutSize.height = nscoord(image->GetHeight() * p2t);
}
}
}
else { // there is a widget
nsSize size; nsSize size;
PRBool widthExplicit, heightExplicit; PRBool widthExplicit, heightExplicit;
PRInt32 ignore; PRInt32 ignore;
@@ -280,8 +443,11 @@ nsInputButtonFrame::GetDesiredSize(nsIPresContext* aPresContext,
aDesiredLayoutSize.width = size.width; aDesiredLayoutSize.width = size.width;
aDesiredLayoutSize.height= size.height; aDesiredLayoutSize.height= size.height;
aDesiredWidgetSize.width = size.width; }
aDesiredWidgetSize.height= size.height; }
aDesiredWidgetSize.width = aDesiredLayoutSize.width;
aDesiredWidgetSize.height= aDesiredLayoutSize.height;
} }
@@ -328,7 +494,7 @@ nsInputButtonFrame::GetCID()
nsresult nsresult
CreateButton(nsIHTMLContent** aInstancePtrResult, CreateButton(nsIHTMLContent** aInstancePtrResult,
nsIAtom* aTag, nsIFormManager* aManager, nsIAtom* aTag, nsIFormManager* aManager,
nsInputButtonType aType) nsButtonType aType)
{ {
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr"); NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) { if (nsnull == aInstancePtrResult) {
@@ -347,7 +513,7 @@ nsresult
NS_NewHTMLInputButton(nsIHTMLContent** aInstancePtrResult, NS_NewHTMLInputButton(nsIHTMLContent** aInstancePtrResult,
nsIAtom* aTag, nsIFormManager* aManager) nsIAtom* aTag, nsIFormManager* aManager)
{ {
return CreateButton(aInstancePtrResult, aTag, aManager, kButton_InputButton); return CreateButton(aInstancePtrResult, aTag, aManager, kButton_Button);
} }
nsresult nsresult
@@ -361,19 +527,26 @@ nsresult
NS_NewHTMLInputSubmit(nsIHTMLContent** aInstancePtrResult, NS_NewHTMLInputSubmit(nsIHTMLContent** aInstancePtrResult,
nsIAtom* aTag, nsIFormManager* aManager) nsIAtom* aTag, nsIFormManager* aManager)
{ {
return CreateButton(aInstancePtrResult, aTag, aManager, kButton_InputSubmit); return CreateButton(aInstancePtrResult, aTag, aManager, kButton_Submit);
} }
nsresult nsresult
NS_NewHTMLInputReset(nsIHTMLContent** aInstancePtrResult, NS_NewHTMLInputReset(nsIHTMLContent** aInstancePtrResult,
nsIAtom* aTag, nsIFormManager* aManager) nsIAtom* aTag, nsIFormManager* aManager)
{ {
return CreateButton(aInstancePtrResult, aTag, aManager, kButton_InputReset); return CreateButton(aInstancePtrResult, aTag, aManager, kButton_Reset);
}
nsresult
NS_NewHTMLInputImage(nsIHTMLContent** aInstancePtrResult,
nsIAtom* aTag, nsIFormManager* aManager)
{
return CreateButton(aInstancePtrResult, aTag, aManager, kButton_Image);
} }
nsresult nsresult
NS_NewHTMLInputHidden(nsIHTMLContent** aInstancePtrResult, NS_NewHTMLInputHidden(nsIHTMLContent** aInstancePtrResult,
nsIAtom* aTag, nsIFormManager* aManager) nsIAtom* aTag, nsIFormManager* aManager)
{ {
return CreateButton(aInstancePtrResult, aTag, aManager, kButton_InputHidden); return CreateButton(aInstancePtrResult, aTag, aManager, kButton_Hidden);
} }

View File

@@ -165,10 +165,10 @@ nsInputCheckbox::GetMaxNumValues()
PRBool PRBool
nsInputCheckbox::GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsInputCheckbox::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues) nsString* aValues, nsString* aNames)
{ {
if (aMaxNumValues <= 0) { if ((aMaxNumValues <= 0) || (nsnull == mName)) {
return PR_FALSE; return PR_FALSE;
} }
nsICheckButton* checkBox = (nsICheckButton *)GetWidget(); nsICheckButton* checkBox = (nsICheckButton *)GetWidget();
@@ -182,6 +182,7 @@ nsInputCheckbox::GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
} else { } else {
aValues[0] = *mValue; aValues[0] = *mValue;
} }
aNames[0] = *mName;
aNumValues = 1; aNumValues = 1;
return PR_TRUE; return PR_TRUE;
@@ -217,7 +218,7 @@ void nsInputCheckbox::SetAttribute(nsIAtom* aAttribute,
mChecked = PR_TRUE; mChecked = PR_TRUE;
} }
else { else {
super::SetAttribute(aAttribute, aValue); nsInputCheckboxSuper::SetAttribute(aAttribute, aValue);
} }
} }
@@ -229,7 +230,7 @@ nsContentAttr nsInputCheckbox::GetAttribute(nsIAtom* aAttribute,
return GetCacheAttribute(mChecked, aResult, eHTMLUnit_Empty); return GetCacheAttribute(mChecked, aResult, eHTMLUnit_Empty);
} }
else { else {
return super::GetAttribute(aAttribute, aResult); return nsInputCheckboxSuper::GetAttribute(aAttribute, aResult);
} }
} }

View File

@@ -25,7 +25,7 @@ class nsString;
class nsInputCheckbox : public nsInput { class nsInputCheckbox : public nsInput {
public: public:
typedef nsInput super; typedef nsInput nsInputCheckboxSuper;
nsInputCheckbox (nsIAtom* aTag, nsIFormManager* aManager); nsInputCheckbox (nsIAtom* aTag, nsIFormManager* aManager);
virtual nsIFrame* CreateFrame(nsIPresContext* aPresContext, virtual nsIFrame* CreateFrame(nsIPresContext* aPresContext,
@@ -39,8 +39,8 @@ public:
virtual PRInt32 GetMaxNumValues(); virtual PRInt32 GetMaxNumValues();
virtual PRBool GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues); nsString* aValues, nsString* aNames);
virtual void Reset(); virtual void Reset();

View File

@@ -27,7 +27,7 @@ class nsString;
class nsInputFile : public nsInput { class nsInputFile : public nsInput {
public: public:
typedef nsInput super; typedef nsInput nsInputFileSuper;
nsInputFile (nsIAtom* aTag, nsIFormManager* aManager); nsInputFile (nsIAtom* aTag, nsIFormManager* aManager);
virtual nsIFrame* CreateFrame(nsIPresContext* aPresContext, virtual nsIFrame* CreateFrame(nsIPresContext* aPresContext,

View File

@@ -76,7 +76,7 @@ nsInputFrame::~nsInputFrame()
NS_METHOD nsInputFrame::SetRect(const nsRect& aRect) NS_METHOD nsInputFrame::SetRect(const nsRect& aRect)
{ {
return super::SetRect(aRect); return nsInputFrameSuper::SetRect(aRect);
} }
@@ -322,10 +322,7 @@ NS_METHOD nsInputFrame::HandleEvent(nsIPresContext& aPresContext,
nsIView* view; nsIView* view;
GetView(view); GetView(view);
if (view == nsnull) { if (view != nsnull) {
return nsEventStatus_eIgnore;
}
nsresult result = GetWidget(view, &thisWidget); nsresult result = GetWidget(view, &thisWidget);
nsISupports* thisWidgetSup; nsISupports* thisWidgetSup;
result = thisWidget->QueryInterface(kSupportsIID, (void **)&thisWidgetSup); result = thisWidget->QueryInterface(kSupportsIID, (void **)&thisWidgetSup);
@@ -346,6 +343,7 @@ NS_METHOD nsInputFrame::HandleEvent(nsIPresContext& aPresContext,
aEventStatus = nsEventStatus_eIgnore; aEventStatus = nsEventStatus_eIgnore;
return NS_OK; return NS_OK;
} }
}
switch (aEvent->message) { switch (aEvent->message) {
case NS_MOUSE_ENTER: case NS_MOUSE_ENTER:
@@ -362,6 +360,9 @@ NS_METHOD nsInputFrame::HandleEvent(nsIPresContext& aPresContext,
widget->SetFocus(); widget->SetFocus();
NS_RELEASE(widget); NS_RELEASE(widget);
NS_RELEASE(view); */ NS_RELEASE(view); */
float conv = aPresContext.GetTwipsToPixels();
((nsInput*)mContent)->SetClickPoint(NS_TO_INT_ROUND(conv * aEvent->point.x),
NS_TO_INT_ROUND(conv * aEvent->point.y));
MouseClicked(&aPresContext); MouseClicked(&aPresContext);
//return PR_FALSE; //return PR_FALSE;
} }
@@ -384,6 +385,7 @@ void nsInputFrame::GetStyleSize(nsIPresContext& aPresContext,
aSize.width = GetStyleDim(aPresContext, aMaxSize.width, aMaxSize.width, pos->mWidth); aSize.width = GetStyleDim(aPresContext, aMaxSize.width, aMaxSize.width, pos->mWidth);
aSize.height = GetStyleDim(aPresContext, aMaxSize.height, aMaxSize.width, pos->mHeight); aSize.height = GetStyleDim(aPresContext, aMaxSize.height, aMaxSize.width, pos->mHeight);
NS_RELEASE(input); NS_RELEASE(input);
} }

View File

@@ -75,7 +75,7 @@ struct nsInputDimensionSpec
* @see nsLeafFrame and its base classes for more info * @see nsLeafFrame and its base classes for more info
*/ */
class nsInputFrame : public nsLeafFrame { class nsInputFrame : public nsLeafFrame {
typedef nsLeafFrame super; typedef nsLeafFrame nsInputFrameSuper;
public: public:
/** /**
* Main constructor * Main constructor

View File

@@ -1,101 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsInputImage.h"
#include "nsInputFrame.h"
#include "nsIContent.h"
#include "prtypes.h"
#include "nsIFrame.h"
#include "nsISupports.h"
#include "nsIAtom.h"
#include "nsIPresContext.h"
#include "nsIHTMLContent.h"
#include "nsHTMLIIDs.h"
class nsInputImageFrame : public nsInputFrame {
public:
nsInputImageFrame(nsIContent* aContent,
PRInt32 aIndexInParent,
nsIFrame* aParentFrame);
virtual void PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView);
protected:
virtual ~nsInputImageFrame();
};
nsInputImageFrame::nsInputImageFrame(nsIContent* aContent,
PRInt32 aIndexInParent,
nsIFrame* aParentFrame)
: nsInputFrame(aContent, aIndexInParent, aParentFrame)
{
}
nsInputImageFrame::~nsInputImageFrame()
{
}
void
nsInputImageFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
{
}
//----------------------------------------------------------------------
// nsInputImage
nsInputImage::nsInputImage(nsIAtom* aTag, nsIFormManager* aManager)
: nsInput(aTag, aManager)
{
}
nsInputImage::~nsInputImage()
{
}
nsIFrame*
nsInputImage::CreateFrame(nsIPresContext* aPresContext,
PRInt32 aIndexInParent,
nsIFrame* aParentFrame)
{
nsIFrame* rv = new nsInputImageFrame(this, aIndexInParent, aParentFrame);
return rv;
}
void nsInputImage::GetType(nsString& aResult) const
{
aResult = "image";
}
nsresult
NS_NewHTMLInputImage(nsIHTMLContent** aInstancePtrResult,
nsIAtom* aTag, nsIFormManager* aManager)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null ptr");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
nsIHTMLContent* it = new nsInputImage(aTag, aManager);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;
}
return it->QueryInterface(kIHTMLContentIID, (void**) aInstancePtrResult);
}

View File

@@ -1,45 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsInputImage_h___
#define nsInputImage_h___
#include "nsInput.h"
class nsIAtom;
class nsString;
// this class definition will move to nsInputImage.cpp
class nsInputImage : public nsInput {
public:
typedef nsInput super;
nsInputImage (nsIAtom* aTag, nsIFormManager* aManager);
virtual nsIFrame* CreateFrame(nsIPresContext* aPresContext,
PRInt32 aIndexInParent,
nsIFrame* aParentFrame);
protected:
virtual ~nsInputImage();
virtual void GetType(nsString& aResult) const;
};
#endif

View File

@@ -209,7 +209,7 @@ void nsInputRadio::SetAttribute(nsIAtom* aAttribute,
mChecked = PR_TRUE; mChecked = PR_TRUE;
} }
else { else {
super::SetAttribute(aAttribute, aValue); nsInputRadioSuper::SetAttribute(aAttribute, aValue);
} }
} }
@@ -221,15 +221,15 @@ nsContentAttr nsInputRadio::GetAttribute(nsIAtom* aAttribute,
return GetCacheAttribute(mChecked, aResult, eHTMLUnit_Empty); return GetCacheAttribute(mChecked, aResult, eHTMLUnit_Empty);
} }
else { else {
return super::GetAttribute(aAttribute, aResult); return nsInputRadioSuper::GetAttribute(aAttribute, aResult);
} }
} }
PRBool PRBool
nsInputRadio::GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsInputRadio::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues) nsString* aValues, nsString* aNames)
{ {
if (aMaxNumValues <= 0) { if ((aMaxNumValues <= 0) || (nsnull == mName)) {
return PR_FALSE; return PR_FALSE;
} }
nsIRadioButton* radio = (nsIRadioButton *)GetWidget(); nsIRadioButton* radio = (nsIRadioButton *)GetWidget();
@@ -243,6 +243,7 @@ nsInputRadio::GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
} else { } else {
aValues[0] = *mValue; aValues[0] = *mValue;
} }
aNames[0] = *mName;
aNumValues = 1; aNumValues = 1;
return PR_TRUE; return PR_TRUE;

View File

@@ -29,7 +29,7 @@ class nsString;
class nsInputRadio : public nsInput class nsInputRadio : public nsInput
{ {
public: public:
typedef nsInput super; typedef nsInput nsInputRadioSuper;
nsInputRadio (nsIAtom* aTag, nsIFormManager* aManager); nsInputRadio (nsIAtom* aTag, nsIFormManager* aManager);
virtual nsIFrame* CreateFrame(nsIPresContext* aPresContext, virtual nsIFrame* CreateFrame(nsIPresContext* aPresContext,
@@ -48,8 +48,8 @@ public:
virtual PRInt32 GetMaxNumValues() { return 1; } virtual PRInt32 GetMaxNumValues() { return 1; }
virtual PRBool GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues); nsString* aValues, nsString* aNames);
virtual void Reset(); virtual void Reset();

View File

@@ -217,15 +217,17 @@ nsInputText::GetMaxNumValues()
} }
PRBool PRBool
nsInputText::GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsInputText::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues) nsString* aValues, nsString* aNames)
{ {
if (aMaxNumValues <= 0) { if ((aMaxNumValues <= 0) || (nsnull == mName)) {
return PR_FALSE; return PR_FALSE;
} }
nsITextWidget* text = (nsITextWidget *)GetWidget(); nsITextWidget* text = (nsITextWidget *)GetWidget();
nsString value; nsString value;
text->GetText(aValues[0], 0); // the last parm is not used text->GetText(aValues[0], 0); // the last parm is not used
aNames[0] = *mName;
aNumValues = 1; aNumValues = 1;
return PR_TRUE; return PR_TRUE;
@@ -268,7 +270,7 @@ void nsInputText::SetAttribute(nsIAtom* aAttribute, const nsString& aValue)
CacheAttribute(aValue, ATTR_NOTSET, mNumCols); CacheAttribute(aValue, ATTR_NOTSET, mNumCols);
} }
else { else {
super::SetAttribute(aAttribute, aValue); nsInputTextSuper::SetAttribute(aAttribute, aValue);
} }
} }
@@ -285,7 +287,7 @@ nsContentAttr nsInputText::GetAttribute(nsIAtom* aAttribute,
return GetCacheAttribute(mNumCols, aResult, eHTMLUnit_Integer); return GetCacheAttribute(mNumCols, aResult, eHTMLUnit_Integer);
} }
else { else {
return super::GetAttribute(aAttribute, aResult); return nsInputTextSuper::GetAttribute(aAttribute, aResult);
} }
} }

View File

@@ -35,7 +35,7 @@ enum nsInputTextType {
class nsInputText : public nsInput { class nsInputText : public nsInput {
public: public:
typedef nsInput super; typedef nsInput nsInputTextSuper;
nsInputText (nsIAtom* aTag, nsIFormManager* aManager, nsInputTextType aType); nsInputText (nsIAtom* aTag, nsIFormManager* aManager, nsInputTextType aType);
virtual nsIFrame* CreateFrame(nsIPresContext* aPresContext, virtual nsIFrame* CreateFrame(nsIPresContext* aPresContext,
@@ -51,8 +51,8 @@ public:
nsInputTextType GetTextType() const; nsInputTextType GetTextType() const;
virtual PRBool GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues); nsString* aValues, nsString* aNames);
virtual void Reset(); virtual void Reset();

View File

@@ -37,6 +37,7 @@
#include "nsIComboBox.h" #include "nsIComboBox.h"
#include "nsIListBox.h" #include "nsIListBox.h"
#include "nsInput.h" #include "nsInput.h"
#include "nsHTMLForms.h"
static NS_DEFINE_IID(kListWidgetIID, NS_ILISTWIDGET_IID); static NS_DEFINE_IID(kListWidgetIID, NS_ILISTWIDGET_IID);
static NS_DEFINE_IID(kComboBoxIID, NS_ICOMBOBOX_IID); static NS_DEFINE_IID(kComboBoxIID, NS_ICOMBOBOX_IID);
@@ -86,8 +87,8 @@ public:
virtual PRInt32 GetMaxNumValues(); virtual PRInt32 GetMaxNumValues();
virtual PRBool GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues); nsString* aValues, nsString* aNames);
PRBool IsMultiple() { return mMultiple; } PRBool IsMultiple() { return mMultiple; }
@@ -121,8 +122,8 @@ public:
virtual PRInt32 GetMaxNumValues(); virtual PRInt32 GetMaxNumValues();
virtual PRBool GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, virtual PRBool GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues); nsString* aValues, nsString* aNames);
PRBool GetText(nsString& aString) const; PRBool GetText(nsString& aString) const;
@@ -277,7 +278,6 @@ nsSelectFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
// printf("\n ** text = %s", text.ToNewCString()); // printf("\n ** text = %s", text.ToNewCString());
// list->AddItemAt(text, 1); // list->AddItemAt(text, 1);
// } // }
printf("\n item=%s\n", text.ToNewCString());
list->AddItemAt(text, i); list->AddItemAt(text, i);
} }
@@ -363,10 +363,10 @@ nsSelect::GetMaxNumValues()
} }
PRBool PRBool
nsSelect::GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsSelect::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues) nsString* aValues, nsString* aNames)
{ {
if (aMaxNumValues <= 0) { if ((aMaxNumValues <= 0) || (nsnull == mName)) {
NS_ASSERTION(0, "invalid max num values"); NS_ASSERTION(0, "invalid max num values");
return PR_FALSE; return PR_FALSE;
} }
@@ -379,7 +379,8 @@ nsSelect::GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
PRInt32 index = list->GetSelectedIndex(); PRInt32 index = list->GetSelectedIndex();
if (index >= 0) { if (index >= 0) {
nsOption* selected = (nsOption*)ChildAt(index); nsOption* selected = (nsOption*)ChildAt(index);
selected->GetValues(aMaxNumValues, aNumValues, aValues); selected->GetNamesValues(aMaxNumValues, aNumValues, aValues, aNames);
aNames[0] = *mName;
return PR_TRUE; return PR_TRUE;
} }
else { else {
@@ -400,7 +401,9 @@ nsSelect::GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
aNumValues = 0; aNumValues = 0;
for (int i = 0; i < numSelections; i++) { for (int i = 0; i < numSelections; i++) {
nsOption* selected = (nsOption*)ChildAt(selections[i]); nsOption* selected = (nsOption*)ChildAt(selections[i]);
selected->GetValues(aMaxNumValues - i, numValues, aValues + i); // options can only have 1 value selected->GetNamesValues(aMaxNumValues - i, numValues,
aValues + i, aNames + i); // options can only have 1 value
aNames[i] = *mName;
aNumValues += 1; aNumValues += 1;
} }
return PR_TRUE; return PR_TRUE;
@@ -429,9 +432,9 @@ nsSelect::Reset()
for (int i = 0; i < numChildren; i++) { for (int i = 0; i < numChildren; i++) {
nsOption* option = (nsOption*)ChildAt(i); // YYY this had better be an option nsOption* option = (nsOption*)ChildAt(i); // YYY this had better be an option
PRBool selAttr; PRInt32 selAttr;
((nsInput *)option)->GetAttribute(nsHTMLAtoms::selected, selAttr); ((nsInput *)option)->GetAttribute(nsHTMLAtoms::selected, selAttr);
if (selAttr) { if (ATTR_NOTSET != selAttr) {
list->SelectItem(i); list->SelectItem(i);
if (!mMultiple) { if (!mMultiple) {
break; break;
@@ -523,7 +526,8 @@ void nsOption::SetText(nsString& aString)
} }
PRBool PRBool
nsOption::GetValues(PRInt32 aMaxNumValues, PRInt32& aNumValues, nsString* aValues) nsOption::GetNamesValues(PRInt32 aMaxNumValues, PRInt32& aNumValues,
nsString* aValues, nsString* aNames)
{ {
if (aMaxNumValues <= 0) { if (aMaxNumValues <= 0) {
NS_ASSERTION(aMaxNumValues > 0, "invalid max num values"); NS_ASSERTION(aMaxNumValues > 0, "invalid max num values");

View File

@@ -18,8 +18,8 @@
<textarea name=a textarea rows=4 cols=20 value="a text area in need of some clearing"></textarea> <textarea name=a textarea rows=4 cols=20 value="a text area in need of some clearing"></textarea>
&nbsp;&nbsp; a checkbox: <input type=checkbox name=check1 checked> &nbsp;&nbsp; a checkbox: <input type=checkbox name=check1 checked>
&nbsp;&nbsp; radio buttons: &nbsp;&nbsp; radio buttons:
<input type=radio name=group1 checked> radio1 <input type=radio name=group1> radio1
<input type=radio name=group1> radio2 <input type=radio name=group1 checked> radio2
<BR> <BR>
<P>select/option hacks; why don't these line up</P> <P>select/option hacks; why don't these line up</P>
<input type=select1>&nbsp;&nbsp; <input type=select1>&nbsp;&nbsp;
@@ -28,6 +28,7 @@
<BR> <BR>
<input type=reset name=reset value="RESET"> <input type=reset name=reset value="RESET">
<input type=submit name=submit value="SUBMIT"> <input type=submit name=submit value="SUBMIT">
<input type=image src=raptor.jpg width=50 height=50 name=imageSubmit> an image submit. For now, click twice.
</form> </form>
</body> </body>