From 1644edb057b3cac0ddddba696e6aeb9c8514ee35 Mon Sep 17 00:00:00 2001 From: "jst%netscape.com" Date: Wed, 28 Jun 2000 22:50:06 +0000 Subject: [PATCH] Fixing nsbeta2+ bug 37051, always set the form associated with a form control as the parent of the form controls script object, this meks form controls always be in the scope of the form they're in. r=vidur@netscape.com --- .../html/content/src/nsGenericHTMLElement.cpp | 71 +++++++++++++++++++ .../html/content/src/nsGenericHTMLElement.h | 2 + .../html/content/src/nsGenericHTMLElement.cpp | 71 +++++++++++++++++++ .../html/content/src/nsGenericHTMLElement.h | 2 + 4 files changed, 146 insertions(+) diff --git a/content/html/content/src/nsGenericHTMLElement.cpp b/content/html/content/src/nsGenericHTMLElement.cpp index 1cdb1d6daa6..5af64ac285e 100644 --- a/content/html/content/src/nsGenericHTMLElement.cpp +++ b/content/html/content/src/nsGenericHTMLElement.cpp @@ -3550,6 +3550,41 @@ nsGenericHTMLContainerFormElement::~nsGenericHTMLContainerFormElement() // Do nothing } +nsresult +nsGenericHTMLContainerFormElement::GetScriptObject(nsIScriptContext* aContext, + void** aScriptObject) +{ + NS_ENSURE_ARG_POINTER(aScriptObject); + + if (mDOMSlots && mDOMSlots->mScriptObject) { + *aScriptObject = mDOMSlots->mScriptObject; + + return NS_OK; + } + + nsresult rv = nsGenericElement::GetScriptObject(aContext, aScriptObject); + NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_TRUE(*aScriptObject, NS_ERROR_FAILURE); + + // If there's a form associated with this control we set the form as parent + // object for this controls script object. + nsCOMPtr owner(do_QueryInterface(mForm)); + + if (owner) { + JSContext *ctx = (JSContext *)aContext->GetNativeContext(); + JSObject *parent = nsnull; + + rv = owner->GetScriptObject(aContext, (void **)&parent); + + if (NS_SUCCEEDED(rv) && parent) { + ::JS_SetParent(ctx, (JSObject *)*aScriptObject, parent); + } + } + + return rv; +} + + nsresult nsGenericHTMLContainerFormElement::SetForm(nsIForm* aForm) { @@ -3601,6 +3636,42 @@ nsGenericHTMLLeafFormElement::~nsGenericHTMLLeafFormElement() // Do nothing } + +nsresult +nsGenericHTMLLeafFormElement::GetScriptObject(nsIScriptContext* aContext, + void** aScriptObject) +{ + NS_ENSURE_ARG_POINTER(aScriptObject); + + if (mDOMSlots && mDOMSlots->mScriptObject) { + *aScriptObject = mDOMSlots->mScriptObject; + + return NS_OK; + } + + nsresult rv = nsGenericElement::GetScriptObject(aContext, aScriptObject); + NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_TRUE(*aScriptObject, NS_ERROR_FAILURE); + + nsCOMPtr owner(do_QueryInterface(mForm)); + + // If there's a form associated with this control we set the form as parent + // object for this controls script object. + if (owner) { + JSContext *ctx = (JSContext *)aContext->GetNativeContext(); + JSObject *parent = nsnull; + + rv = owner->GetScriptObject(aContext, (void **)&parent); + + if (NS_SUCCEEDED(rv) && parent) { + ::JS_SetParent(ctx, (JSObject *)*aScriptObject, parent); + } + } + + return rv; +} + + nsresult nsGenericHTMLLeafFormElement::SetForm(nsIForm* aForm) { diff --git a/content/html/content/src/nsGenericHTMLElement.h b/content/html/content/src/nsGenericHTMLElement.h index a2a916558a5..842b2cf585d 100644 --- a/content/html/content/src/nsGenericHTMLElement.h +++ b/content/html/content/src/nsGenericHTMLElement.h @@ -474,6 +474,7 @@ public: { return nsGenericHTMLElement::SetAttribute(aName, aValue); } + nsresult GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); nsIForm* mForm; }; @@ -494,6 +495,7 @@ public: { return nsGenericHTMLElement::SetAttribute(aName, aValue); } + nsresult GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); nsIForm* mForm; }; diff --git a/layout/html/content/src/nsGenericHTMLElement.cpp b/layout/html/content/src/nsGenericHTMLElement.cpp index 1cdb1d6daa6..5af64ac285e 100644 --- a/layout/html/content/src/nsGenericHTMLElement.cpp +++ b/layout/html/content/src/nsGenericHTMLElement.cpp @@ -3550,6 +3550,41 @@ nsGenericHTMLContainerFormElement::~nsGenericHTMLContainerFormElement() // Do nothing } +nsresult +nsGenericHTMLContainerFormElement::GetScriptObject(nsIScriptContext* aContext, + void** aScriptObject) +{ + NS_ENSURE_ARG_POINTER(aScriptObject); + + if (mDOMSlots && mDOMSlots->mScriptObject) { + *aScriptObject = mDOMSlots->mScriptObject; + + return NS_OK; + } + + nsresult rv = nsGenericElement::GetScriptObject(aContext, aScriptObject); + NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_TRUE(*aScriptObject, NS_ERROR_FAILURE); + + // If there's a form associated with this control we set the form as parent + // object for this controls script object. + nsCOMPtr owner(do_QueryInterface(mForm)); + + if (owner) { + JSContext *ctx = (JSContext *)aContext->GetNativeContext(); + JSObject *parent = nsnull; + + rv = owner->GetScriptObject(aContext, (void **)&parent); + + if (NS_SUCCEEDED(rv) && parent) { + ::JS_SetParent(ctx, (JSObject *)*aScriptObject, parent); + } + } + + return rv; +} + + nsresult nsGenericHTMLContainerFormElement::SetForm(nsIForm* aForm) { @@ -3601,6 +3636,42 @@ nsGenericHTMLLeafFormElement::~nsGenericHTMLLeafFormElement() // Do nothing } + +nsresult +nsGenericHTMLLeafFormElement::GetScriptObject(nsIScriptContext* aContext, + void** aScriptObject) +{ + NS_ENSURE_ARG_POINTER(aScriptObject); + + if (mDOMSlots && mDOMSlots->mScriptObject) { + *aScriptObject = mDOMSlots->mScriptObject; + + return NS_OK; + } + + nsresult rv = nsGenericElement::GetScriptObject(aContext, aScriptObject); + NS_ENSURE_SUCCESS(rv, rv); + NS_ENSURE_TRUE(*aScriptObject, NS_ERROR_FAILURE); + + nsCOMPtr owner(do_QueryInterface(mForm)); + + // If there's a form associated with this control we set the form as parent + // object for this controls script object. + if (owner) { + JSContext *ctx = (JSContext *)aContext->GetNativeContext(); + JSObject *parent = nsnull; + + rv = owner->GetScriptObject(aContext, (void **)&parent); + + if (NS_SUCCEEDED(rv) && parent) { + ::JS_SetParent(ctx, (JSObject *)*aScriptObject, parent); + } + } + + return rv; +} + + nsresult nsGenericHTMLLeafFormElement::SetForm(nsIForm* aForm) { diff --git a/layout/html/content/src/nsGenericHTMLElement.h b/layout/html/content/src/nsGenericHTMLElement.h index a2a916558a5..842b2cf585d 100644 --- a/layout/html/content/src/nsGenericHTMLElement.h +++ b/layout/html/content/src/nsGenericHTMLElement.h @@ -474,6 +474,7 @@ public: { return nsGenericHTMLElement::SetAttribute(aName, aValue); } + nsresult GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); nsIForm* mForm; }; @@ -494,6 +495,7 @@ public: { return nsGenericHTMLElement::SetAttribute(aName, aValue); } + nsresult GetScriptObject(nsIScriptContext* aContext, void** aScriptObject); nsIForm* mForm; };