52381 - DOM selectorText implementation, r=attinasi/jst, sr=waterson

This commit is contained in:
hewitt%netscape.com 2001-01-22 04:03:48 +00:00
parent 6bcebbe36c
commit b061c11ad1
15 changed files with 429 additions and 33 deletions

View File

@ -1220,6 +1220,7 @@ PRBool CSSParserImpl::ParseRuleSet(PRInt32& aErrorCode)
{
// First get the list of selectors for the rule
SelectorList* slist = nsnull;
PRUint32 linenum = mScanner->GetLineNumber();
if (! ParseSelectorList(aErrorCode, slist)) {
REPORT_UNEXPECTED1(NS_LITERAL_STRING("Ruleset ignored due to bad selector"));
SkipRuleSet(aErrorCode);
@ -1248,6 +1249,7 @@ PRBool CSSParserImpl::ParseRuleSet(PRInt32& aErrorCode)
while (nsnull != list) {
nsICSSStyleRule* rule = nsnull;
NS_NewCSSStyleRule(&rule, *(list->mSelectors));
if (nsnull != rule) {
if (nsnull != list->mSelectors->mNext) { // hand off other selectors to new rule
@ -1255,6 +1257,7 @@ PRBool CSSParserImpl::ParseRuleSet(PRInt32& aErrorCode)
ruleFirst->mNext = list->mSelectors->mNext;
list->mSelectors->mNext = nsnull;
}
rule->SetLineNumber(linenum);
rule->SetDeclaration(declaration);
rule->SetWeight(list->mWeight);
rule->SetSourceSelectorText(list->mSourceString); // capture the original input (need this for namespace prefixes)

View File

@ -174,9 +174,8 @@ nsCSSScanner::nsCSSScanner()
mPushback = mLocalPushback;
mPushbackCount = 0;
mPushbackSize = 4;
#ifdef CSS_REPORT_PARSE_ERRORS
mLineNumber = 1;
mLastRead = 0;
#endif
}
nsCSSScanner::~nsCSSScanner()
@ -209,7 +208,6 @@ void nsCSSScanner::InitErrorReporting(nsIURI* aURI)
} else {
mFileName = "from DOM";
}
mLineNumber = 1;
mColNumber = 0;
}
@ -246,6 +244,11 @@ void nsCSSScanner::ReportError(const nsAReadableString& aError)
#endif // CSS_REPORT_PARSE_ERRORS
PRUint32 nsCSSScanner::GetLineNumber()
{
return mLineNumber;
}
void nsCSSScanner::Close()
{
NS_IF_RELEASE(mInput);
@ -274,11 +277,14 @@ PRInt32 nsCSSScanner::Read(PRInt32& aErrorCode)
}
}
rv = PRInt32(mBuffer[mOffset++]);
#ifdef CSS_REPORT_PARSE_ERRORS
if (((rv == '\n') && (mLastRead != '\r')) || (rv == '\r')) {
mLineNumber++;
#ifdef CSS_REPORT_PARSE_ERRORS
mColNumber = 0;
} else if (rv == '\t') {
#endif
}
#ifdef CSS_REPORT_PARSE_ERRORS
else if (rv == '\t') {
mColNumber = ((mColNumber - 1 + TAB_STOP_WIDTH) / TAB_STOP_WIDTH)
* TAB_STOP_WIDTH;
} else if (rv != '\n') {

View File

@ -110,6 +110,8 @@ class nsCSSScanner {
void ReportError(const nsAReadableString& aError);
#endif
PRUint32 GetLineNumber();
// Get the next token. Return nsfalse on EOF or ERROR. aTokenResult
// is filled in with the data for the token.
PRBool Next(PRInt32& aErrorCode, nsCSSToken& aTokenResult);
@ -153,9 +155,9 @@ protected:
PRInt32 mLastRead;
PRUnichar mLocalPushback[4];
PRUint32 mLineNumber;
#ifdef CSS_REPORT_PARSE_ERRORS
nsXPIDLCString mFileName;
PRUint32 mLineNumber;
PRUint32 mColNumber;
#endif

View File

@ -50,6 +50,7 @@
#include "nsIScriptObjectOwner.h"
#include "nsDOMCSSDeclaration.h"
#include "nsINameSpaceManager.h"
#include "nsINameSpace.h"
#include "nsILookAndFeel.h"
#include "nsIStyleSet.h"
@ -603,8 +604,112 @@ void nsCSSSelector::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize)
}
}
nsresult nsCSSSelector::ToString( nsAWritableString& aString ) const
nsresult nsCSSSelector::ToString( nsAWritableString& aString, nsICSSStyleSheet* aSheet ) const
{
const PRUnichar* temp;
// selectors are linked from right-to-left, so the next selector in the linked list
// actually precedes this one in the resulting string
if (mNext) {
mNext->ToString(aString, aSheet);
aString.Append(PRUnichar(' '));
}
// append the namespace prefix
if (mNameSpace > 0) {
nsCOMPtr<nsINameSpace> sheetNS;
aSheet->GetNameSpace(*getter_AddRefs(sheetNS));
nsCOMPtr<nsIAtom> prefixAtom;
// will return null if namespace was the default
sheetNS->FindNameSpacePrefix(mNameSpace, *getter_AddRefs(prefixAtom));
if (prefixAtom) {
const PRUnichar* prefix;
prefixAtom->GetUnicode(&prefix);
aString.Append(prefix);
aString.Append(PRUnichar('|'));
}
}
// smells like a universal selector
if (!mTag && !mID && !mClassList) {
aString.Append(PRUnichar('*'));
} else {
// Append the tag name, if there is one
if (mTag) {
mTag->GetUnicode(&temp);
aString.Append(temp);
}
// Append the id, if there is one
if (mID) {
mID->GetUnicode(&temp);
aString.Append(PRUnichar('#'));
aString.Append(temp);
}
// Append each class in the linked list
if (mClassList) {
nsAtomList* list = mClassList;
while (list != nsnull) {
list->mAtom->GetUnicode(&temp);
aString.Append(PRUnichar('.'));
aString.Append(temp);
list = list->mNext;
}
}
}
// Append each attribute selector in the linked list
if (mAttrList) {
nsAttrSelector* list = mAttrList;
while (list != nsnull) {
aString.Append(PRUnichar('['));
// Append the namespace prefix
if (list->mNameSpace > 0) {
nsCOMPtr<nsINameSpace> sheetNS;
aSheet->GetNameSpace(*getter_AddRefs(sheetNS));
nsCOMPtr<nsIAtom> prefixAtom;
// will return null if namespace was the default
sheetNS->FindNameSpacePrefix(list->mNameSpace, *getter_AddRefs(prefixAtom));
if (prefixAtom) {
const PRUnichar* prefix;
prefixAtom->GetUnicode(&prefix);
aString.Append(prefix);
aString.Append(PRUnichar('|'));
}
}
// Append the attribute name
list->mAttr->GetUnicode(&temp);
aString.Append(temp);
// Append the function
if (list->mFunction == NS_ATTR_FUNC_EQUALS) {
aString.Append(PRUnichar('='));
} else if (list->mFunction == NS_ATTR_FUNC_INCLUDES) {
aString.Append(PRUnichar('~'));
aString.Append(PRUnichar('='));
} else if (list->mFunction == NS_ATTR_FUNC_DASHMATCH) {
aString.Append(PRUnichar('|'));
aString.Append(PRUnichar('='));
}
// Append the value
aString.Append(list->mValue);
aString.Append(PRUnichar(']'));
list = list->mNext;
}
}
// Append each pseudo-class in the linked list
if (mPseudoClassList) {
nsAtomList* list = mPseudoClassList;
while (list != nsnull) {
list->mAtom->GetUnicode(&temp);
aString.Append(temp);
list = list->mNext;
}
}
// Append the operator
if (mOperator) {
aString.Append(PRUnichar(' '));
aString.Append(mOperator);
}
return NS_OK;
}
@ -1009,6 +1114,9 @@ public:
virtual void SetSourceSelectorText(const nsString& aSelectorText);
virtual void GetSourceSelectorText(nsString& aSelectorText) const;
virtual PRUint32 GetLineNumber(void) const;
virtual void SetLineNumber(PRUint32 aLineNumber);
virtual nsICSSDeclaration* GetDeclaration(void) const;
virtual void SetDeclaration(nsICSSDeclaration* aDeclaration);
@ -1054,6 +1162,7 @@ protected:
CSSImportantRule* mImportantRule;
DOMCSSDeclarationImpl* mDOMDeclaration;
void* mScriptObject;
PRUint32 mLineNumber;
};
#ifdef DEBUG_REFS
@ -1287,9 +1396,18 @@ void CSSStyleRuleImpl::SetSourceSelectorText(const nsString& aSelectorText)
void CSSStyleRuleImpl::GetSourceSelectorText(nsString& aSelectorText) const
{
mSelector.ToString( aSelectorText );
mSelector.ToString( aSelectorText, mSheet );
}
PRUint32 CSSStyleRuleImpl::GetLineNumber(void) const
{
return mLineNumber;
}
void CSSStyleRuleImpl::SetLineNumber(PRUint32 aLineNumber)
{
mLineNumber = aLineNumber;
}
nsICSSDeclaration* CSSStyleRuleImpl::GetDeclaration(void) const
{
@ -3349,7 +3467,7 @@ CSSStyleRuleImpl::GetType(PRUint16* aType)
NS_IMETHODIMP
CSSStyleRuleImpl::GetCssText(nsAWritableString& aCssText)
{
mSelector.ToString( aCssText );
mSelector.ToString( aCssText, mSheet );
if (mDeclaration)
{
nsAutoString tempString;
@ -3385,7 +3503,7 @@ CSSStyleRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
NS_IMETHODIMP
CSSStyleRuleImpl::GetSelectorText(nsAWritableString& aSelectorText)
{
mSelector.ToString( aSelectorText );
mSelector.ToString( aSelectorText, mSheet );
return NS_OK;
}

View File

@ -99,7 +99,7 @@ public:
PRInt32 CalcWeight(void) const;
void SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize);
nsresult ToString( nsAWritableString& aString ) const;
nsresult ToString( nsAWritableString& aString, nsICSSStyleSheet* aSheet ) const;
public:
PRInt32 mNameSpace;
@ -127,6 +127,9 @@ public:
virtual void SetSourceSelectorText(const nsString& aSelectorText) = 0;
virtual void GetSourceSelectorText(nsString& aSelectorText) const = 0;
virtual PRUint32 GetLineNumber(void) const = 0;
virtual void SetLineNumber(PRUint32 aLineNumber) = 0;
virtual nsICSSDeclaration* GetDeclaration(void) const = 0;
virtual void SetDeclaration(nsICSSDeclaration* aDeclaration) = 0;

View File

@ -1220,6 +1220,7 @@ PRBool CSSParserImpl::ParseRuleSet(PRInt32& aErrorCode)
{
// First get the list of selectors for the rule
SelectorList* slist = nsnull;
PRUint32 linenum = mScanner->GetLineNumber();
if (! ParseSelectorList(aErrorCode, slist)) {
REPORT_UNEXPECTED1(NS_LITERAL_STRING("Ruleset ignored due to bad selector"));
SkipRuleSet(aErrorCode);
@ -1248,6 +1249,7 @@ PRBool CSSParserImpl::ParseRuleSet(PRInt32& aErrorCode)
while (nsnull != list) {
nsICSSStyleRule* rule = nsnull;
NS_NewCSSStyleRule(&rule, *(list->mSelectors));
if (nsnull != rule) {
if (nsnull != list->mSelectors->mNext) { // hand off other selectors to new rule
@ -1255,6 +1257,7 @@ PRBool CSSParserImpl::ParseRuleSet(PRInt32& aErrorCode)
ruleFirst->mNext = list->mSelectors->mNext;
list->mSelectors->mNext = nsnull;
}
rule->SetLineNumber(linenum);
rule->SetDeclaration(declaration);
rule->SetWeight(list->mWeight);
rule->SetSourceSelectorText(list->mSourceString); // capture the original input (need this for namespace prefixes)

View File

@ -174,9 +174,8 @@ nsCSSScanner::nsCSSScanner()
mPushback = mLocalPushback;
mPushbackCount = 0;
mPushbackSize = 4;
#ifdef CSS_REPORT_PARSE_ERRORS
mLineNumber = 1;
mLastRead = 0;
#endif
}
nsCSSScanner::~nsCSSScanner()
@ -209,7 +208,6 @@ void nsCSSScanner::InitErrorReporting(nsIURI* aURI)
} else {
mFileName = "from DOM";
}
mLineNumber = 1;
mColNumber = 0;
}
@ -246,6 +244,11 @@ void nsCSSScanner::ReportError(const nsAReadableString& aError)
#endif // CSS_REPORT_PARSE_ERRORS
PRUint32 nsCSSScanner::GetLineNumber()
{
return mLineNumber;
}
void nsCSSScanner::Close()
{
NS_IF_RELEASE(mInput);
@ -274,11 +277,14 @@ PRInt32 nsCSSScanner::Read(PRInt32& aErrorCode)
}
}
rv = PRInt32(mBuffer[mOffset++]);
#ifdef CSS_REPORT_PARSE_ERRORS
if (((rv == '\n') && (mLastRead != '\r')) || (rv == '\r')) {
mLineNumber++;
#ifdef CSS_REPORT_PARSE_ERRORS
mColNumber = 0;
} else if (rv == '\t') {
#endif
}
#ifdef CSS_REPORT_PARSE_ERRORS
else if (rv == '\t') {
mColNumber = ((mColNumber - 1 + TAB_STOP_WIDTH) / TAB_STOP_WIDTH)
* TAB_STOP_WIDTH;
} else if (rv != '\n') {

View File

@ -110,6 +110,8 @@ class nsCSSScanner {
void ReportError(const nsAReadableString& aError);
#endif
PRUint32 GetLineNumber();
// Get the next token. Return nsfalse on EOF or ERROR. aTokenResult
// is filled in with the data for the token.
PRBool Next(PRInt32& aErrorCode, nsCSSToken& aTokenResult);
@ -153,9 +155,9 @@ protected:
PRInt32 mLastRead;
PRUnichar mLocalPushback[4];
PRUint32 mLineNumber;
#ifdef CSS_REPORT_PARSE_ERRORS
nsXPIDLCString mFileName;
PRUint32 mLineNumber;
PRUint32 mColNumber;
#endif

View File

@ -50,6 +50,7 @@
#include "nsIScriptObjectOwner.h"
#include "nsDOMCSSDeclaration.h"
#include "nsINameSpaceManager.h"
#include "nsINameSpace.h"
#include "nsILookAndFeel.h"
#include "nsIStyleSet.h"
@ -603,8 +604,112 @@ void nsCSSSelector::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize)
}
}
nsresult nsCSSSelector::ToString( nsAWritableString& aString ) const
nsresult nsCSSSelector::ToString( nsAWritableString& aString, nsICSSStyleSheet* aSheet ) const
{
const PRUnichar* temp;
// selectors are linked from right-to-left, so the next selector in the linked list
// actually precedes this one in the resulting string
if (mNext) {
mNext->ToString(aString, aSheet);
aString.Append(PRUnichar(' '));
}
// append the namespace prefix
if (mNameSpace > 0) {
nsCOMPtr<nsINameSpace> sheetNS;
aSheet->GetNameSpace(*getter_AddRefs(sheetNS));
nsCOMPtr<nsIAtom> prefixAtom;
// will return null if namespace was the default
sheetNS->FindNameSpacePrefix(mNameSpace, *getter_AddRefs(prefixAtom));
if (prefixAtom) {
const PRUnichar* prefix;
prefixAtom->GetUnicode(&prefix);
aString.Append(prefix);
aString.Append(PRUnichar('|'));
}
}
// smells like a universal selector
if (!mTag && !mID && !mClassList) {
aString.Append(PRUnichar('*'));
} else {
// Append the tag name, if there is one
if (mTag) {
mTag->GetUnicode(&temp);
aString.Append(temp);
}
// Append the id, if there is one
if (mID) {
mID->GetUnicode(&temp);
aString.Append(PRUnichar('#'));
aString.Append(temp);
}
// Append each class in the linked list
if (mClassList) {
nsAtomList* list = mClassList;
while (list != nsnull) {
list->mAtom->GetUnicode(&temp);
aString.Append(PRUnichar('.'));
aString.Append(temp);
list = list->mNext;
}
}
}
// Append each attribute selector in the linked list
if (mAttrList) {
nsAttrSelector* list = mAttrList;
while (list != nsnull) {
aString.Append(PRUnichar('['));
// Append the namespace prefix
if (list->mNameSpace > 0) {
nsCOMPtr<nsINameSpace> sheetNS;
aSheet->GetNameSpace(*getter_AddRefs(sheetNS));
nsCOMPtr<nsIAtom> prefixAtom;
// will return null if namespace was the default
sheetNS->FindNameSpacePrefix(list->mNameSpace, *getter_AddRefs(prefixAtom));
if (prefixAtom) {
const PRUnichar* prefix;
prefixAtom->GetUnicode(&prefix);
aString.Append(prefix);
aString.Append(PRUnichar('|'));
}
}
// Append the attribute name
list->mAttr->GetUnicode(&temp);
aString.Append(temp);
// Append the function
if (list->mFunction == NS_ATTR_FUNC_EQUALS) {
aString.Append(PRUnichar('='));
} else if (list->mFunction == NS_ATTR_FUNC_INCLUDES) {
aString.Append(PRUnichar('~'));
aString.Append(PRUnichar('='));
} else if (list->mFunction == NS_ATTR_FUNC_DASHMATCH) {
aString.Append(PRUnichar('|'));
aString.Append(PRUnichar('='));
}
// Append the value
aString.Append(list->mValue);
aString.Append(PRUnichar(']'));
list = list->mNext;
}
}
// Append each pseudo-class in the linked list
if (mPseudoClassList) {
nsAtomList* list = mPseudoClassList;
while (list != nsnull) {
list->mAtom->GetUnicode(&temp);
aString.Append(temp);
list = list->mNext;
}
}
// Append the operator
if (mOperator) {
aString.Append(PRUnichar(' '));
aString.Append(mOperator);
}
return NS_OK;
}
@ -1009,6 +1114,9 @@ public:
virtual void SetSourceSelectorText(const nsString& aSelectorText);
virtual void GetSourceSelectorText(nsString& aSelectorText) const;
virtual PRUint32 GetLineNumber(void) const;
virtual void SetLineNumber(PRUint32 aLineNumber);
virtual nsICSSDeclaration* GetDeclaration(void) const;
virtual void SetDeclaration(nsICSSDeclaration* aDeclaration);
@ -1054,6 +1162,7 @@ protected:
CSSImportantRule* mImportantRule;
DOMCSSDeclarationImpl* mDOMDeclaration;
void* mScriptObject;
PRUint32 mLineNumber;
};
#ifdef DEBUG_REFS
@ -1287,9 +1396,18 @@ void CSSStyleRuleImpl::SetSourceSelectorText(const nsString& aSelectorText)
void CSSStyleRuleImpl::GetSourceSelectorText(nsString& aSelectorText) const
{
mSelector.ToString( aSelectorText );
mSelector.ToString( aSelectorText, mSheet );
}
PRUint32 CSSStyleRuleImpl::GetLineNumber(void) const
{
return mLineNumber;
}
void CSSStyleRuleImpl::SetLineNumber(PRUint32 aLineNumber)
{
mLineNumber = aLineNumber;
}
nsICSSDeclaration* CSSStyleRuleImpl::GetDeclaration(void) const
{
@ -3349,7 +3467,7 @@ CSSStyleRuleImpl::GetType(PRUint16* aType)
NS_IMETHODIMP
CSSStyleRuleImpl::GetCssText(nsAWritableString& aCssText)
{
mSelector.ToString( aCssText );
mSelector.ToString( aCssText, mSheet );
if (mDeclaration)
{
nsAutoString tempString;
@ -3385,7 +3503,7 @@ CSSStyleRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
NS_IMETHODIMP
CSSStyleRuleImpl::GetSelectorText(nsAWritableString& aSelectorText)
{
mSelector.ToString( aSelectorText );
mSelector.ToString( aSelectorText, mSheet );
return NS_OK;
}

View File

@ -99,7 +99,7 @@ public:
PRInt32 CalcWeight(void) const;
void SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize);
nsresult ToString( nsAWritableString& aString ) const;
nsresult ToString( nsAWritableString& aString, nsICSSStyleSheet* aSheet ) const;
public:
PRInt32 mNameSpace;
@ -127,6 +127,9 @@ public:
virtual void SetSourceSelectorText(const nsString& aSelectorText) = 0;
virtual void GetSourceSelectorText(nsString& aSelectorText) const = 0;
virtual PRUint32 GetLineNumber(void) const = 0;
virtual void SetLineNumber(PRUint32 aLineNumber) = 0;
virtual nsICSSDeclaration* GetDeclaration(void) const = 0;
virtual void SetDeclaration(nsICSSDeclaration* aDeclaration) = 0;

View File

@ -1220,6 +1220,7 @@ PRBool CSSParserImpl::ParseRuleSet(PRInt32& aErrorCode)
{
// First get the list of selectors for the rule
SelectorList* slist = nsnull;
PRUint32 linenum = mScanner->GetLineNumber();
if (! ParseSelectorList(aErrorCode, slist)) {
REPORT_UNEXPECTED1(NS_LITERAL_STRING("Ruleset ignored due to bad selector"));
SkipRuleSet(aErrorCode);
@ -1248,6 +1249,7 @@ PRBool CSSParserImpl::ParseRuleSet(PRInt32& aErrorCode)
while (nsnull != list) {
nsICSSStyleRule* rule = nsnull;
NS_NewCSSStyleRule(&rule, *(list->mSelectors));
if (nsnull != rule) {
if (nsnull != list->mSelectors->mNext) { // hand off other selectors to new rule
@ -1255,6 +1257,7 @@ PRBool CSSParserImpl::ParseRuleSet(PRInt32& aErrorCode)
ruleFirst->mNext = list->mSelectors->mNext;
list->mSelectors->mNext = nsnull;
}
rule->SetLineNumber(linenum);
rule->SetDeclaration(declaration);
rule->SetWeight(list->mWeight);
rule->SetSourceSelectorText(list->mSourceString); // capture the original input (need this for namespace prefixes)

View File

@ -174,9 +174,8 @@ nsCSSScanner::nsCSSScanner()
mPushback = mLocalPushback;
mPushbackCount = 0;
mPushbackSize = 4;
#ifdef CSS_REPORT_PARSE_ERRORS
mLineNumber = 1;
mLastRead = 0;
#endif
}
nsCSSScanner::~nsCSSScanner()
@ -209,7 +208,6 @@ void nsCSSScanner::InitErrorReporting(nsIURI* aURI)
} else {
mFileName = "from DOM";
}
mLineNumber = 1;
mColNumber = 0;
}
@ -246,6 +244,11 @@ void nsCSSScanner::ReportError(const nsAReadableString& aError)
#endif // CSS_REPORT_PARSE_ERRORS
PRUint32 nsCSSScanner::GetLineNumber()
{
return mLineNumber;
}
void nsCSSScanner::Close()
{
NS_IF_RELEASE(mInput);
@ -274,11 +277,14 @@ PRInt32 nsCSSScanner::Read(PRInt32& aErrorCode)
}
}
rv = PRInt32(mBuffer[mOffset++]);
#ifdef CSS_REPORT_PARSE_ERRORS
if (((rv == '\n') && (mLastRead != '\r')) || (rv == '\r')) {
mLineNumber++;
#ifdef CSS_REPORT_PARSE_ERRORS
mColNumber = 0;
} else if (rv == '\t') {
#endif
}
#ifdef CSS_REPORT_PARSE_ERRORS
else if (rv == '\t') {
mColNumber = ((mColNumber - 1 + TAB_STOP_WIDTH) / TAB_STOP_WIDTH)
* TAB_STOP_WIDTH;
} else if (rv != '\n') {

View File

@ -110,6 +110,8 @@ class nsCSSScanner {
void ReportError(const nsAReadableString& aError);
#endif
PRUint32 GetLineNumber();
// Get the next token. Return nsfalse on EOF or ERROR. aTokenResult
// is filled in with the data for the token.
PRBool Next(PRInt32& aErrorCode, nsCSSToken& aTokenResult);
@ -153,9 +155,9 @@ protected:
PRInt32 mLastRead;
PRUnichar mLocalPushback[4];
PRUint32 mLineNumber;
#ifdef CSS_REPORT_PARSE_ERRORS
nsXPIDLCString mFileName;
PRUint32 mLineNumber;
PRUint32 mColNumber;
#endif

View File

@ -50,6 +50,7 @@
#include "nsIScriptObjectOwner.h"
#include "nsDOMCSSDeclaration.h"
#include "nsINameSpaceManager.h"
#include "nsINameSpace.h"
#include "nsILookAndFeel.h"
#include "nsIStyleSet.h"
@ -603,8 +604,112 @@ void nsCSSSelector::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize)
}
}
nsresult nsCSSSelector::ToString( nsAWritableString& aString ) const
nsresult nsCSSSelector::ToString( nsAWritableString& aString, nsICSSStyleSheet* aSheet ) const
{
const PRUnichar* temp;
// selectors are linked from right-to-left, so the next selector in the linked list
// actually precedes this one in the resulting string
if (mNext) {
mNext->ToString(aString, aSheet);
aString.Append(PRUnichar(' '));
}
// append the namespace prefix
if (mNameSpace > 0) {
nsCOMPtr<nsINameSpace> sheetNS;
aSheet->GetNameSpace(*getter_AddRefs(sheetNS));
nsCOMPtr<nsIAtom> prefixAtom;
// will return null if namespace was the default
sheetNS->FindNameSpacePrefix(mNameSpace, *getter_AddRefs(prefixAtom));
if (prefixAtom) {
const PRUnichar* prefix;
prefixAtom->GetUnicode(&prefix);
aString.Append(prefix);
aString.Append(PRUnichar('|'));
}
}
// smells like a universal selector
if (!mTag && !mID && !mClassList) {
aString.Append(PRUnichar('*'));
} else {
// Append the tag name, if there is one
if (mTag) {
mTag->GetUnicode(&temp);
aString.Append(temp);
}
// Append the id, if there is one
if (mID) {
mID->GetUnicode(&temp);
aString.Append(PRUnichar('#'));
aString.Append(temp);
}
// Append each class in the linked list
if (mClassList) {
nsAtomList* list = mClassList;
while (list != nsnull) {
list->mAtom->GetUnicode(&temp);
aString.Append(PRUnichar('.'));
aString.Append(temp);
list = list->mNext;
}
}
}
// Append each attribute selector in the linked list
if (mAttrList) {
nsAttrSelector* list = mAttrList;
while (list != nsnull) {
aString.Append(PRUnichar('['));
// Append the namespace prefix
if (list->mNameSpace > 0) {
nsCOMPtr<nsINameSpace> sheetNS;
aSheet->GetNameSpace(*getter_AddRefs(sheetNS));
nsCOMPtr<nsIAtom> prefixAtom;
// will return null if namespace was the default
sheetNS->FindNameSpacePrefix(list->mNameSpace, *getter_AddRefs(prefixAtom));
if (prefixAtom) {
const PRUnichar* prefix;
prefixAtom->GetUnicode(&prefix);
aString.Append(prefix);
aString.Append(PRUnichar('|'));
}
}
// Append the attribute name
list->mAttr->GetUnicode(&temp);
aString.Append(temp);
// Append the function
if (list->mFunction == NS_ATTR_FUNC_EQUALS) {
aString.Append(PRUnichar('='));
} else if (list->mFunction == NS_ATTR_FUNC_INCLUDES) {
aString.Append(PRUnichar('~'));
aString.Append(PRUnichar('='));
} else if (list->mFunction == NS_ATTR_FUNC_DASHMATCH) {
aString.Append(PRUnichar('|'));
aString.Append(PRUnichar('='));
}
// Append the value
aString.Append(list->mValue);
aString.Append(PRUnichar(']'));
list = list->mNext;
}
}
// Append each pseudo-class in the linked list
if (mPseudoClassList) {
nsAtomList* list = mPseudoClassList;
while (list != nsnull) {
list->mAtom->GetUnicode(&temp);
aString.Append(temp);
list = list->mNext;
}
}
// Append the operator
if (mOperator) {
aString.Append(PRUnichar(' '));
aString.Append(mOperator);
}
return NS_OK;
}
@ -1009,6 +1114,9 @@ public:
virtual void SetSourceSelectorText(const nsString& aSelectorText);
virtual void GetSourceSelectorText(nsString& aSelectorText) const;
virtual PRUint32 GetLineNumber(void) const;
virtual void SetLineNumber(PRUint32 aLineNumber);
virtual nsICSSDeclaration* GetDeclaration(void) const;
virtual void SetDeclaration(nsICSSDeclaration* aDeclaration);
@ -1054,6 +1162,7 @@ protected:
CSSImportantRule* mImportantRule;
DOMCSSDeclarationImpl* mDOMDeclaration;
void* mScriptObject;
PRUint32 mLineNumber;
};
#ifdef DEBUG_REFS
@ -1287,9 +1396,18 @@ void CSSStyleRuleImpl::SetSourceSelectorText(const nsString& aSelectorText)
void CSSStyleRuleImpl::GetSourceSelectorText(nsString& aSelectorText) const
{
mSelector.ToString( aSelectorText );
mSelector.ToString( aSelectorText, mSheet );
}
PRUint32 CSSStyleRuleImpl::GetLineNumber(void) const
{
return mLineNumber;
}
void CSSStyleRuleImpl::SetLineNumber(PRUint32 aLineNumber)
{
mLineNumber = aLineNumber;
}
nsICSSDeclaration* CSSStyleRuleImpl::GetDeclaration(void) const
{
@ -3349,7 +3467,7 @@ CSSStyleRuleImpl::GetType(PRUint16* aType)
NS_IMETHODIMP
CSSStyleRuleImpl::GetCssText(nsAWritableString& aCssText)
{
mSelector.ToString( aCssText );
mSelector.ToString( aCssText, mSheet );
if (mDeclaration)
{
nsAutoString tempString;
@ -3385,7 +3503,7 @@ CSSStyleRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
NS_IMETHODIMP
CSSStyleRuleImpl::GetSelectorText(nsAWritableString& aSelectorText)
{
mSelector.ToString( aSelectorText );
mSelector.ToString( aSelectorText, mSheet );
return NS_OK;
}

View File

@ -99,7 +99,7 @@ public:
PRInt32 CalcWeight(void) const;
void SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize);
nsresult ToString( nsAWritableString& aString ) const;
nsresult ToString( nsAWritableString& aString, nsICSSStyleSheet* aSheet ) const;
public:
PRInt32 mNameSpace;
@ -127,6 +127,9 @@ public:
virtual void SetSourceSelectorText(const nsString& aSelectorText) = 0;
virtual void GetSourceSelectorText(nsString& aSelectorText) const = 0;
virtual PRUint32 GetLineNumber(void) const = 0;
virtual void SetLineNumber(PRUint32 aLineNumber) = 0;
virtual nsICSSDeclaration* GetDeclaration(void) const = 0;
virtual void SetDeclaration(nsICSSDeclaration* aDeclaration) = 0;