Implemented document.layers and nsIDOMHTMLLayerElement interface.

This commit is contained in:
vidur%netscape.com 1999-05-17 21:17:48 +00:00
Родитель 802d7b19c1
Коммит 8ffd5ac746
11 изменённых файлов: 208 добавлений и 20 удалений

Просмотреть файл

@ -140,6 +140,7 @@ nsIAtom* nsHTMLAtoms::httpEquiv;
nsIAtom* nsHTMLAtoms::ibPseudo;
nsIAtom* nsHTMLAtoms::id;
nsIAtom* nsHTMLAtoms::iframe;
nsIAtom* nsHTMLAtoms::ilayer;
nsIAtom* nsHTMLAtoms::img;
nsIAtom* nsHTMLAtoms::index;
nsIAtom* nsHTMLAtoms::input;
@ -147,6 +148,7 @@ nsIAtom* nsHTMLAtoms::ismap;
nsIAtom* nsHTMLAtoms::label;
nsIAtom* nsHTMLAtoms::labelContentPseudo;
nsIAtom* nsHTMLAtoms::lang;
nsIAtom* nsHTMLAtoms::layer;
nsIAtom* nsHTMLAtoms::layout;
nsIAtom* nsHTMLAtoms::li;
nsIAtom* nsHTMLAtoms::link;
@ -274,6 +276,7 @@ nsIAtom* nsHTMLAtoms::width;
nsIAtom* nsHTMLAtoms::wrap;
nsIAtom* nsHTMLAtoms::wrappedFramePseudo;
nsIAtom* nsHTMLAtoms::zindex;
nsIAtom* nsHTMLAtoms::z_index;
static nsrefcnt gRefCnt;
@ -403,6 +406,7 @@ void nsHTMLAtoms::AddrefAtoms()
ibPseudo = NS_NewAtom(":ib-pseudo");
id = NS_NewAtom("id");
iframe = NS_NewAtom("iframe");
ilayer = NS_NewAtom("ilayer");
img = NS_NewAtom("img");
index = NS_NewAtom("index");
input = NS_NewAtom("input");
@ -410,6 +414,7 @@ void nsHTMLAtoms::AddrefAtoms()
label = NS_NewAtom("label");
labelContentPseudo = NS_NewAtom(":label-content");
lang = NS_NewAtom("lang");
layer = NS_NewAtom("layer");
layout = NS_NewAtom("layout");
li = NS_NewAtom("li");
link = NS_NewAtom("link");
@ -537,6 +542,7 @@ void nsHTMLAtoms::AddrefAtoms()
wrap = NS_NewAtom("wrap");
wrappedFramePseudo = NS_NewAtom(":wrapped-frame");
zindex = NS_NewAtom("zindex");
z_index = NS_NewAtom("z-index");
}
++gRefCnt;
}
@ -657,6 +663,7 @@ void nsHTMLAtoms::ReleaseAtoms()
NS_RELEASE(ibPseudo);
NS_RELEASE(id);
NS_RELEASE(iframe);
NS_RELEASE(ilayer);
NS_RELEASE(img);
NS_RELEASE(index);
NS_RELEASE(input);
@ -664,6 +671,7 @@ void nsHTMLAtoms::ReleaseAtoms()
NS_RELEASE(label);
NS_RELEASE(labelContentPseudo);
NS_RELEASE(lang);
NS_RELEASE(layer);
NS_RELEASE(layout);
NS_RELEASE(li);
NS_RELEASE(link);
@ -786,6 +794,7 @@ void nsHTMLAtoms::ReleaseAtoms()
NS_RELEASE(wrap);
NS_RELEASE(wrappedFramePseudo);
NS_RELEASE(zindex);
NS_RELEASE(z_index);
}
}

Просмотреть файл

@ -167,6 +167,7 @@ public:
static nsIAtom* ibPseudo;
static nsIAtom* id;
static nsIAtom* iframe;
static nsIAtom* ilayer;
static nsIAtom* img;
static nsIAtom* index;
static nsIAtom* input;
@ -175,6 +176,7 @@ public:
static nsIAtom* label;
static nsIAtom* labelContentPseudo;
static nsIAtom* lang;
static nsIAtom* layer;
static nsIAtom* layout;
static nsIAtom* li;
static nsIAtom* link;
@ -313,6 +315,7 @@ public:
static nsIAtom* wrappedFramePseudo;
static nsIAtom* zindex;
static nsIAtom* z_index;
};
#endif /* nsHTMLAtoms_h___ */

