Follow-on fix for bug 457825. Use sheet principal for agent and user sheets. r=dbaron...
[wine-gecko.git] / content / events / src / nsDOMMutationEvent.cpp
blob179795925b6fdec0eb430145e4df39c65373ba2a
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
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/
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.
15 * The Original Code is mozilla.org code.
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.
22 * Contributor(s):
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.
36 * ***** END LICENSE BLOCK ***** */
38 #include "nsCOMPtr.h"
39 #include "nsDOMMutationEvent.h"
40 #include "nsMutationEvent.h"
41 #include "nsContentUtils.h"
43 class nsPresContext;
45 nsDOMMutationEvent::nsDOMMutationEvent(nsPresContext* aPresContext,
46 nsMutationEvent* aEvent)
47 : nsDOMEvent(aPresContext, aEvent ? aEvent :
48 new nsMutationEvent(PR_FALSE, 0))
50 mEventIsInternal = (aEvent == nsnull);
53 nsDOMMutationEvent::~nsDOMMutationEvent()
55 if (mEventIsInternal) {
56 nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
57 delete mutation;
58 mEvent = nsnull;
62 NS_INTERFACE_MAP_BEGIN(nsDOMMutationEvent)
63 NS_INTERFACE_MAP_ENTRY(nsIDOMMutationEvent)
64 NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(MutationEvent)
65 NS_INTERFACE_MAP_END_INHERITING(nsDOMEvent)
67 NS_IMPL_ADDREF_INHERITED(nsDOMMutationEvent, nsDOMEvent)
68 NS_IMPL_RELEASE_INHERITED(nsDOMMutationEvent, nsDOMEvent)
70 NS_IMETHODIMP
71 nsDOMMutationEvent::GetRelatedNode(nsIDOMNode** aRelatedNode)
73 *aRelatedNode = nsnull;
74 nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
75 *aRelatedNode = mutation->mRelatedNode;
76 NS_IF_ADDREF(*aRelatedNode);
77 return NS_OK;
80 NS_IMETHODIMP
81 nsDOMMutationEvent::GetPrevValue(nsAString& aPrevValue)
83 nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
84 if (mutation->mPrevAttrValue)
85 mutation->mPrevAttrValue->ToString(aPrevValue);
86 return NS_OK;
89 NS_IMETHODIMP
90 nsDOMMutationEvent::GetNewValue(nsAString& aNewValue)
92 nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
93 if (mutation->mNewAttrValue)
94 mutation->mNewAttrValue->ToString(aNewValue);
95 return NS_OK;
98 NS_IMETHODIMP
99 nsDOMMutationEvent::GetAttrName(nsAString& aAttrName)
101 nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
102 if (mutation->mAttrName)
103 mutation->mAttrName->ToString(aAttrName);
104 return NS_OK;
107 NS_IMETHODIMP
108 nsDOMMutationEvent::GetAttrChange(PRUint16* aAttrChange)
110 *aAttrChange = 0;
111 nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
112 if (mutation->mAttrChange)
113 *aAttrChange = mutation->mAttrChange;
114 return NS_OK;
117 NS_IMETHODIMP
118 nsDOMMutationEvent::InitMutationEvent(const nsAString& aTypeArg, PRBool aCanBubbleArg, PRBool aCancelableArg, nsIDOMNode* aRelatedNodeArg, const nsAString& aPrevValueArg, const nsAString& aNewValueArg, const nsAString& aAttrNameArg, PRUint16 aAttrChangeArg)
120 nsresult rv = nsDOMEvent::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
121 NS_ENSURE_SUCCESS(rv, rv);
123 nsMutationEvent* mutation = static_cast<nsMutationEvent*>(mEvent);
124 mutation->mRelatedNode = aRelatedNodeArg;
125 if (!aPrevValueArg.IsEmpty())
126 mutation->mPrevAttrValue = do_GetAtom(aPrevValueArg);
127 if (!aNewValueArg.IsEmpty())
128 mutation->mNewAttrValue = do_GetAtom(aNewValueArg);
129 if (!aAttrNameArg.IsEmpty()) {
130 mutation->mAttrName = do_GetAtom(aAttrNameArg);
132 mutation->mAttrChange = aAttrChangeArg;
134 return NS_OK;
137 nsresult NS_NewDOMMutationEvent(nsIDOMEvent** aInstancePtrResult,
138 nsPresContext* aPresContext,
139 nsMutationEvent *aEvent)
141 nsDOMMutationEvent* it = new nsDOMMutationEvent(aPresContext, aEvent);
142 if (nsnull == it) {
143 return NS_ERROR_OUT_OF_MEMORY;
146 return CallQueryInterface(it, aInstancePtrResult);