Mozilla/mozilla/layout/html/table/src/nsTableContent.cpp
vidur%netscape.com 5e856a67d9 Added nsIJSScriptObject interface to nsGenericHTMLContent class and fixed element.childNodes
git-svn-id: svn://10.0.0.236/trunk@9669 18797224-902f-48f8-a5cc-f745e15eee43
1998-09-09 21:02:42 +00:00

254 lines
6.0 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsTableContent.h"
#include "nsITableContent.h"
#include "nsString.h"
const int nsITableContent::kTableRowGroupType=1;
const int nsITableContent::kTableRowType=2;
const int nsITableContent::kTableColGroupType=3;
const int nsITableContent::kTableColType=4;
const int nsITableContent::kTableCaptionType=5;
const int nsITableContent::kTableCellType=6;
#ifdef NS_DEBUG
static PRBool gsDebug = PR_FALSE;
static PRBool gsNoisyRefs = PR_FALSE;
#else
static const PRBool gsDebug = PR_FALSE;
static const PRBool gsNoisyRefs = PR_FALSE;
#endif
static NS_DEFINE_IID(kITableContentIID, NS_ITABLECONTENT_IID);
/**
* default contstructor
*/
nsTableContent::nsTableContent (nsIAtom* aTag)
: nsHTMLContainer(aTag)
{
mTable = nsnull;
}
nsTableContent::~nsTableContent ()
{
}
/**
*/
nsTableContent::nsTableContent (nsIAtom* aTag, PRBool aImplicit)
: nsHTMLContainer(aTag),
mImplicit(aImplicit)
{
}
nsrefcnt nsTableContent::AddRef(void)
{
if (gsNoisyRefs==PR_TRUE) printf("Add Ref: nsTableContent %d - %p cnt = %d \n",
GetType(), this, mRefCnt+1);
return ++mRefCnt;
}
nsrefcnt nsTableContent::Release(void)
{
if (gsNoisyRefs==PR_TRUE) printf("Release: nsTableContent %d - %p cnt = %d \n",
GetType(), this, mRefCnt-1);
if (--mRefCnt == 0) {
if (gsNoisyRefs==PR_TRUE) printf("Delete: nsTableContent \n");
delete this;
return 0;
}
return mRefCnt;
}
nsresult nsTableContent::QueryInterface(const nsIID& aIID,
void** aInstancePtrResult)
{
NS_PRECONDITION(nsnull != aInstancePtrResult, "null pointer");
if (nsnull == aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kITableContentIID)) {
*aInstancePtrResult = (void*) ((nsITableContent*)this);
AddRef();
return NS_OK;
}
return nsHTMLTagContent::QueryInterface(aIID, aInstancePtrResult);
}
/**
* Don't want to put out implicit tags when saving.
*/
PRBool nsTableContent::SkipSelfForSaving()
{
return mImplicit;
}
nsTablePart* nsTableContent::GetTable ()
{
NS_IF_ADDREF(mTable);
return mTable;
}
void nsTableContent::SetTableForChildren(nsTablePart *aTable)
{
if (aTable != nsnull)
{
PRInt32 count;
ChildCount(count);
for (PRInt32 index = 0; index < count; index++)
{
nsIContent* child;
ChildAt(index, child);
SetTableForTableContent(child,aTable);
NS_RELEASE(child);
}
}
}
void nsTableContent::SetTable (nsTablePart *aTable)
{
// Check to see if the current table was null, if it was, then call
// method to reset children
if (mTable == nsnull)
SetTableForChildren(aTable);
mTable = aTable;
}
NS_METHOD nsTableContent::IsSynthetic(PRBool& aResult)
{
aResult = mImplicit;
return NS_OK;
}
/**
* If the content is a nsTableContent then call SetTable on
* aContent, otherwise, do nothing.
*/
void nsTableContent::SetTableForTableContent(nsIContent* aContent, nsTablePart *aTable)
{
if (aContent != nsnull)
{
nsITableContent* tableContent;
nsresult result = aContent->QueryInterface(kITableContentIID, (void**) &tableContent);
if (NS_OK == result)
{
tableContent->SetTable(aTable);
NS_IF_RELEASE(tableContent);
}
}
}
/* ----- overridable methods from nsHTMLContainer ----- */
NS_IMETHODIMP
nsTableContent::List(FILE* out, PRInt32 aIndent) const
{
PRInt32 i;
for (i = aIndent; --i >= 0; ) fputs(" ", out);
nsIAtom* tag;
GetTag(tag);
if (tag != nsnull) {
nsAutoString buf;
tag->ToString(buf);
fputs(buf, out);
NS_RELEASE(tag);
}
char *isImplicitString = "";
if (PR_TRUE==mImplicit)
isImplicitString = " (I)";
ListAttributes(out);
fprintf(out, " RefCount=%d<%s\n", mRefCnt, isImplicitString);
PRBool canHaveKids;
CanContainChildren(canHaveKids);
if (canHaveKids) {
PRInt32 kids;
ChildCount(kids);
for (i = 0; i < kids; i++) {
nsIContent* kid;
ChildAt(i, kid);
kid->List(out, aIndent + 1);
NS_RELEASE(kid);
}
}
for (i = aIndent; --i >= 0; ) fputs(" ", out);
fputs(">\n", out);
return NS_OK;
}
NS_IMETHODIMP
nsTableContent::InsertChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify)
{
nsresult rv = nsHTMLContainer::InsertChildAt(aKid, aIndex, aNotify);
if (NS_OK == rv) {
SetTableForTableContent(aKid, mTable);
}
return rv;
}
NS_IMETHODIMP
nsTableContent::ReplaceChildAt(nsIContent* aKid, PRInt32 aIndex, PRBool aNotify)
{
nsIContent* child;
ChildAt(aIndex, child);
nsresult rv = nsHTMLContainer::ReplaceChildAt(aKid, aIndex, aNotify);
if (NS_OK == rv)
{
SetTableForTableContent(child,nsnull);
SetTableForTableContent(aKid,mTable);
}
NS_IF_RELEASE(child);
return rv;
}
NS_IMETHODIMP
nsTableContent::AppendChildTo(nsIContent* aKid, PRBool aNotify)
{
nsresult rv = nsHTMLContainer::AppendChildTo(aKid, aNotify);
if (NS_OK == rv)
SetTableForTableContent(aKid,mTable);
return rv;
}
NS_IMETHODIMP
nsTableContent::RemoveChildAt(PRInt32 aIndex, PRBool aNotify)
{
nsTableContent* child;
ChildAt(aIndex, (nsIContent*&) child);
nsresult rv = nsHTMLContainer::RemoveChildAt(aIndex, aNotify);
if (NS_OK == rv)
SetTableForTableContent(child,nsnull);
NS_IF_RELEASE(child);
return rv;
}
/* ---------- nsITableContent implementations ----------- */
nsITableContent::nsITableContent ()
{}