dom/events/MutationEvent.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/events/MutationEvent.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,131 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +#include "nsCOMPtr.h"
    1.10 +#include "mozilla/dom/MutationEvent.h"
    1.11 +#include "mozilla/InternalMutationEvent.h"
    1.12 +
    1.13 +class nsPresContext;
    1.14 +
    1.15 +namespace mozilla {
    1.16 +namespace dom {
    1.17 +
    1.18 +MutationEvent::MutationEvent(EventTarget* aOwner,
    1.19 +                             nsPresContext* aPresContext,
    1.20 +                             InternalMutationEvent* aEvent)
    1.21 +  : Event(aOwner, aPresContext,
    1.22 +          aEvent ? aEvent : new InternalMutationEvent(false, 0))
    1.23 +{
    1.24 +  mEventIsInternal = (aEvent == nullptr);
    1.25 +}
    1.26 +
    1.27 +NS_INTERFACE_MAP_BEGIN(MutationEvent)
    1.28 +  NS_INTERFACE_MAP_ENTRY(nsIDOMMutationEvent)
    1.29 +NS_INTERFACE_MAP_END_INHERITING(Event)
    1.30 +
    1.31 +NS_IMPL_ADDREF_INHERITED(MutationEvent, Event)
    1.32 +NS_IMPL_RELEASE_INHERITED(MutationEvent, Event)
    1.33 +
    1.34 +already_AddRefed<nsINode>
    1.35 +MutationEvent::GetRelatedNode()
    1.36 +{
    1.37 +  nsCOMPtr<nsINode> n =
    1.38 +    do_QueryInterface(mEvent->AsMutationEvent()->mRelatedNode);
    1.39 +  return n.forget();
    1.40 +}
    1.41 +
    1.42 +NS_IMETHODIMP
    1.43 +MutationEvent::GetRelatedNode(nsIDOMNode** aRelatedNode)
    1.44 +{
    1.45 +  nsCOMPtr<nsINode> relatedNode = GetRelatedNode();
    1.46 +  nsCOMPtr<nsIDOMNode> relatedDOMNode = relatedNode ? relatedNode->AsDOMNode() : nullptr;
    1.47 +  relatedDOMNode.forget(aRelatedNode);
    1.48 +  return NS_OK;
    1.49 +}
    1.50 +
    1.51 +NS_IMETHODIMP
    1.52 +MutationEvent::GetPrevValue(nsAString& aPrevValue)
    1.53 +{
    1.54 +  InternalMutationEvent* mutation = mEvent->AsMutationEvent();
    1.55 +  if (mutation->mPrevAttrValue)
    1.56 +    mutation->mPrevAttrValue->ToString(aPrevValue);
    1.57 +  return NS_OK;
    1.58 +}
    1.59 +
    1.60 +NS_IMETHODIMP
    1.61 +MutationEvent::GetNewValue(nsAString& aNewValue)
    1.62 +{
    1.63 +  InternalMutationEvent* mutation = mEvent->AsMutationEvent();
    1.64 +  if (mutation->mNewAttrValue)
    1.65 +      mutation->mNewAttrValue->ToString(aNewValue);
    1.66 +  return NS_OK;
    1.67 +}
    1.68 +
    1.69 +NS_IMETHODIMP
    1.70 +MutationEvent::GetAttrName(nsAString& aAttrName)
    1.71 +{
    1.72 +  InternalMutationEvent* mutation = mEvent->AsMutationEvent();
    1.73 +  if (mutation->mAttrName)
    1.74 +      mutation->mAttrName->ToString(aAttrName);
    1.75 +  return NS_OK;
    1.76 +}
    1.77 +
    1.78 +uint16_t
    1.79 +MutationEvent::AttrChange()
    1.80 +{
    1.81 +  return mEvent->AsMutationEvent()->mAttrChange;
    1.82 +}
    1.83 +
    1.84 +NS_IMETHODIMP
    1.85 +MutationEvent::GetAttrChange(uint16_t* aAttrChange)
    1.86 +{
    1.87 +  *aAttrChange = AttrChange();
    1.88 +  return NS_OK;
    1.89 +}
    1.90 +
    1.91 +NS_IMETHODIMP
    1.92 +MutationEvent::InitMutationEvent(const nsAString& aTypeArg,
    1.93 +                                 bool aCanBubbleArg,
    1.94 +                                 bool aCancelableArg,
    1.95 +                                 nsIDOMNode* aRelatedNodeArg,
    1.96 +                                 const nsAString& aPrevValueArg,
    1.97 +                                 const nsAString& aNewValueArg,
    1.98 +                                 const nsAString& aAttrNameArg,
    1.99 +                                 uint16_t aAttrChangeArg)
   1.100 +{
   1.101 +  nsresult rv = Event::InitEvent(aTypeArg, aCanBubbleArg, aCancelableArg);
   1.102 +  NS_ENSURE_SUCCESS(rv, rv);
   1.103 +
   1.104 +  InternalMutationEvent* mutation = mEvent->AsMutationEvent();
   1.105 +  mutation->mRelatedNode = aRelatedNodeArg;
   1.106 +  if (!aPrevValueArg.IsEmpty())
   1.107 +    mutation->mPrevAttrValue = do_GetAtom(aPrevValueArg);
   1.108 +  if (!aNewValueArg.IsEmpty())
   1.109 +    mutation->mNewAttrValue = do_GetAtom(aNewValueArg);
   1.110 +  if (!aAttrNameArg.IsEmpty()) {
   1.111 +    mutation->mAttrName = do_GetAtom(aAttrNameArg);
   1.112 +  }
   1.113 +  mutation->mAttrChange = aAttrChangeArg;
   1.114 +    
   1.115 +  return NS_OK;
   1.116 +}
   1.117 +
   1.118 +} // namespace dom
   1.119 +} // namespace mozilla
   1.120 +
   1.121 +using namespace mozilla;
   1.122 +using namespace mozilla::dom;
   1.123 +
   1.124 +nsresult
   1.125 +NS_NewDOMMutationEvent(nsIDOMEvent** aInstancePtrResult,
   1.126 +                       EventTarget* aOwner,
   1.127 +                       nsPresContext* aPresContext,
   1.128 +                       InternalMutationEvent* aEvent) 
   1.129 +{
   1.130 +  MutationEvent* it = new MutationEvent(aOwner, aPresContext, aEvent);
   1.131 +  NS_ADDREF(it);
   1.132 +  *aInstancePtrResult = static_cast<Event*>(it);
   1.133 +  return NS_OK;
   1.134 +}

mercurial