2001-09-25 01:32:19 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-17 21:52:36 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-09-06 00:16:36 +00:00
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1998-09-06 00:16:36 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1998-09-06 00:16:36 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
2004-04-17 21:52:36 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 01:32:19 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-25 01:32:19 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-17 21:52:36 +00:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 01:32:19 +00:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-17 21:52:36 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 01:32:19 +00:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-17 21:52:36 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 01:32:19 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-03-31 20:49:25 +00:00
|
|
|
|
2006-03-31 08:41:49 +00:00
|
|
|
/*
|
|
|
|
* Implementation of DOM Core's nsIDOMText node.
|
|
|
|
*/
|
|
|
|
|
2008-10-15 09:40:28 +00:00
|
|
|
#include "nsTextNode.h"
|
2008-06-04 17:53:34 +00:00
|
|
|
#include "nsIDOM3Text.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
#include "nsContentUtils.h"
|
2004-01-27 04:22:58 +00:00
|
|
|
#include "nsIDOMEventListener.h"
|
|
|
|
#include "nsIDOMEventTarget.h"
|
|
|
|
#include "nsIDOMMutationEvent.h"
|
|
|
|
#include "nsIAttribute.h"
|
2004-08-10 10:22:36 +00:00
|
|
|
#include "nsIDocument.h"
|
2006-09-20 03:17:11 +00:00
|
|
|
#include "nsThreadUtils.h"
|
2004-01-27 04:22:58 +00:00
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
|
2004-01-27 04:22:58 +00:00
|
|
|
/**
|
|
|
|
* class used to implement attr() generated content
|
|
|
|
*/
|
2006-09-20 03:17:11 +00:00
|
|
|
class nsAttributeTextNode : public nsTextNode,
|
|
|
|
public nsStubMutationObserver
|
|
|
|
{
|
2004-01-27 04:22:58 +00:00
|
|
|
public:
|
2006-09-20 03:17:11 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
2004-01-27 04:22:58 +00:00
|
|
|
|
2006-09-20 03:17:11 +00:00
|
|
|
nsAttributeTextNode(nsINodeInfo *aNodeInfo,
|
|
|
|
PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttrName) :
|
|
|
|
nsTextNode(aNodeInfo),
|
2008-08-18 01:16:42 +00:00
|
|
|
mGrandparent(nsnull),
|
2006-09-20 03:17:11 +00:00
|
|
|
mNameSpaceID(aNameSpaceID),
|
|
|
|
mAttrName(aAttrName)
|
2005-09-24 18:43:15 +00:00
|
|
|
{
|
2006-09-20 03:17:11 +00:00
|
|
|
NS_ASSERTION(mNameSpaceID != kNameSpaceID_Unknown, "Must know namespace");
|
|
|
|
NS_ASSERTION(mAttrName, "Must have attr name");
|
2004-08-10 10:22:36 +00:00
|
|
|
}
|
2006-09-20 03:17:11 +00:00
|
|
|
|
2004-01-27 04:22:58 +00:00
|
|
|
virtual ~nsAttributeTextNode() {
|
2008-08-18 01:16:42 +00:00
|
|
|
NS_ASSERTION(!mGrandparent, "We were not unbound!");
|
2004-01-27 04:22:58 +00:00
|
|
|
}
|
2005-04-05 23:54:35 +00:00
|
|
|
|
|
|
|
virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
PRBool aCompileEventHandlers);
|
|
|
|
virtual void UnbindFromTree(PRBool aDeep = PR_TRUE,
|
|
|
|
PRBool aNullParent = PR_TRUE);
|
2004-01-27 04:22:58 +00:00
|
|
|
|
2007-07-12 20:05:45 +00:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_ATTRIBUTECHANGED
|
2008-10-08 11:13:26 +00:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
|
2006-09-20 03:17:11 +00:00
|
|
|
|
2006-09-05 10:22:54 +00:00
|
|
|
virtual nsGenericDOMDataNode *CloneDataNode(nsINodeInfo *aNodeInfo,
|
|
|
|
PRBool aCloneText) const
|
2005-09-11 17:15:08 +00:00
|
|
|
{
|
2006-09-20 03:17:11 +00:00
|
|
|
nsAttributeTextNode *it = new nsAttributeTextNode(aNodeInfo,
|
|
|
|
mNameSpaceID,
|
|
|
|
mAttrName);
|
2005-09-11 17:15:08 +00:00
|
|
|
if (it && aCloneText) {
|
|
|
|
it->mText = mText;
|
|
|
|
}
|
|
|
|
|
|
|
|
return it;
|
|
|
|
}
|
|
|
|
|
2006-09-20 03:17:11 +00:00
|
|
|
// Public method for the event to run
|
|
|
|
void UpdateText() {
|
|
|
|
UpdateText(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
2004-01-27 04:22:58 +00:00
|
|
|
private:
|
2006-09-20 03:17:11 +00:00
|
|
|
// Update our text to our parent's current attr value
|
|
|
|
void UpdateText(PRBool aNotify);
|
|
|
|
|
2008-08-18 01:16:42 +00:00
|
|
|
// This doesn't need to be a strong pointer because it's only non-null
|
|
|
|
// while we're bound to the document tree, and it points to an ancestor
|
|
|
|
// so the ancestor must be bound to the document tree the whole time
|
|
|
|
// and can't be deleted.
|
|
|
|
nsIContent* mGrandparent;
|
2006-09-20 03:17:11 +00:00
|
|
|
// What attribute we're showing
|
|
|
|
PRInt32 mNameSpaceID;
|
|
|
|
nsCOMPtr<nsIAtom> mAttrName;
|
2004-01-27 04:22:58 +00:00
|
|
|
};
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
nsresult
|
2006-07-19 04:36:36 +00:00
|
|
|
NS_NewTextNode(nsIContent** aInstancePtrResult,
|
2005-09-24 18:43:15 +00:00
|
|
|
nsNodeInfoManager *aNodeInfoManager)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2005-09-24 18:43:15 +00:00
|
|
|
NS_PRECONDITION(aNodeInfoManager, "Missing nodeInfoManager");
|
|
|
|
|
2004-08-10 10:22:36 +00:00
|
|
|
*aInstancePtrResult = nsnull;
|
|
|
|
|
2005-09-24 18:43:15 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> ni = aNodeInfoManager->GetTextNodeInfo();
|
|
|
|
if (!ni) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2006-07-19 04:36:36 +00:00
|
|
|
nsIContent *instance = new nsTextNode(ni);
|
2005-09-24 18:43:15 +00:00
|
|
|
if (!instance) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2004-08-10 10:22:36 +00:00
|
|
|
|
2005-09-24 18:43:15 +00:00
|
|
|
NS_ADDREF(*aInstancePtrResult = instance);
|
2001-12-16 06:59:31 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2005-09-24 18:43:15 +00:00
|
|
|
nsTextNode::nsTextNode(nsINodeInfo *aNodeInfo)
|
2010-04-19 15:40:16 +00:00
|
|
|
: nsGenericTextNode(aNodeInfo)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsTextNode::~nsTextNode()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsTextNode, nsGenericDOMDataNode)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsTextNode, nsGenericDOMDataNode)
|
1998-09-06 00:16:36 +00:00
|
|
|
|
2010-01-12 13:08:43 +00:00
|
|
|
DOMCI_DATA(Text, nsTextNode)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
|
|
|
// QueryInterface implementation for nsTextNode
|
2008-11-03 10:31:47 +00:00
|
|
|
NS_INTERFACE_TABLE_HEAD(nsTextNode)
|
|
|
|
NS_NODE_INTERFACE_TABLE3(nsTextNode, nsIDOMNode, nsIDOMText,
|
|
|
|
nsIDOMCharacterData)
|
2008-06-04 17:53:34 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRY_TEAROFF(nsIDOM3Text, new nsText3Tearoff(this))
|
2008-11-03 10:31:47 +00:00
|
|
|
NS_INTERFACE_MAP_ENTRIES_CYCLE_COLLECTION(nsTextNode)
|
2010-03-17 15:09:05 +00:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(Text)
|
2001-12-16 06:59:31 +00:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsGenericDOMDataNode)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 16:46:42 +00:00
|
|
|
|
1999-01-19 23:07:33 +00:00
|
|
|
NS_IMETHODIMP
|
2002-03-23 23:54:46 +00:00
|
|
|
nsTextNode::GetNodeName(nsAString& aNodeName)
|
1999-01-19 23:07:33 +00:00
|
|
|
{
|
2004-06-17 00:13:25 +00:00
|
|
|
aNodeName.AssignLiteral("#text");
|
1999-01-19 23:07:33 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-10-30 12:24:28 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextNode::GetNodeValue(nsAString& aNodeValue)
|
|
|
|
{
|
|
|
|
return nsGenericDOMDataNode::GetNodeValue(aNodeValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextNode::SetNodeValue(const nsAString& aNodeValue)
|
|
|
|
{
|
|
|
|
return nsGenericDOMDataNode::SetNodeValue(aNodeValue);
|
|
|
|
}
|
|
|
|
|
1998-09-06 00:16:36 +00:00
|
|
|
NS_IMETHODIMP
|
1998-10-20 17:07:23 +00:00
|
|
|
nsTextNode::GetNodeType(PRUint16* aNodeType)
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
1998-10-20 17:07:23 +00:00
|
|
|
*aNodeType = (PRUint16)nsIDOMNode::TEXT_NODE;
|
1998-09-06 00:16:36 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-09-11 17:15:08 +00:00
|
|
|
PRBool
|
2006-05-05 06:52:21 +00:00
|
|
|
nsTextNode::IsNodeOfType(PRUint32 aFlags) const
|
1998-09-06 00:16:36 +00:00
|
|
|
{
|
2006-07-19 04:36:36 +00:00
|
|
|
return !(aFlags & ~(eCONTENT | eTEXT | eDATA_NODE));
|
1998-09-06 00:16:36 +00:00
|
|
|
}
|
|
|
|
|
2005-09-11 17:15:08 +00:00
|
|
|
nsGenericDOMDataNode*
|
2006-09-05 10:22:54 +00:00
|
|
|
nsTextNode::CloneDataNode(nsINodeInfo *aNodeInfo, PRBool aCloneText) const
|
1999-12-22 01:51:58 +00:00
|
|
|
{
|
2005-09-24 18:43:15 +00:00
|
|
|
nsTextNode *it = new nsTextNode(aNodeInfo);
|
2005-09-11 17:15:08 +00:00
|
|
|
if (it && aCloneText) {
|
2001-12-16 06:59:31 +00:00
|
|
|
it->mText = mText;
|
1999-12-22 01:51:58 +00:00
|
|
|
}
|
2001-12-16 06:59:31 +00:00
|
|
|
|
2004-05-07 20:55:17 +00:00
|
|
|
return it;
|
2001-12-16 06:59:31 +00:00
|
|
|
}
|
|
|
|
|
2008-10-15 09:40:28 +00:00
|
|
|
nsresult
|
|
|
|
nsTextNode::BindToAttribute(nsIAttribute* aAttr)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!IsInDoc(), "Unbind before binding!");
|
|
|
|
NS_ASSERTION(!GetNodeParent(), "Unbind before binding!");
|
|
|
|
NS_ASSERTION(HasSameOwnerDoc(aAttr), "Wrong owner document!");
|
|
|
|
|
|
|
|
mParentPtrBits = reinterpret_cast<PtrBits>(aAttr);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsTextNode::UnbindFromAttribute()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(GetNodeParent(), "Bind before unbinging!");
|
|
|
|
NS_ASSERTION(GetNodeParent() &&
|
|
|
|
GetNodeParent()->IsNodeOfType(nsINode::eATTRIBUTE),
|
|
|
|
"Use this method only to unbind from an attribute!");
|
|
|
|
mParentPtrBits = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-10-16 05:31:36 +00:00
|
|
|
#ifdef DEBUG
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
1998-09-06 00:16:36 +00:00
|
|
|
nsTextNode::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
2010-01-17 23:11:02 +00:00
|
|
|
fprintf(out, "Text@%p", static_cast<const void*>(this));
|
2007-06-28 02:48:16 +00:00
|
|
|
fprintf(out, " intrinsicstate=[%08x]", IntrinsicState());
|
2010-05-12 03:01:08 +00:00
|
|
|
fprintf(out, " flags=[%08x]", GetFlags());
|
2010-05-01 18:42:47 +00:00
|
|
|
fprintf(out, " primaryframe=%p", static_cast<void*>(GetPrimaryFrame()));
|
2007-06-28 02:48:16 +00:00
|
|
|
fprintf(out, " refcount=%d<", mRefCnt.get());
|
1998-09-06 00:16:36 +00:00
|
|
|
|
|
|
|
nsAutoString tmp;
|
2001-12-16 06:59:31 +00:00
|
|
|
ToCString(tmp, 0, mText.GetLength());
|
2006-02-03 14:18:39 +00:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
|
1998-09-06 00:16:36 +00:00
|
|
|
|
|
|
|
fputs(">\n", out);
|
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
void
|
2001-12-16 06:59:31 +00:00
|
|
|
nsTextNode::DumpContent(FILE* out, PRInt32 aIndent, PRBool aDumpAll) const
|
2000-05-26 19:45:37 +00:00
|
|
|
{
|
|
|
|
if(aDumpAll) {
|
|
|
|
PRInt32 index;
|
|
|
|
for (index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
nsAutoString tmp;
|
2001-12-16 06:59:31 +00:00
|
|
|
ToCString(tmp, 0, mText.GetLength());
|
|
|
|
|
2004-05-22 22:15:22 +00:00
|
|
|
if(!tmp.EqualsLiteral("\\n")) {
|
2006-02-03 14:18:39 +00:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(tmp).get(), out);
|
2000-05-26 19:45:37 +00:00
|
|
|
if(aIndent) fputs("\n", out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-10-16 05:31:36 +00:00
|
|
|
#endif
|
2004-01-27 04:22:58 +00:00
|
|
|
|
|
|
|
nsresult
|
2005-09-24 18:43:15 +00:00
|
|
|
NS_NewAttributeContent(nsNodeInfoManager *aNodeInfoManager,
|
|
|
|
PRInt32 aNameSpaceID, nsIAtom* aAttrName,
|
|
|
|
nsIContent** aResult)
|
2004-01-27 04:22:58 +00:00
|
|
|
{
|
2005-09-24 18:43:15 +00:00
|
|
|
NS_PRECONDITION(aNodeInfoManager, "Missing nodeInfoManager");
|
2004-01-27 04:22:58 +00:00
|
|
|
NS_PRECONDITION(aAttrName, "Must have an attr name");
|
|
|
|
NS_PRECONDITION(aNameSpaceID != kNameSpaceID_Unknown, "Must know namespace");
|
|
|
|
|
|
|
|
*aResult = nsnull;
|
2005-09-11 17:15:08 +00:00
|
|
|
|
2005-09-24 18:43:15 +00:00
|
|
|
nsCOMPtr<nsINodeInfo> ni = aNodeInfoManager->GetTextNodeInfo();
|
|
|
|
if (!ni) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2006-09-20 03:17:11 +00:00
|
|
|
nsAttributeTextNode* textNode = new nsAttributeTextNode(ni, aNameSpaceID,
|
|
|
|
aAttrName);
|
2005-09-24 18:43:15 +00:00
|
|
|
if (!textNode) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2004-01-27 04:22:58 +00:00
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
NS_ADDREF(*aResult = textNode);
|
2005-09-24 18:43:15 +00:00
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2004-01-27 04:22:58 +00:00
|
|
|
|
2006-09-20 03:17:11 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED1(nsAttributeTextNode, nsTextNode,
|
|
|
|
nsIMutationObserver)
|
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
nsresult
|
|
|
|
nsAttributeTextNode::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
PRBool aCompileEventHandlers)
|
|
|
|
{
|
2008-08-18 01:16:42 +00:00
|
|
|
NS_PRECONDITION(aParent && aParent->GetParent(),
|
|
|
|
"This node can't be a child of the document or of the document root");
|
2004-01-27 04:22:58 +00:00
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
nsresult rv = nsTextNode::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent, aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2008-08-18 01:16:42 +00:00
|
|
|
NS_ASSERTION(!mGrandparent, "We were already bound!");
|
|
|
|
mGrandparent = aParent->GetParent();
|
|
|
|
mGrandparent->AddMutationObserver(this);
|
2006-09-20 03:17:11 +00:00
|
|
|
|
|
|
|
// Note that there is no need to notify here, since we have no
|
|
|
|
// frame yet at this point.
|
|
|
|
UpdateText(PR_FALSE);
|
2004-01-27 04:22:58 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-05 23:54:35 +00:00
|
|
|
void
|
|
|
|
nsAttributeTextNode::UnbindFromTree(PRBool aDeep, PRBool aNullParent)
|
|
|
|
{
|
2008-08-18 01:16:42 +00:00
|
|
|
// UnbindFromTree can be called anytime so we have to be safe.
|
|
|
|
if (mGrandparent) {
|
|
|
|
// aNullParent might not be true here, but we want to remove the
|
|
|
|
// mutation observer anyway since we only need it while we're
|
|
|
|
// in the document.
|
|
|
|
mGrandparent->RemoveMutationObserver(this);
|
|
|
|
mGrandparent = nsnull;
|
2005-04-05 23:54:35 +00:00
|
|
|
}
|
|
|
|
nsTextNode::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
}
|
|
|
|
|
2004-01-27 04:22:58 +00:00
|
|
|
void
|
2006-09-20 03:17:11 +00:00
|
|
|
nsAttributeTextNode::AttributeChanged(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContent,
|
|
|
|
PRInt32 aNameSpaceID,
|
|
|
|
nsIAtom* aAttribute,
|
2009-12-10 22:36:04 +00:00
|
|
|
PRInt32 aModType)
|
2004-01-27 04:22:58 +00:00
|
|
|
{
|
2006-09-20 03:17:11 +00:00
|
|
|
if (aNameSpaceID == mNameSpaceID && aAttribute == mAttrName &&
|
2008-08-18 01:16:42 +00:00
|
|
|
aContent == mGrandparent) {
|
2006-09-20 03:17:11 +00:00
|
|
|
// Since UpdateText notifies, do it asynchronously. Note that if we get
|
2008-08-18 01:16:42 +00:00
|
|
|
// unbound while the event is up that's ok -- we'll just have no
|
|
|
|
// grandparent when it fires, and will do nothing.
|
2006-09-20 03:17:11 +00:00
|
|
|
// XXXbz ideally we'd either process this on layout flushes or do it right
|
|
|
|
// after nsIMutationObserver notifications are over or something, instead
|
|
|
|
// of doing it fully async.
|
2010-04-20 23:21:35 +00:00
|
|
|
void (nsAttributeTextNode::*update)() = &nsAttributeTextNode::UpdateText;
|
|
|
|
nsCOMPtr<nsIRunnable> ev = NS_NewRunnableMethod(this, update);
|
2006-09-20 03:17:11 +00:00
|
|
|
NS_DispatchToCurrentThread(ev);
|
|
|
|
}
|
|
|
|
}
|
2004-01-27 04:22:58 +00:00
|
|
|
|
2008-10-08 11:13:26 +00:00
|
|
|
void
|
|
|
|
nsAttributeTextNode::NodeWillBeDestroyed(const nsINode* aNode)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aNode == static_cast<nsINode*>(mGrandparent), "Wrong node!");
|
|
|
|
mGrandparent = nsnull;
|
|
|
|
}
|
|
|
|
|
2006-09-20 03:17:11 +00:00
|
|
|
void
|
|
|
|
nsAttributeTextNode::UpdateText(PRBool aNotify)
|
|
|
|
{
|
2008-08-18 01:16:42 +00:00
|
|
|
if (mGrandparent) {
|
2006-09-20 03:17:11 +00:00
|
|
|
nsAutoString attrValue;
|
2008-08-18 01:16:42 +00:00
|
|
|
mGrandparent->GetAttr(mNameSpaceID, mAttrName, attrValue);
|
2006-09-20 03:17:11 +00:00
|
|
|
SetText(attrValue, aNotify);
|
|
|
|
}
|
|
|
|
}
|