Making import rules implement the nsIDOMCSSImportRule interface. Bug 90290, r=pierre, sr=jst

This commit is contained in:
bzbarsky%mit.edu 2001-08-04 21:19:53 +00:00
Родитель d22f5bf6ad
Коммит 70d6c75c7c
20 изменённых файлов: 442 добавлений и 83 удалений

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

@ -9,4 +9,4 @@ nsICSSPseudoComparator.h
nsICSSStyleSheet.h
nsIRuleWalker.h
nsIRuleNode.h
nsIMediaList.h

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

@ -37,6 +37,7 @@ EXPORTS = \
nsIComputedDOMStyle.h \
nsIRuleNode.h \
nsIRuleWalker.h \
nsIMediaList.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))

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

@ -21,7 +21,7 @@
DEPTH=..\..\..\..
EXPORTS=nsICSSLoader.h nsICSSParser.h nsICSSPseudoComparator.h nsICSSStyleSheet.h nsICSSLoaderObserver.h nsIComputedDOMStyle.h nsIRuleNode.h nsIRuleWalker.h
EXPORTS=nsICSSLoader.h nsICSSParser.h nsICSSPseudoComparator.h nsICSSStyleSheet.h nsICSSLoaderObserver.h nsIComputedDOMStyle.h nsIRuleNode.h nsIRuleWalker.h nsIMediaList.h
MODULE=raptor
include <$(DEPTH)\config\rules.mak>

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

@ -25,6 +25,7 @@
#include "nslayout.h"
#include "nsISupports.h"
#include "nsAReadableString.h"
#include "nsICSSImportRule.h"
class nsIAtom;
class nsString;
@ -95,7 +96,8 @@ public:
nsIURI* aURL,
const nsString& aMedia,
PRInt32 aDefaultNameSpaceID,
PRInt32 aSheetIndex) = 0;
PRInt32 aSheetIndex,
nsICSSImportRule* aRule) = 0;
// Load a user agent or user sheet immediately
// (note that @imports mayl come in asynchronously)

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

@ -29,6 +29,7 @@ class nsICSSRule;
class nsIDOMNode;
class nsINameSpace;
class nsICSSStyleRuleProcessor;
class nsIMediaList;
// IID for the nsICSSStyleSheet interface {8f83b0f0-b21a-11d1-8031-006008159b5a}
#define NS_ICSS_STYLE_SHEET_IID \

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

@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Boris Zbarsky
* <bzbarsky@mit.edu>. Portions created by Boris Zbarsky are
* Copyright (C) 2001. All Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsIMediaList_h___
#define nsIMediaList_h___
#include "nsISupportsArray.h"
// IID for the nsIMediaList interface {c8c2bbce-1dd1-11b2-a108-f7290a0e6da2}
#define NS_IMEDIA_LIST_IID \
{0xc8c2bbce, 0x1dd1, 0x11b2, {0xa1, 0x08, 0xf7, 0x29, 0x0a, 0x0e, 0x6d, 0xa2}}
class nsIMediaList : public nsISupportsArray {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IMEDIA_LIST_IID; return iid; }
NS_IMETHOD GetMediaText(nsAWritableString& aMediaText) = 0;
NS_IMETHOD SetMediaText(nsAReadableString& aMediaText) = 0;
};
extern NS_HTML nsresult
NS_NewMediaList(nsIMediaList** aInstancePtrResult, const nsAReadableString& aMediaText);
extern NS_HTML nsresult
NS_NewMediaList(nsIMediaList** aInstancePtrResult);
#endif /* nsICSSLoader_h___ */

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

