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 #ifndef nsTextNode_h 8 #define nsTextNode_h 9 10 /* 11 * Implementation of DOM Core's nsIDOMText node. 12 */ 13 14 #include "mozilla/Attributes.h" 15 #include "mozilla/dom/Text.h" 16 #include "nsIDOMText.h" 17 #include "nsDebug.h" 18 19 class nsNodeInfoManager; 20 21 /** 22 * Class used to implement DOM text nodes 23 */ 24 class nsTextNode : public mozilla::dom::Text, public nsIDOMText { 25 private: Init()26 void Init() { 27 MOZ_ASSERT(mNodeInfo->NodeType() == TEXT_NODE, "Bad NodeType in aNodeInfo"); 28 } 29 30 public: nsTextNode(already_AddRefed<mozilla::dom::NodeInfo> & aNodeInfo)31 explicit nsTextNode(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo) 32 : mozilla::dom::Text(aNodeInfo) { 33 Init(); 34 } 35 nsTextNode(nsNodeInfoManager * aNodeInfoManager)36 explicit nsTextNode(nsNodeInfoManager* aNodeInfoManager) 37 : mozilla::dom::Text(aNodeInfoManager->GetTextNodeInfo()) { 38 Init(); 39 } 40 41 // nsISupports 42 NS_DECL_ISUPPORTS_INHERITED 43 44 // nsIDOMCharacterData 45 NS_FORWARD_NSIDOMCHARACTERDATA(nsGenericDOMDataNode::) 46 using nsGenericDOMDataNode::SetData; // Prevent hiding overloaded virtual 47 // function. 48 49 // nsIDOMText 50 NS_FORWARD_NSIDOMTEXT(nsGenericDOMDataNode::) 51 52 // nsINode 53 virtual bool IsNodeOfType(uint32_t aFlags) const override; 54 55 virtual nsGenericDOMDataNode* CloneDataNode(mozilla::dom::NodeInfo* aNodeInfo, 56 bool aCloneText) const override; 57 58 virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, 59 nsIContent* aBindingParent, 60 bool aCompileEventHandlers) override; 61 virtual void UnbindFromTree(bool aDeep = true, 62 bool aNullParent = true) override; 63 64 nsresult AppendTextForNormalize(const char16_t* aBuffer, uint32_t aLength, 65 bool aNotify, nsIContent* aNextSibling); 66 AsDOMNode()67 virtual nsIDOMNode* AsDOMNode() override { return this; } 68 69 // Need to have a copy here because including nsDocument.h in this file will 70 // fail to build on Windows. 71 static bool IsShadowDOMEnabled(JSContext* aCx, JSObject* aObject); 72 73 #ifdef DEBUG 74 virtual void List(FILE* out, int32_t aIndent) const override; 75 virtual void DumpContent(FILE* out, int32_t aIndent, 76 bool aDumpAll) const override; 77 #endif 78 79 protected: 80 virtual ~nsTextNode(); 81 82 virtual JSObject* WrapNode(JSContext* aCx, 83 JS::Handle<JSObject*> aGivenProto) override; 84 }; 85 86 #endif // nsTextNode_h 87