1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : *
24 : * Alternatively, the contents of this file may be used under the terms of
25 : * either of the GNU General Public License Version 2 or later (the "GPL"),
26 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 : * in which case the provisions of the GPL or the LGPL are applicable instead
28 : * of those above. If you wish to allow use of your version of this file only
29 : * under the terms of either the GPL or the LGPL, and not to allow others to
30 : * use your version of this file under the terms of the MPL, indicate your
31 : * decision by deleting the provisions above and replace them with the notice
32 : * and other provisions required by the GPL or the LGPL. If you do not delete
33 : * the provisions above, a recipient may use your version of this file under
34 : * the terms of any one of the MPL, the GPL or the LGPL.
35 : *
36 : * ***** END LICENSE BLOCK ***** */
37 :
38 : #include "nsCOMPtr.h"
39 : #include "nsDOMMutationEvent.h"
40 : #include "nsMutationEvent.h"
41 : #include "nsContentUtils.h"
42 :
43 : class nsPresContext;
44 :
45 44 : nsDOMMutationEvent::nsDOMMutationEvent(nsPresContext* aPresContext,
46 : nsMutationEvent* aEvent)
47 : : nsDOMEvent(aPresContext, aEvent ? aEvent :
48 44 : new nsMutationEvent(false, 0))
49 : {
50 44 : mEventIsInternal = (aEvent == nsnull);
51 44 : }
52 :
53 132 : nsDOMMutationEvent::~nsDOMMutationEvent()
54 : {
55 44 : if (mEventIsInternal) {
56 44 : nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
57 44 : delete mutation;
58 44 : mEvent = nsnull;
59 : }
60 176 : }
61 :
62 : DOMCI_DATA(MutationEvent, nsDOMMutationEvent)
63 :
64 471 : NS_INTERFACE_MAP_BEGIN(nsDOMMutationEvent)
65 471 : NS_INTERFACE_MAP_ENTRY(nsIDOMMutationEvent)
66 471 : NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MutationEvent)
67 467 : NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
68 :
69 274 : NS_IMPL_ADDREF_INHERITED(nsDOMMutationEvent, nsDOMEvent)
70 274 : NS_IMPL_RELEASE_INHERITED(nsDOMMutationEvent, nsDOMEvent)
71 :
72 : NS_IMETHODIMP
73 0 : nsDOMMutationEvent::GetRelatedNode(nsIDOMNode** aRelatedNode)
74 : {
75 0 : *aRelatedNode = nsnull;
76 0 : nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
77 0 : *aRelatedNode = mutation->mRelatedNode;
78 0 : NS_IF_ADDREF(*aRelatedNode);
79 0 : return NS_OK;
80 : }
81 :
82 : NS_IMETHODIMP
83 0 : nsDOMMutationEvent::GetPrevValue(nsAString& aPrevValue)
84 : {
85 0 : nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
86 0 : if (mutation->mPrevAttrValue)
87 0 : mutation->mPrevAttrValue->ToString(aPrevValue);
88 0 : return NS_OK;
89 : }
90 :
91 : NS_IMETHODIMP
92 0 : nsDOMMutationEvent::GetNewValue(nsAString& aNewValue)
93 : {
94 0 : nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
95 0 : if (mutation->mNewAttrValue)
96 0 : mutation->mNewAttrValue->ToString(aNewValue);
97 0 : return NS_OK;
98 : }
99 :
100 : NS_IMETHODIMP
101 0 : nsDOMMutationEvent::GetAttrName(nsAString& aAttrName)
102 : {
103 0 : nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
104 0 : if (mutation->mAttrName)
105 0 : mutation->mAttrName->ToString(aAttrName);
106 0 : return NS_OK;
107 : }
108 :
109 : NS_IMETHODIMP
110 0 : nsDOMMutationEvent::GetAttrChange(PRUint16* aAttrChange)
111 : {
112 0 : *aAttrChange = 0;
113 0 : nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
114 0 : if (mutation->mAttrChange)
115 0 : *aAttrChange = mutation->mAttrChange;
116 0 : return NS_OK;
117 : }
118 :
119 : NS_IMETHODIMP
120 0 : nsDOMMutationEvent::InitMutationEvent(const nsAString& aTypeArg, bool aCanBubbleArg, bool aCancelableArg, nsIDOMNode* aRelatedNodeArg, const nsAString& aPrevValueArg, const nsAString& aNewValueArg, const nsAString& aAttrNameArg, PRUint16 aAttrChangeArg)
121 : {
122 0 : nsresult rv = nsDOMEvent::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
123 0 : NS_ENSURE_SUCCESS(rv, rv);
124 :
125 0 : nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
126 0 : mutation->mRelatedNode = aRelatedNodeArg;
127 0 : if (!aPrevValueArg.IsEmpty())
128 0 : mutation->mPrevAttrValue = do_GetAtom(aPrevValueArg);
129 0 : if (!aNewValueArg.IsEmpty())
130 0 : mutation->mNewAttrValue = do_GetAtom(aNewValueArg);
131 0 : if (!aAttrNameArg.IsEmpty()) {
132 0 : mutation->mAttrName = do_GetAtom(aAttrNameArg);
133 : }
134 0 : mutation->mAttrChange = aAttrChangeArg;
135 :
136 0 : return NS_OK;
137 : }
138 :
139 44 : nsresult NS_NewDOMMutationEvent(nsIDOMEvent** aInstancePtrResult,
140 : nsPresContext* aPresContext,
141 : nsMutationEvent *aEvent)
142 : {
143 44 : nsDOMMutationEvent* it = new nsDOMMutationEvent(aPresContext, aEvent);
144 44 : if (nsnull == it) {
145 0 : return NS_ERROR_OUT_OF_MEMORY;
146 : }
147 :
148 44 : return CallQueryInterface(it, aInstancePtrResult);
149 : }
|