Bug 567183 - Add DOMMetaAdded and DOMMetaRemoved events [r=jst]
authorMatt Brubeck <mbrubeck@mozilla.com>
Thu, 27 May 2010 15:19:01 -0400
changeset 42874 7c77b50bcd7d4f8c0e2d9cf7d49a405cabd58270
parent 42873 b0afde3559f9adf01c4ffad2e0c06d2d87b80359
child 42875 d9dc6ee9190cfb1aa48dcd4d8d7e5cbe65923a0d
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersjst
bugs567183
milestone1.9.3a5pre
Bug 567183 - Add DOMMetaAdded and DOMMetaRemoved events [r=jst]
content/html/content/src/nsHTMLMetaElement.cpp
--- a/content/html/content/src/nsHTMLMetaElement.cpp
+++ b/content/html/content/src/nsHTMLMetaElement.cpp
@@ -34,16 +34,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 #include "nsIDOMHTMLMetaElement.h"
 #include "nsIDOMEventTarget.h"
 #include "nsGenericHTMLElement.h"
 #include "nsGkAtoms.h"
 #include "nsStyleConsts.h"
+#include "nsPLDOMEvent.h"
 
 
 class nsHTMLMetaElement : public nsGenericHTMLElement,
                           public nsIDOMHTMLMetaElement
 {
 public:
   nsHTMLMetaElement(nsINodeInfo *aNodeInfo);
   virtual ~nsHTMLMetaElement();
@@ -58,16 +59,23 @@ public:
   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLElement
   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
 
   // nsIDOMHTMLMetaElement
   NS_DECL_NSIDOMHTMLMETAELEMENT
 
+  virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
+                              nsIContent* aBindingParent,
+                              PRBool aCompileEventHandlers);
+  virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
+                              PRBool aNullParent = PR_TRUE);
+  void CreateAndDispatchEvent(nsIDocument* aDoc, const nsAString& aEventName);
+
   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
 };
 
 
 NS_IMPL_NS_NEW_HTML_ELEMENT(Meta)
 
 
 nsHTMLMetaElement::nsHTMLMetaElement(nsINodeInfo *aNodeInfo)
@@ -96,8 +104,43 @@ NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLA
 
 NS_IMPL_ELEMENT_CLONE(nsHTMLMetaElement)
 
 
 NS_IMPL_STRING_ATTR(nsHTMLMetaElement, Content, content)
 NS_IMPL_STRING_ATTR(nsHTMLMetaElement, HttpEquiv, httpEquiv)
 NS_IMPL_STRING_ATTR(nsHTMLMetaElement, Name, name)
 NS_IMPL_STRING_ATTR(nsHTMLMetaElement, Scheme, scheme)
+
+nsresult
+nsHTMLMetaElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
+                              nsIContent* aBindingParent,
+                              PRBool aCompileEventHandlers)
+{
+  nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
+                                                 aBindingParent,
+                                                 aCompileEventHandlers);
+  NS_ENSURE_SUCCESS(rv, rv);
+  CreateAndDispatchEvent(aDocument, NS_LITERAL_STRING("DOMMetaAdded"));
+  return rv;
+}
+
+void
+nsHTMLMetaElement::UnbindFromTree(PRBool aDeep, PRBool aNullParent)
+{
+  nsCOMPtr<nsIDocument> oldDoc = GetCurrentDoc();
+  CreateAndDispatchEvent(oldDoc, NS_LITERAL_STRING("DOMMetaRemoved"));
+  nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
+}
+
+void
+nsHTMLMetaElement::CreateAndDispatchEvent(nsIDocument* aDoc,
+                                          const nsAString& aEventName)
+{
+  if (!aDoc)
+    return;
+
+  nsRefPtr<nsPLDOMEvent> event = new nsPLDOMEvent(this, aEventName, PR_TRUE,
+                                                  PR_TRUE);
+  if (event) {
+    event->PostDOMEvent();
+  }
+}