1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4  * License, v. 2.0. If a copy of the MPL was not distributed with this
5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 
7 #ifndef mozilla_MutationEvent_h__
8 #define mozilla_MutationEvent_h__
9 
10 #include "mozilla/BasicEvents.h"
11 #include "nsCOMPtr.h"
12 #include "nsIAtom.h"
13 #include "nsIDOMNode.h"
14 
15 namespace mozilla {
16 
17 class InternalMutationEvent : public WidgetEvent
18 {
19 public:
AsMutationEvent()20   virtual InternalMutationEvent* AsMutationEvent() override { return this; }
21 
InternalMutationEvent(bool aIsTrusted,EventMessage aMessage)22   InternalMutationEvent(bool aIsTrusted, EventMessage aMessage)
23     : WidgetEvent(aIsTrusted, aMessage, eMutationEventClass)
24     , mAttrChange(0)
25   {
26     mFlags.mCancelable = false;
27   }
28 
Duplicate()29   virtual WidgetEvent* Duplicate() const override
30   {
31     MOZ_ASSERT(mClass == eMutationEventClass,
32                "Duplicate() must be overridden by sub class");
33     InternalMutationEvent* result = new InternalMutationEvent(false, mMessage);
34     result->AssignMutationEventData(*this, true);
35     result->mFlags = mFlags;
36     return result;
37   }
38 
39   nsCOMPtr<nsIDOMNode> mRelatedNode;
40   nsCOMPtr<nsIAtom>    mAttrName;
41   nsCOMPtr<nsIAtom>    mPrevAttrValue;
42   nsCOMPtr<nsIAtom>    mNewAttrValue;
43   unsigned short       mAttrChange;
44 
AssignMutationEventData(const InternalMutationEvent & aEvent,bool aCopyTargets)45   void AssignMutationEventData(const InternalMutationEvent& aEvent,
46                                bool aCopyTargets)
47   {
48     AssignEventData(aEvent, aCopyTargets);
49 
50     mRelatedNode = aEvent.mRelatedNode;
51     mAttrName = aEvent.mAttrName;
52     mPrevAttrValue = aEvent.mPrevAttrValue;
53     mNewAttrValue = aEvent.mNewAttrValue;
54     mAttrChange = aEvent.mAttrChange;
55   }
56 };
57 
58 // Bits are actually checked to optimize mutation event firing.
59 // That's why I don't number from 0x00.  The first event should
60 // always be 0x01.
61 #define NS_EVENT_BITS_MUTATION_SUBTREEMODIFIED                0x01
62 #define NS_EVENT_BITS_MUTATION_NODEINSERTED                   0x02
63 #define NS_EVENT_BITS_MUTATION_NODEREMOVED                    0x04
64 #define NS_EVENT_BITS_MUTATION_NODEREMOVEDFROMDOCUMENT        0x08
65 #define NS_EVENT_BITS_MUTATION_NODEINSERTEDINTODOCUMENT       0x10
66 #define NS_EVENT_BITS_MUTATION_ATTRMODIFIED                   0x20
67 #define NS_EVENT_BITS_MUTATION_CHARACTERDATAMODIFIED          0x40
68 
69 } // namespace mozilla
70 
71 #endif // mozilla_MutationEvent_h__
72