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
|
|
|
|
|
|
|
/*
|
|
|
|
* Base class for DOM Core's nsIDOMComment, nsIDOMDocumentType, nsIDOMText,
|
|
|
|
* nsIDOMCDATASection, and nsIDOMProcessingInstruction nodes.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsGenericDOMDataNode_h___
|
|
|
|
#define nsGenericDOMDataNode_h___
|
|
|
|
|
2009-07-26 15:05:41 -07:00
|
|
|
#include "nsIContent.h"
|
2011-08-11 06:29:50 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsTextFragment.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2011-06-23 19:18:01 -07:00
|
|
|
#include "nsEventListenerManager.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGenericElement.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
|
2009-01-14 20:38:07 -08:00
|
|
|
#include "nsISMILAttr.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsIDOMAttr;
|
|
|
|
class nsIDOMEventListener;
|
|
|
|
class nsIDOMNodeList;
|
|
|
|
class nsIFrame;
|
|
|
|
class nsIDOMText;
|
|
|
|
class nsINodeInfo;
|
|
|
|
class nsURI;
|
|
|
|
|
2012-10-01 17:52:06 -07:00
|
|
|
#define DATA_NODE_FLAG_BIT(n_) NODE_FLAG_BIT(NODE_TYPE_SPECIFIC_BITS_OFFSET + (n_))
|
|
|
|
|
|
|
|
// Data node specific flags
|
|
|
|
enum {
|
|
|
|
// This bit is set to indicate that if the text node changes to
|
|
|
|
// non-whitespace, we may need to create a frame for it. This bit must
|
|
|
|
// not be set on nodes that already have a frame.
|
|
|
|
NS_CREATE_FRAME_IF_NON_WHITESPACE = DATA_NODE_FLAG_BIT(0),
|
|
|
|
|
|
|
|
// This bit is set to indicate that if the text node changes to
|
|
|
|
// whitespace, we may need to reframe it (or its ancestors).
|
|
|
|
NS_REFRAME_IF_WHITESPACE = DATA_NODE_FLAG_BIT(1)
|
|
|
|
};
|
|
|
|
|
|
|
|
// Make sure we have enough space for those bits
|
|
|
|
PR_STATIC_ASSERT(NODE_TYPE_SPECIFIC_BITS_OFFSET + 1 < 32);
|
|
|
|
|
2012-10-03 14:32:34 -07:00
|
|
|
#undef DATA_NODE_FLAG_BIT
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
class nsGenericDOMDataNode : public nsIContent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
|
2012-02-01 13:58:01 -08:00
|
|
|
NS_DECL_SIZEOF_EXCLUDING_THIS
|
2011-07-19 10:04:09 -07:00
|
|
|
|
2010-07-23 02:49:57 -07:00
|
|
|
nsGenericDOMDataNode(already_AddRefed<nsINodeInfo> aNodeInfo);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual ~nsGenericDOMDataNode();
|
|
|
|
|
2012-10-09 05:31:24 -07:00
|
|
|
virtual void GetNodeValueInternal(nsAString& aNodeValue);
|
|
|
|
virtual void SetNodeValueInternal(const nsAString& aNodeValue,
|
|
|
|
mozilla::ErrorResult& aError);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Implementation for nsIDOMCharacterData
|
|
|
|
nsresult GetData(nsAString& aData) const;
|
|
|
|
nsresult SetData(const nsAString& aData);
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult GetLength(uint32_t* aLength);
|
|
|
|
nsresult SubstringData(uint32_t aOffset, uint32_t aCount,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAString& aReturn);
|
|
|
|
nsresult AppendData(const nsAString& aArg);
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult InsertData(uint32_t aOffset, const nsAString& aArg);
|
|
|
|
nsresult DeleteData(uint32_t aOffset, uint32_t aCount);
|
|
|
|
nsresult ReplaceData(uint32_t aOffset, uint32_t aCount,
|
2007-03-22 10:30:00 -07:00
|
|
|
const nsAString& aArg);
|
|
|
|
|
|
|
|
// nsINode methods
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual uint32_t GetChildCount() const;
|
|
|
|
virtual nsIContent *GetChildAt(uint32_t aIndex) const;
|
|
|
|
virtual nsIContent * const * GetChildArray(uint32_t* aChildCount) const;
|
2012-10-09 05:31:24 -07:00
|
|
|
virtual int32_t IndexOf(const nsINode* aPossibleChild) const;
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual nsresult InsertChildAt(nsIContent* aKid, uint32_t aIndex,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify);
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual void RemoveChildAt(uint32_t aIndex, bool aNotify);
|
2012-10-09 05:31:24 -07:00
|
|
|
virtual void GetTextContentInternal(nsAString& aTextContent)
|
2010-04-19 08:41:33 -07:00
|
|
|
{
|
2012-10-09 05:31:24 -07:00
|
|
|
GetNodeValue(aTextContent);
|
2010-04-19 08:41:33 -07:00
|
|
|
}
|
2012-10-09 05:31:24 -07:00
|
|
|
virtual void SetTextContentInternal(const nsAString& aTextContent,
|
|
|
|
mozilla::ErrorResult& aError)
|
2010-04-19 08:41:33 -07:00
|
|
|
{
|
|
|
|
// Batch possible DOMSubtreeModified events.
|
2012-07-30 07:20:58 -07:00
|
|
|
mozAutoSubtreeModified subtree(OwnerDoc(), nullptr);
|
2012-10-09 05:31:24 -07:00
|
|
|
return SetNodeValue(aTextContent, aError);
|
2010-04-19 08:41:33 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Implementation for nsIContent
|
|
|
|
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCompileEventHandlers);
|
|
|
|
virtual void UnbindFromTree(bool aDeep = true,
|
|
|
|
bool aNullParent = true);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual already_AddRefed<nsINodeList> GetChildren(uint32_t aFilter);
|
2010-02-11 09:34:01 -08:00
|
|
|
|
2007-07-26 07:16:19 -07:00
|
|
|
virtual nsIAtom *GetIDAttributeName() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual already_AddRefed<nsINodeInfo> GetExistingAttrNameFromQName(const nsAString& aStr) const;
|
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* aAttribute,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIAtom* aPrefix, const nsAString& aValue,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify);
|
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);
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool GetAttr(int32_t aNameSpaceID, nsIAtom *aAttribute,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsAString& aResult) const;
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool HasAttr(int32_t aNameSpaceID, nsIAtom *aAttribute) const;
|
|
|
|
virtual const nsAttrName* GetAttrNameAt(uint32_t aIndex) const;
|
|
|
|
virtual uint32_t GetAttrCount() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual const nsTextFragment *GetText();
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual uint32_t TextLength() const;
|
|
|
|
virtual nsresult SetText(const PRUnichar* aBuffer, uint32_t aLength,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify);
|
2007-03-22 10:30:00 -07:00
|
|
|
// Need to implement this here too to avoid hiding.
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult SetText(const nsAString& aStr, bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return SetText(aStr.BeginReading(), aStr.Length(), aNotify);
|
|
|
|
}
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual nsresult AppendText(const PRUnichar* aBuffer, uint32_t aLength,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify);
|
|
|
|
virtual bool TextIsOnlyWhitespace();
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual void AppendTextTo(nsAString& aResult);
|
2007-11-30 09:57:03 -08:00
|
|
|
virtual void DestroyContent();
|
2008-04-10 15:47:01 -07:00
|
|
|
virtual void SaveSubtreeState();
|
2009-01-14 20:38:07 -08:00
|
|
|
|
2007-03-22 10:30:00 -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;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual nsIContent *GetBindingParent() const;
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual bool IsNodeOfType(uint32_t aFlags) const;
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool IsLink(nsIURI** aURI) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-06-03 18:09:20 -07:00
|
|
|
virtual nsIAtom* DoGetID() const;
|
2008-09-10 20:22:20 -07:00
|
|
|
virtual const nsAttrValue* DoGetClasses() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD WalkContentStyleRules(nsRuleWalker* aRuleWalker);
|
2011-09-28 23:19:26 -07:00
|
|
|
NS_IMETHOD_(bool) IsAttributeMapped(const nsIAtom* aAttribute) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual nsChangeHint GetAttributeChangeHint(const nsIAtom* aAttribute,
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t aModType) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual nsIAtom *GetClassAttributeName() const;
|
|
|
|
|
|
|
|
virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
*aResult = CloneDataNode(aNodeInfo, true);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!*aResult) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult SplitData(uint32_t aOffset, nsIContent** aReturn,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCloneAfterOriginal = true);
|
2008-07-25 03:37:37 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//----------------------------------------
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2012-08-22 08:56:38 -07:00
|
|
|
void ToCString(nsAString& aBuf, int32_t aOffset, int32_t aLen) const;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2012-01-30 12:08:13 -08:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SKIPPABLE_SCRIPT_HOLDER_CLASS(nsGenericDOMDataNode)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
protected:
|
2010-04-19 08:40:16 -07:00
|
|
|
virtual mozilla::dom::Element* GetNameSpaceElement()
|
|
|
|
{
|
2012-10-09 05:31:24 -07:00
|
|
|
nsINode *parent = GetParentNode();
|
2010-04-19 08:40:16 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return parent && parent->IsElement() ? parent->AsElement() : nullptr;
|
2010-04-19 08:40:16 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* There are a set of DOM- and scripting-specific instance variables
|
|
|
|
* that may only be instantiated when a content object is accessed
|
|
|
|
* through the DOM. Rather than burn actual slots in the content
|
|
|
|
* objects for each of these instance variables, we put them off
|
|
|
|
* in a side structure that's only allocated when the content is
|
|
|
|
* accessed through the DOM.
|
|
|
|
*/
|
|
|
|
class nsDataSlots : public nsINode::nsSlots
|
|
|
|
{
|
|
|
|
public:
|
2011-04-07 19:29:49 -07:00
|
|
|
nsDataSlots()
|
|
|
|
: nsINode::nsSlots(),
|
2012-07-30 07:20:58 -07:00
|
|
|
mBindingParent(nullptr)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The nearest enclosing content node with a binding that created us.
|
|
|
|
* @see nsIContent::GetBindingParent
|
|
|
|
*/
|
|
|
|
nsIContent* mBindingParent; // [Weak]
|
|
|
|
};
|
|
|
|
|
|
|
|
// Override from nsINode
|
|
|
|
virtual nsINode::nsSlots* CreateSlots();
|
|
|
|
|
2012-08-10 15:27:28 -07:00
|
|
|
nsDataSlots* DataSlots()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-10 15:27:28 -07:00
|
|
|
return static_cast<nsDataSlots*>(Slots());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDataSlots *GetExistingDataSlots() const
|
|
|
|
{
|
2007-07-08 00:08:04 -07:00
|
|
|
return static_cast<nsDataSlots*>(GetExistingSlots());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult SplitText(uint32_t aOffset, nsIDOMText** aReturn);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-20 22:21:28 -07:00
|
|
|
nsresult GetWholeText(nsAString& aWholeText);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t FirstLogicallyAdjacentTextNode(nsIContent* aParent,
|
|
|
|
int32_t aIndex);
|
2008-06-04 10:53:34 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static int32_t LastLogicallyAdjacentTextNode(nsIContent* aParent,
|
|
|
|
int32_t aIndex,
|
|
|
|
uint32_t aCount);
|
2008-06-04 10:53:34 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult SetTextInternal(uint32_t aOffset, uint32_t aCount,
|
|
|
|
const PRUnichar* aBuffer, uint32_t aLength,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aNotify,
|
2012-07-30 07:20:58 -07:00
|
|
|
CharacterDataChangeInfo::Details* aDetails = nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Method to clone this node. This needs to be overriden by all derived
|
|
|
|
* classes. If aCloneText is true the text content will be cloned too.
|
|
|
|
*
|
|
|
|
* @param aOwnerDocument the ownerDocument of the clone
|
|
|
|
* @param aCloneText if true the text content will be cloned too
|
|
|
|
* @return the clone
|
|
|
|
*/
|
|
|
|
virtual nsGenericDOMDataNode *CloneDataNode(nsINodeInfo *aNodeInfo,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool aCloneText) const = 0;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsTextFragment mText;
|
|
|
|
|
2012-01-30 12:08:13 -08:00
|
|
|
public:
|
2012-06-27 15:09:15 -07:00
|
|
|
virtual bool OwnedOnlyByTheDOMTree()
|
|
|
|
{
|
|
|
|
return GetParent() && mRefCnt.get() == 1;
|
|
|
|
}
|
|
|
|
|
2012-01-30 12:08:13 -08:00
|
|
|
virtual bool IsPurple()
|
|
|
|
{
|
|
|
|
return mRefCnt.IsPurple();
|
|
|
|
}
|
|
|
|
virtual void RemovePurple()
|
|
|
|
{
|
|
|
|
mRefCnt.RemovePurple();
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
already_AddRefed<nsIAtom> GetCurrentValueAtom();
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsGenericDOMDataNode_h___ */
|