mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-18 07:45:30 +00:00
form elements now accept a nsIFormFrame instead of the implementation as the parameter to allow others that inheirit from nsIFormFrame to call "CanSubmit". bug=34896 ender-lite, r=hyatt
This commit is contained in:
parent
5ef4ea6ef7
commit
446e89c8cb
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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<nsIFrameSelection> mFrameSelection;
|
||||
nsCOMPtr<nsIContent> 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<nsIPresShell> presShell = do_QueryReferent(shell);
|
||||
if (!presShell) return;
|
||||
{
|
||||
nsCOMPtr<nsIPresContext> 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<nsIDOMEventReceiver> 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)
|
||||
{
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user