Bug 1686668 [wpt PR 27185] - Update wpt metadata, a=testonly
[gecko.git] / dom / base / Attr.h
blobdfac0c727a4d592086310d93d939fbf5743b2795
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/. */
7 /*
8 * Implementation of DOM Core's Attr node.
9 */
11 #ifndef mozilla_dom_Attr_h
12 #define mozilla_dom_Attr_h
14 #include "mozilla/Attributes.h"
15 #include "nsDOMAttributeMap.h"
16 #include "nsINode.h"
17 #include "nsString.h"
18 #include "nsCOMPtr.h"
19 #include "nsCycleCollectionParticipant.h"
20 #include "nsStubMutationObserver.h"
22 namespace mozilla {
23 class EventChainPreVisitor;
24 namespace dom {
26 class Document;
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;
33 public:
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())
43 // nsINode interface
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;
63 /**
64 * Called when our ownerElement is moved into a new document.
65 * Updates the nodeinfo of this node.
67 nsresult SetOwnerDocument(Document* aDocument);
69 // nsINode interface
70 virtual bool IsNodeOfType(uint32_t aFlags) const override;
71 virtual 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_SCRIPT_HOLDER_CLASS(Attr)
79 // WebIDL
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,
87 ErrorResult& aRv);
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(ErrorResult& aRv);
98 protected:
99 virtual Element* GetNameSpaceElement() override { return GetElement(); }
101 static bool sInitialized;
103 private:
104 RefPtr<nsDOMAttributeMap> mAttrMap;
105 nsString mValue;
108 } // namespace dom
109 } // namespace mozilla
111 #endif /* mozilla_dom_Attr_h */