Make elements deal better with a no-op SetDocument call. Bug 212262,

r=caillon, sr=jst
This commit is contained in:
bzbarsky%mit.edu 2003-07-12 18:01:58 +00:00
parent d042aa0b80
commit 679ed391c9
5 changed files with 37 additions and 23 deletions

View File

@ -230,16 +230,19 @@ NS_IMETHODIMP
nsHTMLAnchorElement::SetDocument(nsIDocument* aDocument, PRBool aDeep,
PRBool aCompileEventHandlers)
{
PRBool documentChanging = (aDocument != mDocument);
// Unregister the access key for the old document.
if (mDocument) {
if (documentChanging && mDocument) {
RegUnRegAccessKey(PR_FALSE);
}
nsresult rv = nsGenericHTMLContainerElement::SetDocument(aDocument, aDeep,
aCompileEventHandlers);
nsresult rv =
nsGenericHTMLContainerElement::SetDocument(aDocument, aDeep,
aCompileEventHandlers);
// Register the access key for the new document.
if (mDocument) {
if (documentChanging && mDocument) {
RegUnRegAccessKey(PR_TRUE);
}

View File

@ -272,8 +272,10 @@ NS_IMETHODIMP
nsHTMLAreaElement::SetDocument(nsIDocument* aDocument, PRBool aDeep,
PRBool aCompileEventHandlers)
{
PRBool documentChanging = (aDocument != mDocument);
// Unregister the access key for the old document.
if (mDocument) {
if (documentChanging && mDocument) {
RegUnRegAccessKey(PR_FALSE);
}
@ -281,7 +283,7 @@ nsHTMLAreaElement::SetDocument(nsIDocument* aDocument, PRBool aDeep,
aCompileEventHandlers);
// Register the access key for the new document.
if (mDocument) {
if (documentChanging && mDocument) {
RegUnRegAccessKey(PR_TRUE);
}

View File

@ -511,7 +511,7 @@ NS_IMETHODIMP
nsHTMLBodyElement::SetDocument(nsIDocument* aDocument, PRBool aDeep,
PRBool aCompileEventHandlers)
{
if (nsnull != mContentStyleRule) {
if (aDocument != mDocument && mContentStyleRule) {
mContentStyleRule->mPart = nsnull;
mContentStyleRule->mSheet = nsnull;

View File

@ -311,16 +311,19 @@ NS_IMETHODIMP
nsHTMLLabelElement::SetDocument(nsIDocument* aDocument, PRBool aDeep,
PRBool aCompileEventHandlers)
{
PRBool documentChanging = (aDocument != mDocument);
// Unregister the access key for the old document.
if (mDocument) {
if (documentChanging && mDocument) {
RegUnRegAccessKey(PR_FALSE);
}
nsresult rv = nsGenericHTMLContainerFormElement::SetDocument(aDocument,
aDeep, aCompileEventHandlers);
nsresult rv =
nsGenericHTMLContainerFormElement::SetDocument(aDocument, aDeep,
aCompileEventHandlers);
// Register the access key for the new document.
if (mDocument) {
if (documentChanging && mDocument) {
RegUnRegAccessKey(PR_TRUE);
}

View File

@ -138,24 +138,30 @@ NS_IMETHODIMP
nsHTMLMapElement::SetDocument(nsIDocument* aDocument, PRBool aDeep,
PRBool aCompileEventHandlers)
{
nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(mDocument));
nsresult rv;
PRBool documentChanging = (aDocument != mDocument);
if (documentChanging) {
nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(mDocument));
if (htmlDoc) {
htmlDoc->RemoveImageMap(this);
if (htmlDoc) {
htmlDoc->RemoveImageMap(this);
}
}
rv = nsGenericHTMLContainerElement::SetDocument(aDocument, aDeep,
aCompileEventHandlers);
nsresult rv = nsGenericHTMLContainerElement::SetDocument(aDocument, aDeep,
aCompileEventHandlers);
NS_ENSURE_SUCCESS(rv, rv);
if (documentChanging) {
// Since we changed the document, gotta re-QI
nsCOMPtr<nsIHTMLDocument> htmlDoc(do_QueryInterface(mDocument));
// Since we changed the document, gotta re-QI
htmlDoc = do_QueryInterface(mDocument);
if (NS_SUCCEEDED(rv) && htmlDoc) {
htmlDoc->AddImageMap(this);
if (htmlDoc) {
htmlDoc->AddImageMap(this);
}
}
return rv;
return NS_OK;
}
NS_IMETHODIMP