|
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
5 |
|
6 /* |
|
7 * Implementation of DOM Core's nsIDOMAttr node. |
|
8 */ |
|
9 |
|
10 #ifndef mozilla_dom_Attr_h |
|
11 #define mozilla_dom_Attr_h |
|
12 |
|
13 #include "mozilla/Attributes.h" |
|
14 #include "nsIAttribute.h" |
|
15 #include "nsIDOMAttr.h" |
|
16 #include "nsIDOMText.h" |
|
17 #include "nsIDOMNodeList.h" |
|
18 #include "nsString.h" |
|
19 #include "nsCOMPtr.h" |
|
20 #include "nsINodeInfo.h" |
|
21 #include "nsCycleCollectionParticipant.h" |
|
22 #include "nsStubMutationObserver.h" |
|
23 #include "nsIDocument.h" |
|
24 |
|
25 namespace mozilla { |
|
26 class EventChainPreVisitor; |
|
27 namespace dom { |
|
28 |
|
29 // Attribute helper class used to wrap up an attribute with a dom |
|
30 // object that implements nsIDOMAttr and nsIDOMNode |
|
31 class Attr MOZ_FINAL : public nsIAttribute, |
|
32 public nsIDOMAttr |
|
33 { |
|
34 public: |
|
35 Attr(nsDOMAttributeMap* aAttrMap, |
|
36 already_AddRefed<nsINodeInfo>&& aNodeInfo, |
|
37 const nsAString& aValue, |
|
38 bool aNsAware); |
|
39 virtual ~Attr() {} |
|
40 |
|
41 NS_DECL_CYCLE_COLLECTING_ISUPPORTS |
|
42 |
|
43 // nsIDOMNode interface |
|
44 NS_FORWARD_NSIDOMNODE_TO_NSINODE |
|
45 virtual void GetTextContentInternal(nsAString& aTextContent) MOZ_OVERRIDE; |
|
46 virtual void SetTextContentInternal(const nsAString& aTextContent, |
|
47 ErrorResult& aError) MOZ_OVERRIDE; |
|
48 virtual void GetNodeValueInternal(nsAString& aNodeValue) MOZ_OVERRIDE; |
|
49 virtual void SetNodeValueInternal(const nsAString& aNodeValue, |
|
50 ErrorResult& aError) MOZ_OVERRIDE; |
|
51 |
|
52 // nsIDOMAttr interface |
|
53 NS_DECL_NSIDOMATTR |
|
54 |
|
55 virtual nsresult PreHandleEvent(EventChainPreVisitor& aVisitor) MOZ_OVERRIDE; |
|
56 |
|
57 // nsIAttribute interface |
|
58 void SetMap(nsDOMAttributeMap *aMap) MOZ_OVERRIDE; |
|
59 Element* GetElement() const; |
|
60 nsresult SetOwnerDocument(nsIDocument* aDocument) MOZ_OVERRIDE; |
|
61 |
|
62 // nsINode interface |
|
63 virtual bool IsNodeOfType(uint32_t aFlags) const MOZ_OVERRIDE; |
|
64 virtual uint32_t GetChildCount() const MOZ_OVERRIDE; |
|
65 virtual nsIContent *GetChildAt(uint32_t aIndex) const MOZ_OVERRIDE; |
|
66 virtual nsIContent * const * GetChildArray(uint32_t* aChildCount) const MOZ_OVERRIDE; |
|
67 virtual int32_t IndexOf(const nsINode* aPossibleChild) const MOZ_OVERRIDE; |
|
68 virtual nsresult InsertChildAt(nsIContent* aKid, uint32_t aIndex, |
|
69 bool aNotify) MOZ_OVERRIDE; |
|
70 virtual void RemoveChildAt(uint32_t aIndex, bool aNotify) MOZ_OVERRIDE; |
|
71 virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE; |
|
72 virtual already_AddRefed<nsIURI> GetBaseURI(bool aTryUseXHRDocBaseURI = false) const MOZ_OVERRIDE; |
|
73 |
|
74 static void Initialize(); |
|
75 static void Shutdown(); |
|
76 |
|
77 NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS_AMBIGUOUS(Attr, |
|
78 nsIAttribute) |
|
79 |
|
80 virtual nsIDOMNode* AsDOMNode() { return this; } |
|
81 |
|
82 // WebIDL |
|
83 virtual JSObject* WrapObject(JSContext* aCx) MOZ_OVERRIDE; |
|
84 |
|
85 // XPCOM GetName() is OK |
|
86 // XPCOM GetValue() is OK |
|
87 |
|
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: |
|
99 virtual Element* GetNameSpaceElement() |
|
100 { |
|
101 return GetElement(); |
|
102 } |
|
103 |
|
104 static bool sInitialized; |
|
105 |
|
106 private: |
|
107 already_AddRefed<nsIAtom> GetNameAtom(nsIContent* aContent); |
|
108 |
|
109 nsString mValue; |
|
110 }; |
|
111 |
|
112 } // namespace dom |
|
113 } // namespace mozilla |
|
114 |
|
115 #endif /* mozilla_dom_Attr_h */ |