- Fix for nsbeta3+ bug 10292: ID attribute information is passed up from the parser to the content sink and into the node info objects associated with content objects. nsIXMLContent now inherits from nsIStyledContent which allows

authors to use ID selectors to target elements in an XML document.

- Checking in a P3P related patch to the pres shell, html document, and xml document from Tom Lendacky (toml@us.ibm.com)
This commit is contained in:
nisheeth%netscape.com 2000-08-30 00:35:43 +00:00
parent 64639d5d02
commit b65a3881e0
37 changed files with 491 additions and 89 deletions

View File

@ -22,13 +22,13 @@
/*
* nsINodeInfo is an interface to node info, such as name, prefix, namespace
* ID and possibly other data that is shared shared between nodes (elements
* ID and possibly other data that is shared between nodes (elements
* and attributes) that have the same name, prefix and namespace ID within
* the same document.
*
* nsINodeInfoManager is an interface to an object that manages a list of
* nsINodeInfo's, every document object should hold a strong reference to
* a nsINodeInfoManager and every nsINodeInfo also holds a string reference
* a nsINodeInfoManager and every nsINodeInfo also holds a strong reference
* to their owning manager. When a nsINodeInfo is no longer used it will
* automatically remove itself from its owner manager, and when all
* nsINodeInfo's have been removed from a nsINodeInfoManager and all external
@ -144,13 +144,22 @@ public:
*/
NS_IMETHOD GetNamespaceID(PRInt32& aResult) = 0;
/*
* Get and set the ID attribute atom for this node.
* See http://www.w3.org/TR/1998/REC-xml-19980210#sec-attribute-types
* for the definition of an ID attribute.
*
*/
NS_IMETHOD GetIDAttributeAtom(nsIAtom** aResult) = 0;
NS_IMETHOD SetIDAttributeAtom(nsIAtom* aResult) = 0;
/*
* Get the owning node info manager, this will never return null.
*/
NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) = 0;
/*
* Utility functions that can be used to check if a nodeinfo holds a spcific
* Utility functions that can be used to check if a nodeinfo holds a specific
* name, name and prefix, name and prefix and namespace ID, or just
* namespace ID.
*/

View File

