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_CYCLE_COLLECTING_ISUPPORTS_FINAL_DELETECYCLECOLLECTABLE
39 NS_DECL_DOMARENA_DESTROY
41 NS_IMPL_FROMNODE_HELPER(Attr
, IsAttr())
44 virtual void GetTextContentInternal(nsAString
& aTextContent
,
45 OOMReporter
& aError
) override
;
46 virtual void SetTextContentInternal(const nsAString
& aTextContent
,
47 nsIPrincipal
* aSubjectPrincipal
,
48 ErrorResult
& aError
) override
;
49 virtual void GetNodeValueInternal(nsAString
& aNodeValue
) override
;
50 virtual void SetNodeValueInternal(const nsAString
& aNodeValue
,
51 ErrorResult
& aError
) override
;
53 void GetEventTargetParent(EventChainPreVisitor
& aVisitor
) override
;
55 void ConstructUbiNode(void* storage
) override
;
57 nsDOMAttributeMap
* GetMap() { return mAttrMap
; }
59 void SetMap(nsDOMAttributeMap
* aMap
);
61 Element
* GetElement() const;
64 * Called when our ownerElement is moved into a new document.
65 * Updates the nodeinfo of this node.
67 nsresult
SetOwnerDocument(Document
* aDocument
);
70 nsresult
Clone(dom::NodeInfo
*, nsINode
** aResult
) const override
;
71 nsIURI
* GetBaseURI(bool aTryUseXHRDocBaseURI
= false) const override
;
73 static void Initialize();
74 static void Shutdown();
76 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_WRAPPERCACHE_CLASS(Attr
)
79 virtual JSObject
* WrapNode(JSContext
* aCx
,
80 JS::Handle
<JSObject
*> aGivenProto
) override
;
82 void GetName(nsAString
& aName
);
83 void GetValue(nsAString
& aValue
);
85 void SetValue(const nsAString
& aValue
, nsIPrincipal
* aTriggeringPrincipal
,
87 void SetValue(const nsAString
& aValue
, ErrorResult
& aRv
);
89 bool Specified() const;
91 // XPCOM GetNamespaceURI() is OK
92 // XPCOM GetPrefix() is OK
93 // XPCOM GetLocalName() is OK
95 Element
* GetOwnerElement();
98 virtual Element
* GetNameSpaceElement() override
{ return GetElement(); }
100 static bool sInitialized
;
103 RefPtr
<nsDOMAttributeMap
> mAttrMap
;
108 } // namespace mozilla
110 #endif /* mozilla_dom_Attr_h */