From 2785da72ed8326509f21eef534063056aa4ae971 Mon Sep 17 00:00:00 2001 From: "hidday%geocities.com" Date: Tue, 19 Mar 2002 13:46:33 +0000 Subject: [PATCH] Fixing bug 26528 "cloneNode() doesn't copy event handlers". r=brendan@mozilla.org sr=jst@netscape.com a=asa@mozilla.org This patch causes event handlers set as attributes on an element to be registered as event handlers on the cloned element as well. This patch also fixes bug 71937 "value of cloned input type=button is not displayed correctly". git-svn-id: svn://10.0.0.236/trunk@116855 18797224-902f-48f8-a5cc-f745e15eee43 --- .../html/content/src/nsGenericHTMLElement.cpp | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp index 288dc8648bf..715294d9a93 100644 --- a/mozilla/content/html/content/src/nsGenericHTMLElement.cpp +++ b/mozilla/content/html/content/src/nsGenericHTMLElement.cpp @@ -338,14 +338,28 @@ nsGenericHTMLElement::CopyInnerTo(nsIContent* aSrcContent, nsGenericHTMLElement* aDst, PRBool aDeep) { - nsresult result = NS_OK; + nsresult rv = NS_OK; - if (nsnull != mAttributes) { - result = mAttributes->Clone(&(aDst->mAttributes)); + if (mAttributes) { + PRInt32 index, count; + GetAttrCount(count); + nsCOMPtr name, prefix; + PRInt32 namespace_id; + nsAutoString value; - if (NS_SUCCEEDED(result)) { + for (index = 0; index < count; index++) { + rv = GetAttrNameAt(index, namespace_id, *getter_AddRefs(name), + *getter_AddRefs(prefix)); + NS_ENSURE_SUCCESS(rv, rv); + rv = GetAttr(namespace_id, name, value); + NS_ENSURE_SUCCESS(rv, rv); + rv = aDst->SetAttr(namespace_id, name, value, PR_FALSE); + NS_ENSURE_SUCCESS(rv, rv); + } + + if (NS_SUCCEEDED(rv)) { nsHTMLValue val; - nsresult rv = aDst->GetHTMLAttribute(nsHTMLAtoms::style, val); + rv = aDst->GetHTMLAttribute(nsHTMLAtoms::style, val); if (rv == NS_CONTENT_ATTR_HAS_VALUE && val.GetUnit() == eHTMLUnit_ISupports) { @@ -355,7 +369,7 @@ nsGenericHTMLElement::CopyInnerTo(nsIContent* aSrcContent, if (rule) { nsCOMPtr ruleClone; - result = rule->Clone(*getter_AddRefs(ruleClone)); + rv = rule->Clone(*getter_AddRefs(ruleClone)); val.SetISupportsValue(ruleClone); aDst->SetHTMLAttribute(nsHTMLAtoms::style, val, PR_FALSE); @@ -371,7 +385,7 @@ nsGenericHTMLElement::CopyInnerTo(nsIContent* aSrcContent, aDst->SetContentID(id); - return result; + return rv; } nsresult