@ -34,7 +34,7 @@ static PRBool kStrictDOMLevel2 = PR_FALSE;
nsNodeInfo::nsNodeInfo()
: mInner(), mOwnerManager(nsnull)
{
NS_INIT_REFCNT();
NS_INIT_REFCNT();
static PRInt32 been_here = 0;
@ -49,6 +49,7 @@ nsNodeInfo::nsNodeInfo()
been_here = 1;
}
// End of temp hack.
}
@ -213,6 +214,26 @@ nsNodeInfo::GetNamespaceID(PRInt32& aResult)
}
NS_IMETHODIMP
nsNodeInfo::GetIDAttributeAtom(nsIAtom** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mInner.mIDAttributeAtom;
return NS_OK;
}
NS_IMETHODIMP
nsNodeInfo::SetIDAttributeAtom(nsIAtom* aID)
{
NS_ENSURE_ARG(aID);
mInner.mIDAttributeAtom = aID;
return NS_OK;
}
NS_IMETHODIMP
nsNodeInfo::GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager)
{

View File

@ -26,6 +26,8 @@
#include "nsINodeInfo.h"
#include "nsINameSpaceManager.h"
#include "plhash.h"
#include "nsIAtom.h"
#include "nsCOMPtr.h"
/*
* nsNodeInfoInner is used for two things:
@ -43,10 +45,10 @@
struct nsNodeInfoInner
{
nsNodeInfoInner(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID)
: mName(aName), mPrefix(aPrefix), mNamespaceID(aNamespaceID) {}
: mName(aName), mPrefix(aPrefix), mNamespaceID(aNamespaceID) { }
nsNodeInfoInner()
: mName(nsnull), mPrefix(nsnull), mNamespaceID(kNameSpaceID_None) {}
: mName(nsnull), mPrefix(nsnull), mNamespaceID(kNameSpaceID_None) { }
static PRIntn PR_CALLBACK KeyCompare(const void *key1, const void *key2);
static PLHashNumber PR_CALLBACK GetHashValue(const void *key);
@ -54,6 +56,7 @@ struct nsNodeInfoInner
nsIAtom* mName;
nsIAtom* mPrefix;
PRInt32 mNamespaceID;
nsCOMPtr<nsIAtom> mIDAttributeAtom;
};
@ -73,6 +76,8 @@ public:
NS_IMETHOD GetPrefixAtom(nsIAtom*& aAtom);
NS_IMETHOD GetNamespaceURI(nsAWritableString& aNameSpaceURI);
NS_IMETHOD GetNamespaceID(PRInt32& aResult);
NS_IMETHOD GetIDAttributeAtom(nsIAtom** aResult);
NS_IMETHOD SetIDAttributeAtom(nsIAtom* aResult);
NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager);
NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom);
NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName);

View File

@ -630,7 +630,6 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
static NS_DEFINE_IID(kParserBundleIID, NS_IPARSER_BUNDLE_IID);
if (needsParser)
{
@ -656,17 +655,16 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
if(mParser) {
nsCOMPtr<nsIWebShellServices> webShellServices(do_QueryInterface(docShell));
nsISupportsParserBundle* parserBundle=nsnull;
nsCOMPtr<nsISupportsParserBundle> parserBundle;
nsresult result;
nsresult result=mParser->QueryInterface(kParserBundleIID,(void**)&parserBundle);
parserBundle = do_QueryInterface(mParser, &result);
if(NS_SUCCEEDED(result)) {
// We do this to help consumers who don't have access to the webshell.
nsAutoString theID;
theID.AssignWithConversion("webshell");
parserBundle->SetDataIntoBundle(theID,webShellServices);
NS_IF_RELEASE(parserBundle);
theID.AssignWithConversion("docshell");
parserBundle->SetDataIntoBundle(theID,docShell);
}
}

View File

@ -24,7 +24,7 @@
#define nsIXMLContent_h___
#include "nsISupports.h"
#include "nsIContent.h"
#include "nsIStyledContent.h"
class nsINameSpace;
class nsINodeInfo;
@ -37,7 +37,7 @@ class nsIWebShell;
/**
* XML content extensions to nsIContent
*/
class nsIXMLContent : public nsIContent {
class nsIXMLContent : public nsIStyledContent {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IXMLCONTENT_IID; return iid; }

View File

@ -113,7 +113,12 @@ nsXMLElement::QueryInterface(REFNSIID aIID,
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIStyledContent::GetIID())) {
nsIStyledContent* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
@ -494,3 +499,53 @@ nsXMLElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
return it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
}
// nsIStyledContent implementation
NS_IMETHODIMP
nsXMLElement::GetID(nsIAtom*& aResult) const
{
nsresult rv;
nsCOMPtr<nsIAtom> atom;
rv = mInner.mNodeInfo->GetIDAttributeAtom(getter_AddRefs(atom));
aResult = nsnull;
if (NS_SUCCEEDED(rv) && atom) {
nsAutoString value;
rv = GetAttribute(kNameSpaceID_Unknown, atom, value);
if (NS_SUCCEEDED(rv))
aResult = NS_NewAtom(value);
}
return rv;
}
NS_IMETHODIMP
nsXMLElement::GetClasses(nsVoidArray& aArray) const
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXMLElement::HasClass(nsIAtom* aClass) const
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXMLElement::GetContentStyleRules(nsISupportsArray* aRules)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXMLElement::GetInlineStyleRules(nsISupportsArray* aRules)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXMLElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
PRInt32& aHint) const
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@ -30,6 +30,7 @@
#include "nsIXMLContent.h"
#include "nsIJSScriptObject.h"
#include "nsGenericXMLElement.h"
#include "nsIStyledContent.h"
class nsIDocument;
class nsIAtom;
@ -225,6 +226,15 @@ public:
}
NS_IMETHOD MaybeTriggerAutoLink(nsIWebShell *aShell);
// nsIStyledContent
NS_IMETHOD GetID(nsIAtom*& aResult) const;
NS_IMETHOD GetClasses(nsVoidArray& aArray) const;
NS_IMETHOD HasClass(nsIAtom* aClass) const;
NS_IMETHOD GetContentStyleRules(nsISupportsArray* aRules);
NS_IMETHOD GetInlineStyleRules(nsISupportsArray* aRules);
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
PRInt32& aHint) const;
// nsIJSScriptObject
virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) {
return mInner.AddProperty(aContext, aObj, aID, aVp);

View File

@ -792,6 +792,12 @@ nsXMLContentSink::OpenContainer(const nsIParserNode& aNode)
PushContent(content);
}
}
// Set the ID attribute atom on the node info object for this node
nsCOMPtr<nsIAtom> IDAttr;
result = aNode.GetIDAttributeAtom(getter_AddRefs(IDAttr));
if (IDAttr && NS_SUCCEEDED(result))
result = nodeInfo->SetIDAttributeAtom(IDAttr);
}
return result;

View File

