fix submit crash in nsWindow; more form control functionality

This commit is contained in:
karnaze 1998-04-28 18:59:38 +00:00
parent edc67259c4
commit 0df7874f85
12 changed files with 109 additions and 55 deletions

View File

@ -1125,6 +1125,9 @@ nsresult HTMLContentSink::ProcessINPUTTag(nsIHTMLContent** aInstancePtrResult,
else if (val.EqualsIgnoreCase("select2")) { // TEMP hack else if (val.EqualsIgnoreCase("select2")) { // TEMP hack
rv = NS_NewHTMLSelect(aInstancePtrResult, atom, mCurrentForm, 2); rv = NS_NewHTMLSelect(aInstancePtrResult, atom, mCurrentForm, 2);
} }
else if (val.EqualsIgnoreCase("select3")) { // TEMP hack
rv = NS_NewHTMLSelect(aInstancePtrResult, atom, mCurrentForm, 3);
}
else { else {
rv = NS_NewHTMLInputSubmit(aInstancePtrResult, atom, mCurrentForm); rv = NS_NewHTMLInputSubmit(aInstancePtrResult, atom, mCurrentForm);
} }

View File

@ -1125,6 +1125,9 @@ nsresult HTMLContentSink::ProcessINPUTTag(nsIHTMLContent** aInstancePtrResult,
else if (val.EqualsIgnoreCase("select2")) { // TEMP hack else if (val.EqualsIgnoreCase("select2")) { // TEMP hack
rv = NS_NewHTMLSelect(aInstancePtrResult, atom, mCurrentForm, 2); rv = NS_NewHTMLSelect(aInstancePtrResult, atom, mCurrentForm, 2);
} }
else if (val.EqualsIgnoreCase("select3")) { // TEMP hack
rv = NS_NewHTMLSelect(aInstancePtrResult, atom, mCurrentForm, 3);
}
else { else {
rv = NS_NewHTMLInputSubmit(aInstancePtrResult, atom, mCurrentForm); rv = NS_NewHTMLInputSubmit(aInstancePtrResult, atom, mCurrentForm);
} }

View File

@ -267,7 +267,7 @@ nsForm::OnSubmit(nsIPresContext* aPresContext, nsIFrame* aFrame)
GetAttribute("action", href); GetAttribute("action", href);
nsString data(href); // this could be more efficient, by allocating a larger buffer nsString data(href); // this could be more efficient, by allocating a larger buffer
data += '$'; data += '?';
PRBool firstTime = PR_TRUE; PRBool firstTime = PR_TRUE;
PRInt32 numChildren = mChildren.Count(); PRInt32 numChildren = mChildren.Count();
@ -302,12 +302,7 @@ nsForm::OnSubmit(nsIPresContext* aPresContext, nsIFrame* aFrame)
} }
} }
char* out = data.ToNewCString(); // make the url string
printf("\nsubmit data =\n%s\n", out);
delete [] out;
#ifdef FIX_THIS
// cause the url
nsILinkHandler* handler; nsILinkHandler* handler;
if (NS_OK == aPresContext->GetLinkHandler(&handler)) { if (NS_OK == aPresContext->GetLinkHandler(&handler)) {
// Resolve url to an absolute url // Resolve url to an absolute url
@ -326,14 +321,13 @@ nsForm::OnSubmit(nsIPresContext* aPresContext, nsIFrame* aFrame)
nsAutoString absURLSpec; nsAutoString absURLSpec;
nsAutoString base; nsAutoString base;
nsresult rv = NS_MakeAbsoluteURL(docURL, base, href, absURLSpec); nsresult rv = NS_MakeAbsoluteURL(docURL, base, data, absURLSpec);
NS_IF_RELEASE(docURL); NS_IF_RELEASE(docURL);
// Now pass on absolute url to the click handler // Now pass on absolute url to the click handler
handler->OnLinkClick(aFrame, absURLSpec, target); handler->OnLinkClick(aFrame, absURLSpec, target);
printf("\nurl=%s\n", absURLSpec.ToNewCString());
} }
#endif
} }
void void

View File

@ -22,9 +22,9 @@
class nsIAtom; class nsIAtom;
class nsIFormManager; class nsIFormManager;
// fix these // fix this
#define CSS_NOTSET 0 #define CSS_NOTSET -1
#define ATTR_NOTSET 0 #define ATTR_NOTSET -1
// Form and Form Controls // Form and Form Controls

View File

