2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-06-10 09:32:38 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* 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/
|
1999-06-10 09:32:38 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* 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.
|
1999-06-10 09:32:38 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 05:32:19 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Contributor(s):
|
2004-04-18 01:52:36 +04:00
|
|
|
* Boris Zbarsky <bzbarsky@mit.edu>
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 05:32:19 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 05:32:19 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/* rules in a CSS stylesheet other than style rules (e.g., @import rules) */
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
#include "nsCSSRules.h"
|
1999-06-10 09:32:38 +04:00
|
|
|
#include "nsICSSImportRule.h"
|
|
|
|
#include "nsICSSNameSpaceRule.h"
|
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
|
|
|
|
#include "nsCSSRule.h"
|
|
|
|
#include "nsLayoutAtoms.h"
|
|
|
|
#include "nsICSSStyleSheet.h"
|
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2001-05-15 12:26:13 +04:00
|
|
|
#include "nsIDOMCSSStyleSheet.h"
|
|
|
|
#include "nsIDOMCSSRule.h"
|
2001-08-05 01:19:53 +04:00
|
|
|
#include "nsIDOMCSSImportRule.h"
|
2001-09-05 04:00:18 +04:00
|
|
|
#include "nsIDOMCSSMediaRule.h"
|
2004-08-05 22:26:14 +04:00
|
|
|
#include "nsIDOMCSSMozDocumentRule.h"
|
2002-08-06 09:26:41 +04:00
|
|
|
#include "nsIDOMCSSCharsetRule.h"
|
2001-08-05 01:19:53 +04:00
|
|
|
#include "nsIMediaList.h"
|
|
|
|
#include "nsIDOMMediaList.h"
|
2001-09-05 04:00:18 +04:00
|
|
|
#include "nsIDOMCSSRuleList.h"
|
2001-08-05 01:19:53 +04:00
|
|
|
#include "nsIDOMStyleSheet.h"
|
2001-09-05 04:00:18 +04:00
|
|
|
#include "nsIDocument.h"
|
2004-08-05 22:26:14 +04:00
|
|
|
#include "nsPresContext.h"
|
2001-05-15 12:26:13 +04:00
|
|
|
|
|
|
|
#include "nsContentUtils.h"
|
2001-09-05 04:00:18 +04:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsDOMError.h"
|
2006-03-22 21:36:36 +03:00
|
|
|
#include "nsIEnumerator.h"
|
1999-06-10 09:32:38 +04:00
|
|
|
|
|
|
|
#define IMPL_STYLE_RULE_INHERIT(_class, super) \
|
|
|
|
NS_IMETHODIMP _class::GetStyleSheet(nsIStyleSheet*& aSheet) const { return super::GetStyleSheet(aSheet); } \
|
|
|
|
NS_IMETHODIMP _class::SetStyleSheet(nsICSSStyleSheet* aSheet) { return super::SetStyleSheet(aSheet); } \
|
2001-09-19 18:16:34 +04:00
|
|
|
NS_IMETHODIMP _class::SetParentRule(nsICSSGroupRule* aRule) { return super::SetParentRule(aRule); } \
|
2003-06-24 09:40:37 +04:00
|
|
|
NS_IMETHODIMP _class::GetDOMRule(nsIDOMCSSRule** aDOMRule) { return CallQueryInterface(this, aDOMRule); } \
|
2001-06-01 02:19:43 +04:00
|
|
|
NS_IMETHODIMP _class::MapRuleInfoInto(nsRuleData* aRuleData) { return NS_OK; }
|
1999-06-10 09:32:38 +04:00
|
|
|
|
|
|
|
#define IMPL_STYLE_RULE_INHERIT2(_class, super) \
|
|
|
|
NS_IMETHODIMP _class::GetStyleSheet(nsIStyleSheet*& aSheet) const { return super::GetStyleSheet(aSheet); } \
|
2001-09-19 18:16:34 +04:00
|
|
|
NS_IMETHODIMP _class::SetParentRule(nsICSSGroupRule* aRule) { return super::SetParentRule(aRule); } \
|
2003-06-24 09:40:37 +04:00
|
|
|
NS_IMETHODIMP _class::GetDOMRule(nsIDOMCSSRule** aDOMRule) { return CallQueryInterface(this, aDOMRule); } \
|
2001-06-01 02:19:43 +04:00
|
|
|
NS_IMETHODIMP _class::MapRuleInfoInto(nsRuleData* aRuleData) { return NS_OK; }
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
// -------------------------------
|
|
|
|
// Style Rule List for group rules
|
|
|
|
//
|
|
|
|
class CSSGroupRuleRuleListImpl : public nsIDOMCSSRuleList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSSGroupRuleRuleListImpl(nsICSSGroupRule *aGroupRule);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_DECL_NSIDOMCSSRULELIST
|
|
|
|
|
|
|
|
void DropReference() { mGroupRule = nsnull; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~CSSGroupRuleRuleListImpl(void);
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsICSSGroupRule* mGroupRule;
|
|
|
|
};
|
|
|
|
|
|
|
|
CSSGroupRuleRuleListImpl::CSSGroupRuleRuleListImpl(nsICSSGroupRule *aGroupRule)
|
|
|
|
{
|
|
|
|
// Not reference counted to avoid circular references.
|
|
|
|
// The rule will tell us when its going away.
|
|
|
|
mGroupRule = aGroupRule;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSGroupRuleRuleListImpl::~CSSGroupRuleRuleListImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryInterface implementation for CSSGroupRuleRuleList
|
|
|
|
NS_INTERFACE_MAP_BEGIN(CSSGroupRuleRuleListImpl)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRuleList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSGroupRuleRuleList)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
2003-09-08 01:50:21 +04:00
|
|
|
NS_IMPL_ADDREF(CSSGroupRuleRuleListImpl)
|
|
|
|
NS_IMPL_RELEASE(CSSGroupRuleRuleListImpl)
|
2001-09-05 04:00:18 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSGroupRuleRuleListImpl::GetLength(PRUint32* aLength)
|
|
|
|
{
|
|
|
|
if (mGroupRule) {
|
|
|
|
PRInt32 count;
|
|
|
|
mGroupRule->StyleRuleCount(count);
|
|
|
|
*aLength = (PRUint32)count;
|
|
|
|
} else {
|
|
|
|
*aLength = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSGroupRuleRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
*aReturn = nsnull;
|
|
|
|
if (mGroupRule) {
|
|
|
|
nsCOMPtr<nsICSSRule> rule;
|
|
|
|
|
|
|
|
result = mGroupRule->GetStyleRuleAt(aIndex, *getter_AddRefs(rule));
|
|
|
|
if (rule) {
|
2003-06-24 09:40:37 +04:00
|
|
|
result = rule->GetDOMRule(aReturn);
|
2001-09-05 04:00:18 +04:00
|
|
|
} else if (result == NS_ERROR_ILLEGAL_VALUE) {
|
|
|
|
result = NS_OK; // per spec: "Return Value ... null if ... not a valid index."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
// -------------------------------------------
|
2002-08-06 09:26:41 +04:00
|
|
|
// CharsetRule
|
1999-06-10 09:32:38 +04:00
|
|
|
//
|
|
|
|
class CSSCharsetRuleImpl : public nsCSSRule,
|
2002-08-06 09:26:41 +04:00
|
|
|
public nsICSSRule,
|
|
|
|
public nsIDOMCSSCharsetRule
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
public:
|
2002-08-06 09:26:41 +04:00
|
|
|
CSSCharsetRuleImpl(const nsAString& aEncoding);
|
1999-06-10 09:32:38 +04:00
|
|
|
CSSCharsetRuleImpl(const CSSCharsetRuleImpl& aCopy);
|
|
|
|
virtual ~CSSCharsetRuleImpl(void);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
DECL_STYLE_RULE_INHERIT
|
|
|
|
|
|
|
|
// nsIStyleRule methods
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1999-06-10 09:32:38 +04:00
|
|
|
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
// nsICSSRule methods
|
|
|
|
NS_IMETHOD GetType(PRInt32& aType) const;
|
|
|
|
NS_IMETHOD Clone(nsICSSRule*& aClone) const;
|
|
|
|
|
2001-05-15 12:26:13 +04:00
|
|
|
// nsIDOMCSSRule interface
|
|
|
|
NS_DECL_NSIDOMCSSRULE
|
|
|
|
|
2002-08-06 09:26:41 +04:00
|
|
|
// nsIDOMCSSCharsetRule methods
|
|
|
|
NS_IMETHOD GetEncoding(nsAString& aEncoding);
|
|
|
|
NS_IMETHOD SetEncoding(const nsAString& aEncoding);
|
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
protected:
|
|
|
|
nsString mEncoding;
|
|
|
|
};
|
|
|
|
|
2002-08-06 09:26:41 +04:00
|
|
|
CSSCharsetRuleImpl::CSSCharsetRuleImpl(const nsAString& aEncoding)
|
1999-06-10 09:32:38 +04:00
|
|
|
: nsCSSRule(),
|
2002-08-06 09:26:41 +04:00
|
|
|
mEncoding(aEncoding)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSCharsetRuleImpl::CSSCharsetRuleImpl(const CSSCharsetRuleImpl& aCopy)
|
|
|
|
: nsCSSRule(aCopy),
|
|
|
|
mEncoding(aCopy.mEncoding)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSCharsetRuleImpl::~CSSCharsetRuleImpl(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-09-08 01:50:21 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(CSSCharsetRuleImpl, nsCSSRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(CSSCharsetRuleImpl, nsCSSRule)
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2001-05-15 12:26:13 +04:00
|
|
|
// QueryInterface implementation for CSSCharsetRuleImpl
|
|
|
|
NS_INTERFACE_MAP_BEGIN(CSSCharsetRuleImpl)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
2002-08-06 09:26:41 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSCharsetRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSRule)
|
2001-05-15 12:26:13 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSCharsetRule)
|
|
|
|
NS_INTERFACE_MAP_END
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2003-09-08 01:50:21 +04:00
|
|
|
IMPL_STYLE_RULE_INHERIT(CSSCharsetRuleImpl, nsCSSRule)
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1999-06-10 09:32:38 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSCharsetRuleImpl::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("@charset \"", out);
|
2006-02-03 17:18:39 +03:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mEncoding).get(), out);
|
1999-06-10 09:32:38 +04:00
|
|
|
fputs("\"\n", out);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSCharsetRuleImpl::GetType(PRInt32& aType) const
|
|
|
|
{
|
|
|
|
aType = nsICSSRule::CHARSET_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSCharsetRuleImpl::Clone(nsICSSRule*& aClone) const
|
|
|
|
{
|
|
|
|
CSSCharsetRuleImpl* clone = new CSSCharsetRuleImpl(*this);
|
|
|
|
if (clone) {
|
2002-12-11 17:24:49 +03:00
|
|
|
return CallQueryInterface(clone, &aClone);
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
aClone = nsnull;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-08-06 09:26:41 +04:00
|
|
|
CSSCharsetRuleImpl::GetEncoding(nsAString& aEncoding)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
aEncoding = mEncoding;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-08-06 09:26:41 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSCharsetRuleImpl::SetEncoding(const nsAString& aEncoding)
|
|
|
|
{
|
|
|
|
mEncoding = aEncoding;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2003-03-05 18:08:41 +03:00
|
|
|
nsresult
|
2002-08-06 09:26:41 +04:00
|
|
|
NS_NewCSSCharsetRule(nsICSSRule** aInstancePtrResult, const nsAString& aEncoding)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
if (! aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
2002-08-06 09:26:41 +04:00
|
|
|
CSSCharsetRuleImpl* it = new CSSCharsetRuleImpl(aEncoding);
|
1999-06-10 09:32:38 +04:00
|
|
|
|
|
|
|
if (! it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2002-08-06 09:26:41 +04:00
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2001-05-15 12:26:13 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSCharsetRuleImpl::GetType(PRUint16* aType)
|
|
|
|
{
|
|
|
|
*aType = nsIDOMCSSRule::CHARSET_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSCharsetRuleImpl::GetCssText(nsAString& aCssText)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AssignLiteral("@charset \"");
|
2001-05-15 12:26:13 +04:00
|
|
|
aCssText.Append(mEncoding);
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AppendLiteral("\";");
|
2001-05-15 12:26:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSCharsetRuleImpl::SetCssText(const nsAString& aCssText)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSCharsetRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
|
|
|
{
|
2001-08-05 01:19:53 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aSheet);
|
|
|
|
|
2001-05-15 12:26:13 +04:00
|
|
|
if (mSheet) {
|
|
|
|
return CallQueryInterface(mSheet, aSheet);
|
|
|
|
}
|
|
|
|
*aSheet = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSCharsetRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
2001-09-19 18:16:34 +04:00
|
|
|
if (mParentRule) {
|
2003-06-24 09:40:37 +04:00
|
|
|
return mParentRule->GetDOMRule(aParentRule);
|
2001-09-19 18:16:34 +04:00
|
|
|
}
|
|
|
|
*aParentRule = nsnull;
|
|
|
|
return NS_OK;
|
2001-05-15 12:26:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
// nsICSSImportRule
|
|
|
|
//
|
|
|
|
class CSSImportRuleImpl : public nsCSSRule,
|
2001-05-15 12:26:13 +04:00
|
|
|
public nsICSSImportRule,
|
2001-08-05 01:19:53 +04:00
|
|
|
public nsIDOMCSSImportRule
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
public:
|
2005-03-30 04:36:57 +04:00
|
|
|
CSSImportRuleImpl(nsMediaList* aMedia);
|
1999-06-10 09:32:38 +04:00
|
|
|
CSSImportRuleImpl(const CSSImportRuleImpl& aCopy);
|
|
|
|
virtual ~CSSImportRuleImpl(void);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
DECL_STYLE_RULE_INHERIT
|
|
|
|
|
|
|
|
// nsIStyleRule methods
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1999-06-10 09:32:38 +04:00
|
|
|
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
// nsICSSRule methods
|
|
|
|
NS_IMETHOD GetType(PRInt32& aType) const;
|
|
|
|
NS_IMETHOD Clone(nsICSSRule*& aClone) const;
|
|
|
|
|
|
|
|
// nsICSSImportRule methods
|
|
|
|
NS_IMETHOD SetURLSpec(const nsString& aURLSpec);
|
|
|
|
NS_IMETHOD GetURLSpec(nsString& aURLSpec) const;
|
|
|
|
|
|
|
|
NS_IMETHOD SetMedia(const nsString& aMedia);
|
|
|
|
NS_IMETHOD GetMedia(nsString& aMedia) const;
|
2001-08-05 01:19:53 +04:00
|
|
|
|
|
|
|
NS_IMETHOD SetSheet(nsICSSStyleSheet*);
|
2001-05-15 12:26:13 +04:00
|
|
|
|
|
|
|
// nsIDOMCSSRule interface
|
|
|
|
NS_DECL_NSIDOMCSSRULE
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2001-08-05 01:19:53 +04:00
|
|
|
// nsIDOMCSSImportRule interface
|
|
|
|
NS_DECL_NSIDOMCSSIMPORTRULE
|
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
protected:
|
|
|
|
nsString mURLSpec;
|
2005-12-02 15:02:44 +03:00
|
|
|
nsRefPtr<nsMediaList> mMedia;
|
2001-08-05 01:19:53 +04:00
|
|
|
nsCOMPtr<nsICSSStyleSheet> mChildSheet;
|
1999-06-10 09:32:38 +04:00
|
|
|
};
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
CSSImportRuleImpl::CSSImportRuleImpl(nsMediaList* aMedia)
|
|
|
|
: nsCSSRule()
|
|
|
|
, mURLSpec()
|
|
|
|
, mMedia(aMedia)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2005-03-30 04:36:57 +04:00
|
|
|
// XXXbz This is really silly.... the mMedia here will be replaced
|
|
|
|
// with itself if we manage to load a sheet. Which should really
|
2004-01-10 05:27:41 +03:00
|
|
|
// never fail nowadays, in sane cases.
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CSSImportRuleImpl::CSSImportRuleImpl(const CSSImportRuleImpl& aCopy)
|
|
|
|
: nsCSSRule(aCopy),
|
2001-08-05 01:19:53 +04:00
|
|
|
mURLSpec(aCopy.mURLSpec)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2004-01-10 05:27:41 +03:00
|
|
|
nsCOMPtr<nsICSSStyleSheet> sheet;
|
2001-08-05 01:19:53 +04:00
|
|
|
if (aCopy.mChildSheet) {
|
2003-02-23 08:36:40 +03:00
|
|
|
aCopy.mChildSheet->Clone(nsnull, this, nsnull, nsnull,
|
2004-01-10 05:27:41 +03:00
|
|
|
getter_AddRefs(sheet));
|
2001-08-05 01:19:53 +04:00
|
|
|
}
|
2004-01-10 05:27:41 +03:00
|
|
|
SetSheet(sheet);
|
2005-03-30 04:36:57 +04:00
|
|
|
// SetSheet sets mMedia appropriately
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CSSImportRuleImpl::~CSSImportRuleImpl(void)
|
|
|
|
{
|
2002-08-06 09:08:47 +04:00
|
|
|
if (mChildSheet) {
|
|
|
|
mChildSheet->SetOwnerRule(nsnull);
|
|
|
|
}
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2003-09-08 01:50:21 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(CSSImportRuleImpl, nsCSSRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(CSSImportRuleImpl, nsCSSRule)
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2001-05-15 12:26:13 +04:00
|
|
|
// QueryInterface implementation for CSSImportRuleImpl
|
|
|
|
NS_INTERFACE_MAP_BEGIN(CSSImportRuleImpl)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSImportRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
2001-08-05 01:19:53 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule)
|
2001-05-15 12:26:13 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSImportRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSImportRule)
|
|
|
|
NS_INTERFACE_MAP_END
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2003-09-08 01:50:21 +04:00
|
|
|
IMPL_STYLE_RULE_INHERIT(CSSImportRuleImpl, nsCSSRule)
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1999-06-10 09:32:38 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportRuleImpl::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("@import \"", out);
|
2006-02-03 17:18:39 +03:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mURLSpec).get(), out);
|
1999-06-10 09:32:38 +04:00
|
|
|
fputs("\" ", out);
|
|
|
|
|
2001-08-05 01:19:53 +04:00
|
|
|
nsAutoString mediaText;
|
2001-09-05 04:00:18 +04:00
|
|
|
mMedia->GetText(mediaText);
|
2006-02-03 17:18:39 +03:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mediaText).get(), out);
|
1999-06-10 09:32:38 +04:00
|
|
|
fputs("\n", out);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportRuleImpl::GetType(PRInt32& aType) const
|
|
|
|
{
|
|
|
|
aType = nsICSSRule::IMPORT_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportRuleImpl::Clone(nsICSSRule*& aClone) const
|
|
|
|
{
|
|
|
|
CSSImportRuleImpl* clone = new CSSImportRuleImpl(*this);
|
|
|
|
if (clone) {
|
2002-12-11 17:24:49 +03:00
|
|
|
return CallQueryInterface(clone, &aClone);
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
aClone = nsnull;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportRuleImpl::SetURLSpec(const nsString& aURLSpec)
|
|
|
|
{
|
|
|
|
mURLSpec = aURLSpec;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportRuleImpl::GetURLSpec(nsString& aURLSpec) const
|
|
|
|
{
|
|
|
|
aURLSpec = mURLSpec;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportRuleImpl::SetMedia(const nsString& aMedia)
|
|
|
|
{
|
2001-08-05 01:19:53 +04:00
|
|
|
if (mMedia) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return mMedia->SetText(aMedia);
|
2001-08-05 01:19:53 +04:00
|
|
|
} else {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportRuleImpl::GetMedia(nsString& aMedia) const
|
|
|
|
{
|
2001-08-05 01:19:53 +04:00
|
|
|
if (mMedia) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return mMedia->GetText(aMedia);
|
2001-08-05 01:19:53 +04:00
|
|
|
} 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;
|
2002-08-06 09:08:47 +04:00
|
|
|
aSheet->SetOwnerRule(this);
|
2001-08-05 01:19:53 +04:00
|
|
|
|
|
|
|
// 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);
|
2005-12-02 15:02:44 +03:00
|
|
|
mMedia = NS_STATIC_CAST(nsMediaList*,
|
|
|
|
NS_STATIC_CAST(nsIDOMMediaList*, mediaList.get()));
|
2001-08-05 01:19:53 +04:00
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-05 18:08:41 +03:00
|
|
|
nsresult
|
1999-06-10 09:32:38 +04:00
|
|
|
NS_NewCSSImportRule(nsICSSImportRule** aInstancePtrResult,
|
|
|
|
const nsString& aURLSpec,
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList* aMedia)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2001-08-05 01:19:53 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aInstancePtrResult);
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2004-01-10 05:27:41 +03:00
|
|
|
CSSImportRuleImpl* it = new CSSImportRuleImpl(aMedia);
|
1999-06-10 09:32:38 +04:00
|
|
|
|
|
|
|
if (! it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
it->SetURLSpec(aURLSpec);
|
2002-08-06 09:26:41 +04:00
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2001-05-15 12:26:13 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportRuleImpl::GetType(PRUint16* aType)
|
|
|
|
{
|
2001-08-05 01:19:53 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aType);
|
2001-05-15 12:26:13 +04:00
|
|
|
*aType = nsIDOMCSSRule::IMPORT_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSImportRuleImpl::GetCssText(nsAString& aCssText)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AssignLiteral("@import url(");
|
2001-05-15 12:26:13 +04:00
|
|
|
aCssText.Append(mURLSpec);
|
2001-08-05 01:19:53 +04:00
|
|
|
aCssText.Append(NS_LITERAL_STRING(")"));
|
|
|
|
if (mMedia) {
|
|
|
|
nsAutoString mediaText;
|
2001-09-05 04:00:18 +04:00
|
|
|
mMedia->GetText(mediaText);
|
2001-08-05 01:19:53 +04:00
|
|
|
if (!mediaText.IsEmpty()) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AppendLiteral(" ");
|
2001-08-05 01:19:53 +04:00
|
|
|
aCssText.Append(mediaText);
|
|
|
|
}
|
|
|
|
}
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AppendLiteral(";");
|
2001-05-15 12:26:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSImportRuleImpl::SetCssText(const nsAString& aCssText)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
|
|
|
{
|
2001-08-05 01:19:53 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aSheet);
|
2001-05-15 12:26:13 +04:00
|
|
|
if (mSheet) {
|
|
|
|
return CallQueryInterface(mSheet, aSheet);
|
|
|
|
}
|
|
|
|
*aSheet = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
2001-09-19 18:16:34 +04:00
|
|
|
if (mParentRule) {
|
2003-06-24 09:40:37 +04:00
|
|
|
return mParentRule->GetDOMRule(aParentRule);
|
2001-09-19 18:16:34 +04:00
|
|
|
}
|
|
|
|
*aParentRule = nsnull;
|
|
|
|
return NS_OK;
|
2001-05-15 12:26:13 +04:00
|
|
|
}
|
|
|
|
|
2001-08-05 01:19:53 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSImportRuleImpl::GetHref(nsAString & aHref)
|
2001-08-05 01:19:53 +04:00
|
|
|
{
|
|
|
|
aHref = mURLSpec;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportRuleImpl::GetMedia(nsIDOMMediaList * *aMedia)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aMedia);
|
|
|
|
if (!mMedia) {
|
|
|
|
*aMedia = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-12-02 15:02:44 +03:00
|
|
|
return CallQueryInterface(mMedia.get(), aMedia);
|
2001-08-05 01:19:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportRuleImpl::GetStyleSheet(nsIDOMCSSStyleSheet * *aStyleSheet)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aStyleSheet);
|
|
|
|
if (!mChildSheet) {
|
|
|
|
*aStyleSheet = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(mChildSheet, aStyleSheet);
|
|
|
|
}
|
2001-05-15 12:26:13 +04:00
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
nsCSSGroupRule::nsCSSGroupRule()
|
|
|
|
: nsCSSRule()
|
|
|
|
, mRuleCollection(nsnull)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static PRBool
|
2005-10-16 00:21:20 +04:00
|
|
|
CloneRuleInto(nsICSSRule* aRule, void* aArray)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
nsICSSRule* clone = nsnull;
|
2005-10-16 00:21:20 +04:00
|
|
|
aRule->Clone(clone);
|
1999-06-10 09:32:38 +04:00
|
|
|
if (clone) {
|
2005-10-16 00:21:20 +04:00
|
|
|
NS_STATIC_CAST(nsCOMArray<nsICSSRule>*, aArray)->AppendObject(clone);
|
1999-06-10 09:32:38 +04:00
|
|
|
NS_RELEASE(clone);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2001-09-20 06:38:56 +04:00
|
|
|
static PRBool
|
2005-10-16 00:21:20 +04:00
|
|
|
SetParentRuleReference(nsICSSRule* aRule, void* aParentRule)
|
2001-09-19 18:16:34 +04:00
|
|
|
{
|
2004-08-05 22:26:14 +04:00
|
|
|
nsCSSGroupRule* parentRule = NS_STATIC_CAST(nsCSSGroupRule*, aParentRule);
|
2005-10-16 00:21:20 +04:00
|
|
|
aRule->SetParentRule(parentRule);
|
2001-09-19 18:16:34 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
nsCSSGroupRule::nsCSSGroupRule(const nsCSSGroupRule& aCopy)
|
|
|
|
: nsCSSRule(aCopy)
|
|
|
|
, mRuleCollection(nsnull) // lazily constructed
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
NS_CONST_CAST(nsCSSGroupRule&, aCopy).mRules.EnumerateForwards(CloneRuleInto, &mRules);
|
|
|
|
mRules.EnumerateForwards(SetParentRuleReference, this);
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
nsCSSGroupRule::~nsCSSGroupRule()
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
mRules.EnumerateForwards(SetParentRuleReference, nsnull);
|
2001-09-05 04:00:18 +04:00
|
|
|
if (mRuleCollection) {
|
|
|
|
mRuleCollection->DropReference();
|
|
|
|
NS_RELEASE(mRuleCollection);
|
|
|
|
}
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
IMPL_STYLE_RULE_INHERIT2(nsCSSGroupRule, nsCSSRule)
|
1999-06-10 09:32:38 +04:00
|
|
|
|
|
|
|
static PRBool
|
2005-10-16 00:21:20 +04:00
|
|
|
SetStyleSheetReference(nsICSSRule* aRule, void* aSheet)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
nsICSSStyleSheet* sheet = (nsICSSStyleSheet*)aSheet;
|
2005-10-16 00:21:20 +04:00
|
|
|
aRule->SetStyleSheet(sheet);
|
1999-06-10 09:32:38 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-05 22:26:14 +04:00
|
|
|
nsCSSGroupRule::SetStyleSheet(nsICSSStyleSheet* aSheet)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
mRules.EnumerateForwards(SetStyleSheetReference, aSheet);
|
1999-06-10 09:32:38 +04:00
|
|
|
return nsCSSRule::SetStyleSheet(aSheet);
|
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2004-08-06 23:48:04 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-05 22:26:14 +04:00
|
|
|
nsCSSGroupRule::List(FILE* out, PRInt32 aIndent) const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
fputs(" {\n", out);
|
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
for (PRInt32 index = 0, count = mRules.Count(); index < count; ++index) {
|
|
|
|
mRules.ObjectAt(index)->List(out, aIndent + 1);
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
fputs("}\n", out);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-05 22:26:14 +04:00
|
|
|
nsCSSGroupRule::AppendStyleRule(nsICSSRule* aRule)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
mRules.AppendObject(aRule);
|
|
|
|
aRule->SetStyleSheet(mSheet);
|
|
|
|
aRule->SetParentRule(this);
|
|
|
|
if (mSheet) {
|
|
|
|
// XXXldb Shouldn't we be using |WillDirty| and |DidDirty| (and
|
|
|
|
// shouldn't |SetModified| be removed?
|
|
|
|
mSheet->SetModified(PR_TRUE);
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
2005-10-16 00:21:20 +04:00
|
|
|
return NS_OK;
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-05 22:26:14 +04:00
|
|
|
nsCSSGroupRule::StyleRuleCount(PRInt32& aCount) const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
aCount = mRules.Count();
|
1999-06-10 09:32:38 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-05 22:26:14 +04:00
|
|
|
nsCSSGroupRule::GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
if (aIndex < 0 || aIndex >= mRules.Count()) {
|
|
|
|
aRule = nsnull;
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
2005-10-16 00:21:20 +04:00
|
|
|
|
|
|
|
NS_ADDREF(aRule = mRules.ObjectAt(aIndex));
|
|
|
|
return NS_OK;
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-10-16 00:21:20 +04:00
|
|
|
nsCSSGroupRule::EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
return NS_CONST_CAST(nsCSSGroupRule*, this)->mRules.EnumerateForwards(aFunc, aData) ? NS_OK : NS_ENUMERATOR_FALSE;
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
/*
|
2001-09-06 17:14:35 +04:00
|
|
|
* The next two methods (DeleteStyleRuleAt and InsertStyleRulesAt)
|
2001-09-05 04:00:18 +04:00
|
|
|
* should never be called unless you have first called WillDirty() on
|
|
|
|
* the parents tylesheet. After they are called, DidDirty() needs to
|
|
|
|
* be called on the sheet
|
|
|
|
*/
|
|
|
|
NS_IMETHODIMP
|
2004-08-05 22:26:14 +04:00
|
|
|
nsCSSGroupRule::DeleteStyleRuleAt(PRUint32 aIndex)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
nsICSSRule* rule = mRules.SafeObjectAt(aIndex);
|
2001-09-06 17:14:35 +04:00
|
|
|
if (rule) {
|
|
|
|
rule->SetStyleSheet(nsnull);
|
2001-09-19 18:16:34 +04:00
|
|
|
rule->SetParentRule(nsnull);
|
2001-09-06 17:14:35 +04:00
|
|
|
}
|
2005-10-16 00:21:20 +04:00
|
|
|
return mRules.RemoveObjectAt(aIndex) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-10-16 00:21:20 +04:00
|
|
|
nsCSSGroupRule::InsertStyleRulesAt(PRUint32 aIndex,
|
|
|
|
nsCOMArray<nsICSSRule>& aRules)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
aRules.EnumerateForwards(SetStyleSheetReference, mSheet);
|
|
|
|
aRules.EnumerateForwards(SetParentRuleReference, this);
|
|
|
|
if (! mRules.InsertObjectsAt(aRules, aIndex)) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-18 05:59:57 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-05 22:26:14 +04:00
|
|
|
nsCSSGroupRule::ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew)
|
2003-06-18 05:59:57 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
PRInt32 index = mRules.IndexOf(aOld);
|
2003-06-18 05:59:57 +04:00
|
|
|
NS_ENSURE_TRUE(index != -1, NS_ERROR_UNEXPECTED);
|
2005-10-16 00:21:20 +04:00
|
|
|
mRules.ReplaceObjectAt(aNew, index);
|
2003-06-18 05:59:57 +04:00
|
|
|
aNew->SetStyleSheet(mSheet);
|
|
|
|
aNew->SetParentRule(this);
|
|
|
|
aOld->SetStyleSheet(nsnull);
|
|
|
|
aOld->SetParentRule(nsnull);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-10 09:32:38 +04:00
|
|
|
|
|
|
|
nsresult
|
2004-08-05 22:26:14 +04:00
|
|
|
nsCSSGroupRule::AppendRulesToCssText(nsAString& aCssText)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AppendLiteral(" {\n");
|
2001-05-15 12:26:13 +04:00
|
|
|
|
|
|
|
// get all the rules
|
2005-10-16 00:21:20 +04:00
|
|
|
for (PRInt32 index = 0, count = mRules.Count(); index < count; ++index) {
|
|
|
|
nsICSSRule* rule = mRules.ObjectAt(index);
|
|
|
|
nsCOMPtr<nsIDOMCSSRule> domRule;
|
|
|
|
rule->GetDOMRule(getter_AddRefs(domRule));
|
|
|
|
if (domRule) {
|
|
|
|
nsAutoString cssText;
|
|
|
|
domRule->GetCssText(cssText);
|
|
|
|
aCssText.Append(NS_LITERAL_STRING(" ") +
|
|
|
|
cssText +
|
|
|
|
NS_LITERAL_STRING("\n"));
|
2001-05-15 12:26:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AppendLiteral("}");
|
2001-05-15 12:26:13 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
nsresult
|
|
|
|
nsCSSGroupRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
|
|
|
if (mSheet) {
|
|
|
|
return CallQueryInterface(mSheet, aSheet);
|
|
|
|
}
|
|
|
|
*aSheet = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
nsresult
|
|
|
|
nsCSSGroupRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2001-09-19 18:16:34 +04:00
|
|
|
if (mParentRule) {
|
2003-06-24 09:40:37 +04:00
|
|
|
return mParentRule->GetDOMRule(aParentRule);
|
2001-09-19 18:16:34 +04:00
|
|
|
}
|
|
|
|
*aParentRule = nsnull;
|
|
|
|
return NS_OK;
|
2001-05-15 12:26:13 +04:00
|
|
|
}
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
// nsIDOMCSSMediaRule or nsIDOMCSSMozDocumentRule methods
|
|
|
|
nsresult
|
|
|
|
nsCSSGroupRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
if (!mRuleCollection) {
|
|
|
|
mRuleCollection = new CSSGroupRuleRuleListImpl(this);
|
|
|
|
if (!mRuleCollection) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(mRuleCollection);
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(mRuleCollection, aRuleList);
|
|
|
|
}
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
nsresult
|
|
|
|
nsCSSGroupRule::InsertRule(const nsAString & aRule, PRUint32 aIndex, PRUint32* _retval)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSheet, NS_ERROR_FAILURE);
|
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
if (aIndex > PRUint32(mRules.Count()))
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
2005-10-16 00:21:20 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(PRUint32(mRules.Count()) <= PR_INT32_MAX,
|
|
|
|
"Too many style rules!");
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
return mSheet->InsertRuleIntoGroup(aRule, this, aIndex, _retval);
|
|
|
|
}
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
nsresult
|
|
|
|
nsCSSGroupRule::DeleteRule(PRUint32 aIndex)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSheet, NS_ERROR_FAILURE);
|
2005-10-16 00:21:20 +04:00
|
|
|
|
|
|
|
if (aIndex >= PRUint32(mRules.Count()))
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
NS_ASSERTION(PRUint32(mRules.Count()) <= PR_INT32_MAX,
|
|
|
|
"Too many style rules!");
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
return mSheet->DeleteRuleFromGroup(this, aIndex);
|
|
|
|
}
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
// -------------------------------------------
|
|
|
|
// nsICSSMediaRule
|
|
|
|
//
|
|
|
|
nsCSSMediaRule::nsCSSMediaRule()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSMediaRule::nsCSSMediaRule(const nsCSSMediaRule& aCopy)
|
|
|
|
: nsCSSGroupRule(aCopy)
|
|
|
|
{
|
|
|
|
if (aCopy.mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
aCopy.mMedia->Clone(getter_AddRefs(mMedia));
|
|
|
|
if (mMedia) {
|
|
|
|
// XXXldb This doesn't really make sense.
|
|
|
|
mMedia->SetStyleSheet(aCopy.mSheet);
|
|
|
|
}
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSMediaRule::~nsCSSMediaRule()
|
|
|
|
{
|
|
|
|
if (mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
mMedia->SetStyleSheet(nsnull);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsCSSMediaRule, nsCSSRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsCSSMediaRule, nsCSSRule)
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsCSSMediaRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsCSSMediaRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSGroupRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMediaRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsCSSGroupRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSMediaRule)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSMediaRule::SetStyleSheet(nsICSSStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
if (mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
// Set to null so it knows it's leaving one sheet and joining another.
|
|
|
|
mMedia->SetStyleSheet(nsnull);
|
|
|
|
mMedia->SetStyleSheet(aSheet);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsCSSGroupRule::SetStyleSheet(aSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSMediaRule::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
for (PRInt32 indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
nsAutoString buffer;
|
|
|
|
|
|
|
|
fputs("@media ", out);
|
|
|
|
|
|
|
|
if (mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
nsAutoString mediaText;
|
|
|
|
mMedia->GetText(mediaText);
|
2006-02-03 17:18:39 +03:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mediaText).get(), out);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsCSSGroupRule::List(out, aIndent);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSMediaRule::GetType(PRInt32& aType) const
|
|
|
|
{
|
|
|
|
aType = nsICSSRule::MEDIA_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSMediaRule::Clone(nsICSSRule*& aClone) const
|
|
|
|
{
|
|
|
|
nsCSSMediaRule* clone = new nsCSSMediaRule(*this);
|
|
|
|
if (clone) {
|
|
|
|
return CallQueryInterface(clone, &aClone);
|
|
|
|
}
|
|
|
|
aClone = nsnull;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2005-03-30 04:36:57 +04:00
|
|
|
nsCSSMediaRule::SetMedia(nsMediaList* aMedia)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2005-03-30 04:36:57 +04:00
|
|
|
mMedia = aMedia;
|
|
|
|
if (aMedia)
|
|
|
|
mMedia->SetStyleSheet(mSheet);
|
|
|
|
return NS_OK;
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSRule methods
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSMediaRule::GetType(PRUint16* aType)
|
|
|
|
{
|
|
|
|
*aType = nsIDOMCSSRule::MEDIA_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSMediaRule::GetCssText(nsAString& aCssText)
|
|
|
|
{
|
|
|
|
aCssText.AssignLiteral("@media ");
|
|
|
|
// get all the media
|
|
|
|
if (mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
nsAutoString mediaText;
|
|
|
|
mMedia->GetText(mediaText);
|
|
|
|
aCssText.Append(mediaText);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsCSSGroupRule::AppendRulesToCssText(aCssText);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSMediaRule::SetCssText(const nsAString& aCssText)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSMediaRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
|
|
|
{
|
|
|
|
return nsCSSGroupRule::GetParentStyleSheet(aSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSMediaRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
|
|
|
return nsCSSGroupRule::GetParentRule(aParentRule);
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSMediaRule methods
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSMediaRule::GetMedia(nsIDOMMediaList* *aMedia)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aMedia);
|
|
|
|
if (!mMedia) {
|
|
|
|
*aMedia = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(mMedia, aMedia);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSMediaRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
|
|
|
|
{
|
|
|
|
return nsCSSGroupRule::GetCssRules(aRuleList);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSMediaRule::InsertRule(const nsAString & aRule, PRUint32 aIndex, PRUint32* _retval)
|
|
|
|
{
|
|
|
|
return nsCSSGroupRule::InsertRule(aRule, aIndex, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSMediaRule::DeleteRule(PRUint32 aIndex)
|
|
|
|
{
|
|
|
|
return nsCSSGroupRule::DeleteRule(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsICSSGroupRule interface
|
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
|
|
nsCSSMediaRule::UseForPresentation(nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
if (mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
return mMedia->Matches(aPresContext);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsCSSDocumentRule::nsCSSDocumentRule(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSDocumentRule::nsCSSDocumentRule(const nsCSSDocumentRule& aCopy)
|
|
|
|
: nsCSSGroupRule(aCopy)
|
|
|
|
, mURLs(new URL(*aCopy.mURLs))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSDocumentRule::~nsCSSDocumentRule(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(nsCSSDocumentRule, nsCSSRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsCSSDocumentRule, nsCSSRule)
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsCSSDocumentRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsCSSDocumentRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSGroupRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMozDocumentRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsCSSGroupRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSMozDocumentRule)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSDocumentRule::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
for (PRInt32 indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
nsCAutoString str;
|
|
|
|
str.AssignLiteral("@-moz-document ");
|
|
|
|
for (URL *url = mURLs; url; url = url->next) {
|
|
|
|
switch (url->func) {
|
|
|
|
case eURL:
|
|
|
|
str.AppendLiteral("url(\"");
|
|
|
|
break;
|
|
|
|
case eURLPrefix:
|
|
|
|
str.AppendLiteral("url-prefix(\"");
|
|
|
|
break;
|
|
|
|
case eDomain:
|
|
|
|
str.AppendLiteral("domain(\"");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsCAutoString escapedURL(url->url);
|
|
|
|
escapedURL.ReplaceSubstring("\"", "\\\""); // escape quotes
|
|
|
|
str.Append(escapedURL);
|
|
|
|
str.AppendLiteral("\"), ");
|
|
|
|
}
|
|
|
|
str.Cut(str.Length() - 2, 1); // remove last ,
|
|
|
|
fputs(str.get(), out);
|
|
|
|
|
|
|
|
return nsCSSGroupRule::List(out, aIndent);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSDocumentRule::GetType(PRInt32& aType) const
|
|
|
|
{
|
|
|
|
aType = nsICSSRule::DOCUMENT_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSDocumentRule::Clone(nsICSSRule*& aClone) const
|
|
|
|
{
|
|
|
|
nsCSSDocumentRule* clone = new nsCSSDocumentRule(*this);
|
|
|
|
if (clone) {
|
|
|
|
return CallQueryInterface(clone, &aClone);
|
|
|
|
}
|
|
|
|
aClone = nsnull;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSRule methods
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSDocumentRule::GetType(PRUint16* aType)
|
|
|
|
{
|
|
|
|
// XXX What should really happen here?
|
|
|
|
*aType = nsIDOMCSSRule::UNKNOWN_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSDocumentRule::GetCssText(nsAString& aCssText)
|
|
|
|
{
|
|
|
|
aCssText.AssignLiteral("@-moz-document ");
|
|
|
|
for (URL *url = mURLs; url; url = url->next) {
|
|
|
|
switch (url->func) {
|
|
|
|
case eURL:
|
|
|
|
aCssText.AppendLiteral("url(\"");
|
|
|
|
break;
|
|
|
|
case eURLPrefix:
|
|
|
|
aCssText.AppendLiteral("url-prefix(\"");
|
|
|
|
break;
|
|
|
|
case eDomain:
|
|
|
|
aCssText.AppendLiteral("domain(\"");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsCAutoString escapedURL(url->url);
|
|
|
|
escapedURL.ReplaceSubstring("\"", "\\\""); // escape quotes
|
|
|
|
AppendUTF8toUTF16(escapedURL, aCssText);
|
|
|
|
aCssText.AppendLiteral("\"), ");
|
|
|
|
}
|
|
|
|
aCssText.Cut(aCssText.Length() - 2, 1); // remove last ,
|
|
|
|
|
|
|
|
return nsCSSGroupRule::AppendRulesToCssText(aCssText);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSDocumentRule::SetCssText(const nsAString& aCssText)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSDocumentRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
|
|
|
{
|
|
|
|
return nsCSSGroupRule::GetParentStyleSheet(aSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSDocumentRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
|
|
|
return nsCSSGroupRule::GetParentRule(aParentRule);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSDocumentRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
|
|
|
|
{
|
|
|
|
return nsCSSGroupRule::GetCssRules(aRuleList);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSDocumentRule::InsertRule(const nsAString & aRule, PRUint32 aIndex, PRUint32* _retval)
|
|
|
|
{
|
|
|
|
return nsCSSGroupRule::InsertRule(aRule, aIndex, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSDocumentRule::DeleteRule(PRUint32 aIndex)
|
|
|
|
{
|
|
|
|
return nsCSSGroupRule::DeleteRule(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsICSSGroupRule interface
|
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
|
|
nsCSSDocumentRule::UseForPresentation(nsPresContext* aPresContext)
|
|
|
|
{
|
2006-05-19 14:26:44 +04:00
|
|
|
nsIURI *docURI = aPresContext->Document()->GetDocumentURI();
|
2004-08-05 22:26:14 +04:00
|
|
|
nsCAutoString docURISpec;
|
|
|
|
if (docURI)
|
|
|
|
docURI->GetSpec(docURISpec);
|
|
|
|
|
|
|
|
for (URL *url = mURLs; url; url = url->next) {
|
|
|
|
switch (url->func) {
|
|
|
|
case eURL: {
|
|
|
|
if (docURISpec == url->url)
|
|
|
|
return PR_TRUE;
|
|
|
|
} break;
|
|
|
|
case eURLPrefix: {
|
|
|
|
if (StringBeginsWith(docURISpec, url->url))
|
|
|
|
return PR_TRUE;
|
|
|
|
} break;
|
|
|
|
case eDomain: {
|
|
|
|
nsCAutoString host;
|
|
|
|
if (docURI)
|
|
|
|
docURI->GetHost(host);
|
|
|
|
PRInt32 lenDiff = host.Length() - url->url.Length();
|
|
|
|
if (lenDiff == 0) {
|
|
|
|
if (host == url->url)
|
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
if (StringEndsWith(host, url->url) &&
|
|
|
|
host.CharAt(lenDiff - 1) == '.')
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
// -------------------------------------------
|
|
|
|
// nsICSSNameSpaceRule
|
|
|
|
//
|
|
|
|
class CSSNameSpaceRuleImpl : public nsCSSRule,
|
2001-05-15 12:26:13 +04:00
|
|
|
public nsICSSNameSpaceRule,
|
|
|
|
public nsIDOMCSSRule
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSSNameSpaceRuleImpl(void);
|
|
|
|
CSSNameSpaceRuleImpl(const CSSNameSpaceRuleImpl& aCopy);
|
|
|
|
virtual ~CSSNameSpaceRuleImpl(void);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
|
|
|
|
DECL_STYLE_RULE_INHERIT
|
|
|
|
|
|
|
|
// nsIStyleRule methods
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1999-06-10 09:32:38 +04:00
|
|
|
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
// nsICSSRule methods
|
|
|
|
NS_IMETHOD GetType(PRInt32& aType) const;
|
|
|
|
NS_IMETHOD Clone(nsICSSRule*& aClone) const;
|
|
|
|
|
|
|
|
// nsICSSNameSpaceRule methods
|
|
|
|
NS_IMETHOD GetPrefix(nsIAtom*& aPrefix) const;
|
|
|
|
NS_IMETHOD SetPrefix(nsIAtom* aPrefix);
|
|
|
|
|
|
|
|
NS_IMETHOD GetURLSpec(nsString& aURLSpec) const;
|
|
|
|
NS_IMETHOD SetURLSpec(const nsString& aURLSpec);
|
|
|
|
|
2001-05-15 12:26:13 +04:00
|
|
|
// nsIDOMCSSRule interface
|
|
|
|
NS_DECL_NSIDOMCSSRULE
|
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
protected:
|
|
|
|
nsIAtom* mPrefix;
|
|
|
|
nsString mURLSpec;
|
|
|
|
};
|
|
|
|
|
|
|
|
CSSNameSpaceRuleImpl::CSSNameSpaceRuleImpl(void)
|
|
|
|
: nsCSSRule(),
|
|
|
|
mPrefix(nsnull),
|
|
|
|
mURLSpec()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSNameSpaceRuleImpl::CSSNameSpaceRuleImpl(const CSSNameSpaceRuleImpl& aCopy)
|
|
|
|
: nsCSSRule(aCopy),
|
|
|
|
mPrefix(aCopy.mPrefix),
|
|
|
|
mURLSpec(aCopy.mURLSpec)
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mPrefix);
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSNameSpaceRuleImpl::~CSSNameSpaceRuleImpl(void)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mPrefix);
|
|
|
|
}
|
|
|
|
|
2003-09-08 01:50:21 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(CSSNameSpaceRuleImpl, nsCSSRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(CSSNameSpaceRuleImpl, nsCSSRule)
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2001-05-15 12:26:13 +04:00
|
|
|
// QueryInterface implementation for CSSNameSpaceRuleImpl
|
|
|
|
NS_INTERFACE_MAP_BEGIN(CSSNameSpaceRuleImpl)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSNameSpaceRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSNameSpaceRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSNameSpaceRule)
|
|
|
|
NS_INTERFACE_MAP_END
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2003-09-08 01:50:21 +04:00
|
|
|
IMPL_STYLE_RULE_INHERIT(CSSNameSpaceRuleImpl, nsCSSRule)
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1999-06-10 09:32:38 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSNameSpaceRuleImpl::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
for (PRInt32 indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
nsAutoString buffer;
|
|
|
|
|
|
|
|
fputs("@namespace ", out);
|
|
|
|
|
|
|
|
if (mPrefix) {
|
|
|
|
mPrefix->ToString(buffer);
|
2006-02-03 17:18:39 +03:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(buffer).get(), out);
|
1999-06-10 09:32:38 +04:00
|
|
|
fputs(" ", out);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs("url(", out);
|
2006-02-03 17:18:39 +03:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mURLSpec).get(), out);
|
1999-06-10 09:32:38 +04:00
|
|
|
fputs(")\n", out);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSNameSpaceRuleImpl::GetType(PRInt32& aType) const
|
|
|
|
{
|
|
|
|
aType = nsICSSRule::NAMESPACE_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSNameSpaceRuleImpl::Clone(nsICSSRule*& aClone) const
|
|
|
|
{
|
|
|
|
CSSNameSpaceRuleImpl* clone = new CSSNameSpaceRuleImpl(*this);
|
|
|
|
if (clone) {
|
2002-12-11 17:24:49 +03:00
|
|
|
return CallQueryInterface(clone, &aClone);
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
aClone = nsnull;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSNameSpaceRuleImpl::GetPrefix(nsIAtom*& aPrefix) const
|
|
|
|
{
|
|
|
|
aPrefix = mPrefix;
|
|
|
|
NS_IF_ADDREF(aPrefix);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSNameSpaceRuleImpl::SetPrefix(nsIAtom* aPrefix)
|
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mPrefix);
|
|
|
|
mPrefix = aPrefix;
|
|
|
|
NS_IF_ADDREF(mPrefix);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSNameSpaceRuleImpl::GetURLSpec(nsString& aURLSpec) const
|
|
|
|
{
|
|
|
|
aURLSpec = mURLSpec;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSNameSpaceRuleImpl::SetURLSpec(const nsString& aURLSpec)
|
|
|
|
{
|
|
|
|
mURLSpec = aURLSpec;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
NS_NewCSSNameSpaceRule(nsICSSNameSpaceRule** aInstancePtrResult,
|
|
|
|
nsIAtom* aPrefix, const nsString& aURLSpec)
|
|
|
|
{
|
|
|
|
if (! aInstancePtrResult) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSNameSpaceRuleImpl* it = new CSSNameSpaceRuleImpl();
|
|
|
|
|
|
|
|
if (! it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
it->SetPrefix(aPrefix);
|
|
|
|
it->SetURLSpec(aURLSpec);
|
2002-08-06 09:26:41 +04:00
|
|
|
return CallQueryInterface(it, aInstancePtrResult);
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2001-05-15 12:26:13 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSNameSpaceRuleImpl::GetType(PRUint16* aType)
|
|
|
|
{
|
2004-08-05 22:26:14 +04:00
|
|
|
// XXX What should really happen here?
|
2001-05-15 12:26:13 +04:00
|
|
|
*aType = nsIDOMCSSRule::UNKNOWN_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSNameSpaceRuleImpl::GetCssText(nsAString& aCssText)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AssignLiteral("@namespace ");
|
2001-05-15 12:26:13 +04:00
|
|
|
if (mPrefix) {
|
|
|
|
nsString atomStr;
|
|
|
|
mPrefix->ToString(atomStr);
|
|
|
|
aCssText.Append(atomStr);
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AppendLiteral(" ");
|
2001-05-15 12:26:13 +04:00
|
|
|
}
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AppendLiteral("url(");
|
2001-05-15 12:26:13 +04:00
|
|
|
aCssText.Append(mURLSpec);
|
|
|
|
aCssText.Append(NS_LITERAL_STRING(");"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-24 01:56:05 +03:00
|
|
|
CSSNameSpaceRuleImpl::SetCssText(const nsAString& aCssText)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSNameSpaceRuleImpl::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
|
|
|
{
|
|
|
|
if (mSheet) {
|
|
|
|
return CallQueryInterface(mSheet, aSheet);
|
|
|
|
}
|
|
|
|
*aSheet = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSNameSpaceRuleImpl::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
2001-09-19 18:16:34 +04:00
|
|
|
if (mParentRule) {
|
2003-06-24 09:40:37 +04:00
|
|
|
return mParentRule->GetDOMRule(aParentRule);
|
2001-09-19 18:16:34 +04:00
|
|
|
}
|
|
|
|
*aParentRule = nsnull;
|
|
|
|
return NS_OK;
|
2001-05-15 12:26:13 +04:00
|
|
|
}
|