@ -399,6 +399,18 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand,
else rv = NS_NewXMLContentSink(&sink, this, aUrl, nsnull);
if(NS_SUCCEEDED(rv) && (docShell)) {
nsCOMPtr<nsISupportsParserBundle> parserBundle;
nsresult result;
parserBundle = do_QueryInterface(mParser, &result);
if(NS_SUCCEEDED(result)) {
// We do this to help consumers who don't have access to the webshell.
nsAutoString theID;
theID.AssignWithConversion("docshell");
parserBundle->SetDataIntoBundle(theID,docShell);
}
nsCOMPtr<nsIContentViewer> cv;
docShell->GetContentViewer(getter_AddRefs(cv));
if (cv) {

View File

@ -311,8 +311,7 @@ public:
*/
class nsXULElement : public nsIStyledContent,
public nsIXMLContent,
class nsXULElement : public nsIXMLContent,
public nsIXULContent,
public nsIDOMXULElement,
public nsIDOMEventReceiver,
@ -392,6 +391,13 @@ public:
NS_IMETHOD GetBindingParent(nsIContent** aContent);
NS_IMETHOD SetBindingParent(nsIContent* aParent);
// nsIXMLContent
NS_IMETHOD SetContainingNameSpace(nsINameSpace* aNameSpace);
NS_IMETHOD GetContainingNameSpace(nsINameSpace*& aNameSpace) const;
NS_IMETHOD SetNameSpacePrefix(nsIAtom* aNameSpace);
NS_IMETHOD GetNameSpacePrefix(nsIAtom*& aNameSpace) const;
NS_IMETHOD MaybeTriggerAutoLink(nsIWebShell *aShell);
// nsIStyledContent
NS_IMETHOD GetID(nsIAtom*& aResult) const;
NS_IMETHOD GetClasses(nsVoidArray& aArray) const;
@ -402,12 +408,6 @@ public:
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
PRInt32& aHint) const;
// nsIXMLContent
NS_IMETHOD SetContainingNameSpace(nsINameSpace* aNameSpace);
NS_IMETHOD GetContainingNameSpace(nsINameSpace*& aNameSpace) const;
NS_IMETHOD SetNameSpacePrefix(nsIAtom* aNameSpace);
NS_IMETHOD GetNameSpacePrefix(nsIAtom*& aNameSpace) const;
NS_IMETHOD MaybeTriggerAutoLink(nsIWebShell *aShell);
// nsIXULContent
NS_IMETHOD PeekChildCount(PRInt32& aCount) const;

View File

@ -506,11 +506,22 @@ void nsExpatTokenizer::FrontloadMisplacedContent(nsDeque& aDeque){
void nsExpatTokenizer::HandleStartElement(void *userData, const XML_Char *name, const XML_Char **atts) {
XMLParserState* state = (XMLParserState*) userData;
CToken* theToken = state->tokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_unknown);
if(theToken) {
if(theToken) {
// If an ID attribute exists for this element, set it on the start token
PRInt32 index = XML_GetIdAttributeIndex(state->parser);
if (index >= 0) {
nsCOMPtr<nsIAtom> attributeAtom = dont_AddRef(NS_NewAtom((const PRUnichar *) atts[index]));
CStartToken* startToken = NS_STATIC_CAST(CStartToken*, theToken);
startToken->SetIDAttributeAtom(attributeAtom);
}
// Set the element name on the start token and add the token to the token queue
nsString& theString=theToken->GetStringValueXXX();
theString.Assign((PRUnichar *) name);
AddToken(theToken, NS_OK, state->tokenDeque, state->tokenRecycler);
int theAttrCount=0;
// For each attribute on this element, create and add attribute tokens to the token queue
int theAttrCount=0;
while(*atts){
theAttrCount++;
CAttributeToken* theAttrToken = (CAttributeToken*)
@ -519,7 +530,7 @@ void nsExpatTokenizer::HandleStartElement(void *userData, const XML_Char *name,
nsString& theKey=theAttrToken->GetKey();
theKey.Assign((PRUnichar *) (*atts++));
nsString& theValue=theAttrToken->GetStringValueXXX();
theValue.Assign((PRUnichar *) (*atts++));
theValue.Assign((PRUnichar *) (*atts++));
}
CToken* theTok=(CToken*)theAttrToken;
AddToken(theTok, NS_OK, state->tokenDeque, state->tokenRecycler);
@ -843,7 +854,7 @@ int nsExpatTokenizer::HandleExternalEntityRef(XML_Parser parser,
}
#else /* ! XML_DTD */
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleExternalEntityRef() not yet implemented.");
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleExternalEntityRef() not yet implemented.");
#endif /* XML_DTD */

View File

@ -140,6 +140,24 @@ void CStartToken::Reinitialize(PRInt32 aTag, const nsString& aString){
mTrailingContent.Truncate();
}
nsresult CStartToken::GetIDAttributeAtom(nsIAtom** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mIDAttributeAtom;
return NS_OK;
}
nsresult CStartToken::SetIDAttributeAtom(nsIAtom* aID)
{
NS_ENSURE_ARG(aID);
mIDAttributeAtom = aID;
return NS_OK;
}
/*
* This method returns the typeid (the tag type) for this token.
*

View File

@ -130,14 +130,23 @@ class CStartToken: public CHTMLToken {
virtual void DebugDumpSource(nsOutputStream& out);
virtual void GetSource(nsString& anOutputString);
virtual void AppendSource(nsString& anOutputString);
virtual void Reinitialize(PRInt32 aTag, const nsString& aString);
/*
* Get and set the ID attribute atom for this element.
* See http://www.w3.org/TR/1998/REC-xml-19980210#sec-attribute-types
* for the definition of an ID attribute.
*
*/
virtual nsresult GetIDAttributeAtom(nsIAtom** aResult);
virtual nsresult SetIDAttributeAtom(nsIAtom* aID);
nsString mTrailingContent;
PRInt32 mOrigin;
protected:
PRBool mAttributed;
PRBool mEmpty;
PRBool mEmpty;
nsCOMPtr<nsIAtom> mIDAttributeAtom;
};
@ -283,8 +292,7 @@ class CAttributeToken: public CHTMLToken {
virtual void Reinitialize(PRInt32 aTag, const nsString& aString);
PRBool mHasEqualWithoutValue;
nsString mTextKey;
nsString mTextKey;
};

View File

@ -155,8 +155,14 @@ class nsIParserNode : public nsISupports {
*/
virtual void GetSource(nsString& aString)=0;
/*
* Get and set the ID attribute atom for this node.
* See http://www.w3.org/TR/1998/REC-xml-19980210#sec-attribute-types
* for the definition of an ID attribute.
*
*/
virtual nsresult GetIDAttributeAtom(nsIAtom** aResult) const = 0;
virtual nsresult SetIDAttributeAtom(nsIAtom* aID) = 0;
};
#endif

View File

@ -383,3 +383,20 @@ void nsCParserNode::GetSource(nsString& aString) {
aString.AppendWithConversion(">");
}
nsresult
nsCParserNode::GetIDAttributeAtom(nsIAtom** aResult) const
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mIDAttributeAtom;
return NS_OK;
}
nsresult
nsCParserNode::SetIDAttributeAtom(nsIAtom* aID)
{
NS_ENSURE_ARG(aID);
mIDAttributeAtom = aID;
return NS_OK;
}

View File

@ -180,6 +180,15 @@ class nsCParserNode : public nsIParserNode {
*/
virtual void GetSource(nsString& aString);
/*
* Get and set the ID attribute atom for this node.
* See http://www.w3.org/TR/1998/REC-xml-19980210#sec-attribute-types
* for the definition of an ID attribute.
*
*/
virtual nsresult GetIDAttributeAtom(nsIAtom** aResult) const;
virtual nsresult SetIDAttributeAtom(nsIAtom* aID);
/**
* This pair of methods allows us to set a generic bit (for arbitrary use)
* on each node stored in the context.
@ -194,6 +203,7 @@ class nsCParserNode : public nsIParserNode {
nsString* mSkippedContent;
PRInt32 mUseCount;
PRBool mGenericState;
nsCOMPtr<nsIAtom> mIDAttributeAtom;
nsITokenRecycler* mRecycler;
};

View File

@ -633,6 +633,14 @@ nsresult CWellFormedDTD::HandleStartToken(CToken* aToken) {
else return kEOF;
}
}
// Pass the ID Attribute atom from the start token to the parser node
CStartToken* startToken = NS_STATIC_CAST(CStartToken *, aToken);
nsCOMPtr<nsIAtom> IDAttr;
result = startToken->GetIDAttributeAtom(getter_AddRefs(IDAttr));
if (IDAttr && NS_SUCCEEDED(result))
result = theNode.SetIDAttributeAtom(IDAttr);
if(NS_OK==result){
if(mSink) {
result=mSink->OpenContainer(theNode);
@ -646,7 +654,7 @@ nsresult CWellFormedDTD::HandleStartToken(CToken* aToken) {
/**
* This method gets called when an end token has been
* encountered in the parse process.
* encountered in the parse process.
*
* @update harishd 08/18/99
*

View File

@ -96,6 +96,7 @@
#include "plarena.h"
#include "nsCSSAtoms.h"
#include "nsIObserverService.h" // for reflow observation
#include "nsIDocShell.h" // for reflow observation
#ifdef MOZ_PERF_METRICS
#include "nsITimeRecorder.h"
#endif
@ -1593,19 +1594,25 @@ PresShell::NotifyReflowObservers(const char *aData)
{
if (!aData) { return NS_ERROR_NULL_POINTER; }
nsresult observerResult = NS_OK;
nsCOMPtr<nsISupports> pDocument;
nsresult result = NS_OK;
nsCOMPtr<nsISupports> pContainer;
nsCOMPtr<nsIDocShell> pDocShell;
nsAutoString sTopic,
sData;
if (mDocument && mObserverService) {
pDocument = do_QueryInterface( mDocument,
&observerResult );
if (NS_SUCCEEDED( observerResult )) {
result = mPresContext->GetContainer( getter_AddRefs( pContainer ) );
if (NS_SUCCEEDED( result ) && pContainer) {
pDocShell = do_QueryInterface( pContainer,
&result );
if (NS_SUCCEEDED( result ) && pDocShell && mObserverService) {
sTopic.AssignWithConversion( NS_PRESSHELL_REFLOW_TOPIC );
sData.AssignWithConversion( aData );
observerResult = mObserverService->Notify( pDocument,
sTopic.GetUnicode( ),
sData.GetUnicode( ) );
result = mObserverService->Notify( pDocShell,
sTopic.GetUnicode( ),
sData.GetUnicode( ) );
// notice that we don't really care what the observer service returns
}
}

View File

@ -22,13 +22,13 @@
/*
* nsINodeInfo is an interface to node info, such as name, prefix, namespace
* ID and possibly other data that is shared shared between nodes (elements
* ID and possibly other data that is shared between nodes (elements
* and attributes) that have the same name, prefix and namespace ID within
* the same document.
*
* nsINodeInfoManager is an interface to an object that manages a list of
* nsINodeInfo's, every document object should hold a strong reference to
* a nsINodeInfoManager and every nsINodeInfo also holds a string reference
* a nsINodeInfoManager and every nsINodeInfo also holds a strong reference
* to their owning manager. When a nsINodeInfo is no longer used it will
* automatically remove itself from its owner manager, and when all
* nsINodeInfo's have been removed from a nsINodeInfoManager and all external
@ -144,13 +144,22 @@ public:
*/
NS_IMETHOD GetNamespaceID(PRInt32& aResult) = 0;
/*
* Get and set the ID attribute atom for this node.
* See http://www.w3.org/TR/1998/REC-xml-19980210#sec-attribute-types
* for the definition of an ID attribute.
*
*/
NS_IMETHOD GetIDAttributeAtom(nsIAtom** aResult) = 0;
NS_IMETHOD SetIDAttributeAtom(nsIAtom* aResult) = 0;
/*
* Get the owning node info manager, this will never return null.
*/
NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager) = 0;
/*
* Utility functions that can be used to check if a nodeinfo holds a spcific
* Utility functions that can be used to check if a nodeinfo holds a specific
* name, name and prefix, name and prefix and namespace ID, or just
* namespace ID.
*/

View File

@ -34,7 +34,7 @@ static PRBool kStrictDOMLevel2 = PR_FALSE;
nsNodeInfo::nsNodeInfo()
: mInner(), mOwnerManager(nsnull)
{
NS_INIT_REFCNT();
NS_INIT_REFCNT();
static PRInt32 been_here = 0;
@ -49,6 +49,7 @@ nsNodeInfo::nsNodeInfo()
been_here = 1;
}
// End of temp hack.
}
@ -213,6 +214,26 @@ nsNodeInfo::GetNamespaceID(PRInt32& aResult)
}
NS_IMETHODIMP
nsNodeInfo::GetIDAttributeAtom(nsIAtom** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mInner.mIDAttributeAtom;
return NS_OK;
}
NS_IMETHODIMP
nsNodeInfo::SetIDAttributeAtom(nsIAtom* aID)
{
NS_ENSURE_ARG(aID);
mInner.mIDAttributeAtom = aID;
return NS_OK;
}
NS_IMETHODIMP
nsNodeInfo::GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager)
{

View File

@ -26,6 +26,8 @@
#include "nsINodeInfo.h"
#include "nsINameSpaceManager.h"
#include "plhash.h"
#include "nsIAtom.h"
#include "nsCOMPtr.h"
/*
* nsNodeInfoInner is used for two things:
@ -43,10 +45,10 @@
struct nsNodeInfoInner
{
nsNodeInfoInner(nsIAtom *aName, nsIAtom *aPrefix, PRInt32 aNamespaceID)
: mName(aName), mPrefix(aPrefix), mNamespaceID(aNamespaceID) {}
: mName(aName), mPrefix(aPrefix), mNamespaceID(aNamespaceID) { }
nsNodeInfoInner()
: mName(nsnull), mPrefix(nsnull), mNamespaceID(kNameSpaceID_None) {}
: mName(nsnull), mPrefix(nsnull), mNamespaceID(kNameSpaceID_None) { }
static PRIntn PR_CALLBACK KeyCompare(const void *key1, const void *key2);
static PLHashNumber PR_CALLBACK GetHashValue(const void *key);
@ -54,6 +56,7 @@ struct nsNodeInfoInner
nsIAtom* mName;
nsIAtom* mPrefix;
PRInt32 mNamespaceID;
nsCOMPtr<nsIAtom> mIDAttributeAtom;
};
@ -73,6 +76,8 @@ public:
NS_IMETHOD GetPrefixAtom(nsIAtom*& aAtom);
NS_IMETHOD GetNamespaceURI(nsAWritableString& aNameSpaceURI);
NS_IMETHOD GetNamespaceID(PRInt32& aResult);
NS_IMETHOD GetIDAttributeAtom(nsIAtom** aResult);
NS_IMETHOD SetIDAttributeAtom(nsIAtom* aResult);
NS_IMETHOD GetNodeInfoManager(nsINodeInfoManager*& aNodeInfoManager);
NS_IMETHOD_(PRBool) Equals(nsIAtom *aNameAtom);
NS_IMETHOD_(PRBool) Equals(const nsAReadableString& aName);

View File

@ -96,6 +96,7 @@
#include "plarena.h"
#include "nsCSSAtoms.h"
#include "nsIObserverService.h" // for reflow observation
#include "nsIDocShell.h" // for reflow observation
#ifdef MOZ_PERF_METRICS
#include "nsITimeRecorder.h"
#endif
@ -1593,19 +1594,25 @@ PresShell::NotifyReflowObservers(const char *aData)
{
if (!aData) { return NS_ERROR_NULL_POINTER; }
nsresult observerResult = NS_OK;
nsCOMPtr<nsISupports> pDocument;
nsresult result = NS_OK;
nsCOMPtr<nsISupports> pContainer;
nsCOMPtr<nsIDocShell> pDocShell;
nsAutoString sTopic,
sData;
if (mDocument && mObserverService) {
pDocument = do_QueryInterface( mDocument,
&observerResult );
if (NS_SUCCEEDED( observerResult )) {
result = mPresContext->GetContainer( getter_AddRefs( pContainer ) );
if (NS_SUCCEEDED( result ) && pContainer) {
pDocShell = do_QueryInterface( pContainer,
&result );
if (NS_SUCCEEDED( result ) && pDocShell && mObserverService) {
sTopic.AssignWithConversion( NS_PRESSHELL_REFLOW_TOPIC );
sData.AssignWithConversion( aData );
observerResult = mObserverService->Notify( pDocument,
sTopic.GetUnicode( ),
sData.GetUnicode( ) );
result = mObserverService->Notify( pDocShell,
sTopic.GetUnicode( ),
sData.GetUnicode( ) );
// notice that we don't really care what the observer service returns
}
}

View File

@ -630,7 +630,6 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
static NS_DEFINE_IID(kParserBundleIID, NS_IPARSER_BUNDLE_IID);
if (needsParser)
{
@ -656,17 +655,16 @@ nsHTMLDocument::StartDocumentLoad(const char* aCommand,
nsCOMPtr<nsIDocShell> docShell(do_QueryInterface(aContainer));
if(mParser) {
nsCOMPtr<nsIWebShellServices> webShellServices(do_QueryInterface(docShell));
nsISupportsParserBundle* parserBundle=nsnull;
nsCOMPtr<nsISupportsParserBundle> parserBundle;
nsresult result;
nsresult result=mParser->QueryInterface(kParserBundleIID,(void**)&parserBundle);
parserBundle = do_QueryInterface(mParser, &result);
if(NS_SUCCEEDED(result)) {
// We do this to help consumers who don't have access to the webshell.
nsAutoString theID;
theID.AssignWithConversion("webshell");
parserBundle->SetDataIntoBundle(theID,webShellServices);
NS_IF_RELEASE(parserBundle);
theID.AssignWithConversion("docshell");
parserBundle->SetDataIntoBundle(theID,docShell);
}
}

View File

@ -24,7 +24,7 @@
#define nsIXMLContent_h___
#include "nsISupports.h"
#include "nsIContent.h"
#include "nsIStyledContent.h"
class nsINameSpace;
class nsINodeInfo;
@ -37,7 +37,7 @@ class nsIWebShell;
/**
* XML content extensions to nsIContent
*/
class nsIXMLContent : public nsIContent {
class nsIXMLContent : public nsIStyledContent {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IXMLCONTENT_IID; return iid; }

View File

@ -113,7 +113,12 @@ nsXMLElement::QueryInterface(REFNSIID aIID,
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIStyledContent::GetIID())) {
nsIStyledContent* tmp = this;
*aInstancePtr = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
return NS_NOINTERFACE;
}
@ -494,3 +499,53 @@ nsXMLElement::CloneNode(PRBool aDeep, nsIDOMNode** aReturn)
return it->QueryInterface(kIDOMNodeIID, (void**) aReturn);
}
// nsIStyledContent implementation
NS_IMETHODIMP
nsXMLElement::GetID(nsIAtom*& aResult) const
{
nsresult rv;
nsCOMPtr<nsIAtom> atom;
rv = mInner.mNodeInfo->GetIDAttributeAtom(getter_AddRefs(atom));
aResult = nsnull;
if (NS_SUCCEEDED(rv) && atom) {
nsAutoString value;
rv = GetAttribute(kNameSpaceID_Unknown, atom, value);
if (NS_SUCCEEDED(rv))
aResult = NS_NewAtom(value);
}
return rv;
}
NS_IMETHODIMP
nsXMLElement::GetClasses(nsVoidArray& aArray) const
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXMLElement::HasClass(nsIAtom* aClass) const
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXMLElement::GetContentStyleRules(nsISupportsArray* aRules)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXMLElement::GetInlineStyleRules(nsISupportsArray* aRules)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsXMLElement::GetMappedAttributeImpact(const nsIAtom* aAttribute,
PRInt32& aHint) const
{
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@ -30,6 +30,7 @@
#include "nsIXMLContent.h"
#include "nsIJSScriptObject.h"
#include "nsGenericXMLElement.h"
#include "nsIStyledContent.h"
class nsIDocument;
class nsIAtom;
@ -225,6 +226,15 @@ public:
}
NS_IMETHOD MaybeTriggerAutoLink(nsIWebShell *aShell);
// nsIStyledContent
NS_IMETHOD GetID(nsIAtom*& aResult) const;
NS_IMETHOD GetClasses(nsVoidArray& aArray) const;
NS_IMETHOD HasClass(nsIAtom* aClass) const;
NS_IMETHOD GetContentStyleRules(nsISupportsArray* aRules);
NS_IMETHOD GetInlineStyleRules(nsISupportsArray* aRules);
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
PRInt32& aHint) const;
// nsIJSScriptObject
virtual PRBool AddProperty(JSContext *aContext, JSObject *aObj, jsval aID, jsval *aVp) {
return mInner.AddProperty(aContext, aObj, aID, aVp);

View File

@ -792,6 +792,12 @@ nsXMLContentSink::OpenContainer(const nsIParserNode& aNode)
PushContent(content);
}
}
// Set the ID attribute atom on the node info object for this node
nsCOMPtr<nsIAtom> IDAttr;
result = aNode.GetIDAttributeAtom(getter_AddRefs(IDAttr));
if (IDAttr && NS_SUCCEEDED(result))
result = nodeInfo->SetIDAttributeAtom(IDAttr);
}
return result;

