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/. */ 6 7 /* 8 * Implementation of DOM Core's Attr node. 9 */ 10 11 #ifndef mozilla_dom_Attr_h 12 #define mozilla_dom_Attr_h 13 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" 21 22 namespace mozilla { 23 class EventChainPreVisitor; 24 namespace dom { 25 26 class Document; 27 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; 32 33 public: 34 Attr(nsDOMAttributeMap* aAttrMap, already_AddRefed<dom::NodeInfo>&& aNodeInfo, 35 const nsAString& aValue); 36 37 NS_DECL_CYCLE_COLLECTING_ISUPPORTS_FINAL_DELETECYCLECOLLECTABLE 38 39 NS_DECL_DOMARENA_DESTROY 40 41 NS_IMPL_FROMNODE_HELPER(Attr, IsAttr()) 42 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; 52 53 void GetEventTargetParent(EventChainPreVisitor& aVisitor) override; 54 55 void ConstructUbiNode(void* storage) override; 56 GetMap()57 nsDOMAttributeMap* GetMap() { return mAttrMap; } 58 59 void SetMap(nsDOMAttributeMap* aMap); 60 61 Element* GetElement() const; 62 63 /** 64 * Called when our ownerElement is moved into a new document. 65 * Updates the nodeinfo of this node. 66 */ 67 nsresult SetOwnerDocument(Document* aDocument); 68 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; 73 74 static void Initialize(); 75 static void Shutdown(); 76 77 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(Attr) 78 79 // WebIDL 80 virtual JSObject* WrapNode(JSContext* aCx, 81 JS::Handle<JSObject*> aGivenProto) override; 82 83 void GetName(nsAString& aName); 84 void GetValue(nsAString& aValue); 85 86 void SetValue(const nsAString& aValue, nsIPrincipal* aTriggeringPrincipal, 87 ErrorResult& aRv); 88 void SetValue(const nsAString& aValue, ErrorResult& aRv); 89 90 bool Specified() const; 91 92 // XPCOM GetNamespaceURI() is OK 93 // XPCOM GetPrefix() is OK 94 // XPCOM GetLocalName() is OK 95 96 Element* GetOwnerElement(ErrorResult& aRv); 97 98 protected: GetNameSpaceElement()99 virtual Element* GetNameSpaceElement() override { return GetElement(); } 100 101 static bool sInitialized; 102 103 private: 104 RefPtr<nsDOMAttributeMap> mAttrMap; 105 nsString mValue; 106 }; 107 108 } // namespace dom 109 } // namespace mozilla 110 111 #endif /* mozilla_dom_Attr_h */ 112