Просмотреть файл

@ -70,6 +70,9 @@ const PRInt32 kBackward = 1;
#include "nsHTMLContentSinkStream.h"
#endif
// XXX Used to control whether we implement document.layers
//#define NS_IMPLEMENT_DOCUMENT_LAYERS
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
@ -110,6 +113,7 @@ nsHTMLDocument::nsHTMLDocument()
mEmbeds = nsnull;
mLinks = nsnull;
mAnchors = nsnull;
mLayers = nsnull;
mNamedItems = nsnull;
mParser = nsnull;
nsHTMLAtoms::AddrefAtoms();
@ -144,6 +148,7 @@ nsHTMLDocument::~nsHTMLDocument()
NS_IF_RELEASE(mEmbeds);
NS_IF_RELEASE(mLinks);
NS_IF_RELEASE(mAnchors);
NS_IF_RELEASE(mLayers);
if (nsnull != mAttrStyleSheet) {
mAttrStyleSheet->SetOwningDocument(nsnull);
NS_RELEASE(mAttrStyleSheet);
@ -231,6 +236,7 @@ nsHTMLDocument::Reset(nsIURL *aURL)
NS_IF_RELEASE(mEmbeds);
NS_IF_RELEASE(mLinks);
NS_IF_RELEASE(mAnchors);
NS_IF_RELEASE(mLayers);
for (i = 0; i < mImageMaps.Count(); i++) {
nsIDOMHTMLMapElement* map = (nsIDOMHTMLMapElement*)mImageMaps.ElementAt(i);
@ -1570,11 +1576,42 @@ nsHTMLDocument::GetEmbeds(nsIDOMHTMLCollection** aEmbeds)
return NS_OK;
}
PRBool
nsHTMLDocument::MatchLayers(nsIContent *aContent, nsString* aData)
{
nsIAtom *name;
aContent->GetTag(name);
nsAutoString attr;
PRBool result = PR_FALSE;
if ((nsnull != name) &&
((nsHTMLAtoms::layer == name) || (nsHTMLAtoms::ilayer == name))) {
result = PR_TRUE;
}
NS_IF_RELEASE(name);
return result;
}
NS_IMETHODIMP
nsHTMLDocument::GetLayers(nsIDOMHTMLCollection** aLayers)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
#ifdef NS_IMPLEMENT_DOCUMENT_LAYERS
if (nsnull == mLayers) {
mAnchors = new nsContentList(this, MatchLayers, nsnull);
if (nsnull == mLayers) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(mLayers);
}
*aLayers = (nsIDOMHTMLCollection *)mLayers;
NS_ADDREF(mLayers);
#else
*aLayers = nsnull;
#endif
return NS_OK;
}
NS_IMETHODIMP
@ -1615,7 +1652,7 @@ IsNamedItem(nsIContent* aContent, nsIAtom *aTag,
PRBool aInForm, nsString& aName)
{
// Only the content types reflected in Level 0 with a NAME
// attribute are registered. Images and forms always get
// attribute are registered. Images, layers and forms always get
// reflected up to the document. Applets and embeds only go
// to the closest container (which could be a form).
if ((aTag == nsHTMLAtoms::img) || (aTag == nsHTMLAtoms::form) ||
@ -1626,6 +1663,13 @@ IsNamedItem(nsIContent* aContent, nsIAtom *aTag,
}
}
if ((aTag == nsHTMLAtoms::layer) || (aTag == nsHTMLAtoms::ilayer)) {
if ((NS_CONTENT_ATTR_HAS_VALUE == aContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::name, aName)) ||
(NS_CONTENT_ATTR_HAS_VALUE == aContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::id, aName))) {
return PR_TRUE;
}
}
return PR_FALSE;
}

Просмотреть файл