@ -56,6 +56,9 @@
#include "nsIXULPrototypeCache.h"
#endif
#include "nsIDOMMediaList.h"
#include "nsIDOMStyleSheet.h"
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
class CSSLoaderImpl;
@ -137,7 +140,8 @@ public:
nsICSSLoaderObserver* aObserver);
SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL, const nsString& aMedia,
PRInt32 aDefaultNameSpaceID,
nsICSSStyleSheet* aParentSheet, PRInt32 aSheetIndex);
nsICSSStyleSheet* aParentSheet, PRInt32 aSheetIndex,
nsICSSImportRule* aParentRule);
SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
nsICSSLoaderObserver* aObserver);
@ -156,6 +160,7 @@ public:
PRBool mDidBlockParser;
nsICSSStyleSheet* mParentSheet;
nsICSSImportRule* mParentRule;
SheetLoadData* mNext;
SheetLoadData* mParentData;
@ -245,7 +250,8 @@ public:
nsIURI* aURL,
const nsString& aMedia,
PRInt32 aDefaultNameSpaceID,
PRInt32 aIndex);
PRInt32 aIndex,
nsICSSImportRule* aRule);
NS_IMETHOD LoadAgentSheet(nsIURI* aURL,
nsICSSStyleSheet*& aSheet,
@ -345,6 +351,7 @@ SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
mParserToUnblock(aParserToUnblock),
mDidBlockParser(PR_FALSE),
mParentSheet(nsnull),
mParentRule(nsnull),
mNext(nsnull),
mParentData(nsnull),
mPendingChildren(0),
@ -364,7 +371,9 @@ SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
const nsString& aMedia,
PRInt32 aDefaultNameSpaceID,
nsICSSStyleSheet* aParentSheet, PRInt32 aSheetIndex)
nsICSSStyleSheet* aParentSheet,
PRInt32 aSheetIndex,
nsICSSImportRule* aParentRule)
: mLoader(aLoader),
mURL(aURL),
mTitle(),
@ -375,6 +384,7 @@ SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
mParserToUnblock(nsnull),
mDidBlockParser(PR_FALSE),
mParentSheet(aParentSheet),
mParentRule(aParentRule),
mNext(nsnull),
mParentData(nsnull),
mPendingChildren(0),
@ -387,6 +397,7 @@ SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
NS_ADDREF(mLoader);
NS_ADDREF(mURL);
NS_ADDREF(mParentSheet);
NS_ADDREF(mParentRule);
}
SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
@ -401,6 +412,7 @@ SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
mParserToUnblock(nsnull),
mDidBlockParser(PR_FALSE),
mParentSheet(nsnull),
mParentRule(nsnull),
mNext(nsnull),
mParentData(nsnull),
mPendingChildren(0),
@ -423,6 +435,7 @@ SheetLoadData::~SheetLoadData(void)
NS_IF_RELEASE(mOwningElement);
NS_IF_RELEASE(mParserToUnblock);
NS_IF_RELEASE(mParentSheet);
NS_IF_RELEASE(mParentRule);
NS_IF_RELEASE(mObserver);
NS_IF_RELEASE(mNext);
}
@ -797,6 +810,9 @@ CSSLoaderImpl::SheetComplete(nsICSSStyleSheet* aSheet, SheetLoadData* aLoadData)
PrepareSheet(aSheet, data->mTitle, data->mMedia);
if (data->mParentSheet) { // is child sheet
InsertChildSheet(aSheet, data->mParentSheet, data->mSheetIndex);
if (data->mParentRule) { // we have the @import rule that loaded this sheet
data->mParentRule->SetSheet(aSheet);
}
}
else if (data->mIsAgent) { // is agent sheet
if (data->mObserver) {
@ -1409,7 +1425,8 @@ CSSLoaderImpl::LoadChildSheet(nsICSSStyleSheet* aParentSheet,
nsIURI* aURL,
const nsString& aMedia,
PRInt32 aDefaultNameSpaceID,
PRInt32 aIndex)
PRInt32 aIndex,
nsICSSImportRule* aParentRule)
{
nsresult result = NS_ERROR_NULL_POINTER;
@ -1445,13 +1462,16 @@ CSSLoaderImpl::LoadChildSheet(nsICSSStyleSheet* aParentSheet,
result = SetMedia(clone, aMedia);
if (NS_SUCCEEDED(result)) {
result = InsertChildSheet(clone, aParentSheet, aIndex);
if (NS_SUCCEEDED(result) && aParentRule) {
aParentRule->SetSheet(clone);
}
}
NS_RELEASE(clone);
}
}
else {
SheetLoadData* data = new SheetLoadData(this, aURL, aMedia, aDefaultNameSpaceID,
aParentSheet, aIndex);
aParentSheet, aIndex, aParentRule);
if (data == nsnull) {
result = NS_ERROR_OUT_OF_MEMORY;
}

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

@ -959,21 +959,18 @@ PRBool CSSParserImpl::ParseImportRule(PRInt32& aErrorCode)
PRBool CSSParserImpl::ProcessImport(PRInt32& aErrorCode, const nsString& aURLSpec, const nsString& aMedia)
{
PRBool result = PR_FALSE;
nsICSSImportRule* rule = nsnull;
NS_NewCSSImportRule(&rule, aURLSpec, aMedia);
nsCOMPtr<nsICSSImportRule> rule;
NS_NewCSSImportRule(getter_AddRefs(rule), aURLSpec, aMedia);
if (rule) {
AppendRule(rule);
NS_RELEASE(rule);
}
if (mChildLoader) {
// XXX probably need a way to encode unicode junk for the part of
// the url that follows a "?"
nsIURI* url;
nsCOMPtr<nsIURI> url;
// XXX need to have nsILoadGroup passed in here
aErrorCode = NS_NewURI(&url, aURLSpec, mURL/*, group*/);
aErrorCode = NS_NewURI(getter_AddRefs(url), aURLSpec, mURL/*, group*/);
if (NS_FAILED(aErrorCode)) {
// import url is bad
@ -984,12 +981,11 @@ PRBool CSSParserImpl::ProcessImport(PRInt32& aErrorCode, const nsString& aURLSpe
PRBool bContains = PR_FALSE;
if (NS_SUCCEEDED(mSheet->ContainsStyleSheet(url,bContains)) &&
bContains != PR_TRUE ) { // don't allow circular references
mChildLoader->LoadChildSheet(mSheet, url, aMedia, kNameSpaceID_Unknown, mChildSheetCount++);
mChildLoader->LoadChildSheet(mSheet, url, aMedia, kNameSpaceID_Unknown, mChildSheetCount++, rule);
}
NS_RELEASE(url);
}
return result;
return PR_TRUE;
}
// Parse a CSS2 media rule: "@media medium [, medium] { ... }"

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

@ -38,6 +38,10 @@
#include "nsISizeOfHandler.h"
#include "nsIDOMCSSStyleSheet.h"
#include "nsIDOMCSSRule.h"
#include "nsIDOMCSSImportRule.h"
#include "nsIMediaList.h"
#include "nsIDOMMediaList.h"
#include "nsIDOMStyleSheet.h"
#include "nsContentUtils.h"
@ -253,6 +257,8 @@ CSSCharsetRuleImpl::SetCssText(const nsAReadableString& aCssText)
NS_IMETHODIMP
CSSCharsetRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
{
NS_ENSURE_ARG_POINTER(aSheet);
if (mSheet) {
return CallQueryInterface(mSheet, aSheet);
}
@ -273,7 +279,7 @@ CSSCharsetRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
//
class CSSImportRuleImpl : public nsCSSRule,
public nsICSSImportRule,
public nsIDOMCSSRule
public nsIDOMCSSImportRule
{
public:
CSSImportRuleImpl(void);
@ -299,27 +305,42 @@ public:
NS_IMETHOD SetMedia(const nsString& aMedia);
NS_IMETHOD GetMedia(nsString& aMedia) const;
NS_IMETHOD SetSheet(nsICSSStyleSheet*);
// nsIDOMCSSRule interface
NS_DECL_NSIDOMCSSRULE
// nsIDOMCSSImportRule interface
NS_DECL_NSIDOMCSSIMPORTRULE
protected:
nsString mURLSpec;
nsString mMedia;
nsCOMPtr<nsIMediaList> mMedia;
nsCOMPtr<nsICSSStyleSheet> mChildSheet;
};
CSSImportRuleImpl::CSSImportRuleImpl(void)
: nsCSSRule(),
mURLSpec(),
mMedia()
mURLSpec()
{
NS_NewMediaList(getter_AddRefs(mMedia));
}
CSSImportRuleImpl::CSSImportRuleImpl(const CSSImportRuleImpl& aCopy)
: nsCSSRule(aCopy),
mURLSpec(aCopy.mURLSpec),
mMedia(aCopy.mMedia)
mURLSpec(aCopy.mURLSpec)
{
if (aCopy.mChildSheet) {
aCopy.mChildSheet->Clone(*getter_AddRefs(mChildSheet));
}
NS_NewMediaList(getter_AddRefs(mMedia));
if (aCopy.mMedia && mMedia) {
mMedia->AppendElement(aCopy.mMedia);
}
}
CSSImportRuleImpl::~CSSImportRuleImpl(void)
@ -335,6 +356,7 @@ NS_INTERFACE_MAP_BEGIN(CSSImportRuleImpl)
NS_INTERFACE_MAP_ENTRY(nsICSSRule)
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSImportRule)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSImportRule)
NS_INTERFACE_MAP_END
@ -351,7 +373,9 @@ CSSImportRuleImpl::List(FILE* out, PRInt32 aIndent) const
fputs(mURLSpec, out);
fputs("\" ", out);
fputs(mMedia, out);
nsAutoString mediaText;
mMedia->GetMediaText(mediaText);
fputs(mediaText, out);
fputs("\n", out);
return NS_OK;
@ -361,8 +385,7 @@ CSSImportRuleImpl::List(FILE* out, PRInt32 aIndent) const
* SizeOf method:
*
* Self (reported as CSSImportRuleImpl's size):
* 1) sizeof(*this) + the size of the mURLSpec string +
* the size of the mMedia string
* 1) sizeof(*this) + the size of the mURLSpec string
*
* Contained / Aggregated data (not reported as CSSImportRuleImpl's size):
* none
@ -393,9 +416,6 @@ void CSSImportRuleImpl::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize
mURLSpec.SizeOf(aSizeOfHandler, &localSize);
aSize += localSize;
aSize -= sizeof(mURLSpec); // counted in sizeof(*this) and nsString->SizeOf()
mMedia.SizeOf(aSizeOfHandler, &localSize);
aSize += localSize;
aSize -= sizeof(mMedia); // counted in sizeof(*this) and nsString->SizeOf()
aSizeOfHandler->AddSize(tag,aSize);
}
@ -435,14 +455,41 @@ CSSImportRuleImpl::GetURLSpec(nsString& aURLSpec) const
NS_IMETHODIMP
CSSImportRuleImpl::SetMedia(const nsString& aMedia)
{
mMedia = aMedia;
return NS_OK;
if (mMedia) {
return mMedia->SetMediaText(aMedia);
} else {
return NS_OK;
}
}
NS_IMETHODIMP
CSSImportRuleImpl::GetMedia(nsString& aMedia) const
{
aMedia = mMedia;
if (mMedia) {
return mMedia->GetMediaText(aMedia);
} else {
aMedia.Truncate();
return NS_OK;
}
}
NS_IMETHODIMP
CSSImportRuleImpl::SetSheet(nsICSSStyleSheet* aSheet)
{
nsresult rv;
NS_ENSURE_ARG_POINTER(aSheet);
// set the new sheet
mChildSheet = aSheet;
// set our medialist to be the same as the sheet's medialist
nsCOMPtr<nsIDOMStyleSheet> sheet(do_QueryInterface(mChildSheet, &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMMediaList> mediaList;
rv = sheet->GetMedia(getter_AddRefs(mediaList));
NS_ENSURE_SUCCESS(rv, rv);
mMedia = do_QueryInterface(mediaList);
return NS_OK;
}
@ -451,9 +498,7 @@ NS_NewCSSImportRule(nsICSSImportRule** aInstancePtrResult,
const nsString& aURLSpec,
const nsString& aMedia)
{
if (! aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
CSSImportRuleImpl* it = new CSSImportRuleImpl();
@ -469,6 +514,7 @@ NS_NewCSSImportRule(nsICSSImportRule** aInstancePtrResult,
NS_IMETHODIMP
CSSImportRuleImpl::GetType(PRUint16* aType)
{
NS_ENSURE_ARG_POINTER(aType);
*aType = nsIDOMCSSRule::IMPORT_RULE;
return NS_OK;
}
@ -478,8 +524,15 @@ CSSImportRuleImpl::GetCssText(nsAWritableString& aCssText)
{
aCssText.Assign(NS_LITERAL_STRING("@import url("));
aCssText.Append(mURLSpec);
aCssText.Append(NS_LITERAL_STRING(") "));
aCssText.Append(mMedia);
aCssText.Append(NS_LITERAL_STRING(")"));
if (mMedia) {
nsAutoString mediaText;
mMedia->GetMediaText(mediaText);
if (!mediaText.IsEmpty()) {
aCssText.Append(NS_LITERAL_STRING(" "));
aCssText.Append(mediaText);
}
}
aCssText.Append(NS_LITERAL_STRING(";"));
return NS_OK;
}
@ -493,6 +546,7 @@ CSSImportRuleImpl::SetCssText(const nsAReadableString& aCssText)
NS_IMETHODIMP
CSSImportRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
{
NS_ENSURE_ARG_POINTER(aSheet);
if (mSheet) {
return CallQueryInterface(mSheet, aSheet);
}
@ -506,6 +560,36 @@ CSSImportRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
CSSImportRuleImpl::GetHref(nsAWritableString & aHref)
{
aHref = mURLSpec;
return NS_OK;
}
NS_IMETHODIMP
CSSImportRuleImpl::GetMedia(nsIDOMMediaList * *aMedia)
{
NS_ENSURE_ARG_POINTER(aMedia);
if (!mMedia) {
*aMedia = nsnull;
return NS_OK;
}
return CallQueryInterface(mMedia, aMedia);
}
NS_IMETHODIMP
CSSImportRuleImpl::GetStyleSheet(nsIDOMCSSStyleSheet * *aStyleSheet)
{
NS_ENSURE_ARG_POINTER(aStyleSheet);
if (!mChildSheet) {
*aStyleSheet = nsnull;
return NS_OK;
}
return CallQueryInterface(mChildSheet, aStyleSheet);
}
// -------------------------------------------
// nsICSSMediaRule

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

@ -36,6 +36,7 @@
#include "nsICSSStyleRule.h"
#include "nsICSSNameSpaceRule.h"
#include "nsICSSMediaRule.h"
#include "nsIMediaList.h"
#include "nsIHTMLContent.h"
#include "nsIDocument.h"
#include "nsIPresContext.h"
@ -903,7 +904,7 @@ CSSRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn)
}
class DOMMediaListImpl : public nsIDOMMediaList,
public nsISupportsArray
public nsIMediaList
{
NS_DECL_ISUPPORTS
@ -931,10 +932,10 @@ private:
CSSStyleSheetImpl* mStyleSheet;
};
// QueryInterface implementation for CSSStyleRuleImpl
// QueryInterface implementation for DOMMediaListImpl
NS_INTERFACE_MAP_BEGIN(DOMMediaListImpl)
NS_INTERFACE_MAP_ENTRY(nsIDOMMediaList)
NS_INTERFACE_MAP_ENTRY(nsIMediaList)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMediaList)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(MediaList)
NS_INTERFACE_MAP_ENTRY(nsISerializable)
@ -958,6 +959,29 @@ DOMMediaListImpl::~DOMMediaListImpl()
{
}
nsresult
NS_NewMediaList(nsIMediaList** aInstancePtrResult) {
return NS_NewMediaList(aInstancePtrResult, NS_LITERAL_STRING(""));
}
nsresult
NS_NewMediaList(nsIMediaList** aInstancePtrResult, const nsAReadableString& aMediaText) {
nsresult rv;
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
nsCOMPtr<nsISupportsArray> array;
rv = NS_NewISupportsArray(getter_AddRefs(array));
if (NS_FAILED(rv)) {
return NS_ERROR_OUT_OF_MEMORY;
}
DOMMediaListImpl* medialist = new DOMMediaListImpl(array, nsnull);
NS_ENSURE_TRUE(medialist, NS_ERROR_OUT_OF_MEMORY);
rv = medialist->SetMediaText(aMediaText);
NS_ENSURE_SUCCESS(rv, rv);
*aInstancePtrResult = medialist;
NS_ADDREF(*aInstancePtrResult);
}
NS_IMETHODIMP
DOMMediaListImpl::GetMediaText(nsAWritableString& aMediaText)
{
@ -1730,6 +1754,11 @@ CSSStyleSheetImpl::UseForMedium(nsIAtom* aMedium) const
if (-1 != mMedia->IndexOf(nsLayoutAtoms::all)) {
return NS_OK;
}
PRUint32 count;
mMedia->Count(&count);
if (count == 0) { // equivalent to having a medium of "all"
return NS_OK;
}
return NS_COMFALSE;
}
return NS_OK;

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

@ -24,7 +24,7 @@
#include "nslayout.h"
#include "nsICSSRule.h"
//#include "nsString.h"
#include "nsString.h"
class nsIAtom;
class nsIURI;
@ -42,6 +42,8 @@ public:
NS_IMETHOD SetMedia(const nsString& aMedia) = 0;
NS_IMETHOD GetMedia(nsString& aMedia) const = 0;
NS_IMETHOD SetSheet(nsICSSStyleSheet*) = 0;
};
extern NS_HTML nsresult

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

@ -1400,7 +1400,7 @@ nsDOMClassInfo::Init()
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(CSSImportRule, nsIDOMCSSImportRule)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSRule)
DOM_CLASSINFO_MAP_ENTRY(nsIDOMCSSImportRule)
DOM_CLASSINFO_MAP_END
DOM_CLASSINFO_MAP_BEGIN(CSSMediaRule, nsIDOMCSSMediaRule)

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

@ -56,6 +56,9 @@
#include "nsIXULPrototypeCache.h"
#endif
#include "nsIDOMMediaList.h"
#include "nsIDOMStyleSheet.h"
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
class CSSLoaderImpl;
@ -137,7 +140,8 @@ public:
nsICSSLoaderObserver* aObserver);
SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL, const nsString& aMedia,
PRInt32 aDefaultNameSpaceID,
nsICSSStyleSheet* aParentSheet, PRInt32 aSheetIndex);
nsICSSStyleSheet* aParentSheet, PRInt32 aSheetIndex,
nsICSSImportRule* aParentRule);
SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
nsICSSLoaderObserver* aObserver);
@ -156,6 +160,7 @@ public:
PRBool mDidBlockParser;
nsICSSStyleSheet* mParentSheet;
nsICSSImportRule* mParentRule;
SheetLoadData* mNext;
SheetLoadData* mParentData;
@ -245,7 +250,8 @@ public:
nsIURI* aURL,
const nsString& aMedia,
PRInt32 aDefaultNameSpaceID,
PRInt32 aIndex);
PRInt32 aIndex,
nsICSSImportRule* aRule);
NS_IMETHOD LoadAgentSheet(nsIURI* aURL,
nsICSSStyleSheet*& aSheet,
@ -345,6 +351,7 @@ SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
mParserToUnblock(aParserToUnblock),
mDidBlockParser(PR_FALSE),
mParentSheet(nsnull),
mParentRule(nsnull),
mNext(nsnull),
mParentData(nsnull),
mPendingChildren(0),
@ -364,7 +371,9 @@ SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
const nsString& aMedia,
PRInt32 aDefaultNameSpaceID,
nsICSSStyleSheet* aParentSheet, PRInt32 aSheetIndex)
nsICSSStyleSheet* aParentSheet,
PRInt32 aSheetIndex,
nsICSSImportRule* aParentRule)
: mLoader(aLoader),
mURL(aURL),
mTitle(),
@ -375,6 +384,7 @@ SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
mParserToUnblock(nsnull),
mDidBlockParser(PR_FALSE),
mParentSheet(aParentSheet),
mParentRule(aParentRule),
mNext(nsnull),
mParentData(nsnull),
mPendingChildren(0),
@ -387,6 +397,7 @@ SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
NS_ADDREF(mLoader);
NS_ADDREF(mURL);
NS_ADDREF(mParentSheet);
NS_ADDREF(mParentRule);
}
SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
@ -401,6 +412,7 @@ SheetLoadData::SheetLoadData(CSSLoaderImpl* aLoader, nsIURI* aURL,
mParserToUnblock(nsnull),
mDidBlockParser(PR_FALSE),
mParentSheet(nsnull),
mParentRule(nsnull),
mNext(nsnull),
mParentData(nsnull),
mPendingChildren(0),
@ -423,6 +435,7 @@ SheetLoadData::~SheetLoadData(void)
NS_IF_RELEASE(mOwningElement);
NS_IF_RELEASE(mParserToUnblock);
NS_IF_RELEASE(mParentSheet);
NS_IF_RELEASE(mParentRule);
NS_IF_RELEASE(mObserver);
NS_IF_RELEASE(mNext);
}
@ -797,6 +810,9 @@ CSSLoaderImpl::SheetComplete(nsICSSStyleSheet* aSheet, SheetLoadData* aLoadData)
PrepareSheet(aSheet, data->mTitle, data->mMedia);
if (data->mParentSheet) { // is child sheet
InsertChildSheet(aSheet, data->mParentSheet, data->mSheetIndex);
if (data->mParentRule) { // we have the @import rule that loaded this sheet
data->mParentRule->SetSheet(aSheet);
}
}
else if (data->mIsAgent) { // is agent sheet
if (data->mObserver) {
@ -1409,7 +1425,8 @@ CSSLoaderImpl::LoadChildSheet(nsICSSStyleSheet* aParentSheet,
nsIURI* aURL,
const nsString& aMedia,
PRInt32 aDefaultNameSpaceID,
PRInt32 aIndex)
PRInt32 aIndex,
nsICSSImportRule* aParentRule)
{
nsresult result = NS_ERROR_NULL_POINTER;
@ -1445,13 +1462,16 @@ CSSLoaderImpl::LoadChildSheet(nsICSSStyleSheet* aParentSheet,
result = SetMedia(clone, aMedia);
if (NS_SUCCEEDED(result)) {
result = InsertChildSheet(clone, aParentSheet, aIndex);
if (NS_SUCCEEDED(result) && aParentRule) {
aParentRule->SetSheet(clone);
}
}
NS_RELEASE(clone);
}
}
else {
SheetLoadData* data = new SheetLoadData(this, aURL, aMedia, aDefaultNameSpaceID,
aParentSheet, aIndex);
aParentSheet, aIndex, aParentRule);
if (data == nsnull) {
result = NS_ERROR_OUT_OF_MEMORY;
}

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

@ -959,21 +959,18 @@ PRBool CSSParserImpl::ParseImportRule(PRInt32& aErrorCode)
PRBool CSSParserImpl::ProcessImport(PRInt32& aErrorCode, const nsString& aURLSpec, const nsString& aMedia)
{
PRBool result = PR_FALSE;
nsICSSImportRule* rule = nsnull;
NS_NewCSSImportRule(&rule, aURLSpec, aMedia);
nsCOMPtr<nsICSSImportRule> rule;
NS_NewCSSImportRule(getter_AddRefs(rule), aURLSpec, aMedia);
if (rule) {
AppendRule(rule);
NS_RELEASE(rule);
}
if (mChildLoader) {
// XXX probably need a way to encode unicode junk for the part of
// the url that follows a "?"
nsIURI* url;
nsCOMPtr<nsIURI> url;
// XXX need to have nsILoadGroup passed in here
aErrorCode = NS_NewURI(&url, aURLSpec, mURL/*, group*/);
aErrorCode = NS_NewURI(getter_AddRefs(url), aURLSpec, mURL/*, group*/);
if (NS_FAILED(aErrorCode)) {
// import url is bad
@ -984,12 +981,11 @@ PRBool CSSParserImpl::ProcessImport(PRInt32& aErrorCode, const nsString& aURLSpe
PRBool bContains = PR_FALSE;
if (NS_SUCCEEDED(mSheet->ContainsStyleSheet(url,bContains)) &&
bContains != PR_TRUE ) { // don't allow circular references
mChildLoader->LoadChildSheet(mSheet, url, aMedia, kNameSpaceID_Unknown, mChildSheetCount++);
mChildLoader->LoadChildSheet(mSheet, url, aMedia, kNameSpaceID_Unknown, mChildSheetCount++, rule);
}
NS_RELEASE(url);
}
return result;
return PR_TRUE;
}
// Parse a CSS2 media rule: "@media medium [, medium] { ... }"

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

@ -38,6 +38,10 @@
#include "nsISizeOfHandler.h"
#include "nsIDOMCSSStyleSheet.h"
#include "nsIDOMCSSRule.h"
#include "nsIDOMCSSImportRule.h"
#include "nsIMediaList.h"
#include "nsIDOMMediaList.h"
#include "nsIDOMStyleSheet.h"
#include "nsContentUtils.h"
@ -253,6 +257,8 @@ CSSCharsetRuleImpl::SetCssText(const nsAReadableString& aCssText)
NS_IMETHODIMP
CSSCharsetRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
{
NS_ENSURE_ARG_POINTER(aSheet);
if (mSheet) {
return CallQueryInterface(mSheet, aSheet);
}
@ -273,7 +279,7 @@ CSSCharsetRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
//
class CSSImportRuleImpl : public nsCSSRule,
public nsICSSImportRule,
public nsIDOMCSSRule
public nsIDOMCSSImportRule
{
public:
CSSImportRuleImpl(void);
@ -299,27 +305,42 @@ public:
NS_IMETHOD SetMedia(const nsString& aMedia);
NS_IMETHOD GetMedia(nsString& aMedia) const;
NS_IMETHOD SetSheet(nsICSSStyleSheet*);
// nsIDOMCSSRule interface
NS_DECL_NSIDOMCSSRULE
// nsIDOMCSSImportRule interface
NS_DECL_NSIDOMCSSIMPORTRULE
protected:
nsString mURLSpec;
nsString mMedia;
nsCOMPtr<nsIMediaList> mMedia;
nsCOMPtr<nsICSSStyleSheet> mChildSheet;
};
CSSImportRuleImpl::CSSImportRuleImpl(void)
: nsCSSRule(),
mURLSpec(),
mMedia()
mURLSpec()
{
NS_NewMediaList(getter_AddRefs(mMedia));
}
CSSImportRuleImpl::CSSImportRuleImpl(const CSSImportRuleImpl& aCopy)
: nsCSSRule(aCopy),
mURLSpec(aCopy.mURLSpec),
mMedia(aCopy.mMedia)
mURLSpec(aCopy.mURLSpec)
{
if (aCopy.mChildSheet) {
aCopy.mChildSheet->Clone(*getter_AddRefs(mChildSheet));
}
NS_NewMediaList(getter_AddRefs(mMedia));
if (aCopy.mMedia && mMedia) {
mMedia->AppendElement(aCopy.mMedia);
}
}
CSSImportRuleImpl::~CSSImportRuleImpl(void)
@ -335,6 +356,7 @@ NS_INTERFACE_MAP_BEGIN(CSSImportRuleImpl)
NS_INTERFACE_MAP_ENTRY(nsICSSRule)
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSImportRule)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSImportRule)
NS_INTERFACE_MAP_END
@ -351,7 +373,9 @@ CSSImportRuleImpl::List(FILE* out, PRInt32 aIndent) const
fputs(mURLSpec, out);
fputs("\" ", out);
fputs(mMedia, out);
nsAutoString mediaText;
mMedia->GetMediaText(mediaText);
fputs(mediaText, out);
fputs("\n", out);
return NS_OK;
@ -361,8 +385,7 @@ CSSImportRuleImpl::List(FILE* out, PRInt32 aIndent) const
* SizeOf method:
*
* Self (reported as CSSImportRuleImpl's size):
* 1) sizeof(*this) + the size of the mURLSpec string +
* the size of the mMedia string
* 1) sizeof(*this) + the size of the mURLSpec string
*
* Contained / Aggregated data (not reported as CSSImportRuleImpl's size):
* none
@ -393,9 +416,6 @@ void CSSImportRuleImpl::SizeOf(nsISizeOfHandler *aSizeOfHandler, PRUint32 &aSize
mURLSpec.SizeOf(aSizeOfHandler, &localSize);
aSize += localSize;
aSize -= sizeof(mURLSpec); // counted in sizeof(*this) and nsString->SizeOf()
mMedia.SizeOf(aSizeOfHandler, &localSize);
aSize += localSize;
aSize -= sizeof(mMedia); // counted in sizeof(*this) and nsString->SizeOf()
aSizeOfHandler->AddSize(tag,aSize);
}
@ -435,14 +455,41 @@ CSSImportRuleImpl::GetURLSpec(nsString& aURLSpec) const
NS_IMETHODIMP
CSSImportRuleImpl::SetMedia(const nsString& aMedia)
{
mMedia = aMedia;
return NS_OK;
if (mMedia) {
return mMedia->SetMediaText(aMedia);
} else {
return NS_OK;
}
}
NS_IMETHODIMP
CSSImportRuleImpl::GetMedia(nsString& aMedia) const
{
aMedia = mMedia;
if (mMedia) {
return mMedia->GetMediaText(aMedia);
} else {
aMedia.Truncate();
return NS_OK;
}
}
NS_IMETHODIMP
CSSImportRuleImpl::SetSheet(nsICSSStyleSheet* aSheet)
{
nsresult rv;
NS_ENSURE_ARG_POINTER(aSheet);
// set the new sheet
mChildSheet = aSheet;
// set our medialist to be the same as the sheet's medialist
nsCOMPtr<nsIDOMStyleSheet> sheet(do_QueryInterface(mChildSheet, &rv));
NS_ENSURE_SUCCESS(rv, rv);
nsCOMPtr<nsIDOMMediaList> mediaList;
rv = sheet->GetMedia(getter_AddRefs(mediaList));
NS_ENSURE_SUCCESS(rv, rv);
mMedia = do_QueryInterface(mediaList);
return NS_OK;
}
@ -451,9 +498,7 @@ NS_NewCSSImportRule(nsICSSImportRule** aInstancePtrResult,
const nsString& aURLSpec,
const nsString& aMedia)
{
if (! aInstancePtrResult) {
return NS_ERROR_NULL_POINTER;
}
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
CSSImportRuleImpl* it = new CSSImportRuleImpl();
@ -469,6 +514,7 @@ NS_NewCSSImportRule(nsICSSImportRule** aInstancePtrResult,
NS_IMETHODIMP
CSSImportRuleImpl::GetType(PRUint16* aType)
{
NS_ENSURE_ARG_POINTER(aType);
*aType = nsIDOMCSSRule::IMPORT_RULE;
return NS_OK;
}
@ -478,8 +524,15 @@ CSSImportRuleImpl::GetCssText(nsAWritableString& aCssText)
{
aCssText.Assign(NS_LITERAL_STRING("@import url("));
aCssText.Append(mURLSpec);
aCssText.Append(NS_LITERAL_STRING(") "));
aCssText.Append(mMedia);
aCssText.Append(NS_LITERAL_STRING(")"));
if (mMedia) {
nsAutoString mediaText;
mMedia->GetMediaText(mediaText);
if (!mediaText.IsEmpty()) {
aCssText.Append(NS_LITERAL_STRING(" "));
aCssText.Append(mediaText);
}
}
aCssText.Append(NS_LITERAL_STRING(";"));
return NS_OK;
}
@ -493,6 +546,7 @@ CSSImportRuleImpl::SetCssText(const nsAReadableString& aCssText)
NS_IMETHODIMP
CSSImportRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
{
NS_ENSURE_ARG_POINTER(aSheet);
if (mSheet) {
return CallQueryInterface(mSheet, aSheet);
}
@ -506,6 +560,36 @@ CSSImportRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
CSSImportRuleImpl::GetHref(nsAWritableString & aHref)
{
aHref = mURLSpec;
return NS_OK;
}
NS_IMETHODIMP
CSSImportRuleImpl::GetMedia(nsIDOMMediaList * *aMedia)
{
NS_ENSURE_ARG_POINTER(aMedia);
if (!mMedia) {
*aMedia = nsnull;
return NS_OK;
}
return CallQueryInterface(mMedia, aMedia);
}
NS_IMETHODIMP
CSSImportRuleImpl::GetStyleSheet(nsIDOMCSSStyleSheet * *aStyleSheet)
{
NS_ENSURE_ARG_POINTER(aStyleSheet);
if (!mChildSheet) {
*aStyleSheet = nsnull;
return NS_OK;
}
return CallQueryInterface(mChildSheet, aStyleSheet);
}
// -------------------------------------------
// nsICSSMediaRule

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

@ -36,6 +36,7 @@
#include "nsICSSStyleRule.h"
#include "nsICSSNameSpaceRule.h"
#include "nsICSSMediaRule.h"
#include "nsIMediaList.h"
#include "nsIHTMLContent.h"
#include "nsIDocument.h"
#include "nsIPresContext.h"
@ -903,7 +904,7 @@ CSSRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn)
}
class DOMMediaListImpl : public nsIDOMMediaList,
public nsISupportsArray
public nsIMediaList
{
NS_DECL_ISUPPORTS
@ -931,10 +932,10 @@ private:
CSSStyleSheetImpl* mStyleSheet;
};
// QueryInterface implementation for CSSStyleRuleImpl
// QueryInterface implementation for DOMMediaListImpl
NS_INTERFACE_MAP_BEGIN(DOMMediaListImpl)
NS_INTERFACE_MAP_ENTRY(nsIDOMMediaList)
NS_INTERFACE_MAP_ENTRY(nsIMediaList)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIDOMMediaList)
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(MediaList)
NS_INTERFACE_MAP_ENTRY(nsISerializable)
@ -958,6 +959,29 @@ DOMMediaListImpl::~DOMMediaListImpl()
{
}
nsresult
NS_NewMediaList(nsIMediaList** aInstancePtrResult) {
return NS_NewMediaList(aInstancePtrResult, NS_LITERAL_STRING(""));
}
nsresult
NS_NewMediaList(nsIMediaList** aInstancePtrResult, const nsAReadableString& aMediaText) {
nsresult rv;
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
nsCOMPtr<nsISupportsArray> array;
rv = NS_NewISupportsArray(getter_AddRefs(array));
if (NS_FAILED(rv)) {
return NS_ERROR_OUT_OF_MEMORY;
}
DOMMediaListImpl* medialist = new DOMMediaListImpl(array, nsnull);
NS_ENSURE_TRUE(medialist, NS_ERROR_OUT_OF_MEMORY);
rv = medialist->SetMediaText(aMediaText);
NS_ENSURE_SUCCESS(rv, rv);
*aInstancePtrResult = medialist;
NS_ADDREF(*aInstancePtrResult);
}
NS_IMETHODIMP
DOMMediaListImpl::GetMediaText(nsAWritableString& aMediaText)
{
@ -1730,6 +1754,11 @@ CSSStyleSheetImpl::UseForMedium(nsIAtom* aMedium) const
if (-1 != mMedia->IndexOf(nsLayoutAtoms::all)) {
return NS_OK;
}
PRUint32 count;
mMedia->Count(&count);
if (count == 0) { // equivalent to having a medium of "all"
return NS_OK;
}
return NS_COMFALSE;
}
return NS_OK;

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

@ -24,7 +24,7 @@
#include "nslayout.h"
#include "nsICSSRule.h"
//#include "nsString.h"
#include "nsString.h"
class nsIAtom;
class nsIURI;
@ -42,6 +42,8 @@ public:
NS_IMETHOD SetMedia(const nsString& aMedia) = 0;
NS_IMETHOD GetMedia(nsString& aMedia) const = 0;
NS_IMETHOD SetSheet(nsICSSStyleSheet*) = 0;
};
extern NS_HTML nsresult

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

@ -25,6 +25,7 @@
#include "nslayout.h"
#include "nsISupports.h"
#include "nsAReadableString.h"
#include "nsICSSImportRule.h"
class nsIAtom;
class nsString;
@ -95,7 +96,8 @@ public:
nsIURI* aURL,
const nsString& aMedia,
PRInt32 aDefaultNameSpaceID,
PRInt32 aSheetIndex) = 0;
PRInt32 aSheetIndex,
nsICSSImportRule* aRule) = 0;
// Load a user agent or user sheet immediately
// (note that @imports mayl come in asynchronously)

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