@ -44,6 +44,8 @@ public:
virtual const nsIID& GetIID(); virtual const nsIID& GetIID();
virtual void MouseClicked(nsIPresContext* aPresContext); virtual void MouseClicked(nsIPresContext* aPresContext);
virtual PRInt32 GetPadding() const;
NS_IMETHOD SetRect(const nsRect& aRect);
protected: protected:
virtual ~nsInputCheckboxFrame(); virtual ~nsInputCheckboxFrame();
@ -66,6 +68,13 @@ nsInputCheckboxFrame::~nsInputCheckboxFrame()
mCacheState = PR_FALSE; mCacheState = PR_FALSE;
} }
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& const nsIID&
nsInputCheckboxFrame::GetIID() nsInputCheckboxFrame::GetIID()
@ -81,6 +90,11 @@ nsInputCheckboxFrame::GetCID()
return kCheckboxCID; return kCheckboxCID;
} }
PRInt32 nsInputCheckboxFrame::GetPadding() const
{
return GetDefaultPadding();
}
void void
nsInputCheckboxFrame::GetDesiredSize(nsIPresContext* aPresContext, nsInputCheckboxFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsSize& aMaxSize, const nsSize& aMaxSize,
@ -97,10 +111,11 @@ nsInputCheckboxFrame::GetDesiredSize(nsIPresContext* aPresContext,
} }
float p2t = aPresContext->GetPixelsToTwips(); float p2t = aPresContext->GetPixelsToTwips();
aDesiredLayoutSize.width = (int)(13 * p2t); aDesiredWidgetSize.width = (int)(12 * p2t);
aDesiredLayoutSize.height = (int)(13 * p2t); aDesiredWidgetSize.height = (int)(12 * p2t);
aDesiredWidgetSize.width = aDesiredLayoutSize.width; PRInt32 padding = GetPadding();
aDesiredWidgetSize.height = aDesiredLayoutSize.height; aDesiredLayoutSize.width = aDesiredWidgetSize.width + (2 * padding);
aDesiredLayoutSize.height = aDesiredWidgetSize.height;
} }
void void

View File

