diff --git a/mozilla/layout/html/forms/src/nsFormFrame.cpp b/mozilla/layout/html/forms/src/nsFormFrame.cpp
index 40b19ea018c..175ee9fca6b 100644
--- a/mozilla/layout/html/forms/src/nsFormFrame.cpp
+++ b/mozilla/layout/html/forms/src/nsFormFrame.cpp
@@ -174,13 +174,15 @@ nsFormFrame::~nsFormFrame()
}
PRBool
-nsFormFrame::CanSubmit(nsFormControlFrame& aFrame)
+nsFormFrame::CanSubmit(nsIFormControlFrame *aFrame)
{
- if (mTextSubmitter == &aFrame) {
+ if (!aFrame)
+ return PR_FALSE;
+ if (mTextSubmitter == aFrame) {
return PR_TRUE;
}
PRInt32 type;
- aFrame.GetType(&type);
+ aFrame->GetType(&type);
if ((NS_FORM_INPUT_SUBMIT == type) || (NS_FORM_INPUT_IMAGE == type)) {
return PR_TRUE;
}
diff --git a/mozilla/layout/html/forms/src/nsFormFrame.h b/mozilla/layout/html/forms/src/nsFormFrame.h
index c080a925e3f..6c467530219 100644
--- a/mozilla/layout/html/forms/src/nsFormFrame.h
+++ b/mozilla/layout/html/forms/src/nsFormFrame.h
@@ -77,7 +77,7 @@ public:
void RemoveRadioControlFrame(nsIFormControlFrame * aFrame);
nsresult GetRadioInfo(nsIFormControlFrame* aFrame, nsString& aName, nsRadioControlGroup *& aGroup);
- PRBool CanSubmit(nsFormControlFrame& aFrame);
+ PRBool CanSubmit(nsIFormControlFrame *aFrame);
NS_IMETHOD GetMethod(PRInt32* aMethod);
NS_IMETHOD GetEnctype(PRInt32* aEnctype);
diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp
index 523fd3e375f..0a354f0391c 100644
--- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp
+++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame.cpp
@@ -1082,7 +1082,7 @@ nsGfxTextControlFrame::EnterPressed(nsIPresContext* aPresContext)
}
// Submit the form
- if (mFormFrame && mFormFrame->CanSubmit(*this)) {
+ if (mFormFrame && mFormFrame->CanSubmit(this)) {
nsIContent *formContent = nsnull;
nsEventStatus status = nsEventStatus_eIgnore;
diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp
index 7b60697e395..4bdd40f9133 100644
--- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp
+++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.cpp
@@ -74,6 +74,12 @@
#include "nsBoxLayoutState.h"
#include "nsINameSpaceManager.h"
#include "nsLayoutAtoms.h" //getframetype
+//for keylistener for "return" check
+#include "nsIDOMKeyListener.h"
+#include "nsIDOMKeyEvent.h"
+#include "nsIPrivateDOMEvent.h"
+#include "nsIDOMEventReceiver.h"
+
#define DEFAULT_COLUMN_WIDTH 20
@@ -95,7 +101,7 @@ class nsTextAreaKeyListener : public nsIDOMKeyListener, public nsSupportsWeakRef
{
public:
/** the default constructor
- */
+ */
nsTextAreaKeyListener();
/** the default destructor. virtual due to the possibility of derivation.
*/
@@ -192,7 +198,6 @@ nsTextAreaKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
return NS_OK;
}
PRUint32 keyCode;
- PRUint32 flags;
keyEvent->GetKeyCode(&keyCode);
if (nsIDOMKeyEvent::DOM_VK_RETURN==keyCode
|| nsIDOMKeyEvent::DOM_VK_ENTER==keyCode)
@@ -264,7 +269,7 @@ public:
//END INTERFACES
-
+ nsWeakPtr &GetPresShell(){return mPresShellWeak;}
private:
nsCOMPtr mFrameSelection;
nsCOMPtr mLimiter;
@@ -1223,6 +1228,12 @@ nsGfxTextControlFrame2::CreateAnonymousContent(nsIPresContext* aPresContext,
getter_AddRefs(frameSel));
//create selection controller
mTextSelImpl = new nsTextAreaSelectionImpl(frameSel,shell,content);
+ if (!mTextSelImpl)
+ return NS_ERROR_OUT_OF_MEMORY;
+ mTextKeyListener = new nsTextAreaKeyListener();
+ if (!mTextKeyListener)
+ return NS_ERROR_OUT_OF_MEMORY;
+ mTextKeyListener->SetFrame(this);
mSelCon = do_QueryInterface((nsISupports *)(nsISelectionController *)mTextSelImpl);//this will addref it once
mSelCon->SetDisplaySelection(nsISelectionController::SELECTION_ON);
//get the flags
@@ -2088,6 +2099,43 @@ nsGfxTextControlFrame2::DoesAttributeExist(nsIAtom *aAtt)
return rv;
}
+void
+nsGfxTextControlFrame2::SubmitAttempt()
+{
+ // Submit the form
+ if (mFormFrame && mTextSelImpl && mFormFrame->CanSubmit(this)) {
+ nsIContent *formContent = nsnull;
+
+ nsEventStatus status = nsEventStatus_eIgnore;
+
+ nsWeakPtr &shell = mTextSelImpl->GetPresShell();
+ nsCOMPtr presShell = do_QueryReferent(shell);
+ if (!presShell) return;
+ {
+ nsCOMPtr context;
+ if (NS_SUCCEEDED(presShell->GetPresContext(getter_AddRefs(context))) && context)
+ {
+ mFormFrame->GetContent(&formContent);
+ if (nsnull != formContent) {
+ nsEvent event;
+ event.eventStructType = NS_EVENT;
+ event.message = NS_FORM_SUBMIT;
+
+ formContent->HandleDOMEvent(context, &event, nsnull, NS_EVENT_FLAG_INIT, &status);
+ NS_RELEASE(formContent);
+ }
+
+ if (nsEventStatus_eConsumeNoDefault != status) {
+ mFormFrame->OnSubmit(context, this);
+ }
+ }
+ }
+ }
+}
+
+
+//======
+//privates
nsString *
nsGfxTextControlFrame2::GetCachedString()
@@ -2217,6 +2265,15 @@ nsGfxTextControlFrame2::SetInitialChildList(nsIPresContext* aPresContext,
first->QueryInterface(NS_GET_IID(nsIScrollableFrame), (void **) &scrollableFrame);
if (scrollableFrame)
scrollableFrame->SetScrollbarVisibility(aPresContext,PR_FALSE,PR_FALSE);
+ //register keylistener
+ nsCOMPtr erP;
+ if (NS_SUCCEEDED(mContent->QueryInterface(NS_GET_IID(nsIDOMEventReceiver), getter_AddRefs(erP))) && erP)
+ {
+ // register the event listeners with the DOM event reveiver
+ rv = erP->AddEventListenerByIID(mTextKeyListener, NS_GET_IID(nsIDOMKeyListener));
+ NS_ASSERTION(NS_SUCCEEDED(rv), "failed to register key listener");
+ }
+
}
while(first)
{
diff --git a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h
index 383cb2cd622..0a09a430785 100644
--- a/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h
+++ b/mozilla/layout/html/forms/src/nsGfxTextControlFrame2.h
@@ -43,7 +43,7 @@ class nsIHTMLContent;
class nsIEditor;
class nsISelectionController;
class nsTextAreaSelectionImpl;
-
+class nsTextAreaKeyListener;
@@ -138,6 +138,8 @@ public:
NS_IMETHOD GetText(nsString* aText, PRBool aInitialValue);
NS_DECL_ISUPPORTS_INHERITED
+public: //for methods who access nsGfxTextControlFrame2 directly
+ void SubmitAttempt();
protected:
nsString *GetCachedString();
virtual PRIntn GetSkipSides() const;
@@ -225,6 +227,7 @@ private:
PRBool mIsProcessing;
nsFormFrame *mFormFrame;
nsTextAreaSelectionImpl *mTextSelImpl;
+ nsTextAreaKeyListener *mTextKeyListener;
};
#endif
diff --git a/mozilla/layout/html/forms/src/nsNativeTextControlFrame.cpp b/mozilla/layout/html/forms/src/nsNativeTextControlFrame.cpp
index 2ec35ee4391..6e234d92405 100644
--- a/mozilla/layout/html/forms/src/nsNativeTextControlFrame.cpp
+++ b/mozilla/layout/html/forms/src/nsNativeTextControlFrame.cpp
@@ -89,7 +89,7 @@ nsNativeTextControlFrame::~nsNativeTextControlFrame()
void
nsNativeTextControlFrame::EnterPressed(nsIPresContext* aPresContext)
{
- if (mFormFrame && mFormFrame->CanSubmit(*this)) {
+ if (mFormFrame && mFormFrame->CanSubmit(this)) {
nsIContent *formContent = nsnull;
mFormFrame->GetContent(&formContent);