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
rv = NS_NewHTMLSelect(aInstancePtrResult, atom, mCurrentForm, 2);
}
else if (val.EqualsIgnoreCase("select3")) { // TEMP hack
rv = NS_NewHTMLSelect(aInstancePtrResult, atom, mCurrentForm, 3);
}
else {
rv = NS_NewHTMLInputSubmit(aInstancePtrResult, atom, mCurrentForm);
}

View File

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

View File

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

View File

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

View File

@ -44,6 +44,8 @@ public:
virtual const nsIID& GetIID();
virtual void MouseClicked(nsIPresContext* aPresContext);
virtual PRInt32 GetPadding() const;
NS_IMETHOD SetRect(const nsRect& aRect);
protected:
virtual ~nsInputCheckboxFrame();
@ -66,6 +68,13 @@ nsInputCheckboxFrame::~nsInputCheckboxFrame()
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&
nsInputCheckboxFrame::GetIID()
@ -81,6 +90,11 @@ nsInputCheckboxFrame::GetCID()
return kCheckboxCID;
}
PRInt32 nsInputCheckboxFrame::GetPadding() const
{
return GetDefaultPadding();
}
void
nsInputCheckboxFrame::GetDesiredSize(nsIPresContext* aPresContext,
const nsSize& aMaxSize,
@ -97,10 +111,11 @@ nsInputCheckboxFrame::GetDesiredSize(nsIPresContext* aPresContext,
}
float p2t = aPresContext->GetPixelsToTwips();
aDesiredLayoutSize.width = (int)(13 * p2t);
aDesiredLayoutSize.height = (int)(13 * p2t);
aDesiredWidgetSize.width = aDesiredLayoutSize.width;
aDesiredWidgetSize.height = aDesiredLayoutSize.height;
aDesiredWidgetSize.width = (int)(12 * p2t);
aDesiredWidgetSize.height = (int)(12 * p2t);
PRInt32 padding = GetPadding();
aDesiredLayoutSize.width = aDesiredWidgetSize.width + (2 * padding);
aDesiredLayoutSize.height = aDesiredWidgetSize.height;
}
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
// they could be blended, and bordered, and so on...
NS_METHOD
@ -84,6 +90,9 @@ nsInputFrame::Paint(nsIPresContext& aPresContext,
nsPoint offset;
nsIView *parent;
GetOffsetFromView(offset, parent);
//offset.x += padding + GetPadding(); // add back the padding if present
if (nsnull == parent) { // a problem
NS_ASSERTION(0, "parent view was null\n");
} else {
@ -195,8 +204,8 @@ nsInputFrame::ResizeReflow(nsIPresContext* aPresContext,
nsReflowMetrics layoutSize;
nsSize widgetSize;
GetDesiredSize(aPresContext, aMaxSize, layoutSize, widgetSize);
mCacheBounds.width = widgetSize.width; // YYY what about caching widget size?
mCacheBounds.height = widgetSize.height;
mCacheBounds.width = layoutSize.width; // YYY what about caching widget size?
mCacheBounds.height = layoutSize.height;
nsRect boundBox(0, 0, widgetSize.width, widgetSize.height);
@ -260,6 +269,11 @@ nsInputFrame::GetWidgetInitData()
return nsnull;
}
PRInt32 nsInputFrame::GetPadding() const
{
return 0;
}
void
nsInputFrame::PostCreateWidget(nsIPresContext* aPresContext, nsIView *aView)
{
@ -423,6 +437,7 @@ nsInputFrame::CalculateSize (nsIPresContext* aPresContext, nsInputFrame* aFrame,
PRBool& aHeightExplicit, PRInt32& aRowHeight)
{
PRInt32 charWidth = 0;
PRInt32 numRows = 1;
aWidthExplicit = PR_FALSE;
aHeightExplicit = PR_FALSE;
@ -487,6 +502,7 @@ nsInputFrame::CalculateSize (nsIPresContext* aPresContext, nsInputFrame* aFrame,
charWidth = GetTextSize(*aPresContext, aFrame, 1, textSize);
aBounds.height = textSize.height * rowAttr;
aRowHeight = textSize.height;
numRows = rowAttr;
}
else {
aBounds.height = aBounds.height * rowAttr;
@ -519,8 +535,7 @@ nsInputFrame::CalculateSize (nsIPresContext* aPresContext, nsInputFrame* aFrame,
NS_RELEASE(content);
// return number of rows that the calcuated size can support
return (int)(((float)aBounds.height) / ((float)aRowHeight));
return numRows;
}

View File

@ -73,6 +73,7 @@ struct nsInputDimensionSpec
* @see nsLeafFrame and its base classes for more info
*/
class nsInputFrame : public nsLeafFrame {
typedef nsLeafFrame super;
public:
/**
* Main constructor
@ -98,6 +99,8 @@ public:
nsGUIEvent* aEvent,
nsEventStatus& aEventStatus);
NS_IMETHOD SetRect(const nsRect& aRect);
virtual PRBool IsHidden();
/**
@ -132,6 +135,8 @@ public:
*/
virtual const nsIID& GetIID();
PRInt32 GetDefaultPadding() const { return 40; }
virtual PRInt32 GetPadding() const;
/**
* Get the widget associated with this frame
* @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 void MouseClicked(nsIPresContext* aPresContext);
virtual PRInt32 GetPadding() const;
NS_IMETHOD SetRect(const nsRect& aRect);
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&
nsInputRadioFrame::GetIID()
{
@ -90,10 +105,11 @@ nsInputRadioFrame::GetDesiredSize(nsIPresContext* aPresContext,
nsSize& aDesiredWidgetSize)
{
float p2t = aPresContext->GetPixelsToTwips();
aDesiredLayoutSize.width = (int)(12 * p2t);
aDesiredLayoutSize.height = (int)(12 * p2t);
aDesiredWidgetSize.width = aDesiredLayoutSize.width;
aDesiredWidgetSize.height = aDesiredLayoutSize.height;
aDesiredWidgetSize.width = (int)(12 * p2t);
aDesiredWidgetSize.height = (int)(12 * p2t);
PRInt32 padding = GetPadding();
aDesiredLayoutSize.width = aDesiredWidgetSize.width + (2 * padding);
aDesiredLayoutSize.height = aDesiredWidgetSize.height;
}
void

View File

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

View File

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

View File

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

View File

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