2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Implementation of DOM Core's nsIDOMDocumentFragment.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nsIDOMDocumentFragment.h"
|
2012-07-02 06:31:49 -07:00
|
|
|
#include "mozilla/dom/FragmentOrElement.h"
|
2012-07-24 01:10:25 -07:00
|
|
|
#include "nsGenericElement.h" // for DOMCI_NODE_DATA
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsINodeInfo.h"
|
|
|
|
#include "nsNodeInfoManager.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsDOMString.h"
|
2012-05-18 01:29:38 -07:00
|
|
|
#include "nsContentUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-02 06:31:49 -07:00
|
|
|
using namespace mozilla;
|
|
|
|
using namespace mozilla::dom;
|
|
|
|
|
|
|
|
class nsDocumentFragment : public FragmentOrElement,
|
2011-06-14 00:56:49 -07:00
|
|
|
public nsIDOMDocumentFragment
|
2011-06-14 00:56:48 -07:00
|
|
|
{
|
|
|
|
public:
|
2012-07-02 06:31:49 -07:00
|
|
|
using FragmentOrElement::GetFirstChild;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
2011-06-14 00:56:48 -07:00
|
|
|
// interface nsIDOMNode
|
2012-10-09 05:31:24 -07:00
|
|
|
NS_FORWARD_NSIDOMNODE_TO_NSINODE
|
2011-06-14 00:56:48 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// interface nsIDOMDocumentFragment
|
2011-06-14 00:56:48 -07:00
|
|
|
// NS_DECL_NSIDOCUMENTFRAGMENT Empty
|
|
|
|
|
|
|
|
nsDocumentFragment(already_AddRefed<nsINodeInfo> aNodeInfo);
|
|
|
|
virtual ~nsDocumentFragment()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// nsIContent
|
2012-07-24 01:10:25 -07:00
|
|
|
virtual already_AddRefed<nsINodeInfo>
|
|
|
|
GetExistingAttrNameFromQName(const nsAString& aStr) const
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2011-09-28 23:19:26 -07:00
|
|
|
const nsAString& aValue, bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return SetAttr(aNameSpaceID, aName, nullptr, aValue, aNotify);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual nsresult SetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool GetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAString& aResult) const
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool HasAttr(int32_t aNameSpaceID, nsIAtom* aName) const
|
2012-07-02 06:31:49 -07:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual nsresult UnsetAttr(int32_t aNameSpaceID, nsIAtom* aAttribute,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual const nsAttrName* GetAttrNameAt(uint32_t aIndex) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual uint32_t GetAttrCount() const
|
2012-07-02 06:31:49 -07:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool IsNodeOfType(uint32_t aFlags) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
virtual nsXPCClassInfo* GetClassInfo();
|
|
|
|
|
2012-04-25 06:47:30 -07:00
|
|
|
virtual nsIDOMNode* AsDOMNode() { return this; }
|
|
|
|
|
2010-06-03 18:09:20 -07:00
|
|
|
virtual nsIAtom* DoGetID() const;
|
|
|
|
virtual nsIAtom *GetIDAttributeName() const;
|
|
|
|
|
2012-07-02 06:31:49 -07:00
|
|
|
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(false, "Trying to bind a fragment to a tree");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void UnbindFromTree(bool aDeep, bool aNullParent)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(false, "Trying to unbind a fragment from a tree");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-06-15 05:16:20 -07:00
|
|
|
virtual Element* GetNameSpaceElement()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-07-02 06:31:49 -07:00
|
|
|
#ifdef DEBUG
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual void List(FILE* out, int32_t aIndent) const;
|
|
|
|
virtual void DumpContent(FILE* out, int32_t aIndent, bool aDumpAll) const;
|
2012-07-02 06:31:49 -07:00
|
|
|
#endif
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
|
|
|
|
};
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewDocumentFragment(nsIDOMDocumentFragment** aInstancePtrResult,
|
|
|
|
nsNodeInfoManager *aNodeInfoManager)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG(aNodeInfoManager);
|
|
|
|
|
|
|
|
nsCOMPtr<nsINodeInfo> nodeInfo;
|
2008-09-12 15:32:18 -07:00
|
|
|
nodeInfo = aNodeInfoManager->GetNodeInfo(nsGkAtoms::documentFragmentNodeName,
|
2012-07-30 07:20:58 -07:00
|
|
|
nullptr, kNameSpaceID_None,
|
2011-06-14 00:56:49 -07:00
|
|
|
nsIDOMNode::DOCUMENT_FRAGMENT_NODE);
|
2008-09-25 15:46:52 -07:00
|
|
|
NS_ENSURE_TRUE(nodeInfo, NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
nsDocumentFragment *it = new nsDocumentFragment(nodeInfo.forget());
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aInstancePtrResult = it);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
nsDocumentFragment::nsDocumentFragment(already_AddRefed<nsINodeInfo> aNodeInfo)
|
2012-07-02 06:31:49 -07:00
|
|
|
: FragmentOrElement(aNodeInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-07-02 06:31:49 -07:00
|
|
|
NS_ABORT_IF_FALSE(mNodeInfo->NodeType() ==
|
|
|
|
nsIDOMNode::DOCUMENT_FRAGMENT_NODE &&
|
|
|
|
mNodeInfo->Equals(nsGkAtoms::documentFragmentNodeName,
|
|
|
|
kNameSpaceID_None),
|
|
|
|
"Bad NodeType in aNodeInfo");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDocumentFragment::IsNodeOfType(uint32_t aFlags) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return !(aFlags & ~(eCONTENT | eDOCUMENT_FRAGMENT));
|
|
|
|
}
|
|
|
|
|
2010-06-03 18:09:20 -07:00
|
|
|
nsIAtom*
|
|
|
|
nsDocumentFragment::DoGetID() const
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-03 18:09:20 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
nsDocumentFragment::GetIDAttributeName() const
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-03 18:09:20 -07:00
|
|
|
}
|
|
|
|
|
2012-07-02 06:31:49 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDocumentFragment::List(FILE* out, int32_t aIndent) const
|
2012-07-02 06:31:49 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t indent;
|
2012-07-02 06:31:49 -07:00
|
|
|
for (indent = aIndent; --indent >= 0; ) {
|
|
|
|
fputs(" ", out);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(out, "DocumentFragment@%p", (void *)this);
|
|
|
|
|
|
|
|
fprintf(out, " flags=[%08x]", static_cast<unsigned int>(GetFlags()));
|
|
|
|
fprintf(out, " refcount=%d<", mRefCnt.get());
|
|
|
|
|
|
|
|
nsIContent* child = GetFirstChild();
|
|
|
|
if (child) {
|
|
|
|
fputs("\n", out);
|
|
|
|
|
|
|
|
for (; child; child = child->GetNextSibling()) {
|
|
|
|
child->List(out, aIndent + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (indent = aIndent; --indent >= 0; ) {
|
|
|
|
fputs(" ", out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs(">\n", out);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsDocumentFragment::DumpContent(FILE* out, int32_t aIndent,
|
2012-07-02 06:31:49 -07:00
|
|
|
bool aDumpAll) const
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t indent;
|
2012-07-02 06:31:49 -07:00
|
|
|
for (indent = aIndent; --indent >= 0; ) {
|
|
|
|
fputs(" ", out);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs("<DocumentFragment>", out);
|
|
|
|
|
|
|
|
if(aIndent) {
|
|
|
|
fputs("\n", out);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (nsIContent* child = GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t indent = aIndent ? aIndent + 1 : 0;
|
2012-07-02 06:31:49 -07:00
|
|
|
child->DumpContent(out, indent, aDumpAll);
|
|
|
|
}
|
|
|
|
for (indent = aIndent; --indent >= 0; ) {
|
|
|
|
fputs(" ", out);
|
|
|
|
}
|
|
|
|
fputs("</DocumentFragment>", out);
|
|
|
|
|
|
|
|
if(aIndent) {
|
|
|
|
fputs("\n", out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
DOMCI_NODE_DATA(DocumentFragment, nsDocumentFragment)
|
2010-01-12 05:08:43 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// QueryInterface implementation for nsDocumentFragment
|
2012-05-18 01:29:38 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsDocumentFragment)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsDocumentFragment)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIContent)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsINode)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMDocumentFragment)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMEventTarget)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsISupportsWeakReference,
|
|
|
|
new nsNodeSupportsWeakRefTearoff(this))
|
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOMNodeSelector,
|
|
|
|
new nsNodeSelectorTearoff(this))
|
|
|
|
// nsNodeSH::PreCreate() depends on the identity pointer being the
|
|
|
|
// same as nsINode (which nsIContent inherits), so if you change the
|
|
|
|
// below line, make sure nsNodeSH::PreCreate() still does the right
|
|
|
|
// thing!
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIContent)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(DocumentFragment)
|
2012-05-18 01:29:38 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-07-02 06:31:49 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsDocumentFragment, FragmentOrElement)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsDocumentFragment, FragmentOrElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMPL_ELEMENT_CLONE(nsDocumentFragment)
|