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

This commit is contained in:
jst%netscape.com 2000-06-28 22:50:06 +00:00
Родитель 5217801971
Коммит 1644edb057
4 изменённых файлов: 146 добавлений и 0 удалений

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

@ -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<nsIScriptObjectOwner> 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<nsIScriptObjectOwner> 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)
{

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

@ -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;
};

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

@ -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<nsIScriptObjectOwner> 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<nsIScriptObjectOwner> 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)
{

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

@ -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;
};