@ -167,6 +167,7 @@ protected:
virtual void InternalAddStyleSheet(nsIStyleSheet* aSheet);
static PRBool MatchLinks(nsIContent *aContent, nsString* aData);
static PRBool MatchAnchors(nsIContent *aContent, nsString* aData);
static PRBool MatchLayers(nsIContent *aContent, nsString* aData);
static PRBool MatchNameAttribute(nsIContent* aContent, nsString* aData);
PRBool GetBodyContent();
@ -192,6 +193,7 @@ protected:
nsContentList *mLinks;
nsContentList *mAnchors;
nsContentList *mForms;
nsContentList *mLayers;
PLHashTable *mNamedItems;

Просмотреть файл

@ -167,6 +167,7 @@ public:
static nsIAtom* ibPseudo;
static nsIAtom* id;
static nsIAtom* iframe;
static nsIAtom* ilayer;
static nsIAtom* img;
static nsIAtom* index;
static nsIAtom* input;
@ -175,6 +176,7 @@ public:
static nsIAtom* label;
static nsIAtom* labelContentPseudo;
static nsIAtom* lang;
static nsIAtom* layer;
static nsIAtom* layout;
static nsIAtom* li;
static nsIAtom* link;
@ -313,6 +315,7 @@ public:
static nsIAtom* wrappedFramePseudo;
static nsIAtom* zindex;
static nsIAtom* z_index;
};
#endif /* nsHTMLAtoms_h___ */

Просмотреть файл

@ -140,6 +140,7 @@ nsIAtom* nsHTMLAtoms::httpEquiv;
nsIAtom* nsHTMLAtoms::ibPseudo;
nsIAtom* nsHTMLAtoms::id;
nsIAtom* nsHTMLAtoms::iframe;
nsIAtom* nsHTMLAtoms::ilayer;
nsIAtom* nsHTMLAtoms::img;
nsIAtom* nsHTMLAtoms::index;
nsIAtom* nsHTMLAtoms::input;
@ -147,6 +148,7 @@ nsIAtom* nsHTMLAtoms::ismap;
nsIAtom* nsHTMLAtoms::label;
nsIAtom* nsHTMLAtoms::labelContentPseudo;
nsIAtom* nsHTMLAtoms::lang;
nsIAtom* nsHTMLAtoms::layer;
nsIAtom* nsHTMLAtoms::layout;
nsIAtom* nsHTMLAtoms::li;
nsIAtom* nsHTMLAtoms::link;
@ -274,6 +276,7 @@ nsIAtom* nsHTMLAtoms::width;
nsIAtom* nsHTMLAtoms::wrap;
nsIAtom* nsHTMLAtoms::wrappedFramePseudo;
nsIAtom* nsHTMLAtoms::zindex;
nsIAtom* nsHTMLAtoms::z_index;
static nsrefcnt gRefCnt;
@ -403,6 +406,7 @@ void nsHTMLAtoms::AddrefAtoms()
ibPseudo = NS_NewAtom(":ib-pseudo");
id = NS_NewAtom("id");
iframe = NS_NewAtom("iframe");
ilayer = NS_NewAtom("ilayer");
img = NS_NewAtom("img");
index = NS_NewAtom("index");
input = NS_NewAtom("input");
@ -410,6 +414,7 @@ void nsHTMLAtoms::AddrefAtoms()
label = NS_NewAtom("label");
labelContentPseudo = NS_NewAtom(":label-content");
lang = NS_NewAtom("lang");
layer = NS_NewAtom("layer");
layout = NS_NewAtom("layout");
li = NS_NewAtom("li");
link = NS_NewAtom("link");
@ -537,6 +542,7 @@ void nsHTMLAtoms::AddrefAtoms()
wrap = NS_NewAtom("wrap");
wrappedFramePseudo = NS_NewAtom(":wrapped-frame");
zindex = NS_NewAtom("zindex");
z_index = NS_NewAtom("z-index");
}
++gRefCnt;
}
@ -657,6 +663,7 @@ void nsHTMLAtoms::ReleaseAtoms()
NS_RELEASE(ibPseudo);
NS_RELEASE(id);
NS_RELEASE(iframe);
NS_RELEASE(ilayer);
NS_RELEASE(img);
NS_RELEASE(index);
NS_RELEASE(input);
@ -664,6 +671,7 @@ void nsHTMLAtoms::ReleaseAtoms()
NS_RELEASE(label);
NS_RELEASE(labelContentPseudo);
NS_RELEASE(lang);
NS_RELEASE(layer);
NS_RELEASE(layout);
NS_RELEASE(li);
NS_RELEASE(link);
@ -786,6 +794,7 @@ void nsHTMLAtoms::ReleaseAtoms()
NS_RELEASE(wrap);
NS_RELEASE(wrappedFramePseudo);
NS_RELEASE(zindex);
NS_RELEASE(z_index);
}
}

