Attr.h (3841B)
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 "nsCOMPtr.h" 16 #include "nsCycleCollectionParticipant.h" 17 #include "nsDOMAttributeMap.h" 18 #include "nsINode.h" 19 #include "nsString.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_ISUPPORTS_INHERITED 38 NS_IMETHOD_(void) DeleteCycleCollectable(void) final; 39 40 NS_DECL_DOMARENA_DESTROY 41 42 NS_IMPL_FROMNODE_HELPER(Attr, IsAttr()) 43 44 // nsINode interface 45 MOZ_CAN_RUN_SCRIPT void SetTextContent(const nsAString& aTextContent, 46 nsIPrincipal* aSubjectPrincipal, 47 mozilla::ErrorResult& aError) override; 48 virtual void GetTextContentInternal(nsAString& aTextContent, 49 OOMReporter& aError) override; 50 virtual void SetTextContentInternal(const nsAString& aTextContent, 51 nsIPrincipal* aSubjectPrincipal, 52 ErrorResult& aError, 53 MutationEffectOnScript) override; 54 MOZ_CAN_RUN_SCRIPT void SetNodeValue(const nsAString& aNodeValue, 55 mozilla::ErrorResult& aError) override; 56 virtual void GetNodeValueInternal(nsAString& aNodeValue) override; 57 virtual void SetNodeValueInternal( 58 const nsAString& aNodeValue, ErrorResult& aError, 59 MutationEffectOnScript aMutationEffectOnScript = 60 MutationEffectOnScript::DropTrustWorthiness) override; 61 62 void GetEventTargetParent(EventChainPreVisitor& aVisitor) override; 63 64 void ConstructUbiNode(void* storage) override; 65 66 nsDOMAttributeMap* GetMap() { return mAttrMap; } 67 68 void SetMap(nsDOMAttributeMap* aMap); 69 70 Element* GetElement() const; 71 72 /** 73 * Called when our ownerElement is moved into a new document. 74 * Updates the nodeinfo of this node. 75 */ 76 nsresult SetOwnerDocument(Document* aDocument); 77 78 // nsINode interface 79 nsresult Clone(dom::NodeInfo*, nsINode** aResult) const override; 80 nsIURI* GetBaseURI(bool aTryUseXHRDocBaseURI = false) const override; 81 82 static void Initialize(); 83 static void Shutdown(); 84 85 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_WRAPPERCACHE_CLASS(Attr) 86 87 // WebIDL 88 virtual JSObject* WrapNode(JSContext* aCx, 89 JS::Handle<JSObject*> aGivenProto) override; 90 91 void GetName(nsAString& aName); 92 void GetValue(nsAString& aValue); 93 94 MOZ_CAN_RUN_SCRIPT void SetValue(const nsAString& aValue, 95 nsIPrincipal* aTriggeringPrincipal, 96 ErrorResult& aRv); 97 void SetValueInternal(const nsAString& aValue, ErrorResult& aRv); 98 99 bool Specified() const; 100 101 // XPCOM GetNamespaceURI() is OK 102 // XPCOM GetPrefix() is OK 103 // XPCOM GetLocalName() is OK 104 105 Element* GetOwnerElement(); 106 107 protected: 108 virtual Element* GetNameSpaceElement() override { return GetElement(); } 109 110 static bool sInitialized; 111 112 private: 113 RefPtr<nsDOMAttributeMap> mAttrMap; 114 nsString mValue; 115 }; 116 117 } // namespace dom 118 } // namespace mozilla 119 120 #endif /* mozilla_dom_Attr_h */