style change notification support

This commit is contained in:
peterl%netscape.com 1998-11-26 01:34:53 +00:00
Родитель 1ec6fad39c
Коммит 4222f0257e
67 изменённых файлов: 2992 добавлений и 3097 удалений

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

@ -93,6 +93,16 @@ public:
NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aDisabled) { return NS_OK; }
NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint) { return NS_OK; }
NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) { return NS_OK; }
NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) { return NS_OK; }
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument);
protected:

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

@ -123,6 +123,16 @@ public:
NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aDisabled) { return NS_OK; }
NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint) { return NS_OK; }
NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) { return NS_OK; }
NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) { return NS_OK; }
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument);
// nsIScriptObjectOwner interface
@ -438,12 +448,7 @@ nsDocument::~nsDocument()
index = mStyleSheets.Count();
while (--index >= 0) {
nsIStyleSheet* sheet = (nsIStyleSheet*) mStyleSheets.ElementAt(index);
nsICSSStyleSheet* css;
nsresult rv = sheet->QueryInterface(kICSSStyleSheetIID, (void **)&css);
if (NS_SUCCEEDED(rv)) {
css->SetDocument(nsnull);
NS_RELEASE(css);
}
sheet->SetOwningDocument(nsnull);
NS_RELEASE(sheet);
}
@ -541,12 +546,7 @@ nsDocument::StartDocumentLoad(nsIURL *aURL,
PRInt32 index = mStyleSheets.Count();
while (--index >= 0) {
nsIStyleSheet* sheet = (nsIStyleSheet*) mStyleSheets.ElementAt(index);
nsICSSStyleSheet* css;
nsresult rv = sheet->QueryInterface(kICSSStyleSheetIID, (void **)&css);
if (NS_SUCCEEDED(rv)) {
css->SetDocument(nsnull);
NS_RELEASE(css);
}
sheet->SetOwningDocument(nsnull);
NS_RELEASE(sheet);
}
mStyleSheets.Clear();
@ -718,33 +718,34 @@ void nsDocument::AddStyleSheet(nsIStyleSheet* aSheet)
NS_PRECONDITION(nsnull != aSheet, "null arg");
mStyleSheets.AppendElement(aSheet);
NS_ADDREF(aSheet);
nsICSSStyleSheet* css;
nsresult rv = aSheet->QueryInterface(kICSSStyleSheetIID, (void **)&css);
if (NS_SUCCEEDED(rv)) {
css->SetDocument(this);
NS_RELEASE(css);
}
aSheet->SetOwningDocument(this);
PRInt32 count = mPresShells.Count();
PRInt32 index;
for (index = 0; index < count; index++) {
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
nsIStyleSet* set = shell->GetStyleSet();
if (nsnull != set) {
AddStyleSheetToSet(aSheet, set);
NS_RELEASE(set);
PRBool enabled = PR_TRUE;
aSheet->GetEnabled(enabled);
if (enabled) {
PRInt32 count = mPresShells.Count();
PRInt32 index;
for (index = 0; index < count; index++) {
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
nsIStyleSet* set = shell->GetStyleSet();
if (nsnull != set) {
AddStyleSheetToSet(aSheet, set);
NS_RELEASE(set);
}
}
}
count = mObservers.Count();
for (index = 0; index < count; index++) {
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
observer->StyleSheetAdded(this, aSheet);
// XXX should observers be notified for disabled sheets??? I think not, but I could be wrong
count = mObservers.Count();
for (index = 0; index < count; index++) {
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
observer->StyleSheetAdded(this, aSheet);
}
}
}
void nsDocument::SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
PRBool mDisabled)
PRBool aDisabled)
{
NS_PRECONDITION(nsnull != aSheet, "null arg");
PRInt32 count;
@ -757,7 +758,7 @@ void nsDocument::SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
nsIStyleSet* set = shell->GetStyleSet();
if (nsnull != set) {
if (mDisabled) {
if (aDisabled) {
set->RemoveDocStyleSheet(aSheet);
}
else {
@ -771,7 +772,7 @@ void nsDocument::SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
count = mObservers.Count();
for (index = 0; index < count; index++) {
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
observer->StyleSheetDisabledStateChanged(this, aSheet, mDisabled);
observer->StyleSheetDisabledStateChanged(this, aSheet, aDisabled);
}
}
@ -929,6 +930,42 @@ nsDocument::AttributeChanged(nsIContent* aChild,
return NS_OK;
}
NS_IMETHODIMP
nsDocument::StyleRuleChanged(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule,
PRInt32 aHint)
{
PRInt32 count = mObservers.Count();
for (PRInt32 i = 0; i < count; i++) {
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
observer->StyleRuleChanged(this, aStyleSheet, aStyleRule, aHint);
}
return NS_OK;
}
NS_IMETHODIMP
nsDocument::StyleRuleAdded(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule)
{
PRInt32 count = mObservers.Count();
for (PRInt32 i = 0; i < count; i++) {
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
observer->StyleRuleAdded(this, aStyleSheet, aStyleRule);
}
return NS_OK;
}
NS_IMETHODIMP
nsDocument::StyleRuleRemoved(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule)
{
PRInt32 count = mObservers.Count();
for (PRInt32 i = 0; i < count; i++) {
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
observer->StyleRuleRemoved(this, aStyleSheet, aStyleRule);
}
return NS_OK;
}
nsresult nsDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
nsresult res = NS_OK;

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

@ -175,6 +175,14 @@ public:
nsIContent* aChild,
PRInt32 aIndexInContainer);
NS_IMETHOD StyleRuleChanged(nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint); // See nsStyleConsts fot hint values
NS_IMETHOD StyleRuleAdded(nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
/**
* Returns the Selection Object
*/

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

@ -87,14 +87,14 @@ public:
nsIStyleContext* aParentContext,
PRBool aForceUnique = PR_FALSE);
NS_IMETHODIMP ConstructFrame(nsIPresContext* aPresContext,
NS_IMETHOD ConstructFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIFrame*& aFrameSubTree);
NS_IMETHOD ReconstructFrames(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIFrame*& aFrameSubTree);
NS_IMETHOD ReconstructFrames(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIFrame* aFrameSubTree);
nsIFrame* aFrameSubTree);
NS_IMETHOD ContentAppended(nsIPresContext* aPresContext,
nsIContent* aContainer,
PRInt32 aNewIndexInContainer);
@ -122,6 +122,18 @@ public:
// xxx style rules enumeration
// Style change notifications
NS_IMETHOD StyleRuleChanged(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint); // See nsStyleConsts fot hint values
NS_IMETHOD StyleRuleAdded(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD StyleRuleRemoved(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0);
private:
@ -727,7 +739,31 @@ StyleSetImpl::AttributeChanged(nsIPresContext* aPresContext,
}
// xxx style rules enumeration
// Style change notifications
NS_IMETHODIMP
StyleSetImpl::StyleRuleChanged(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint)
{
return mFrameConstructor->StyleRuleChanged(aPresContext, aStyleSheet, aStyleRule, aHint);
}
NS_IMETHODIMP
StyleSetImpl::StyleRuleAdded(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
return mFrameConstructor->StyleRuleAdded(aPresContext, aStyleSheet, aStyleRule);
}
NS_IMETHODIMP
StyleSetImpl::StyleRuleRemoved(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
return mFrameConstructor->StyleRuleRemoved(aPresContext, aStyleSheet, aStyleRule);
}
void StyleSetImpl::List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets)
{

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

@ -197,7 +197,7 @@ static nsresult EnsureWritableAttributes(nsIHTMLContent* aContent,
nsMapAttributesFunc mapFunc;
result = aContent->GetAttributeMappingFunction(mapFunc);
if (NS_OK == result) {
result = NS_NewHTMLAttributes(&aAttributes, mapFunc);
result = NS_NewHTMLAttributes(&aAttributes, nsnull, mapFunc);
if (NS_OK == result) {
aAttributes->AddContentRef();
}
@ -366,6 +366,7 @@ nsGenericHTMLElement::SetDocument(nsIDocument* aDocument, PRBool aDeep)
if ((nsnull != mDocument) && (nsnull != mAttributes)) {
nsIHTMLStyleSheet* sheet = GetAttrStyleSheet(mDocument);
if (nsnull != sheet) {
mAttributes->SetStyleSheet(sheet);
sheet->SetAttributesFor(htmlContent, mAttributes); // sync attributes with sheet
NS_RELEASE(sheet);
}

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

@ -42,7 +42,73 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIDOMHTMLBodyElementIID, NS_IDOMHTMLBODYELEMENT_IID);
static NS_DEFINE_IID(kIHTMLContentContainerIID, NS_IHTMLCONTENTCONTAINER_IID);
class BodyRule;
//----------------------------------------------------------------------
class nsHTMLBodyElement;
class BodyRule: public nsIStyleRule {
public:
BodyRule(nsHTMLBodyElement* aPart, nsIHTMLStyleSheet* aSheet);
~BodyRule();
NS_DECL_ISUPPORTS
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
// Strength is an out-of-band weighting, always 0 here
NS_IMETHOD GetStrength(PRInt32& aStrength);
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext,
nsIPresContext* aPresContext);
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
nsHTMLBodyElement* mPart; // not ref-counted, cleared by content
nsIHTMLStyleSheet* mSheet; // not ref-counted, cleared by content
};
//----------------------------------------------------------------------
// special subclass of inner class to override set document
class nsBodyInner: public nsGenericHTMLContainerElement
{
public:
nsBodyInner();
~nsBodyInner();
nsresult SetDocument(nsIDocument* aDocument, PRBool aDeep);
BodyRule* mStyleRule;
};
nsBodyInner::nsBodyInner()
: nsGenericHTMLContainerElement(),
mStyleRule(nsnull)
{
}
nsBodyInner::~nsBodyInner()
{
if (nsnull != mStyleRule) {
mStyleRule->mPart = nsnull;
mStyleRule->mSheet = nsnull;
NS_RELEASE(mStyleRule);
}
}
nsresult nsBodyInner::SetDocument(nsIDocument* aDocument, PRBool aDeep)
{
if (nsnull != mStyleRule) {
mStyleRule->mPart = nsnull;
mStyleRule->mSheet = nsnull;
NS_RELEASE(mStyleRule); // destroy old style rule since the sheet will probably change
}
return nsGenericHTMLContainerElement::SetDocument(aDocument, aDeep);
}
//----------------------------------------------------------------------
class nsHTMLBodyElement : public nsIDOMHTMLBodyElement,
public nsIScriptObjectOwner,
@ -92,38 +158,19 @@ public:
NS_IMPL_IHTMLCONTENT_USING_GENERIC2(mInner)
protected:
nsGenericHTMLContainerElement mInner;
BodyRule* mStyleRule;
nsBodyInner mInner;
friend BodyRule;
};
class BodyRule: public nsIStyleRule {
public:
BodyRule(nsHTMLBodyElement* aPart);
~BodyRule();
NS_DECL_ISUPPORTS
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
// Strength is an out-of-band weighting, always 0 here
NS_IMETHOD GetStrength(PRInt32& aStrength);
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext,
nsIPresContext* aPresContext);
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
nsHTMLBodyElement* mPart;
};
//----------------------------------------------------------------------
BodyRule::BodyRule(nsHTMLBodyElement* aPart)
BodyRule::BodyRule(nsHTMLBodyElement* aPart, nsIHTMLStyleSheet* aSheet)
{
NS_INIT_REFCNT();
mPart = aPart;
mSheet = aSheet;
}
BodyRule::~BodyRule()
@ -146,6 +193,14 @@ BodyRule::HashValue(PRUint32& aValue) const
return NS_OK;
}
NS_IMETHODIMP
BodyRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
// Strength is an out-of-band weighting, useful for mapping CSS ! important
// always 0 here
NS_IMETHODIMP
@ -244,7 +299,6 @@ NS_NewHTMLBodyElement(nsIHTMLContent** aInstancePtrResult, nsIAtom* aTag)
}
nsHTMLBodyElement::nsHTMLBodyElement(nsIAtom* aTag)
: mStyleRule(nsnull)
{
NS_INIT_REFCNT();
mInner.Init(this, aTag);
@ -252,10 +306,6 @@ nsHTMLBodyElement::nsHTMLBodyElement(nsIAtom* aTag)
nsHTMLBodyElement::~nsHTMLBodyElement()
{
if (nsnull != mStyleRule) {
mStyleRule->mPart = nsnull;
NS_RELEASE(mStyleRule);
}
}
NS_IMPL_ADDREF(nsHTMLBodyElement)
@ -454,14 +504,39 @@ nsHTMLBodyElement::HandleDOMEvent(nsIPresContext& aPresContext,
aFlags, aEventStatus);
}
static nsIHTMLStyleSheet* GetAttrStyleSheet(nsIDocument* aDocument)
{
nsIHTMLStyleSheet* sheet = nsnull;
nsIHTMLContentContainer* htmlContainer;
if (nsnull != aDocument) {
if (NS_OK == aDocument->QueryInterface(kIHTMLContentContainerIID, (void**)&htmlContainer)) {
htmlContainer->GetAttributeStyleSheet(&sheet);
NS_RELEASE(htmlContainer);
}
}
NS_ASSERTION(nsnull != sheet, "can't get attribute style sheet");
return sheet;
}
NS_IMETHODIMP
nsHTMLBodyElement::GetStyleRule(nsIStyleRule*& aResult)
{
if (nsnull == mStyleRule) {
mStyleRule = new BodyRule(this);
NS_IF_ADDREF(mStyleRule);
if (nsnull == mInner.mStyleRule) {
nsIHTMLStyleSheet* sheet = nsnull;
if (nsnull != mInner.mDocument) { // find style sheet
sheet = GetAttrStyleSheet(mInner.mDocument);
}
mInner.mStyleRule = new BodyRule(this, sheet);
NS_IF_RELEASE(sheet);
NS_IF_ADDREF(mInner.mStyleRule);
}
NS_IF_ADDREF(mStyleRule);
aResult = mStyleRule;
NS_IF_ADDREF(mInner.mStyleRule);
aResult = mInner.mStyleRule;
return NS_OK;
}

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

@ -131,8 +131,14 @@ nsHTMLDocument::~nsHTMLDocument()
NS_IF_RELEASE(mEmbeds);
NS_IF_RELEASE(mLinks);
NS_IF_RELEASE(mAnchors);
NS_IF_RELEASE(mAttrStyleSheet);
NS_IF_RELEASE(mStyleAttrStyleSheet);
if (nsnull != mAttrStyleSheet) {
mAttrStyleSheet->SetOwningDocument(nsnull);
NS_RELEASE(mAttrStyleSheet);
}
if (nsnull != mStyleAttrStyleSheet) {
mStyleAttrStyleSheet->SetOwningDocument(nsnull);
NS_RELEASE(mStyleAttrStyleSheet);
}
NS_IF_RELEASE(mParser);
for (i = 0; i < mImageMaps.Count(); i++) {
nsIImageMap* map = (nsIImageMap*)mImageMaps.ElementAt(i);
@ -208,8 +214,14 @@ nsHTMLDocument::StartDocumentLoad(nsIURL *aURL,
nsIWebShell* webShell;
NS_IF_RELEASE(mAttrStyleSheet);
NS_IF_RELEASE(mStyleAttrStyleSheet);
if (nsnull != mAttrStyleSheet) {
mAttrStyleSheet->SetOwningDocument(nsnull);
NS_RELEASE(mAttrStyleSheet);
}
if (nsnull != mStyleAttrStyleSheet) {
mStyleAttrStyleSheet->SetOwningDocument(nsnull);
NS_RELEASE(mStyleAttrStyleSheet);
}
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
@ -231,10 +243,10 @@ nsHTMLDocument::StartDocumentLoad(nsIURL *aURL,
#endif
if (NS_OK == rv) {
if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL)) {
if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this)) {
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
}
if (NS_OK == NS_NewHTMLCSSStyleSheet(&mStyleAttrStyleSheet, aURL)) {
if (NS_OK == NS_NewHTMLCSSStyleSheet(&mStyleAttrStyleSheet, aURL, this)) {
AddStyleSheet(mStyleAttrStyleSheet); // tell the world about our new style sheet
}

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

@ -195,7 +195,7 @@ nsImageDocument::StartDocumentLoad(nsIURL* aURL,
// Create style attribute style sheet
nsresult rv;
nsIHTMLCSSStyleSheet* styleAttrSheet;
rv = NS_NewHTMLCSSStyleSheet(&styleAttrSheet, aURL);
rv = NS_NewHTMLCSSStyleSheet(&styleAttrSheet, aURL, this);
if (NS_OK != rv) {
return rv;
}
@ -203,7 +203,7 @@ nsImageDocument::StartDocumentLoad(nsIURL* aURL,
NS_RELEASE(styleAttrSheet);
// Create html attribute style sheet
rv = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL);
rv = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this);
if (NS_OK != rv) {
return rv;
}

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

@ -192,10 +192,17 @@ void nsMarkupDocument::StyleSheetsToXIF(nsXIFConverter& aConverter)
if (sheet != nsnull)
{
nsIURL& sheetURL = *sheet->GetURL();
nsIURL* sheetURL = nsnull;
sheet->GetURL(sheetURL);
if (!(sheetURL == docURL))
if (nsnull == sheetURL) {
break;
}
if (!(*sheetURL == docURL)) {
NS_RELEASE(sheetURL);
break;
}
NS_RELEASE(sheetURL);
nsresult isCss = sheet->QueryInterface(kICSSStyleSheetIID, (void**)&cssSheet);
if ((isCss == NS_OK) && (cssSheet != nsnull))

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

@ -21,7 +21,7 @@
#include "nslayout.h"
#include "nsISupports.h"
class nsIStyleRule;
class nsIStyleSheet;
class nsICSSStyleSheet;
class nsIUnicharInputStream;
class nsIURL;
class nsString;
@ -40,11 +40,11 @@ public:
// Set a style sheet for the parser to fill in. The style sheet must
// implement the nsICSSStyleSheet interface
NS_IMETHOD SetStyleSheet(nsIStyleSheet* aSheet) = 0;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet) = 0;
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
nsIURL* aInputURL,
nsIStyleSheet*& aResult) = 0;
nsIURL* aInputURL,
nsICSSStyleSheet*& aResult) = 0;
// Parse declarations assuming that the outer curly braces have
// already been accounted for. aBaseURL is the base url to use for

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

@ -198,11 +198,11 @@ public:
NS_IMETHOD GetInfoMask(PRUint32& aResult);
NS_IMETHOD SetStyleSheet(nsIStyleSheet* aSheet);
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet);
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
nsIURL* aInputURL,
nsIStyleSheet*& aResult);
nsIURL* aInputURL,
nsICSSStyleSheet*& aResult);
NS_IMETHOD ParseDeclarations(const nsString& aDeclaration,
nsIURL* aBaseURL,
@ -364,32 +364,27 @@ CSSParserImpl::GetInfoMask(PRUint32& aResult)
}
NS_METHOD
CSSParserImpl::SetStyleSheet(nsIStyleSheet* aSheet)
CSSParserImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
{
NS_PRECONDITION(nsnull != aSheet, "null ptr");
if (nsnull == aSheet) {
return NS_ERROR_NULL_POINTER;
}
// Make sure the sheet supports the correct interface!
static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID);
nsICSSStyleSheet* cssSheet;
nsresult rv = aSheet->QueryInterface(kICSSStyleSheetIID, (void**)&cssSheet);
if (NS_OK != rv) {
return rv;
if (aSheet != mSheet) {
// Switch to using the new sheet
NS_IF_RELEASE(mSheet);
mSheet = aSheet;
NS_ADDREF(mSheet);
}
// Switch to using the new sheet
NS_IF_RELEASE(mSheet);
mSheet = cssSheet;
return NS_OK;
}
NS_METHOD
CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
nsIURL* aInputURL,
nsIStyleSheet*& aResult)
nsICSSStyleSheet*& aResult)
{
if (nsnull == mSheet) {
NS_NewCSSStyleSheet(&mSheet, aInputURL);
@ -425,9 +420,8 @@ CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
mScanner = nsnull;
NS_IF_RELEASE(mURL);
nsIStyleSheet* sheet = nsnull;
mSheet->QueryInterface(kIStyleSheetIID, (void**)&sheet);
aResult = sheet;
aResult = mSheet;
NS_ADDREF(aResult);
return NS_OK;
}
@ -711,15 +705,11 @@ NS_IMETHODIMP CSSParserImpl::ProcessImport(const nsString& aURLSpec)
nsICSSParser* parser;
rv = NS_NewCSSParser(&parser);
if (NS_OK == rv) {
nsIStyleSheet* childSheet = nsnull;
nsICSSStyleSheet* childSheet = nsnull;
rv = parser->Parse(uin, url, childSheet);
NS_RELEASE(parser);
if ((NS_OK == rv) && (nsnull != childSheet)) {
nsICSSStyleSheet* cssChild = nsnull;
if (NS_OK == childSheet->QueryInterface(kICSSStyleSheetIID, (void**)&cssChild)) {
mSheet->AppendStyleSheet(cssChild);
NS_RELEASE(cssChild);
}
mSheet->AppendStyleSheet(childSheet);
}
NS_IF_RELEASE(childSheet);
}

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

@ -17,9 +17,10 @@
*/
#include "nsICSSStyleRule.h"
#include "nsICSSDeclaration.h"
#include "nsIStyleSheet.h"
#include "nsICSSStyleSheet.h"
#include "nsIStyleContext.h"
#include "nsIPresContext.h"
#include "nsIDocument.h"
#include "nsIDeviceContext.h"
#include "nsIArena.h"
#include "nsIAtom.h"
@ -31,8 +32,8 @@
#include "nsStyleUtil.h"
#include "nsIFontMetrics.h"
#include "nsIDOMCSSStyleSheet.h"
#include "nsIDOMCSSRule.h"
#include "nsIDOMCSSStyleRule.h"
#include "nsIDOMCSSStyleRuleSimple.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptObjectOwner.h"
@ -45,8 +46,8 @@ 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(kIDOMCSSRuleIID, NS_IDOMCSSRULE_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);
@ -162,15 +163,19 @@ static void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
nsIStyleContext* aContext, nsIPresContext* aPresContext);
class CSSStyleRuleImpl;
class CSSImportantRule : public nsIStyleRule {
public:
CSSImportantRule(nsICSSDeclaration* aDeclaration);
CSSImportantRule(nsICSSStyleSheet* aSheet, nsICSSDeclaration* aDeclaration);
NS_DECL_ISUPPORTS
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
// Strength is an out-of-band weighting, useful for mapping CSS ! important
NS_IMETHOD GetStrength(PRInt32& aStrength);
@ -182,10 +187,14 @@ protected:
~CSSImportantRule(void);
nsICSSDeclaration* mDeclaration;
nsICSSStyleSheet* mSheet;
friend CSSStyleRuleImpl;
};
CSSImportantRule::CSSImportantRule(nsICSSDeclaration* aDeclaration)
: mDeclaration(aDeclaration)
CSSImportantRule::CSSImportantRule(nsICSSStyleSheet* aSheet, nsICSSDeclaration* aDeclaration)
: mSheet(aSheet),
mDeclaration(aDeclaration)
{
NS_INIT_REFCNT();
NS_IF_ADDREF(mDeclaration);
@ -212,6 +221,14 @@ CSSImportantRule::HashValue(PRUint32& aValue) const
return NS_OK;
}
NS_IMETHODIMP
CSSImportantRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
// Strength is an out-of-band weighting, useful for mapping CSS ! important
NS_IMETHODIMP
CSSImportantRule::GetStrength(PRInt32& aStrength)
@ -299,7 +316,18 @@ nsresult
DOMCSSDeclarationImpl::StylePropertyChanged(const nsString& aPropertyName,
PRInt32 aHint)
{
// XXX TBI
nsIStyleSheet* sheet = nsnull;
if (nsnull != mRule) {
mRule->GetStyleSheet(sheet);
if (nsnull != sheet) {
nsIDocument* doc = nsnull;
sheet->GetOwningDocument(doc);
if (nsnull != doc) {
doc->StyleRuleChanged(sheet, mRule, aHint);
}
}
}
return NS_OK;
}
@ -316,7 +344,7 @@ DOMCSSDeclarationImpl::GetParent(nsISupports **aParent)
// -- nsCSSStyleRule -------------------------------
class CSSStyleRuleImpl : public nsICSSStyleRule,
public nsIDOMCSSStyleRuleSimple,
public nsIDOMCSSStyleRule,
public nsIScriptObjectOwner {
public:
void* operator new(size_t size);
@ -346,20 +374,24 @@ public:
virtual nsIStyleRule* GetImportantRule(void);
virtual nsIStyleSheet* GetStyleSheet(void);
virtual void SetStyleSheet(nsIStyleSheet *aSheet);
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* 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);
// nsIDOMCSSRule interface
NS_IMETHOD GetType(PRUint16* aType);
NS_IMETHOD GetCssText(nsString& aCssText);
NS_IMETHOD SetCssText(const nsString& aCssText);
NS_IMETHOD GetSheet(nsIDOMCSSStyleSheet** aSheet);
// nsIDOMCSSStyleRuleSimple interface
// nsIDOMCSSStyleRule interface
NS_IMETHOD GetSelectorText(nsString& aSelectorText);
NS_IMETHOD SetSelectorText(const nsString& aSelectorText);
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle);
NS_IMETHOD SetStyle(nsIDOMCSSStyleDeclaration* aStyle);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
@ -377,13 +409,13 @@ protected:
PRUint32 mInHeap : 1;
PRUint32 mRefCnt : 31;
nsCSSSelector mSelector;
nsICSSDeclaration* mDeclaration;
PRInt32 mWeight;
CSSImportantRule* mImportantRule;
nsIStyleSheet* mStyleSheet;
DOMCSSDeclarationImpl *mDOMDeclaration;
void* mScriptObject;
nsCSSSelector mSelector;
nsICSSDeclaration* mDeclaration;
PRInt32 mWeight;
CSSImportantRule* mImportantRule;
nsICSSStyleSheet* mSheet;
DOMCSSDeclarationImpl* mDOMDeclaration;
void* mScriptObject;
#ifdef DEBUG_REFS
PRInt32 mInstance;
#endif
@ -453,7 +485,10 @@ CSSStyleRuleImpl::~CSSStyleRuleImpl()
delete selector;
}
NS_IF_RELEASE(mDeclaration);
NS_IF_RELEASE(mImportantRule);
if (nsnull != mImportantRule) {
mImportantRule->mSheet = nsnull;
NS_RELEASE(mImportantRule);
}
if (nsnull != mDOMDeclaration) {
mDOMDeclaration->DropReference();
}
@ -505,14 +540,14 @@ nsresult CSSStyleRuleImpl::QueryInterface(const nsIID& aIID,
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMCSSStyleRuleIID)) {
nsIDOMCSSStyleRule *tmp = this;
if (aIID.Equals(kIDOMCSSRuleIID)) {
nsIDOMCSSRule *tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMCSSStyleRuleSimpleIID)) {
nsIDOMCSSStyleRuleSimple *tmp = this;
if (aIID.Equals(kIDOMCSSStyleRuleIID)) {
nsIDOMCSSStyleRule *tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
@ -637,10 +672,12 @@ nsICSSDeclaration* CSSStyleRuleImpl::GetDeclaration(void) const
void CSSStyleRuleImpl::SetDeclaration(nsICSSDeclaration* aDeclaration)
{
NS_IF_RELEASE(mImportantRule);
NS_IF_RELEASE(mDeclaration);
mDeclaration = aDeclaration;
NS_IF_ADDREF(mDeclaration);
if (mDeclaration != aDeclaration) {
NS_IF_RELEASE(mImportantRule);
NS_IF_RELEASE(mDeclaration);
mDeclaration = aDeclaration;
NS_IF_ADDREF(mDeclaration);
}
}
PRInt32 CSSStyleRuleImpl::GetWeight(void) const
@ -659,7 +696,7 @@ nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
nsICSSDeclaration* important;
mDeclaration->GetImportantValues(important);
if (nsnull != important) {
mImportantRule = new CSSImportantRule(important);
mImportantRule = new CSSImportantRule(mSheet, important);
NS_ADDREF(mImportantRule);
NS_RELEASE(important);
}
@ -668,19 +705,25 @@ nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
return mImportantRule;
}
nsIStyleSheet* CSSStyleRuleImpl::GetStyleSheet(void)
NS_IMETHODIMP
CSSStyleRuleImpl::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mStyleSheet);
return mStyleSheet;
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
void CSSStyleRuleImpl::SetStyleSheet(nsIStyleSheet *aSheet)
NS_IMETHODIMP
CSSStyleRuleImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
{
// XXX We don't reference count this up reference. The style sheet
// 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;
mSheet = aSheet;
if (nsnull != mImportantRule) { // we're responsible for this guy too
mImportantRule->mSheet = aSheet;
}
return NS_OK;
}
nscoord CalcLength(const nsCSSValue& aValue,
@ -1284,8 +1327,8 @@ void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
}
else if (eCSSUnit_Inherit == ourColor->mBackPositionX.GetUnit()) {
color->mBackgroundXPosition = parentColor->mBackgroundXPosition;
color->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_LENGTH;
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & NS_STYLE_BG_X_POSITION_PERCENT);
color->mBackgroundFlags &= ~(NS_STYLE_BG_X_POSITION_LENGTH | NS_STYLE_BG_X_POSITION_PERCENT);
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & (NS_STYLE_BG_X_POSITION_LENGTH | NS_STYLE_BG_X_POSITION_PERCENT));
}
if (eCSSUnit_Percent == ourColor->mBackPositionY.GetUnit()) {
@ -1306,8 +1349,8 @@ void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
}
else if (eCSSUnit_Inherit == ourColor->mBackPositionY.GetUnit()) {
color->mBackgroundYPosition = parentColor->mBackgroundYPosition;
color->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_LENGTH;
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & NS_STYLE_BG_Y_POSITION_PERCENT);
color->mBackgroundFlags &= ~(NS_STYLE_BG_Y_POSITION_LENGTH | NS_STYLE_BG_Y_POSITION_PERCENT);
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & (NS_STYLE_BG_Y_POSITION_LENGTH | NS_STYLE_BG_Y_POSITION_PERCENT));
}
// opacity: factor, percent, inherit
@ -1693,14 +1736,37 @@ CSSStyleRuleImpl::List(FILE* out, PRInt32 aIndent) const
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetType(nsString& aType)
CSSStyleRuleImpl::GetType(PRUint16* aType)
{
// XXX Need to define the different types
aType.SetString("simple");
*aType = nsIDOMCSSRule::STYLE_RULE;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetCssText(nsString& aCssText)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::SetCssText(const nsString& aCssText)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetSheet(nsIDOMCSSStyleSheet** aSheet)
{
if (nsnull != mSheet) {
return mSheet->QueryInterface(kIDOMCSSStyleSheetIID, (void**)aSheet);
}
*aSheet = nsnull;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetSelectorText(nsString& aSelectorText)
{
@ -1763,6 +1829,13 @@ CSSStyleRuleImpl::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::SetStyle(nsIDOMCSSStyleDeclaration* aStyle)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
@ -1773,10 +1846,10 @@ CSSStyleRuleImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObje
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);
res = NS_NewScriptCSSStyleRule(aContext,
supports,
(nsISupports *)global,
(void**)&mScriptObject);
}
*aScriptObject = mScriptObject;

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

@ -30,12 +30,14 @@
#include "nsHTMLAtoms.h"
#include "nsIFrame.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsIPtr.h"
#include "nsHTMLIIDs.h"
#include "nsIDOMStyleSheetCollection.h"
#include "nsIDOMCSSStyleSheet.h"
#include "nsIDOMCSSStyleRule.h"
#include "nsIDOMCSSStyleRuleCollection.h"
#include "nsIDOMNode.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsICSSParser.h"
@ -540,6 +542,25 @@ public:
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
// basic style sheet data
NS_IMETHOD GetURL(nsIURL*& aURL) const;
NS_IMETHOD GetTitle(nsString& aTitle) const;
NS_IMETHOD SetTitle(const nsString& aTitle);
NS_IMETHOD GetType(nsString& aType) const;
NS_IMETHOD GetMediumCount(PRInt32& aCount) const;
NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsString& aMedium) const;
NS_IMETHOD AppendMedium(const nsString& aMedium);
NS_IMETHOD GetEnabled(PRBool& aEnabled) const;
NS_IMETHOD SetEnabled(PRBool aEnabled);
// style sheet owner info
NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // may be null
NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
NS_IMETHOD SetOwningNode(nsIDOMNode* aOwningNode);
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aParentContext,
@ -551,9 +572,7 @@ public:
nsIStyleContext* aParentContext,
nsISupportsArray* aResults);
virtual nsIURL* GetURL(void);
virtual PRBool ContainsStyleSheet(nsIURL* aURL);
virtual PRBool ContainsStyleSheet(nsIURL* aURL) const;
virtual void AppendStyleSheet(nsICSSStyleSheet* aSheet);
@ -561,32 +580,29 @@ public:
virtual void PrependStyleRule(nsICSSStyleRule* aRule);
virtual void AppendStyleRule(nsICSSStyleRule* aRule);
virtual PRInt32 StyleRuleCount(void);
virtual nsresult GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule);
virtual PRInt32 StyleRuleCount(void) const;
virtual nsresult GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule) const;
virtual PRInt32 StyleSheetCount();
virtual nsresult GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet);
virtual void SetDocument(nsIDocument *aDocument);
virtual PRInt32 StyleSheetCount(void) const;
virtual nsresult GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const;
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
// nsIDOMStyleSheet interface
NS_IMETHOD GetType(nsString& aType);
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 GetOwningNode(nsIDOMNode** aOwningNode);
NS_IMETHOD GetParentStyleSheet(nsIDOMStyleSheet** 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);
NS_IMETHOD GetMedia(nsString& aMedia);
NS_IMETHOD GetCssRules(nsIDOMCSSStyleRuleCollection** aCssRules);
NS_IMETHOD InsertRule(const nsString& aRule, PRUint32 aIndex, PRUint32* aReturn);
NS_IMETHOD DeleteRule(PRUint32 aIndex);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
@ -608,6 +624,8 @@ protected:
PRUint32 mRefCnt : 31;
nsIURLPtr mURL;
nsString mTitle;
nsVoidArray mMedia;
nsICSSStyleSheetPtr mFirstChild;
nsISupportsArrayPtr mOrderedRules;
nsISupportsArrayPtr mWeightedRules;
@ -617,8 +635,9 @@ protected:
CSSStyleRuleCollectionImpl* mRuleCollection;
CSSImportsCollectionImpl* mImportsCollection;
nsIDocument* mDocument;
nsIDOMNode* mOwningNode;
PRBool mDisabled;
void * mScriptObject;
void* mScriptObject;
};
@ -662,7 +681,8 @@ static PRInt32 gInstanceCount;
CSSStyleSheetImpl::CSSStyleSheetImpl(nsIURL* aURL)
: nsICSSStyleSheet(),
mURL(nsnull), mFirstChild(nsnull),
mURL(nsnull), mTitle(), mMedia(),
mFirstChild(nsnull),
mOrderedRules(nsnull), mWeightedRules(nsnull),
mNext(nsnull),
mRuleHash(nsnull)
@ -673,6 +693,7 @@ CSSStyleSheetImpl::CSSStyleSheetImpl(nsIURL* aURL)
mRuleCollection = nsnull;
mImportsCollection = nsnull;
mDocument = nsnull;
mOwningNode = nsnull;
mDisabled = PR_FALSE;
mScriptObject = nsnull;
#ifdef DEBUG_REFS
@ -698,6 +719,11 @@ CSSStyleSheetImpl::~CSSStyleSheetImpl()
--gInstanceCount;
fprintf(stdout, "%d - CSSStyleSheet\n", gInstanceCount);
#endif
PRInt32 count = mMedia.Count();
while (0 < count) {
nsString* medium = (nsString*)mMedia.ElementAt(--count);
delete medium;
}
if (mFirstChild.IsNotNull()) {
nsICSSStyleSheet* child = mFirstChild;
while (nsnull != child) {
@ -1084,12 +1110,122 @@ PRInt32 CSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
return matchCount;
}
nsIURL* CSSStyleSheetImpl::GetURL(void)
NS_IMETHODIMP
CSSStyleSheetImpl::GetURL(nsIURL*& aURL) const
{
return mURL.AddRef();
nsIURL* url = mURL;
aURL = mURL;
NS_IF_ADDREF(aURL);
return NS_OK;
}
PRBool CSSStyleSheetImpl::ContainsStyleSheet(nsIURL* aURL)
NS_IMETHODIMP
CSSStyleSheetImpl::GetTitle(nsString& aTitle) const
{
aTitle = mTitle;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::SetTitle(const nsString& aTitle)
{
mTitle = aTitle;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetType(nsString& aType) const
{
aType.Truncate();
aType.Append("text/css");
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
{
aCount = mMedia.Count();
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsString& aMedium) const
{
nsString* medium = (nsString*)mMedia.ElementAt(aIndex);
if (nsnull != medium) {
aMedium = *medium;
return NS_OK;
}
aMedium.Truncate();
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
CSSStyleSheetImpl::AppendMedium(const nsString& aMedium)
{
nsString* medium = new nsString(aMedium);
mMedia.AppendElement(medium);
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetEnabled(PRBool& aEnabled) const
{
aEnabled = ((PR_TRUE == mDisabled) ? PR_FALSE : PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::SetEnabled(PRBool aEnabled)
{
PRBool oldState = mDisabled;
mDisabled = ((PR_TRUE == aEnabled) ? PR_FALSE : PR_TRUE);
if ((nsnull != mDocument) && (mDisabled != oldState)) {
mDocument->SetStyleSheetDisabledState(this, mDisabled);
}
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
{
NS_IF_ADDREF(mParent);
aParent = mParent;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
{
nsIDocument* doc = mDocument;
CSSStyleSheetImpl* parent = (CSSStyleSheetImpl*)mParent;
while ((nsnull == doc) && (nsnull != parent)) {
doc = parent->mDocument;
parent = (CSSStyleSheetImpl*)(parent->mParent);
}
NS_IF_ADDREF(doc);
aDocument = doc;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
{ // not ref counted
mDocument = aDocument;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::SetOwningNode(nsIDOMNode* aOwningNode)
{ // not ref counted
mOwningNode = aOwningNode;
return NS_OK;
}
PRBool CSSStyleSheetImpl::ContainsStyleSheet(nsIURL* aURL) const
{
NS_PRECONDITION(nsnull != aURL, "null arg");
@ -1182,7 +1318,7 @@ void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
aRule->SetStyleSheet(this);
}
PRInt32 CSSStyleSheetImpl::StyleRuleCount(void)
PRInt32 CSSStyleSheetImpl::StyleRuleCount(void) const
{
if (mOrderedRules.IsNotNull()) {
return mOrderedRules->Count();
@ -1190,7 +1326,7 @@ PRInt32 CSSStyleSheetImpl::StyleRuleCount(void)
return 0;
}
nsresult CSSStyleSheetImpl::GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule)
nsresult CSSStyleSheetImpl::GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule) const
{
nsresult result = NS_ERROR_ILLEGAL_VALUE;
@ -1206,7 +1342,7 @@ nsresult CSSStyleSheetImpl::GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRu
return result;
}
PRInt32 CSSStyleSheetImpl::StyleSheetCount()
PRInt32 CSSStyleSheetImpl::StyleSheetCount(void) const
{
// 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
@ -1223,7 +1359,7 @@ PRInt32 CSSStyleSheetImpl::StyleSheetCount()
return count;
}
nsresult CSSStyleSheetImpl::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet)
nsresult CSSStyleSheetImpl::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const
{
// 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
@ -1243,13 +1379,6 @@ nsresult CSSStyleSheetImpl::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& a
return NS_OK;
}
void CSSStyleSheetImpl::SetDocument(nsIDocument *aDocument)
{
// This reference is not reference counted and should not be
// released. The document will tell us when it goes away.
mDocument = aDocument;
}
void CSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
{
nsAutoString buffer;
@ -1303,6 +1432,15 @@ void CSSStyleSheetImpl::BuildHash(void)
}
}
// nsIDOMStyleSheet interface
NS_IMETHODIMP
CSSStyleSheetImpl::GetType(nsString& aType)
{
aType.Truncate();
aType.Append("text/css");
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetDisabled(PRBool* aDisabled)
{
@ -1313,13 +1451,13 @@ CSSStyleSheetImpl::GetDisabled(PRBool* aDisabled)
NS_IMETHODIMP
CSSStyleSheetImpl::SetDisabled(PRBool aDisabled)
{
if ((nsnull != mDocument) && (mDisabled != aDisabled)) {
mDocument->SetStyleSheetDisabledState(this, aDisabled);
}
PRBool oldState = mDisabled;
mDisabled = aDisabled;
if ((nsnull != mDocument) && (mDisabled != oldState)) {
mDocument->SetStyleSheetDisabledState(this, mDisabled);
}
return NS_OK;
}
@ -1332,18 +1470,18 @@ CSSStyleSheetImpl::GetReadOnly(PRBool* aReadOnly)
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetOwningElement(nsIDOMHTMLElement** aOwningElement)
CSSStyleSheetImpl::GetOwningNode(nsIDOMNode** aOwningNode)
{
// XXX TBI
*aOwningElement = nsnull;
NS_IF_ADDREF(mOwningNode);
*aOwningNode = mOwningNode;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aParentStyleSheet)
CSSStyleSheetImpl::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
{
if (nsnull != mParent) {
return mParent->QueryInterface(kIDOMCSSStyleSheetIID, (void **)aParentStyleSheet);
return mParent->QueryInterface(kIDOMStyleSheetIID, (void **)aParentStyleSheet);
}
else {
*aParentStyleSheet = nsnull;
@ -1364,32 +1502,31 @@ CSSStyleSheetImpl::GetHref(nsString& aHref)
return NS_OK;
}
NS_IMETHODIMP
NS_IMETHODIMP
CSSStyleSheetImpl::GetTitle(nsString& aTitle)
{
// XX TBI
aTitle = mTitle;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetImports(nsIDOMStyleSheetCollection** aImports)
NS_IMETHODIMP
CSSStyleSheetImpl::GetMedia(nsString& aMedia)
{
if (nsnull == mImportsCollection) {
mImportsCollection = new CSSImportsCollectionImpl(this);
if (nsnull == mImportsCollection) {
return NS_ERROR_OUT_OF_MEMORY;
aMedia.Truncate();
PRInt32 count = mMedia.Count();
PRInt32 index = 0;
while (index < count) {
nsString* medium = (nsString*)mMedia.ElementAt(index++);
aMedia.Append(*medium);
if (index < count) {
aMedia.Append(", ");
}
NS_ADDREF(mImportsCollection);
}
*aImports = mImportsCollection;
NS_ADDREF(mImportsCollection);
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetRules(nsIDOMCSSStyleRuleCollection** aRules)
CSSStyleSheetImpl::GetCssRules(nsIDOMCSSStyleRuleCollection** aCssRules)
{
if (nsnull == mRuleCollection) {
mRuleCollection = new CSSStyleRuleCollectionImpl(this);
@ -1399,37 +1536,31 @@ CSSStyleSheetImpl::GetRules(nsIDOMCSSStyleRuleCollection** aRules)
NS_ADDREF(mRuleCollection);
}
*aRules = mRuleCollection;
*aCssRules = mRuleCollection;
NS_ADDREF(mRuleCollection);
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::AddRule(const nsString& aSelector,
const nsString& aDeclaration,
PRUint32 aIndex,
PRUint32* aReturn)
CSSStyleSheetImpl::InsertRule(const nsString& aRule,
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(" } ");
nsAutoString str(aRule);
nsIUnicharInputStream* input = nsnull;
result = NS_NewStringUnicharInputStream(&input, &str);
if (NS_OK == result) {
nsIStyleSheet *tmp;
nsICSSStyleSheet* 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_ASSERTION(tmp == this, "parser incorrectly created a new stylesheet");
NS_RELEASE(tmp);
NS_RELEASE(input);
*aReturn = mOrderedRules->Count();
}
@ -1441,21 +1572,9 @@ CSSStyleSheetImpl::AddRule(const nsString& aSelector,
}
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)
CSSStyleSheetImpl::DeleteRule(PRUint32 aIndex)
{
// XXX TBI: handle @rule types
nsICSSStyleRule *rule;
rule = (nsICSSStyleRule *)mOrderedRules->ElementAt(aIndex);
@ -1469,36 +1588,6 @@ CSSStyleSheetImpl::RemoveRule(PRUint32 aIndex)
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)
{

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

@ -37,6 +37,7 @@ nsDOMCSSDeclaration::~nsDOMCSSDeclaration()
NS_IMPL_ADDREF(nsDOMCSSDeclaration);
NS_IMPL_RELEASE(nsDOMCSSDeclaration);
static NS_DEFINE_IID(kIDOMCSS2PropertiesIID, NS_IDOMCSS2PROPERTIES_IID);
static NS_DEFINE_IID(kIDOMCSSStyleDeclarationIID, NS_IDOMCSSSTYLEDECLARATION_IID);
static NS_DEFINE_IID(kICSSStyleRuleIID, NS_ICSS_STYLE_RULE_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
@ -50,6 +51,12 @@ nsDOMCSSDeclaration::QueryInterface(REFNSIID aIID,
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIDOMCSS2PropertiesIID)) {
nsIDOMCSS2Properties *tmp = this;
AddRef();
*aInstancePtr = (void*) tmp;
return NS_OK;
}
if (aIID.Equals(kIDOMCSSStyleDeclarationIID)) {
nsIDOMCSSStyleDeclaration *tmp = this;
AddRef();
@ -83,12 +90,12 @@ nsDOMCSSDeclaration::GetScriptObject(nsIScriptContext* aContext,
res = GetParent(&parent);
if (NS_OK == res) {
nsISupports *supports = (nsISupports *)(nsIDOMCSSStyleDeclaration *)this;
nsISupports *supports = (nsISupports *)(nsIDOMCSS2Properties *)this;
// XXX Should be done through factory
res = NS_NewScriptCSSStyleDeclaration(aContext,
supports,
parent,
(void**)&mScriptObject);
res = NS_NewScriptCSS2Properties(aContext,
supports,
parent,
(void**)&mScriptObject);
NS_RELEASE(parent);
}
}
@ -104,6 +111,20 @@ nsDOMCSSDeclaration::SetScriptObject(void* aScriptObject)
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetCssText(nsString& aCssText)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSDeclaration::SetCssText(const nsString& aCssText)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetLength(PRUint32* aLength)
{
@ -649,6 +670,18 @@ nsDOMCSSDeclaration::SetCounterReset(const nsString& aCounterReset)
return SetProperty("counter-reset", aCounterReset, "");
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetCssFloat(nsString& aCssFloat)
{
return GetPropertyValue("float", aCssFloat);
}
NS_IMETHODIMP
nsDOMCSSDeclaration::SetCssFloat(const nsString& aCssFloat)
{
return SetProperty("float", aCssFloat, "");
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetCue(nsString& aCue)
{
@ -745,18 +778,6 @@ nsDOMCSSDeclaration::SetEmptyCells(const nsString& aEmptyCells)
return SetProperty("empty-cells", aEmptyCells, "");
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetStyleFloat(nsString& aStyleFloat)
{
return GetPropertyValue("style-float", aStyleFloat);
}
NS_IMETHODIMP
nsDOMCSSDeclaration::SetStyleFloat(const nsString& aStyleFloat)
{
return SetProperty("style-float", aStyleFloat, "");
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetFont(nsString& aFont)
{

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

@ -20,12 +20,12 @@
#define nsDOMCSSSDeclaration_h___
#include "nsISupports.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMCSS2Properties.h"
#include "nsIScriptObjectOwner.h"
class nsICSSDeclaration;
class nsDOMCSSDeclaration : public nsIDOMCSSStyleDeclaration,
class nsDOMCSSDeclaration : public nsIDOMCSS2Properties,
public nsIScriptObjectOwner
{
public:
@ -34,6 +34,8 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_IDOMCSSSTYLEDECLARATION
NS_DECL_IDOMCSS2PROPERTIES
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);

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

@ -17,6 +17,7 @@
*/
#include "nsIHTMLAttributes.h"
#include "nsIHTMLStyleSheet.h"
#include "nsIStyleRule.h"
#include "nsString.h"
#include "nsISupportsArray.h"
@ -171,7 +172,7 @@ public:
void* operator new(size_t size, nsIArena* aArena);
void operator delete(void* ptr);
HTMLAttributesImpl(nsMapAttributesFunc aMapFunc);
HTMLAttributesImpl(nsIHTMLStyleSheet* aSheet, nsMapAttributesFunc aMapFunc);
HTMLAttributesImpl(const HTMLAttributesImpl& aCopy);
~HTMLAttributesImpl(void);
@ -212,6 +213,8 @@ public:
// nsIStyleRule
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
NS_IMETHOD SetStyleSheet(nsIHTMLStyleSheet* aSheet);
// Strength is an out-of-band weighting, always 0 here
NS_IMETHOD GetStrength(PRInt32& aStrength);
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
@ -231,11 +234,12 @@ protected:
PRUint32 mInHeap : 1;
PRUint32 mRefCnt : 31;
PRInt32 mContentRefCount;
PRInt32 mCount;
HTMLAttribute mFirst;
nsIAtom* mID;
nsIAtom* mClass;
nsIHTMLStyleSheet* mSheet;
PRInt32 mContentRefCount;
PRInt32 mCount;
HTMLAttribute mFirst;
nsIAtom* mID;
nsIAtom* mClass;
nsMapAttributesFunc mMapper;
#ifdef DEBUG_REFS
@ -285,8 +289,10 @@ void HTMLAttributesImpl::operator delete(void* ptr)
}
HTMLAttributesImpl::HTMLAttributesImpl(nsMapAttributesFunc aMapFunc)
: mFirst(),
HTMLAttributesImpl::HTMLAttributesImpl(nsIHTMLStyleSheet* aSheet,
nsMapAttributesFunc aMapFunc)
: mSheet(aSheet),
mFirst(),
mCount(0),
mID(nsnull),
mClass(nsnull),
@ -302,7 +308,8 @@ HTMLAttributesImpl::HTMLAttributesImpl(nsMapAttributesFunc aMapFunc)
}
HTMLAttributesImpl::HTMLAttributesImpl(const HTMLAttributesImpl& aCopy)
: mFirst(aCopy.mFirst),
: mSheet(aCopy.mSheet),
mFirst(aCopy.mFirst),
mCount(aCopy.mCount),
mID(aCopy.mID),
mClass(aCopy.mClass),
@ -803,6 +810,21 @@ HTMLAttributesImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPre
return NS_OK;
}
NS_IMETHODIMP
HTMLAttributesImpl::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
NS_IMETHODIMP
HTMLAttributesImpl::SetStyleSheet(nsIHTMLStyleSheet* aSheet)
{ // this is not ref-counted, sheet sets to null when it goes away
mSheet = aSheet;
return NS_OK;
}
// Strength is an out-of-band weighting, always 0 here
NS_IMETHODIMP
HTMLAttributesImpl::GetStrength(PRInt32& aStrength)
@ -840,13 +862,14 @@ HTMLAttributesImpl::List(FILE* out, PRInt32 aIndent) const
}
extern NS_HTML nsresult
NS_NewHTMLAttributes(nsIHTMLAttributes** aInstancePtrResult, nsMapAttributesFunc aMapFunc)
NS_NewHTMLAttributes(nsIHTMLAttributes** aInstancePtrResult, nsIHTMLStyleSheet* aSheet,
nsMapAttributesFunc aMapFunc)
{
if (aInstancePtrResult == nsnull) {
return NS_ERROR_NULL_POINTER;
}
HTMLAttributesImpl *it = new HTMLAttributesImpl(aMapFunc);
HTMLAttributesImpl *it = new HTMLAttributesImpl(aSheet, aMapFunc);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;

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

@ -29,6 +29,7 @@
#include "nsICSSStyleRule.h"
#include "nsIStyleContext.h"
#include "nsIPresContext.h"
#include "nsIDocument.h"
static NS_DEFINE_IID(kIHTMLCSSStyleSheetIID, NS_IHTML_CSS_STYLE_SHEET_IID);
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
@ -37,22 +38,26 @@ static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
class BodyFixupRule : public nsIStyleRule {
public:
BodyFixupRule();
BodyFixupRule(nsIHTMLCSSStyleSheet* aSheet);
~BodyFixupRule();
NS_DECL_ISUPPORTS
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aValue) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
// Strength is an out-of-band weighting, always 0 here
NS_IMETHOD GetStrength(PRInt32& aStrength);
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
nsIHTMLCSSStyleSheet* mSheet;
};
BodyFixupRule::BodyFixupRule()
BodyFixupRule::BodyFixupRule(nsIHTMLCSSStyleSheet* aSheet)
: mSheet(aSheet)
{
NS_INIT_REFCNT();
}
@ -77,6 +82,14 @@ BodyFixupRule::HashValue(PRUint32& aValue) const
return NS_OK;
}
NS_IMETHODIMP
BodyFixupRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
// Strength is an out-of-band weighting, always MaxInt here
NS_IMETHODIMP
BodyFixupRule::GetStrength(PRInt32& aStrength)
@ -115,12 +128,27 @@ public:
void* operator new(size_t size, nsIArena* aArena);
void operator delete(void* ptr);
HTMLCSSStyleSheetImpl(nsIURL* aURL);
HTMLCSSStyleSheetImpl(nsIURL* aURL, nsIDocument* aDocument);
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
// basic style sheet data
NS_IMETHOD GetURL(nsIURL*& aURL) const;
NS_IMETHOD GetTitle(nsString& aTitle) const;
NS_IMETHOD GetType(nsString& aType) const;
NS_IMETHOD GetMediumCount(PRInt32& aCount) const;
NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsString& aMedium) const;
NS_IMETHOD GetEnabled(PRBool& aEnabled) const;
NS_IMETHOD SetEnabled(PRBool aEnabled);
// style sheet owner info
NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // will be null
NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aParentContext,
@ -132,8 +160,6 @@ public:
nsIStyleContext* aParentContext,
nsISupportsArray* aResults);
virtual nsIURL* GetURL(void);
// XXX style rule enumerations
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
@ -150,8 +176,9 @@ protected:
PRUint32 mInHeap : 1;
PRUint32 mRefCnt : 31;
nsIURL* mURL;
nsIStyleRule* mBodyRule;
nsIURL* mURL;
nsIDocument* mDocument;
BodyFixupRule* mBodyRule;
};
@ -191,9 +218,10 @@ void HTMLCSSStyleSheetImpl::operator delete(void* ptr)
HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL)
HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL, nsIDocument* aDocument)
: nsIHTMLCSSStyleSheet(),
mURL(aURL),
mDocument(aDocument),
mBodyRule(nsnull)
{
NS_INIT_REFCNT();
@ -203,7 +231,10 @@ HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL)
HTMLCSSStyleSheetImpl::~HTMLCSSStyleSheetImpl()
{
NS_RELEASE(mURL);
NS_IF_RELEASE(mBodyRule);
if (nsnull != mBodyRule) {
mBodyRule->mSheet = nsnull;
NS_RELEASE(mBodyRule);
}
}
NS_IMPL_ADDREF(HTMLCSSStyleSheetImpl)
@ -274,11 +305,8 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
htmlContent->GetTag(tag);
if (tag == nsHTMLAtoms::body) {
if (nsnull == mBodyRule) {
BodyFixupRule* bodyRule = new BodyFixupRule();
if ((nsnull != bodyRule) &&
(NS_OK != bodyRule->QueryInterface(kIStyleRuleIID, (void**)&mBodyRule))) {
delete bodyRule;
}
mBodyRule = new BodyFixupRule(this);
NS_IF_ADDREF(mBodyRule);
}
if (nsnull != mBodyRule) {
aResults->AppendElement(mBodyRule);
@ -301,10 +329,78 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
return 0;
}
nsIURL* HTMLCSSStyleSheetImpl::GetURL(void)
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetURL(nsIURL*& aURL) const
{
NS_ADDREF(mURL);
return mURL;
NS_IF_ADDREF(mURL);
aURL = mURL;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetTitle(nsString& aTitle) const
{
aTitle.Truncate();
aTitle.Append("Internal HTML/CSS Style Sheet");
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetType(nsString& aType) const
{
aType.Truncate();
aType.Append("text/html");
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
{
aCount = 0;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsString& aMedium) const
{
aMedium.Truncate();
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetEnabled(PRBool& aEnabled) const
{
aEnabled = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::SetEnabled(PRBool aEnabled)
{ // these can't be disabled
return NS_OK;
}
// style sheet owner info
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
{
aParent = nsnull;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
{
NS_IF_ADDREF(mDocument);
aDocument = mDocument;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
{
mDocument = aDocument;
return NS_OK;
}
void HTMLCSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
@ -322,13 +418,14 @@ void HTMLCSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
}
NS_HTML nsresult
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult, nsIURL* aURL)
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult, nsIURL* aURL,
nsIDocument* aDocument)
{
if (aInstancePtrResult == nsnull) {
return NS_ERROR_NULL_POINTER;
}
HTMLCSSStyleSheetImpl* it = new HTMLCSSStyleSheetImpl(aURL);
HTMLCSSStyleSheetImpl* it = new HTMLCSSStyleSheetImpl(aURL, aDocument);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;

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

@ -53,13 +53,14 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
class HTMLAnchorRule : public nsIStyleRule {
public:
HTMLAnchorRule();
HTMLAnchorRule(nsIHTMLStyleSheet* aSheet);
~HTMLAnchorRule();
NS_DECL_ISUPPORTS
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aValue) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
// Strength is an out-of-band weighting, always 0 here
NS_IMETHOD GetStrength(PRInt32& aStrength);
@ -67,10 +68,12 @@ public:
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
nscolor mColor;
nscolor mColor;
nsIHTMLStyleSheet* mSheet;
};
HTMLAnchorRule::HTMLAnchorRule()
HTMLAnchorRule::HTMLAnchorRule(nsIHTMLStyleSheet* aSheet)
: mSheet(aSheet)
{
NS_INIT_REFCNT();
}
@ -95,6 +98,14 @@ HTMLAnchorRule::HashValue(PRUint32& aValue) const
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
// Strength is an out-of-band weighting, always 0 here
NS_IMETHODIMP
HTMLAnchorRule::GetStrength(PRInt32& aStrength)
@ -201,12 +212,28 @@ public:
void* operator new(size_t size, nsIArena* aArena);
void operator delete(void* ptr);
HTMLStyleSheetImpl(nsIURL* aURL);
HTMLStyleSheetImpl(nsIURL* aURL, nsIDocument* aDocument);
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
// nsIStyleSheet api
NS_IMETHOD GetURL(nsIURL*& aURL) const;
NS_IMETHOD GetTitle(nsString& aTitle) const;
NS_IMETHOD GetType(nsString& aType) const;
NS_IMETHOD GetMediumCount(PRInt32& aCount) const;
NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsString& aMedium) const;
NS_IMETHOD GetEnabled(PRBool& aEnabled) const;
NS_IMETHOD SetEnabled(PRBool aEnabled);
// style sheet owner info
NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // will be null
NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
NS_IMETHOD SetOwningDocument(nsIDocument* aDocumemt);
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aParentContext,
@ -218,8 +245,6 @@ public:
nsIStyleContext* aParentContext,
nsISupportsArray* aResults);
virtual nsIURL* GetURL(void);
NS_IMETHOD SetLinkColor(nscolor aColor);
NS_IMETHOD SetActiveLinkColor(nscolor aColor);
NS_IMETHOD SetVisitedLinkColor(nscolor aColor);
@ -278,7 +303,17 @@ public:
nsIAtom* aAttribute,
PRInt32 aHint);
// XXX style rule enumerations
// Style change notifications
NS_IMETHOD StyleRuleChanged(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint); // See nsStyleConsts fot hint values
NS_IMETHOD StyleRuleAdded(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD StyleRuleRemoved(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
@ -361,11 +396,12 @@ protected:
PRUint32 mInHeap : 1;
PRUint32 mRefCnt : 31;
nsIURL* mURL;
HTMLAnchorRule* mLinkRule;
HTMLAnchorRule* mVisitedRule;
HTMLAnchorRule* mActiveRule;
nsHashtable mAttrTable;
nsIURL* mURL;
nsIDocument* mDocument;
HTMLAnchorRule* mLinkRule;
HTMLAnchorRule* mVisitedRule;
HTMLAnchorRule* mActiveRule;
nsHashtable mAttrTable;
nsIHTMLAttributes* mRecycledAttrs;
};
@ -406,9 +442,10 @@ void HTMLStyleSheetImpl::operator delete(void* ptr)
HTMLStyleSheetImpl::HTMLStyleSheetImpl(nsIURL* aURL)
HTMLStyleSheetImpl::HTMLStyleSheetImpl(nsIURL* aURL, nsIDocument* aDocument)
: nsIHTMLStyleSheet(),
mURL(aURL),
mDocument(aDocument),
mLinkRule(nsnull),
mVisitedRule(nsnull),
mActiveRule(nsnull),
@ -421,9 +458,18 @@ HTMLStyleSheetImpl::HTMLStyleSheetImpl(nsIURL* aURL)
HTMLStyleSheetImpl::~HTMLStyleSheetImpl()
{
NS_RELEASE(mURL);
NS_IF_RELEASE(mLinkRule);
NS_IF_RELEASE(mVisitedRule);
NS_IF_RELEASE(mActiveRule);
if (nsnull != mLinkRule) {
mLinkRule->mSheet = nsnull;
NS_RELEASE(mLinkRule);
}
if (nsnull != mVisitedRule) {
mVisitedRule->mSheet = nsnull;
NS_RELEASE(mVisitedRule);
}
if (nsnull != mActiveRule) {
mActiveRule->mSheet = nsnull;
NS_RELEASE(mActiveRule);
}
NS_IF_RELEASE(mRecycledAttrs);
}
@ -556,17 +602,85 @@ PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
}
nsIURL* HTMLStyleSheetImpl::GetURL(void)
// nsIStyleSheet api
NS_IMETHODIMP
HTMLStyleSheetImpl::GetURL(nsIURL*& aURL) const
{
NS_ADDREF(mURL);
return mURL;
NS_IF_ADDREF(mURL);
aURL = mURL;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetTitle(nsString& aTitle) const
{
aTitle.Truncate();
aTitle.Append("Internal HTML Style Sheet");
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetType(nsString& aType) const
{
aType.Truncate();
aType.Append("text/html");
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
{
aCount = 0;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsString& aMedium) const
{
aMedium.Truncate();
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetEnabled(PRBool& aEnabled) const
{
aEnabled = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::SetEnabled(PRBool aEnabled)
{ // these can't be disabled
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
{
aParent = nsnull;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
{
NS_IF_ADDREF(mDocument);
aDocument = mDocument;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
{
mDocument = aDocument;
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetLinkColor(nscolor aColor)
{
if (nsnull == mLinkRule) {
mLinkRule = new HTMLAnchorRule();
mLinkRule = new HTMLAnchorRule(this);
if (nsnull == mLinkRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -579,7 +693,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetLinkColor(nscolor aColor)
NS_IMETHODIMP HTMLStyleSheetImpl::SetActiveLinkColor(nscolor aColor)
{
if (nsnull == mActiveRule) {
mActiveRule = new HTMLAnchorRule();
mActiveRule = new HTMLAnchorRule(this);
if (nsnull == mActiveRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -592,7 +706,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetActiveLinkColor(nscolor aColor)
NS_IMETHODIMP HTMLStyleSheetImpl::SetVisitedLinkColor(nscolor aColor)
{
if (nsnull == mVisitedRule) {
mVisitedRule = new HTMLAnchorRule();
mVisitedRule = new HTMLAnchorRule(this);
if (nsnull == mVisitedRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -712,7 +826,7 @@ HTMLStyleSheetImpl::EnsureSingleAttributes(nsIHTMLAttributes*& aAttributes,
aSingleAttrs->SetMappingFunction(aMapFunc);
}
else {
result = NS_NewHTMLAttributes(&aSingleAttrs, aMapFunc);
result = NS_NewHTMLAttributes(&aSingleAttrs, this, aMapFunc);
}
}
else {
@ -2403,6 +2517,77 @@ HTMLStyleSheetImpl::AttributeChanged(nsIPresContext* aPresContext,
return result;
}
// Style change notifications
NS_IMETHODIMP
HTMLStyleSheetImpl::StyleRuleChanged(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint)
{
nsIPresShell* shell = aPresContext->GetShell();
nsIFrame* frame = shell->GetRootFrame();
PRBool reframe = PR_FALSE;
PRBool reflow = PR_FALSE;
PRBool render = PR_FALSE;
PRBool restyle = PR_FALSE;
switch (aHint) {
default:
case NS_STYLE_HINT_UNKNOWN:
case NS_STYLE_HINT_FRAMECHANGE:
reframe = PR_TRUE;
case NS_STYLE_HINT_REFLOW:
reflow = PR_TRUE;
case NS_STYLE_HINT_VISUAL:
render = PR_TRUE;
case NS_STYLE_HINT_CONTENT:
restyle = PR_TRUE;
break;
case NS_STYLE_HINT_AURAL:
break;
}
if (restyle) {
nsIStyleContext* sc;
frame->GetStyleContext(sc);
sc->RemapStyle(aPresContext);
NS_RELEASE(sc);
}
// XXX hack, skip the root and scrolling frames
frame->FirstChild(nsnull, frame);
frame->FirstChild(nsnull, frame);
if (reframe) {
NS_NOTYETIMPLEMENTED("frame change reflow");
}
else if (reflow) {
StyleChangeReflow(aPresContext, frame, nsnull);
}
else if (render) {
ApplyRenderingChangeToTree(aPresContext, frame);
}
NS_RELEASE(shell);
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::StyleRuleAdded(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::StyleRuleRemoved(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
return NS_OK;
}
void HTMLStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
{
@ -2419,13 +2604,14 @@ void HTMLStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
}
NS_HTML nsresult
NS_NewHTMLStyleSheet(nsIHTMLStyleSheet** aInstancePtrResult, nsIURL* aURL)
NS_NewHTMLStyleSheet(nsIHTMLStyleSheet** aInstancePtrResult, nsIURL* aURL,
nsIDocument* aDocument)
{
if (aInstancePtrResult == nsnull) {
return NS_ERROR_NULL_POINTER;
}
HTMLStyleSheetImpl *it = new HTMLStyleSheetImpl(aURL);
HTMLStyleSheetImpl *it = new HTMLStyleSheetImpl(aURL, aDocument);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;

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

@ -25,7 +25,7 @@ class nsIAtom;
class nsIArena;
class nsString;
class nsICSSDeclaration;
class nsIStyleSheet;
class nsICSSStyleSheet;
struct nsCSSSelector {
public:
@ -66,8 +66,7 @@ public:
virtual nsIStyleRule* GetImportantRule(void) = 0;
virtual nsIStyleSheet* GetStyleSheet(void) = 0;
virtual void SetStyleSheet(nsIStyleSheet *aSheet) = 0;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet) = 0;
};
extern NS_HTML nsresult

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

@ -25,6 +25,7 @@
class nsIAtom;
class nsISizeOfHandler;
class nsISupportsArray;
class nsIHTMLStyleSheet;
// IID for the nsIHTMLAttributes interface {a18f85f0-c058-11d1-8031-006008159b5a}
@ -66,6 +67,7 @@ public:
NS_IMETHOD Clone(nsIHTMLAttributes** aInstancePtrResult) = 0;
NS_IMETHOD Reset(void) = 0;
NS_IMETHOD SetMappingFunction(nsMapAttributesFunc aMapFunc) = 0;
NS_IMETHOD SetStyleSheet(nsIHTMLStyleSheet* aSheet) = 0;
/**
* Add this object's size information to the sizeof handler.
@ -76,7 +78,9 @@ public:
};
extern NS_HTML nsresult
NS_NewHTMLAttributes(nsIHTMLAttributes** aInstancePtrResult, nsMapAttributesFunc aMapFunc);
NS_NewHTMLAttributes(nsIHTMLAttributes** aInstancePtrResult,
nsIHTMLStyleSheet* aSheet,
nsMapAttributesFunc aMapFunc);
#endif /* nsIHTMLAttributes_h___ */

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

@ -31,6 +31,7 @@ public:
};
extern NS_HTML nsresult
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult, nsIURL* aURL);
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult, nsIURL* aURL,
nsIDocument* aDocument);
#endif /* nsIHTMLCSSStyleSheet_h___ */

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

@ -18,7 +18,6 @@
*/
#include "nsXMLContentSink.h"
#include "nsIStyleSheet.h"
#include "nsIUnicharInputStream.h"
#include "nsIDocument.h"
#include "nsIXMLDocument.h"
@ -38,6 +37,7 @@
#include "nsVoidArray.h"
#include "nsCRT.h"
#include "nsICSSParser.h"
#include "nsICSSStyleSheet.h"
#include "nsHTMLAtoms.h"
#include "nsIScriptContext.h"
#include "nsIScriptContextOwner.h"
@ -695,36 +695,19 @@ nsXMLContentSink::AddComment(const nsIParserNode& aNode)
// XXX Borrowed from HTMLContentSink. Should be shared.
nsresult
nsXMLContentSink::LoadStyleSheet(nsIURL* aURL,
nsIUnicharInputStream* aUIN,
PRBool aInline)
nsIUnicharInputStream* aUIN)
{
/* XXX use repository */
nsICSSParser* parser;
nsresult rv = NS_NewCSSParser(&parser);
if (NS_OK == rv) {
if (aInline && (nsnull != mStyleSheet)) {
parser->SetStyleSheet(mStyleSheet);
// XXX we do probably need to trigger a style change reflow
// when we are finished if this is adding data to the same sheet
}
nsIStyleSheet* sheet = nsnull;
nsICSSStyleSheet* sheet = nsnull;
// XXX note: we are ignoring rv until the error code stuff in the
// input routines is converted to use nsresult's
parser->Parse(aUIN, aURL, sheet);
if (nsnull != sheet) {
if (aInline) {
if (nsnull == mStyleSheet) {
// Add in the sheet the first time; if we update the sheet
// with new data (mutliple style tags in the same document)
// then the sheet will be updated by the css parser and
// therefore we don't need to add it to the document)
mDocument->AddStyleSheet(sheet);
mStyleSheet = sheet;
}
}
else {
mDocument->AddStyleSheet(sheet);
}
mDocument->AddStyleSheet(sheet);
NS_RELEASE(sheet);
rv = NS_OK;
} else {
rv = NS_ERROR_OUT_OF_MEMORY;/* XXX */
@ -827,7 +810,7 @@ nsXMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
return result;
}
result = LoadStyleSheet(url, uin, PR_FALSE);
result = LoadStyleSheet(url, uin);
NS_RELEASE(uin);
NS_RELEASE(url);
}

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

@ -32,7 +32,6 @@ class nsIContent;
class nsVoidArray;
class nsIXMLDocument;
class nsIUnicharInputStream;
class nsIStyleSheet;
typedef enum {
eXMLContentSinkState_InProlog,
@ -79,8 +78,7 @@ protected:
void StartLayout();
nsresult LoadStyleSheet(nsIURL* aURL,
nsIUnicharInputStream* aUIN,
PRBool aInline);
nsIUnicharInputStream* aUIN);
nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
PRBool* aDidFlush=nsnull);
@ -119,7 +117,6 @@ protected:
PRInt32 mNestLevel;
nsVoidArray* mContentStack;
nsIStyleSheet* mStyleSheet;
nsScrollPreference mOriginalScrollPreference;
PRUnichar* mText;

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

@ -85,7 +85,10 @@ nsXMLDocument::~nsXMLDocument()
}
mNameSpaces = nsnull;
}
NS_IF_RELEASE(mAttrStyleSheet);
if (nsnull != mAttrStyleSheet) {
mAttrStyleSheet->SetOwningDocument(nsnull);
NS_RELEASE(mAttrStyleSheet);
}
if (nsnull != mProlog) {
delete mProlog;
}
@ -136,6 +139,11 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl,
return rv;
}
if (nsnull != mAttrStyleSheet) {
mAttrStyleSheet->SetOwningDocument(nsnull);
NS_RELEASE(mAttrStyleSheet);
}
nsIWebShell* webShell;
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
@ -154,7 +162,7 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl,
if (NS_OK == rv) {
// For the HTML content within a document
if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aUrl)) {
if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aUrl, this)) {
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
}

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

@ -21,6 +21,7 @@
#include "nsIDocument.h"
#include "nsIDocumentObserver.h"
#include "nsIStyleSet.h"
#include "nsICSSStyleSheet.h" // XXX for UA sheet loading hack, can this go away please?
#include "nsIStyleContext.h"
#include "nsFrame.h"
#include "nsIReflowCommand.h"
@ -193,6 +194,16 @@ public:
NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aDisabled);
NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint);
NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument);
// nsIPresShell
@ -232,6 +243,8 @@ public:
protected:
~PresShell();
nsresult ReconstructFrames(void);
#ifdef NS_DEBUG
void VerifyIncrementalReflow();
#endif
@ -902,17 +915,8 @@ PresShell::ContentRemoved(nsIDocument *aDocument,
return rv;
}
NS_IMETHODIMP
PresShell::StyleSheetAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet)
{
return NS_OK;
}
NS_IMETHODIMP
PresShell::StyleSheetDisabledStateChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aDisabled)
nsresult
PresShell::ReconstructFrames(void)
{
nsresult rv = NS_OK;
if (nsnull != mRootFrame) {
@ -934,6 +938,57 @@ PresShell::StyleSheetDisabledStateChanged(nsIDocument *aDocument,
return rv;
}
NS_IMETHODIMP
PresShell::StyleSheetAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet)
{
return ReconstructFrames();
}
NS_IMETHODIMP
PresShell::StyleSheetDisabledStateChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aDisabled)
{
return ReconstructFrames();
}
NS_IMETHODIMP
PresShell::StyleRuleChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint)
{
EnterReflowLock();
nsresult rv = mStyleSet->StyleRuleChanged(mPresContext, aStyleSheet,
aStyleRule, aHint);
ExitReflowLock();
return rv;
}
NS_IMETHODIMP
PresShell::StyleRuleAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
EnterReflowLock();
nsresult rv = mStyleSet->StyleRuleAdded(mPresContext, aStyleSheet, aStyleRule);
ExitReflowLock();
return rv;
}
NS_IMETHODIMP
PresShell::StyleRuleRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
EnterReflowLock();
nsresult rv = mStyleSet->StyleRuleRemoved(mPresContext, aStyleSheet, aStyleRule);
ExitReflowLock();
return rv;
}
NS_IMETHODIMP
PresShell::DocumentWillBeDestroyed(nsIDocument *aDocument)
{
@ -1116,8 +1171,8 @@ NS_IMETHODIMP PresShell :: ResizeReflow(nsIView *aView, nscoord aWidth, nscoord
#include "nsIScrollableView.h"
#include "nsIDeviceContext.h"
#include "nsIURL.h"
#include "nsICSSParser.h"
#include "nsIStyleSheet.h"
//#include "nsICSSParser.h"
//#include "nsIStyleSheet.h"
static NS_DEFINE_IID(kViewManagerCID, NS_VIEW_MANAGER_CID);
static NS_DEFINE_IID(kIViewManagerIID, NS_IVIEWMANAGER_IID);

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

@ -93,6 +93,16 @@ public:
NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aDisabled) { return NS_OK; }
NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint) { return NS_OK; }
NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) { return NS_OK; }
NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) { return NS_OK; }
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument);
protected:

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

@ -123,6 +123,16 @@ public:
NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aDisabled) { return NS_OK; }
NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint) { return NS_OK; }
NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) { return NS_OK; }
NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule) { return NS_OK; }
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument);
// nsIScriptObjectOwner interface
@ -438,12 +448,7 @@ nsDocument::~nsDocument()
index = mStyleSheets.Count();
while (--index >= 0) {
nsIStyleSheet* sheet = (nsIStyleSheet*) mStyleSheets.ElementAt(index);
nsICSSStyleSheet* css;
nsresult rv = sheet->QueryInterface(kICSSStyleSheetIID, (void **)&css);
if (NS_SUCCEEDED(rv)) {
css->SetDocument(nsnull);
NS_RELEASE(css);
}
sheet->SetOwningDocument(nsnull);
NS_RELEASE(sheet);
}
@ -541,12 +546,7 @@ nsDocument::StartDocumentLoad(nsIURL *aURL,
PRInt32 index = mStyleSheets.Count();
while (--index >= 0) {
nsIStyleSheet* sheet = (nsIStyleSheet*) mStyleSheets.ElementAt(index);
nsICSSStyleSheet* css;
nsresult rv = sheet->QueryInterface(kICSSStyleSheetIID, (void **)&css);
if (NS_SUCCEEDED(rv)) {
css->SetDocument(nsnull);
NS_RELEASE(css);
}
sheet->SetOwningDocument(nsnull);
NS_RELEASE(sheet);
}
mStyleSheets.Clear();
@ -718,33 +718,34 @@ void nsDocument::AddStyleSheet(nsIStyleSheet* aSheet)
NS_PRECONDITION(nsnull != aSheet, "null arg");
mStyleSheets.AppendElement(aSheet);
NS_ADDREF(aSheet);
nsICSSStyleSheet* css;
nsresult rv = aSheet->QueryInterface(kICSSStyleSheetIID, (void **)&css);
if (NS_SUCCEEDED(rv)) {
css->SetDocument(this);
NS_RELEASE(css);
}
aSheet->SetOwningDocument(this);
PRInt32 count = mPresShells.Count();
PRInt32 index;
for (index = 0; index < count; index++) {
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
nsIStyleSet* set = shell->GetStyleSet();
if (nsnull != set) {
AddStyleSheetToSet(aSheet, set);
NS_RELEASE(set);
PRBool enabled = PR_TRUE;
aSheet->GetEnabled(enabled);
if (enabled) {
PRInt32 count = mPresShells.Count();
PRInt32 index;
for (index = 0; index < count; index++) {
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
nsIStyleSet* set = shell->GetStyleSet();
if (nsnull != set) {
AddStyleSheetToSet(aSheet, set);
NS_RELEASE(set);
}
}
}
count = mObservers.Count();
for (index = 0; index < count; index++) {
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
observer->StyleSheetAdded(this, aSheet);
// XXX should observers be notified for disabled sheets??? I think not, but I could be wrong
count = mObservers.Count();
for (index = 0; index < count; index++) {
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
observer->StyleSheetAdded(this, aSheet);
}
}
}
void nsDocument::SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
PRBool mDisabled)
PRBool aDisabled)
{
NS_PRECONDITION(nsnull != aSheet, "null arg");
PRInt32 count;
@ -757,7 +758,7 @@ void nsDocument::SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
nsIPresShell* shell = (nsIPresShell*)mPresShells.ElementAt(index);
nsIStyleSet* set = shell->GetStyleSet();
if (nsnull != set) {
if (mDisabled) {
if (aDisabled) {
set->RemoveDocStyleSheet(aSheet);
}
else {
@ -771,7 +772,7 @@ void nsDocument::SetStyleSheetDisabledState(nsIStyleSheet* aSheet,
count = mObservers.Count();
for (index = 0; index < count; index++) {
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers.ElementAt(index);
observer->StyleSheetDisabledStateChanged(this, aSheet, mDisabled);
observer->StyleSheetDisabledStateChanged(this, aSheet, aDisabled);
}
}
@ -929,6 +930,42 @@ nsDocument::AttributeChanged(nsIContent* aChild,
return NS_OK;
}
NS_IMETHODIMP
nsDocument::StyleRuleChanged(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule,
PRInt32 aHint)
{
PRInt32 count = mObservers.Count();
for (PRInt32 i = 0; i < count; i++) {
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
observer->StyleRuleChanged(this, aStyleSheet, aStyleRule, aHint);
}
return NS_OK;
}
NS_IMETHODIMP
nsDocument::StyleRuleAdded(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule)
{
PRInt32 count = mObservers.Count();
for (PRInt32 i = 0; i < count; i++) {
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
observer->StyleRuleAdded(this, aStyleSheet, aStyleRule);
}
return NS_OK;
}
NS_IMETHODIMP
nsDocument::StyleRuleRemoved(nsIStyleSheet* aStyleSheet, nsIStyleRule* aStyleRule)
{
PRInt32 count = mObservers.Count();
for (PRInt32 i = 0; i < count; i++) {
nsIDocumentObserver* observer = (nsIDocumentObserver*)mObservers[i];
observer->StyleRuleRemoved(this, aStyleSheet, aStyleRule);
}
return NS_OK;
}
nsresult nsDocument::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
nsresult res = NS_OK;

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

@ -175,6 +175,14 @@ public:
nsIContent* aChild,
PRInt32 aIndexInContainer);
NS_IMETHOD StyleRuleChanged(nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint); // See nsStyleConsts fot hint values
NS_IMETHOD StyleRuleAdded(nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD StyleRuleRemoved(nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
/**
* Returns the Selection Object
*/

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

@ -87,14 +87,14 @@ public:
nsIStyleContext* aParentContext,
PRBool aForceUnique = PR_FALSE);
NS_IMETHODIMP ConstructFrame(nsIPresContext* aPresContext,
NS_IMETHOD ConstructFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIFrame*& aFrameSubTree);
NS_IMETHOD ReconstructFrames(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIFrame*& aFrameSubTree);
NS_IMETHOD ReconstructFrames(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIFrame* aFrameSubTree);
nsIFrame* aFrameSubTree);
NS_IMETHOD ContentAppended(nsIPresContext* aPresContext,
nsIContent* aContainer,
PRInt32 aNewIndexInContainer);
@ -122,6 +122,18 @@ public:
// xxx style rules enumeration
// Style change notifications
NS_IMETHOD StyleRuleChanged(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint); // See nsStyleConsts fot hint values
NS_IMETHOD StyleRuleAdded(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD StyleRuleRemoved(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0);
private:
@ -727,7 +739,31 @@ StyleSetImpl::AttributeChanged(nsIPresContext* aPresContext,
}
// xxx style rules enumeration
// Style change notifications
NS_IMETHODIMP
StyleSetImpl::StyleRuleChanged(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint)
{
return mFrameConstructor->StyleRuleChanged(aPresContext, aStyleSheet, aStyleRule, aHint);
}
NS_IMETHODIMP
StyleSetImpl::StyleRuleAdded(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
return mFrameConstructor->StyleRuleAdded(aPresContext, aStyleSheet, aStyleRule);
}
NS_IMETHODIMP
StyleSetImpl::StyleRuleRemoved(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
return mFrameConstructor->StyleRuleRemoved(aPresContext, aStyleSheet, aStyleRule);
}
void StyleSetImpl::List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets)
{

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

@ -21,6 +21,7 @@
#include "nsIDocument.h"
#include "nsIDocumentObserver.h"
#include "nsIStyleSet.h"
#include "nsICSSStyleSheet.h" // XXX for UA sheet loading hack, can this go away please?
#include "nsIStyleContext.h"
#include "nsFrame.h"
#include "nsIReflowCommand.h"
@ -193,6 +194,16 @@ public:
NS_IMETHOD StyleSheetDisabledStateChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aDisabled);
NS_IMETHOD StyleRuleChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint);
NS_IMETHOD StyleRuleAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD StyleRuleRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD DocumentWillBeDestroyed(nsIDocument *aDocument);
// nsIPresShell
@ -232,6 +243,8 @@ public:
protected:
~PresShell();
nsresult ReconstructFrames(void);
#ifdef NS_DEBUG
void VerifyIncrementalReflow();
#endif
@ -902,17 +915,8 @@ PresShell::ContentRemoved(nsIDocument *aDocument,
return rv;
}
NS_IMETHODIMP
PresShell::StyleSheetAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet)
{
return NS_OK;
}
NS_IMETHODIMP
PresShell::StyleSheetDisabledStateChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aDisabled)
nsresult
PresShell::ReconstructFrames(void)
{
nsresult rv = NS_OK;
if (nsnull != mRootFrame) {
@ -934,6 +938,57 @@ PresShell::StyleSheetDisabledStateChanged(nsIDocument *aDocument,
return rv;
}
NS_IMETHODIMP
PresShell::StyleSheetAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet)
{
return ReconstructFrames();
}
NS_IMETHODIMP
PresShell::StyleSheetDisabledStateChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
PRBool aDisabled)
{
return ReconstructFrames();
}
NS_IMETHODIMP
PresShell::StyleRuleChanged(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint)
{
EnterReflowLock();
nsresult rv = mStyleSet->StyleRuleChanged(mPresContext, aStyleSheet,
aStyleRule, aHint);
ExitReflowLock();
return rv;
}
NS_IMETHODIMP
PresShell::StyleRuleAdded(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
EnterReflowLock();
nsresult rv = mStyleSet->StyleRuleAdded(mPresContext, aStyleSheet, aStyleRule);
ExitReflowLock();
return rv;
}
NS_IMETHODIMP
PresShell::StyleRuleRemoved(nsIDocument *aDocument,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
EnterReflowLock();
nsresult rv = mStyleSet->StyleRuleRemoved(mPresContext, aStyleSheet, aStyleRule);
ExitReflowLock();
return rv;
}
NS_IMETHODIMP
PresShell::DocumentWillBeDestroyed(nsIDocument *aDocument)
{
@ -1116,8 +1171,8 @@ NS_IMETHODIMP PresShell :: ResizeReflow(nsIView *aView, nscoord aWidth, nscoord
#include "nsIScrollableView.h"
#include "nsIDeviceContext.h"
#include "nsIURL.h"
#include "nsICSSParser.h"
#include "nsIStyleSheet.h"
//#include "nsICSSParser.h"
//#include "nsIStyleSheet.h"
static NS_DEFINE_IID(kViewManagerCID, NS_VIEW_MANAGER_CID);
static NS_DEFINE_IID(kIViewManagerIID, NS_IVIEWMANAGER_IID);

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -197,7 +197,7 @@ static nsresult EnsureWritableAttributes(nsIHTMLContent* aContent,
nsMapAttributesFunc mapFunc;
result = aContent->GetAttributeMappingFunction(mapFunc);
if (NS_OK == result) {
result = NS_NewHTMLAttributes(&aAttributes, mapFunc);
result = NS_NewHTMLAttributes(&aAttributes, nsnull, mapFunc);
if (NS_OK == result) {
aAttributes->AddContentRef();
}
@ -366,6 +366,7 @@ nsGenericHTMLElement::SetDocument(nsIDocument* aDocument, PRBool aDeep)
if ((nsnull != mDocument) && (nsnull != mAttributes)) {
nsIHTMLStyleSheet* sheet = GetAttrStyleSheet(mDocument);
if (nsnull != sheet) {
mAttributes->SetStyleSheet(sheet);
sheet->SetAttributesFor(htmlContent, mAttributes); // sync attributes with sheet
NS_RELEASE(sheet);
}

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

@ -42,7 +42,73 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
static NS_DEFINE_IID(kIDOMHTMLBodyElementIID, NS_IDOMHTMLBODYELEMENT_IID);
static NS_DEFINE_IID(kIHTMLContentContainerIID, NS_IHTMLCONTENTCONTAINER_IID);
class BodyRule;
//----------------------------------------------------------------------
class nsHTMLBodyElement;
class BodyRule: public nsIStyleRule {
public:
BodyRule(nsHTMLBodyElement* aPart, nsIHTMLStyleSheet* aSheet);
~BodyRule();
NS_DECL_ISUPPORTS
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
// Strength is an out-of-band weighting, always 0 here
NS_IMETHOD GetStrength(PRInt32& aStrength);
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext,
nsIPresContext* aPresContext);
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
nsHTMLBodyElement* mPart; // not ref-counted, cleared by content
nsIHTMLStyleSheet* mSheet; // not ref-counted, cleared by content
};
//----------------------------------------------------------------------
// special subclass of inner class to override set document
class nsBodyInner: public nsGenericHTMLContainerElement
{
public:
nsBodyInner();
~nsBodyInner();
nsresult SetDocument(nsIDocument* aDocument, PRBool aDeep);
BodyRule* mStyleRule;
};
nsBodyInner::nsBodyInner()
: nsGenericHTMLContainerElement(),
mStyleRule(nsnull)
{
}
nsBodyInner::~nsBodyInner()
{
if (nsnull != mStyleRule) {
mStyleRule->mPart = nsnull;
mStyleRule->mSheet = nsnull;
NS_RELEASE(mStyleRule);
}
}
nsresult nsBodyInner::SetDocument(nsIDocument* aDocument, PRBool aDeep)
{
if (nsnull != mStyleRule) {
mStyleRule->mPart = nsnull;
mStyleRule->mSheet = nsnull;
NS_RELEASE(mStyleRule); // destroy old style rule since the sheet will probably change
}
return nsGenericHTMLContainerElement::SetDocument(aDocument, aDeep);
}
//----------------------------------------------------------------------
class nsHTMLBodyElement : public nsIDOMHTMLBodyElement,
public nsIScriptObjectOwner,
@ -92,38 +158,19 @@ public:
NS_IMPL_IHTMLCONTENT_USING_GENERIC2(mInner)
protected:
nsGenericHTMLContainerElement mInner;
BodyRule* mStyleRule;
nsBodyInner mInner;
friend BodyRule;
};
class BodyRule: public nsIStyleRule {
public:
BodyRule(nsHTMLBodyElement* aPart);
~BodyRule();
NS_DECL_ISUPPORTS
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
// Strength is an out-of-band weighting, always 0 here
NS_IMETHOD GetStrength(PRInt32& aStrength);
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext,
nsIPresContext* aPresContext);
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
nsHTMLBodyElement* mPart;
};
//----------------------------------------------------------------------
BodyRule::BodyRule(nsHTMLBodyElement* aPart)
BodyRule::BodyRule(nsHTMLBodyElement* aPart, nsIHTMLStyleSheet* aSheet)
{
NS_INIT_REFCNT();
mPart = aPart;
mSheet = aSheet;
}
BodyRule::~BodyRule()
@ -146,6 +193,14 @@ BodyRule::HashValue(PRUint32& aValue) const
return NS_OK;
}
NS_IMETHODIMP
BodyRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
// Strength is an out-of-band weighting, useful for mapping CSS ! important
// always 0 here
NS_IMETHODIMP
@ -244,7 +299,6 @@ NS_NewHTMLBodyElement(nsIHTMLContent** aInstancePtrResult, nsIAtom* aTag)
}
nsHTMLBodyElement::nsHTMLBodyElement(nsIAtom* aTag)
: mStyleRule(nsnull)
{
NS_INIT_REFCNT();
mInner.Init(this, aTag);
@ -252,10 +306,6 @@ nsHTMLBodyElement::nsHTMLBodyElement(nsIAtom* aTag)
nsHTMLBodyElement::~nsHTMLBodyElement()
{
if (nsnull != mStyleRule) {
mStyleRule->mPart = nsnull;
NS_RELEASE(mStyleRule);
}
}
NS_IMPL_ADDREF(nsHTMLBodyElement)
@ -454,14 +504,39 @@ nsHTMLBodyElement::HandleDOMEvent(nsIPresContext& aPresContext,
aFlags, aEventStatus);
}
static nsIHTMLStyleSheet* GetAttrStyleSheet(nsIDocument* aDocument)
{
nsIHTMLStyleSheet* sheet = nsnull;
nsIHTMLContentContainer* htmlContainer;
if (nsnull != aDocument) {
if (NS_OK == aDocument->QueryInterface(kIHTMLContentContainerIID, (void**)&htmlContainer)) {
htmlContainer->GetAttributeStyleSheet(&sheet);
NS_RELEASE(htmlContainer);
}
}
NS_ASSERTION(nsnull != sheet, "can't get attribute style sheet");
return sheet;
}
NS_IMETHODIMP
nsHTMLBodyElement::GetStyleRule(nsIStyleRule*& aResult)
{
if (nsnull == mStyleRule) {
mStyleRule = new BodyRule(this);
NS_IF_ADDREF(mStyleRule);
if (nsnull == mInner.mStyleRule) {
nsIHTMLStyleSheet* sheet = nsnull;
if (nsnull != mInner.mDocument) { // find style sheet
sheet = GetAttrStyleSheet(mInner.mDocument);
}
mInner.mStyleRule = new BodyRule(this, sheet);
NS_IF_RELEASE(sheet);
NS_IF_ADDREF(mInner.mStyleRule);
}
NS_IF_ADDREF(mStyleRule);
aResult = mStyleRule;
NS_IF_ADDREF(mInner.mStyleRule);
aResult = mInner.mStyleRule;
return NS_OK;
}

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

@ -131,8 +131,14 @@ nsHTMLDocument::~nsHTMLDocument()
NS_IF_RELEASE(mEmbeds);
NS_IF_RELEASE(mLinks);
NS_IF_RELEASE(mAnchors);
NS_IF_RELEASE(mAttrStyleSheet);
NS_IF_RELEASE(mStyleAttrStyleSheet);
if (nsnull != mAttrStyleSheet) {
mAttrStyleSheet->SetOwningDocument(nsnull);
NS_RELEASE(mAttrStyleSheet);
}
if (nsnull != mStyleAttrStyleSheet) {
mStyleAttrStyleSheet->SetOwningDocument(nsnull);
NS_RELEASE(mStyleAttrStyleSheet);
}
NS_IF_RELEASE(mParser);
for (i = 0; i < mImageMaps.Count(); i++) {
nsIImageMap* map = (nsIImageMap*)mImageMaps.ElementAt(i);
@ -208,8 +214,14 @@ nsHTMLDocument::StartDocumentLoad(nsIURL *aURL,
nsIWebShell* webShell;
NS_IF_RELEASE(mAttrStyleSheet);
NS_IF_RELEASE(mStyleAttrStyleSheet);
if (nsnull != mAttrStyleSheet) {
mAttrStyleSheet->SetOwningDocument(nsnull);
NS_RELEASE(mAttrStyleSheet);
}
if (nsnull != mStyleAttrStyleSheet) {
mStyleAttrStyleSheet->SetOwningDocument(nsnull);
NS_RELEASE(mStyleAttrStyleSheet);
}
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
static NS_DEFINE_IID(kCParserCID, NS_PARSER_IID);
@ -231,10 +243,10 @@ nsHTMLDocument::StartDocumentLoad(nsIURL *aURL,
#endif
if (NS_OK == rv) {
if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL)) {
if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this)) {
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
}
if (NS_OK == NS_NewHTMLCSSStyleSheet(&mStyleAttrStyleSheet, aURL)) {
if (NS_OK == NS_NewHTMLCSSStyleSheet(&mStyleAttrStyleSheet, aURL, this)) {
AddStyleSheet(mStyleAttrStyleSheet); // tell the world about our new style sheet
}

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

@ -195,7 +195,7 @@ nsImageDocument::StartDocumentLoad(nsIURL* aURL,
// Create style attribute style sheet
nsresult rv;
nsIHTMLCSSStyleSheet* styleAttrSheet;
rv = NS_NewHTMLCSSStyleSheet(&styleAttrSheet, aURL);
rv = NS_NewHTMLCSSStyleSheet(&styleAttrSheet, aURL, this);
if (NS_OK != rv) {
return rv;
}
@ -203,7 +203,7 @@ nsImageDocument::StartDocumentLoad(nsIURL* aURL,
NS_RELEASE(styleAttrSheet);
// Create html attribute style sheet
rv = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL);
rv = NS_NewHTMLStyleSheet(&mAttrStyleSheet, aURL, this);
if (NS_OK != rv) {
return rv;
}

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

@ -192,10 +192,17 @@ void nsMarkupDocument::StyleSheetsToXIF(nsXIFConverter& aConverter)
if (sheet != nsnull)
{
nsIURL& sheetURL = *sheet->GetURL();
nsIURL* sheetURL = nsnull;
sheet->GetURL(sheetURL);
if (!(sheetURL == docURL))
if (nsnull == sheetURL) {
break;
}
if (!(*sheetURL == docURL)) {
NS_RELEASE(sheetURL);
break;
}
NS_RELEASE(sheetURL);
nsresult isCss = sheet->QueryInterface(kICSSStyleSheetIID, (void**)&cssSheet);
if ((isCss == NS_OK) && (cssSheet != nsnull))

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

@ -21,7 +21,7 @@
#include "nslayout.h"
#include "nsISupports.h"
class nsIStyleRule;
class nsIStyleSheet;
class nsICSSStyleSheet;
class nsIUnicharInputStream;
class nsIURL;
class nsString;
@ -40,11 +40,11 @@ public:
// Set a style sheet for the parser to fill in. The style sheet must
// implement the nsICSSStyleSheet interface
NS_IMETHOD SetStyleSheet(nsIStyleSheet* aSheet) = 0;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet) = 0;
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
nsIURL* aInputURL,
nsIStyleSheet*& aResult) = 0;
nsIURL* aInputURL,
nsICSSStyleSheet*& aResult) = 0;
// Parse declarations assuming that the outer curly braces have
// already been accounted for. aBaseURL is the base url to use for

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

@ -198,11 +198,11 @@ public:
NS_IMETHOD GetInfoMask(PRUint32& aResult);
NS_IMETHOD SetStyleSheet(nsIStyleSheet* aSheet);
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet);
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
nsIURL* aInputURL,
nsIStyleSheet*& aResult);
nsIURL* aInputURL,
nsICSSStyleSheet*& aResult);
NS_IMETHOD ParseDeclarations(const nsString& aDeclaration,
nsIURL* aBaseURL,
@ -364,32 +364,27 @@ CSSParserImpl::GetInfoMask(PRUint32& aResult)
}
NS_METHOD
CSSParserImpl::SetStyleSheet(nsIStyleSheet* aSheet)
CSSParserImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
{
NS_PRECONDITION(nsnull != aSheet, "null ptr");
if (nsnull == aSheet) {
return NS_ERROR_NULL_POINTER;
}
// Make sure the sheet supports the correct interface!
static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID);
nsICSSStyleSheet* cssSheet;
nsresult rv = aSheet->QueryInterface(kICSSStyleSheetIID, (void**)&cssSheet);
if (NS_OK != rv) {
return rv;
if (aSheet != mSheet) {
// Switch to using the new sheet
NS_IF_RELEASE(mSheet);
mSheet = aSheet;
NS_ADDREF(mSheet);
}
// Switch to using the new sheet
NS_IF_RELEASE(mSheet);
mSheet = cssSheet;
return NS_OK;
}
NS_METHOD
CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
nsIURL* aInputURL,
nsIStyleSheet*& aResult)
nsICSSStyleSheet*& aResult)
{
if (nsnull == mSheet) {
NS_NewCSSStyleSheet(&mSheet, aInputURL);
@ -425,9 +420,8 @@ CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
mScanner = nsnull;
NS_IF_RELEASE(mURL);
nsIStyleSheet* sheet = nsnull;
mSheet->QueryInterface(kIStyleSheetIID, (void**)&sheet);
aResult = sheet;
aResult = mSheet;
NS_ADDREF(aResult);
return NS_OK;
}
@ -711,15 +705,11 @@ NS_IMETHODIMP CSSParserImpl::ProcessImport(const nsString& aURLSpec)
nsICSSParser* parser;
rv = NS_NewCSSParser(&parser);
if (NS_OK == rv) {
nsIStyleSheet* childSheet = nsnull;
nsICSSStyleSheet* childSheet = nsnull;
rv = parser->Parse(uin, url, childSheet);
NS_RELEASE(parser);
if ((NS_OK == rv) && (nsnull != childSheet)) {
nsICSSStyleSheet* cssChild = nsnull;
if (NS_OK == childSheet->QueryInterface(kICSSStyleSheetIID, (void**)&cssChild)) {
mSheet->AppendStyleSheet(cssChild);
NS_RELEASE(cssChild);
}
mSheet->AppendStyleSheet(childSheet);
}
NS_IF_RELEASE(childSheet);
}

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

@ -17,9 +17,10 @@
*/
#include "nsICSSStyleRule.h"
#include "nsICSSDeclaration.h"
#include "nsIStyleSheet.h"
#include "nsICSSStyleSheet.h"
#include "nsIStyleContext.h"
#include "nsIPresContext.h"
#include "nsIDocument.h"
#include "nsIDeviceContext.h"
#include "nsIArena.h"
#include "nsIAtom.h"
@ -31,8 +32,8 @@
#include "nsStyleUtil.h"
#include "nsIFontMetrics.h"
#include "nsIDOMCSSStyleSheet.h"
#include "nsIDOMCSSRule.h"
#include "nsIDOMCSSStyleRule.h"
#include "nsIDOMCSSStyleRuleSimple.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptObjectOwner.h"
@ -45,8 +46,8 @@ 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(kIDOMCSSRuleIID, NS_IDOMCSSRULE_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);
@ -162,15 +163,19 @@ static void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
nsIStyleContext* aContext, nsIPresContext* aPresContext);
class CSSStyleRuleImpl;
class CSSImportantRule : public nsIStyleRule {
public:
CSSImportantRule(nsICSSDeclaration* aDeclaration);
CSSImportantRule(nsICSSStyleSheet* aSheet, nsICSSDeclaration* aDeclaration);
NS_DECL_ISUPPORTS
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
// Strength is an out-of-band weighting, useful for mapping CSS ! important
NS_IMETHOD GetStrength(PRInt32& aStrength);
@ -182,10 +187,14 @@ protected:
~CSSImportantRule(void);
nsICSSDeclaration* mDeclaration;
nsICSSStyleSheet* mSheet;
friend CSSStyleRuleImpl;
};
CSSImportantRule::CSSImportantRule(nsICSSDeclaration* aDeclaration)
: mDeclaration(aDeclaration)
CSSImportantRule::CSSImportantRule(nsICSSStyleSheet* aSheet, nsICSSDeclaration* aDeclaration)
: mSheet(aSheet),
mDeclaration(aDeclaration)
{
NS_INIT_REFCNT();
NS_IF_ADDREF(mDeclaration);
@ -212,6 +221,14 @@ CSSImportantRule::HashValue(PRUint32& aValue) const
return NS_OK;
}
NS_IMETHODIMP
CSSImportantRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
// Strength is an out-of-band weighting, useful for mapping CSS ! important
NS_IMETHODIMP
CSSImportantRule::GetStrength(PRInt32& aStrength)
@ -299,7 +316,18 @@ nsresult
DOMCSSDeclarationImpl::StylePropertyChanged(const nsString& aPropertyName,
PRInt32 aHint)
{
// XXX TBI
nsIStyleSheet* sheet = nsnull;
if (nsnull != mRule) {
mRule->GetStyleSheet(sheet);
if (nsnull != sheet) {
nsIDocument* doc = nsnull;
sheet->GetOwningDocument(doc);
if (nsnull != doc) {
doc->StyleRuleChanged(sheet, mRule, aHint);
}
}
}
return NS_OK;
}
@ -316,7 +344,7 @@ DOMCSSDeclarationImpl::GetParent(nsISupports **aParent)
// -- nsCSSStyleRule -------------------------------
class CSSStyleRuleImpl : public nsICSSStyleRule,
public nsIDOMCSSStyleRuleSimple,
public nsIDOMCSSStyleRule,
public nsIScriptObjectOwner {
public:
void* operator new(size_t size);
@ -346,20 +374,24 @@ public:
virtual nsIStyleRule* GetImportantRule(void);
virtual nsIStyleSheet* GetStyleSheet(void);
virtual void SetStyleSheet(nsIStyleSheet *aSheet);
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* 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);
// nsIDOMCSSRule interface
NS_IMETHOD GetType(PRUint16* aType);
NS_IMETHOD GetCssText(nsString& aCssText);
NS_IMETHOD SetCssText(const nsString& aCssText);
NS_IMETHOD GetSheet(nsIDOMCSSStyleSheet** aSheet);
// nsIDOMCSSStyleRuleSimple interface
// nsIDOMCSSStyleRule interface
NS_IMETHOD GetSelectorText(nsString& aSelectorText);
NS_IMETHOD SetSelectorText(const nsString& aSelectorText);
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle);
NS_IMETHOD SetStyle(nsIDOMCSSStyleDeclaration* aStyle);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
@ -377,13 +409,13 @@ protected:
PRUint32 mInHeap : 1;
PRUint32 mRefCnt : 31;
nsCSSSelector mSelector;
nsICSSDeclaration* mDeclaration;
PRInt32 mWeight;
CSSImportantRule* mImportantRule;
nsIStyleSheet* mStyleSheet;
DOMCSSDeclarationImpl *mDOMDeclaration;
void* mScriptObject;
nsCSSSelector mSelector;
nsICSSDeclaration* mDeclaration;
PRInt32 mWeight;
CSSImportantRule* mImportantRule;
nsICSSStyleSheet* mSheet;
DOMCSSDeclarationImpl* mDOMDeclaration;
void* mScriptObject;
#ifdef DEBUG_REFS
PRInt32 mInstance;
#endif
@ -453,7 +485,10 @@ CSSStyleRuleImpl::~CSSStyleRuleImpl()
delete selector;
}
NS_IF_RELEASE(mDeclaration);
NS_IF_RELEASE(mImportantRule);
if (nsnull != mImportantRule) {
mImportantRule->mSheet = nsnull;
NS_RELEASE(mImportantRule);
}
if (nsnull != mDOMDeclaration) {
mDOMDeclaration->DropReference();
}
@ -505,14 +540,14 @@ nsresult CSSStyleRuleImpl::QueryInterface(const nsIID& aIID,
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMCSSStyleRuleIID)) {
nsIDOMCSSStyleRule *tmp = this;
if (aIID.Equals(kIDOMCSSRuleIID)) {
nsIDOMCSSRule *tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMCSSStyleRuleSimpleIID)) {
nsIDOMCSSStyleRuleSimple *tmp = this;
if (aIID.Equals(kIDOMCSSStyleRuleIID)) {
nsIDOMCSSStyleRule *tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
@ -637,10 +672,12 @@ nsICSSDeclaration* CSSStyleRuleImpl::GetDeclaration(void) const
void CSSStyleRuleImpl::SetDeclaration(nsICSSDeclaration* aDeclaration)
{
NS_IF_RELEASE(mImportantRule);
NS_IF_RELEASE(mDeclaration);
mDeclaration = aDeclaration;
NS_IF_ADDREF(mDeclaration);
if (mDeclaration != aDeclaration) {
NS_IF_RELEASE(mImportantRule);
NS_IF_RELEASE(mDeclaration);
mDeclaration = aDeclaration;
NS_IF_ADDREF(mDeclaration);
}
}
PRInt32 CSSStyleRuleImpl::GetWeight(void) const
@ -659,7 +696,7 @@ nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
nsICSSDeclaration* important;
mDeclaration->GetImportantValues(important);
if (nsnull != important) {
mImportantRule = new CSSImportantRule(important);
mImportantRule = new CSSImportantRule(mSheet, important);
NS_ADDREF(mImportantRule);
NS_RELEASE(important);
}
@ -668,19 +705,25 @@ nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
return mImportantRule;
}
nsIStyleSheet* CSSStyleRuleImpl::GetStyleSheet(void)
NS_IMETHODIMP
CSSStyleRuleImpl::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mStyleSheet);
return mStyleSheet;
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
void CSSStyleRuleImpl::SetStyleSheet(nsIStyleSheet *aSheet)
NS_IMETHODIMP
CSSStyleRuleImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
{
// XXX We don't reference count this up reference. The style sheet
// 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;
mSheet = aSheet;
if (nsnull != mImportantRule) { // we're responsible for this guy too
mImportantRule->mSheet = aSheet;
}
return NS_OK;
}
nscoord CalcLength(const nsCSSValue& aValue,
@ -1284,8 +1327,8 @@ void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
}
else if (eCSSUnit_Inherit == ourColor->mBackPositionX.GetUnit()) {
color->mBackgroundXPosition = parentColor->mBackgroundXPosition;
color->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_LENGTH;
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & NS_STYLE_BG_X_POSITION_PERCENT);
color->mBackgroundFlags &= ~(NS_STYLE_BG_X_POSITION_LENGTH | NS_STYLE_BG_X_POSITION_PERCENT);
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & (NS_STYLE_BG_X_POSITION_LENGTH | NS_STYLE_BG_X_POSITION_PERCENT));
}
if (eCSSUnit_Percent == ourColor->mBackPositionY.GetUnit()) {
@ -1306,8 +1349,8 @@ void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
}
else if (eCSSUnit_Inherit == ourColor->mBackPositionY.GetUnit()) {
color->mBackgroundYPosition = parentColor->mBackgroundYPosition;
color->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_LENGTH;
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & NS_STYLE_BG_Y_POSITION_PERCENT);
color->mBackgroundFlags &= ~(NS_STYLE_BG_Y_POSITION_LENGTH | NS_STYLE_BG_Y_POSITION_PERCENT);
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & (NS_STYLE_BG_Y_POSITION_LENGTH | NS_STYLE_BG_Y_POSITION_PERCENT));
}
// opacity: factor, percent, inherit
@ -1693,14 +1736,37 @@ CSSStyleRuleImpl::List(FILE* out, PRInt32 aIndent) const
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetType(nsString& aType)
CSSStyleRuleImpl::GetType(PRUint16* aType)
{
// XXX Need to define the different types
aType.SetString("simple");
*aType = nsIDOMCSSRule::STYLE_RULE;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetCssText(nsString& aCssText)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::SetCssText(const nsString& aCssText)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetSheet(nsIDOMCSSStyleSheet** aSheet)
{
if (nsnull != mSheet) {
return mSheet->QueryInterface(kIDOMCSSStyleSheetIID, (void**)aSheet);
}
*aSheet = nsnull;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetSelectorText(nsString& aSelectorText)
{
@ -1763,6 +1829,13 @@ CSSStyleRuleImpl::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::SetStyle(nsIDOMCSSStyleDeclaration* aStyle)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
@ -1773,10 +1846,10 @@ CSSStyleRuleImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObje
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);
res = NS_NewScriptCSSStyleRule(aContext,
supports,
(nsISupports *)global,
(void**)&mScriptObject);
}
*aScriptObject = mScriptObject;

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

@ -30,12 +30,14 @@
#include "nsHTMLAtoms.h"
#include "nsIFrame.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsIPtr.h"
#include "nsHTMLIIDs.h"
#include "nsIDOMStyleSheetCollection.h"
#include "nsIDOMCSSStyleSheet.h"
#include "nsIDOMCSSStyleRule.h"
#include "nsIDOMCSSStyleRuleCollection.h"
#include "nsIDOMNode.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsICSSParser.h"
@ -540,6 +542,25 @@ public:
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
// basic style sheet data
NS_IMETHOD GetURL(nsIURL*& aURL) const;
NS_IMETHOD GetTitle(nsString& aTitle) const;
NS_IMETHOD SetTitle(const nsString& aTitle);
NS_IMETHOD GetType(nsString& aType) const;
NS_IMETHOD GetMediumCount(PRInt32& aCount) const;
NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsString& aMedium) const;
NS_IMETHOD AppendMedium(const nsString& aMedium);
NS_IMETHOD GetEnabled(PRBool& aEnabled) const;
NS_IMETHOD SetEnabled(PRBool aEnabled);
// style sheet owner info
NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // may be null
NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
NS_IMETHOD SetOwningNode(nsIDOMNode* aOwningNode);
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aParentContext,
@ -551,9 +572,7 @@ public:
nsIStyleContext* aParentContext,
nsISupportsArray* aResults);
virtual nsIURL* GetURL(void);
virtual PRBool ContainsStyleSheet(nsIURL* aURL);
virtual PRBool ContainsStyleSheet(nsIURL* aURL) const;
virtual void AppendStyleSheet(nsICSSStyleSheet* aSheet);
@ -561,32 +580,29 @@ public:
virtual void PrependStyleRule(nsICSSStyleRule* aRule);
virtual void AppendStyleRule(nsICSSStyleRule* aRule);
virtual PRInt32 StyleRuleCount(void);
virtual nsresult GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule);
virtual PRInt32 StyleRuleCount(void) const;
virtual nsresult GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule) const;
virtual PRInt32 StyleSheetCount();
virtual nsresult GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet);
virtual void SetDocument(nsIDocument *aDocument);
virtual PRInt32 StyleSheetCount(void) const;
virtual nsresult GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const;
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
// nsIDOMStyleSheet interface
NS_IMETHOD GetType(nsString& aType);
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 GetOwningNode(nsIDOMNode** aOwningNode);
NS_IMETHOD GetParentStyleSheet(nsIDOMStyleSheet** 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);
NS_IMETHOD GetMedia(nsString& aMedia);
NS_IMETHOD GetCssRules(nsIDOMCSSStyleRuleCollection** aCssRules);
NS_IMETHOD InsertRule(const nsString& aRule, PRUint32 aIndex, PRUint32* aReturn);
NS_IMETHOD DeleteRule(PRUint32 aIndex);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
@ -608,6 +624,8 @@ protected:
PRUint32 mRefCnt : 31;
nsIURLPtr mURL;
nsString mTitle;
nsVoidArray mMedia;
nsICSSStyleSheetPtr mFirstChild;
nsISupportsArrayPtr mOrderedRules;
nsISupportsArrayPtr mWeightedRules;
@ -617,8 +635,9 @@ protected:
CSSStyleRuleCollectionImpl* mRuleCollection;
CSSImportsCollectionImpl* mImportsCollection;
nsIDocument* mDocument;
nsIDOMNode* mOwningNode;
PRBool mDisabled;
void * mScriptObject;
void* mScriptObject;
};
@ -662,7 +681,8 @@ static PRInt32 gInstanceCount;
CSSStyleSheetImpl::CSSStyleSheetImpl(nsIURL* aURL)
: nsICSSStyleSheet(),
mURL(nsnull), mFirstChild(nsnull),
mURL(nsnull), mTitle(), mMedia(),
mFirstChild(nsnull),
mOrderedRules(nsnull), mWeightedRules(nsnull),
mNext(nsnull),
mRuleHash(nsnull)
@ -673,6 +693,7 @@ CSSStyleSheetImpl::CSSStyleSheetImpl(nsIURL* aURL)
mRuleCollection = nsnull;
mImportsCollection = nsnull;
mDocument = nsnull;
mOwningNode = nsnull;
mDisabled = PR_FALSE;
mScriptObject = nsnull;
#ifdef DEBUG_REFS
@ -698,6 +719,11 @@ CSSStyleSheetImpl::~CSSStyleSheetImpl()
--gInstanceCount;
fprintf(stdout, "%d - CSSStyleSheet\n", gInstanceCount);
#endif
PRInt32 count = mMedia.Count();
while (0 < count) {
nsString* medium = (nsString*)mMedia.ElementAt(--count);
delete medium;
}
if (mFirstChild.IsNotNull()) {
nsICSSStyleSheet* child = mFirstChild;
while (nsnull != child) {
@ -1084,12 +1110,122 @@ PRInt32 CSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
return matchCount;
}
nsIURL* CSSStyleSheetImpl::GetURL(void)
NS_IMETHODIMP
CSSStyleSheetImpl::GetURL(nsIURL*& aURL) const
{
return mURL.AddRef();
nsIURL* url = mURL;
aURL = mURL;
NS_IF_ADDREF(aURL);
return NS_OK;
}
PRBool CSSStyleSheetImpl::ContainsStyleSheet(nsIURL* aURL)
NS_IMETHODIMP
CSSStyleSheetImpl::GetTitle(nsString& aTitle) const
{
aTitle = mTitle;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::SetTitle(const nsString& aTitle)
{
mTitle = aTitle;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetType(nsString& aType) const
{
aType.Truncate();
aType.Append("text/css");
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
{
aCount = mMedia.Count();
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsString& aMedium) const
{
nsString* medium = (nsString*)mMedia.ElementAt(aIndex);
if (nsnull != medium) {
aMedium = *medium;
return NS_OK;
}
aMedium.Truncate();
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
CSSStyleSheetImpl::AppendMedium(const nsString& aMedium)
{
nsString* medium = new nsString(aMedium);
mMedia.AppendElement(medium);
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetEnabled(PRBool& aEnabled) const
{
aEnabled = ((PR_TRUE == mDisabled) ? PR_FALSE : PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::SetEnabled(PRBool aEnabled)
{
PRBool oldState = mDisabled;
mDisabled = ((PR_TRUE == aEnabled) ? PR_FALSE : PR_TRUE);
if ((nsnull != mDocument) && (mDisabled != oldState)) {
mDocument->SetStyleSheetDisabledState(this, mDisabled);
}
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
{
NS_IF_ADDREF(mParent);
aParent = mParent;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
{
nsIDocument* doc = mDocument;
CSSStyleSheetImpl* parent = (CSSStyleSheetImpl*)mParent;
while ((nsnull == doc) && (nsnull != parent)) {
doc = parent->mDocument;
parent = (CSSStyleSheetImpl*)(parent->mParent);
}
NS_IF_ADDREF(doc);
aDocument = doc;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
{ // not ref counted
mDocument = aDocument;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::SetOwningNode(nsIDOMNode* aOwningNode)
{ // not ref counted
mOwningNode = aOwningNode;
return NS_OK;
}
PRBool CSSStyleSheetImpl::ContainsStyleSheet(nsIURL* aURL) const
{
NS_PRECONDITION(nsnull != aURL, "null arg");
@ -1182,7 +1318,7 @@ void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
aRule->SetStyleSheet(this);
}
PRInt32 CSSStyleSheetImpl::StyleRuleCount(void)
PRInt32 CSSStyleSheetImpl::StyleRuleCount(void) const
{
if (mOrderedRules.IsNotNull()) {
return mOrderedRules->Count();
@ -1190,7 +1326,7 @@ PRInt32 CSSStyleSheetImpl::StyleRuleCount(void)
return 0;
}
nsresult CSSStyleSheetImpl::GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule)
nsresult CSSStyleSheetImpl::GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule) const
{
nsresult result = NS_ERROR_ILLEGAL_VALUE;
@ -1206,7 +1342,7 @@ nsresult CSSStyleSheetImpl::GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRu
return result;
}
PRInt32 CSSStyleSheetImpl::StyleSheetCount()
PRInt32 CSSStyleSheetImpl::StyleSheetCount(void) const
{
// 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
@ -1223,7 +1359,7 @@ PRInt32 CSSStyleSheetImpl::StyleSheetCount()
return count;
}
nsresult CSSStyleSheetImpl::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet)
nsresult CSSStyleSheetImpl::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const
{
// 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
@ -1243,13 +1379,6 @@ nsresult CSSStyleSheetImpl::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& a
return NS_OK;
}
void CSSStyleSheetImpl::SetDocument(nsIDocument *aDocument)
{
// This reference is not reference counted and should not be
// released. The document will tell us when it goes away.
mDocument = aDocument;
}
void CSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
{
nsAutoString buffer;
@ -1303,6 +1432,15 @@ void CSSStyleSheetImpl::BuildHash(void)
}
}
// nsIDOMStyleSheet interface
NS_IMETHODIMP
CSSStyleSheetImpl::GetType(nsString& aType)
{
aType.Truncate();
aType.Append("text/css");
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetDisabled(PRBool* aDisabled)
{
@ -1313,13 +1451,13 @@ CSSStyleSheetImpl::GetDisabled(PRBool* aDisabled)
NS_IMETHODIMP
CSSStyleSheetImpl::SetDisabled(PRBool aDisabled)
{
if ((nsnull != mDocument) && (mDisabled != aDisabled)) {
mDocument->SetStyleSheetDisabledState(this, aDisabled);
}
PRBool oldState = mDisabled;
mDisabled = aDisabled;
if ((nsnull != mDocument) && (mDisabled != oldState)) {
mDocument->SetStyleSheetDisabledState(this, mDisabled);
}
return NS_OK;
}
@ -1332,18 +1470,18 @@ CSSStyleSheetImpl::GetReadOnly(PRBool* aReadOnly)
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetOwningElement(nsIDOMHTMLElement** aOwningElement)
CSSStyleSheetImpl::GetOwningNode(nsIDOMNode** aOwningNode)
{
// XXX TBI
*aOwningElement = nsnull;
NS_IF_ADDREF(mOwningNode);
*aOwningNode = mOwningNode;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aParentStyleSheet)
CSSStyleSheetImpl::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
{
if (nsnull != mParent) {
return mParent->QueryInterface(kIDOMCSSStyleSheetIID, (void **)aParentStyleSheet);
return mParent->QueryInterface(kIDOMStyleSheetIID, (void **)aParentStyleSheet);
}
else {
*aParentStyleSheet = nsnull;
@ -1364,32 +1502,31 @@ CSSStyleSheetImpl::GetHref(nsString& aHref)
return NS_OK;
}
NS_IMETHODIMP
NS_IMETHODIMP
CSSStyleSheetImpl::GetTitle(nsString& aTitle)
{
// XX TBI
aTitle = mTitle;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetImports(nsIDOMStyleSheetCollection** aImports)
NS_IMETHODIMP
CSSStyleSheetImpl::GetMedia(nsString& aMedia)
{
if (nsnull == mImportsCollection) {
mImportsCollection = new CSSImportsCollectionImpl(this);
if (nsnull == mImportsCollection) {
return NS_ERROR_OUT_OF_MEMORY;
aMedia.Truncate();
PRInt32 count = mMedia.Count();
PRInt32 index = 0;
while (index < count) {
nsString* medium = (nsString*)mMedia.ElementAt(index++);
aMedia.Append(*medium);
if (index < count) {
aMedia.Append(", ");
}
NS_ADDREF(mImportsCollection);
}
*aImports = mImportsCollection;
NS_ADDREF(mImportsCollection);
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetRules(nsIDOMCSSStyleRuleCollection** aRules)
CSSStyleSheetImpl::GetCssRules(nsIDOMCSSStyleRuleCollection** aCssRules)
{
if (nsnull == mRuleCollection) {
mRuleCollection = new CSSStyleRuleCollectionImpl(this);
@ -1399,37 +1536,31 @@ CSSStyleSheetImpl::GetRules(nsIDOMCSSStyleRuleCollection** aRules)
NS_ADDREF(mRuleCollection);
}
*aRules = mRuleCollection;
*aCssRules = mRuleCollection;
NS_ADDREF(mRuleCollection);
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::AddRule(const nsString& aSelector,
const nsString& aDeclaration,
PRUint32 aIndex,
PRUint32* aReturn)
CSSStyleSheetImpl::InsertRule(const nsString& aRule,
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(" } ");
nsAutoString str(aRule);
nsIUnicharInputStream* input = nsnull;
result = NS_NewStringUnicharInputStream(&input, &str);
if (NS_OK == result) {
nsIStyleSheet *tmp;
nsICSSStyleSheet* 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_ASSERTION(tmp == this, "parser incorrectly created a new stylesheet");
NS_RELEASE(tmp);
NS_RELEASE(input);
*aReturn = mOrderedRules->Count();
}
@ -1441,21 +1572,9 @@ CSSStyleSheetImpl::AddRule(const nsString& aSelector,
}
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)
CSSStyleSheetImpl::DeleteRule(PRUint32 aIndex)
{
// XXX TBI: handle @rule types
nsICSSStyleRule *rule;
rule = (nsICSSStyleRule *)mOrderedRules->ElementAt(aIndex);
@ -1469,36 +1588,6 @@ CSSStyleSheetImpl::RemoveRule(PRUint32 aIndex)
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)
{

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

@ -37,6 +37,7 @@ nsDOMCSSDeclaration::~nsDOMCSSDeclaration()
NS_IMPL_ADDREF(nsDOMCSSDeclaration);
NS_IMPL_RELEASE(nsDOMCSSDeclaration);
static NS_DEFINE_IID(kIDOMCSS2PropertiesIID, NS_IDOMCSS2PROPERTIES_IID);
static NS_DEFINE_IID(kIDOMCSSStyleDeclarationIID, NS_IDOMCSSSTYLEDECLARATION_IID);
static NS_DEFINE_IID(kICSSStyleRuleIID, NS_ICSS_STYLE_RULE_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
@ -50,6 +51,12 @@ nsDOMCSSDeclaration::QueryInterface(REFNSIID aIID,
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIDOMCSS2PropertiesIID)) {
nsIDOMCSS2Properties *tmp = this;
AddRef();
*aInstancePtr = (void*) tmp;
return NS_OK;
}
if (aIID.Equals(kIDOMCSSStyleDeclarationIID)) {
nsIDOMCSSStyleDeclaration *tmp = this;
AddRef();
@ -83,12 +90,12 @@ nsDOMCSSDeclaration::GetScriptObject(nsIScriptContext* aContext,
res = GetParent(&parent);
if (NS_OK == res) {
nsISupports *supports = (nsISupports *)(nsIDOMCSSStyleDeclaration *)this;
nsISupports *supports = (nsISupports *)(nsIDOMCSS2Properties *)this;
// XXX Should be done through factory
res = NS_NewScriptCSSStyleDeclaration(aContext,
supports,
parent,
(void**)&mScriptObject);
res = NS_NewScriptCSS2Properties(aContext,
supports,
parent,
(void**)&mScriptObject);
NS_RELEASE(parent);
}
}
@ -104,6 +111,20 @@ nsDOMCSSDeclaration::SetScriptObject(void* aScriptObject)
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetCssText(nsString& aCssText)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSDeclaration::SetCssText(const nsString& aCssText)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetLength(PRUint32* aLength)
{
@ -649,6 +670,18 @@ nsDOMCSSDeclaration::SetCounterReset(const nsString& aCounterReset)
return SetProperty("counter-reset", aCounterReset, "");
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetCssFloat(nsString& aCssFloat)
{
return GetPropertyValue("float", aCssFloat);
}
NS_IMETHODIMP
nsDOMCSSDeclaration::SetCssFloat(const nsString& aCssFloat)
{
return SetProperty("float", aCssFloat, "");
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetCue(nsString& aCue)
{
@ -745,18 +778,6 @@ nsDOMCSSDeclaration::SetEmptyCells(const nsString& aEmptyCells)
return SetProperty("empty-cells", aEmptyCells, "");
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetStyleFloat(nsString& aStyleFloat)
{
return GetPropertyValue("style-float", aStyleFloat);
}
NS_IMETHODIMP
nsDOMCSSDeclaration::SetStyleFloat(const nsString& aStyleFloat)
{
return SetProperty("style-float", aStyleFloat, "");
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetFont(nsString& aFont)
{

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

@ -20,12 +20,12 @@
#define nsDOMCSSSDeclaration_h___
#include "nsISupports.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMCSS2Properties.h"
#include "nsIScriptObjectOwner.h"
class nsICSSDeclaration;
class nsDOMCSSDeclaration : public nsIDOMCSSStyleDeclaration,
class nsDOMCSSDeclaration : public nsIDOMCSS2Properties,
public nsIScriptObjectOwner
{
public:
@ -34,6 +34,8 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_IDOMCSSSTYLEDECLARATION
NS_DECL_IDOMCSS2PROPERTIES
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);

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

@ -17,6 +17,7 @@
*/
#include "nsIHTMLAttributes.h"
#include "nsIHTMLStyleSheet.h"
#include "nsIStyleRule.h"
#include "nsString.h"
#include "nsISupportsArray.h"
@ -171,7 +172,7 @@ public:
void* operator new(size_t size, nsIArena* aArena);
void operator delete(void* ptr);
HTMLAttributesImpl(nsMapAttributesFunc aMapFunc);
HTMLAttributesImpl(nsIHTMLStyleSheet* aSheet, nsMapAttributesFunc aMapFunc);
HTMLAttributesImpl(const HTMLAttributesImpl& aCopy);
~HTMLAttributesImpl(void);
@ -212,6 +213,8 @@ public:
// nsIStyleRule
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
NS_IMETHOD SetStyleSheet(nsIHTMLStyleSheet* aSheet);
// Strength is an out-of-band weighting, always 0 here
NS_IMETHOD GetStrength(PRInt32& aStrength);
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
@ -231,11 +234,12 @@ protected:
PRUint32 mInHeap : 1;
PRUint32 mRefCnt : 31;
PRInt32 mContentRefCount;
PRInt32 mCount;
HTMLAttribute mFirst;
nsIAtom* mID;
nsIAtom* mClass;
nsIHTMLStyleSheet* mSheet;
PRInt32 mContentRefCount;
PRInt32 mCount;
HTMLAttribute mFirst;
nsIAtom* mID;
nsIAtom* mClass;
nsMapAttributesFunc mMapper;
#ifdef DEBUG_REFS
@ -285,8 +289,10 @@ void HTMLAttributesImpl::operator delete(void* ptr)
}
HTMLAttributesImpl::HTMLAttributesImpl(nsMapAttributesFunc aMapFunc)
: mFirst(),
HTMLAttributesImpl::HTMLAttributesImpl(nsIHTMLStyleSheet* aSheet,
nsMapAttributesFunc aMapFunc)
: mSheet(aSheet),
mFirst(),
mCount(0),
mID(nsnull),
mClass(nsnull),
@ -302,7 +308,8 @@ HTMLAttributesImpl::HTMLAttributesImpl(nsMapAttributesFunc aMapFunc)
}
HTMLAttributesImpl::HTMLAttributesImpl(const HTMLAttributesImpl& aCopy)
: mFirst(aCopy.mFirst),
: mSheet(aCopy.mSheet),
mFirst(aCopy.mFirst),
mCount(aCopy.mCount),
mID(aCopy.mID),
mClass(aCopy.mClass),
@ -803,6 +810,21 @@ HTMLAttributesImpl::MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPre
return NS_OK;
}
NS_IMETHODIMP
HTMLAttributesImpl::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
NS_IMETHODIMP
HTMLAttributesImpl::SetStyleSheet(nsIHTMLStyleSheet* aSheet)
{ // this is not ref-counted, sheet sets to null when it goes away
mSheet = aSheet;
return NS_OK;
}
// Strength is an out-of-band weighting, always 0 here
NS_IMETHODIMP
HTMLAttributesImpl::GetStrength(PRInt32& aStrength)
@ -840,13 +862,14 @@ HTMLAttributesImpl::List(FILE* out, PRInt32 aIndent) const
}
extern NS_HTML nsresult
NS_NewHTMLAttributes(nsIHTMLAttributes** aInstancePtrResult, nsMapAttributesFunc aMapFunc)
NS_NewHTMLAttributes(nsIHTMLAttributes** aInstancePtrResult, nsIHTMLStyleSheet* aSheet,
nsMapAttributesFunc aMapFunc)
{
if (aInstancePtrResult == nsnull) {
return NS_ERROR_NULL_POINTER;
}
HTMLAttributesImpl *it = new HTMLAttributesImpl(aMapFunc);
HTMLAttributesImpl *it = new HTMLAttributesImpl(aSheet, aMapFunc);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;

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

@ -29,6 +29,7 @@
#include "nsICSSStyleRule.h"
#include "nsIStyleContext.h"
#include "nsIPresContext.h"
#include "nsIDocument.h"
static NS_DEFINE_IID(kIHTMLCSSStyleSheetIID, NS_IHTML_CSS_STYLE_SHEET_IID);
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
@ -37,22 +38,26 @@ static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
class BodyFixupRule : public nsIStyleRule {
public:
BodyFixupRule();
BodyFixupRule(nsIHTMLCSSStyleSheet* aSheet);
~BodyFixupRule();
NS_DECL_ISUPPORTS
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aValue) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
// Strength is an out-of-band weighting, always 0 here
NS_IMETHOD GetStrength(PRInt32& aStrength);
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
nsIHTMLCSSStyleSheet* mSheet;
};
BodyFixupRule::BodyFixupRule()
BodyFixupRule::BodyFixupRule(nsIHTMLCSSStyleSheet* aSheet)
: mSheet(aSheet)
{
NS_INIT_REFCNT();
}
@ -77,6 +82,14 @@ BodyFixupRule::HashValue(PRUint32& aValue) const
return NS_OK;
}
NS_IMETHODIMP
BodyFixupRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
// Strength is an out-of-band weighting, always MaxInt here
NS_IMETHODIMP
BodyFixupRule::GetStrength(PRInt32& aStrength)
@ -115,12 +128,27 @@ public:
void* operator new(size_t size, nsIArena* aArena);
void operator delete(void* ptr);
HTMLCSSStyleSheetImpl(nsIURL* aURL);
HTMLCSSStyleSheetImpl(nsIURL* aURL, nsIDocument* aDocument);
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
// basic style sheet data
NS_IMETHOD GetURL(nsIURL*& aURL) const;
NS_IMETHOD GetTitle(nsString& aTitle) const;
NS_IMETHOD GetType(nsString& aType) const;
NS_IMETHOD GetMediumCount(PRInt32& aCount) const;
NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsString& aMedium) const;
NS_IMETHOD GetEnabled(PRBool& aEnabled) const;
NS_IMETHOD SetEnabled(PRBool aEnabled);
// style sheet owner info
NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // will be null
NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aParentContext,
@ -132,8 +160,6 @@ public:
nsIStyleContext* aParentContext,
nsISupportsArray* aResults);
virtual nsIURL* GetURL(void);
// XXX style rule enumerations
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
@ -150,8 +176,9 @@ protected:
PRUint32 mInHeap : 1;
PRUint32 mRefCnt : 31;
nsIURL* mURL;
nsIStyleRule* mBodyRule;
nsIURL* mURL;
nsIDocument* mDocument;
BodyFixupRule* mBodyRule;
};
@ -191,9 +218,10 @@ void HTMLCSSStyleSheetImpl::operator delete(void* ptr)
HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL)
HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL, nsIDocument* aDocument)
: nsIHTMLCSSStyleSheet(),
mURL(aURL),
mDocument(aDocument),
mBodyRule(nsnull)
{
NS_INIT_REFCNT();
@ -203,7 +231,10 @@ HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL)
HTMLCSSStyleSheetImpl::~HTMLCSSStyleSheetImpl()
{
NS_RELEASE(mURL);
NS_IF_RELEASE(mBodyRule);
if (nsnull != mBodyRule) {
mBodyRule->mSheet = nsnull;
NS_RELEASE(mBodyRule);
}
}
NS_IMPL_ADDREF(HTMLCSSStyleSheetImpl)
@ -274,11 +305,8 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
htmlContent->GetTag(tag);
if (tag == nsHTMLAtoms::body) {
if (nsnull == mBodyRule) {
BodyFixupRule* bodyRule = new BodyFixupRule();
if ((nsnull != bodyRule) &&
(NS_OK != bodyRule->QueryInterface(kIStyleRuleIID, (void**)&mBodyRule))) {
delete bodyRule;
}
mBodyRule = new BodyFixupRule(this);
NS_IF_ADDREF(mBodyRule);
}
if (nsnull != mBodyRule) {
aResults->AppendElement(mBodyRule);
@ -301,10 +329,78 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
return 0;
}
nsIURL* HTMLCSSStyleSheetImpl::GetURL(void)
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetURL(nsIURL*& aURL) const
{
NS_ADDREF(mURL);
return mURL;
NS_IF_ADDREF(mURL);
aURL = mURL;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetTitle(nsString& aTitle) const
{
aTitle.Truncate();
aTitle.Append("Internal HTML/CSS Style Sheet");
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetType(nsString& aType) const
{
aType.Truncate();
aType.Append("text/html");
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
{
aCount = 0;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsString& aMedium) const
{
aMedium.Truncate();
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetEnabled(PRBool& aEnabled) const
{
aEnabled = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::SetEnabled(PRBool aEnabled)
{ // these can't be disabled
return NS_OK;
}
// style sheet owner info
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
{
aParent = nsnull;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
{
NS_IF_ADDREF(mDocument);
aDocument = mDocument;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
{
mDocument = aDocument;
return NS_OK;
}
void HTMLCSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
@ -322,13 +418,14 @@ void HTMLCSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
}
NS_HTML nsresult
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult, nsIURL* aURL)
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult, nsIURL* aURL,
nsIDocument* aDocument)
{
if (aInstancePtrResult == nsnull) {
return NS_ERROR_NULL_POINTER;
}
HTMLCSSStyleSheetImpl* it = new HTMLCSSStyleSheetImpl(aURL);
HTMLCSSStyleSheetImpl* it = new HTMLCSSStyleSheetImpl(aURL, aDocument);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;

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

@ -53,13 +53,14 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
class HTMLAnchorRule : public nsIStyleRule {
public:
HTMLAnchorRule();
HTMLAnchorRule(nsIHTMLStyleSheet* aSheet);
~HTMLAnchorRule();
NS_DECL_ISUPPORTS
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aValue) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
// Strength is an out-of-band weighting, always 0 here
NS_IMETHOD GetStrength(PRInt32& aStrength);
@ -67,10 +68,12 @@ public:
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
nscolor mColor;
nscolor mColor;
nsIHTMLStyleSheet* mSheet;
};
HTMLAnchorRule::HTMLAnchorRule()
HTMLAnchorRule::HTMLAnchorRule(nsIHTMLStyleSheet* aSheet)
: mSheet(aSheet)
{
NS_INIT_REFCNT();
}
@ -95,6 +98,14 @@ HTMLAnchorRule::HashValue(PRUint32& aValue) const
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
// Strength is an out-of-band weighting, always 0 here
NS_IMETHODIMP
HTMLAnchorRule::GetStrength(PRInt32& aStrength)
@ -201,12 +212,28 @@ public:
void* operator new(size_t size, nsIArena* aArena);
void operator delete(void* ptr);
HTMLStyleSheetImpl(nsIURL* aURL);
HTMLStyleSheetImpl(nsIURL* aURL, nsIDocument* aDocument);
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
// nsIStyleSheet api
NS_IMETHOD GetURL(nsIURL*& aURL) const;
NS_IMETHOD GetTitle(nsString& aTitle) const;
NS_IMETHOD GetType(nsString& aType) const;
NS_IMETHOD GetMediumCount(PRInt32& aCount) const;
NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsString& aMedium) const;
NS_IMETHOD GetEnabled(PRBool& aEnabled) const;
NS_IMETHOD SetEnabled(PRBool aEnabled);
// style sheet owner info
NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // will be null
NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
NS_IMETHOD SetOwningDocument(nsIDocument* aDocumemt);
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aParentContext,
@ -218,8 +245,6 @@ public:
nsIStyleContext* aParentContext,
nsISupportsArray* aResults);
virtual nsIURL* GetURL(void);
NS_IMETHOD SetLinkColor(nscolor aColor);
NS_IMETHOD SetActiveLinkColor(nscolor aColor);
NS_IMETHOD SetVisitedLinkColor(nscolor aColor);
@ -278,7 +303,17 @@ public:
nsIAtom* aAttribute,
PRInt32 aHint);
// XXX style rule enumerations
// Style change notifications
NS_IMETHOD StyleRuleChanged(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint); // See nsStyleConsts fot hint values
NS_IMETHOD StyleRuleAdded(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD StyleRuleRemoved(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
@ -361,11 +396,12 @@ protected:
PRUint32 mInHeap : 1;
PRUint32 mRefCnt : 31;
nsIURL* mURL;
HTMLAnchorRule* mLinkRule;
HTMLAnchorRule* mVisitedRule;
HTMLAnchorRule* mActiveRule;
nsHashtable mAttrTable;
nsIURL* mURL;
nsIDocument* mDocument;
HTMLAnchorRule* mLinkRule;
HTMLAnchorRule* mVisitedRule;
HTMLAnchorRule* mActiveRule;
nsHashtable mAttrTable;
nsIHTMLAttributes* mRecycledAttrs;
};
@ -406,9 +442,10 @@ void HTMLStyleSheetImpl::operator delete(void* ptr)
HTMLStyleSheetImpl::HTMLStyleSheetImpl(nsIURL* aURL)
HTMLStyleSheetImpl::HTMLStyleSheetImpl(nsIURL* aURL, nsIDocument* aDocument)
: nsIHTMLStyleSheet(),
mURL(aURL),
mDocument(aDocument),
mLinkRule(nsnull),
mVisitedRule(nsnull),
mActiveRule(nsnull),
@ -421,9 +458,18 @@ HTMLStyleSheetImpl::HTMLStyleSheetImpl(nsIURL* aURL)
HTMLStyleSheetImpl::~HTMLStyleSheetImpl()
{
NS_RELEASE(mURL);
NS_IF_RELEASE(mLinkRule);
NS_IF_RELEASE(mVisitedRule);
NS_IF_RELEASE(mActiveRule);
if (nsnull != mLinkRule) {
mLinkRule->mSheet = nsnull;
NS_RELEASE(mLinkRule);
}
if (nsnull != mVisitedRule) {
mVisitedRule->mSheet = nsnull;
NS_RELEASE(mVisitedRule);
}
if (nsnull != mActiveRule) {
mActiveRule->mSheet = nsnull;
NS_RELEASE(mActiveRule);
}
NS_IF_RELEASE(mRecycledAttrs);
}
@ -556,17 +602,85 @@ PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
}
nsIURL* HTMLStyleSheetImpl::GetURL(void)
// nsIStyleSheet api
NS_IMETHODIMP
HTMLStyleSheetImpl::GetURL(nsIURL*& aURL) const
{
NS_ADDREF(mURL);
return mURL;
NS_IF_ADDREF(mURL);
aURL = mURL;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetTitle(nsString& aTitle) const
{
aTitle.Truncate();
aTitle.Append("Internal HTML Style Sheet");
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetType(nsString& aType) const
{
aType.Truncate();
aType.Append("text/html");
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
{
aCount = 0;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsString& aMedium) const
{
aMedium.Truncate();
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetEnabled(PRBool& aEnabled) const
{
aEnabled = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::SetEnabled(PRBool aEnabled)
{ // these can't be disabled
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
{
aParent = nsnull;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
{
NS_IF_ADDREF(mDocument);
aDocument = mDocument;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
{
mDocument = aDocument;
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetLinkColor(nscolor aColor)
{
if (nsnull == mLinkRule) {
mLinkRule = new HTMLAnchorRule();
mLinkRule = new HTMLAnchorRule(this);
if (nsnull == mLinkRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -579,7 +693,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetLinkColor(nscolor aColor)
NS_IMETHODIMP HTMLStyleSheetImpl::SetActiveLinkColor(nscolor aColor)
{
if (nsnull == mActiveRule) {
mActiveRule = new HTMLAnchorRule();
mActiveRule = new HTMLAnchorRule(this);
if (nsnull == mActiveRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -592,7 +706,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetActiveLinkColor(nscolor aColor)
NS_IMETHODIMP HTMLStyleSheetImpl::SetVisitedLinkColor(nscolor aColor)
{
if (nsnull == mVisitedRule) {
mVisitedRule = new HTMLAnchorRule();
mVisitedRule = new HTMLAnchorRule(this);
if (nsnull == mVisitedRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -712,7 +826,7 @@ HTMLStyleSheetImpl::EnsureSingleAttributes(nsIHTMLAttributes*& aAttributes,
aSingleAttrs->SetMappingFunction(aMapFunc);
}
else {
result = NS_NewHTMLAttributes(&aSingleAttrs, aMapFunc);
result = NS_NewHTMLAttributes(&aSingleAttrs, this, aMapFunc);
}
}
else {
@ -2403,6 +2517,77 @@ HTMLStyleSheetImpl::AttributeChanged(nsIPresContext* aPresContext,
return result;
}
// Style change notifications
NS_IMETHODIMP
HTMLStyleSheetImpl::StyleRuleChanged(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint)
{
nsIPresShell* shell = aPresContext->GetShell();
nsIFrame* frame = shell->GetRootFrame();
PRBool reframe = PR_FALSE;
PRBool reflow = PR_FALSE;
PRBool render = PR_FALSE;
PRBool restyle = PR_FALSE;
switch (aHint) {
default:
case NS_STYLE_HINT_UNKNOWN:
case NS_STYLE_HINT_FRAMECHANGE:
reframe = PR_TRUE;
case NS_STYLE_HINT_REFLOW:
reflow = PR_TRUE;
case NS_STYLE_HINT_VISUAL:
render = PR_TRUE;
case NS_STYLE_HINT_CONTENT:
restyle = PR_TRUE;
break;
case NS_STYLE_HINT_AURAL:
break;
}
if (restyle) {
nsIStyleContext* sc;
frame->GetStyleContext(sc);
sc->RemapStyle(aPresContext);
NS_RELEASE(sc);
}
// XXX hack, skip the root and scrolling frames
frame->FirstChild(nsnull, frame);
frame->FirstChild(nsnull, frame);
if (reframe) {
NS_NOTYETIMPLEMENTED("frame change reflow");
}
else if (reflow) {
StyleChangeReflow(aPresContext, frame, nsnull);
}
else if (render) {
ApplyRenderingChangeToTree(aPresContext, frame);
}
NS_RELEASE(shell);
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::StyleRuleAdded(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::StyleRuleRemoved(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
return NS_OK;
}
void HTMLStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
{
@ -2419,13 +2604,14 @@ void HTMLStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
}
NS_HTML nsresult
NS_NewHTMLStyleSheet(nsIHTMLStyleSheet** aInstancePtrResult, nsIURL* aURL)
NS_NewHTMLStyleSheet(nsIHTMLStyleSheet** aInstancePtrResult, nsIURL* aURL,
nsIDocument* aDocument)
{
if (aInstancePtrResult == nsnull) {
return NS_ERROR_NULL_POINTER;
}
HTMLStyleSheetImpl *it = new HTMLStyleSheetImpl(aURL);
HTMLStyleSheetImpl *it = new HTMLStyleSheetImpl(aURL, aDocument);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;

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

@ -25,7 +25,7 @@ class nsIAtom;
class nsIArena;
class nsString;
class nsICSSDeclaration;
class nsIStyleSheet;
class nsICSSStyleSheet;
struct nsCSSSelector {
public:
@ -66,8 +66,7 @@ public:
virtual nsIStyleRule* GetImportantRule(void) = 0;
virtual nsIStyleSheet* GetStyleSheet(void) = 0;
virtual void SetStyleSheet(nsIStyleSheet *aSheet) = 0;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet) = 0;
};
extern NS_HTML nsresult

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

@ -1,53 +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.
*/
#ifndef nsICSSStyleSheet_h___
#define nsICSSStyleSheet_h___
#include "nslayout.h"
#include "nsIStyleSheet.h"
class nsICSSStyleRule;
class nsIDocument;
// IID for the nsICSSStyleSheet interface {8f83b0f0-b21a-11d1-8031-006008159b5a}
#define NS_ICSS_STYLE_SHEET_IID \
{0x8f83b0f0, 0xb21a, 0x11d1, {0x80, 0x31, 0x00, 0x60, 0x08, 0x15, 0x9b, 0x5a}}
class nsICSSStyleSheet : public nsIStyleSheet {
public:
virtual PRBool ContainsStyleSheet(nsIURL* aURL) = 0;
virtual void AppendStyleSheet(nsICSSStyleSheet* aSheet) = 0;
// XXX do these belong here or are they generic?
virtual void PrependStyleRule(nsICSSStyleRule* aRule) = 0;
virtual void AppendStyleRule(nsICSSStyleRule* aRule) = 0;
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;
virtual void SetDocument(nsIDocument* aDocument) = 0;
};
extern NS_HTML nsresult
NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult, nsIURL* aURL);
#endif /* nsICSSStyleSheet_h___ */

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

@ -25,6 +25,7 @@
class nsIAtom;
class nsISizeOfHandler;
class nsISupportsArray;
class nsIHTMLStyleSheet;
// IID for the nsIHTMLAttributes interface {a18f85f0-c058-11d1-8031-006008159b5a}
@ -66,6 +67,7 @@ public:
NS_IMETHOD Clone(nsIHTMLAttributes** aInstancePtrResult) = 0;
NS_IMETHOD Reset(void) = 0;
NS_IMETHOD SetMappingFunction(nsMapAttributesFunc aMapFunc) = 0;
NS_IMETHOD SetStyleSheet(nsIHTMLStyleSheet* aSheet) = 0;
/**
* Add this object's size information to the sizeof handler.
@ -76,7 +78,9 @@ public:
};
extern NS_HTML nsresult
NS_NewHTMLAttributes(nsIHTMLAttributes** aInstancePtrResult, nsMapAttributesFunc aMapFunc);
NS_NewHTMLAttributes(nsIHTMLAttributes** aInstancePtrResult,
nsIHTMLStyleSheet* aSheet,
nsMapAttributesFunc aMapFunc);
#endif /* nsIHTMLAttributes_h___ */

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

@ -31,6 +31,7 @@ public:
};
extern NS_HTML nsresult
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult, nsIURL* aURL);
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult, nsIURL* aURL,
nsIDocument* aDocument);
#endif /* nsIHTMLCSSStyleSheet_h___ */

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

@ -27,6 +27,7 @@ class nsString;
class nsHTMLValue;
class nsIHTMLAttributes;
class nsIHTMLContent;
class nsIDocument;
// IID for the nsIHTMLStyleSheet interface {bddbd1b0-c5cc-11d1-8031-006008159b5a}
#define NS_IHTML_STYLE_SHEET_IID \
@ -57,6 +58,7 @@ public:
};
extern NS_HTML nsresult
NS_NewHTMLStyleSheet(nsIHTMLStyleSheet** aInstancePtrResult, nsIURL* aURL);
NS_NewHTMLStyleSheet(nsIHTMLStyleSheet** aInstancePtrResult, nsIURL* aURL,
nsIDocument* aDocument);
#endif /* nsIHTMLStyleSheet_h___ */

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

@ -17,7 +17,7 @@
*/
#include <stdio.h>
#include "nsICSSParser.h"
#include "nsIStyleSheet.h"
#include "nsICSSStyleSheet.h"
#include "nsIStyleRule.h"
#include "nsIURL.h"
#include "nsIInputStream.h"
@ -128,7 +128,7 @@ int main(int argc, char** argv)
}
// Parse the input and produce a style set
nsIStyleSheet* sheet;
nsICSSStyleSheet* sheet;
rv = css->Parse(uin, url, sheet);
if (NS_OK == rv) {
if (verbose) {

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

@ -198,11 +198,11 @@ public:
NS_IMETHOD GetInfoMask(PRUint32& aResult);
NS_IMETHOD SetStyleSheet(nsIStyleSheet* aSheet);
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet);
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
nsIURL* aInputURL,
nsIStyleSheet*& aResult);
nsIURL* aInputURL,
nsICSSStyleSheet*& aResult);
NS_IMETHOD ParseDeclarations(const nsString& aDeclaration,
nsIURL* aBaseURL,
@ -364,32 +364,27 @@ CSSParserImpl::GetInfoMask(PRUint32& aResult)
}
NS_METHOD
CSSParserImpl::SetStyleSheet(nsIStyleSheet* aSheet)
CSSParserImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
{
NS_PRECONDITION(nsnull != aSheet, "null ptr");
if (nsnull == aSheet) {
return NS_ERROR_NULL_POINTER;
}
// Make sure the sheet supports the correct interface!
static NS_DEFINE_IID(kICSSStyleSheetIID, NS_ICSS_STYLE_SHEET_IID);
nsICSSStyleSheet* cssSheet;
nsresult rv = aSheet->QueryInterface(kICSSStyleSheetIID, (void**)&cssSheet);
if (NS_OK != rv) {
return rv;
if (aSheet != mSheet) {
// Switch to using the new sheet
NS_IF_RELEASE(mSheet);
mSheet = aSheet;
NS_ADDREF(mSheet);
}
// Switch to using the new sheet
NS_IF_RELEASE(mSheet);
mSheet = cssSheet;
return NS_OK;
}
NS_METHOD
CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
nsIURL* aInputURL,
nsIStyleSheet*& aResult)
nsICSSStyleSheet*& aResult)
{
if (nsnull == mSheet) {
NS_NewCSSStyleSheet(&mSheet, aInputURL);
@ -425,9 +420,8 @@ CSSParserImpl::Parse(nsIUnicharInputStream* aInput,
mScanner = nsnull;
NS_IF_RELEASE(mURL);
nsIStyleSheet* sheet = nsnull;
mSheet->QueryInterface(kIStyleSheetIID, (void**)&sheet);
aResult = sheet;
aResult = mSheet;
NS_ADDREF(aResult);
return NS_OK;
}
@ -711,15 +705,11 @@ NS_IMETHODIMP CSSParserImpl::ProcessImport(const nsString& aURLSpec)
nsICSSParser* parser;
rv = NS_NewCSSParser(&parser);
if (NS_OK == rv) {
nsIStyleSheet* childSheet = nsnull;
nsICSSStyleSheet* childSheet = nsnull;
rv = parser->Parse(uin, url, childSheet);
NS_RELEASE(parser);
if ((NS_OK == rv) && (nsnull != childSheet)) {
nsICSSStyleSheet* cssChild = nsnull;
if (NS_OK == childSheet->QueryInterface(kICSSStyleSheetIID, (void**)&cssChild)) {
mSheet->AppendStyleSheet(cssChild);
NS_RELEASE(cssChild);
}
mSheet->AppendStyleSheet(childSheet);
}
NS_IF_RELEASE(childSheet);
}

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

@ -17,9 +17,10 @@
*/
#include "nsICSSStyleRule.h"
#include "nsICSSDeclaration.h"
#include "nsIStyleSheet.h"
#include "nsICSSStyleSheet.h"
#include "nsIStyleContext.h"
#include "nsIPresContext.h"
#include "nsIDocument.h"
#include "nsIDeviceContext.h"
#include "nsIArena.h"
#include "nsIAtom.h"
@ -31,8 +32,8 @@
#include "nsStyleUtil.h"
#include "nsIFontMetrics.h"
#include "nsIDOMCSSStyleSheet.h"
#include "nsIDOMCSSRule.h"
#include "nsIDOMCSSStyleRule.h"
#include "nsIDOMCSSStyleRuleSimple.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIScriptGlobalObject.h"
#include "nsIScriptObjectOwner.h"
@ -45,8 +46,8 @@ 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(kIDOMCSSRuleIID, NS_IDOMCSSRULE_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);
@ -162,15 +163,19 @@ static void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
nsIStyleContext* aContext, nsIPresContext* aPresContext);
class CSSStyleRuleImpl;
class CSSImportantRule : public nsIStyleRule {
public:
CSSImportantRule(nsICSSDeclaration* aDeclaration);
CSSImportantRule(nsICSSStyleSheet* aSheet, nsICSSDeclaration* aDeclaration);
NS_DECL_ISUPPORTS
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aResult) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
// Strength is an out-of-band weighting, useful for mapping CSS ! important
NS_IMETHOD GetStrength(PRInt32& aStrength);
@ -182,10 +187,14 @@ protected:
~CSSImportantRule(void);
nsICSSDeclaration* mDeclaration;
nsICSSStyleSheet* mSheet;
friend CSSStyleRuleImpl;
};
CSSImportantRule::CSSImportantRule(nsICSSDeclaration* aDeclaration)
: mDeclaration(aDeclaration)
CSSImportantRule::CSSImportantRule(nsICSSStyleSheet* aSheet, nsICSSDeclaration* aDeclaration)
: mSheet(aSheet),
mDeclaration(aDeclaration)
{
NS_INIT_REFCNT();
NS_IF_ADDREF(mDeclaration);
@ -212,6 +221,14 @@ CSSImportantRule::HashValue(PRUint32& aValue) const
return NS_OK;
}
NS_IMETHODIMP
CSSImportantRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
// Strength is an out-of-band weighting, useful for mapping CSS ! important
NS_IMETHODIMP
CSSImportantRule::GetStrength(PRInt32& aStrength)
@ -299,7 +316,18 @@ nsresult
DOMCSSDeclarationImpl::StylePropertyChanged(const nsString& aPropertyName,
PRInt32 aHint)
{
// XXX TBI
nsIStyleSheet* sheet = nsnull;
if (nsnull != mRule) {
mRule->GetStyleSheet(sheet);
if (nsnull != sheet) {
nsIDocument* doc = nsnull;
sheet->GetOwningDocument(doc);
if (nsnull != doc) {
doc->StyleRuleChanged(sheet, mRule, aHint);
}
}
}
return NS_OK;
}
@ -316,7 +344,7 @@ DOMCSSDeclarationImpl::GetParent(nsISupports **aParent)
// -- nsCSSStyleRule -------------------------------
class CSSStyleRuleImpl : public nsICSSStyleRule,
public nsIDOMCSSStyleRuleSimple,
public nsIDOMCSSStyleRule,
public nsIScriptObjectOwner {
public:
void* operator new(size_t size);
@ -346,20 +374,24 @@ public:
virtual nsIStyleRule* GetImportantRule(void);
virtual nsIStyleSheet* GetStyleSheet(void);
virtual void SetStyleSheet(nsIStyleSheet *aSheet);
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* 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);
// nsIDOMCSSRule interface
NS_IMETHOD GetType(PRUint16* aType);
NS_IMETHOD GetCssText(nsString& aCssText);
NS_IMETHOD SetCssText(const nsString& aCssText);
NS_IMETHOD GetSheet(nsIDOMCSSStyleSheet** aSheet);
// nsIDOMCSSStyleRuleSimple interface
// nsIDOMCSSStyleRule interface
NS_IMETHOD GetSelectorText(nsString& aSelectorText);
NS_IMETHOD SetSelectorText(const nsString& aSelectorText);
NS_IMETHOD GetStyle(nsIDOMCSSStyleDeclaration** aStyle);
NS_IMETHOD SetStyle(nsIDOMCSSStyleDeclaration* aStyle);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
@ -377,13 +409,13 @@ protected:
PRUint32 mInHeap : 1;
PRUint32 mRefCnt : 31;
nsCSSSelector mSelector;
nsICSSDeclaration* mDeclaration;
PRInt32 mWeight;
CSSImportantRule* mImportantRule;
nsIStyleSheet* mStyleSheet;
DOMCSSDeclarationImpl *mDOMDeclaration;
void* mScriptObject;
nsCSSSelector mSelector;
nsICSSDeclaration* mDeclaration;
PRInt32 mWeight;
CSSImportantRule* mImportantRule;
nsICSSStyleSheet* mSheet;
DOMCSSDeclarationImpl* mDOMDeclaration;
void* mScriptObject;
#ifdef DEBUG_REFS
PRInt32 mInstance;
#endif
@ -453,7 +485,10 @@ CSSStyleRuleImpl::~CSSStyleRuleImpl()
delete selector;
}
NS_IF_RELEASE(mDeclaration);
NS_IF_RELEASE(mImportantRule);
if (nsnull != mImportantRule) {
mImportantRule->mSheet = nsnull;
NS_RELEASE(mImportantRule);
}
if (nsnull != mDOMDeclaration) {
mDOMDeclaration->DropReference();
}
@ -505,14 +540,14 @@ nsresult CSSStyleRuleImpl::QueryInterface(const nsIID& aIID,
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMCSSStyleRuleIID)) {
nsIDOMCSSStyleRule *tmp = this;
if (aIID.Equals(kIDOMCSSRuleIID)) {
nsIDOMCSSRule *tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kIDOMCSSStyleRuleSimpleIID)) {
nsIDOMCSSStyleRuleSimple *tmp = this;
if (aIID.Equals(kIDOMCSSStyleRuleIID)) {
nsIDOMCSSStyleRule *tmp = this;
*aInstancePtrResult = (void*) tmp;
NS_ADDREF_THIS();
return NS_OK;
@ -637,10 +672,12 @@ nsICSSDeclaration* CSSStyleRuleImpl::GetDeclaration(void) const
void CSSStyleRuleImpl::SetDeclaration(nsICSSDeclaration* aDeclaration)
{
NS_IF_RELEASE(mImportantRule);
NS_IF_RELEASE(mDeclaration);
mDeclaration = aDeclaration;
NS_IF_ADDREF(mDeclaration);
if (mDeclaration != aDeclaration) {
NS_IF_RELEASE(mImportantRule);
NS_IF_RELEASE(mDeclaration);
mDeclaration = aDeclaration;
NS_IF_ADDREF(mDeclaration);
}
}
PRInt32 CSSStyleRuleImpl::GetWeight(void) const
@ -659,7 +696,7 @@ nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
nsICSSDeclaration* important;
mDeclaration->GetImportantValues(important);
if (nsnull != important) {
mImportantRule = new CSSImportantRule(important);
mImportantRule = new CSSImportantRule(mSheet, important);
NS_ADDREF(mImportantRule);
NS_RELEASE(important);
}
@ -668,19 +705,25 @@ nsIStyleRule* CSSStyleRuleImpl::GetImportantRule(void)
return mImportantRule;
}
nsIStyleSheet* CSSStyleRuleImpl::GetStyleSheet(void)
NS_IMETHODIMP
CSSStyleRuleImpl::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mStyleSheet);
return mStyleSheet;
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
void CSSStyleRuleImpl::SetStyleSheet(nsIStyleSheet *aSheet)
NS_IMETHODIMP
CSSStyleRuleImpl::SetStyleSheet(nsICSSStyleSheet* aSheet)
{
// XXX We don't reference count this up reference. The style sheet
// 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;
mSheet = aSheet;
if (nsnull != mImportantRule) { // we're responsible for this guy too
mImportantRule->mSheet = aSheet;
}
return NS_OK;
}
nscoord CalcLength(const nsCSSValue& aValue,
@ -1284,8 +1327,8 @@ void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
}
else if (eCSSUnit_Inherit == ourColor->mBackPositionX.GetUnit()) {
color->mBackgroundXPosition = parentColor->mBackgroundXPosition;
color->mBackgroundFlags &= ~NS_STYLE_BG_X_POSITION_LENGTH;
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & NS_STYLE_BG_X_POSITION_PERCENT);
color->mBackgroundFlags &= ~(NS_STYLE_BG_X_POSITION_LENGTH | NS_STYLE_BG_X_POSITION_PERCENT);
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & (NS_STYLE_BG_X_POSITION_LENGTH | NS_STYLE_BG_X_POSITION_PERCENT));
}
if (eCSSUnit_Percent == ourColor->mBackPositionY.GetUnit()) {
@ -1306,8 +1349,8 @@ void MapDeclarationInto(nsICSSDeclaration* aDeclaration,
}
else if (eCSSUnit_Inherit == ourColor->mBackPositionY.GetUnit()) {
color->mBackgroundYPosition = parentColor->mBackgroundYPosition;
color->mBackgroundFlags &= ~NS_STYLE_BG_Y_POSITION_LENGTH;
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & NS_STYLE_BG_Y_POSITION_PERCENT);
color->mBackgroundFlags &= ~(NS_STYLE_BG_Y_POSITION_LENGTH | NS_STYLE_BG_Y_POSITION_PERCENT);
color->mBackgroundFlags |= (parentColor->mBackgroundFlags & (NS_STYLE_BG_Y_POSITION_LENGTH | NS_STYLE_BG_Y_POSITION_PERCENT));
}
// opacity: factor, percent, inherit
@ -1693,14 +1736,37 @@ CSSStyleRuleImpl::List(FILE* out, PRInt32 aIndent) const
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetType(nsString& aType)
CSSStyleRuleImpl::GetType(PRUint16* aType)
{
// XXX Need to define the different types
aType.SetString("simple");
*aType = nsIDOMCSSRule::STYLE_RULE;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetCssText(nsString& aCssText)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::SetCssText(const nsString& aCssText)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetSheet(nsIDOMCSSStyleSheet** aSheet)
{
if (nsnull != mSheet) {
return mSheet->QueryInterface(kIDOMCSSStyleSheetIID, (void**)aSheet);
}
*aSheet = nsnull;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetSelectorText(nsString& aSelectorText)
{
@ -1763,6 +1829,13 @@ CSSStyleRuleImpl::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::SetStyle(nsIDOMCSSStyleDeclaration* aStyle)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
CSSStyleRuleImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
@ -1773,10 +1846,10 @@ CSSStyleRuleImpl::GetScriptObject(nsIScriptContext *aContext, void** aScriptObje
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);
res = NS_NewScriptCSSStyleRule(aContext,
supports,
(nsISupports *)global,
(void**)&mScriptObject);
}
*aScriptObject = mScriptObject;

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

@ -30,12 +30,14 @@
#include "nsHTMLAtoms.h"
#include "nsIFrame.h"
#include "nsString.h"
#include "nsVoidArray.h"
#include "nsIPtr.h"
#include "nsHTMLIIDs.h"
#include "nsIDOMStyleSheetCollection.h"
#include "nsIDOMCSSStyleSheet.h"
#include "nsIDOMCSSStyleRule.h"
#include "nsIDOMCSSStyleRuleCollection.h"
#include "nsIDOMNode.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsICSSParser.h"
@ -540,6 +542,25 @@ public:
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
// basic style sheet data
NS_IMETHOD GetURL(nsIURL*& aURL) const;
NS_IMETHOD GetTitle(nsString& aTitle) const;
NS_IMETHOD SetTitle(const nsString& aTitle);
NS_IMETHOD GetType(nsString& aType) const;
NS_IMETHOD GetMediumCount(PRInt32& aCount) const;
NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsString& aMedium) const;
NS_IMETHOD AppendMedium(const nsString& aMedium);
NS_IMETHOD GetEnabled(PRBool& aEnabled) const;
NS_IMETHOD SetEnabled(PRBool aEnabled);
// style sheet owner info
NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // may be null
NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
NS_IMETHOD SetOwningNode(nsIDOMNode* aOwningNode);
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aParentContext,
@ -551,9 +572,7 @@ public:
nsIStyleContext* aParentContext,
nsISupportsArray* aResults);
virtual nsIURL* GetURL(void);
virtual PRBool ContainsStyleSheet(nsIURL* aURL);
virtual PRBool ContainsStyleSheet(nsIURL* aURL) const;
virtual void AppendStyleSheet(nsICSSStyleSheet* aSheet);
@ -561,32 +580,29 @@ public:
virtual void PrependStyleRule(nsICSSStyleRule* aRule);
virtual void AppendStyleRule(nsICSSStyleRule* aRule);
virtual PRInt32 StyleRuleCount(void);
virtual nsresult GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule);
virtual PRInt32 StyleRuleCount(void) const;
virtual nsresult GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule) const;
virtual PRInt32 StyleSheetCount();
virtual nsresult GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet);
virtual void SetDocument(nsIDocument *aDocument);
virtual PRInt32 StyleSheetCount(void) const;
virtual nsresult GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const;
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
// nsIDOMStyleSheet interface
NS_IMETHOD GetType(nsString& aType);
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 GetOwningNode(nsIDOMNode** aOwningNode);
NS_IMETHOD GetParentStyleSheet(nsIDOMStyleSheet** 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);
NS_IMETHOD GetMedia(nsString& aMedia);
NS_IMETHOD GetCssRules(nsIDOMCSSStyleRuleCollection** aCssRules);
NS_IMETHOD InsertRule(const nsString& aRule, PRUint32 aIndex, PRUint32* aReturn);
NS_IMETHOD DeleteRule(PRUint32 aIndex);
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
@ -608,6 +624,8 @@ protected:
PRUint32 mRefCnt : 31;
nsIURLPtr mURL;
nsString mTitle;
nsVoidArray mMedia;
nsICSSStyleSheetPtr mFirstChild;
nsISupportsArrayPtr mOrderedRules;
nsISupportsArrayPtr mWeightedRules;
@ -617,8 +635,9 @@ protected:
CSSStyleRuleCollectionImpl* mRuleCollection;
CSSImportsCollectionImpl* mImportsCollection;
nsIDocument* mDocument;
nsIDOMNode* mOwningNode;
PRBool mDisabled;
void * mScriptObject;
void* mScriptObject;
};
@ -662,7 +681,8 @@ static PRInt32 gInstanceCount;
CSSStyleSheetImpl::CSSStyleSheetImpl(nsIURL* aURL)
: nsICSSStyleSheet(),
mURL(nsnull), mFirstChild(nsnull),
mURL(nsnull), mTitle(), mMedia(),
mFirstChild(nsnull),
mOrderedRules(nsnull), mWeightedRules(nsnull),
mNext(nsnull),
mRuleHash(nsnull)
@ -673,6 +693,7 @@ CSSStyleSheetImpl::CSSStyleSheetImpl(nsIURL* aURL)
mRuleCollection = nsnull;
mImportsCollection = nsnull;
mDocument = nsnull;
mOwningNode = nsnull;
mDisabled = PR_FALSE;
mScriptObject = nsnull;
#ifdef DEBUG_REFS
@ -698,6 +719,11 @@ CSSStyleSheetImpl::~CSSStyleSheetImpl()
--gInstanceCount;
fprintf(stdout, "%d - CSSStyleSheet\n", gInstanceCount);
#endif
PRInt32 count = mMedia.Count();
while (0 < count) {
nsString* medium = (nsString*)mMedia.ElementAt(--count);
delete medium;
}
if (mFirstChild.IsNotNull()) {
nsICSSStyleSheet* child = mFirstChild;
while (nsnull != child) {
@ -1084,12 +1110,122 @@ PRInt32 CSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
return matchCount;
}
nsIURL* CSSStyleSheetImpl::GetURL(void)
NS_IMETHODIMP
CSSStyleSheetImpl::GetURL(nsIURL*& aURL) const
{
return mURL.AddRef();
nsIURL* url = mURL;
aURL = mURL;
NS_IF_ADDREF(aURL);
return NS_OK;
}
PRBool CSSStyleSheetImpl::ContainsStyleSheet(nsIURL* aURL)
NS_IMETHODIMP
CSSStyleSheetImpl::GetTitle(nsString& aTitle) const
{
aTitle = mTitle;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::SetTitle(const nsString& aTitle)
{
mTitle = aTitle;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetType(nsString& aType) const
{
aType.Truncate();
aType.Append("text/css");
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
{
aCount = mMedia.Count();
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsString& aMedium) const
{
nsString* medium = (nsString*)mMedia.ElementAt(aIndex);
if (nsnull != medium) {
aMedium = *medium;
return NS_OK;
}
aMedium.Truncate();
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
CSSStyleSheetImpl::AppendMedium(const nsString& aMedium)
{
nsString* medium = new nsString(aMedium);
mMedia.AppendElement(medium);
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetEnabled(PRBool& aEnabled) const
{
aEnabled = ((PR_TRUE == mDisabled) ? PR_FALSE : PR_TRUE);
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::SetEnabled(PRBool aEnabled)
{
PRBool oldState = mDisabled;
mDisabled = ((PR_TRUE == aEnabled) ? PR_FALSE : PR_TRUE);
if ((nsnull != mDocument) && (mDisabled != oldState)) {
mDocument->SetStyleSheetDisabledState(this, mDisabled);
}
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
{
NS_IF_ADDREF(mParent);
aParent = mParent;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
{
nsIDocument* doc = mDocument;
CSSStyleSheetImpl* parent = (CSSStyleSheetImpl*)mParent;
while ((nsnull == doc) && (nsnull != parent)) {
doc = parent->mDocument;
parent = (CSSStyleSheetImpl*)(parent->mParent);
}
NS_IF_ADDREF(doc);
aDocument = doc;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
{ // not ref counted
mDocument = aDocument;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::SetOwningNode(nsIDOMNode* aOwningNode)
{ // not ref counted
mOwningNode = aOwningNode;
return NS_OK;
}
PRBool CSSStyleSheetImpl::ContainsStyleSheet(nsIURL* aURL) const
{
NS_PRECONDITION(nsnull != aURL, "null arg");
@ -1182,7 +1318,7 @@ void CSSStyleSheetImpl::AppendStyleRule(nsICSSStyleRule* aRule)
aRule->SetStyleSheet(this);
}
PRInt32 CSSStyleSheetImpl::StyleRuleCount(void)
PRInt32 CSSStyleSheetImpl::StyleRuleCount(void) const
{
if (mOrderedRules.IsNotNull()) {
return mOrderedRules->Count();
@ -1190,7 +1326,7 @@ PRInt32 CSSStyleSheetImpl::StyleRuleCount(void)
return 0;
}
nsresult CSSStyleSheetImpl::GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule)
nsresult CSSStyleSheetImpl::GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRule) const
{
nsresult result = NS_ERROR_ILLEGAL_VALUE;
@ -1206,7 +1342,7 @@ nsresult CSSStyleSheetImpl::GetStyleRuleAt(PRInt32 aIndex, nsICSSStyleRule*& aRu
return result;
}
PRInt32 CSSStyleSheetImpl::StyleSheetCount()
PRInt32 CSSStyleSheetImpl::StyleSheetCount(void) const
{
// 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
@ -1223,7 +1359,7 @@ PRInt32 CSSStyleSheetImpl::StyleSheetCount()
return count;
}
nsresult CSSStyleSheetImpl::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet)
nsresult CSSStyleSheetImpl::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const
{
// 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
@ -1243,13 +1379,6 @@ nsresult CSSStyleSheetImpl::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& a
return NS_OK;
}
void CSSStyleSheetImpl::SetDocument(nsIDocument *aDocument)
{
// This reference is not reference counted and should not be
// released. The document will tell us when it goes away.
mDocument = aDocument;
}
void CSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
{
nsAutoString buffer;
@ -1303,6 +1432,15 @@ void CSSStyleSheetImpl::BuildHash(void)
}
}
// nsIDOMStyleSheet interface
NS_IMETHODIMP
CSSStyleSheetImpl::GetType(nsString& aType)
{
aType.Truncate();
aType.Append("text/css");
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetDisabled(PRBool* aDisabled)
{
@ -1313,13 +1451,13 @@ CSSStyleSheetImpl::GetDisabled(PRBool* aDisabled)
NS_IMETHODIMP
CSSStyleSheetImpl::SetDisabled(PRBool aDisabled)
{
if ((nsnull != mDocument) && (mDisabled != aDisabled)) {
mDocument->SetStyleSheetDisabledState(this, aDisabled);
}
PRBool oldState = mDisabled;
mDisabled = aDisabled;
if ((nsnull != mDocument) && (mDisabled != oldState)) {
mDocument->SetStyleSheetDisabledState(this, mDisabled);
}
return NS_OK;
}
@ -1332,18 +1470,18 @@ CSSStyleSheetImpl::GetReadOnly(PRBool* aReadOnly)
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetOwningElement(nsIDOMHTMLElement** aOwningElement)
CSSStyleSheetImpl::GetOwningNode(nsIDOMNode** aOwningNode)
{
// XXX TBI
*aOwningElement = nsnull;
NS_IF_ADDREF(mOwningNode);
*aOwningNode = mOwningNode;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aParentStyleSheet)
CSSStyleSheetImpl::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
{
if (nsnull != mParent) {
return mParent->QueryInterface(kIDOMCSSStyleSheetIID, (void **)aParentStyleSheet);
return mParent->QueryInterface(kIDOMStyleSheetIID, (void **)aParentStyleSheet);
}
else {
*aParentStyleSheet = nsnull;
@ -1364,32 +1502,31 @@ CSSStyleSheetImpl::GetHref(nsString& aHref)
return NS_OK;
}
NS_IMETHODIMP
NS_IMETHODIMP
CSSStyleSheetImpl::GetTitle(nsString& aTitle)
{
// XX TBI
aTitle = mTitle;
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetImports(nsIDOMStyleSheetCollection** aImports)
NS_IMETHODIMP
CSSStyleSheetImpl::GetMedia(nsString& aMedia)
{
if (nsnull == mImportsCollection) {
mImportsCollection = new CSSImportsCollectionImpl(this);
if (nsnull == mImportsCollection) {
return NS_ERROR_OUT_OF_MEMORY;
aMedia.Truncate();
PRInt32 count = mMedia.Count();
PRInt32 index = 0;
while (index < count) {
nsString* medium = (nsString*)mMedia.ElementAt(index++);
aMedia.Append(*medium);
if (index < count) {
aMedia.Append(", ");
}
NS_ADDREF(mImportsCollection);
}
*aImports = mImportsCollection;
NS_ADDREF(mImportsCollection);
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::GetRules(nsIDOMCSSStyleRuleCollection** aRules)
CSSStyleSheetImpl::GetCssRules(nsIDOMCSSStyleRuleCollection** aCssRules)
{
if (nsnull == mRuleCollection) {
mRuleCollection = new CSSStyleRuleCollectionImpl(this);
@ -1399,37 +1536,31 @@ CSSStyleSheetImpl::GetRules(nsIDOMCSSStyleRuleCollection** aRules)
NS_ADDREF(mRuleCollection);
}
*aRules = mRuleCollection;
*aCssRules = mRuleCollection;
NS_ADDREF(mRuleCollection);
return NS_OK;
}
NS_IMETHODIMP
CSSStyleSheetImpl::AddRule(const nsString& aSelector,
const nsString& aDeclaration,
PRUint32 aIndex,
PRUint32* aReturn)
CSSStyleSheetImpl::InsertRule(const nsString& aRule,
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(" } ");
nsAutoString str(aRule);
nsIUnicharInputStream* input = nsnull;
result = NS_NewStringUnicharInputStream(&input, &str);
if (NS_OK == result) {
nsIStyleSheet *tmp;
nsICSSStyleSheet* 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_ASSERTION(tmp == this, "parser incorrectly created a new stylesheet");
NS_RELEASE(tmp);
NS_RELEASE(input);
*aReturn = mOrderedRules->Count();
}
@ -1441,21 +1572,9 @@ CSSStyleSheetImpl::AddRule(const nsString& aSelector,
}
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)
CSSStyleSheetImpl::DeleteRule(PRUint32 aIndex)
{
// XXX TBI: handle @rule types
nsICSSStyleRule *rule;
rule = (nsICSSStyleRule *)mOrderedRules->ElementAt(aIndex);
@ -1469,36 +1588,6 @@ CSSStyleSheetImpl::RemoveRule(PRUint32 aIndex)
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)
{

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

@ -37,6 +37,7 @@ nsDOMCSSDeclaration::~nsDOMCSSDeclaration()
NS_IMPL_ADDREF(nsDOMCSSDeclaration);
NS_IMPL_RELEASE(nsDOMCSSDeclaration);
static NS_DEFINE_IID(kIDOMCSS2PropertiesIID, NS_IDOMCSS2PROPERTIES_IID);
static NS_DEFINE_IID(kIDOMCSSStyleDeclarationIID, NS_IDOMCSSSTYLEDECLARATION_IID);
static NS_DEFINE_IID(kICSSStyleRuleIID, NS_ICSS_STYLE_RULE_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
@ -50,6 +51,12 @@ nsDOMCSSDeclaration::QueryInterface(REFNSIID aIID,
if (nsnull == aInstancePtr) {
return NS_ERROR_NULL_POINTER;
}
if (aIID.Equals(kIDOMCSS2PropertiesIID)) {
nsIDOMCSS2Properties *tmp = this;
AddRef();
*aInstancePtr = (void*) tmp;
return NS_OK;
}
if (aIID.Equals(kIDOMCSSStyleDeclarationIID)) {
nsIDOMCSSStyleDeclaration *tmp = this;
AddRef();
@ -83,12 +90,12 @@ nsDOMCSSDeclaration::GetScriptObject(nsIScriptContext* aContext,
res = GetParent(&parent);
if (NS_OK == res) {
nsISupports *supports = (nsISupports *)(nsIDOMCSSStyleDeclaration *)this;
nsISupports *supports = (nsISupports *)(nsIDOMCSS2Properties *)this;
// XXX Should be done through factory
res = NS_NewScriptCSSStyleDeclaration(aContext,
supports,
parent,
(void**)&mScriptObject);
res = NS_NewScriptCSS2Properties(aContext,
supports,
parent,
(void**)&mScriptObject);
NS_RELEASE(parent);
}
}
@ -104,6 +111,20 @@ nsDOMCSSDeclaration::SetScriptObject(void* aScriptObject)
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetCssText(nsString& aCssText)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSDeclaration::SetCssText(const nsString& aCssText)
{
// XXX TBI
return NS_OK;
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetLength(PRUint32* aLength)
{
@ -649,6 +670,18 @@ nsDOMCSSDeclaration::SetCounterReset(const nsString& aCounterReset)
return SetProperty("counter-reset", aCounterReset, "");
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetCssFloat(nsString& aCssFloat)
{
return GetPropertyValue("float", aCssFloat);
}
NS_IMETHODIMP
nsDOMCSSDeclaration::SetCssFloat(const nsString& aCssFloat)
{
return SetProperty("float", aCssFloat, "");
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetCue(nsString& aCue)
{
@ -745,18 +778,6 @@ nsDOMCSSDeclaration::SetEmptyCells(const nsString& aEmptyCells)
return SetProperty("empty-cells", aEmptyCells, "");
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetStyleFloat(nsString& aStyleFloat)
{
return GetPropertyValue("style-float", aStyleFloat);
}
NS_IMETHODIMP
nsDOMCSSDeclaration::SetStyleFloat(const nsString& aStyleFloat)
{
return SetProperty("style-float", aStyleFloat, "");
}
NS_IMETHODIMP
nsDOMCSSDeclaration::GetFont(nsString& aFont)
{

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

@ -20,12 +20,12 @@
#define nsDOMCSSSDeclaration_h___
#include "nsISupports.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMCSS2Properties.h"
#include "nsIScriptObjectOwner.h"
class nsICSSDeclaration;
class nsDOMCSSDeclaration : public nsIDOMCSSStyleDeclaration,
class nsDOMCSSDeclaration : public nsIDOMCSS2Properties,
public nsIScriptObjectOwner
{
public:
@ -34,6 +34,8 @@ public:
NS_DECL_ISUPPORTS
NS_DECL_IDOMCSSSTYLEDECLARATION
NS_DECL_IDOMCSS2PROPERTIES
// nsIScriptObjectOwner interface
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);

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

@ -29,6 +29,7 @@
#include "nsICSSStyleRule.h"
#include "nsIStyleContext.h"
#include "nsIPresContext.h"
#include "nsIDocument.h"
static NS_DEFINE_IID(kIHTMLCSSStyleSheetIID, NS_IHTML_CSS_STYLE_SHEET_IID);
static NS_DEFINE_IID(kIStyleSheetIID, NS_ISTYLE_SHEET_IID);
@ -37,22 +38,26 @@ static NS_DEFINE_IID(kIStyleRuleIID, NS_ISTYLE_RULE_IID);
class BodyFixupRule : public nsIStyleRule {
public:
BodyFixupRule();
BodyFixupRule(nsIHTMLCSSStyleSheet* aSheet);
~BodyFixupRule();
NS_DECL_ISUPPORTS
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aValue) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
// Strength is an out-of-band weighting, always 0 here
NS_IMETHOD GetStrength(PRInt32& aStrength);
NS_IMETHOD MapStyleInto(nsIStyleContext* aContext, nsIPresContext* aPresContext);
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
nsIHTMLCSSStyleSheet* mSheet;
};
BodyFixupRule::BodyFixupRule()
BodyFixupRule::BodyFixupRule(nsIHTMLCSSStyleSheet* aSheet)
: mSheet(aSheet)
{
NS_INIT_REFCNT();
}
@ -77,6 +82,14 @@ BodyFixupRule::HashValue(PRUint32& aValue) const
return NS_OK;
}
NS_IMETHODIMP
BodyFixupRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
// Strength is an out-of-band weighting, always MaxInt here
NS_IMETHODIMP
BodyFixupRule::GetStrength(PRInt32& aStrength)
@ -115,12 +128,27 @@ public:
void* operator new(size_t size, nsIArena* aArena);
void operator delete(void* ptr);
HTMLCSSStyleSheetImpl(nsIURL* aURL);
HTMLCSSStyleSheetImpl(nsIURL* aURL, nsIDocument* aDocument);
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
// basic style sheet data
NS_IMETHOD GetURL(nsIURL*& aURL) const;
NS_IMETHOD GetTitle(nsString& aTitle) const;
NS_IMETHOD GetType(nsString& aType) const;
NS_IMETHOD GetMediumCount(PRInt32& aCount) const;
NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsString& aMedium) const;
NS_IMETHOD GetEnabled(PRBool& aEnabled) const;
NS_IMETHOD SetEnabled(PRBool aEnabled);
// style sheet owner info
NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // will be null
NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aParentContext,
@ -132,8 +160,6 @@ public:
nsIStyleContext* aParentContext,
nsISupportsArray* aResults);
virtual nsIURL* GetURL(void);
// XXX style rule enumerations
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
@ -150,8 +176,9 @@ protected:
PRUint32 mInHeap : 1;
PRUint32 mRefCnt : 31;
nsIURL* mURL;
nsIStyleRule* mBodyRule;
nsIURL* mURL;
nsIDocument* mDocument;
BodyFixupRule* mBodyRule;
};
@ -191,9 +218,10 @@ void HTMLCSSStyleSheetImpl::operator delete(void* ptr)
HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL)
HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL, nsIDocument* aDocument)
: nsIHTMLCSSStyleSheet(),
mURL(aURL),
mDocument(aDocument),
mBodyRule(nsnull)
{
NS_INIT_REFCNT();
@ -203,7 +231,10 @@ HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl(nsIURL* aURL)
HTMLCSSStyleSheetImpl::~HTMLCSSStyleSheetImpl()
{
NS_RELEASE(mURL);
NS_IF_RELEASE(mBodyRule);
if (nsnull != mBodyRule) {
mBodyRule->mSheet = nsnull;
NS_RELEASE(mBodyRule);
}
}
NS_IMPL_ADDREF(HTMLCSSStyleSheetImpl)
@ -274,11 +305,8 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
htmlContent->GetTag(tag);
if (tag == nsHTMLAtoms::body) {
if (nsnull == mBodyRule) {
BodyFixupRule* bodyRule = new BodyFixupRule();
if ((nsnull != bodyRule) &&
(NS_OK != bodyRule->QueryInterface(kIStyleRuleIID, (void**)&mBodyRule))) {
delete bodyRule;
}
mBodyRule = new BodyFixupRule(this);
NS_IF_ADDREF(mBodyRule);
}
if (nsnull != mBodyRule) {
aResults->AppendElement(mBodyRule);
@ -301,10 +329,78 @@ PRInt32 HTMLCSSStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
return 0;
}
nsIURL* HTMLCSSStyleSheetImpl::GetURL(void)
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetURL(nsIURL*& aURL) const
{
NS_ADDREF(mURL);
return mURL;
NS_IF_ADDREF(mURL);
aURL = mURL;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetTitle(nsString& aTitle) const
{
aTitle.Truncate();
aTitle.Append("Internal HTML/CSS Style Sheet");
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetType(nsString& aType) const
{
aType.Truncate();
aType.Append("text/html");
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
{
aCount = 0;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsString& aMedium) const
{
aMedium.Truncate();
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetEnabled(PRBool& aEnabled) const
{
aEnabled = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::SetEnabled(PRBool aEnabled)
{ // these can't be disabled
return NS_OK;
}
// style sheet owner info
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
{
aParent = nsnull;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
{
NS_IF_ADDREF(mDocument);
aDocument = mDocument;
return NS_OK;
}
NS_IMETHODIMP
HTMLCSSStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
{
mDocument = aDocument;
return NS_OK;
}
void HTMLCSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
@ -322,13 +418,14 @@ void HTMLCSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
}
NS_HTML nsresult
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult, nsIURL* aURL)
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult, nsIURL* aURL,
nsIDocument* aDocument)
{
if (aInstancePtrResult == nsnull) {
return NS_ERROR_NULL_POINTER;
}
HTMLCSSStyleSheetImpl* it = new HTMLCSSStyleSheetImpl(aURL);
HTMLCSSStyleSheetImpl* it = new HTMLCSSStyleSheetImpl(aURL, aDocument);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;

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

@ -53,13 +53,14 @@ static NS_DEFINE_IID(kIWebShellIID, NS_IWEB_SHELL_IID);
class HTMLAnchorRule : public nsIStyleRule {
public:
HTMLAnchorRule();
HTMLAnchorRule(nsIHTMLStyleSheet* aSheet);
~HTMLAnchorRule();
NS_DECL_ISUPPORTS
NS_IMETHOD Equals(const nsIStyleRule* aRule, PRBool& aValue) const;
NS_IMETHOD HashValue(PRUint32& aValue) const;
NS_IMETHOD GetStyleSheet(nsIStyleSheet*& aSheet) const;
// Strength is an out-of-band weighting, always 0 here
NS_IMETHOD GetStrength(PRInt32& aStrength);
@ -67,10 +68,12 @@ public:
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
nscolor mColor;
nscolor mColor;
nsIHTMLStyleSheet* mSheet;
};
HTMLAnchorRule::HTMLAnchorRule()
HTMLAnchorRule::HTMLAnchorRule(nsIHTMLStyleSheet* aSheet)
: mSheet(aSheet)
{
NS_INIT_REFCNT();
}
@ -95,6 +98,14 @@ HTMLAnchorRule::HashValue(PRUint32& aValue) const
return NS_OK;
}
NS_IMETHODIMP
HTMLAnchorRule::GetStyleSheet(nsIStyleSheet*& aSheet) const
{
NS_IF_ADDREF(mSheet);
aSheet = mSheet;
return NS_OK;
}
// Strength is an out-of-band weighting, always 0 here
NS_IMETHODIMP
HTMLAnchorRule::GetStrength(PRInt32& aStrength)
@ -201,12 +212,28 @@ public:
void* operator new(size_t size, nsIArena* aArena);
void operator delete(void* ptr);
HTMLStyleSheetImpl(nsIURL* aURL);
HTMLStyleSheetImpl(nsIURL* aURL, nsIDocument* aDocument);
NS_IMETHOD QueryInterface(const nsIID& aIID, void** aInstancePtr);
NS_IMETHOD_(nsrefcnt) AddRef();
NS_IMETHOD_(nsrefcnt) Release();
// nsIStyleSheet api
NS_IMETHOD GetURL(nsIURL*& aURL) const;
NS_IMETHOD GetTitle(nsString& aTitle) const;
NS_IMETHOD GetType(nsString& aType) const;
NS_IMETHOD GetMediumCount(PRInt32& aCount) const;
NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsString& aMedium) const;
NS_IMETHOD GetEnabled(PRBool& aEnabled) const;
NS_IMETHOD SetEnabled(PRBool aEnabled);
// style sheet owner info
NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // will be null
NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
NS_IMETHOD SetOwningDocument(nsIDocument* aDocumemt);
virtual PRInt32 RulesMatching(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIStyleContext* aParentContext,
@ -218,8 +245,6 @@ public:
nsIStyleContext* aParentContext,
nsISupportsArray* aResults);
virtual nsIURL* GetURL(void);
NS_IMETHOD SetLinkColor(nscolor aColor);
NS_IMETHOD SetActiveLinkColor(nscolor aColor);
NS_IMETHOD SetVisitedLinkColor(nscolor aColor);
@ -278,7 +303,17 @@ public:
nsIAtom* aAttribute,
PRInt32 aHint);
// XXX style rule enumerations
// Style change notifications
NS_IMETHOD StyleRuleChanged(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint); // See nsStyleConsts fot hint values
NS_IMETHOD StyleRuleAdded(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD StyleRuleRemoved(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
@ -361,11 +396,12 @@ protected:
PRUint32 mInHeap : 1;
PRUint32 mRefCnt : 31;
nsIURL* mURL;
HTMLAnchorRule* mLinkRule;
HTMLAnchorRule* mVisitedRule;
HTMLAnchorRule* mActiveRule;
nsHashtable mAttrTable;
nsIURL* mURL;
nsIDocument* mDocument;
HTMLAnchorRule* mLinkRule;
HTMLAnchorRule* mVisitedRule;
HTMLAnchorRule* mActiveRule;
nsHashtable mAttrTable;
nsIHTMLAttributes* mRecycledAttrs;
};
@ -406,9 +442,10 @@ void HTMLStyleSheetImpl::operator delete(void* ptr)
HTMLStyleSheetImpl::HTMLStyleSheetImpl(nsIURL* aURL)
HTMLStyleSheetImpl::HTMLStyleSheetImpl(nsIURL* aURL, nsIDocument* aDocument)
: nsIHTMLStyleSheet(),
mURL(aURL),
mDocument(aDocument),
mLinkRule(nsnull),
mVisitedRule(nsnull),
mActiveRule(nsnull),
@ -421,9 +458,18 @@ HTMLStyleSheetImpl::HTMLStyleSheetImpl(nsIURL* aURL)
HTMLStyleSheetImpl::~HTMLStyleSheetImpl()
{
NS_RELEASE(mURL);
NS_IF_RELEASE(mLinkRule);
NS_IF_RELEASE(mVisitedRule);
NS_IF_RELEASE(mActiveRule);
if (nsnull != mLinkRule) {
mLinkRule->mSheet = nsnull;
NS_RELEASE(mLinkRule);
}
if (nsnull != mVisitedRule) {
mVisitedRule->mSheet = nsnull;
NS_RELEASE(mVisitedRule);
}
if (nsnull != mActiveRule) {
mActiveRule->mSheet = nsnull;
NS_RELEASE(mActiveRule);
}
NS_IF_RELEASE(mRecycledAttrs);
}
@ -556,17 +602,85 @@ PRInt32 HTMLStyleSheetImpl::RulesMatching(nsIPresContext* aPresContext,
}
nsIURL* HTMLStyleSheetImpl::GetURL(void)
// nsIStyleSheet api
NS_IMETHODIMP
HTMLStyleSheetImpl::GetURL(nsIURL*& aURL) const
{
NS_ADDREF(mURL);
return mURL;
NS_IF_ADDREF(mURL);
aURL = mURL;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetTitle(nsString& aTitle) const
{
aTitle.Truncate();
aTitle.Append("Internal HTML Style Sheet");
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetType(nsString& aType) const
{
aType.Truncate();
aType.Append("text/html");
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
{
aCount = 0;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsString& aMedium) const
{
aMedium.Truncate();
return NS_ERROR_INVALID_ARG;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetEnabled(PRBool& aEnabled) const
{
aEnabled = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::SetEnabled(PRBool aEnabled)
{ // these can't be disabled
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
{
aParent = nsnull;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
{
NS_IF_ADDREF(mDocument);
aDocument = mDocument;
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
{
mDocument = aDocument;
return NS_OK;
}
NS_IMETHODIMP HTMLStyleSheetImpl::SetLinkColor(nscolor aColor)
{
if (nsnull == mLinkRule) {
mLinkRule = new HTMLAnchorRule();
mLinkRule = new HTMLAnchorRule(this);
if (nsnull == mLinkRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -579,7 +693,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetLinkColor(nscolor aColor)
NS_IMETHODIMP HTMLStyleSheetImpl::SetActiveLinkColor(nscolor aColor)
{
if (nsnull == mActiveRule) {
mActiveRule = new HTMLAnchorRule();
mActiveRule = new HTMLAnchorRule(this);
if (nsnull == mActiveRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -592,7 +706,7 @@ NS_IMETHODIMP HTMLStyleSheetImpl::SetActiveLinkColor(nscolor aColor)
NS_IMETHODIMP HTMLStyleSheetImpl::SetVisitedLinkColor(nscolor aColor)
{
if (nsnull == mVisitedRule) {
mVisitedRule = new HTMLAnchorRule();
mVisitedRule = new HTMLAnchorRule(this);
if (nsnull == mVisitedRule) {
return NS_ERROR_OUT_OF_MEMORY;
}
@ -712,7 +826,7 @@ HTMLStyleSheetImpl::EnsureSingleAttributes(nsIHTMLAttributes*& aAttributes,
aSingleAttrs->SetMappingFunction(aMapFunc);
}
else {
result = NS_NewHTMLAttributes(&aSingleAttrs, aMapFunc);
result = NS_NewHTMLAttributes(&aSingleAttrs, this, aMapFunc);
}
}
else {
@ -2403,6 +2517,77 @@ HTMLStyleSheetImpl::AttributeChanged(nsIPresContext* aPresContext,
return result;
}
// Style change notifications
NS_IMETHODIMP
HTMLStyleSheetImpl::StyleRuleChanged(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint)
{
nsIPresShell* shell = aPresContext->GetShell();
nsIFrame* frame = shell->GetRootFrame();
PRBool reframe = PR_FALSE;
PRBool reflow = PR_FALSE;
PRBool render = PR_FALSE;
PRBool restyle = PR_FALSE;
switch (aHint) {
default:
case NS_STYLE_HINT_UNKNOWN:
case NS_STYLE_HINT_FRAMECHANGE:
reframe = PR_TRUE;
case NS_STYLE_HINT_REFLOW:
reflow = PR_TRUE;
case NS_STYLE_HINT_VISUAL:
render = PR_TRUE;
case NS_STYLE_HINT_CONTENT:
restyle = PR_TRUE;
break;
case NS_STYLE_HINT_AURAL:
break;
}
if (restyle) {
nsIStyleContext* sc;
frame->GetStyleContext(sc);
sc->RemapStyle(aPresContext);
NS_RELEASE(sc);
}
// XXX hack, skip the root and scrolling frames
frame->FirstChild(nsnull, frame);
frame->FirstChild(nsnull, frame);
if (reframe) {
NS_NOTYETIMPLEMENTED("frame change reflow");
}
else if (reflow) {
StyleChangeReflow(aPresContext, frame, nsnull);
}
else if (render) {
ApplyRenderingChangeToTree(aPresContext, frame);
}
NS_RELEASE(shell);
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::StyleRuleAdded(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
return NS_OK;
}
NS_IMETHODIMP
HTMLStyleSheetImpl::StyleRuleRemoved(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
return NS_OK;
}
void HTMLStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
{
@ -2419,13 +2604,14 @@ void HTMLStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
}
NS_HTML nsresult
NS_NewHTMLStyleSheet(nsIHTMLStyleSheet** aInstancePtrResult, nsIURL* aURL)
NS_NewHTMLStyleSheet(nsIHTMLStyleSheet** aInstancePtrResult, nsIURL* aURL,
nsIDocument* aDocument)
{
if (aInstancePtrResult == nsnull) {
return NS_ERROR_NULL_POINTER;
}
HTMLStyleSheetImpl *it = new HTMLStyleSheetImpl(aURL);
HTMLStyleSheetImpl *it = new HTMLStyleSheetImpl(aURL, aDocument);
if (nsnull == it) {
return NS_ERROR_OUT_OF_MEMORY;

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

@ -21,7 +21,7 @@
#include "nslayout.h"
#include "nsISupports.h"
class nsIStyleRule;
class nsIStyleSheet;
class nsICSSStyleSheet;
class nsIUnicharInputStream;
class nsIURL;
class nsString;
@ -40,11 +40,11 @@ public:
// Set a style sheet for the parser to fill in. The style sheet must
// implement the nsICSSStyleSheet interface
NS_IMETHOD SetStyleSheet(nsIStyleSheet* aSheet) = 0;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet) = 0;
NS_IMETHOD Parse(nsIUnicharInputStream* aInput,
nsIURL* aInputURL,
nsIStyleSheet*& aResult) = 0;
nsIURL* aInputURL,
nsICSSStyleSheet*& aResult) = 0;
// Parse declarations assuming that the outer curly braces have
// already been accounted for. aBaseURL is the base url to use for

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

@ -25,7 +25,7 @@ class nsIAtom;
class nsIArena;
class nsString;
class nsICSSDeclaration;
class nsIStyleSheet;
class nsICSSStyleSheet;
struct nsCSSSelector {
public:
@ -66,8 +66,7 @@ public:
virtual nsIStyleRule* GetImportantRule(void) = 0;
virtual nsIStyleSheet* GetStyleSheet(void) = 0;
virtual void SetStyleSheet(nsIStyleSheet *aSheet) = 0;
NS_IMETHOD SetStyleSheet(nsICSSStyleSheet* aSheet) = 0;
};
extern NS_HTML nsresult

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

@ -31,6 +31,7 @@ public:
};
extern NS_HTML nsresult
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult, nsIURL* aURL);
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult, nsIURL* aURL,
nsIDocument* aDocument);
#endif /* nsIHTMLCSSStyleSheet_h___ */

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

@ -87,14 +87,14 @@ public:
nsIStyleContext* aParentContext,
PRBool aForceUnique = PR_FALSE);
NS_IMETHODIMP ConstructFrame(nsIPresContext* aPresContext,
NS_IMETHOD ConstructFrame(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIFrame*& aFrameSubTree);
NS_IMETHOD ReconstructFrames(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIFrame*& aFrameSubTree);
NS_IMETHOD ReconstructFrames(nsIPresContext* aPresContext,
nsIContent* aContent,
nsIFrame* aParentFrame,
nsIFrame* aFrameSubTree);
nsIFrame* aFrameSubTree);
NS_IMETHOD ContentAppended(nsIPresContext* aPresContext,
nsIContent* aContainer,
PRInt32 aNewIndexInContainer);
@ -122,6 +122,18 @@ public:
// xxx style rules enumeration
// Style change notifications
NS_IMETHOD StyleRuleChanged(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint); // See nsStyleConsts fot hint values
NS_IMETHOD StyleRuleAdded(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
NS_IMETHOD StyleRuleRemoved(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule);
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0);
private:
@ -727,7 +739,31 @@ StyleSetImpl::AttributeChanged(nsIPresContext* aPresContext,
}
// xxx style rules enumeration
// Style change notifications
NS_IMETHODIMP
StyleSetImpl::StyleRuleChanged(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule,
PRInt32 aHint)
{
return mFrameConstructor->StyleRuleChanged(aPresContext, aStyleSheet, aStyleRule, aHint);
}
NS_IMETHODIMP
StyleSetImpl::StyleRuleAdded(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
return mFrameConstructor->StyleRuleAdded(aPresContext, aStyleSheet, aStyleRule);
}
NS_IMETHODIMP
StyleSetImpl::StyleRuleRemoved(nsIPresContext* aPresContext,
nsIStyleSheet* aStyleSheet,
nsIStyleRule* aStyleRule)
{
return mFrameConstructor->StyleRuleRemoved(aPresContext, aStyleSheet, aStyleRule);
}
void StyleSetImpl::List(FILE* out, PRInt32 aIndent, nsISupportsArray* aSheets)
{

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

@ -18,7 +18,6 @@
*/
#include "nsXMLContentSink.h"
#include "nsIStyleSheet.h"
#include "nsIUnicharInputStream.h"
#include "nsIDocument.h"
#include "nsIXMLDocument.h"
@ -38,6 +37,7 @@
#include "nsVoidArray.h"
#include "nsCRT.h"
#include "nsICSSParser.h"
#include "nsICSSStyleSheet.h"
#include "nsHTMLAtoms.h"
#include "nsIScriptContext.h"
#include "nsIScriptContextOwner.h"
@ -695,36 +695,19 @@ nsXMLContentSink::AddComment(const nsIParserNode& aNode)
// XXX Borrowed from HTMLContentSink. Should be shared.
nsresult
nsXMLContentSink::LoadStyleSheet(nsIURL* aURL,
nsIUnicharInputStream* aUIN,
PRBool aInline)
nsIUnicharInputStream* aUIN)
{
/* XXX use repository */
nsICSSParser* parser;
nsresult rv = NS_NewCSSParser(&parser);
if (NS_OK == rv) {
if (aInline && (nsnull != mStyleSheet)) {
parser->SetStyleSheet(mStyleSheet);
// XXX we do probably need to trigger a style change reflow
// when we are finished if this is adding data to the same sheet
}
nsIStyleSheet* sheet = nsnull;
nsICSSStyleSheet* sheet = nsnull;
// XXX note: we are ignoring rv until the error code stuff in the
// input routines is converted to use nsresult's
parser->Parse(aUIN, aURL, sheet);
if (nsnull != sheet) {
if (aInline) {
if (nsnull == mStyleSheet) {
// Add in the sheet the first time; if we update the sheet
// with new data (mutliple style tags in the same document)
// then the sheet will be updated by the css parser and
// therefore we don't need to add it to the document)
mDocument->AddStyleSheet(sheet);
mStyleSheet = sheet;
}
}
else {
mDocument->AddStyleSheet(sheet);
}
mDocument->AddStyleSheet(sheet);
NS_RELEASE(sheet);
rv = NS_OK;
} else {
rv = NS_ERROR_OUT_OF_MEMORY;/* XXX */
@ -827,7 +810,7 @@ nsXMLContentSink::AddProcessingInstruction(const nsIParserNode& aNode)
return result;
}
result = LoadStyleSheet(url, uin, PR_FALSE);
result = LoadStyleSheet(url, uin);
NS_RELEASE(uin);
NS_RELEASE(url);
}

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

@ -32,7 +32,6 @@ class nsIContent;
class nsVoidArray;
class nsIXMLDocument;
class nsIUnicharInputStream;
class nsIStyleSheet;
typedef enum {
eXMLContentSinkState_InProlog,
@ -79,8 +78,7 @@ protected:
void StartLayout();
nsresult LoadStyleSheet(nsIURL* aURL,
nsIUnicharInputStream* aUIN,
PRBool aInline);
nsIUnicharInputStream* aUIN);
nsresult FlushText(PRBool aCreateTextNode=PR_TRUE,
PRBool* aDidFlush=nsnull);
@ -119,7 +117,6 @@ protected:
PRInt32 mNestLevel;
nsVoidArray* mContentStack;
nsIStyleSheet* mStyleSheet;
nsScrollPreference mOriginalScrollPreference;
PRUnichar* mText;

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

@ -85,7 +85,10 @@ nsXMLDocument::~nsXMLDocument()
}
mNameSpaces = nsnull;
}
NS_IF_RELEASE(mAttrStyleSheet);
if (nsnull != mAttrStyleSheet) {
mAttrStyleSheet->SetOwningDocument(nsnull);
NS_RELEASE(mAttrStyleSheet);
}
if (nsnull != mProlog) {
delete mProlog;
}
@ -136,6 +139,11 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl,
return rv;
}
if (nsnull != mAttrStyleSheet) {
mAttrStyleSheet->SetOwningDocument(nsnull);
NS_RELEASE(mAttrStyleSheet);
}
nsIWebShell* webShell;
static NS_DEFINE_IID(kCParserIID, NS_IPARSER_IID);
@ -154,7 +162,7 @@ nsXMLDocument::StartDocumentLoad(nsIURL *aUrl,
if (NS_OK == rv) {
// For the HTML content within a document
if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aUrl)) {
if (NS_OK == NS_NewHTMLStyleSheet(&mAttrStyleSheet, aUrl, this)) {
AddStyleSheet(mAttrStyleSheet); // tell the world about our new style sheet
}

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

@ -46,6 +46,7 @@
#include "nsIDocument.h"
#include "nsIDocumentViewer.h"
#include "nsICSSParser.h"
#include "nsICSSStyleSheet.h"
#include "nsLayoutCID.h"
/* Forward declarations.... */
@ -197,7 +198,7 @@ public:
nsIContentViewer** aDocViewer);
};
static nsIStyleSheet* gUAStyleSheet;
static nsICSSStyleSheet* gUAStyleSheet;
nsDocFactoryImpl::nsDocFactoryImpl()
{
@ -535,7 +536,7 @@ nsresult nsDocFactoryImpl::InitUAStyleSheet()
NS_RELEASE(in);
}
else {
// printf("open of %s failed: error=%x\n", UA_CSS_URL, ec);
printf("open of %s failed: error=%x\n", UA_CSS_URL, ec);
rv = NS_ERROR_ILLEGAL_VALUE; // XXX need a better error code here
}

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

@ -46,6 +46,7 @@
#include "nsIDocument.h"
#include "nsIDocumentViewer.h"
#include "nsICSSParser.h"
#include "nsICSSStyleSheet.h"
#include "nsLayoutCID.h"
/* Forward declarations.... */
@ -197,7 +198,7 @@ public:
nsIContentViewer** aDocViewer);
};
static nsIStyleSheet* gUAStyleSheet;
static nsICSSStyleSheet* gUAStyleSheet;
nsDocFactoryImpl::nsDocFactoryImpl()
{
@ -535,7 +536,7 @@ nsresult nsDocFactoryImpl::InitUAStyleSheet()
NS_RELEASE(in);
}
else {
// printf("open of %s failed: error=%x\n", UA_CSS_URL, ec);
printf("open of %s failed: error=%x\n", UA_CSS_URL, ec);
rv = NS_ERROR_ILLEGAL_VALUE; // XXX need a better error code here
}