Просмотреть файл

@ -140,6 +140,7 @@ nsIAtom* nsHTMLAtoms::httpEquiv;
nsIAtom* nsHTMLAtoms::ibPseudo;
nsIAtom* nsHTMLAtoms::id;
nsIAtom* nsHTMLAtoms::iframe;
nsIAtom* nsHTMLAtoms::ilayer;
nsIAtom* nsHTMLAtoms::img;
nsIAtom* nsHTMLAtoms::index;
nsIAtom* nsHTMLAtoms::input;
@ -147,6 +148,7 @@ nsIAtom* nsHTMLAtoms::ismap;
nsIAtom* nsHTMLAtoms::label;
nsIAtom* nsHTMLAtoms::labelContentPseudo;
nsIAtom* nsHTMLAtoms::lang;
nsIAtom* nsHTMLAtoms::layer;
nsIAtom* nsHTMLAtoms::layout;
nsIAtom* nsHTMLAtoms::li;
nsIAtom* nsHTMLAtoms::link;
@ -274,6 +276,7 @@ nsIAtom* nsHTMLAtoms::width;
nsIAtom* nsHTMLAtoms::wrap;
nsIAtom* nsHTMLAtoms::wrappedFramePseudo;
nsIAtom* nsHTMLAtoms::zindex;
nsIAtom* nsHTMLAtoms::z_index;
static nsrefcnt gRefCnt;
@ -403,6 +406,7 @@ void nsHTMLAtoms::AddrefAtoms()
ibPseudo = NS_NewAtom(":ib-pseudo");
id = NS_NewAtom("id");
iframe = NS_NewAtom("iframe");
ilayer = NS_NewAtom("ilayer");
img = NS_NewAtom("img");
index = NS_NewAtom("index");
input = NS_NewAtom("input");
@ -410,6 +414,7 @@ void nsHTMLAtoms::AddrefAtoms()
label = NS_NewAtom("label");
labelContentPseudo = NS_NewAtom(":label-content");
lang = NS_NewAtom("lang");
layer = NS_NewAtom("layer");
layout = NS_NewAtom("layout");
li = NS_NewAtom("li");
link = NS_NewAtom("link");
@ -537,6 +542,7 @@ void nsHTMLAtoms::AddrefAtoms()
wrap = NS_NewAtom("wrap");
wrappedFramePseudo = NS_NewAtom(":wrapped-frame");
zindex = NS_NewAtom("zindex");
z_index = NS_NewAtom("z-index");
}
++gRefCnt;
}
@ -657,6 +663,7 @@ void nsHTMLAtoms::ReleaseAtoms()
NS_RELEASE(ibPseudo);
NS_RELEASE(id);
NS_RELEASE(iframe);
NS_RELEASE(ilayer);
NS_RELEASE(img);
NS_RELEASE(index);
NS_RELEASE(input);
@ -664,6 +671,7 @@ void nsHTMLAtoms::ReleaseAtoms()
NS_RELEASE(label);
NS_RELEASE(labelContentPseudo);
NS_RELEASE(lang);
NS_RELEASE(layer);
NS_RELEASE(layout);
NS_RELEASE(li);
NS_RELEASE(link);
@ -786,6 +794,7 @@ void nsHTMLAtoms::ReleaseAtoms()
NS_RELEASE(wrap);
NS_RELEASE(wrappedFramePseudo);
NS_RELEASE(zindex);
NS_RELEASE(z_index);
}
}

Просмотреть файл

