Bug 847586 - Paris binding for MutationEvent, r=Ms2ger
☠☠ backed out by 630d841daf46 ☠ ☠
authorOlli Pettay <Olli.Pettay@helsinki.fi>
Thu, 14 Mar 2013 13:31:54 +0200
changeset 124801 ea13caf078a735f3bd4904a56900df59cd6e8e18
parent 124800 6ab8497cb00fcf154e9d215b5a9af7477cec9cfd
child 124802 630d841daf46397e796c7fa30f6cee92a8f672ac
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersMs2ger
bugs847586
milestone22.0a1
Bug 847586 - Paris binding for MutationEvent, r=Ms2ger
content/events/src/nsDOMMutationEvent.cpp
content/events/src/nsDOMMutationEvent.h
dom/bindings/Bindings.conf
dom/webidl/MutationEvent.webidl
dom/webidl/WebIDL.mk
--- a/content/events/src/nsDOMMutationEvent.cpp
+++ b/content/events/src/nsDOMMutationEvent.cpp
@@ -1,28 +1,27 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsCOMPtr.h"
 #include "nsDOMClassInfoID.h"
 #include "nsDOMMutationEvent.h"
-#include "nsMutationEvent.h"
-
 
 class nsPresContext;
 
 nsDOMMutationEvent::nsDOMMutationEvent(mozilla::dom::EventTarget* aOwner,
                                        nsPresContext* aPresContext,
                                        nsMutationEvent* aEvent)
   : nsDOMEvent(aOwner, aPresContext,
                aEvent ? aEvent : new nsMutationEvent(false, 0))
 {
   mEventIsInternal = (aEvent == nullptr);
+  SetIsDOMBinding();
 }
 
 nsDOMMutationEvent::~nsDOMMutationEvent()
 {
   if (mEventIsInternal) {
     nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
     delete mutation;
     mEvent = nullptr;
@@ -37,20 +36,19 @@ NS_INTERFACE_MAP_BEGIN(nsDOMMutationEven
 NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
 
 NS_IMPL_ADDREF_INHERITED(nsDOMMutationEvent, nsDOMEvent)
 NS_IMPL_RELEASE_INHERITED(nsDOMMutationEvent, nsDOMEvent)
 
 NS_IMETHODIMP
 nsDOMMutationEvent::GetRelatedNode(nsIDOMNode** aRelatedNode)
 {
-  *aRelatedNode = nullptr;
-  nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
-  *aRelatedNode = mutation->mRelatedNode;
-  NS_IF_ADDREF(*aRelatedNode);
+  nsCOMPtr<nsINode> relatedNode = GetRelatedNode();
+  nsCOMPtr<nsIDOMNode> relatedDOMNode = relatedNode ? relatedNode->AsDOMNode() : nullptr;
+  relatedDOMNode.forget(aRelatedNode);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMMutationEvent::GetPrevValue(nsAString& aPrevValue)
 {
   nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
   if (mutation->mPrevAttrValue)
@@ -74,20 +72,17 @@ nsDOMMutationEvent::GetAttrName(nsAStrin
   if (mutation->mAttrName)
       mutation->mAttrName->ToString(aAttrName);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMMutationEvent::GetAttrChange(uint16_t* aAttrChange)
 {
-  *aAttrChange = 0;
-  nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
-  if (mutation->mAttrChange)
-      *aAttrChange = mutation->mAttrChange;
+  *aAttrChange = AttrChange();
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsDOMMutationEvent::InitMutationEvent(const nsAString& aTypeArg, bool aCanBubbleArg, bool aCancelableArg, nsIDOMNode* aRelatedNodeArg, const nsAString& aPrevValueArg, const nsAString& aNewValueArg, const nsAString& aAttrNameArg, uint16_t aAttrChangeArg)
 {
   nsresult rv = nsDOMEvent::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
   NS_ENSURE_SUCCESS(rv, rv);
--- a/content/events/src/nsDOMMutationEvent.h
+++ b/content/events/src/nsDOMMutationEvent.h
@@ -3,27 +3,64 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef nsDOMMutationEvent_h__
 #define nsDOMMutationEvent_h__
 
 #include "nsIDOMMutationEvent.h"
 #include "nsDOMEvent.h"
+#include "nsMutationEvent.h"
+#include "mozilla/dom/MutationEventBinding.h"
 
 class nsDOMMutationEvent : public nsDOMEvent,
                            public nsIDOMMutationEvent
 {
 public:
   nsDOMMutationEvent(mozilla::dom::EventTarget* aOwner,
                      nsPresContext* aPresContext, nsMutationEvent* aEvent);
 
   virtual ~nsDOMMutationEvent();
-                     
+
   NS_DECL_ISUPPORTS_INHERITED
 
   NS_DECL_NSIDOMMUTATIONEVENT
 
   // Forward to base class
   NS_FORWARD_TO_NSDOMEVENT
+
+  virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope)
+  {
+    return mozilla::dom::MutationEventBinding::Wrap(aCx, aScope, this);
+  }
+
+  // xpidl implementation
+  // GetPrevValue(nsAString& aPrevValue);
+  // GetNewValue(nsAString& aNewValue);
+  // GetAttrName(nsAString& aAttrName);
+
+  already_AddRefed<nsINode> GetRelatedNode()
+  {
+    nsCOMPtr<nsINode> n =
+      do_QueryInterface(static_cast<nsMutationEvent*>(mEvent)->mRelatedNode);
+    return n.forget();
+  }
+
+  uint16_t AttrChange()
+  {
+    return static_cast<nsMutationEvent*>(mEvent)->mAttrChange;
+  }
+
+  void InitMutationEvent(const nsAString& aType,
+                         bool& aCanBubble, bool& aCancelable,
+                         nsINode* aRelatedNode,
+                         const nsAString& aPrevValue,
+                         const nsAString& aNewValue,
+                         const nsAString& aAttrName,
+                         uint16_t& aAttrChange, mozilla::ErrorResult& aRv)
+  {
+    aRv = InitMutationEvent(aType, aCanBubble, aCancelable,
+                            aRelatedNode ? aRelatedNode->AsDOMNode() : nullptr,
+                            aPrevValue, aNewValue, aAttrName, aAttrChange);
+  }
 };
 
 #endif // nsDOMMutationEvent_h__
--- a/dom/bindings/Bindings.conf
+++ b/dom/bindings/Bindings.conf
@@ -513,16 +513,19 @@ DOMInterfaces = {
 {
     'nativeType': 'nsIChannel',
     'notflattened': True
 },
 {
     'workers': True,
 }],
 
+'MutationEvent': {
+    'nativeType': 'nsDOMMutationEvent',
+},
 
 'MutationObserver': {
     'nativeType': 'nsDOMMutationObserver',
 },
 
 'MutationRecord': {
     'nativeType': 'nsDOMMutationRecord',
     'headerFile': 'nsDOMMutationObserver.h',
new file mode 100644
--- /dev/null
+++ b/dom/webidl/MutationEvent.webidl
@@ -0,0 +1,33 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * The origin of this IDL file is
+ * http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html
+ *
+ * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
+ * liability, trademark and document use rules apply.
+ */
+interface MutationEvent : Event
+{
+  const unsigned short MODIFICATION = 1;
+  const unsigned short ADDITION     = 2;
+  const unsigned short REMOVAL      = 3;
+
+  readonly attribute Node?          relatedNode;
+  readonly attribute DOMString      prevValue;
+  readonly attribute DOMString      newValue;
+  readonly attribute DOMString      attrName;
+  readonly attribute unsigned short attrChange;
+
+  [Throws]
+  void initMutationEvent(DOMString type,
+                         boolean canBubble,
+                         boolean cancelable,
+                         Node? relatedNode,
+                         DOMString prevValue,
+                         DOMString newValue,
+                         DOMString attrName,
+                         unsigned short attrChange);
+};
--- a/dom/webidl/WebIDL.mk
+++ b/dom/webidl/WebIDL.mk
@@ -120,16 +120,17 @@ webidl_files = \
   HTMLUListElement.webidl \
   IDBVersionChangeEvent.webidl \
   ImageData.webidl \
   LinkStyle.webidl \
   LocalMediaStream.webidl \
   Location.webidl \
   MediaStream.webidl \
   MessageEvent.webidl \
+  MutationEvent.webidl \
   MutationObserver.webidl \
   Node.webidl \
   NodeFilter.webidl \
   NodeIterator.webidl \
   NodeList.webidl \
   PaintRequest.webidl \
   PaintRequestList.webidl \
   PannerNode.webidl \