@ -72,6 +72,12 @@ nsInputFrame::~nsInputFrame()
{ {
} }
NS_METHOD nsInputFrame::SetRect(const nsRect& aRect)
{
return super::SetRect(aRect);
}
// XXX it would be cool if form element used our rendering sw, then // XXX it would be cool if form element used our rendering sw, then
// they could be blended, and bordered, and so on... // they could be blended, and bordered, and so on...
NS_METHOD NS_METHOD
@ -84,6 +90,9 @@ nsInputFrame::Paint(nsIPresContext& aPresContext,
nsPoint offset; nsPoint offset;
nsIView *parent; nsIView *parent;
GetOffsetFromView(offset, parent); GetOffsetFromView(offset, parent);
//offset.x += padding + GetPadding(); // add back the padding if present
if (nsnull == parent) { // a problem if (nsnull == parent) { // a problem
NS_ASSERTION(0, "parent view was null\n"); NS_ASSERTION(0, "parent view was null\n");
} else { } else {
@ -195,8 +204,8 @@ nsInputFrame::ResizeReflow(nsIPresContext* aPresContext,
nsReflowMetrics layoutSize; nsReflowMetrics layoutSize;
nsSize widgetSize; nsSize widgetSize;
GetDesiredSize(aPresContext, aMaxSize, layoutSize, widgetSize); GetDesiredSize(aPresContext, aMaxSize, layoutSize, widgetSize);
mCacheBounds.width = widgetSize.width; // YYY what about caching widget size? mCacheBounds.width = layoutSize.width; // YYY what about caching widget size?
mCacheBounds.height = widgetSize.height; mCacheBounds.height = layoutSize.height;
nsRect boundBox(0, 0, widgetSize.width, widgetSize.height); nsRect boundBox(0, 0, widgetSize.width, widgetSize.height);
@ -260,6 +269,11 @@ nsInputFrame::GetWidgetInitData()
return nsnull; return nsnull;
} }
PRInt32 nsInputFrame::GetPadding() const
{
return 0;
}
void void
nsInputFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView) nsInputFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
{ {
@ -423,6 +437,7 @@ nsInputFrame::CalculateSize (nsIPresContext* aPresContext, nsInputFrame* aFrame,
PRBool& aHeightExplicit, PRInt32& aRowHeight) PRBool& aHeightExplicit, PRInt32& aRowHeight)
{ {
PRInt32 charWidth = 0; PRInt32 charWidth = 0;
PRInt32 numRows = 1;
aWidthExplicit = PR_FALSE; aWidthExplicit = PR_FALSE;
aHeightExplicit = PR_FALSE; aHeightExplicit = PR_FALSE;
@ -487,6 +502,7 @@ nsInputFrame::CalculateSize (nsIPresContext* aPresContext, nsInputFrame* aFrame,
charWidth = GetTextSize(*aPresContext, aFrame, 1, textSize); charWidth = GetTextSize(*aPresContext, aFrame, 1, textSize);
aBounds.height = textSize.height * rowAttr; aBounds.height = textSize.height * rowAttr;
aRowHeight = textSize.height; aRowHeight = textSize.height;
numRows = rowAttr;
} }
else { else {
aBounds.height = aBounds.height * rowAttr; aBounds.height = aBounds.height * rowAttr;
@ -519,8 +535,7 @@ nsInputFrame::CalculateSize (nsIPresContext* aPresContext, nsInputFrame* aFrame,
NS_RELEASE(content); NS_RELEASE(content);
// return number of rows that the calcuated size can support return numRows;
return (int)(((float)aBounds.height) / ((float)aRowHeight));
} }

View File

@ -73,6 +73,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;
public: public:
/** /**
* Main constructor * Main constructor
@ -98,6 +99,8 @@ public:
nsGUIEvent* aEvent, nsGUIEvent* aEvent,
nsEventStatus& aEventStatus); nsEventStatus& aEventStatus);
NS_IMETHOD SetRect(const nsRect& aRect);
virtual PRBool IsHidden(); virtual PRBool IsHidden();
/** /**
@ -132,6 +135,8 @@ public:
*/ */
virtual const nsIID& GetIID(); virtual const nsIID& GetIID();
PRInt32 GetDefaultPadding() const { return 40; }
virtual PRInt32 GetPadding() const;
/** /**
* Get the widget associated with this frame * Get the widget associated with this frame
* @param aView the view associated with the frame. It is a convience parm. * @param aView the view associated with the frame. It is a convience parm.

View File

@ -46,6 +46,8 @@ public:
virtual const nsIID& GetIID(); virtual const nsIID& GetIID();
virtual void MouseClicked(nsIPresContext* aPresContext); virtual void MouseClicked(nsIPresContext* aPresContext);
virtual PRInt32 GetPadding() const;
NS_IMETHOD SetRect(const nsRect& aRect);
protected: protected:
@ -69,6 +71,19 @@ 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& const nsIID&
nsInputRadioFrame::GetIID() nsInputRadioFrame::GetIID()
{ {
@ -90,10 +105,11 @@ nsInputRadioFrame::GetDesiredSize(nsIPresContext* aPresContext,
nsSize& aDesiredWidgetSize) nsSize& aDesiredWidgetSize)
{ {
float p2t = aPresContext->GetPixelsToTwips(); float p2t = aPresContext->GetPixelsToTwips();
aDesiredLayoutSize.width = (int)(12 * p2t); aDesiredWidgetSize.width = (int)(12 * p2t);
aDesiredLayoutSize.height = (int)(12 * p2t); aDesiredWidgetSize.height = (int)(12 * p2t);
aDesiredWidgetSize.width = aDesiredLayoutSize.width; PRInt32 padding = GetPadding();
aDesiredWidgetSize.height = aDesiredLayoutSize.height; aDesiredLayoutSize.width = aDesiredWidgetSize.width + (2 * padding);
aDesiredLayoutSize.height = aDesiredWidgetSize.height;
} }
void void

View File

@ -227,7 +227,8 @@ nsSelectFrame::GetDesiredSize(nsIPresContext* aPresContext,
aDesiredWidgetSize.width = aDesiredLayoutSize.width; aDesiredWidgetSize.width = aDesiredLayoutSize.width;
aDesiredWidgetSize.height = aDesiredWidgetSize.height =
(isCombo && !heightExplicit) ? rowHeight + 100 : aDesiredLayoutSize.height; (isCombo && !heightExplicit) ? aDesiredLayoutSize.height + (rowHeight * numChildren) + 100
: aDesiredLayoutSize.height;
NS_RELEASE(select); NS_RELEASE(select);
@ -269,13 +270,12 @@ nsSelectFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
if (PR_TRUE != option->GetText(text)) { if (PR_TRUE != option->GetText(text)) {
text = " "; text = " ";
} }
if (isCombo) { // if (isCombo) {
printf("\n ** text = %s", text.ToNewCString()); // printf("\n ** text = %s", text.ToNewCString());
list->AddItemAt(text, 1); // list->AddItemAt(text, 1);
} // }
else { printf("\n item=%s\n", text.ToNewCString());
list->AddItemAt(text, i); list->AddItemAt(text, i);
}
} }
NS_RELEASE(view); NS_RELEASE(view);
@ -598,13 +598,16 @@ void HACK(nsSelect* aSel, PRInt32 aIndex)
if (aIndex == 1) { if (aIndex == 1) {
nsString size("2"); nsString size("2");
aSel->SetAttribute(sizeAttr, size); aSel->SetAttribute(sizeAttr, size);
} else { } else if (aIndex == 2) {
nsString size("4"); nsString size("4");
aSel->SetAttribute(sizeAttr, size); aSel->SetAttribute(sizeAttr, size);
nsIAtom* multAttr = NS_NewAtom("MULTIPLE"); nsIAtom* multAttr = NS_NewAtom("MULTIPLE");
nsString mult("1"); nsString mult("1");
aSel->SetAttribute(multAttr, mult); aSel->SetAttribute(multAttr, mult);
numOpt = 8; numOpt = 8;
} else {
nsString size("1");
aSel->SetAttribute(sizeAttr, size);
} }
for (int i = 0; i < numOpt; i++) { for (int i = 0; i < numOpt; i++) {

View File

@ -2,36 +2,33 @@
<title>Example 8</title> <title>Example 8</title>
<body> <body>
<H1>Example 8: Form Controls</H1> <H1>Example 8: Forms</H1>
<form action=foo method=get>
<BR> <BR>
a text field <FORM METHOD="GET" ACTION="http://search.yahoo.com/bin/search" NAME="searchform">
<BR> <P> hey yahoo </P>
<input type=text name=text value="some text"> <INPUT TYPE="TEXT" NAME="p" SIZE=15 MAXLENGTH=80>
<BR> <INPUT TYPE="submit" VALUE="Search">
a text area <INPUT TYPE="HIDDEN" NAME="a" VALUE="n">
<BR> &nbsp;&nbsp;password:&nbsp;&nbsp;<INPUT TYPE="PASSWORD">
<textarea name=textarea rows=5 cols=20 value="text area"></textarea> </FORM>
<BR>
a checkbox: <input type=checkbox name=check1 checked><BR>
<BR>
<P> radio buttons</P>
<BR> <BR>
<FORM METHOD="GET" ACTION="http://www.mcp.com/cgi-bin/post-query" NAME="echo">
<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; radio buttons:
<input type=radio name=group1 checked> radio1 <input type=radio name=group1 checked> radio1
<input type=radio name=group1> radio2 <input type=radio name=group1> radio2
<BR> <BR>
select/option hack1 <P>select/option hacks; why don't these line up</P>
<input type=select1> <input type=select1>&nbsp;&nbsp;
<input type=select2>&nbsp;&nbsp;
<input type=select3>
<BR> <BR>
select/option hack2
<input type=select2>
<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">
</form> </form>
</body> </body>
</html> </html>

View File

@ -169,6 +169,7 @@ nsWindow::nsWindow(nsISupports *aOuter) : nsObject(aOuter)
mIsShiftDown = PR_FALSE; mIsShiftDown = PR_FALSE;
mIsControlDown = PR_FALSE; mIsControlDown = PR_FALSE;
mIsAltDown = PR_FALSE; mIsAltDown = PR_FALSE;
mIsDestroying = PR_FALSE;
} }
@ -179,6 +180,7 @@ nsWindow::nsWindow(nsISupports *aOuter) : nsObject(aOuter)
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
nsWindow::~nsWindow() nsWindow::~nsWindow()
{ {
mIsDestroying = PR_TRUE;
Destroy(); Destroy();
} }
@ -1437,7 +1439,7 @@ PRBool nsWindow::DispatchMouseEvent(PRUint32 aEventType)
if (rect.Contains(event.point.x, event.point.y)) { if (rect.Contains(event.point.x, event.point.y)) {
if (mCurrentWindow == NULL || mCurrentWindow != this) { if (mCurrentWindow == NULL || mCurrentWindow != this) {
if (nsnull != mCurrentWindow) { if ((nsnull != mCurrentWindow) && (!mCurrentWindow->mIsDestroying)) {
mCurrentWindow->DispatchMouseEvent(NS_MOUSE_EXIT); mCurrentWindow->DispatchMouseEvent(NS_MOUSE_EXIT);
} }
mCurrentWindow = this; mCurrentWindow = this;

View File

@ -171,6 +171,7 @@ protected:
PRBool mIsShiftDown; PRBool mIsShiftDown;
PRBool mIsControlDown; PRBool mIsControlDown;
PRBool mIsAltDown; PRBool mIsAltDown;
PRBool mIsDestroying;
// keep the list of children // keep the list of children
class Enumerator : public nsIEnumerator { class Enumerator : public nsIEnumerator {