@ -167,6 +167,7 @@ public:
static nsIAtom* ibPseudo;
static nsIAtom* id;
static nsIAtom* iframe;
static nsIAtom* ilayer;
static nsIAtom* img;
static nsIAtom* index;
static nsIAtom* input;
@ -175,6 +176,7 @@ public:
static nsIAtom* label;
static nsIAtom* labelContentPseudo;
static nsIAtom* lang;
static nsIAtom* layer;
static nsIAtom* layout;
static nsIAtom* li;
static nsIAtom* link;
@ -313,6 +315,7 @@ public:
static nsIAtom* wrappedFramePseudo;
static nsIAtom* zindex;
static nsIAtom* z_index;
};
#endif /* nsHTMLAtoms_h___ */

Просмотреть файл

@ -18,7 +18,10 @@
*/
#include "nsIDOMHTMLElement.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMHTMLLayerElement.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMDocument.h"
#include "nsIDocument.h"
#include "nsIHTMLContent.h"
#include "nsGenericHTMLElement.h"
#include "nsHTMLAtoms.h"
@ -30,12 +33,13 @@
#define _I32_MIN (-2147483647 - 1) /* minimum signed 32 bit value */
static NS_DEFINE_IID(kIDOMHTMLLayerElementIID, NS_IDOMHTMLELEMENT_IID);
static NS_DEFINE_IID(kIDOMHTMLLayerElementIID, NS_IDOMHTMLLAYERELEMENT_IID);
static NS_DEFINE_IID(kIDOMDocumentIID, NS_IDOMDOCUMENT_IID);
class nsHTMLLayerElement : public nsIDOMHTMLElement,/* XXX need layer api */
public nsIScriptObjectOwner,
public nsIDOMEventReceiver,
public nsIHTMLContent
class nsHTMLLayerElement : public nsIDOMHTMLLayerElement,
public nsIScriptObjectOwner,
public nsIDOMEventReceiver,
public nsIHTMLContent
{
public:
nsHTMLLayerElement(nsIAtom* aTag);
@ -54,8 +58,21 @@ public:
NS_IMPL_IDOMHTMLELEMENT_USING_GENERIC(mInner)
// nsIDOMHTMLLayerElement
NS_IMETHOD GetCite(nsString& aCite);
NS_IMETHOD SetCite(const nsString& aCite);
NS_IMETHOD GetTop(PRInt32* aTop);
NS_IMETHOD SetTop(PRInt32 aTop);
NS_IMETHOD GetLeft(PRInt32* aLeft);
NS_IMETHOD SetLeft(PRInt32 aLeft);
NS_IMETHOD GetVisibility(nsString& aVisibility);
NS_IMETHOD SetVisibility(const nsString& aVisibility);
NS_IMETHOD GetBackground(nsString& aBackground);
NS_IMETHOD SetBackground(const nsString& aBackground);
NS_IMETHOD GetBgColor(nsString& aBgColor);
NS_IMETHOD SetBgColor(const nsString& aBgColor);
NS_IMETHOD GetName(nsString& aName);
NS_IMETHOD SetName(const nsString& aName);
NS_IMETHOD GetZIndex(PRInt32* aZIndex);
NS_IMETHOD SetZIndex(PRInt32 aZIndex);
NS_IMETHOD GetDocument(nsIDOMDocument** aReturn);
// nsIScriptObjectOwner
NS_IMPL_ISCRIPTOBJECTOWNER_USING_GENERIC(mInner)
@ -105,17 +122,43 @@ nsresult
nsHTMLLayerElement::QueryInterface(REFNSIID aIID, void** aInstancePtr)
{
NS_IMPL_HTML_CONTENT_QUERY_INTERFACE(aIID, aInstancePtr, this)
#if XXX
if (aIID.Equals(kIDOMHTMLLayerElementIID)) {
nsIDOMHTMLLayerElement* tmp = this;
*aInstancePtr = (void*) tmp;
mRefCnt++;
return NS_OK;
}
#endif
return NS_NOINTERFACE;
}
NS_IMPL_INT_ATTR(nsHTMLLayerElement, Top, top)
NS_IMPL_INT_ATTR(nsHTMLLayerElement, Left, left)
NS_IMPL_STRING_ATTR(nsHTMLLayerElement, Visibility, visibility)
NS_IMPL_STRING_ATTR(nsHTMLLayerElement, Background, background)
NS_IMPL_STRING_ATTR(nsHTMLLayerElement, BgColor, bgcolor)
NS_IMPL_STRING_ATTR(nsHTMLLayerElement, Name, name)
NS_IMPL_INT_ATTR(nsHTMLLayerElement, ZIndex, zindex)
NS_IMETHODIMP
nsHTMLLayerElement::GetDocument(nsIDOMDocument** aDocument)
{
// XXX This is cheating. We should really return the layer's
// internal document.
nsresult result = NS_OK;
nsIDocument* document;
result = mInner.GetDocument(document);
if (NS_SUCCEEDED(result)) {
result = document->QueryInterface(kIDOMDocumentIID, (void**)&aDocument);
NS_RELEASE(document);
}
else {
*aDocument = nsnull;
}
return result;
}
nsresult
nsHTMLLayerElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
{
@ -127,11 +170,12 @@ nsHTMLLayerElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
return it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
}
NS_IMPL_STRING_ATTR(nsHTMLLayerElement, Cite, cite)
static nsGenericHTMLElement::EnumTable kVisibilityTable[] = {
{"hide", NS_STYLE_VISIBILITY_HIDDEN},
{"hidden", NS_STYLE_VISIBILITY_HIDDEN},
{"visible", NS_STYLE_VISIBILITY_VISIBLE},
{"show", NS_STYLE_VISIBILITY_VISIBLE},
{"hide", NS_STYLE_VISIBILITY_HIDDEN},
{"inherit", NS_STYLE_VISIBILITY_VISIBLE},
{0}
};
@ -159,7 +203,8 @@ nsHTMLLayerElement::StringToAttribute(nsIAtom* aAttribute,
return NS_CONTENT_ATTR_HAS_VALUE;
}
}
else if (aAttribute == nsHTMLAtoms::zindex) {
else if ((aAttribute == nsHTMLAtoms::zindex) ||
(aAttribute == nsHTMLAtoms::z_index)) {
if (nsGenericHTMLElement::ParseValue(aValue, 0, aResult, eHTMLUnit_Integer)) {
return NS_CONTENT_ATTR_HAS_VALUE;
}
@ -251,6 +296,10 @@ MapAttributesInto(nsIHTMLAttributes* aAttributes,
if (value.GetUnit() == eHTMLUnit_Integer) {
position->mZIndex.SetIntValue(value.GetIntValue(), eStyleUnit_Integer);
}
aAttributes->GetAttribute(nsHTMLAtoms::z_index, value);
if (value.GetUnit() == eHTMLUnit_Integer) {
position->mZIndex.SetIntValue(value.GetIntValue(), eStyleUnit_Integer);
}
// Visibility
aAttributes->GetAttribute(nsHTMLAtoms::visibility, value);
@ -293,6 +342,17 @@ nsHTMLLayerElement::GetStyleHintForAttributeChange(
const nsIAtom* aAttribute,
PRInt32 *aHint) const
{
nsGenericHTMLElement::GetStyleHintForCommonAttributes(this, aAttribute, aHint);
if ((aAttribute == nsHTMLAtoms::visibility) ||
(aAttribute == nsHTMLAtoms::z_index) ||
(aAttribute == nsHTMLAtoms::zindex)) {
*aHint = NS_STYLE_HINT_VISUAL;
}
else if ((aAttribute == nsHTMLAtoms::top) ||
(aAttribute == nsHTMLAtoms::left)) {
*aHint = NS_STYLE_HINT_REFLOW;
}
else {
nsGenericHTMLElement::GetStyleHintForCommonAttributes(this, aAttribute, aHint);
}
return NS_OK;
}

Просмотреть файл

@ -70,6 +70,9 @@ const PRInt32 kBackward = 1;
#include "nsHTMLContentSinkStream.h"
#endif
// XXX Used to control whether we implement document.layers
//#define NS_IMPLEMENT_DOCUMENT_LAYERS
static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIDocumentIID, NS_IDOCUMENT_IID);
static NS_DEFINE_IID(kIContentIID, NS_ICONTENT_IID);
@ -110,6 +113,7 @@ nsHTMLDocument::nsHTMLDocument()
mEmbeds = nsnull;
mLinks = nsnull;
mAnchors = nsnull;
mLayers = nsnull;
mNamedItems = nsnull;
mParser = nsnull;
nsHTMLAtoms::AddrefAtoms();
@ -144,6 +148,7 @@ nsHTMLDocument::~nsHTMLDocument()
NS_IF_RELEASE(mEmbeds);
NS_IF_RELEASE(mLinks);
NS_IF_RELEASE(mAnchors);
NS_IF_RELEASE(mLayers);
if (nsnull != mAttrStyleSheet) {
mAttrStyleSheet->SetOwningDocument(nsnull);
NS_RELEASE(mAttrStyleSheet);
@ -231,6 +236,7 @@ nsHTMLDocument::Reset(nsIURL *aURL)
NS_IF_RELEASE(mEmbeds);
NS_IF_RELEASE(mLinks);
NS_IF_RELEASE(mAnchors);
NS_IF_RELEASE(mLayers);
for (i = 0; i < mImageMaps.Count(); i++) {
nsIDOMHTMLMapElement* map = (nsIDOMHTMLMapElement*)mImageMaps.ElementAt(i);
@ -1570,11 +1576,42 @@ nsHTMLDocument::GetEmbeds(nsIDOMHTMLCollection** aEmbeds)
return NS_OK;
}
PRBool
nsHTMLDocument::MatchLayers(nsIContent *aContent, nsString* aData)
{
nsIAtom *name;
aContent->GetTag(name);
nsAutoString attr;
PRBool result = PR_FALSE;
if ((nsnull != name) &&
((nsHTMLAtoms::layer == name) || (nsHTMLAtoms::ilayer == name))) {
result = PR_TRUE;
}
NS_IF_RELEASE(name);
return result;
}
NS_IMETHODIMP
nsHTMLDocument::GetLayers(nsIDOMHTMLCollection** aLayers)
{
//XXX TBI
return NS_ERROR_NOT_IMPLEMENTED;
#ifdef NS_IMPLEMENT_DOCUMENT_LAYERS
if (nsnull == mLayers) {
mAnchors = new nsContentList(this, MatchLayers, nsnull);
if (nsnull == mLayers) {
return NS_ERROR_OUT_OF_MEMORY;
}
NS_ADDREF(mLayers);
}
*aLayers = (nsIDOMHTMLCollection *)mLayers;
NS_ADDREF(mLayers);
#else
*aLayers = nsnull;
#endif
return NS_OK;
}
NS_IMETHODIMP
@ -1615,7 +1652,7 @@ IsNamedItem(nsIContent* aContent, nsIAtom *aTag,
PRBool aInForm, nsString& aName)
{
// Only the content types reflected in Level 0 with a NAME
// attribute are registered. Images and forms always get
// attribute are registered. Images, layers and forms always get
// reflected up to the document. Applets and embeds only go
// to the closest container (which could be a form).
if ((aTag == nsHTMLAtoms::img) || (aTag == nsHTMLAtoms::form) ||
@ -1626,6 +1663,13 @@ IsNamedItem(nsIContent* aContent, nsIAtom *aTag,
}
}
if ((aTag == nsHTMLAtoms::layer) || (aTag == nsHTMLAtoms::ilayer)) {
if ((NS_CONTENT_ATTR_HAS_VALUE == aContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::name, aName)) ||
(NS_CONTENT_ATTR_HAS_VALUE == aContent->GetAttribute(kNameSpaceID_HTML, nsHTMLAtoms::id, aName))) {
return PR_TRUE;
}
}
return PR_FALSE;
}

Просмотреть файл

@ -167,6 +167,7 @@ protected:
virtual void InternalAddStyleSheet(nsIStyleSheet* aSheet);
static PRBool MatchLinks(nsIContent *aContent, nsString* aData);
static PRBool MatchAnchors(nsIContent *aContent, nsString* aData);
static PRBool MatchLayers(nsIContent *aContent, nsString* aData);
static PRBool MatchNameAttribute(nsIContent* aContent, nsString* aData);
PRBool GetBodyContent();
@ -192,6 +193,7 @@ protected:
nsContentList *mLinks;
nsContentList *mAnchors;
nsContentList *mForms;
nsContentList *mLayers;
PLHashTable *mNamedItems;