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/. */
8 * Implementation of DOM Core's Attr node.
11 #ifndef mozilla_dom_Attr_h
12 #define mozilla_dom_Attr_h
14 #include "mozilla/Attributes.h"
15 #include "nsDOMAttributeMap.h"
19 #include "nsCycleCollectionParticipant.h"
20 #include "nsStubMutationObserver.h"
23 class EventChainPreVisitor
;
28 // Attribute helper class used to wrap up an attribute with a dom
29 // object that implements the DOM Attr interface.
30 class Attr final
: public nsINode
{
31 virtual ~Attr() = default;
34 Attr(nsDOMAttributeMap
* aAttrMap
, already_AddRefed
<dom::NodeInfo
>&& aNodeInfo
,
35 const nsAString
& aValue
);
37 NS_DECL_ISUPPORTS_INHERITED
38 NS_IMETHOD_(void) DeleteCycleCollectable(void) final
;
40 NS_DECL_DOMARENA_DESTROY
42 NS_IMPL_FROMNODE_HELPER(Attr
, IsAttr())
45 virtual void GetTextContentInternal(nsAString
& aTextContent
,
46 OOMReporter
& aError
) override
;
47 virtual void SetTextContentInternal(const nsAString
& aTextContent
,
48 nsIPrincipal
* aSubjectPrincipal
,
49 ErrorResult
& aError
) override
;
50 virtual void GetNodeValueInternal(nsAString
& aNodeValue
) override
;
51 virtual void SetNodeValueInternal(const nsAString
& aNodeValue
,
52 ErrorResult
& aError
) override
;
54 void GetEventTargetParent(EventChainPreVisitor
& aVisitor
) override
;
56 void ConstructUbiNode(void* storage
) override
;
58 nsDOMAttributeMap
* GetMap() { return mAttrMap
; }
60 void SetMap(nsDOMAttributeMap
* aMap
);
62 Element
* GetElement() const;
65 * Called when our ownerElement is moved into a new document.
66 * Updates the nodeinfo of this node.
68 nsresult
SetOwnerDocument(Document
* aDocument
);
71 nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
72 nsIURI
* GetBaseURI(bool aTryUseXHRDocBaseURI
= false) const override
;
74 static void Initialize();
75 static void Shutdown();
77 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_WRAPPERCACHE_CLASS(Attr
)
80 virtual JSObject
* WrapNode(JSContext
* aCx
,
81 JS::Handle
<JSObject
*> aGivenProto
) override
;
83 void GetName(nsAString
& aName
);
84 void GetValue(nsAString
& aValue
);
86 void SetValue(const nsAString
& aValue
, nsIPrincipal
* aTriggeringPrincipal
,
88 void SetValue(const nsAString
& aValue
, ErrorResult
& aRv
);
90 bool Specified() const;
92 // XPCOM GetNamespaceURI() is OK
93 // XPCOM GetPrefix() is OK
94 // XPCOM GetLocalName() is OK
96 Element
* GetOwnerElement();
99 virtual Element
* GetNameSpaceElement() override
{ return GetElement(); }
101 static bool sInitialized
;
104 RefPtr
<nsDOMAttributeMap
> mAttrMap
;
109 } // namespace mozilla
111 #endif /* mozilla_dom_Attr_h */