зеркало из https://github.com/mozilla/pjs.git
Implemented style sheet and style rule interfaces on CSS classes. Made public new entry point for CSSParser for adding new imports.
This commit is contained in:
Родитель
c131607db5
Коммит
0031f0710a
|
@ -24,7 +24,6 @@ DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
|||
|
||||
CPPSRCS= \
|
||||
nsCommentNode.cpp \
|
||||
nsDOMStyleDeclaration.cpp \
|
||||
nsGenericDOMDataNode.cpp \
|
||||
nsGenericHTMLElement.cpp \
|
||||
nsHTMLAnchorElement.cpp \
|
||||
|
@ -92,7 +91,6 @@ CPPSRCS= \
|
|||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsCommentNode.obj \
|
||||
.\$(OBJDIR)\nsDOMStyleDeclaration.obj \
|
||||
.\$(OBJDIR)\nsGenericDOMDataNode.obj \
|
||||
.\$(OBJDIR)\nsGenericHTMLElement.obj \
|
||||
.\$(OBJDIR)\nsHTMLAnchorElement.obj \
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsIDOMScriptObjectFactory.h"
|
||||
#include "nsIDOMCSSStyleDeclaration.h"
|
||||
#include "nsDOMStyleDeclaration.h"
|
||||
#include "nsDOMCSSDeclaration.h"
|
||||
#include "prprf.h"
|
||||
#include "prmem.h"
|
||||
|
||||
|
@ -175,7 +175,7 @@ public:
|
|||
// nsIDOMNodeList interface
|
||||
NS_DECL_IDOMNODELIST
|
||||
|
||||
void DropContent();
|
||||
void DropReference();
|
||||
|
||||
private:
|
||||
nsGenericHTMLContainerElement *mContent;
|
||||
|
@ -554,6 +554,113 @@ DOMAttributeMap::GetLength(PRUint32 *aLength)
|
|||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class nsDOMCSSAttributeDeclaration : public nsDOMCSSDeclaration
|
||||
{
|
||||
public:
|
||||
nsDOMCSSAttributeDeclaration(nsIHTMLContent *aContent);
|
||||
~nsDOMCSSAttributeDeclaration();
|
||||
|
||||
virtual void DropReference();
|
||||
virtual nsresult GetCSSDeclaration(nsICSSDeclaration **aDecl,
|
||||
PRBool aAllocate);
|
||||
virtual nsresult StylePropertyChanged(const nsString& aPropertyName,
|
||||
PRInt32 aHint);
|
||||
virtual nsresult GetParent(nsISupports **aParent);
|
||||
|
||||
protected:
|
||||
nsIHTMLContent *mContent;
|
||||
};
|
||||
|
||||
nsDOMCSSAttributeDeclaration::nsDOMCSSAttributeDeclaration(nsIHTMLContent *aContent)
|
||||
{
|
||||
// This reference is not reference-counted. The content
|
||||
// object tells us when its about to go away.
|
||||
mContent = aContent;
|
||||
}
|
||||
|
||||
nsDOMCSSAttributeDeclaration::~nsDOMCSSAttributeDeclaration()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
nsDOMCSSAttributeDeclaration::DropReference()
|
||||
{
|
||||
mContent = nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMCSSAttributeDeclaration::GetCSSDeclaration(nsICSSDeclaration **aDecl,
|
||||
PRBool aAllocate)
|
||||
{
|
||||
nsHTMLValue val;
|
||||
nsIStyleRule* rule;
|
||||
nsICSSStyleRule* cssRule;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
*aDecl = nsnull;
|
||||
if (nsnull != mContent) {
|
||||
mContent->GetAttribute(nsHTMLAtoms::style, val);
|
||||
if (eHTMLUnit_ISupports == val.GetUnit()) {
|
||||
rule = (nsIStyleRule*) val.GetISupportsValue();
|
||||
result = rule->QueryInterface(kICSSStyleRuleIID, (void**)&cssRule);
|
||||
if (NS_OK == result) {
|
||||
*aDecl = cssRule->GetDeclaration();
|
||||
NS_RELEASE(cssRule);
|
||||
}
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
else if (PR_TRUE == aAllocate) {
|
||||
result = NS_NewCSSDeclaration(aDecl);
|
||||
if (NS_OK == result) {
|
||||
result = NS_NewCSSStyleRule(&cssRule, nsCSSSelector());
|
||||
if (NS_OK == result) {
|
||||
cssRule->SetDeclaration(*aDecl);
|
||||
cssRule->SetWeight(0x7fffffff);
|
||||
rule = (nsIStyleRule *)cssRule;
|
||||
result = mContent->SetAttribute(nsHTMLAtoms::style,
|
||||
nsHTMLValue(cssRule),
|
||||
PR_FALSE);
|
||||
NS_RELEASE(cssRule);
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(*aDecl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMCSSAttributeDeclaration::StylePropertyChanged(const nsString& aPropertyName,
|
||||
PRInt32 aHint)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
if (nsnull != mContent) {
|
||||
nsIDocument *doc;
|
||||
result = mContent->GetDocument(doc);
|
||||
if (NS_OK == result) {
|
||||
result = doc->AttributeChanged(mContent, nsHTMLAtoms::style, aHint);
|
||||
NS_RELEASE(doc);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMCSSAttributeDeclaration::GetParent(nsISupports **aParent)
|
||||
{
|
||||
if (nsnull != mContent) {
|
||||
return mContent->QueryInterface(kISupportsIID, (void **)aParent);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static nsresult EnsureWritableAttributes(nsIHTMLContent* aContent,
|
||||
nsIHTMLAttributes*& aAttributes, PRBool aCreate)
|
||||
{
|
||||
|
@ -641,11 +748,11 @@ nsGenericHTMLElement::~nsGenericHTMLElement()
|
|||
NS_IF_RELEASE(mListenerManager);
|
||||
if (nsnull != mDOMSlots) {
|
||||
if (nsnull != mDOMSlots->mChildNodes) {
|
||||
mDOMSlots->mChildNodes->DropContent();
|
||||
mDOMSlots->mChildNodes->DropReference();
|
||||
NS_RELEASE(mDOMSlots->mChildNodes);
|
||||
}
|
||||
if (nsnull != mDOMSlots->mStyle) {
|
||||
mDOMSlots->mStyle->DropContent();
|
||||
mDOMSlots->mStyle->DropReference();
|
||||
NS_RELEASE(mDOMSlots->mStyle);
|
||||
}
|
||||
// XXX Should really be arena managed
|
||||
|
@ -954,7 +1061,7 @@ nsGenericHTMLElement::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
|
|||
nsDOMSlots *slots = GetDOMSlots();
|
||||
|
||||
if (nsnull == slots->mStyle) {
|
||||
slots->mStyle = new nsDOMStyleDeclaration(mContent);
|
||||
slots->mStyle = new nsDOMCSSAttributeDeclaration(mContent);
|
||||
if (nsnull == slots->mStyle) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -2909,7 +3016,7 @@ nsChildContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
|
|||
}
|
||||
|
||||
void
|
||||
nsChildContentList::DropContent()
|
||||
nsChildContentList::DropReference()
|
||||
{
|
||||
mContent = nsnull;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ class nsIStyleRule;
|
|||
class nsISupportsArray;
|
||||
class nsIDOMScriptObjectFactory;
|
||||
class nsChildContentList;
|
||||
class nsDOMStyleDeclaration;
|
||||
class nsDOMCSSDeclaration;
|
||||
|
||||
|
||||
// There are a set of DOM- and scripting-specific instance variables
|
||||
|
@ -59,7 +59,7 @@ class nsDOMStyleDeclaration;
|
|||
typedef struct {
|
||||
void *mScriptObject;
|
||||
nsChildContentList *mChildNodes;
|
||||
nsDOMStyleDeclaration *mStyle;
|
||||
nsDOMCSSDeclaration *mStyle;
|
||||
} nsDOMSlots;
|
||||
|
||||
class nsGenericHTMLElement : public nsIJSScriptObject {
|
||||
|
|
|
@ -48,6 +48,9 @@
|
|||
#include "nsIFormManager.h"
|
||||
#include "nsRepository.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "nsIDOMStyleSheet.h"
|
||||
#include "nsIDOMStyleSheetCollection.h"
|
||||
|
||||
|
||||
// Find/Serach Includes
|
||||
#include "nsISelection.h"
|
||||
|
@ -73,6 +76,239 @@ static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID);
|
|||
static NS_DEFINE_IID(kIDOMNSHTMLDocumentIID, NS_IDOMNSHTMLDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID);
|
||||
static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID);
|
||||
static NS_DEFINE_IID(kIDOMStyleSheetCollectionIID, NS_IDOMSTYLESHEETCOLLECTION_IID);
|
||||
static NS_DEFINE_IID(kIDOMStyleSheetIID, NS_IDOMSTYLESHEET_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIDocumentObserverIID, NS_IDOCUMENT_OBSERVER_IID);
|
||||
|
||||
class nsDOMStyleSheetCollection : public nsIDOMStyleSheetCollection,
|
||||
public nsIScriptObjectOwner,
|
||||
public nsIDocumentObserver
|
||||
{
|
||||
public:
|
||||
nsDOMStyleSheetCollection(nsIDocument *aDocument);
|
||||
~nsDOMStyleSheetCollection();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IDOMSTYLESHEETCOLLECTION
|
||||
|
||||
NS_IMETHOD BeginUpdate(nsIDocument *aDocument) { return NS_OK; }
|
||||
NS_IMETHOD EndUpdate(nsIDocument *aDocument) { return NS_OK; }
|
||||
NS_IMETHOD BeginLoad(nsIDocument *aDocument) { return NS_OK; }
|
||||
NS_IMETHOD EndLoad(nsIDocument *aDocument) { return NS_OK; }
|
||||
NS_IMETHOD BeginReflow(nsIDocument *aDocument,
|
||||
nsIPresShell* aShell) { return NS_OK; }
|
||||
NS_IMETHOD EndReflow(nsIDocument *aDocument,
|
||||
nsIPresShell* aShell) { return NS_OK; }
|
||||
NS_IMETHOD ContentChanged(nsIDocument *aDocument,
|
||||
nsIContent* aContent,
|
||||
nsISupports* aSubContent) { return NS_OK; }
|
||||
NS_IMETHOD AttributeChanged(nsIDocument *aDocument,
|
||||
nsIContent* aContent,
|
||||
nsIAtom* aAttribute,
|
||||
PRInt32 aHint) { return NS_OK; }
|
||||
NS_IMETHOD ContentAppended(nsIDocument *aDocument,
|
||||
nsIContent* aContainer,
|
||||
PRInt32 aNewIndexInContainer)
|
||||
{ return NS_OK; }
|
||||
NS_IMETHOD ContentInserted(nsIDocument *aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) { return NS_OK; }
|
||||
NS_IMETHOD ContentReplaced(nsIDocument *aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aOldChild,
|
||||
nsIContent* aNewChild,
|
||||
PRInt32 aIndexInContainer) { return NS_OK; }
|
||||
NS_IMETHOD ContentRemoved(nsIDocument *aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) { return NS_OK; }
|
||||
NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument,
|
||||
nsIStyleSheet* aStyleSheet);
|
||||
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
protected:
|
||||
PRInt32 mLength;
|
||||
nsIDocument* mDocument;
|
||||
void* mScriptObject;
|
||||
};
|
||||
|
||||
nsDOMStyleSheetCollection::nsDOMStyleSheetCollection(nsIDocument *aDocument)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mLength = -1;
|
||||
// Not reference counted to avoid circular references.
|
||||
// The document will tell us when its going away.
|
||||
mDocument = aDocument;
|
||||
mDocument->AddObserver(this);
|
||||
mScriptObject = nsnull;
|
||||
}
|
||||
|
||||
nsDOMStyleSheetCollection::~nsDOMStyleSheetCollection()
|
||||
{
|
||||
if (nsnull != mDocument) {
|
||||
mDocument->RemoveObserver(this);
|
||||
}
|
||||
mDocument = nsnull;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsDOMStyleSheetCollection)
|
||||
NS_IMPL_RELEASE(nsDOMStyleSheetCollection)
|
||||
|
||||
nsresult
|
||||
nsDOMStyleSheetCollection::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
||||
{
|
||||
if (NULL == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kIDOMStyleSheetCollectionIID)) {
|
||||
nsIDOMStyleSheetCollection *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
nsIScriptObjectOwner *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDocumentObserverIID)) {
|
||||
nsIDocumentObserver *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
nsIDOMStyleSheetCollection *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMStyleSheetCollection::GetLength(PRUint32* aLength)
|
||||
{
|
||||
if (nsnull != mDocument) {
|
||||
// XXX Find the number and then cache it. We'll use the
|
||||
// observer notification to figure out if new ones have
|
||||
// been added or removed.
|
||||
if (-1 == mLength) {
|
||||
PRUint32 count = 0;
|
||||
PRInt32 i, imax = mDocument->GetNumberOfStyleSheets();
|
||||
|
||||
for (i = 0; i < imax; i++) {
|
||||
nsIStyleSheet *sheet = mDocument->GetStyleSheetAt(i);
|
||||
nsIDOMStyleSheet *domss;
|
||||
|
||||
if (NS_OK == sheet->QueryInterface(kIDOMStyleSheetIID, (void **)&domss)) {
|
||||
count++;
|
||||
NS_RELEASE(domss);
|
||||
}
|
||||
|
||||
NS_RELEASE(sheet);
|
||||
}
|
||||
mLength = count;
|
||||
}
|
||||
*aLength = mLength;
|
||||
}
|
||||
else {
|
||||
*aLength = 0;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMStyleSheetCollection::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn)
|
||||
{
|
||||
*aReturn = nsnull;
|
||||
if (nsnull != mDocument) {
|
||||
PRUint32 count = 0;
|
||||
PRInt32 i, imax = mDocument->GetNumberOfStyleSheets();
|
||||
|
||||
// XXX Not particularly efficient, but does anyone care?
|
||||
for (i = 0; (i < imax) && (nsnull == *aReturn); i++) {
|
||||
nsIStyleSheet *sheet = mDocument->GetStyleSheetAt(i);
|
||||
nsIDOMStyleSheet *domss;
|
||||
|
||||
if (NS_OK == sheet->QueryInterface(kIDOMStyleSheetIID, (void **)&domss)) {
|
||||
if (count++ == aIndex) {
|
||||
*aReturn = domss;
|
||||
NS_ADDREF(domss);
|
||||
}
|
||||
NS_RELEASE(domss);
|
||||
}
|
||||
|
||||
NS_RELEASE(sheet);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMStyleSheetCollection::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
nsISupports *supports = (nsISupports *)(nsIDOMStyleSheetCollection *)this;
|
||||
nsISupports *parent = (nsISupports *)mDocument;
|
||||
|
||||
// XXX Should be done through factory
|
||||
res = NS_NewScriptStyleSheetCollection(aContext,
|
||||
supports,
|
||||
parent,
|
||||
(void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMStyleSheetCollection::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMStyleSheetCollection::StyleSheetAdded(nsIDocument *aDocument,
|
||||
nsIStyleSheet* aStyleSheet)
|
||||
{
|
||||
if (-1 != mLength) {
|
||||
nsIDOMStyleSheet *domss;
|
||||
if (NS_OK == aStyleSheet->QueryInterface(kIDOMStyleSheetIID, (void **)&domss)) {
|
||||
mLength++;
|
||||
NS_RELEASE(domss);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMStyleSheetCollection::DocumentWillBeDestroyed(nsIDocument *aDocument)
|
||||
{
|
||||
if (nsnull != mDocument) {
|
||||
aDocument->RemoveObserver(this);
|
||||
mDocument = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_LAYOUT nsresult
|
||||
NS_NewHTMLDocument(nsIDocument** aInstancePtrResult)
|
||||
|
@ -93,6 +329,7 @@ nsHTMLDocument::nsHTMLDocument()
|
|||
mAnchors = nsnull;
|
||||
mNamedItems = nsnull;
|
||||
mParser = nsnull;
|
||||
mDOMStyleSheets = nsnull;
|
||||
nsHTMLAtoms::AddrefAtoms();
|
||||
mDTDMode = eDTDMode_NoQuirks;
|
||||
|
||||
|
@ -124,6 +361,7 @@ nsHTMLDocument::~nsHTMLDocument()
|
|||
NS_IF_RELEASE(mEmbeds);
|
||||
NS_IF_RELEASE(mLinks);
|
||||
NS_IF_RELEASE(mAnchors);
|
||||
NS_IF_RELEASE(mDOMStyleSheets);
|
||||
NS_IF_RELEASE(mAttrStyleSheet);
|
||||
NS_IF_RELEASE(mStyleAttrStyleSheet);
|
||||
NS_IF_RELEASE(mParser);
|
||||
|
@ -830,6 +1068,23 @@ nsHTMLDocument::GetLastModified(nsString& aLastModified)
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets)
|
||||
{
|
||||
if (nsnull == mDOMStyleSheets) {
|
||||
mDOMStyleSheets = new nsDOMStyleSheetCollection(this);
|
||||
if (nsnull == mDOMStyleSheets) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(mDOMStyleSheets);
|
||||
}
|
||||
|
||||
*aStyleSheets = mDOMStyleSheets;
|
||||
NS_ADDREF(mDOMStyleSheets);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::GetEmbeds(nsIDOMHTMLCollection** aEmbeds)
|
||||
{
|
||||
|
|
|
@ -32,6 +32,7 @@ class nsContentList;
|
|||
class nsIContentViewerContainer;
|
||||
class nsIParser;
|
||||
class BlockText;
|
||||
class nsDOMStyleSheetCollection;
|
||||
|
||||
class nsHTMLDocument : public nsMarkupDocument, public nsIHTMLDocument, public nsIDOMHTMLDocument, public nsIDOMNSHTMLDocument {
|
||||
public:
|
||||
|
@ -161,6 +162,7 @@ protected:
|
|||
nsContentList *mLinks;
|
||||
nsContentList *mAnchors;
|
||||
nsContentList *mForms;
|
||||
nsDOMStyleSheetCollection *mDOMStyleSheets;
|
||||
|
||||
PLHashTable *mNamedItems;
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
NS_IMETHOD SetStyleSheet(nsIStyleSheet* aSheet) = 0;
|
||||
|
||||
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
|
||||
nsIURL* aInputURL,
|
||||
nsIURL* aInputURL,
|
||||
nsIStyleSheet*& aResult) = 0;
|
||||
|
||||
// Parse declarations assuming that the outer curly braces have
|
||||
|
@ -58,6 +58,7 @@ public:
|
|||
nsICSSDeclaration* aDeclaration,
|
||||
PRInt32* aHint) = 0;
|
||||
|
||||
NS_IMETHOD ProcessImport(const nsString& aURLSpec) = 0;
|
||||
};
|
||||
|
||||
// Values or'd in the GetInfoMask; other bits are reserved
|
||||
|
|
|
@ -197,7 +197,7 @@ public:
|
|||
NS_IMETHOD SetStyleSheet(nsIStyleSheet* aSheet);
|
||||
|
||||
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
|
||||
nsIURL* aInputURL,
|
||||
nsIURL* aInputURL,
|
||||
nsIStyleSheet*& aResult);
|
||||
|
||||
NS_IMETHOD ParseDeclarations(const nsString& aDeclaration,
|
||||
|
@ -209,6 +209,8 @@ public:
|
|||
nsICSSDeclaration* aDeclaration,
|
||||
PRInt32* aHint);
|
||||
|
||||
NS_IMETHOD ProcessImport(const nsString& aURLSpec);
|
||||
|
||||
protected:
|
||||
PRBool GetToken(PRInt32* aErrorCode, PRBool aSkipWS);
|
||||
void UngetToken();
|
||||
|
@ -281,8 +283,6 @@ protected:
|
|||
PRBool TranslateLength(nsICSSDeclaration* aDeclaration, const char* aName,
|
||||
float aNumber, const nsString& aDimension);
|
||||
|
||||
void ProcessImport(const nsString& aURLSpec);
|
||||
|
||||
// Current token. The value is valid after calling GetToken
|
||||
nsCSSToken mToken;
|
||||
|
||||
|
@ -364,7 +364,7 @@ CSSParserImpl::SetStyleSheet(nsIStyleSheet* aSheet)
|
|||
|
||||
NS_METHOD
|
||||
CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
|
||||
nsIURL* aInputURL,
|
||||
nsIURL* aInputURL,
|
||||
nsIStyleSheet*& aResult)
|
||||
{
|
||||
if (nsnull == mSheet) {
|
||||
|
@ -598,7 +598,7 @@ PRBool CSSParserImpl::ParseImportRule(PRInt32* aErrorCode)
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
void CSSParserImpl::ProcessImport(const nsString& aURLSpec)
|
||||
NS_IMETHODIMP CSSParserImpl::ProcessImport(const nsString& aURLSpec)
|
||||
{
|
||||
// XXX probably need a way to encode unicode junk for the part of
|
||||
// the url that follows a "?"
|
||||
|
@ -609,7 +609,7 @@ void CSSParserImpl::ProcessImport(const nsString& aURLSpec)
|
|||
if (NS_OK != rv) {
|
||||
// import url is bad
|
||||
// XXX log this somewhere for easier web page debugging
|
||||
return;
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (PR_FALSE == mSheet->ContainsStyleSheet(url)) { // don't allow circular references
|
||||
|
@ -656,6 +656,8 @@ void CSSParserImpl::ProcessImport(const nsString& aURLSpec)
|
|||
}
|
||||
}
|
||||
NS_RELEASE(url);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void CSSParserImpl::SkipUntil(PRInt32* aErrorCode, PRUnichar aStopSymbol)
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
#include "nsICSSStyleRule.h"
|
||||
#include "nsICSSDeclaration.h"
|
||||
#include "nsIStyleSheet.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
|
@ -29,12 +30,25 @@
|
|||
#include "nsUnitConversion.h"
|
||||
#include "nsStyleUtil.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
#include "nsIDOMCSSStyleSheet.h"
|
||||
#include "nsIDOMCSSStyleRule.h"
|
||||
#include "nsIDOMCSSStyleRuleSimple.h"
|
||||
#include "nsIDOMCSSStyleDeclaration.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsDOMCSSDeclaration.h"
|
||||
|
||||
//#define DEBUG_REFS
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
|
||||
static NS_DEFINE_IID(kICSSDeclarationIID, NS_ICSS_DECLARATION_IID);
|
||||
static NS_DEFINE_IID(kICSSStyleRuleIID, NS_ICSS_STYLE_RULE_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleSheetIID, NS_IDOMCSSSTYLESHEET_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleRuleIID, NS_IDOMCSSSTYLERULE_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleRuleSimpleIID, NS_IDOMCSSSTYLERULESIMPLE_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleDeclarationIID, NS_IDOMCSSSTYLEDECLARATION_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
|
||||
static NS_DEFINE_IID(kCSSFontSID, NS_CSS_FONT_SID);
|
||||
static NS_DEFINE_IID(kCSSColorSID, NS_CSS_COLOR_SID);
|
||||
|
@ -231,10 +245,79 @@ CSSImportantRule::List(FILE* out, PRInt32 aIndent) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// -- nsDOMStyleRuleDeclaration -------------------------------
|
||||
|
||||
class DOMCSSDeclarationImpl : public nsDOMCSSDeclaration
|
||||
{
|
||||
public:
|
||||
DOMCSSDeclarationImpl(nsICSSStyleRule *aRule);
|
||||
~DOMCSSDeclarationImpl();
|
||||
|
||||
virtual void DropReference();
|
||||
virtual nsresult GetCSSDeclaration(nsICSSDeclaration **aDecl,
|
||||
PRBool aAllocate);
|
||||
virtual nsresult StylePropertyChanged(const nsString& aPropertyName,
|
||||
PRInt32 aHint);
|
||||
virtual nsresult GetParent(nsISupports **aParent);
|
||||
|
||||
protected:
|
||||
nsICSSStyleRule *mRule;
|
||||
};
|
||||
|
||||
DOMCSSDeclarationImpl::DOMCSSDeclarationImpl(nsICSSStyleRule *aRule)
|
||||
{
|
||||
// This reference is not reference-counted. The rule
|
||||
// object tells us when its about to go away.
|
||||
mRule = aRule;
|
||||
}
|
||||
|
||||
DOMCSSDeclarationImpl::~DOMCSSDeclarationImpl()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
DOMCSSDeclarationImpl::DropReference()
|
||||
{
|
||||
mRule = nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DOMCSSDeclarationImpl::GetCSSDeclaration(nsICSSDeclaration **aDecl,
|
||||
PRBool aAllocate)
|
||||
{
|
||||
if (nsnull != mRule) {
|
||||
*aDecl = mRule->GetDeclaration();
|
||||
}
|
||||
else {
|
||||
*aDecl = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DOMCSSDeclarationImpl::StylePropertyChanged(const nsString& aPropertyName,
|
||||
PRInt32 aHint)
|
||||
{
|
||||
// XXX TBI
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DOMCSSDeclarationImpl::GetParent(nsISupports **aParent)
|
||||
{
|
||||
if (nsnull != mRule) {
|
||||
return mRule->QueryInterface(kISupportsIID, (void **)aParent);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// -- nsCSSStyleRule -------------------------------
|
||||
|
||||
class CSSStyleRuleImpl : public nsICSSStyleRule {
|
||||
class CSSStyleRuleImpl : public nsICSSStyleRule,
|
||||
public nsIDOMCSSStyleRuleSimple,
|
||||
public nsIScriptObjectOwner {
|
||||
public:
|
||||
void* operator new(size_t size);
|
||||
void* operator new(size_t size, nsIArena* aArena);
|
||||
|
@ -263,10 +346,25 @@ public:
|
|||
|
||||
virtual nsIStyleRule* GetImportantRule(void);
|
||||
|
||||
virtual nsIStyleSheet* GetStyleSheet(void);
|
||||
virtual void SetStyleSheet(nsIStyleSheet *aSheet);
|
||||
|
||||
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
||||
|
||||
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
// nsIDOMCSSStyleRule interface
|
||||
NS_IMETHOD GetType(nsString& aType);
|
||||
|
||||
// nsIDOMCSSStyleRuleSimple interface
|
||||
NS_IMETHOD GetSelectorText(nsString& aSelectorText);
|
||||
NS_IMETHOD SetSelectorText(const nsString& aSelectorText);
|
||||
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
private:
|
||||
// These are not supported and are not implemented!
|
||||
CSSStyleRuleImpl(const CSSStyleRuleImpl& aCopy);
|
||||
|
@ -283,6 +381,9 @@ protected:
|
|||
nsICSSDeclaration* mDeclaration;
|
||||
PRInt32 mWeight;
|
||||
CSSImportantRule* mImportantRule;
|
||||
nsIStyleSheet* mStyleSheet;
|
||||
DOMCSSDeclarationImpl *mDOMDeclaration;
|
||||
void* mScriptObject;
|
||||
#ifdef DEBUG_REFS
|
||||
PRInt32 mInstance;
|
||||
#endif
|
||||
|
@ -334,6 +435,8 @@ CSSStyleRuleImpl::CSSStyleRuleImpl(const nsCSSSelector& aSelector)
|
|||
mWeight(0), mImportantRule(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mDOMDeclaration = nsnull;
|
||||
mScriptObject = nsnull;
|
||||
#ifdef DEBUG_REFS
|
||||
mInstance = gInstanceCount++;
|
||||
fprintf(stdout, "%d of %d + CSSStyleRule\n", mInstance, gInstanceCount);
|
||||
|
@ -351,6 +454,9 @@ CSSStyleRuleImpl::~CSSStyleRuleImpl()
|
|||
}
|
||||
NS_IF_RELEASE(mDeclaration);
|
||||
NS_IF_RELEASE(mImportantRule);
|
||||
if (nsnull != mDOMDeclaration) {
|
||||
mDOMDeclaration->DropReference();
|
||||
}
|
||||
#ifdef DEBUG_REFS
|
||||
--gInstanceCount;
|
||||
fprintf(stdout, "%d of %d - CSSStyleRule\n", mInstance, gInstanceCount);
|
||||
|
@ -389,7 +495,6 @@ nsresult CSSStyleRuleImpl::QueryInterface(const nsIID& aIID,
|
|||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kICSSStyleRuleIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsICSSStyleRule*)this);
|
||||
NS_ADDREF_THIS();
|
||||
|
@ -400,8 +505,28 @@ nsresult CSSStyleRuleImpl::QueryInterface(const nsIID& aIID,
|
|||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMCSSStyleRuleIID)) {
|
||||
nsIDOMCSSStyleRule *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMCSSStyleRuleSimpleIID)) {
|
||||
nsIDOMCSSStyleRuleSimple *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
nsIScriptObjectOwner *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsISupports*)this);
|
||||
nsICSSStyleRule *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -543,6 +668,21 @@ nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
|
|||
return mImportantRule;
|
||||
}
|
||||
|
||||
nsIStyleSheet* CSSStyleRuleImpl::GetStyleSheet(void)
|
||||
{
|
||||
NS_IF_ADDREF(mStyleSheet);
|
||||
|
||||
return mStyleSheet;
|
||||
}
|
||||
|
||||
void CSSStyleRuleImpl::SetStyleSheet(nsIStyleSheet *aSheet)
|
||||
{
|
||||
// XXX We don't reference count this up reference. The style sheet
|
||||
// will tell us when it's going away or when we're detached from
|
||||
// it.
|
||||
mStyleSheet = aSheet;
|
||||
}
|
||||
|
||||
nscoord CalcLength(const nsCSSValue& aValue,
|
||||
const nsStyleFont* aFont,
|
||||
nsIPresContext* aPresContext)
|
||||
|
@ -1236,6 +1376,105 @@ CSSStyleRuleImpl::List(FILE* out, PRInt32 aIndent) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::GetType(nsString& aType)
|
||||
{
|
||||
// XXX Need to define the different types
|
||||
aType.SetString("simple");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::GetSelectorText(nsString& aSelectorText)
|
||||
{
|
||||
nsAutoString buffer;
|
||||
nsAutoString thisSelector;
|
||||
nsCSSSelector *selector = &mSelector;
|
||||
|
||||
// XXX Ugh...they're in reverse order from the source. Sorry
|
||||
// for the ugliness.
|
||||
aSelectorText.SetLength(0);
|
||||
while (nsnull != selector) {
|
||||
thisSelector.SetLength(0);
|
||||
if (nsnull != selector->mTag) {
|
||||
selector->mTag->ToString(buffer);
|
||||
thisSelector.Append(buffer);
|
||||
}
|
||||
if (nsnull != selector->mID) {
|
||||
selector->mID->ToString(buffer);
|
||||
thisSelector.Append("#");
|
||||
thisSelector.Append(buffer);
|
||||
}
|
||||
if (nsnull != selector->mClass) {
|
||||
selector->mClass->ToString(buffer);
|
||||
thisSelector.Append(".");
|
||||
thisSelector.Append(buffer);
|
||||
}
|
||||
if (nsnull != selector->mPseudoClass) {
|
||||
selector->mPseudoClass->ToString(buffer);
|
||||
thisSelector.Append(":");
|
||||
thisSelector.Append(buffer);
|
||||
}
|
||||
aSelectorText.Insert(thisSelector, 0, thisSelector.Length());
|
||||
selector = selector->mNext;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::SetSelectorText(const nsString& aSelectorText)
|
||||
{
|
||||
// XXX TBI
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
|
||||
{
|
||||
if (nsnull == mDOMDeclaration) {
|
||||
mDOMDeclaration = new DOMCSSDeclarationImpl(this);
|
||||
if (nsnull == mDOMDeclaration) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(mDOMDeclaration);
|
||||
}
|
||||
|
||||
*aStyle = mDOMDeclaration;
|
||||
NS_ADDREF(mDOMDeclaration);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
nsISupports *supports = (nsISupports *)(nsICSSStyleRule *)this;
|
||||
// XXX Parent should be the style sheet
|
||||
// XXX Should be done through factory
|
||||
res = NS_NewScriptCSSStyleRuleSimple(aContext,
|
||||
supports,
|
||||
(nsISupports *)global,
|
||||
(void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
NS_RELEASE(global);
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_HTML nsresult
|
||||
NS_NewCSSStyleRule(nsICSSStyleRule** aInstancePtrResult, const nsCSSSelector& aSelector)
|
||||
{
|
||||
|
|
|
@ -32,6 +32,13 @@
|
|||
#include "nsString.h"
|
||||
#include "nsIPtr.h"
|
||||
#include "nsHTMLIIDs.h"
|
||||
#include "nsIDOMStyleSheetCollection.h"
|
||||
#include "nsIDOMCSSStyleSheet.h"
|
||||
#include "nsIDOMCSSStyleRule.h"
|
||||
#include "nsIDOMCSSStyleRuleCollection.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsICSSParser.h"
|
||||
|
||||
//#define DEBUG_REFS
|
||||
//#define DEBUG_RULES
|
||||
|
@ -39,6 +46,12 @@
|
|||
static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID);
|
||||
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
|
||||
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
|
||||
static NS_DEFINE_IID(kIDOMStyleSheetIID, NS_IDOMSTYLESHEET_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleSheetIID, NS_IDOMCSSSTYLESHEET_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleRuleIID, NS_IDOMCSSSTYLERULE_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleRuleCollectionIID, NS_IDOMCSSSTYLERULECOLLECTION_IID);
|
||||
static NS_DEFINE_IID(kIDOMStyleSheetCollectionIID, NS_IDOMSTYLESHEETCOLLECTION_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
|
||||
NS_DEF_PTR(nsIHTMLContent);
|
||||
NS_DEF_PTR(nsIContent);
|
||||
|
@ -129,6 +142,7 @@ public:
|
|||
RuleEnumFunc aFunc, void* aData);
|
||||
void EnumerateTagRules(nsIAtom* aTag,
|
||||
RuleEnumFunc aFunc, void* aData);
|
||||
|
||||
protected:
|
||||
void AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyleRule* aRule);
|
||||
|
||||
|
@ -171,6 +185,7 @@ void RuleHash::AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyl
|
|||
value = value->mNext;
|
||||
}
|
||||
value->mNext = new RuleValue(aRule, mRuleCount++);
|
||||
value = value->mNext;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,11 +257,279 @@ void RuleHash::EnumerateTagRules(nsIAtom* aTag, RuleEnumFunc aFunc, void* aData)
|
|||
}
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
// Style Rule Collection for the DOM
|
||||
//
|
||||
class CSSStyleRuleCollectionImpl : public nsIDOMCSSStyleRuleCollection,
|
||||
public nsIScriptObjectOwner
|
||||
{
|
||||
public:
|
||||
CSSStyleRuleCollectionImpl(nsICSSStyleSheet *aStyleSheet);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMCSSStyleRuleCollection interface
|
||||
NS_IMETHOD GetLength(PRUint32* aLength);
|
||||
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMCSSStyleRule** aReturn);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
void DropReference() { mStyleSheet = nsnull; }
|
||||
|
||||
protected:
|
||||
virtual ~CSSStyleRuleCollectionImpl();
|
||||
|
||||
nsICSSStyleSheet* mStyleSheet;
|
||||
void* mScriptObject;
|
||||
};
|
||||
|
||||
CSSStyleRuleCollectionImpl::CSSStyleRuleCollectionImpl(nsICSSStyleSheet *aStyleSheet)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
// Not reference counted to avoid circular references.
|
||||
// The style sheet will tell us when its going away.
|
||||
mStyleSheet = aStyleSheet;
|
||||
mScriptObject = nsnull;
|
||||
}
|
||||
|
||||
CSSStyleRuleCollectionImpl::~CSSStyleRuleCollectionImpl()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(CSSStyleRuleCollectionImpl);
|
||||
NS_IMPL_RELEASE(CSSStyleRuleCollectionImpl);
|
||||
|
||||
nsresult
|
||||
CSSStyleRuleCollectionImpl::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
||||
{
|
||||
if (NULL == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kIDOMCSSStyleRuleCollectionIID)) {
|
||||
nsIDOMCSSStyleRuleCollection *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
nsIScriptObjectOwner *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
nsIDOMCSSStyleRuleCollection *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleCollectionImpl::GetLength(PRUint32* aLength)
|
||||
{
|
||||
if (nsnull != mStyleSheet) {
|
||||
*aLength = mStyleSheet->StyleRuleCount();
|
||||
}
|
||||
else {
|
||||
*aLength = 0;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleCollectionImpl::Item(PRUint32 aIndex, nsIDOMCSSStyleRule** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
*aReturn = nsnull;
|
||||
if (nsnull != mStyleSheet) {
|
||||
nsICSSStyleRule *rule;
|
||||
|
||||
result = mStyleSheet->GetStyleRuleAt(aIndex, rule);
|
||||
if (NS_OK == result) {
|
||||
result = rule->QueryInterface(kIDOMCSSStyleRuleIID, (void **)aReturn);
|
||||
}
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleCollectionImpl::GetScriptObject(nsIScriptContext *aContext,
|
||||
void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
nsISupports *supports = (nsISupports *)(nsIDOMCSSStyleRuleCollection *)this;
|
||||
|
||||
// XXX Should be done through factory
|
||||
res = NS_NewScriptCSSStyleRuleCollection(aContext,
|
||||
supports,
|
||||
(nsISupports *)mStyleSheet,
|
||||
(void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleCollectionImpl::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
// Imports Collection for the DOM
|
||||
//
|
||||
class CSSImportsCollectionImpl : public nsIDOMStyleSheetCollection,
|
||||
public nsIScriptObjectOwner
|
||||
{
|
||||
public:
|
||||
CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMCSSStyleSheetCollection interface
|
||||
NS_IMETHOD GetLength(PRUint32* aLength);
|
||||
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
void DropReference() { mStyleSheet = nsnull; }
|
||||
|
||||
protected:
|
||||
virtual ~CSSImportsCollectionImpl();
|
||||
|
||||
nsICSSStyleSheet* mStyleSheet;
|
||||
void* mScriptObject;
|
||||
};
|
||||
|
||||
CSSImportsCollectionImpl::CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
// Not reference counted to avoid circular references.
|
||||
// The style sheet will tell us when its going away.
|
||||
mStyleSheet = aStyleSheet;
|
||||
mScriptObject = nsnull;
|
||||
}
|
||||
|
||||
CSSImportsCollectionImpl::~CSSImportsCollectionImpl()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(CSSImportsCollectionImpl);
|
||||
NS_IMPL_RELEASE(CSSImportsCollectionImpl);
|
||||
|
||||
nsresult
|
||||
CSSImportsCollectionImpl::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
||||
{
|
||||
if (NULL == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kIDOMStyleSheetCollectionIID)) {
|
||||
nsIDOMStyleSheetCollection *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
nsIScriptObjectOwner *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
nsIDOMStyleSheetCollection *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSImportsCollectionImpl::GetLength(PRUint32* aLength)
|
||||
{
|
||||
if (nsnull != mStyleSheet) {
|
||||
*aLength = mStyleSheet->StyleSheetCount();
|
||||
}
|
||||
else {
|
||||
*aLength = 0;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSImportsCollectionImpl::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
*aReturn = nsnull;
|
||||
if (nsnull != mStyleSheet) {
|
||||
nsICSSStyleSheet *sheet;
|
||||
|
||||
result = mStyleSheet->GetStyleSheetAt(aIndex, sheet);
|
||||
if (NS_OK == result) {
|
||||
result = sheet->QueryInterface(kIDOMStyleSheetIID, (void **)aReturn);
|
||||
}
|
||||
NS_RELEASE(sheet);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSImportsCollectionImpl::GetScriptObject(nsIScriptContext *aContext,
|
||||
void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
nsISupports *supports = (nsISupports *)(nsIDOMStyleSheetCollection *)this;
|
||||
|
||||
// XXX Should be done through factory
|
||||
res = NS_NewScriptStyleSheetCollection(aContext,
|
||||
supports,
|
||||
(nsISupports *)mStyleSheet,
|
||||
(void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSImportsCollectionImpl::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
// CSS Style Sheet
|
||||
//
|
||||
class CSSStyleSheetImpl : public nsICSSStyleSheet {
|
||||
class CSSStyleSheetImpl : public nsICSSStyleSheet,
|
||||
public nsIDOMCSSStyleSheet,
|
||||
public nsIScriptObjectOwner {
|
||||
public:
|
||||
void* operator new(size_t size);
|
||||
void* operator new(size_t size, nsIArena* aArena);
|
||||
|
@ -281,8 +564,32 @@ public:
|
|||
virtual PRInt32 StyleRuleCount(void);
|
||||
virtual nsresult GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule);
|
||||
|
||||
virtual PRInt32 StyleSheetCount();
|
||||
virtual nsresult GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet);
|
||||
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
// nsIDOMStyleSheet interface
|
||||
NS_IMETHOD GetDisabled(PRBool* aDisabled);
|
||||
NS_IMETHOD SetDisabled(PRBool aDisabled);
|
||||
NS_IMETHOD GetReadOnly(PRBool* aReadOnly);
|
||||
|
||||
// nsIDOMCSSStyleSheet interface
|
||||
NS_IMETHOD GetOwningElement(nsIDOMHTMLElement** aOwningElement);
|
||||
NS_IMETHOD GetParentStyleSheet(nsIDOMCSSStyleSheet** aParentStyleSheet);
|
||||
NS_IMETHOD GetHref(nsString& aHref);
|
||||
NS_IMETHOD GetTitle(nsString& aTitle);
|
||||
NS_IMETHOD GetImports(nsIDOMStyleSheetCollection** aImports);
|
||||
NS_IMETHOD GetRules(nsIDOMCSSStyleRuleCollection** aRules);
|
||||
NS_IMETHOD AddRule(const nsString& aSelector, const nsString& aDeclaration, PRUint32 aIndex, PRUint32* aReturn);
|
||||
NS_IMETHOD AddImport(const nsString& aUrl, PRUint32 aIndex, PRUint32* aReturn);
|
||||
NS_IMETHOD RemoveRule(PRUint32 aIndex);
|
||||
NS_IMETHOD RemoveImport(PRUint32 aIndex);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
private:
|
||||
// These are not supported and are not implemented!
|
||||
CSSStyleSheetImpl(const CSSStyleSheetImpl& aCopy);
|
||||
|
@ -303,7 +610,11 @@ protected:
|
|||
nsISupportsArrayPtr mOrderedRules;
|
||||
nsISupportsArrayPtr mWeightedRules;
|
||||
nsICSSStyleSheetPtr mNext;
|
||||
nsICSSStyleSheet* mParent;
|
||||
RuleHash* mRuleHash;
|
||||
CSSStyleRuleCollectionImpl* mRuleCollection;
|
||||
CSSImportsCollectionImpl* mImportsCollection;
|
||||
void * mScriptObject;
|
||||
};
|
||||
|
||||
|
||||
|
@ -354,18 +665,49 @@ CSSStyleSheetImpl::CSSStyleSheetImpl(nsIURL* aURL)
|
|||
{
|
||||
NS_INIT_REFCNT();
|
||||
mURL.SetAddRef(aURL);
|
||||
mParent = nsnull;
|
||||
mRuleCollection = nsnull;
|
||||
mImportsCollection = nsnull;
|
||||
mScriptObject = nsnull;
|
||||
#ifdef DEBUG_REFS
|
||||
++gInstanceCount;
|
||||
fprintf(stdout, "%d + CSSStyleSheet size: %d\n", gInstanceCount, sizeof(*this));
|
||||
#endif
|
||||
}
|
||||
|
||||
static PRBool DropStyleSheetReference(nsISupports* aElement, void *aData)
|
||||
{
|
||||
nsICSSStyleRule *rule = (nsICSSStyleRule *)aElement;
|
||||
|
||||
if (nsnull != rule) {
|
||||
rule->SetStyleSheet(nsnull);
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
CSSStyleSheetImpl::~CSSStyleSheetImpl()
|
||||
{
|
||||
#ifdef DEBUG_REFS
|
||||
--gInstanceCount;
|
||||
fprintf(stdout, "%d - CSSStyleSheet\n", gInstanceCount);
|
||||
#endif
|
||||
if (mFirstChild.IsNotNull()) {
|
||||
nsICSSStyleSheet* child = mFirstChild;
|
||||
while (nsnull != child) {
|
||||
((CSSStyleSheetImpl *)child)->mParent = nsnull;
|
||||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
}
|
||||
}
|
||||
if (nsnull != mRuleCollection) {
|
||||
mRuleCollection->DropReference();
|
||||
NS_RELEASE(mRuleCollection);
|
||||
}
|
||||
if (nsnull != mImportsCollection) {
|
||||
mImportsCollection->DropReference();
|
||||
NS_RELEASE(mImportsCollection);
|
||||
}
|
||||
mOrderedRules->EnumerateForwards(DropStyleSheetReference, nsnull);
|
||||
ClearHash();
|
||||
}
|
||||
|
||||
|
@ -390,8 +732,28 @@ nsresult CSSStyleSheetImpl::QueryInterface(const nsIID& aIID,
|
|||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMStyleSheetIID)) {
|
||||
nsIDOMStyleSheet *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMCSSStyleSheetIID)) {
|
||||
nsIDOMCSSStyleSheet *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
nsIScriptObjectOwner *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsISupports*)this);
|
||||
nsICSSStyleSheet *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -750,6 +1112,10 @@ void CSSStyleSheetImpl::AppendStyleSheet(nsICSSStyleSheet* aSheet)
|
|||
}
|
||||
((CSSStyleSheetImpl*)child)->mNext.SetAddRef(aSheet);
|
||||
}
|
||||
|
||||
// This is not reference counted. Our parent tells us when
|
||||
// it's going away.
|
||||
((CSSStyleSheetImpl*)aSheet)->mParent = this;
|
||||
}
|
||||
|
||||
void CSSStyleSheetImpl::PrependStyleRule(nsICSSStyleRule* aRule)
|
||||
|
@ -778,6 +1144,7 @@ void CSSStyleSheetImpl::PrependStyleRule(nsICSSStyleRule* aRule)
|
|||
}
|
||||
mWeightedRules->InsertElementAt(aRule, index + 1);
|
||||
mOrderedRules->InsertElementAt(aRule, 0);
|
||||
aRule->SetStyleSheet(this);
|
||||
}
|
||||
|
||||
void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
|
||||
|
@ -807,6 +1174,7 @@ void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
|
|||
}
|
||||
mWeightedRules->InsertElementAt(aRule, index);
|
||||
mOrderedRules->AppendElement(aRule);
|
||||
aRule->SetStyleSheet(this);
|
||||
}
|
||||
|
||||
PRInt32 CSSStyleSheetImpl::StyleRuleCount(void)
|
||||
|
@ -833,6 +1201,43 @@ nsresult CSSStyleSheetImpl::GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRu
|
|||
return result;
|
||||
}
|
||||
|
||||
PRInt32 CSSStyleSheetImpl::StyleSheetCount()
|
||||
{
|
||||
// XXX Far from an ideal way to do this, but the hope is that
|
||||
// it won't be done too often. If it is, we might want to
|
||||
// consider storing the children in an array.
|
||||
PRInt32 count = 0;
|
||||
if (mFirstChild.IsNotNull()) {
|
||||
nsICSSStyleSheet* child = mFirstChild;
|
||||
while (nsnull != child) {
|
||||
count++;
|
||||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
nsresult CSSStyleSheetImpl::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet)
|
||||
{
|
||||
// XXX Ughh...an O(n^2) method for doing iteration. Again, we hope
|
||||
// that this isn't done too often. If it is, we need to change the
|
||||
// underlying storage mechanism
|
||||
aSheet = nsnull;
|
||||
if (mFirstChild.IsNotNull()) {
|
||||
nsICSSStyleSheet* child = mFirstChild;
|
||||
while ((nsnull != child) && (0 != aIndex)) {
|
||||
--aIndex;
|
||||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
}
|
||||
|
||||
aSheet = child;
|
||||
NS_IF_ADDREF(child);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void CSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
nsAutoString buffer;
|
||||
|
@ -886,6 +1291,224 @@ void CSSStyleSheetImpl::BuildHash(void)
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetDisabled(PRBool* aDisabled)
|
||||
{
|
||||
// XXX TBI
|
||||
*aDisabled = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::SetDisabled(PRBool aDisabled)
|
||||
{
|
||||
// XXX TBI
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetReadOnly(PRBool* aReadOnly)
|
||||
{
|
||||
// XXX TBI
|
||||
*aReadOnly = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetOwningElement(nsIDOMHTMLElement** aOwningElement)
|
||||
{
|
||||
// XXX TBI
|
||||
*aOwningElement = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aParentStyleSheet)
|
||||
{
|
||||
if (nsnull != mParent) {
|
||||
return mParent->QueryInterface(kIDOMCSSStyleSheetIID, (void **)aParentStyleSheet);
|
||||
}
|
||||
else {
|
||||
*aParentStyleSheet = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetHref(nsString& aHref)
|
||||
{
|
||||
if (mURL.IsNotNull()) {
|
||||
mURL->ToString(aHref);
|
||||
}
|
||||
else {
|
||||
aHref.SetLength(0);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetTitle(nsString& aTitle)
|
||||
{
|
||||
// XX TBI
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetImports(nsIDOMStyleSheetCollection** aImports)
|
||||
{
|
||||
if (nsnull == mImportsCollection) {
|
||||
mImportsCollection = new CSSImportsCollectionImpl(this);
|
||||
if (nsnull == mImportsCollection) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(mImportsCollection);
|
||||
}
|
||||
|
||||
*aImports = mImportsCollection;
|
||||
NS_ADDREF(mImportsCollection);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetRules(nsIDOMCSSStyleRuleCollection** aRules)
|
||||
{
|
||||
if (nsnull == mRuleCollection) {
|
||||
mRuleCollection = new CSSStyleRuleCollectionImpl(this);
|
||||
if (nsnull == mRuleCollection) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(mRuleCollection);
|
||||
}
|
||||
|
||||
*aRules = mRuleCollection;
|
||||
NS_ADDREF(mRuleCollection);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::AddRule(const nsString& aSelector,
|
||||
const nsString& aDeclaration,
|
||||
PRUint32 aIndex,
|
||||
PRUint32* aReturn)
|
||||
{
|
||||
nsICSSParser* css;
|
||||
nsresult result = NS_NewCSSParser(&css);
|
||||
if (NS_OK == result) {
|
||||
nsAutoString str;
|
||||
str.SetString(aSelector);
|
||||
// XXX Can we assume that the braces aren't there?
|
||||
str.Append(" { ");
|
||||
str.Append(aDeclaration);
|
||||
str.Append(" } ");
|
||||
|
||||
nsIUnicharInputStream* input = nsnull;
|
||||
result = NS_NewStringUnicharInputStream(&input, &str);
|
||||
if (NS_OK == result) {
|
||||
nsIStyleSheet *tmp;
|
||||
css->SetStyleSheet(this);
|
||||
// XXX Currently, the parser will append the rule to the
|
||||
// style sheet. We shouldn't ignore the index.
|
||||
result = css->Parse(input, mURL, tmp);
|
||||
NS_ASSERTION(tmp = this, "parser incorrectly created a new stylesheet");
|
||||
NS_RELEASE(input);
|
||||
*aReturn = mOrderedRules->Count();
|
||||
}
|
||||
|
||||
NS_RELEASE(css);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::AddImport(const nsString& aUrl, PRUint32 aIndex, PRUint32* aReturn)
|
||||
{
|
||||
nsICSSParser* css;
|
||||
nsresult result = NS_NewCSSParser(&css);
|
||||
if (NS_OK == result) {
|
||||
css->SetStyleSheet(this);
|
||||
result = css->ProcessImport(aUrl);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::RemoveRule(PRUint32 aIndex)
|
||||
{
|
||||
nsICSSStyleRule *rule;
|
||||
|
||||
rule = (nsICSSStyleRule *)mOrderedRules->ElementAt(aIndex);
|
||||
if (nsnull != rule) {
|
||||
mOrderedRules->RemoveElementAt(aIndex);
|
||||
mWeightedRules->RemoveElement(rule);
|
||||
rule->SetStyleSheet(nsnull);
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::RemoveImport(PRUint32 aIndex)
|
||||
{
|
||||
if (mFirstChild.IsNotNull()) {
|
||||
nsICSSStyleSheet* prev = nsnull;
|
||||
nsICSSStyleSheet* child = mFirstChild;
|
||||
while ((nsnull != child) && (0 != aIndex)) {
|
||||
prev = child;
|
||||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
--aIndex;
|
||||
}
|
||||
|
||||
if ((nsnull != child) && (0 == aIndex)) {
|
||||
// Hold on to the child while we clean it up
|
||||
NS_ADDREF(child);
|
||||
if (nsnull == prev) {
|
||||
mFirstChild.SetAddRef(((CSSStyleSheetImpl*)child)->mNext);
|
||||
}
|
||||
else {
|
||||
((CSSStyleSheetImpl*)prev)->mNext.SetAddRef(((CSSStyleSheetImpl*)child)->mNext);
|
||||
}
|
||||
((CSSStyleSheetImpl*)child)->mNext.SetAddRef(nsnull);
|
||||
((CSSStyleSheetImpl*)child)->mParent = nsnull;
|
||||
NS_RELEASE(child);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
nsISupports *supports = (nsISupports *)(nsICSSStyleSheet *)this;
|
||||
// XXX Should be done through factory
|
||||
res = NS_NewScriptCSSStyleSheet(aContext,
|
||||
supports,
|
||||
(nsISupports *)global,
|
||||
(void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
NS_RELEASE(global);
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_HTML nsresult
|
||||
NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult, nsIURL* aURL)
|
||||
{
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,55 @@
|
|||
/* -*- 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 "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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
#ifndef nsDOMCSSDeclaration_h___
|
||||
#define nsDOMCSSSDeclaration_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIDOMCSSStyleDeclaration.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
|
||||
class nsICSSDeclaration;
|
||||
|
||||
class nsDOMCSSDeclaration : public nsIDOMCSSStyleDeclaration,
|
||||
public nsIScriptObjectOwner
|
||||
{
|
||||
public:
|
||||
nsDOMCSSDeclaration();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_IDOMCSSSTYLEDECLARATION
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
virtual void DropReference() = 0;
|
||||
virtual nsresult GetCSSDeclaration(nsICSSDeclaration **aDecl,
|
||||
PRBool aAllocate) = 0;
|
||||
virtual nsresult StylePropertyChanged(const nsString& aPropertyName,
|
||||
PRInt32 aHint) = 0;
|
||||
virtual nsresult GetParent(nsISupports **aParent) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~nsDOMCSSDeclaration();
|
||||
|
||||
void *mScriptObject;
|
||||
};
|
||||
|
||||
#endif // nsDOMCSSDeclaration_h___
|
|
@ -25,7 +25,7 @@ class nsIAtom;
|
|||
class nsIArena;
|
||||
class nsString;
|
||||
class nsICSSDeclaration;
|
||||
|
||||
class nsIStyleSheet;
|
||||
|
||||
struct nsCSSSelector {
|
||||
public:
|
||||
|
@ -65,6 +65,9 @@ public:
|
|||
virtual void SetWeight(PRInt32 aWeight) = 0;
|
||||
|
||||
virtual nsIStyleRule* GetImportantRule(void) = 0;
|
||||
|
||||
virtual nsIStyleSheet* GetStyleSheet(void) = 0;
|
||||
virtual void SetStyleSheet(nsIStyleSheet *aSheet) = 0;
|
||||
};
|
||||
|
||||
extern NS_HTML nsresult
|
||||
|
|
|
@ -38,7 +38,6 @@ public:
|
|||
NS_IMETHOD SetSelectorText(const nsString& aSelectorText)=0;
|
||||
|
||||
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle)=0;
|
||||
NS_IMETHOD SetStyle(nsIDOMCSSStyleDeclaration* aStyle)=0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -46,7 +45,6 @@ public:
|
|||
NS_IMETHOD GetSelectorText(nsString& aSelectorText); \
|
||||
NS_IMETHOD SetSelectorText(const nsString& aSelectorText); \
|
||||
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle); \
|
||||
NS_IMETHOD SetStyle(nsIDOMCSSStyleDeclaration* aStyle); \
|
||||
|
||||
|
||||
|
||||
|
@ -54,7 +52,6 @@ public:
|
|||
NS_IMETHOD GetSelectorText(nsString& aSelectorText) { return _to##GetSelectorText(aSelectorText); } \
|
||||
NS_IMETHOD SetSelectorText(const nsString& aSelectorText) { return _to##SetSelectorText(aSelectorText); } \
|
||||
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle) { return _to##GetStyle(aStyle); } \
|
||||
NS_IMETHOD SetStyle(nsIDOMCSSStyleDeclaration* aStyle) { return _to##SetStyle(aStyle); } \
|
||||
|
||||
|
||||
extern nsresult NS_InitCSSStyleRuleSimpleClass(nsIScriptContext *aContext, void **aPrototype);
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "nsIScriptContext.h"
|
||||
|
||||
class nsIDOMElement;
|
||||
class nsIDOMStyleSheetCollection;
|
||||
class nsIDOMHTMLCollection;
|
||||
|
||||
#define NS_IDOMNSHTMLDOCUMENT_IID \
|
||||
|
@ -49,6 +50,8 @@ public:
|
|||
NS_IMETHOD GetFgColor(nsString& aFgColor)=0;
|
||||
NS_IMETHOD SetFgColor(const nsString& aFgColor)=0;
|
||||
|
||||
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets)=0;
|
||||
|
||||
NS_IMETHOD GetLastModified(nsString& aLastModified)=0;
|
||||
|
||||
NS_IMETHOD GetEmbeds(nsIDOMHTMLCollection** aEmbeds)=0;
|
||||
|
@ -74,6 +77,7 @@ public:
|
|||
NS_IMETHOD SetBgColor(const nsString& aBgColor); \
|
||||
NS_IMETHOD GetFgColor(nsString& aFgColor); \
|
||||
NS_IMETHOD SetFgColor(const nsString& aFgColor); \
|
||||
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets); \
|
||||
NS_IMETHOD GetLastModified(nsString& aLastModified); \
|
||||
NS_IMETHOD GetEmbeds(nsIDOMHTMLCollection** aEmbeds); \
|
||||
NS_IMETHOD GetLayers(nsIDOMHTMLCollection** aLayers); \
|
||||
|
@ -94,6 +98,7 @@ public:
|
|||
NS_IMETHOD SetBgColor(const nsString& aBgColor) { return _to##SetBgColor(aBgColor); } \
|
||||
NS_IMETHOD GetFgColor(nsString& aFgColor) { return _to##GetFgColor(aFgColor); } \
|
||||
NS_IMETHOD SetFgColor(const nsString& aFgColor) { return _to##SetFgColor(aFgColor); } \
|
||||
NS_IMETHOD GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets) { return _to##GetStyleSheets(aStyleSheets); } \
|
||||
NS_IMETHOD GetLastModified(nsString& aLastModified) { return _to##GetLastModified(aLastModified); } \
|
||||
NS_IMETHOD GetEmbeds(nsIDOMHTMLCollection** aEmbeds) { return _to##GetEmbeds(aEmbeds); } \
|
||||
NS_IMETHOD GetLayers(nsIDOMHTMLCollection** aLayers) { return _to##GetLayers(aLayers); } \
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
interface CSSStyleRuleSimple : CSSStyleRule {
|
||||
attribute wstring selectorText;
|
||||
attribute CSSStyleDeclaration style;
|
||||
readonly attribute CSSStyleDeclaration style;
|
||||
};
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
attribute wstring vlinkColor;
|
||||
attribute wstring bgColor;
|
||||
attribute wstring fgColor;
|
||||
readonly attribute StyleSheetCollection styleSheets;
|
||||
readonly attribute wstring lastModified;
|
||||
|
||||
readonly attribute HTMLCollection embeds;
|
||||
|
|
|
@ -25,6 +25,7 @@
|
|||
#include "nsIDOMHTMLFormElement.h"
|
||||
#include "nsIDOMHTMLInputElement.h"
|
||||
#include "nsIScriptEventListener.h"
|
||||
#include "nsIDOMCSSStyleSheet.h"
|
||||
#include "jsurl.h"
|
||||
|
||||
// Force references to all of the symbols that we want exported from
|
||||
|
@ -42,5 +43,6 @@ void XXXDomNeverCalled()
|
|||
NS_NewScriptHTMLImageElement(0, 0, 0, 0);
|
||||
NS_NewScriptHTMLFormElement(0, 0, 0, 0);
|
||||
NS_NewScriptHTMLInputElement(0, 0, 0, 0);
|
||||
NS_NewScriptCSSStyleSheet(0, 0, 0, 0);
|
||||
NET_InitJavaScriptProtocol();
|
||||
}
|
||||
|
|
|
@ -105,7 +105,11 @@
|
|||
#include "nsIDOMNSHTMLFormElement.h"
|
||||
#include "nsIDOMNavigator.h"
|
||||
#include "nsIDOMLocation.h"
|
||||
#include "nsIDOMStyleSheetCollection.h"
|
||||
#include "nsIDOMCSSStyleDeclaration.h"
|
||||
#include "nsIDOMCSSStyleSheet.h"
|
||||
#include "nsIDOMCSSStyleRuleSimple.h"
|
||||
#include "nsIDOMCSSStyleRuleCollection.h"
|
||||
#include "plhash.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDOMNativeObjectRegistry, NS_IDOM_NATIVE_OBJECT_REGISTRY_IID);
|
||||
|
@ -673,5 +677,9 @@ void XXXDomNeverCalled()
|
|||
NS_NewScriptLocation(0, 0, 0, 0);
|
||||
NS_NewScriptEventListener(0, 0, 0);
|
||||
NS_NewScriptCSSStyleDeclaration(0, 0, 0, 0);
|
||||
NS_NewScriptCSSStyleSheet(0, 0, 0, 0);
|
||||
NS_NewScriptCSSStyleRuleSimple(0, 0, 0, 0);
|
||||
NS_NewScriptStyleSheetCollection(0, 0, 0, 0);
|
||||
NS_NewScriptCSSStyleRuleCollection(0, 0, 0, 0);
|
||||
NET_InitJavaScriptProtocol();
|
||||
}
|
||||
|
|
|
@ -1,417 +0,0 @@
|
|||
/* -*- 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.
|
||||
*/
|
||||
/* AUTO-GENERATED. DO NOT EDIT!!! */
|
||||
|
||||
#include "jsapi.h"
|
||||
#include "nscore.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIJSScriptObject.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIDOMCSSStyleDeclaration.h"
|
||||
#include "nsIDOMCSSStyleRuleSimple.h"
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
|
||||
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
|
||||
static NS_DEFINE_IID(kICSSStyleDeclarationIID, NS_IDOMCSSSTYLEDECLARATION_IID);
|
||||
static NS_DEFINE_IID(kICSSStyleRuleSimpleIID, NS_IDOMCSSSTYLERULESIMPLE_IID);
|
||||
|
||||
NS_DEF_PTR(nsIDOMCSSStyleDeclaration);
|
||||
NS_DEF_PTR(nsIDOMCSSStyleRuleSimple);
|
||||
|
||||
//
|
||||
// CSSStyleRuleSimple property ids
|
||||
//
|
||||
enum CSSStyleRuleSimple_slots {
|
||||
CSSSTYLERULESIMPLE_SELECTORTEXT = -1,
|
||||
CSSSTYLERULESIMPLE_STYLE = -2
|
||||
};
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// CSSStyleRuleSimple Properties Getter
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
GetCSSStyleRuleSimpleProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIDOMCSSStyleRuleSimple *a = (nsIDOMCSSStyleRuleSimple*)JS_GetPrivate(cx, obj);
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == a) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case CSSSTYLERULESIMPLE_SELECTORTEXT:
|
||||
{
|
||||
nsAutoString prop;
|
||||
if (NS_OK == a->GetSelectorText(prop)) {
|
||||
JSString *jsstring = JS_NewUCStringCopyN(cx, prop, prop.Length());
|
||||
// set the return value
|
||||
*vp = STRING_TO_JSVAL(jsstring);
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CSSSTYLERULESIMPLE_STYLE:
|
||||
{
|
||||
nsIDOMCSSStyleDeclaration* prop;
|
||||
if (NS_OK == a->GetStyle(&prop)) {
|
||||
// get the js object
|
||||
if (prop != nsnull) {
|
||||
nsIScriptObjectOwner *owner = nsnull;
|
||||
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
|
||||
JSObject *object = nsnull;
|
||||
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
|
||||
// set the return value
|
||||
*vp = OBJECT_TO_JSVAL(object);
|
||||
}
|
||||
NS_RELEASE(owner);
|
||||
}
|
||||
NS_RELEASE(prop);
|
||||
}
|
||||
else {
|
||||
*vp = JSVAL_NULL;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
nsIJSScriptObject *object;
|
||||
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
|
||||
PRBool rval;
|
||||
rval = object->GetProperty(cx, id, vp);
|
||||
NS_RELEASE(object);
|
||||
return rval;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
nsIJSScriptObject *object;
|
||||
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
|
||||
PRBool rval;
|
||||
rval = object->GetProperty(cx, id, vp);
|
||||
NS_RELEASE(object);
|
||||
return rval;
|
||||
}
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// CSSStyleRuleSimple Properties Setter
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
SetCSSStyleRuleSimpleProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
nsIDOMCSSStyleRuleSimple *a = (nsIDOMCSSStyleRuleSimple*)JS_GetPrivate(cx, obj);
|
||||
|
||||
// If there's no private data, this must be the prototype, so ignore
|
||||
if (nsnull == a) {
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
if (JSVAL_IS_INT(id)) {
|
||||
switch(JSVAL_TO_INT(id)) {
|
||||
case CSSSTYLERULESIMPLE_SELECTORTEXT:
|
||||
{
|
||||
nsAutoString prop;
|
||||
JSString *jsstring;
|
||||
if ((jsstring = JS_ValueToString(cx, *vp)) != nsnull) {
|
||||
prop.SetString(JS_GetStringChars(jsstring));
|
||||
}
|
||||
else {
|
||||
prop.SetString((const char *)nsnull);
|
||||
}
|
||||
|
||||
a->SetSelectorText(prop);
|
||||
|
||||
break;
|
||||
}
|
||||
case CSSSTYLERULESIMPLE_STYLE:
|
||||
{
|
||||
nsIDOMCSSStyleDeclaration* prop;
|
||||
if (JSVAL_IS_NULL(*vp)) {
|
||||
prop = nsnull;
|
||||
}
|
||||
else if (JSVAL_IS_OBJECT(*vp)) {
|
||||
JSObject *jsobj = JSVAL_TO_OBJECT(*vp);
|
||||
nsISupports *supports = (nsISupports *)JS_GetPrivate(cx, jsobj);
|
||||
if (NS_OK != supports->QueryInterface(kICSSStyleDeclarationIID, (void **)&prop)) {
|
||||
JS_ReportError(cx, "Parameter must be of type CSSStyleDeclaration");
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Parameter must be an object");
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
a->SetStyle(prop);
|
||||
if (prop) NS_RELEASE(prop);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
nsIJSScriptObject *object;
|
||||
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
|
||||
PRBool rval;
|
||||
rval = object->SetProperty(cx, id, vp);
|
||||
NS_RELEASE(object);
|
||||
return rval;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
nsIJSScriptObject *object;
|
||||
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
|
||||
PRBool rval;
|
||||
rval = object->SetProperty(cx, id, vp);
|
||||
NS_RELEASE(object);
|
||||
return rval;
|
||||
}
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// CSSStyleRuleSimple finalizer
|
||||
//
|
||||
PR_STATIC_CALLBACK(void)
|
||||
FinalizeCSSStyleRuleSimple(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
nsIDOMCSSStyleRuleSimple *a = (nsIDOMCSSStyleRuleSimple*)JS_GetPrivate(cx, obj);
|
||||
|
||||
if (nsnull != a) {
|
||||
// get the js object
|
||||
nsIScriptObjectOwner *owner = nsnull;
|
||||
if (NS_OK == a->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
|
||||
owner->SetScriptObject(nsnull);
|
||||
NS_RELEASE(owner);
|
||||
}
|
||||
|
||||
NS_RELEASE(a);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// CSSStyleRuleSimple enumerate
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
EnumerateCSSStyleRuleSimple(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
nsIDOMCSSStyleRuleSimple *a = (nsIDOMCSSStyleRuleSimple*)JS_GetPrivate(cx, obj);
|
||||
|
||||
if (nsnull != a) {
|
||||
// get the js object
|
||||
nsIJSScriptObject *object;
|
||||
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
|
||||
object->EnumerateProperty(cx);
|
||||
NS_RELEASE(object);
|
||||
}
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// CSSStyleRuleSimple resolve
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
ResolveCSSStyleRuleSimple(JSContext *cx, JSObject *obj, jsval id)
|
||||
{
|
||||
nsIDOMCSSStyleRuleSimple *a = (nsIDOMCSSStyleRuleSimple*)JS_GetPrivate(cx, obj);
|
||||
|
||||
if (nsnull != a) {
|
||||
// get the js object
|
||||
nsIJSScriptObject *object;
|
||||
if (NS_OK == a->QueryInterface(kIJSScriptObjectIID, (void**)&object)) {
|
||||
object->Resolve(cx, id);
|
||||
NS_RELEASE(object);
|
||||
}
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
|
||||
/***********************************************************************/
|
||||
//
|
||||
// class for CSSStyleRuleSimple
|
||||
//
|
||||
JSClass CSSStyleRuleSimpleClass = {
|
||||
"CSSStyleRuleSimple",
|
||||
JSCLASS_HAS_PRIVATE,
|
||||
JS_PropertyStub,
|
||||
JS_PropertyStub,
|
||||
GetCSSStyleRuleSimpleProperty,
|
||||
SetCSSStyleRuleSimpleProperty,
|
||||
EnumerateCSSStyleRuleSimple,
|
||||
ResolveCSSStyleRuleSimple,
|
||||
JS_ConvertStub,
|
||||
FinalizeCSSStyleRuleSimple
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// CSSStyleRuleSimple class properties
|
||||
//
|
||||
static JSPropertySpec CSSStyleRuleSimpleProperties[] =
|
||||
{
|
||||
{"selectorText", CSSSTYLERULESIMPLE_SELECTORTEXT, JSPROP_ENUMERATE},
|
||||
{"style", CSSSTYLERULESIMPLE_STYLE, JSPROP_ENUMERATE},
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// CSSStyleRuleSimple class methods
|
||||
//
|
||||
static JSFunctionSpec CSSStyleRuleSimpleMethods[] =
|
||||
{
|
||||
{0}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// CSSStyleRuleSimple constructor
|
||||
//
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
CSSStyleRuleSimple(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
|
||||
{
|
||||
return JS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// CSSStyleRuleSimple class initialization
|
||||
//
|
||||
nsresult NS_InitCSSStyleRuleSimpleClass(nsIScriptContext *aContext, void **aPrototype)
|
||||
{
|
||||
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
|
||||
JSObject *proto = nsnull;
|
||||
JSObject *constructor = nsnull;
|
||||
JSObject *parent_proto = nsnull;
|
||||
JSObject *global = JS_GetGlobalObject(jscontext);
|
||||
jsval vp;
|
||||
|
||||
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "CSSStyleRuleSimple", &vp)) ||
|
||||
!JSVAL_IS_OBJECT(vp) ||
|
||||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
|
||||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
|
||||
!JSVAL_IS_OBJECT(vp)) {
|
||||
|
||||
if (NS_OK != NS_InitCSSStyleRuleClass(aContext, (void **)&parent_proto)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
proto = JS_InitClass(jscontext, // context
|
||||
global, // global object
|
||||
parent_proto, // parent proto
|
||||
&CSSStyleRuleSimpleClass, // JSClass
|
||||
CSSStyleRuleSimple, // JSNative ctor
|
||||
0, // ctor args
|
||||
CSSStyleRuleSimpleProperties, // proto props
|
||||
CSSStyleRuleSimpleMethods, // proto funcs
|
||||
nsnull, // ctor props (static)
|
||||
nsnull); // ctor funcs (static)
|
||||
if (nsnull == proto) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
}
|
||||
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
|
||||
proto = JSVAL_TO_OBJECT(vp);
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (aPrototype) {
|
||||
*aPrototype = proto;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
// Method for creating a new CSSStyleRuleSimple JavaScript object
|
||||
//
|
||||
extern "C" NS_DOM nsresult NS_NewScriptCSSStyleRuleSimple(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptCSSStyleRuleSimple");
|
||||
JSObject *proto;
|
||||
JSObject *parent;
|
||||
nsIScriptObjectOwner *owner;
|
||||
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
|
||||
nsresult result = NS_OK;
|
||||
nsIDOMCSSStyleRuleSimple *aCSSStyleRuleSimple;
|
||||
|
||||
if (nsnull == aParent) {
|
||||
parent = nsnull;
|
||||
}
|
||||
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
|
||||
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
|
||||
NS_RELEASE(owner);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
NS_RELEASE(owner);
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (NS_OK != NS_InitCSSStyleRuleSimpleClass(aContext, (void **)&proto)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
result = aSupports->QueryInterface(kICSSStyleRuleSimpleIID, (void **)&aCSSStyleRuleSimple);
|
||||
if (NS_OK != result) {
|
||||
return result;
|
||||
}
|
||||
|
||||
// create a js object for this class
|
||||
*aReturn = JS_NewObject(jscontext, &CSSStyleRuleSimpleClass, proto, parent);
|
||||
if (nsnull != *aReturn) {
|
||||
// connect the native object to the js object
|
||||
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aCSSStyleRuleSimple);
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(aCSSStyleRuleSimple);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
|
@ -29,6 +29,7 @@
|
|||
#include "nsIDOMHTMLElement.h"
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
#include "nsIDOMNSHTMLDocument.h"
|
||||
#include "nsIDOMStyleSheetCollection.h"
|
||||
#include "nsIDOMHTMLCollection.h"
|
||||
#include "nsIDOMNodeList.h"
|
||||
|
||||
|
@ -40,6 +41,7 @@ static NS_DEFINE_IID(kIElementIID, NS_IDOMELEMENT_IID);
|
|||
static NS_DEFINE_IID(kIHTMLElementIID, NS_IDOMHTMLELEMENT_IID);
|
||||
static NS_DEFINE_IID(kIHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kINSHTMLDocumentIID, NS_IDOMNSHTMLDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kIStyleSheetCollectionIID, NS_IDOMSTYLESHEETCOLLECTION_IID);
|
||||
static NS_DEFINE_IID(kIHTMLCollectionIID, NS_IDOMHTMLCOLLECTION_IID);
|
||||
static NS_DEFINE_IID(kINodeListIID, NS_IDOMNODELIST_IID);
|
||||
|
||||
|
@ -47,6 +49,7 @@ NS_DEF_PTR(nsIDOMElement);
|
|||
NS_DEF_PTR(nsIDOMHTMLElement);
|
||||
NS_DEF_PTR(nsIDOMHTMLDocument);
|
||||
NS_DEF_PTR(nsIDOMNSHTMLDocument);
|
||||
NS_DEF_PTR(nsIDOMStyleSheetCollection);
|
||||
NS_DEF_PTR(nsIDOMHTMLCollection);
|
||||
NS_DEF_PTR(nsIDOMNodeList);
|
||||
|
||||
|
@ -74,10 +77,11 @@ enum HTMLDocument_slots {
|
|||
NSHTMLDOCUMENT_VLINKCOLOR = -18,
|
||||
NSHTMLDOCUMENT_BGCOLOR = -19,
|
||||
NSHTMLDOCUMENT_FGCOLOR = -20,
|
||||
NSHTMLDOCUMENT_LASTMODIFIED = -21,
|
||||
NSHTMLDOCUMENT_EMBEDS = -22,
|
||||
NSHTMLDOCUMENT_LAYERS = -23,
|
||||
NSHTMLDOCUMENT_PLUGINS = -24
|
||||
NSHTMLDOCUMENT_STYLESHEETS = -21,
|
||||
NSHTMLDOCUMENT_LASTMODIFIED = -22,
|
||||
NSHTMLDOCUMENT_EMBEDS = -23,
|
||||
NSHTMLDOCUMENT_LAYERS = -24,
|
||||
NSHTMLDOCUMENT_PLUGINS = -25
|
||||
};
|
||||
|
||||
/***********************************************************************/
|
||||
|
@ -485,6 +489,42 @@ GetHTMLDocumentProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
|||
}
|
||||
break;
|
||||
}
|
||||
case NSHTMLDOCUMENT_STYLESHEETS:
|
||||
{
|
||||
nsIDOMStyleSheetCollection* prop;
|
||||
nsIDOMNSHTMLDocument* b;
|
||||
if (NS_OK == a->QueryInterface(kINSHTMLDocumentIID, (void **)&b)) {
|
||||
if(NS_OK == b->GetStyleSheets(&prop)) {
|
||||
// get the js object
|
||||
if (prop != nsnull) {
|
||||
nsIScriptObjectOwner *owner = nsnull;
|
||||
if (NS_OK == prop->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
|
||||
JSObject *object = nsnull;
|
||||
nsIScriptContext *script_cx = (nsIScriptContext *)JS_GetContextPrivate(cx);
|
||||
if (NS_OK == owner->GetScriptObject(script_cx, (void**)&object)) {
|
||||
// set the return value
|
||||
*vp = OBJECT_TO_JSVAL(object);
|
||||
}
|
||||
NS_RELEASE(owner);
|
||||
}
|
||||
NS_RELEASE(prop);
|
||||
}
|
||||
else {
|
||||
*vp = JSVAL_NULL;
|
||||
}
|
||||
NS_RELEASE(b);
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(b);
|
||||
return JS_FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
JS_ReportError(cx, "Object must be of type NSHTMLDocument");
|
||||
return JS_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case NSHTMLDOCUMENT_LASTMODIFIED:
|
||||
{
|
||||
nsAutoString prop;
|
||||
|
@ -1368,6 +1408,7 @@ static JSPropertySpec HTMLDocumentProperties[] =
|
|||
{"vlinkColor", NSHTMLDOCUMENT_VLINKCOLOR, JSPROP_ENUMERATE},
|
||||
{"bgColor", NSHTMLDOCUMENT_BGCOLOR, JSPROP_ENUMERATE},
|
||||
{"fgColor", NSHTMLDOCUMENT_FGCOLOR, JSPROP_ENUMERATE},
|
||||
{"styleSheets", NSHTMLDOCUMENT_STYLESHEETS, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"lastModified", NSHTMLDOCUMENT_LASTMODIFIED, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"embeds", NSHTMLDOCUMENT_EMBEDS, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
{"layers", NSHTMLDOCUMENT_LAYERS, JSPROP_ENUMERATE | JSPROP_READONLY},
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/* -*- Mode: js; 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.
|
||||
*/
|
||||
|
||||
var s;
|
||||
for (s = 0; s < document.styleSheets.length; s++) {
|
||||
var sheet = document.styleSheets[s];
|
||||
dump("Style sheet #" + (s+1) + ": " + sheet.title + "\n");
|
||||
var i, r;
|
||||
dump("\n");
|
||||
for (i = 0; i < sheet.imports.length; i++) {
|
||||
dump("@import url(" + sheet.imports[i].href + ");\n");
|
||||
}
|
||||
dump("\n");
|
||||
for (r = 0; r < sheet.rules.length; r++) {
|
||||
var rule = sheet.rules[r];
|
||||
dump(rule.selectorText + " {" + "\n");
|
||||
var style = rule.style;
|
||||
var p;
|
||||
for (p = 0; p < style.length; p++) {
|
||||
dump(" " + style[p] + ":" + style.getPropertyValue(style[p]) + ";\n");
|
||||
}
|
||||
dump(" }\n");
|
||||
}
|
||||
dump("\n");
|
||||
}
|
|
@ -22,7 +22,6 @@ LIBRARY_NAME = nglhtmlcon_s
|
|||
# Note the sophisticated alphabetical ordering :-|
|
||||
CPPSRCS= \
|
||||
nsCommentNode.cpp \
|
||||
nsDOMStyleDeclaration.cpp \
|
||||
nsGenericDOMDataNode.cpp \
|
||||
nsGenericHTMLElement.cpp \
|
||||
nsHTMLAnchorElement.cpp \
|
||||
|
|
|
@ -24,7 +24,6 @@ DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
|||
|
||||
CPPSRCS= \
|
||||
nsCommentNode.cpp \
|
||||
nsDOMStyleDeclaration.cpp \
|
||||
nsGenericDOMDataNode.cpp \
|
||||
nsGenericHTMLElement.cpp \
|
||||
nsHTMLAnchorElement.cpp \
|
||||
|
@ -92,7 +91,6 @@ CPPSRCS= \
|
|||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsCommentNode.obj \
|
||||
.\$(OBJDIR)\nsDOMStyleDeclaration.obj \
|
||||
.\$(OBJDIR)\nsGenericDOMDataNode.obj \
|
||||
.\$(OBJDIR)\nsGenericHTMLElement.obj \
|
||||
.\$(OBJDIR)\nsHTMLAnchorElement.obj \
|
||||
|
|
|
@ -60,7 +60,7 @@
|
|||
#include "nsIServiceManager.h"
|
||||
#include "nsIDOMScriptObjectFactory.h"
|
||||
#include "nsIDOMCSSStyleDeclaration.h"
|
||||
#include "nsDOMStyleDeclaration.h"
|
||||
#include "nsDOMCSSDeclaration.h"
|
||||
#include "prprf.h"
|
||||
#include "prmem.h"
|
||||
|
||||
|
@ -175,7 +175,7 @@ public:
|
|||
// nsIDOMNodeList interface
|
||||
NS_DECL_IDOMNODELIST
|
||||
|
||||
void DropContent();
|
||||
void DropReference();
|
||||
|
||||
private:
|
||||
nsGenericHTMLContainerElement *mContent;
|
||||
|
@ -554,6 +554,113 @@ DOMAttributeMap::GetLength(PRUint32 *aLength)
|
|||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
class nsDOMCSSAttributeDeclaration : public nsDOMCSSDeclaration
|
||||
{
|
||||
public:
|
||||
nsDOMCSSAttributeDeclaration(nsIHTMLContent *aContent);
|
||||
~nsDOMCSSAttributeDeclaration();
|
||||
|
||||
virtual void DropReference();
|
||||
virtual nsresult GetCSSDeclaration(nsICSSDeclaration **aDecl,
|
||||
PRBool aAllocate);
|
||||
virtual nsresult StylePropertyChanged(const nsString& aPropertyName,
|
||||
PRInt32 aHint);
|
||||
virtual nsresult GetParent(nsISupports **aParent);
|
||||
|
||||
protected:
|
||||
nsIHTMLContent *mContent;
|
||||
};
|
||||
|
||||
nsDOMCSSAttributeDeclaration::nsDOMCSSAttributeDeclaration(nsIHTMLContent *aContent)
|
||||
{
|
||||
// This reference is not reference-counted. The content
|
||||
// object tells us when its about to go away.
|
||||
mContent = aContent;
|
||||
}
|
||||
|
||||
nsDOMCSSAttributeDeclaration::~nsDOMCSSAttributeDeclaration()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
nsDOMCSSAttributeDeclaration::DropReference()
|
||||
{
|
||||
mContent = nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMCSSAttributeDeclaration::GetCSSDeclaration(nsICSSDeclaration **aDecl,
|
||||
PRBool aAllocate)
|
||||
{
|
||||
nsHTMLValue val;
|
||||
nsIStyleRule* rule;
|
||||
nsICSSStyleRule* cssRule;
|
||||
nsresult result = NS_OK;
|
||||
|
||||
*aDecl = nsnull;
|
||||
if (nsnull != mContent) {
|
||||
mContent->GetAttribute(nsHTMLAtoms::style, val);
|
||||
if (eHTMLUnit_ISupports == val.GetUnit()) {
|
||||
rule = (nsIStyleRule*) val.GetISupportsValue();
|
||||
result = rule->QueryInterface(kICSSStyleRuleIID, (void**)&cssRule);
|
||||
if (NS_OK == result) {
|
||||
*aDecl = cssRule->GetDeclaration();
|
||||
NS_RELEASE(cssRule);
|
||||
}
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
else if (PR_TRUE == aAllocate) {
|
||||
result = NS_NewCSSDeclaration(aDecl);
|
||||
if (NS_OK == result) {
|
||||
result = NS_NewCSSStyleRule(&cssRule, nsCSSSelector());
|
||||
if (NS_OK == result) {
|
||||
cssRule->SetDeclaration(*aDecl);
|
||||
cssRule->SetWeight(0x7fffffff);
|
||||
rule = (nsIStyleRule *)cssRule;
|
||||
result = mContent->SetAttribute(nsHTMLAtoms::style,
|
||||
nsHTMLValue(cssRule),
|
||||
PR_FALSE);
|
||||
NS_RELEASE(cssRule);
|
||||
}
|
||||
else {
|
||||
NS_RELEASE(*aDecl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMCSSAttributeDeclaration::StylePropertyChanged(const nsString& aPropertyName,
|
||||
PRInt32 aHint)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
if (nsnull != mContent) {
|
||||
nsIDocument *doc;
|
||||
result = mContent->GetDocument(doc);
|
||||
if (NS_OK == result) {
|
||||
result = doc->AttributeChanged(mContent, nsHTMLAtoms::style, aHint);
|
||||
NS_RELEASE(doc);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsDOMCSSAttributeDeclaration::GetParent(nsISupports **aParent)
|
||||
{
|
||||
if (nsnull != mContent) {
|
||||
return mContent->QueryInterface(kISupportsIID, (void **)aParent);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------
|
||||
|
||||
static nsresult EnsureWritableAttributes(nsIHTMLContent* aContent,
|
||||
nsIHTMLAttributes*& aAttributes, PRBool aCreate)
|
||||
{
|
||||
|
@ -641,11 +748,11 @@ nsGenericHTMLElement::~nsGenericHTMLElement()
|
|||
NS_IF_RELEASE(mListenerManager);
|
||||
if (nsnull != mDOMSlots) {
|
||||
if (nsnull != mDOMSlots->mChildNodes) {
|
||||
mDOMSlots->mChildNodes->DropContent();
|
||||
mDOMSlots->mChildNodes->DropReference();
|
||||
NS_RELEASE(mDOMSlots->mChildNodes);
|
||||
}
|
||||
if (nsnull != mDOMSlots->mStyle) {
|
||||
mDOMSlots->mStyle->DropContent();
|
||||
mDOMSlots->mStyle->DropReference();
|
||||
NS_RELEASE(mDOMSlots->mStyle);
|
||||
}
|
||||
// XXX Should really be arena managed
|
||||
|
@ -954,7 +1061,7 @@ nsGenericHTMLElement::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
|
|||
nsDOMSlots *slots = GetDOMSlots();
|
||||
|
||||
if (nsnull == slots->mStyle) {
|
||||
slots->mStyle = new nsDOMStyleDeclaration(mContent);
|
||||
slots->mStyle = new nsDOMCSSAttributeDeclaration(mContent);
|
||||
if (nsnull == slots->mStyle) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
@ -2909,7 +3016,7 @@ nsChildContentList::Item(PRUint32 aIndex, nsIDOMNode** aReturn)
|
|||
}
|
||||
|
||||
void
|
||||
nsChildContentList::DropContent()
|
||||
nsChildContentList::DropReference()
|
||||
{
|
||||
mContent = nsnull;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ class nsIStyleRule;
|
|||
class nsISupportsArray;
|
||||
class nsIDOMScriptObjectFactory;
|
||||
class nsChildContentList;
|
||||
class nsDOMStyleDeclaration;
|
||||
class nsDOMCSSDeclaration;
|
||||
|
||||
|
||||
// There are a set of DOM- and scripting-specific instance variables
|
||||
|
@ -59,7 +59,7 @@ class nsDOMStyleDeclaration;
|
|||
typedef struct {
|
||||
void *mScriptObject;
|
||||
nsChildContentList *mChildNodes;
|
||||
nsDOMStyleDeclaration *mStyle;
|
||||
nsDOMCSSDeclaration *mStyle;
|
||||
} nsDOMSlots;
|
||||
|
||||
class nsGenericHTMLElement : public nsIJSScriptObject {
|
||||
|
|
|
@ -48,6 +48,9 @@
|
|||
#include "nsIFormManager.h"
|
||||
#include "nsRepository.h"
|
||||
#include "nsParserCIID.h"
|
||||
#include "nsIDOMStyleSheet.h"
|
||||
#include "nsIDOMStyleSheetCollection.h"
|
||||
|
||||
|
||||
// Find/Serach Includes
|
||||
#include "nsISelection.h"
|
||||
|
@ -73,6 +76,239 @@ static NS_DEFINE_IID(kIDOMHTMLDocumentIID, NS_IDOMHTMLDOCUMENT_IID);
|
|||
static NS_DEFINE_IID(kIDOMNSHTMLDocumentIID, NS_IDOMNSHTMLDOCUMENT_IID);
|
||||
static NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID);
|
||||
static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID);
|
||||
static NS_DEFINE_IID(kIDOMStyleSheetCollectionIID, NS_IDOMSTYLESHEETCOLLECTION_IID);
|
||||
static NS_DEFINE_IID(kIDOMStyleSheetIID, NS_IDOMSTYLESHEET_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
static NS_DEFINE_IID(kIDocumentObserverIID, NS_IDOCUMENT_OBSERVER_IID);
|
||||
|
||||
class nsDOMStyleSheetCollection : public nsIDOMStyleSheetCollection,
|
||||
public nsIScriptObjectOwner,
|
||||
public nsIDocumentObserver
|
||||
{
|
||||
public:
|
||||
nsDOMStyleSheetCollection(nsIDocument *aDocument);
|
||||
~nsDOMStyleSheetCollection();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IDOMSTYLESHEETCOLLECTION
|
||||
|
||||
NS_IMETHOD BeginUpdate(nsIDocument *aDocument) { return NS_OK; }
|
||||
NS_IMETHOD EndUpdate(nsIDocument *aDocument) { return NS_OK; }
|
||||
NS_IMETHOD BeginLoad(nsIDocument *aDocument) { return NS_OK; }
|
||||
NS_IMETHOD EndLoad(nsIDocument *aDocument) { return NS_OK; }
|
||||
NS_IMETHOD BeginReflow(nsIDocument *aDocument,
|
||||
nsIPresShell* aShell) { return NS_OK; }
|
||||
NS_IMETHOD EndReflow(nsIDocument *aDocument,
|
||||
nsIPresShell* aShell) { return NS_OK; }
|
||||
NS_IMETHOD ContentChanged(nsIDocument *aDocument,
|
||||
nsIContent* aContent,
|
||||
nsISupports* aSubContent) { return NS_OK; }
|
||||
NS_IMETHOD AttributeChanged(nsIDocument *aDocument,
|
||||
nsIContent* aContent,
|
||||
nsIAtom* aAttribute,
|
||||
PRInt32 aHint) { return NS_OK; }
|
||||
NS_IMETHOD ContentAppended(nsIDocument *aDocument,
|
||||
nsIContent* aContainer,
|
||||
PRInt32 aNewIndexInContainer)
|
||||
{ return NS_OK; }
|
||||
NS_IMETHOD ContentInserted(nsIDocument *aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) { return NS_OK; }
|
||||
NS_IMETHOD ContentReplaced(nsIDocument *aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aOldChild,
|
||||
nsIContent* aNewChild,
|
||||
PRInt32 aIndexInContainer) { return NS_OK; }
|
||||
NS_IMETHOD ContentRemoved(nsIDocument *aDocument,
|
||||
nsIContent* aContainer,
|
||||
nsIContent* aChild,
|
||||
PRInt32 aIndexInContainer) { return NS_OK; }
|
||||
NS_IMETHOD StyleSheetAdded(nsIDocument *aDocument,
|
||||
nsIStyleSheet* aStyleSheet);
|
||||
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
protected:
|
||||
PRInt32 mLength;
|
||||
nsIDocument* mDocument;
|
||||
void* mScriptObject;
|
||||
};
|
||||
|
||||
nsDOMStyleSheetCollection::nsDOMStyleSheetCollection(nsIDocument *aDocument)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mLength = -1;
|
||||
// Not reference counted to avoid circular references.
|
||||
// The document will tell us when its going away.
|
||||
mDocument = aDocument;
|
||||
mDocument->AddObserver(this);
|
||||
mScriptObject = nsnull;
|
||||
}
|
||||
|
||||
nsDOMStyleSheetCollection::~nsDOMStyleSheetCollection()
|
||||
{
|
||||
if (nsnull != mDocument) {
|
||||
mDocument->RemoveObserver(this);
|
||||
}
|
||||
mDocument = nsnull;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsDOMStyleSheetCollection)
|
||||
NS_IMPL_RELEASE(nsDOMStyleSheetCollection)
|
||||
|
||||
nsresult
|
||||
nsDOMStyleSheetCollection::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
||||
{
|
||||
if (NULL == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kIDOMStyleSheetCollectionIID)) {
|
||||
nsIDOMStyleSheetCollection *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
nsIScriptObjectOwner *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDocumentObserverIID)) {
|
||||
nsIDocumentObserver *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
nsIDOMStyleSheetCollection *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMStyleSheetCollection::GetLength(PRUint32* aLength)
|
||||
{
|
||||
if (nsnull != mDocument) {
|
||||
// XXX Find the number and then cache it. We'll use the
|
||||
// observer notification to figure out if new ones have
|
||||
// been added or removed.
|
||||
if (-1 == mLength) {
|
||||
PRUint32 count = 0;
|
||||
PRInt32 i, imax = mDocument->GetNumberOfStyleSheets();
|
||||
|
||||
for (i = 0; i < imax; i++) {
|
||||
nsIStyleSheet *sheet = mDocument->GetStyleSheetAt(i);
|
||||
nsIDOMStyleSheet *domss;
|
||||
|
||||
if (NS_OK == sheet->QueryInterface(kIDOMStyleSheetIID, (void **)&domss)) {
|
||||
count++;
|
||||
NS_RELEASE(domss);
|
||||
}
|
||||
|
||||
NS_RELEASE(sheet);
|
||||
}
|
||||
mLength = count;
|
||||
}
|
||||
*aLength = mLength;
|
||||
}
|
||||
else {
|
||||
*aLength = 0;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMStyleSheetCollection::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn)
|
||||
{
|
||||
*aReturn = nsnull;
|
||||
if (nsnull != mDocument) {
|
||||
PRUint32 count = 0;
|
||||
PRInt32 i, imax = mDocument->GetNumberOfStyleSheets();
|
||||
|
||||
// XXX Not particularly efficient, but does anyone care?
|
||||
for (i = 0; (i < imax) && (nsnull == *aReturn); i++) {
|
||||
nsIStyleSheet *sheet = mDocument->GetStyleSheetAt(i);
|
||||
nsIDOMStyleSheet *domss;
|
||||
|
||||
if (NS_OK == sheet->QueryInterface(kIDOMStyleSheetIID, (void **)&domss)) {
|
||||
if (count++ == aIndex) {
|
||||
*aReturn = domss;
|
||||
NS_ADDREF(domss);
|
||||
}
|
||||
NS_RELEASE(domss);
|
||||
}
|
||||
|
||||
NS_RELEASE(sheet);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMStyleSheetCollection::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
nsISupports *supports = (nsISupports *)(nsIDOMStyleSheetCollection *)this;
|
||||
nsISupports *parent = (nsISupports *)mDocument;
|
||||
|
||||
// XXX Should be done through factory
|
||||
res = NS_NewScriptStyleSheetCollection(aContext,
|
||||
supports,
|
||||
parent,
|
||||
(void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMStyleSheetCollection::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMStyleSheetCollection::StyleSheetAdded(nsIDocument *aDocument,
|
||||
nsIStyleSheet* aStyleSheet)
|
||||
{
|
||||
if (-1 != mLength) {
|
||||
nsIDOMStyleSheet *domss;
|
||||
if (NS_OK == aStyleSheet->QueryInterface(kIDOMStyleSheetIID, (void **)&domss)) {
|
||||
mLength++;
|
||||
NS_RELEASE(domss);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDOMStyleSheetCollection::DocumentWillBeDestroyed(nsIDocument *aDocument)
|
||||
{
|
||||
if (nsnull != mDocument) {
|
||||
aDocument->RemoveObserver(this);
|
||||
mDocument = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_LAYOUT nsresult
|
||||
NS_NewHTMLDocument(nsIDocument** aInstancePtrResult)
|
||||
|
@ -93,6 +329,7 @@ nsHTMLDocument::nsHTMLDocument()
|
|||
mAnchors = nsnull;
|
||||
mNamedItems = nsnull;
|
||||
mParser = nsnull;
|
||||
mDOMStyleSheets = nsnull;
|
||||
nsHTMLAtoms::AddrefAtoms();
|
||||
mDTDMode = eDTDMode_NoQuirks;
|
||||
|
||||
|
@ -124,6 +361,7 @@ nsHTMLDocument::~nsHTMLDocument()
|
|||
NS_IF_RELEASE(mEmbeds);
|
||||
NS_IF_RELEASE(mLinks);
|
||||
NS_IF_RELEASE(mAnchors);
|
||||
NS_IF_RELEASE(mDOMStyleSheets);
|
||||
NS_IF_RELEASE(mAttrStyleSheet);
|
||||
NS_IF_RELEASE(mStyleAttrStyleSheet);
|
||||
NS_IF_RELEASE(mParser);
|
||||
|
@ -830,6 +1068,23 @@ nsHTMLDocument::GetLastModified(nsString& aLastModified)
|
|||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::GetStyleSheets(nsIDOMStyleSheetCollection** aStyleSheets)
|
||||
{
|
||||
if (nsnull == mDOMStyleSheets) {
|
||||
mDOMStyleSheets = new nsDOMStyleSheetCollection(this);
|
||||
if (nsnull == mDOMStyleSheets) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(mDOMStyleSheets);
|
||||
}
|
||||
|
||||
*aStyleSheets = mDOMStyleSheets;
|
||||
NS_ADDREF(mDOMStyleSheets);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTMLDocument::GetEmbeds(nsIDOMHTMLCollection** aEmbeds)
|
||||
{
|
||||
|
|
|
@ -32,6 +32,7 @@ class nsContentList;
|
|||
class nsIContentViewerContainer;
|
||||
class nsIParser;
|
||||
class BlockText;
|
||||
class nsDOMStyleSheetCollection;
|
||||
|
||||
class nsHTMLDocument : public nsMarkupDocument, public nsIHTMLDocument, public nsIDOMHTMLDocument, public nsIDOMNSHTMLDocument {
|
||||
public:
|
||||
|
@ -161,6 +162,7 @@ protected:
|
|||
nsContentList *mLinks;
|
||||
nsContentList *mAnchors;
|
||||
nsContentList *mForms;
|
||||
nsDOMStyleSheetCollection *mDOMStyleSheets;
|
||||
|
||||
PLHashTable *mNamedItems;
|
||||
|
||||
|
|
|
@ -43,7 +43,7 @@ public:
|
|||
NS_IMETHOD SetStyleSheet(nsIStyleSheet* aSheet) = 0;
|
||||
|
||||
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
|
||||
nsIURL* aInputURL,
|
||||
nsIURL* aInputURL,
|
||||
nsIStyleSheet*& aResult) = 0;
|
||||
|
||||
// Parse declarations assuming that the outer curly braces have
|
||||
|
@ -58,6 +58,7 @@ public:
|
|||
nsICSSDeclaration* aDeclaration,
|
||||
PRInt32* aHint) = 0;
|
||||
|
||||
NS_IMETHOD ProcessImport(const nsString& aURLSpec) = 0;
|
||||
};
|
||||
|
||||
// Values or'd in the GetInfoMask; other bits are reserved
|
||||
|
|
|
@ -35,6 +35,7 @@ CPPSRCS = \
|
|||
nsCSSScanner.cpp \
|
||||
nsCSSStyleRule.cpp \
|
||||
nsCSSStyleSheet.cpp \
|
||||
nsDOMCSSDeclaration.cpp \
|
||||
nsHTMLAttributes.cpp \
|
||||
nsHTMLStyleSheet.cpp \
|
||||
nsHTMLCSSStyleSheet.cpp \
|
||||
|
@ -43,6 +44,7 @@ CPPSRCS = \
|
|||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nsDOMCSSDeclaration.h \
|
||||
nsCSSProps.h \
|
||||
nsCSSPropIDs.h \
|
||||
nsICSSStyleSheet.h \
|
||||
|
|
|
@ -24,13 +24,14 @@ REQUIRES=xpcom raptor dom js
|
|||
DEFINES=-D_IMPL_NS_HTML -DWIN32_LEAN_AND_MEAN
|
||||
|
||||
EXPORTS=nsCSSProps.h nsCSSPropIDs.h nsICSSStyleSheet.h nsICSSStyleRule.h \
|
||||
nsICSSDeclaration.h nsHTMLValue.h nsIHTMLCSSStyleSheet.h
|
||||
nsICSSDeclaration.h nsHTMLValue.h nsIHTMLCSSStyleSheet.h \
|
||||
nsDOMCSSDeclaration.h
|
||||
|
||||
CPPSRCS=nsCSSKeywords.cpp nsCSSLayout.cpp nsCSSDeclaration.cpp \
|
||||
nsCSSParser.cpp nsCSSProps.cpp nsCSSProps2.cpp nsCSSRendering.cpp \
|
||||
nsCSSScanner.cpp nsCSSStyleRule.cpp nsCSSStyleSheet.cpp nsHTMLAttributes.cpp \
|
||||
nsHTMLStyleSheet.cpp nsHTMLCSSStyleSheet.cpp nsHTMLValue.cpp \
|
||||
nsStyleUtil.cpp
|
||||
nsStyleUtil.cpp nsDOMCSSDeclaration.cpp
|
||||
|
||||
CPP_OBJS=.\$(OBJDIR)\nsCSSKeywords.obj .\$(OBJDIR)\nsCSSLayout.obj \
|
||||
.\$(OBJDIR)\nsCSSDeclaration.obj .\$(OBJDIR)\nsCSSParser.obj \
|
||||
|
@ -39,7 +40,8 @@ CPP_OBJS=.\$(OBJDIR)\nsCSSKeywords.obj .\$(OBJDIR)\nsCSSLayout.obj \
|
|||
.\$(OBJDIR)\nsCSSScanner.obj .\$(OBJDIR)\nsCSSStyleRule.obj \
|
||||
.\$(OBJDIR)\nsCSSStyleSheet.obj .\$(OBJDIR)\nsHTMLAttributes.obj \
|
||||
.\$(OBJDIR)\nsHTMLStyleSheet.obj .\$(OBJDIR)\nsHTMLCSSStyleSheet.obj \
|
||||
.\$(OBJDIR)\nsHTMLValue.obj .\$(OBJDIR)\nsStyleUtil.obj
|
||||
.\$(OBJDIR)\nsHTMLValue.obj .\$(OBJDIR)\nsStyleUtil.obj \
|
||||
.\$(OBJDIR)\nsDOMCSSDeclaration.obj
|
||||
|
||||
LINCS=-I$(PUBLIC)\xpcom -I$(PUBLIC)\raptor -I$(PUBLIC)\netlib \
|
||||
-I..\..\..\base\src \
|
||||
|
|
|
@ -197,7 +197,7 @@ public:
|
|||
NS_IMETHOD SetStyleSheet(nsIStyleSheet* aSheet);
|
||||
|
||||
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
|
||||
nsIURL* aInputURL,
|
||||
nsIURL* aInputURL,
|
||||
nsIStyleSheet*& aResult);
|
||||
|
||||
NS_IMETHOD ParseDeclarations(const nsString& aDeclaration,
|
||||
|
@ -209,6 +209,8 @@ public:
|
|||
nsICSSDeclaration* aDeclaration,
|
||||
PRInt32* aHint);
|
||||
|
||||
NS_IMETHOD ProcessImport(const nsString& aURLSpec);
|
||||
|
||||
protected:
|
||||
PRBool GetToken(PRInt32* aErrorCode, PRBool aSkipWS);
|
||||
void UngetToken();
|
||||
|
@ -281,8 +283,6 @@ protected:
|
|||
PRBool TranslateLength(nsICSSDeclaration* aDeclaration, const char* aName,
|
||||
float aNumber, const nsString& aDimension);
|
||||
|
||||
void ProcessImport(const nsString& aURLSpec);
|
||||
|
||||
// Current token. The value is valid after calling GetToken
|
||||
nsCSSToken mToken;
|
||||
|
||||
|
@ -364,7 +364,7 @@ CSSParserImpl::SetStyleSheet(nsIStyleSheet* aSheet)
|
|||
|
||||
NS_METHOD
|
||||
CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
|
||||
nsIURL* aInputURL,
|
||||
nsIURL* aInputURL,
|
||||
nsIStyleSheet*& aResult)
|
||||
{
|
||||
if (nsnull == mSheet) {
|
||||
|
@ -598,7 +598,7 @@ PRBool CSSParserImpl::ParseImportRule(PRInt32* aErrorCode)
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
void CSSParserImpl::ProcessImport(const nsString& aURLSpec)
|
||||
NS_IMETHODIMP CSSParserImpl::ProcessImport(const nsString& aURLSpec)
|
||||
{
|
||||
// XXX probably need a way to encode unicode junk for the part of
|
||||
// the url that follows a "?"
|
||||
|
@ -609,7 +609,7 @@ void CSSParserImpl::ProcessImport(const nsString& aURLSpec)
|
|||
if (NS_OK != rv) {
|
||||
// import url is bad
|
||||
// XXX log this somewhere for easier web page debugging
|
||||
return;
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (PR_FALSE == mSheet->ContainsStyleSheet(url)) { // don't allow circular references
|
||||
|
@ -656,6 +656,8 @@ void CSSParserImpl::ProcessImport(const nsString& aURLSpec)
|
|||
}
|
||||
}
|
||||
NS_RELEASE(url);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void CSSParserImpl::SkipUntil(PRInt32* aErrorCode, PRUnichar aStopSymbol)
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
#include "nsICSSStyleRule.h"
|
||||
#include "nsICSSDeclaration.h"
|
||||
#include "nsIStyleSheet.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
|
@ -29,12 +30,25 @@
|
|||
#include "nsUnitConversion.h"
|
||||
#include "nsStyleUtil.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
#include "nsIDOMCSSStyleSheet.h"
|
||||
#include "nsIDOMCSSStyleRule.h"
|
||||
#include "nsIDOMCSSStyleRuleSimple.h"
|
||||
#include "nsIDOMCSSStyleDeclaration.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsDOMCSSDeclaration.h"
|
||||
|
||||
//#define DEBUG_REFS
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
|
||||
static NS_DEFINE_IID(kICSSDeclarationIID, NS_ICSS_DECLARATION_IID);
|
||||
static NS_DEFINE_IID(kICSSStyleRuleIID, NS_ICSS_STYLE_RULE_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleSheetIID, NS_IDOMCSSSTYLESHEET_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleRuleIID, NS_IDOMCSSSTYLERULE_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleRuleSimpleIID, NS_IDOMCSSSTYLERULESIMPLE_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleDeclarationIID, NS_IDOMCSSSTYLEDECLARATION_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
|
||||
static NS_DEFINE_IID(kCSSFontSID, NS_CSS_FONT_SID);
|
||||
static NS_DEFINE_IID(kCSSColorSID, NS_CSS_COLOR_SID);
|
||||
|
@ -231,10 +245,79 @@ CSSImportantRule::List(FILE* out, PRInt32 aIndent) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// -- nsDOMStyleRuleDeclaration -------------------------------
|
||||
|
||||
class DOMCSSDeclarationImpl : public nsDOMCSSDeclaration
|
||||
{
|
||||
public:
|
||||
DOMCSSDeclarationImpl(nsICSSStyleRule *aRule);
|
||||
~DOMCSSDeclarationImpl();
|
||||
|
||||
virtual void DropReference();
|
||||
virtual nsresult GetCSSDeclaration(nsICSSDeclaration **aDecl,
|
||||
PRBool aAllocate);
|
||||
virtual nsresult StylePropertyChanged(const nsString& aPropertyName,
|
||||
PRInt32 aHint);
|
||||
virtual nsresult GetParent(nsISupports **aParent);
|
||||
|
||||
protected:
|
||||
nsICSSStyleRule *mRule;
|
||||
};
|
||||
|
||||
DOMCSSDeclarationImpl::DOMCSSDeclarationImpl(nsICSSStyleRule *aRule)
|
||||
{
|
||||
// This reference is not reference-counted. The rule
|
||||
// object tells us when its about to go away.
|
||||
mRule = aRule;
|
||||
}
|
||||
|
||||
DOMCSSDeclarationImpl::~DOMCSSDeclarationImpl()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
DOMCSSDeclarationImpl::DropReference()
|
||||
{
|
||||
mRule = nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DOMCSSDeclarationImpl::GetCSSDeclaration(nsICSSDeclaration **aDecl,
|
||||
PRBool aAllocate)
|
||||
{
|
||||
if (nsnull != mRule) {
|
||||
*aDecl = mRule->GetDeclaration();
|
||||
}
|
||||
else {
|
||||
*aDecl = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DOMCSSDeclarationImpl::StylePropertyChanged(const nsString& aPropertyName,
|
||||
PRInt32 aHint)
|
||||
{
|
||||
// XXX TBI
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DOMCSSDeclarationImpl::GetParent(nsISupports **aParent)
|
||||
{
|
||||
if (nsnull != mRule) {
|
||||
return mRule->QueryInterface(kISupportsIID, (void **)aParent);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// -- nsCSSStyleRule -------------------------------
|
||||
|
||||
class CSSStyleRuleImpl : public nsICSSStyleRule {
|
||||
class CSSStyleRuleImpl : public nsICSSStyleRule,
|
||||
public nsIDOMCSSStyleRuleSimple,
|
||||
public nsIScriptObjectOwner {
|
||||
public:
|
||||
void* operator new(size_t size);
|
||||
void* operator new(size_t size, nsIArena* aArena);
|
||||
|
@ -263,10 +346,25 @@ public:
|
|||
|
||||
virtual nsIStyleRule* GetImportantRule(void);
|
||||
|
||||
virtual nsIStyleSheet* GetStyleSheet(void);
|
||||
virtual void SetStyleSheet(nsIStyleSheet *aSheet);
|
||||
|
||||
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
||||
|
||||
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
// nsIDOMCSSStyleRule interface
|
||||
NS_IMETHOD GetType(nsString& aType);
|
||||
|
||||
// nsIDOMCSSStyleRuleSimple interface
|
||||
NS_IMETHOD GetSelectorText(nsString& aSelectorText);
|
||||
NS_IMETHOD SetSelectorText(const nsString& aSelectorText);
|
||||
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
private:
|
||||
// These are not supported and are not implemented!
|
||||
CSSStyleRuleImpl(const CSSStyleRuleImpl& aCopy);
|
||||
|
@ -283,6 +381,9 @@ protected:
|
|||
nsICSSDeclaration* mDeclaration;
|
||||
PRInt32 mWeight;
|
||||
CSSImportantRule* mImportantRule;
|
||||
nsIStyleSheet* mStyleSheet;
|
||||
DOMCSSDeclarationImpl *mDOMDeclaration;
|
||||
void* mScriptObject;
|
||||
#ifdef DEBUG_REFS
|
||||
PRInt32 mInstance;
|
||||
#endif
|
||||
|
@ -334,6 +435,8 @@ CSSStyleRuleImpl::CSSStyleRuleImpl(const nsCSSSelector& aSelector)
|
|||
mWeight(0), mImportantRule(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mDOMDeclaration = nsnull;
|
||||
mScriptObject = nsnull;
|
||||
#ifdef DEBUG_REFS
|
||||
mInstance = gInstanceCount++;
|
||||
fprintf(stdout, "%d of %d + CSSStyleRule\n", mInstance, gInstanceCount);
|
||||
|
@ -351,6 +454,9 @@ CSSStyleRuleImpl::~CSSStyleRuleImpl()
|
|||
}
|
||||
NS_IF_RELEASE(mDeclaration);
|
||||
NS_IF_RELEASE(mImportantRule);
|
||||
if (nsnull != mDOMDeclaration) {
|
||||
mDOMDeclaration->DropReference();
|
||||
}
|
||||
#ifdef DEBUG_REFS
|
||||
--gInstanceCount;
|
||||
fprintf(stdout, "%d of %d - CSSStyleRule\n", mInstance, gInstanceCount);
|
||||
|
@ -389,7 +495,6 @@ nsresult CSSStyleRuleImpl::QueryInterface(const nsIID& aIID,
|
|||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kICSSStyleRuleIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsICSSStyleRule*)this);
|
||||
NS_ADDREF_THIS();
|
||||
|
@ -400,8 +505,28 @@ nsresult CSSStyleRuleImpl::QueryInterface(const nsIID& aIID,
|
|||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMCSSStyleRuleIID)) {
|
||||
nsIDOMCSSStyleRule *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMCSSStyleRuleSimpleIID)) {
|
||||
nsIDOMCSSStyleRuleSimple *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
nsIScriptObjectOwner *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsISupports*)this);
|
||||
nsICSSStyleRule *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -543,6 +668,21 @@ nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
|
|||
return mImportantRule;
|
||||
}
|
||||
|
||||
nsIStyleSheet* CSSStyleRuleImpl::GetStyleSheet(void)
|
||||
{
|
||||
NS_IF_ADDREF(mStyleSheet);
|
||||
|
||||
return mStyleSheet;
|
||||
}
|
||||
|
||||
void CSSStyleRuleImpl::SetStyleSheet(nsIStyleSheet *aSheet)
|
||||
{
|
||||
// XXX We don't reference count this up reference. The style sheet
|
||||
// will tell us when it's going away or when we're detached from
|
||||
// it.
|
||||
mStyleSheet = aSheet;
|
||||
}
|
||||
|
||||
nscoord CalcLength(const nsCSSValue& aValue,
|
||||
const nsStyleFont* aFont,
|
||||
nsIPresContext* aPresContext)
|
||||
|
@ -1236,6 +1376,105 @@ CSSStyleRuleImpl::List(FILE* out, PRInt32 aIndent) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::GetType(nsString& aType)
|
||||
{
|
||||
// XXX Need to define the different types
|
||||
aType.SetString("simple");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::GetSelectorText(nsString& aSelectorText)
|
||||
{
|
||||
nsAutoString buffer;
|
||||
nsAutoString thisSelector;
|
||||
nsCSSSelector *selector = &mSelector;
|
||||
|
||||
// XXX Ugh...they're in reverse order from the source. Sorry
|
||||
// for the ugliness.
|
||||
aSelectorText.SetLength(0);
|
||||
while (nsnull != selector) {
|
||||
thisSelector.SetLength(0);
|
||||
if (nsnull != selector->mTag) {
|
||||
selector->mTag->ToString(buffer);
|
||||
thisSelector.Append(buffer);
|
||||
}
|
||||
if (nsnull != selector->mID) {
|
||||
selector->mID->ToString(buffer);
|
||||
thisSelector.Append("#");
|
||||
thisSelector.Append(buffer);
|
||||
}
|
||||
if (nsnull != selector->mClass) {
|
||||
selector->mClass->ToString(buffer);
|
||||
thisSelector.Append(".");
|
||||
thisSelector.Append(buffer);
|
||||
}
|
||||
if (nsnull != selector->mPseudoClass) {
|
||||
selector->mPseudoClass->ToString(buffer);
|
||||
thisSelector.Append(":");
|
||||
thisSelector.Append(buffer);
|
||||
}
|
||||
aSelectorText.Insert(thisSelector, 0, thisSelector.Length());
|
||||
selector = selector->mNext;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::SetSelectorText(const nsString& aSelectorText)
|
||||
{
|
||||
// XXX TBI
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
|
||||
{
|
||||
if (nsnull == mDOMDeclaration) {
|
||||
mDOMDeclaration = new DOMCSSDeclarationImpl(this);
|
||||
if (nsnull == mDOMDeclaration) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(mDOMDeclaration);
|
||||
}
|
||||
|
||||
*aStyle = mDOMDeclaration;
|
||||
NS_ADDREF(mDOMDeclaration);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
nsISupports *supports = (nsISupports *)(nsICSSStyleRule *)this;
|
||||
// XXX Parent should be the style sheet
|
||||
// XXX Should be done through factory
|
||||
res = NS_NewScriptCSSStyleRuleSimple(aContext,
|
||||
supports,
|
||||
(nsISupports *)global,
|
||||
(void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
NS_RELEASE(global);
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_HTML nsresult
|
||||
NS_NewCSSStyleRule(nsICSSStyleRule** aInstancePtrResult, const nsCSSSelector& aSelector)
|
||||
{
|
||||
|
|
|
@ -32,6 +32,13 @@
|
|||
#include "nsString.h"
|
||||
#include "nsIPtr.h"
|
||||
#include "nsHTMLIIDs.h"
|
||||
#include "nsIDOMStyleSheetCollection.h"
|
||||
#include "nsIDOMCSSStyleSheet.h"
|
||||
#include "nsIDOMCSSStyleRule.h"
|
||||
#include "nsIDOMCSSStyleRuleCollection.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsICSSParser.h"
|
||||
|
||||
//#define DEBUG_REFS
|
||||
//#define DEBUG_RULES
|
||||
|
@ -39,6 +46,12 @@
|
|||
static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID);
|
||||
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
|
||||
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
|
||||
static NS_DEFINE_IID(kIDOMStyleSheetIID, NS_IDOMSTYLESHEET_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleSheetIID, NS_IDOMCSSSTYLESHEET_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleRuleIID, NS_IDOMCSSSTYLERULE_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleRuleCollectionIID, NS_IDOMCSSSTYLERULECOLLECTION_IID);
|
||||
static NS_DEFINE_IID(kIDOMStyleSheetCollectionIID, NS_IDOMSTYLESHEETCOLLECTION_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
|
||||
NS_DEF_PTR(nsIHTMLContent);
|
||||
NS_DEF_PTR(nsIContent);
|
||||
|
@ -129,6 +142,7 @@ public:
|
|||
RuleEnumFunc aFunc, void* aData);
|
||||
void EnumerateTagRules(nsIAtom* aTag,
|
||||
RuleEnumFunc aFunc, void* aData);
|
||||
|
||||
protected:
|
||||
void AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyleRule* aRule);
|
||||
|
||||
|
@ -171,6 +185,7 @@ void RuleHash::AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyl
|
|||
value = value->mNext;
|
||||
}
|
||||
value->mNext = new RuleValue(aRule, mRuleCount++);
|
||||
value = value->mNext;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,11 +257,279 @@ void RuleHash::EnumerateTagRules(nsIAtom* aTag, RuleEnumFunc aFunc, void* aData)
|
|||
}
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
// Style Rule Collection for the DOM
|
||||
//
|
||||
class CSSStyleRuleCollectionImpl : public nsIDOMCSSStyleRuleCollection,
|
||||
public nsIScriptObjectOwner
|
||||
{
|
||||
public:
|
||||
CSSStyleRuleCollectionImpl(nsICSSStyleSheet *aStyleSheet);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMCSSStyleRuleCollection interface
|
||||
NS_IMETHOD GetLength(PRUint32* aLength);
|
||||
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMCSSStyleRule** aReturn);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
void DropReference() { mStyleSheet = nsnull; }
|
||||
|
||||
protected:
|
||||
virtual ~CSSStyleRuleCollectionImpl();
|
||||
|
||||
nsICSSStyleSheet* mStyleSheet;
|
||||
void* mScriptObject;
|
||||
};
|
||||
|
||||
CSSStyleRuleCollectionImpl::CSSStyleRuleCollectionImpl(nsICSSStyleSheet *aStyleSheet)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
// Not reference counted to avoid circular references.
|
||||
// The style sheet will tell us when its going away.
|
||||
mStyleSheet = aStyleSheet;
|
||||
mScriptObject = nsnull;
|
||||
}
|
||||
|
||||
CSSStyleRuleCollectionImpl::~CSSStyleRuleCollectionImpl()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(CSSStyleRuleCollectionImpl);
|
||||
NS_IMPL_RELEASE(CSSStyleRuleCollectionImpl);
|
||||
|
||||
nsresult
|
||||
CSSStyleRuleCollectionImpl::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
||||
{
|
||||
if (NULL == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kIDOMCSSStyleRuleCollectionIID)) {
|
||||
nsIDOMCSSStyleRuleCollection *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
nsIScriptObjectOwner *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
nsIDOMCSSStyleRuleCollection *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleCollectionImpl::GetLength(PRUint32* aLength)
|
||||
{
|
||||
if (nsnull != mStyleSheet) {
|
||||
*aLength = mStyleSheet->StyleRuleCount();
|
||||
}
|
||||
else {
|
||||
*aLength = 0;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleCollectionImpl::Item(PRUint32 aIndex, nsIDOMCSSStyleRule** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
*aReturn = nsnull;
|
||||
if (nsnull != mStyleSheet) {
|
||||
nsICSSStyleRule *rule;
|
||||
|
||||
result = mStyleSheet->GetStyleRuleAt(aIndex, rule);
|
||||
if (NS_OK == result) {
|
||||
result = rule->QueryInterface(kIDOMCSSStyleRuleIID, (void **)aReturn);
|
||||
}
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleCollectionImpl::GetScriptObject(nsIScriptContext *aContext,
|
||||
void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
nsISupports *supports = (nsISupports *)(nsIDOMCSSStyleRuleCollection *)this;
|
||||
|
||||
// XXX Should be done through factory
|
||||
res = NS_NewScriptCSSStyleRuleCollection(aContext,
|
||||
supports,
|
||||
(nsISupports *)mStyleSheet,
|
||||
(void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleCollectionImpl::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
// Imports Collection for the DOM
|
||||
//
|
||||
class CSSImportsCollectionImpl : public nsIDOMStyleSheetCollection,
|
||||
public nsIScriptObjectOwner
|
||||
{
|
||||
public:
|
||||
CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMCSSStyleSheetCollection interface
|
||||
NS_IMETHOD GetLength(PRUint32* aLength);
|
||||
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
void DropReference() { mStyleSheet = nsnull; }
|
||||
|
||||
protected:
|
||||
virtual ~CSSImportsCollectionImpl();
|
||||
|
||||
nsICSSStyleSheet* mStyleSheet;
|
||||
void* mScriptObject;
|
||||
};
|
||||
|
||||
CSSImportsCollectionImpl::CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
// Not reference counted to avoid circular references.
|
||||
// The style sheet will tell us when its going away.
|
||||
mStyleSheet = aStyleSheet;
|
||||
mScriptObject = nsnull;
|
||||
}
|
||||
|
||||
CSSImportsCollectionImpl::~CSSImportsCollectionImpl()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(CSSImportsCollectionImpl);
|
||||
NS_IMPL_RELEASE(CSSImportsCollectionImpl);
|
||||
|
||||
nsresult
|
||||
CSSImportsCollectionImpl::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
||||
{
|
||||
if (NULL == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kIDOMStyleSheetCollectionIID)) {
|
||||
nsIDOMStyleSheetCollection *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
nsIScriptObjectOwner *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
nsIDOMStyleSheetCollection *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSImportsCollectionImpl::GetLength(PRUint32* aLength)
|
||||
{
|
||||
if (nsnull != mStyleSheet) {
|
||||
*aLength = mStyleSheet->StyleSheetCount();
|
||||
}
|
||||
else {
|
||||
*aLength = 0;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSImportsCollectionImpl::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
*aReturn = nsnull;
|
||||
if (nsnull != mStyleSheet) {
|
||||
nsICSSStyleSheet *sheet;
|
||||
|
||||
result = mStyleSheet->GetStyleSheetAt(aIndex, sheet);
|
||||
if (NS_OK == result) {
|
||||
result = sheet->QueryInterface(kIDOMStyleSheetIID, (void **)aReturn);
|
||||
}
|
||||
NS_RELEASE(sheet);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSImportsCollectionImpl::GetScriptObject(nsIScriptContext *aContext,
|
||||
void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
nsISupports *supports = (nsISupports *)(nsIDOMStyleSheetCollection *)this;
|
||||
|
||||
// XXX Should be done through factory
|
||||
res = NS_NewScriptStyleSheetCollection(aContext,
|
||||
supports,
|
||||
(nsISupports *)mStyleSheet,
|
||||
(void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSImportsCollectionImpl::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
// CSS Style Sheet
|
||||
//
|
||||
class CSSStyleSheetImpl : public nsICSSStyleSheet {
|
||||
class CSSStyleSheetImpl : public nsICSSStyleSheet,
|
||||
public nsIDOMCSSStyleSheet,
|
||||
public nsIScriptObjectOwner {
|
||||
public:
|
||||
void* operator new(size_t size);
|
||||
void* operator new(size_t size, nsIArena* aArena);
|
||||
|
@ -281,8 +564,32 @@ public:
|
|||
virtual PRInt32 StyleRuleCount(void);
|
||||
virtual nsresult GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule);
|
||||
|
||||
virtual PRInt32 StyleSheetCount();
|
||||
virtual nsresult GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet);
|
||||
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
// nsIDOMStyleSheet interface
|
||||
NS_IMETHOD GetDisabled(PRBool* aDisabled);
|
||||
NS_IMETHOD SetDisabled(PRBool aDisabled);
|
||||
NS_IMETHOD GetReadOnly(PRBool* aReadOnly);
|
||||
|
||||
// nsIDOMCSSStyleSheet interface
|
||||
NS_IMETHOD GetOwningElement(nsIDOMHTMLElement** aOwningElement);
|
||||
NS_IMETHOD GetParentStyleSheet(nsIDOMCSSStyleSheet** aParentStyleSheet);
|
||||
NS_IMETHOD GetHref(nsString& aHref);
|
||||
NS_IMETHOD GetTitle(nsString& aTitle);
|
||||
NS_IMETHOD GetImports(nsIDOMStyleSheetCollection** aImports);
|
||||
NS_IMETHOD GetRules(nsIDOMCSSStyleRuleCollection** aRules);
|
||||
NS_IMETHOD AddRule(const nsString& aSelector, const nsString& aDeclaration, PRUint32 aIndex, PRUint32* aReturn);
|
||||
NS_IMETHOD AddImport(const nsString& aUrl, PRUint32 aIndex, PRUint32* aReturn);
|
||||
NS_IMETHOD RemoveRule(PRUint32 aIndex);
|
||||
NS_IMETHOD RemoveImport(PRUint32 aIndex);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
private:
|
||||
// These are not supported and are not implemented!
|
||||
CSSStyleSheetImpl(const CSSStyleSheetImpl& aCopy);
|
||||
|
@ -303,7 +610,11 @@ protected:
|
|||
nsISupportsArrayPtr mOrderedRules;
|
||||
nsISupportsArrayPtr mWeightedRules;
|
||||
nsICSSStyleSheetPtr mNext;
|
||||
nsICSSStyleSheet* mParent;
|
||||
RuleHash* mRuleHash;
|
||||
CSSStyleRuleCollectionImpl* mRuleCollection;
|
||||
CSSImportsCollectionImpl* mImportsCollection;
|
||||
void * mScriptObject;
|
||||
};
|
||||
|
||||
|
||||
|
@ -354,18 +665,49 @@ CSSStyleSheetImpl::CSSStyleSheetImpl(nsIURL* aURL)
|
|||
{
|
||||
NS_INIT_REFCNT();
|
||||
mURL.SetAddRef(aURL);
|
||||
mParent = nsnull;
|
||||
mRuleCollection = nsnull;
|
||||
mImportsCollection = nsnull;
|
||||
mScriptObject = nsnull;
|
||||
#ifdef DEBUG_REFS
|
||||
++gInstanceCount;
|
||||
fprintf(stdout, "%d + CSSStyleSheet size: %d\n", gInstanceCount, sizeof(*this));
|
||||
#endif
|
||||
}
|
||||
|
||||
static PRBool DropStyleSheetReference(nsISupports* aElement, void *aData)
|
||||
{
|
||||
nsICSSStyleRule *rule = (nsICSSStyleRule *)aElement;
|
||||
|
||||
if (nsnull != rule) {
|
||||
rule->SetStyleSheet(nsnull);
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
CSSStyleSheetImpl::~CSSStyleSheetImpl()
|
||||
{
|
||||
#ifdef DEBUG_REFS
|
||||
--gInstanceCount;
|
||||
fprintf(stdout, "%d - CSSStyleSheet\n", gInstanceCount);
|
||||
#endif
|
||||
if (mFirstChild.IsNotNull()) {
|
||||
nsICSSStyleSheet* child = mFirstChild;
|
||||
while (nsnull != child) {
|
||||
((CSSStyleSheetImpl *)child)->mParent = nsnull;
|
||||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
}
|
||||
}
|
||||
if (nsnull != mRuleCollection) {
|
||||
mRuleCollection->DropReference();
|
||||
NS_RELEASE(mRuleCollection);
|
||||
}
|
||||
if (nsnull != mImportsCollection) {
|
||||
mImportsCollection->DropReference();
|
||||
NS_RELEASE(mImportsCollection);
|
||||
}
|
||||
mOrderedRules->EnumerateForwards(DropStyleSheetReference, nsnull);
|
||||
ClearHash();
|
||||
}
|
||||
|
||||
|
@ -390,8 +732,28 @@ nsresult CSSStyleSheetImpl::QueryInterface(const nsIID& aIID,
|
|||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMStyleSheetIID)) {
|
||||
nsIDOMStyleSheet *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMCSSStyleSheetIID)) {
|
||||
nsIDOMCSSStyleSheet *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
nsIScriptObjectOwner *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsISupports*)this);
|
||||
nsICSSStyleSheet *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -750,6 +1112,10 @@ void CSSStyleSheetImpl::AppendStyleSheet(nsICSSStyleSheet* aSheet)
|
|||
}
|
||||
((CSSStyleSheetImpl*)child)->mNext.SetAddRef(aSheet);
|
||||
}
|
||||
|
||||
// This is not reference counted. Our parent tells us when
|
||||
// it's going away.
|
||||
((CSSStyleSheetImpl*)aSheet)->mParent = this;
|
||||
}
|
||||
|
||||
void CSSStyleSheetImpl::PrependStyleRule(nsICSSStyleRule* aRule)
|
||||
|
@ -778,6 +1144,7 @@ void CSSStyleSheetImpl::PrependStyleRule(nsICSSStyleRule* aRule)
|
|||
}
|
||||
mWeightedRules->InsertElementAt(aRule, index + 1);
|
||||
mOrderedRules->InsertElementAt(aRule, 0);
|
||||
aRule->SetStyleSheet(this);
|
||||
}
|
||||
|
||||
void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
|
||||
|
@ -807,6 +1174,7 @@ void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
|
|||
}
|
||||
mWeightedRules->InsertElementAt(aRule, index);
|
||||
mOrderedRules->AppendElement(aRule);
|
||||
aRule->SetStyleSheet(this);
|
||||
}
|
||||
|
||||
PRInt32 CSSStyleSheetImpl::StyleRuleCount(void)
|
||||
|
@ -833,6 +1201,43 @@ nsresult CSSStyleSheetImpl::GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRu
|
|||
return result;
|
||||
}
|
||||
|
||||
PRInt32 CSSStyleSheetImpl::StyleSheetCount()
|
||||
{
|
||||
// XXX Far from an ideal way to do this, but the hope is that
|
||||
// it won't be done too often. If it is, we might want to
|
||||
// consider storing the children in an array.
|
||||
PRInt32 count = 0;
|
||||
if (mFirstChild.IsNotNull()) {
|
||||
nsICSSStyleSheet* child = mFirstChild;
|
||||
while (nsnull != child) {
|
||||
count++;
|
||||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
nsresult CSSStyleSheetImpl::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet)
|
||||
{
|
||||
// XXX Ughh...an O(n^2) method for doing iteration. Again, we hope
|
||||
// that this isn't done too often. If it is, we need to change the
|
||||
// underlying storage mechanism
|
||||
aSheet = nsnull;
|
||||
if (mFirstChild.IsNotNull()) {
|
||||
nsICSSStyleSheet* child = mFirstChild;
|
||||
while ((nsnull != child) && (0 != aIndex)) {
|
||||
--aIndex;
|
||||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
}
|
||||
|
||||
aSheet = child;
|
||||
NS_IF_ADDREF(child);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void CSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
nsAutoString buffer;
|
||||
|
@ -886,6 +1291,224 @@ void CSSStyleSheetImpl::BuildHash(void)
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetDisabled(PRBool* aDisabled)
|
||||
{
|
||||
// XXX TBI
|
||||
*aDisabled = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::SetDisabled(PRBool aDisabled)
|
||||
{
|
||||
// XXX TBI
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetReadOnly(PRBool* aReadOnly)
|
||||
{
|
||||
// XXX TBI
|
||||
*aReadOnly = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetOwningElement(nsIDOMHTMLElement** aOwningElement)
|
||||
{
|
||||
// XXX TBI
|
||||
*aOwningElement = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aParentStyleSheet)
|
||||
{
|
||||
if (nsnull != mParent) {
|
||||
return mParent->QueryInterface(kIDOMCSSStyleSheetIID, (void **)aParentStyleSheet);
|
||||
}
|
||||
else {
|
||||
*aParentStyleSheet = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetHref(nsString& aHref)
|
||||
{
|
||||
if (mURL.IsNotNull()) {
|
||||
mURL->ToString(aHref);
|
||||
}
|
||||
else {
|
||||
aHref.SetLength(0);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetTitle(nsString& aTitle)
|
||||
{
|
||||
// XX TBI
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetImports(nsIDOMStyleSheetCollection** aImports)
|
||||
{
|
||||
if (nsnull == mImportsCollection) {
|
||||
mImportsCollection = new CSSImportsCollectionImpl(this);
|
||||
if (nsnull == mImportsCollection) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(mImportsCollection);
|
||||
}
|
||||
|
||||
*aImports = mImportsCollection;
|
||||
NS_ADDREF(mImportsCollection);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetRules(nsIDOMCSSStyleRuleCollection** aRules)
|
||||
{
|
||||
if (nsnull == mRuleCollection) {
|
||||
mRuleCollection = new CSSStyleRuleCollectionImpl(this);
|
||||
if (nsnull == mRuleCollection) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(mRuleCollection);
|
||||
}
|
||||
|
||||
*aRules = mRuleCollection;
|
||||
NS_ADDREF(mRuleCollection);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::AddRule(const nsString& aSelector,
|
||||
const nsString& aDeclaration,
|
||||
PRUint32 aIndex,
|
||||
PRUint32* aReturn)
|
||||
{
|
||||
nsICSSParser* css;
|
||||
nsresult result = NS_NewCSSParser(&css);
|
||||
if (NS_OK == result) {
|
||||
nsAutoString str;
|
||||
str.SetString(aSelector);
|
||||
// XXX Can we assume that the braces aren't there?
|
||||
str.Append(" { ");
|
||||
str.Append(aDeclaration);
|
||||
str.Append(" } ");
|
||||
|
||||
nsIUnicharInputStream* input = nsnull;
|
||||
result = NS_NewStringUnicharInputStream(&input, &str);
|
||||
if (NS_OK == result) {
|
||||
nsIStyleSheet *tmp;
|
||||
css->SetStyleSheet(this);
|
||||
// XXX Currently, the parser will append the rule to the
|
||||
// style sheet. We shouldn't ignore the index.
|
||||
result = css->Parse(input, mURL, tmp);
|
||||
NS_ASSERTION(tmp = this, "parser incorrectly created a new stylesheet");
|
||||
NS_RELEASE(input);
|
||||
*aReturn = mOrderedRules->Count();
|
||||
}
|
||||
|
||||
NS_RELEASE(css);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::AddImport(const nsString& aUrl, PRUint32 aIndex, PRUint32* aReturn)
|
||||
{
|
||||
nsICSSParser* css;
|
||||
nsresult result = NS_NewCSSParser(&css);
|
||||
if (NS_OK == result) {
|
||||
css->SetStyleSheet(this);
|
||||
result = css->ProcessImport(aUrl);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::RemoveRule(PRUint32 aIndex)
|
||||
{
|
||||
nsICSSStyleRule *rule;
|
||||
|
||||
rule = (nsICSSStyleRule *)mOrderedRules->ElementAt(aIndex);
|
||||
if (nsnull != rule) {
|
||||
mOrderedRules->RemoveElementAt(aIndex);
|
||||
mWeightedRules->RemoveElement(rule);
|
||||
rule->SetStyleSheet(nsnull);
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::RemoveImport(PRUint32 aIndex)
|
||||
{
|
||||
if (mFirstChild.IsNotNull()) {
|
||||
nsICSSStyleSheet* prev = nsnull;
|
||||
nsICSSStyleSheet* child = mFirstChild;
|
||||
while ((nsnull != child) && (0 != aIndex)) {
|
||||
prev = child;
|
||||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
--aIndex;
|
||||
}
|
||||
|
||||
if ((nsnull != child) && (0 == aIndex)) {
|
||||
// Hold on to the child while we clean it up
|
||||
NS_ADDREF(child);
|
||||
if (nsnull == prev) {
|
||||
mFirstChild.SetAddRef(((CSSStyleSheetImpl*)child)->mNext);
|
||||
}
|
||||
else {
|
||||
((CSSStyleSheetImpl*)prev)->mNext.SetAddRef(((CSSStyleSheetImpl*)child)->mNext);
|
||||
}
|
||||
((CSSStyleSheetImpl*)child)->mNext.SetAddRef(nsnull);
|
||||
((CSSStyleSheetImpl*)child)->mParent = nsnull;
|
||||
NS_RELEASE(child);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
nsISupports *supports = (nsISupports *)(nsICSSStyleSheet *)this;
|
||||
// XXX Should be done through factory
|
||||
res = NS_NewScriptCSSStyleSheet(aContext,
|
||||
supports,
|
||||
(nsISupports *)global,
|
||||
(void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
NS_RELEASE(global);
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_HTML nsresult
|
||||
NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult, nsIURL* aURL)
|
||||
{
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,55 @@
|
|||
/* -*- 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 "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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
#ifndef nsDOMCSSDeclaration_h___
|
||||
#define nsDOMCSSSDeclaration_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIDOMCSSStyleDeclaration.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
|
||||
class nsICSSDeclaration;
|
||||
|
||||
class nsDOMCSSDeclaration : public nsIDOMCSSStyleDeclaration,
|
||||
public nsIScriptObjectOwner
|
||||
{
|
||||
public:
|
||||
nsDOMCSSDeclaration();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_IDOMCSSSTYLEDECLARATION
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
virtual void DropReference() = 0;
|
||||
virtual nsresult GetCSSDeclaration(nsICSSDeclaration **aDecl,
|
||||
PRBool aAllocate) = 0;
|
||||
virtual nsresult StylePropertyChanged(const nsString& aPropertyName,
|
||||
PRInt32 aHint) = 0;
|
||||
virtual nsresult GetParent(nsISupports **aParent) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~nsDOMCSSDeclaration();
|
||||
|
||||
void *mScriptObject;
|
||||
};
|
||||
|
||||
#endif // nsDOMCSSDeclaration_h___
|
|
@ -25,7 +25,7 @@ class nsIAtom;
|
|||
class nsIArena;
|
||||
class nsString;
|
||||
class nsICSSDeclaration;
|
||||
|
||||
class nsIStyleSheet;
|
||||
|
||||
struct nsCSSSelector {
|
||||
public:
|
||||
|
@ -65,6 +65,9 @@ public:
|
|||
virtual void SetWeight(PRInt32 aWeight) = 0;
|
||||
|
||||
virtual nsIStyleRule* GetImportantRule(void) = 0;
|
||||
|
||||
virtual nsIStyleSheet* GetStyleSheet(void) = 0;
|
||||
virtual void SetStyleSheet(nsIStyleSheet *aSheet) = 0;
|
||||
};
|
||||
|
||||
extern NS_HTML nsresult
|
||||
|
|
|
@ -39,6 +39,10 @@ public:
|
|||
|
||||
virtual PRInt32 StyleRuleCount(void) = 0;
|
||||
virtual nsresult GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule) = 0;
|
||||
|
||||
virtual PRInt32 StyleSheetCount() = 0;
|
||||
virtual nsresult GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) = 0;
|
||||
|
||||
};
|
||||
|
||||
extern NS_HTML nsresult
|
||||
|
|
|
@ -197,7 +197,7 @@ public:
|
|||
NS_IMETHOD SetStyleSheet(nsIStyleSheet* aSheet);
|
||||
|
||||
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
|
||||
nsIURL* aInputURL,
|
||||
nsIURL* aInputURL,
|
||||
nsIStyleSheet*& aResult);
|
||||
|
||||
NS_IMETHOD ParseDeclarations(const nsString& aDeclaration,
|
||||
|
@ -209,6 +209,8 @@ public:
|
|||
nsICSSDeclaration* aDeclaration,
|
||||
PRInt32* aHint);
|
||||
|
||||
NS_IMETHOD ProcessImport(const nsString& aURLSpec);
|
||||
|
||||
protected:
|
||||
PRBool GetToken(PRInt32* aErrorCode, PRBool aSkipWS);
|
||||
void UngetToken();
|
||||
|
@ -281,8 +283,6 @@ protected:
|
|||
PRBool TranslateLength(nsICSSDeclaration* aDeclaration, const char* aName,
|
||||
float aNumber, const nsString& aDimension);
|
||||
|
||||
void ProcessImport(const nsString& aURLSpec);
|
||||
|
||||
// Current token. The value is valid after calling GetToken
|
||||
nsCSSToken mToken;
|
||||
|
||||
|
@ -364,7 +364,7 @@ CSSParserImpl::SetStyleSheet(nsIStyleSheet* aSheet)
|
|||
|
||||
NS_METHOD
|
||||
CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
|
||||
nsIURL* aInputURL,
|
||||
nsIURL* aInputURL,
|
||||
nsIStyleSheet*& aResult)
|
||||
{
|
||||
if (nsnull == mSheet) {
|
||||
|
@ -598,7 +598,7 @@ PRBool CSSParserImpl::ParseImportRule(PRInt32* aErrorCode)
|
|||
return PR_TRUE;
|
||||
}
|
||||
|
||||
void CSSParserImpl::ProcessImport(const nsString& aURLSpec)
|
||||
NS_IMETHODIMP CSSParserImpl::ProcessImport(const nsString& aURLSpec)
|
||||
{
|
||||
// XXX probably need a way to encode unicode junk for the part of
|
||||
// the url that follows a "?"
|
||||
|
@ -609,7 +609,7 @@ void CSSParserImpl::ProcessImport(const nsString& aURLSpec)
|
|||
if (NS_OK != rv) {
|
||||
// import url is bad
|
||||
// XXX log this somewhere for easier web page debugging
|
||||
return;
|
||||
return rv;
|
||||
}
|
||||
|
||||
if (PR_FALSE == mSheet->ContainsStyleSheet(url)) { // don't allow circular references
|
||||
|
@ -656,6 +656,8 @@ void CSSParserImpl::ProcessImport(const nsString& aURLSpec)
|
|||
}
|
||||
}
|
||||
NS_RELEASE(url);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
void CSSParserImpl::SkipUntil(PRInt32* aErrorCode, PRUnichar aStopSymbol)
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
*/
|
||||
#include "nsICSSStyleRule.h"
|
||||
#include "nsICSSDeclaration.h"
|
||||
#include "nsIStyleSheet.h"
|
||||
#include "nsIStyleContext.h"
|
||||
#include "nsIPresContext.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
|
@ -29,12 +30,25 @@
|
|||
#include "nsUnitConversion.h"
|
||||
#include "nsStyleUtil.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
#include "nsIDOMCSSStyleSheet.h"
|
||||
#include "nsIDOMCSSStyleRule.h"
|
||||
#include "nsIDOMCSSStyleRuleSimple.h"
|
||||
#include "nsIDOMCSSStyleDeclaration.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsDOMCSSDeclaration.h"
|
||||
|
||||
//#define DEBUG_REFS
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
|
||||
static NS_DEFINE_IID(kICSSDeclarationIID, NS_ICSS_DECLARATION_IID);
|
||||
static NS_DEFINE_IID(kICSSStyleRuleIID, NS_ICSS_STYLE_RULE_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleSheetIID, NS_IDOMCSSSTYLESHEET_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleRuleIID, NS_IDOMCSSSTYLERULE_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleRuleSimpleIID, NS_IDOMCSSSTYLERULESIMPLE_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleDeclarationIID, NS_IDOMCSSSTYLEDECLARATION_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
|
||||
static NS_DEFINE_IID(kCSSFontSID, NS_CSS_FONT_SID);
|
||||
static NS_DEFINE_IID(kCSSColorSID, NS_CSS_COLOR_SID);
|
||||
|
@ -231,10 +245,79 @@ CSSImportantRule::List(FILE* out, PRInt32 aIndent) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
// -- nsDOMStyleRuleDeclaration -------------------------------
|
||||
|
||||
class DOMCSSDeclarationImpl : public nsDOMCSSDeclaration
|
||||
{
|
||||
public:
|
||||
DOMCSSDeclarationImpl(nsICSSStyleRule *aRule);
|
||||
~DOMCSSDeclarationImpl();
|
||||
|
||||
virtual void DropReference();
|
||||
virtual nsresult GetCSSDeclaration(nsICSSDeclaration **aDecl,
|
||||
PRBool aAllocate);
|
||||
virtual nsresult StylePropertyChanged(const nsString& aPropertyName,
|
||||
PRInt32 aHint);
|
||||
virtual nsresult GetParent(nsISupports **aParent);
|
||||
|
||||
protected:
|
||||
nsICSSStyleRule *mRule;
|
||||
};
|
||||
|
||||
DOMCSSDeclarationImpl::DOMCSSDeclarationImpl(nsICSSStyleRule *aRule)
|
||||
{
|
||||
// This reference is not reference-counted. The rule
|
||||
// object tells us when its about to go away.
|
||||
mRule = aRule;
|
||||
}
|
||||
|
||||
DOMCSSDeclarationImpl::~DOMCSSDeclarationImpl()
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
DOMCSSDeclarationImpl::DropReference()
|
||||
{
|
||||
mRule = nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DOMCSSDeclarationImpl::GetCSSDeclaration(nsICSSDeclaration **aDecl,
|
||||
PRBool aAllocate)
|
||||
{
|
||||
if (nsnull != mRule) {
|
||||
*aDecl = mRule->GetDeclaration();
|
||||
}
|
||||
else {
|
||||
*aDecl = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DOMCSSDeclarationImpl::StylePropertyChanged(const nsString& aPropertyName,
|
||||
PRInt32 aHint)
|
||||
{
|
||||
// XXX TBI
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
DOMCSSDeclarationImpl::GetParent(nsISupports **aParent)
|
||||
{
|
||||
if (nsnull != mRule) {
|
||||
return mRule->QueryInterface(kISupportsIID, (void **)aParent);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// -- nsCSSStyleRule -------------------------------
|
||||
|
||||
class CSSStyleRuleImpl : public nsICSSStyleRule {
|
||||
class CSSStyleRuleImpl : public nsICSSStyleRule,
|
||||
public nsIDOMCSSStyleRuleSimple,
|
||||
public nsIScriptObjectOwner {
|
||||
public:
|
||||
void* operator new(size_t size);
|
||||
void* operator new(size_t size, nsIArena* aArena);
|
||||
|
@ -263,10 +346,25 @@ public:
|
|||
|
||||
virtual nsIStyleRule* GetImportantRule(void);
|
||||
|
||||
virtual nsIStyleSheet* GetStyleSheet(void);
|
||||
virtual void SetStyleSheet(nsIStyleSheet *aSheet);
|
||||
|
||||
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
|
||||
|
||||
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
// nsIDOMCSSStyleRule interface
|
||||
NS_IMETHOD GetType(nsString& aType);
|
||||
|
||||
// nsIDOMCSSStyleRuleSimple interface
|
||||
NS_IMETHOD GetSelectorText(nsString& aSelectorText);
|
||||
NS_IMETHOD SetSelectorText(const nsString& aSelectorText);
|
||||
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
private:
|
||||
// These are not supported and are not implemented!
|
||||
CSSStyleRuleImpl(const CSSStyleRuleImpl& aCopy);
|
||||
|
@ -283,6 +381,9 @@ protected:
|
|||
nsICSSDeclaration* mDeclaration;
|
||||
PRInt32 mWeight;
|
||||
CSSImportantRule* mImportantRule;
|
||||
nsIStyleSheet* mStyleSheet;
|
||||
DOMCSSDeclarationImpl *mDOMDeclaration;
|
||||
void* mScriptObject;
|
||||
#ifdef DEBUG_REFS
|
||||
PRInt32 mInstance;
|
||||
#endif
|
||||
|
@ -334,6 +435,8 @@ CSSStyleRuleImpl::CSSStyleRuleImpl(const nsCSSSelector& aSelector)
|
|||
mWeight(0), mImportantRule(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mDOMDeclaration = nsnull;
|
||||
mScriptObject = nsnull;
|
||||
#ifdef DEBUG_REFS
|
||||
mInstance = gInstanceCount++;
|
||||
fprintf(stdout, "%d of %d + CSSStyleRule\n", mInstance, gInstanceCount);
|
||||
|
@ -351,6 +454,9 @@ CSSStyleRuleImpl::~CSSStyleRuleImpl()
|
|||
}
|
||||
NS_IF_RELEASE(mDeclaration);
|
||||
NS_IF_RELEASE(mImportantRule);
|
||||
if (nsnull != mDOMDeclaration) {
|
||||
mDOMDeclaration->DropReference();
|
||||
}
|
||||
#ifdef DEBUG_REFS
|
||||
--gInstanceCount;
|
||||
fprintf(stdout, "%d of %d - CSSStyleRule\n", mInstance, gInstanceCount);
|
||||
|
@ -389,7 +495,6 @@ nsresult CSSStyleRuleImpl::QueryInterface(const nsIID& aIID,
|
|||
if (nsnull == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kICSSStyleRuleIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsICSSStyleRule*)this);
|
||||
NS_ADDREF_THIS();
|
||||
|
@ -400,8 +505,28 @@ nsresult CSSStyleRuleImpl::QueryInterface(const nsIID& aIID,
|
|||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMCSSStyleRuleIID)) {
|
||||
nsIDOMCSSStyleRule *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMCSSStyleRuleSimpleIID)) {
|
||||
nsIDOMCSSStyleRuleSimple *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
nsIScriptObjectOwner *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsISupports*)this);
|
||||
nsICSSStyleRule *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -543,6 +668,21 @@ nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
|
|||
return mImportantRule;
|
||||
}
|
||||
|
||||
nsIStyleSheet* CSSStyleRuleImpl::GetStyleSheet(void)
|
||||
{
|
||||
NS_IF_ADDREF(mStyleSheet);
|
||||
|
||||
return mStyleSheet;
|
||||
}
|
||||
|
||||
void CSSStyleRuleImpl::SetStyleSheet(nsIStyleSheet *aSheet)
|
||||
{
|
||||
// XXX We don't reference count this up reference. The style sheet
|
||||
// will tell us when it's going away or when we're detached from
|
||||
// it.
|
||||
mStyleSheet = aSheet;
|
||||
}
|
||||
|
||||
nscoord CalcLength(const nsCSSValue& aValue,
|
||||
const nsStyleFont* aFont,
|
||||
nsIPresContext* aPresContext)
|
||||
|
@ -1236,6 +1376,105 @@ CSSStyleRuleImpl::List(FILE* out, PRInt32 aIndent) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::GetType(nsString& aType)
|
||||
{
|
||||
// XXX Need to define the different types
|
||||
aType.SetString("simple");
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::GetSelectorText(nsString& aSelectorText)
|
||||
{
|
||||
nsAutoString buffer;
|
||||
nsAutoString thisSelector;
|
||||
nsCSSSelector *selector = &mSelector;
|
||||
|
||||
// XXX Ugh...they're in reverse order from the source. Sorry
|
||||
// for the ugliness.
|
||||
aSelectorText.SetLength(0);
|
||||
while (nsnull != selector) {
|
||||
thisSelector.SetLength(0);
|
||||
if (nsnull != selector->mTag) {
|
||||
selector->mTag->ToString(buffer);
|
||||
thisSelector.Append(buffer);
|
||||
}
|
||||
if (nsnull != selector->mID) {
|
||||
selector->mID->ToString(buffer);
|
||||
thisSelector.Append("#");
|
||||
thisSelector.Append(buffer);
|
||||
}
|
||||
if (nsnull != selector->mClass) {
|
||||
selector->mClass->ToString(buffer);
|
||||
thisSelector.Append(".");
|
||||
thisSelector.Append(buffer);
|
||||
}
|
||||
if (nsnull != selector->mPseudoClass) {
|
||||
selector->mPseudoClass->ToString(buffer);
|
||||
thisSelector.Append(":");
|
||||
thisSelector.Append(buffer);
|
||||
}
|
||||
aSelectorText.Insert(thisSelector, 0, thisSelector.Length());
|
||||
selector = selector->mNext;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::SetSelectorText(const nsString& aSelectorText)
|
||||
{
|
||||
// XXX TBI
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
|
||||
{
|
||||
if (nsnull == mDOMDeclaration) {
|
||||
mDOMDeclaration = new DOMCSSDeclarationImpl(this);
|
||||
if (nsnull == mDOMDeclaration) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(mDOMDeclaration);
|
||||
}
|
||||
|
||||
*aStyle = mDOMDeclaration;
|
||||
NS_ADDREF(mDOMDeclaration);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
nsISupports *supports = (nsISupports *)(nsICSSStyleRule *)this;
|
||||
// XXX Parent should be the style sheet
|
||||
// XXX Should be done through factory
|
||||
res = NS_NewScriptCSSStyleRuleSimple(aContext,
|
||||
supports,
|
||||
(nsISupports *)global,
|
||||
(void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
NS_RELEASE(global);
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleImpl::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_HTML nsresult
|
||||
NS_NewCSSStyleRule(nsICSSStyleRule** aInstancePtrResult, const nsCSSSelector& aSelector)
|
||||
{
|
||||
|
|
|
@ -32,6 +32,13 @@
|
|||
#include "nsString.h"
|
||||
#include "nsIPtr.h"
|
||||
#include "nsHTMLIIDs.h"
|
||||
#include "nsIDOMStyleSheetCollection.h"
|
||||
#include "nsIDOMCSSStyleSheet.h"
|
||||
#include "nsIDOMCSSStyleRule.h"
|
||||
#include "nsIDOMCSSStyleRuleCollection.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsICSSParser.h"
|
||||
|
||||
//#define DEBUG_REFS
|
||||
//#define DEBUG_RULES
|
||||
|
@ -39,6 +46,12 @@
|
|||
static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID);
|
||||
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
|
||||
static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
|
||||
static NS_DEFINE_IID(kIDOMStyleSheetIID, NS_IDOMSTYLESHEET_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleSheetIID, NS_IDOMCSSSTYLESHEET_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleRuleIID, NS_IDOMCSSSTYLERULE_IID);
|
||||
static NS_DEFINE_IID(kIDOMCSSStyleRuleCollectionIID, NS_IDOMCSSSTYLERULECOLLECTION_IID);
|
||||
static NS_DEFINE_IID(kIDOMStyleSheetCollectionIID, NS_IDOMSTYLESHEETCOLLECTION_IID);
|
||||
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
|
||||
|
||||
NS_DEF_PTR(nsIHTMLContent);
|
||||
NS_DEF_PTR(nsIContent);
|
||||
|
@ -129,6 +142,7 @@ public:
|
|||
RuleEnumFunc aFunc, void* aData);
|
||||
void EnumerateTagRules(nsIAtom* aTag,
|
||||
RuleEnumFunc aFunc, void* aData);
|
||||
|
||||
protected:
|
||||
void AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyleRule* aRule);
|
||||
|
||||
|
@ -171,6 +185,7 @@ void RuleHash::AppendRuleToTable(nsHashtable& aTable, nsIAtom* aAtom, nsICSSStyl
|
|||
value = value->mNext;
|
||||
}
|
||||
value->mNext = new RuleValue(aRule, mRuleCount++);
|
||||
value = value->mNext;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -242,11 +257,279 @@ void RuleHash::EnumerateTagRules(nsIAtom* aTag, RuleEnumFunc aFunc, void* aData)
|
|||
}
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
// Style Rule Collection for the DOM
|
||||
//
|
||||
class CSSStyleRuleCollectionImpl : public nsIDOMCSSStyleRuleCollection,
|
||||
public nsIScriptObjectOwner
|
||||
{
|
||||
public:
|
||||
CSSStyleRuleCollectionImpl(nsICSSStyleSheet *aStyleSheet);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMCSSStyleRuleCollection interface
|
||||
NS_IMETHOD GetLength(PRUint32* aLength);
|
||||
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMCSSStyleRule** aReturn);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
void DropReference() { mStyleSheet = nsnull; }
|
||||
|
||||
protected:
|
||||
virtual ~CSSStyleRuleCollectionImpl();
|
||||
|
||||
nsICSSStyleSheet* mStyleSheet;
|
||||
void* mScriptObject;
|
||||
};
|
||||
|
||||
CSSStyleRuleCollectionImpl::CSSStyleRuleCollectionImpl(nsICSSStyleSheet *aStyleSheet)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
// Not reference counted to avoid circular references.
|
||||
// The style sheet will tell us when its going away.
|
||||
mStyleSheet = aStyleSheet;
|
||||
mScriptObject = nsnull;
|
||||
}
|
||||
|
||||
CSSStyleRuleCollectionImpl::~CSSStyleRuleCollectionImpl()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(CSSStyleRuleCollectionImpl);
|
||||
NS_IMPL_RELEASE(CSSStyleRuleCollectionImpl);
|
||||
|
||||
nsresult
|
||||
CSSStyleRuleCollectionImpl::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
||||
{
|
||||
if (NULL == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kIDOMCSSStyleRuleCollectionIID)) {
|
||||
nsIDOMCSSStyleRuleCollection *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
nsIScriptObjectOwner *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
nsIDOMCSSStyleRuleCollection *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleCollectionImpl::GetLength(PRUint32* aLength)
|
||||
{
|
||||
if (nsnull != mStyleSheet) {
|
||||
*aLength = mStyleSheet->StyleRuleCount();
|
||||
}
|
||||
else {
|
||||
*aLength = 0;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleCollectionImpl::Item(PRUint32 aIndex, nsIDOMCSSStyleRule** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
*aReturn = nsnull;
|
||||
if (nsnull != mStyleSheet) {
|
||||
nsICSSStyleRule *rule;
|
||||
|
||||
result = mStyleSheet->GetStyleRuleAt(aIndex, rule);
|
||||
if (NS_OK == result) {
|
||||
result = rule->QueryInterface(kIDOMCSSStyleRuleIID, (void **)aReturn);
|
||||
}
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleCollectionImpl::GetScriptObject(nsIScriptContext *aContext,
|
||||
void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
nsISupports *supports = (nsISupports *)(nsIDOMCSSStyleRuleCollection *)this;
|
||||
|
||||
// XXX Should be done through factory
|
||||
res = NS_NewScriptCSSStyleRuleCollection(aContext,
|
||||
supports,
|
||||
(nsISupports *)mStyleSheet,
|
||||
(void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleRuleCollectionImpl::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
// Imports Collection for the DOM
|
||||
//
|
||||
class CSSImportsCollectionImpl : public nsIDOMStyleSheetCollection,
|
||||
public nsIScriptObjectOwner
|
||||
{
|
||||
public:
|
||||
CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
// nsIDOMCSSStyleSheetCollection interface
|
||||
NS_IMETHOD GetLength(PRUint32* aLength);
|
||||
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
void DropReference() { mStyleSheet = nsnull; }
|
||||
|
||||
protected:
|
||||
virtual ~CSSImportsCollectionImpl();
|
||||
|
||||
nsICSSStyleSheet* mStyleSheet;
|
||||
void* mScriptObject;
|
||||
};
|
||||
|
||||
CSSImportsCollectionImpl::CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
// Not reference counted to avoid circular references.
|
||||
// The style sheet will tell us when its going away.
|
||||
mStyleSheet = aStyleSheet;
|
||||
mScriptObject = nsnull;
|
||||
}
|
||||
|
||||
CSSImportsCollectionImpl::~CSSImportsCollectionImpl()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(CSSImportsCollectionImpl);
|
||||
NS_IMPL_RELEASE(CSSImportsCollectionImpl);
|
||||
|
||||
nsresult
|
||||
CSSImportsCollectionImpl::QueryInterface(REFNSIID aIID, void** aInstancePtrResult)
|
||||
{
|
||||
if (NULL == aInstancePtrResult) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
if (aIID.Equals(kIDOMStyleSheetCollectionIID)) {
|
||||
nsIDOMStyleSheetCollection *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
nsIScriptObjectOwner *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
nsIDOMStyleSheetCollection *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSImportsCollectionImpl::GetLength(PRUint32* aLength)
|
||||
{
|
||||
if (nsnull != mStyleSheet) {
|
||||
*aLength = mStyleSheet->StyleSheetCount();
|
||||
}
|
||||
else {
|
||||
*aLength = 0;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSImportsCollectionImpl::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn)
|
||||
{
|
||||
nsresult result = NS_OK;
|
||||
|
||||
*aReturn = nsnull;
|
||||
if (nsnull != mStyleSheet) {
|
||||
nsICSSStyleSheet *sheet;
|
||||
|
||||
result = mStyleSheet->GetStyleSheetAt(aIndex, sheet);
|
||||
if (NS_OK == result) {
|
||||
result = sheet->QueryInterface(kIDOMStyleSheetIID, (void **)aReturn);
|
||||
}
|
||||
NS_RELEASE(sheet);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSImportsCollectionImpl::GetScriptObject(nsIScriptContext *aContext,
|
||||
void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
nsISupports *supports = (nsISupports *)(nsIDOMStyleSheetCollection *)this;
|
||||
|
||||
// XXX Should be done through factory
|
||||
res = NS_NewScriptStyleSheetCollection(aContext,
|
||||
supports,
|
||||
(nsISupports *)mStyleSheet,
|
||||
(void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSImportsCollectionImpl::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// -------------------------------
|
||||
// CSS Style Sheet
|
||||
//
|
||||
class CSSStyleSheetImpl : public nsICSSStyleSheet {
|
||||
class CSSStyleSheetImpl : public nsICSSStyleSheet,
|
||||
public nsIDOMCSSStyleSheet,
|
||||
public nsIScriptObjectOwner {
|
||||
public:
|
||||
void* operator new(size_t size);
|
||||
void* operator new(size_t size, nsIArena* aArena);
|
||||
|
@ -281,8 +564,32 @@ public:
|
|||
virtual PRInt32 StyleRuleCount(void);
|
||||
virtual nsresult GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule);
|
||||
|
||||
virtual PRInt32 StyleSheetCount();
|
||||
virtual nsresult GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet);
|
||||
|
||||
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
||||
|
||||
// nsIDOMStyleSheet interface
|
||||
NS_IMETHOD GetDisabled(PRBool* aDisabled);
|
||||
NS_IMETHOD SetDisabled(PRBool aDisabled);
|
||||
NS_IMETHOD GetReadOnly(PRBool* aReadOnly);
|
||||
|
||||
// nsIDOMCSSStyleSheet interface
|
||||
NS_IMETHOD GetOwningElement(nsIDOMHTMLElement** aOwningElement);
|
||||
NS_IMETHOD GetParentStyleSheet(nsIDOMCSSStyleSheet** aParentStyleSheet);
|
||||
NS_IMETHOD GetHref(nsString& aHref);
|
||||
NS_IMETHOD GetTitle(nsString& aTitle);
|
||||
NS_IMETHOD GetImports(nsIDOMStyleSheetCollection** aImports);
|
||||
NS_IMETHOD GetRules(nsIDOMCSSStyleRuleCollection** aRules);
|
||||
NS_IMETHOD AddRule(const nsString& aSelector, const nsString& aDeclaration, PRUint32 aIndex, PRUint32* aReturn);
|
||||
NS_IMETHOD AddImport(const nsString& aUrl, PRUint32 aIndex, PRUint32* aReturn);
|
||||
NS_IMETHOD RemoveRule(PRUint32 aIndex);
|
||||
NS_IMETHOD RemoveImport(PRUint32 aIndex);
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
private:
|
||||
// These are not supported and are not implemented!
|
||||
CSSStyleSheetImpl(const CSSStyleSheetImpl& aCopy);
|
||||
|
@ -303,7 +610,11 @@ protected:
|
|||
nsISupportsArrayPtr mOrderedRules;
|
||||
nsISupportsArrayPtr mWeightedRules;
|
||||
nsICSSStyleSheetPtr mNext;
|
||||
nsICSSStyleSheet* mParent;
|
||||
RuleHash* mRuleHash;
|
||||
CSSStyleRuleCollectionImpl* mRuleCollection;
|
||||
CSSImportsCollectionImpl* mImportsCollection;
|
||||
void * mScriptObject;
|
||||
};
|
||||
|
||||
|
||||
|
@ -354,18 +665,49 @@ CSSStyleSheetImpl::CSSStyleSheetImpl(nsIURL* aURL)
|
|||
{
|
||||
NS_INIT_REFCNT();
|
||||
mURL.SetAddRef(aURL);
|
||||
mParent = nsnull;
|
||||
mRuleCollection = nsnull;
|
||||
mImportsCollection = nsnull;
|
||||
mScriptObject = nsnull;
|
||||
#ifdef DEBUG_REFS
|
||||
++gInstanceCount;
|
||||
fprintf(stdout, "%d + CSSStyleSheet size: %d\n", gInstanceCount, sizeof(*this));
|
||||
#endif
|
||||
}
|
||||
|
||||
static PRBool DropStyleSheetReference(nsISupports* aElement, void *aData)
|
||||
{
|
||||
nsICSSStyleRule *rule = (nsICSSStyleRule *)aElement;
|
||||
|
||||
if (nsnull != rule) {
|
||||
rule->SetStyleSheet(nsnull);
|
||||
}
|
||||
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
CSSStyleSheetImpl::~CSSStyleSheetImpl()
|
||||
{
|
||||
#ifdef DEBUG_REFS
|
||||
--gInstanceCount;
|
||||
fprintf(stdout, "%d - CSSStyleSheet\n", gInstanceCount);
|
||||
#endif
|
||||
if (mFirstChild.IsNotNull()) {
|
||||
nsICSSStyleSheet* child = mFirstChild;
|
||||
while (nsnull != child) {
|
||||
((CSSStyleSheetImpl *)child)->mParent = nsnull;
|
||||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
}
|
||||
}
|
||||
if (nsnull != mRuleCollection) {
|
||||
mRuleCollection->DropReference();
|
||||
NS_RELEASE(mRuleCollection);
|
||||
}
|
||||
if (nsnull != mImportsCollection) {
|
||||
mImportsCollection->DropReference();
|
||||
NS_RELEASE(mImportsCollection);
|
||||
}
|
||||
mOrderedRules->EnumerateForwards(DropStyleSheetReference, nsnull);
|
||||
ClearHash();
|
||||
}
|
||||
|
||||
|
@ -390,8 +732,28 @@ nsresult CSSStyleSheetImpl::QueryInterface(const nsIID& aIID,
|
|||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMStyleSheetIID)) {
|
||||
nsIDOMStyleSheet *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIDOMCSSStyleSheetIID)) {
|
||||
nsIDOMCSSStyleSheet *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kIScriptObjectOwnerIID)) {
|
||||
nsIScriptObjectOwner *tmp = this;
|
||||
*aInstancePtrResult = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtrResult = (void*) ((nsISupports*)this);
|
||||
nsICSSStyleSheet *tmp = this;
|
||||
nsISupports *tmp2 = tmp;
|
||||
*aInstancePtrResult = (void*) tmp2;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -750,6 +1112,10 @@ void CSSStyleSheetImpl::AppendStyleSheet(nsICSSStyleSheet* aSheet)
|
|||
}
|
||||
((CSSStyleSheetImpl*)child)->mNext.SetAddRef(aSheet);
|
||||
}
|
||||
|
||||
// This is not reference counted. Our parent tells us when
|
||||
// it's going away.
|
||||
((CSSStyleSheetImpl*)aSheet)->mParent = this;
|
||||
}
|
||||
|
||||
void CSSStyleSheetImpl::PrependStyleRule(nsICSSStyleRule* aRule)
|
||||
|
@ -778,6 +1144,7 @@ void CSSStyleSheetImpl::PrependStyleRule(nsICSSStyleRule* aRule)
|
|||
}
|
||||
mWeightedRules->InsertElementAt(aRule, index + 1);
|
||||
mOrderedRules->InsertElementAt(aRule, 0);
|
||||
aRule->SetStyleSheet(this);
|
||||
}
|
||||
|
||||
void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
|
||||
|
@ -807,6 +1174,7 @@ void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
|
|||
}
|
||||
mWeightedRules->InsertElementAt(aRule, index);
|
||||
mOrderedRules->AppendElement(aRule);
|
||||
aRule->SetStyleSheet(this);
|
||||
}
|
||||
|
||||
PRInt32 CSSStyleSheetImpl::StyleRuleCount(void)
|
||||
|
@ -833,6 +1201,43 @@ nsresult CSSStyleSheetImpl::GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRu
|
|||
return result;
|
||||
}
|
||||
|
||||
PRInt32 CSSStyleSheetImpl::StyleSheetCount()
|
||||
{
|
||||
// XXX Far from an ideal way to do this, but the hope is that
|
||||
// it won't be done too often. If it is, we might want to
|
||||
// consider storing the children in an array.
|
||||
PRInt32 count = 0;
|
||||
if (mFirstChild.IsNotNull()) {
|
||||
nsICSSStyleSheet* child = mFirstChild;
|
||||
while (nsnull != child) {
|
||||
count++;
|
||||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
nsresult CSSStyleSheetImpl::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet)
|
||||
{
|
||||
// XXX Ughh...an O(n^2) method for doing iteration. Again, we hope
|
||||
// that this isn't done too often. If it is, we need to change the
|
||||
// underlying storage mechanism
|
||||
aSheet = nsnull;
|
||||
if (mFirstChild.IsNotNull()) {
|
||||
nsICSSStyleSheet* child = mFirstChild;
|
||||
while ((nsnull != child) && (0 != aIndex)) {
|
||||
--aIndex;
|
||||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
}
|
||||
|
||||
aSheet = child;
|
||||
NS_IF_ADDREF(child);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void CSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
|
||||
{
|
||||
nsAutoString buffer;
|
||||
|
@ -886,6 +1291,224 @@ void CSSStyleSheetImpl::BuildHash(void)
|
|||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetDisabled(PRBool* aDisabled)
|
||||
{
|
||||
// XXX TBI
|
||||
*aDisabled = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::SetDisabled(PRBool aDisabled)
|
||||
{
|
||||
// XXX TBI
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetReadOnly(PRBool* aReadOnly)
|
||||
{
|
||||
// XXX TBI
|
||||
*aReadOnly = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetOwningElement(nsIDOMHTMLElement** aOwningElement)
|
||||
{
|
||||
// XXX TBI
|
||||
*aOwningElement = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aParentStyleSheet)
|
||||
{
|
||||
if (nsnull != mParent) {
|
||||
return mParent->QueryInterface(kIDOMCSSStyleSheetIID, (void **)aParentStyleSheet);
|
||||
}
|
||||
else {
|
||||
*aParentStyleSheet = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetHref(nsString& aHref)
|
||||
{
|
||||
if (mURL.IsNotNull()) {
|
||||
mURL->ToString(aHref);
|
||||
}
|
||||
else {
|
||||
aHref.SetLength(0);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetTitle(nsString& aTitle)
|
||||
{
|
||||
// XX TBI
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetImports(nsIDOMStyleSheetCollection** aImports)
|
||||
{
|
||||
if (nsnull == mImportsCollection) {
|
||||
mImportsCollection = new CSSImportsCollectionImpl(this);
|
||||
if (nsnull == mImportsCollection) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(mImportsCollection);
|
||||
}
|
||||
|
||||
*aImports = mImportsCollection;
|
||||
NS_ADDREF(mImportsCollection);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetRules(nsIDOMCSSStyleRuleCollection** aRules)
|
||||
{
|
||||
if (nsnull == mRuleCollection) {
|
||||
mRuleCollection = new CSSStyleRuleCollectionImpl(this);
|
||||
if (nsnull == mRuleCollection) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_ADDREF(mRuleCollection);
|
||||
}
|
||||
|
||||
*aRules = mRuleCollection;
|
||||
NS_ADDREF(mRuleCollection);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::AddRule(const nsString& aSelector,
|
||||
const nsString& aDeclaration,
|
||||
PRUint32 aIndex,
|
||||
PRUint32* aReturn)
|
||||
{
|
||||
nsICSSParser* css;
|
||||
nsresult result = NS_NewCSSParser(&css);
|
||||
if (NS_OK == result) {
|
||||
nsAutoString str;
|
||||
str.SetString(aSelector);
|
||||
// XXX Can we assume that the braces aren't there?
|
||||
str.Append(" { ");
|
||||
str.Append(aDeclaration);
|
||||
str.Append(" } ");
|
||||
|
||||
nsIUnicharInputStream* input = nsnull;
|
||||
result = NS_NewStringUnicharInputStream(&input, &str);
|
||||
if (NS_OK == result) {
|
||||
nsIStyleSheet *tmp;
|
||||
css->SetStyleSheet(this);
|
||||
// XXX Currently, the parser will append the rule to the
|
||||
// style sheet. We shouldn't ignore the index.
|
||||
result = css->Parse(input, mURL, tmp);
|
||||
NS_ASSERTION(tmp = this, "parser incorrectly created a new stylesheet");
|
||||
NS_RELEASE(input);
|
||||
*aReturn = mOrderedRules->Count();
|
||||
}
|
||||
|
||||
NS_RELEASE(css);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::AddImport(const nsString& aUrl, PRUint32 aIndex, PRUint32* aReturn)
|
||||
{
|
||||
nsICSSParser* css;
|
||||
nsresult result = NS_NewCSSParser(&css);
|
||||
if (NS_OK == result) {
|
||||
css->SetStyleSheet(this);
|
||||
result = css->ProcessImport(aUrl);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::RemoveRule(PRUint32 aIndex)
|
||||
{
|
||||
nsICSSStyleRule *rule;
|
||||
|
||||
rule = (nsICSSStyleRule *)mOrderedRules->ElementAt(aIndex);
|
||||
if (nsnull != rule) {
|
||||
mOrderedRules->RemoveElementAt(aIndex);
|
||||
mWeightedRules->RemoveElement(rule);
|
||||
rule->SetStyleSheet(nsnull);
|
||||
NS_RELEASE(rule);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::RemoveImport(PRUint32 aIndex)
|
||||
{
|
||||
if (mFirstChild.IsNotNull()) {
|
||||
nsICSSStyleSheet* prev = nsnull;
|
||||
nsICSSStyleSheet* child = mFirstChild;
|
||||
while ((nsnull != child) && (0 != aIndex)) {
|
||||
prev = child;
|
||||
child = ((CSSStyleSheetImpl*)child)->mNext;
|
||||
--aIndex;
|
||||
}
|
||||
|
||||
if ((nsnull != child) && (0 == aIndex)) {
|
||||
// Hold on to the child while we clean it up
|
||||
NS_ADDREF(child);
|
||||
if (nsnull == prev) {
|
||||
mFirstChild.SetAddRef(((CSSStyleSheetImpl*)child)->mNext);
|
||||
}
|
||||
else {
|
||||
((CSSStyleSheetImpl*)prev)->mNext.SetAddRef(((CSSStyleSheetImpl*)child)->mNext);
|
||||
}
|
||||
((CSSStyleSheetImpl*)child)->mNext.SetAddRef(nsnull);
|
||||
((CSSStyleSheetImpl*)child)->mParent = nsnull;
|
||||
NS_RELEASE(child);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
|
||||
|
||||
if (nsnull == mScriptObject) {
|
||||
nsISupports *supports = (nsISupports *)(nsICSSStyleSheet *)this;
|
||||
// XXX Should be done through factory
|
||||
res = NS_NewScriptCSSStyleSheet(aContext,
|
||||
supports,
|
||||
(nsISupports *)global,
|
||||
(void**)&mScriptObject);
|
||||
}
|
||||
*aScriptObject = mScriptObject;
|
||||
|
||||
NS_RELEASE(global);
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
CSSStyleSheetImpl::SetScriptObject(void* aScriptObject)
|
||||
{
|
||||
mScriptObject = aScriptObject;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_HTML nsresult
|
||||
NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult, nsIURL* aURL)
|
||||
{
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,55 @@
|
|||
/* -*- 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 "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/NPL/
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
* The Original Code is Mozilla Communicator client code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape Communications
|
||||
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
||||
* Netscape Communications Corporation. All Rights Reserved.
|
||||
*/
|
||||
#ifndef nsDOMCSSDeclaration_h___
|
||||
#define nsDOMCSSSDeclaration_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIDOMCSSStyleDeclaration.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
|
||||
class nsICSSDeclaration;
|
||||
|
||||
class nsDOMCSSDeclaration : public nsIDOMCSSStyleDeclaration,
|
||||
public nsIScriptObjectOwner
|
||||
{
|
||||
public:
|
||||
nsDOMCSSDeclaration();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_IDOMCSSSTYLEDECLARATION
|
||||
|
||||
// nsIScriptObjectOwner interface
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
virtual void DropReference() = 0;
|
||||
virtual nsresult GetCSSDeclaration(nsICSSDeclaration **aDecl,
|
||||
PRBool aAllocate) = 0;
|
||||
virtual nsresult StylePropertyChanged(const nsString& aPropertyName,
|
||||
PRInt32 aHint) = 0;
|
||||
virtual nsresult GetParent(nsISupports **aParent) = 0;
|
||||
|
||||
protected:
|
||||
virtual ~nsDOMCSSDeclaration();
|
||||
|
||||
void *mScriptObject;
|
||||
};
|
||||
|
||||
#endif // nsDOMCSSDeclaration_h___
|
|
@ -43,7 +43,7 @@ public:
|
|||
NS_IMETHOD SetStyleSheet(nsIStyleSheet* aSheet) = 0;
|
||||
|
||||
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
|
||||
nsIURL* aInputURL,
|
||||
nsIURL* aInputURL,
|
||||
nsIStyleSheet*& aResult) = 0;
|
||||
|
||||
// Parse declarations assuming that the outer curly braces have
|
||||
|
@ -58,6 +58,7 @@ public:
|
|||
nsICSSDeclaration* aDeclaration,
|
||||
PRInt32* aHint) = 0;
|
||||
|
||||
NS_IMETHOD ProcessImport(const nsString& aURLSpec) = 0;
|
||||
};
|
||||
|
||||
// Values or'd in the GetInfoMask; other bits are reserved
|
||||
|
|
|
@ -25,7 +25,7 @@ class nsIAtom;
|
|||
class nsIArena;
|
||||
class nsString;
|
||||
class nsICSSDeclaration;
|
||||
|
||||
class nsIStyleSheet;
|
||||
|
||||
struct nsCSSSelector {
|
||||
public:
|
||||
|
@ -65,6 +65,9 @@ public:
|
|||
virtual void SetWeight(PRInt32 aWeight) = 0;
|
||||
|
||||
virtual nsIStyleRule* GetImportantRule(void) = 0;
|
||||
|
||||
virtual nsIStyleSheet* GetStyleSheet(void) = 0;
|
||||
virtual void SetStyleSheet(nsIStyleSheet *aSheet) = 0;
|
||||
};
|
||||
|
||||
extern NS_HTML nsresult
|
||||
|
|
Загрузка…
Ссылка в новой задаче