@ -29,6 +29,7 @@ class nsICSSRule;
class nsIDOMNode;
class nsINameSpace;
class nsICSSStyleRuleProcessor;
class nsIMediaList;
// IID for the nsICSSStyleSheet interface {8f83b0f0-b21a-11d1-8031-006008159b5a}
#define NS_ICSS_STYLE_SHEET_IID \

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

@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Boris Zbarsky
* <bzbarsky@mit.edu>. Portions created by Boris Zbarsky are
* Copyright (C) 2001. All Rights Reserved.
*
* Contributor(s):
*/
#ifndef nsIMediaList_h___
#define nsIMediaList_h___
#include "nsISupportsArray.h"
// IID for the nsIMediaList interface {c8c2bbce-1dd1-11b2-a108-f7290a0e6da2}
#define NS_IMEDIA_LIST_IID \
{0xc8c2bbce, 0x1dd1, 0x11b2, {0xa1, 0x08, 0xf7, 0x29, 0x0a, 0x0e, 0x6d, 0xa2}}
class nsIMediaList : public nsISupportsArray {
public:
static const nsIID& GetIID() { static nsIID iid = NS_IMEDIA_LIST_IID; return iid; }
NS_IMETHOD GetMediaText(nsAWritableString& aMediaText) = 0;
NS_IMETHOD SetMediaText(nsAReadableString& aMediaText) = 0;
};
extern NS_HTML nsresult
NS_NewMediaList(nsIMediaList** aInstancePtrResult, const nsAReadableString& aMediaText);
extern NS_HTML nsresult
NS_NewMediaList(nsIMediaList** aInstancePtrResult);
#endif /* nsICSSLoader_h___ */