dom/events/MutationEvent.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #include "nsCOMPtr.h"
michael@0 7 #include "mozilla/dom/MutationEvent.h"
michael@0 8 #include "mozilla/InternalMutationEvent.h"
michael@0 9
michael@0 10 class nsPresContext;
michael@0 11
michael@0 12 namespace mozilla {
michael@0 13 namespace dom {
michael@0 14
michael@0 15 MutationEvent::MutationEvent(EventTarget* aOwner,
michael@0 16 nsPresContext* aPresContext,
michael@0 17 InternalMutationEvent* aEvent)
michael@0 18 : Event(aOwner, aPresContext,
michael@0 19 aEvent ? aEvent : new InternalMutationEvent(false, 0))
michael@0 20 {
michael@0 21 mEventIsInternal = (aEvent == nullptr);
michael@0 22 }
michael@0 23
michael@0 24 NS_INTERFACE_MAP_BEGIN(MutationEvent)
michael@0 25 NS_INTERFACE_MAP_ENTRY(nsIDOMMutationEvent)
michael@0 26 NS_INTERFACE_MAP_END_INHERITING(Event)
michael@0 27
michael@0 28 NS_IMPL_ADDREF_INHERITED(MutationEvent, Event)
michael@0 29 NS_IMPL_RELEASE_INHERITED(MutationEvent, Event)
michael@0 30
michael@0 31 already_AddRefed<nsINode>
michael@0 32 MutationEvent::GetRelatedNode()
michael@0 33 {
michael@0 34 nsCOMPtr<nsINode> n =
michael@0 35 do_QueryInterface(mEvent->AsMutationEvent()->mRelatedNode);
michael@0 36 return n.forget();
michael@0 37 }
michael@0 38
michael@0 39 NS_IMETHODIMP
michael@0 40 MutationEvent::GetRelatedNode(nsIDOMNode** aRelatedNode)
michael@0 41 {
michael@0 42 nsCOMPtr<nsINode> relatedNode = GetRelatedNode();
michael@0 43 nsCOMPtr<nsIDOMNode> relatedDOMNode = relatedNode ? relatedNode->AsDOMNode() : nullptr;
michael@0 44 relatedDOMNode.forget(aRelatedNode);
michael@0 45 return NS_OK;
michael@0 46 }
michael@0 47
michael@0 48 NS_IMETHODIMP
michael@0 49 MutationEvent::GetPrevValue(nsAString& aPrevValue)
michael@0 50 {
michael@0 51 InternalMutationEvent* mutation = mEvent->AsMutationEvent();
michael@0 52 if (mutation->mPrevAttrValue)
michael@0 53 mutation->mPrevAttrValue->ToString(aPrevValue);
michael@0 54 return NS_OK;
michael@0 55 }
michael@0 56
michael@0 57 NS_IMETHODIMP
michael@0 58 MutationEvent::GetNewValue(nsAString& aNewValue)
michael@0 59 {
michael@0 60 InternalMutationEvent* mutation = mEvent->AsMutationEvent();
michael@0 61 if (mutation->mNewAttrValue)
michael@0 62 mutation->mNewAttrValue->ToString(aNewValue);
michael@0 63 return NS_OK;
michael@0 64 }
michael@0 65
michael@0 66 NS_IMETHODIMP
michael@0 67 MutationEvent::GetAttrName(nsAString& aAttrName)
michael@0 68 {
michael@0 69 InternalMutationEvent* mutation = mEvent->AsMutationEvent();
michael@0 70 if (mutation->mAttrName)
michael@0 71 mutation->mAttrName->ToString(aAttrName);
michael@0 72 return NS_OK;
michael@0 73 }
michael@0 74
michael@0 75 uint16_t
michael@0 76 MutationEvent::AttrChange()
michael@0 77 {
michael@0 78 return mEvent->AsMutationEvent()->mAttrChange;
michael@0 79 }
michael@0 80
michael@0 81 NS_IMETHODIMP
michael@0 82 MutationEvent::GetAttrChange(uint16_t* aAttrChange)
michael@0 83 {
michael@0 84 *aAttrChange = AttrChange();
michael@0 85 return NS_OK;
michael@0 86 }
michael@0 87
michael@0 88 NS_IMETHODIMP
michael@0 89 MutationEvent::InitMutationEvent(const nsAString& aTypeArg,
michael@0 90 bool aCanBubbleArg,
michael@0 91 bool aCancelableArg,
michael@0 92 nsIDOMNode* aRelatedNodeArg,
michael@0 93 const nsAString& aPrevValueArg,
michael@0 94 const nsAString& aNewValueArg,
michael@0 95 const nsAString& aAttrNameArg,
michael@0 96 uint16_t aAttrChangeArg)
michael@0 97 {
michael@0 98 nsresult rv = Event::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
michael@0 99 NS_ENSURE_SUCCESS(rv, rv);
michael@0 100
michael@0 101 InternalMutationEvent* mutation = mEvent->AsMutationEvent();
michael@0 102 mutation->mRelatedNode = aRelatedNodeArg;
michael@0 103 if (!aPrevValueArg.IsEmpty())
michael@0 104 mutation->mPrevAttrValue = do_GetAtom(aPrevValueArg);
michael@0 105 if (!aNewValueArg.IsEmpty())
michael@0 106 mutation->mNewAttrValue = do_GetAtom(aNewValueArg);
michael@0 107 if (!aAttrNameArg.IsEmpty()) {
michael@0 108 mutation->mAttrName = do_GetAtom(aAttrNameArg);
michael@0 109 }
michael@0 110 mutation->mAttrChange = aAttrChangeArg;
michael@0 111
michael@0 112 return NS_OK;
michael@0 113 }
michael@0 114
michael@0 115 } // namespace dom
michael@0 116 } // namespace mozilla
michael@0 117
michael@0 118 using namespace mozilla;
michael@0 119 using namespace mozilla::dom;
michael@0 120
michael@0 121 nsresult
michael@0 122 NS_NewDOMMutationEvent(nsIDOMEvent** aInstancePtrResult,
michael@0 123 EventTarget* aOwner,
michael@0 124 nsPresContext* aPresContext,
michael@0 125 InternalMutationEvent* aEvent)
michael@0 126 {
michael@0 127 MutationEvent* it = new MutationEvent(aOwner, aPresContext, aEvent);
michael@0 128 NS_ADDREF(it);
michael@0 129 *aInstancePtrResult = static_cast<Event*>(it);
michael@0 130 return NS_OK;
michael@0 131 }

mercurial