View File

@ -399,6 +399,18 @@ nsXMLDocument::StartDocumentLoad(const char* aCommand,
else rv = NS_NewXMLContentSink(&sink, this, aUrl, nsnull);
if(NS_SUCCEEDED(rv) && (docShell)) {
nsCOMPtr<nsISupportsParserBundle> parserBundle;
nsresult result;
parserBundle = do_QueryInterface(mParser, &result);
if(NS_SUCCEEDED(result)) {
// We do this to help consumers who don't have access to the webshell.
nsAutoString theID;
theID.AssignWithConversion("docshell");
parserBundle->SetDataIntoBundle(theID,docShell);
}
nsCOMPtr<nsIContentViewer> cv;
docShell->GetContentViewer(getter_AddRefs(cv));
if (cv) {

View File

@ -48,7 +48,7 @@
#include "nsIView.h"
class AnonymousElement : public nsXMLElement, public nsIStyledContent, public nsIAnonymousContent
class AnonymousElement : public nsXMLElement, public nsIAnonymousContent
{
public:
AnonymousElement(nsINodeInfo *aNodeInfo):nsXMLElement(aNodeInfo) {}

View File

@ -506,11 +506,22 @@ void nsExpatTokenizer::FrontloadMisplacedContent(nsDeque& aDeque){
void nsExpatTokenizer::HandleStartElement(void *userData, const XML_Char *name, const XML_Char **atts) {
XMLParserState* state = (XMLParserState*) userData;
CToken* theToken = state->tokenRecycler->CreateTokenOfType(eToken_start,eHTMLTag_unknown);
if(theToken) {
if(theToken) {
// If an ID attribute exists for this element, set it on the start token
PRInt32 index = XML_GetIdAttributeIndex(state->parser);
if (index >= 0) {
nsCOMPtr<nsIAtom> attributeAtom = dont_AddRef(NS_NewAtom((const PRUnichar *) atts[index]));
CStartToken* startToken = NS_STATIC_CAST(CStartToken*, theToken);
startToken->SetIDAttributeAtom(attributeAtom);
}
// Set the element name on the start token and add the token to the token queue
nsString& theString=theToken->GetStringValueXXX();
theString.Assign((PRUnichar *) name);
AddToken(theToken, NS_OK, state->tokenDeque, state->tokenRecycler);
int theAttrCount=0;
// For each attribute on this element, create and add attribute tokens to the token queue
int theAttrCount=0;
while(*atts){
theAttrCount++;
CAttributeToken* theAttrToken = (CAttributeToken*)
@ -519,7 +530,7 @@ void nsExpatTokenizer::HandleStartElement(void *userData, const XML_Char *name,
nsString& theKey=theAttrToken->GetKey();
theKey.Assign((PRUnichar *) (*atts++));
nsString& theValue=theAttrToken->GetStringValueXXX();
theValue.Assign((PRUnichar *) (*atts++));
theValue.Assign((PRUnichar *) (*atts++));
}
CToken* theTok=(CToken*)theAttrToken;
AddToken(theTok, NS_OK, state->tokenDeque, state->tokenRecycler);
@ -843,7 +854,7 @@ int nsExpatTokenizer::HandleExternalEntityRef(XML_Parser parser,
}
#else /* ! XML_DTD */
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleExternalEntityRef() not yet implemented.");
NS_NOTYETIMPLEMENTED("Error: nsExpatTokenizer::HandleExternalEntityRef() not yet implemented.");
#endif /* XML_DTD */

View File

@ -140,6 +140,24 @@ void CStartToken::Reinitialize(PRInt32 aTag, const nsString& aString){
mTrailingContent.Truncate();
}
nsresult CStartToken::GetIDAttributeAtom(nsIAtom** aResult)
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mIDAttributeAtom;
return NS_OK;
}
nsresult CStartToken::SetIDAttributeAtom(nsIAtom* aID)
{
NS_ENSURE_ARG(aID);
mIDAttributeAtom = aID;
return NS_OK;
}
/*
* This method returns the typeid (the tag type) for this token.
*

View File

@ -130,14 +130,23 @@ class CStartToken: public CHTMLToken {
virtual void DebugDumpSource(nsOutputStream& out);
virtual void GetSource(nsString& anOutputString);
virtual void AppendSource(nsString& anOutputString);
virtual void Reinitialize(PRInt32 aTag, const nsString& aString);
/*
* Get and set the ID attribute atom for this element.
* See http://www.w3.org/TR/1998/REC-xml-19980210#sec-attribute-types
* for the definition of an ID attribute.
*
*/
virtual nsresult GetIDAttributeAtom(nsIAtom** aResult);
virtual nsresult SetIDAttributeAtom(nsIAtom* aID);
nsString mTrailingContent;
PRInt32 mOrigin;
protected:
PRBool mAttributed;
PRBool mEmpty;
PRBool mEmpty;
nsCOMPtr<nsIAtom> mIDAttributeAtom;
};
@ -283,8 +292,7 @@ class CAttributeToken: public CHTMLToken {
virtual void Reinitialize(PRInt32 aTag, const nsString& aString);
PRBool mHasEqualWithoutValue;
nsString mTextKey;
nsString mTextKey;
};

View File

@ -155,8 +155,14 @@ class nsIParserNode : public nsISupports {
*/
virtual void GetSource(nsString& aString)=0;
/*
* Get and set the ID attribute atom for this node.
* See http://www.w3.org/TR/1998/REC-xml-19980210#sec-attribute-types
* for the definition of an ID attribute.
*
*/
virtual nsresult GetIDAttributeAtom(nsIAtom** aResult) const = 0;
virtual nsresult SetIDAttributeAtom(nsIAtom* aID) = 0;
};
#endif

View File

@ -383,3 +383,20 @@ void nsCParserNode::GetSource(nsString& aString) {
aString.AppendWithConversion(">");
}
nsresult
nsCParserNode::GetIDAttributeAtom(nsIAtom** aResult) const
{
NS_ENSURE_ARG_POINTER(aResult);
*aResult = mIDAttributeAtom;
return NS_OK;
}
nsresult
nsCParserNode::SetIDAttributeAtom(nsIAtom* aID)
{
NS_ENSURE_ARG(aID);
mIDAttributeAtom = aID;
return NS_OK;
}

View File

@ -180,6 +180,15 @@ class nsCParserNode : public nsIParserNode {
*/
virtual void GetSource(nsString& aString);
/*
* Get and set the ID attribute atom for this node.
* See http://www.w3.org/TR/1998/REC-xml-19980210#sec-attribute-types
* for the definition of an ID attribute.
*
*/
virtual nsresult GetIDAttributeAtom(nsIAtom** aResult) const;
virtual nsresult SetIDAttributeAtom(nsIAtom* aID);
/**
* This pair of methods allows us to set a generic bit (for arbitrary use)
* on each node stored in the context.
@ -194,6 +203,7 @@ class nsCParserNode : public nsIParserNode {
nsString* mSkippedContent;
PRInt32 mUseCount;
PRBool mGenericState;
nsCOMPtr<nsIAtom> mIDAttributeAtom;
nsITokenRecycler* mRecycler;
};

View File

@ -633,6 +633,14 @@ nsresult CWellFormedDTD::HandleStartToken(CToken* aToken) {
else return kEOF;
}
}
// Pass the ID Attribute atom from the start token to the parser node
CStartToken* startToken = NS_STATIC_CAST(CStartToken *, aToken);
nsCOMPtr<nsIAtom> IDAttr;
result = startToken->GetIDAttributeAtom(getter_AddRefs(IDAttr));
if (IDAttr && NS_SUCCEEDED(result))
result = theNode.SetIDAttributeAtom(IDAttr);
if(NS_OK==result){
if(mSink) {
result=mSink->OpenContainer(theNode);
@ -646,7 +654,7 @@ nsresult CWellFormedDTD::HandleStartToken(CToken* aToken) {
/**
* This method gets called when an end token has been
* encountered in the parse process.
* encountered in the parse process.
*
* @update harishd 08/18/99
*

View File

@ -311,8 +311,7 @@ public:
*/
class nsXULElement : public nsIStyledContent,
public nsIXMLContent,
class nsXULElement : public nsIXMLContent,
public nsIXULContent,
public nsIDOMXULElement,
public nsIDOMEventReceiver,
@ -392,6 +391,13 @@ public:
NS_IMETHOD GetBindingParent(nsIContent** aContent);
NS_IMETHOD SetBindingParent(nsIContent* aParent);
// nsIXMLContent
NS_IMETHOD SetContainingNameSpace(nsINameSpace* aNameSpace);
NS_IMETHOD GetContainingNameSpace(nsINameSpace*& aNameSpace) const;
NS_IMETHOD SetNameSpacePrefix(nsIAtom* aNameSpace);
NS_IMETHOD GetNameSpacePrefix(nsIAtom*& aNameSpace) const;
NS_IMETHOD MaybeTriggerAutoLink(nsIWebShell *aShell);
// nsIStyledContent
NS_IMETHOD GetID(nsIAtom*& aResult) const;
NS_IMETHOD GetClasses(nsVoidArray& aArray) const;
@ -402,12 +408,6 @@ public:
NS_IMETHOD GetMappedAttributeImpact(const nsIAtom* aAttribute,
PRInt32& aHint) const;
// nsIXMLContent
NS_IMETHOD SetContainingNameSpace(nsINameSpace* aNameSpace);
NS_IMETHOD GetContainingNameSpace(nsINameSpace*& aNameSpace) const;
NS_IMETHOD SetNameSpacePrefix(nsIAtom* aNameSpace);
NS_IMETHOD GetNameSpacePrefix(nsIAtom*& aNameSpace) const;
NS_IMETHOD MaybeTriggerAutoLink(nsIWebShell *aShell);
// nsIXULContent
NS_IMETHOD PeekChildCount(PRInt32& aCount) const;