Make so hitting return in text field submits form when there is a single text field and no submit

or there is a submit and the submit btn is to be included in the post data
Bug 99920 r=attinasi sr=kin a=pdt
This commit is contained in:
rods%netscape.com 2001-09-28 00:37:27 +00:00
Родитель 7e0457daae
Коммит 11ec02ccf2
3 изменённых файлов: 47 добавлений и 3 удалений

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

@ -1905,3 +1905,29 @@ nsFormFrame::StyleChangeReflow(nsIPresContext* aPresContext,
NS_RELEASE(reflowCmd);
}
}
// Bug 99920 - Finds the first submit button and how many text inputs there
// if there is only one text input or password then submission can take place
// or it can take place if it finds at least one submit button
nsIFrame*
nsFormFrame::GetFirstSubmitButtonAndTxtCnt(PRInt32& aInputTxtCnt)
{
nsIFrame* submitFrame = nsnull;
aInputTxtCnt = 0;
PRInt32 numControls = mFormControls.Count();
for (int i = 0; i < numControls; i++) {
nsIFormControlFrame* fcFrame = (nsIFormControlFrame*) mFormControls.ElementAt(i);
PRInt32 type;
fcFrame->GetType(&type);
if ((type == NS_FORM_INPUT_SUBMIT || type == NS_FORM_BUTTON_SUBMIT) &&
submitFrame == nsnull) {
NS_ASSERTION(fcFrame->QueryInterface(NS_GET_IID(nsIFrame), (void**)&submitFrame) == NS_OK,
"This has to be a frame!");
} else if (type == NS_FORM_INPUT_TEXT || type == NS_FORM_INPUT_PASSWORD) {
aInputTxtCnt++;
}
}
return submitFrame;
}

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

@ -103,6 +103,9 @@ public:
mState |= aFlags;
}
// helper function
nsIFrame* GetFirstSubmitButtonAndTxtCnt(PRInt32& aInputTxtCnt);
protected:
NS_IMETHOD_(nsrefcnt) AddRef(void);
NS_IMETHOD_(nsrefcnt) Release(void);

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

@ -3146,9 +3146,24 @@ nsGfxTextControlFrame2::SubmitAttempt()
nsCOMPtr<nsIPresContext> context;
if (NS_SUCCEEDED(presShell->GetPresContext(getter_AddRefs(context))) && context)
{
// do Submit & Frame processing of event
nsFormControlHelper::DoManualSubmitOrReset(context, presShell, mFormFrame,
this, PR_TRUE, PR_FALSE);
// We got here because somebody press <return> instead a text input
// Bug 99920 - Finds the first submit button and how many text inputs there
// if there is only one text input or password then submission can take place
// or it can take place if it finds at least one submit button
//
// Here we change the submitter frame to the submit button it found (if it found one)
// so the button gets included as part of the "post data"
nsIFrame* originFrame = this;
PRInt32 inputTxtCnt;
nsIFrame* submitBtn = mFormFrame->GetFirstSubmitButtonAndTxtCnt(inputTxtCnt);
if (submitBtn != nsnull) {
originFrame = submitBtn;
}
if (inputTxtCnt == 1 || submitBtn != nsnull) {
// do Submit & Frame processing of event
nsFormControlHelper::DoManualSubmitOrReset(context, presShell, mFormFrame,
originFrame, PR_TRUE, PR_FALSE);
}
}
}
}