1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/src/DocumentFragment.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,155 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * vim: sw=2 ts=2 et : 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef mozilla_dom_DocumentFragment_h__ 1.11 +#define mozilla_dom_DocumentFragment_h__ 1.12 + 1.13 +#include "mozilla/Attributes.h" 1.14 +#include "mozilla/dom/FragmentOrElement.h" 1.15 +#include "nsIDOMDocumentFragment.h" 1.16 + 1.17 +class nsINodeInfo; 1.18 +class nsIAtom; 1.19 +class nsAString; 1.20 +class nsIDocument; 1.21 +class nsIContent; 1.22 + 1.23 +namespace mozilla { 1.24 +namespace dom { 1.25 + 1.26 +class Element; 1.27 + 1.28 +class DocumentFragment : public FragmentOrElement, 1.29 + public nsIDOMDocumentFragment 1.30 +{ 1.31 +private: 1.32 + void Init() 1.33 + { 1.34 + NS_ABORT_IF_FALSE(mNodeInfo->NodeType() == 1.35 + nsIDOMNode::DOCUMENT_FRAGMENT_NODE && 1.36 + mNodeInfo->Equals(nsGkAtoms::documentFragmentNodeName, 1.37 + kNameSpaceID_None), 1.38 + "Bad NodeType in aNodeInfo"); 1.39 + } 1.40 + 1.41 +public: 1.42 + using FragmentOrElement::GetFirstChild; 1.43 + using nsINode::QuerySelector; 1.44 + using nsINode::QuerySelectorAll; 1.45 + // Make sure bindings can see our superclass' protected GetElementById method. 1.46 + using nsINode::GetElementById; 1.47 + 1.48 + // nsISupports 1.49 + NS_DECL_ISUPPORTS_INHERITED 1.50 + 1.51 + // interface nsIDOMNode 1.52 + NS_FORWARD_NSIDOMNODE_TO_NSINODE 1.53 + 1.54 + // interface nsIDOMDocumentFragment 1.55 + NS_DECL_NSIDOMDOCUMENTFRAGMENT 1.56 + 1.57 + DocumentFragment(already_AddRefed<nsINodeInfo>& aNodeInfo) 1.58 + : FragmentOrElement(aNodeInfo), mHost(nullptr) 1.59 + { 1.60 + Init(); 1.61 + } 1.62 + 1.63 + DocumentFragment(nsNodeInfoManager* aNodeInfoManager) 1.64 + : FragmentOrElement(aNodeInfoManager->GetNodeInfo( 1.65 + nsGkAtoms::documentFragmentNodeName, 1.66 + nullptr, kNameSpaceID_None, 1.67 + nsIDOMNode::DOCUMENT_FRAGMENT_NODE)), 1.68 + mHost(nullptr) 1.69 + { 1.70 + Init(); 1.71 + } 1.72 + 1.73 + virtual ~DocumentFragment() 1.74 + { 1.75 + } 1.76 + 1.77 + virtual JSObject* WrapNode(JSContext *aCx) MOZ_OVERRIDE; 1.78 + 1.79 + // nsIContent 1.80 + nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, 1.81 + const nsAString& aValue, bool aNotify) 1.82 + { 1.83 + return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify); 1.84 + } 1.85 + virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName, 1.86 + nsIAtom* aPrefix, const nsAString& aValue, 1.87 + bool aNotify) MOZ_OVERRIDE 1.88 + { 1.89 + return NS_OK; 1.90 + } 1.91 + virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute, 1.92 + bool aNotify) MOZ_OVERRIDE 1.93 + { 1.94 + return NS_OK; 1.95 + } 1.96 + virtual const nsAttrName* GetAttrNameAt(uint32_t aIndex) const MOZ_OVERRIDE 1.97 + { 1.98 + return nullptr; 1.99 + } 1.100 + virtual uint32_t GetAttrCount() const MOZ_OVERRIDE 1.101 + { 1.102 + return 0; 1.103 + } 1.104 + 1.105 + virtual bool IsNodeOfType(uint32_t aFlags) const MOZ_OVERRIDE; 1.106 + 1.107 + virtual nsIDOMNode* AsDOMNode() MOZ_OVERRIDE { return this; } 1.108 + 1.109 + virtual nsIAtom* DoGetID() const MOZ_OVERRIDE; 1.110 + virtual nsIAtom *GetIDAttributeName() const MOZ_OVERRIDE; 1.111 + 1.112 + virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent, 1.113 + nsIContent* aBindingParent, 1.114 + bool aCompileEventHandlers) MOZ_OVERRIDE 1.115 + { 1.116 + NS_ASSERTION(false, "Trying to bind a fragment to a tree"); 1.117 + return NS_ERROR_NOT_IMPLEMENTED; 1.118 + } 1.119 + 1.120 + virtual void UnbindFromTree(bool aDeep, bool aNullParent) MOZ_OVERRIDE 1.121 + { 1.122 + NS_ASSERTION(false, "Trying to unbind a fragment from a tree"); 1.123 + return; 1.124 + } 1.125 + 1.126 + virtual Element* GetNameSpaceElement() 1.127 + { 1.128 + return nullptr; 1.129 + } 1.130 + 1.131 + nsIContent* GetHost() const 1.132 + { 1.133 + return mHost; 1.134 + } 1.135 + 1.136 + void SetHost(nsIContent* aHost) 1.137 + { 1.138 + mHost = aHost; 1.139 + } 1.140 + 1.141 + static already_AddRefed<DocumentFragment> 1.142 + Constructor(const GlobalObject& aGlobal, ErrorResult& aRv); 1.143 + 1.144 +#ifdef DEBUG 1.145 + virtual void List(FILE* out, int32_t aIndent) const MOZ_OVERRIDE; 1.146 + virtual void DumpContent(FILE* out, int32_t aIndent, bool aDumpAll) const MOZ_OVERRIDE; 1.147 +#endif 1.148 + 1.149 +protected: 1.150 + nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const MOZ_OVERRIDE; 1.151 + nsIContent* mHost; // Weak 1.152 +}; 1.153 + 1.154 +} // namespace dom 1.155 +} // namespace mozilla 1.156 + 1.157 + 1.158 +#endif // mozilla_dom_DocumentFragment_h__