2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2003-02-22 19:10:53 +03:00
|
|
|
// vim:cindent:tabstop=2:expandtab:shiftwidth=2:
|
2001-09-25 05:32:19 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-04-14 00:24:54 +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/
|
1998-04-14 00:24:54 +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.
|
1998-04-14 00:24:54 +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) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Contributor(s):
|
2006-04-04 03:52:17 +04:00
|
|
|
* L. David Baron <dbaron@dbaron.org>
|
2000-02-03 01:24:56 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-02-13 17:06:29 +03:00
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
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
|
|
|
|
2006-04-04 03:52:17 +04:00
|
|
|
/* representation of a CSS style sheet */
|
1999-02-27 04:35:51 +03:00
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
#include "nsCSSStyleSheet.h"
|
2002-03-22 09:28:16 +03:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIAtom.h"
|
1999-06-18 21:34:08 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2004-07-28 11:08:41 +04:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsICSSStyleRule.h"
|
1999-06-10 09:29:22 +04:00
|
|
|
#include "nsICSSNameSpaceRule.h"
|
2004-08-05 22:26:14 +04:00
|
|
|
#include "nsICSSGroupRule.h"
|
2005-04-14 19:27:16 +04:00
|
|
|
#include "nsICSSImportRule.h"
|
2001-08-05 01:19:53 +04:00
|
|
|
#include "nsIMediaList.h"
|
1998-05-19 04:09:29 +04:00
|
|
|
#include "nsIDocument.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsString.h"
|
1998-11-26 04:34:53 +03:00
|
|
|
#include "nsVoidArray.h"
|
2000-04-26 17:58:56 +04:00
|
|
|
#include "nsIDOMStyleSheetList.h"
|
1998-10-06 05:39:33 +04:00
|
|
|
#include "nsIDOMCSSStyleSheet.h"
|
2003-06-24 09:40:37 +04:00
|
|
|
#include "nsIDOMCSSRule.h"
|
2002-08-06 09:08:47 +04:00
|
|
|
#include "nsIDOMCSSImportRule.h"
|
2000-04-26 17:58:56 +04:00
|
|
|
#include "nsIDOMCSSRuleList.h"
|
|
|
|
#include "nsIDOMMediaList.h"
|
1998-11-26 04:34:53 +03:00
|
|
|
#include "nsIDOMNode.h"
|
2000-04-26 17:58:56 +04:00
|
|
|
#include "nsDOMError.h"
|
1998-10-06 05:39:33 +04:00
|
|
|
#include "nsICSSParser.h"
|
2001-09-05 04:00:18 +04:00
|
|
|
#include "nsICSSLoader.h"
|
2002-08-06 09:08:47 +04:00
|
|
|
#include "nsICSSLoaderObserver.h"
|
1998-12-11 05:50:43 +03:00
|
|
|
#include "nsINameSpaceManager.h"
|
2005-02-19 03:10:38 +03:00
|
|
|
#include "nsXMLNameSpaceMap.h"
|
2000-03-31 11:08:36 +04:00
|
|
|
#include "nsCOMPtr.h"
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
#include "nsContentUtils.h"
|
2002-06-15 03:54:18 +04:00
|
|
|
#include "nsIJSContextStack.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
2008-04-11 21:29:06 +04:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2008-07-26 20:14:48 +04:00
|
|
|
#include "nsCSSDeclaration.h"
|
|
|
|
#include "nsRuleNode.h"
|
1999-06-03 05:57:52 +04:00
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
// -------------------------------
|
2000-04-26 17:58:56 +04:00
|
|
|
// Style Rule List for the DOM
|
1998-10-06 05:39:33 +04:00
|
|
|
//
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
class CSSRuleListImpl : public nsIDOMCSSRuleList
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
public:
|
2004-08-04 07:27:28 +04:00
|
|
|
CSSRuleListImpl(nsCSSStyleSheet *aStyleSheet);
|
1998-10-06 05:39:33 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
// nsIDOMCSSRuleList interface
|
1998-10-06 05:39:33 +04:00
|
|
|
NS_IMETHOD GetLength(PRUint32* aLength);
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn);
|
1998-10-06 05:39:33 +04:00
|
|
|
|
|
|
|
void DropReference() { mStyleSheet = nsnull; }
|
|
|
|
|
|
|
|
protected:
|
2000-04-26 17:58:56 +04:00
|
|
|
virtual ~CSSRuleListImpl();
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet* mStyleSheet;
|
1999-06-03 05:57:52 +04:00
|
|
|
public:
|
|
|
|
PRBool mRulesAccessed;
|
1998-10-06 05:39:33 +04:00
|
|
|
};
|
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
CSSRuleListImpl::CSSRuleListImpl(nsCSSStyleSheet *aStyleSheet)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
// Not reference counted to avoid circular references.
|
|
|
|
// The style sheet will tell us when its going away.
|
|
|
|
mStyleSheet = aStyleSheet;
|
1999-06-03 05:57:52 +04:00
|
|
|
mRulesAccessed = PR_FALSE;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
CSSRuleListImpl::~CSSRuleListImpl()
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
// QueryInterface implementation for CSSRuleList
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(CSSRuleListImpl)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRuleList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSRuleList)
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
1998-10-06 05:39:33 +04:00
|
|
|
|
|
|
|
|
2003-09-08 01:50:21 +04:00
|
|
|
NS_IMPL_ADDREF(CSSRuleListImpl)
|
|
|
|
NS_IMPL_RELEASE(CSSRuleListImpl)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
NS_IMETHODIMP
|
2000-04-26 17:58:56 +04:00
|
|
|
CSSRuleListImpl::GetLength(PRUint32* aLength)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
if (nsnull != mStyleSheet) {
|
1999-06-10 09:29:22 +04:00
|
|
|
PRInt32 count;
|
|
|
|
mStyleSheet->StyleRuleCount(count);
|
|
|
|
*aLength = (PRUint32)count;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aLength = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-04-26 17:58:56 +04:00
|
|
|
CSSRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
*aReturn = nsnull;
|
2001-03-20 01:12:12 +03:00
|
|
|
if (mStyleSheet) {
|
1999-06-03 05:57:52 +04:00
|
|
|
result = mStyleSheet->EnsureUniqueInner(); // needed to ensure rules have correct parent
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
2001-03-20 01:12:12 +03:00
|
|
|
nsCOMPtr<nsICSSRule> rule;
|
1999-06-03 05:57:52 +04:00
|
|
|
|
2001-03-20 01:12:12 +03:00
|
|
|
result = mStyleSheet->GetStyleRuleAt(aIndex, *getter_AddRefs(rule));
|
|
|
|
if (rule) {
|
2003-06-24 09:40:37 +04:00
|
|
|
result = rule->GetDOMRule(aReturn);
|
1999-06-03 05:57:52 +04:00
|
|
|
mRulesAccessed = PR_TRUE; // signal to never share rules again
|
2001-03-20 01:12:12 +03:00
|
|
|
} else if (result == NS_ERROR_ILLEGAL_VALUE) {
|
|
|
|
result = NS_OK; // per spec: "Return Value ... null if ... not a valid index."
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
template <class Numeric>
|
|
|
|
PRInt32 DoCompare(Numeric a, Numeric b)
|
|
|
|
{
|
|
|
|
if (a == b)
|
|
|
|
return 0;
|
|
|
|
if (a < b)
|
|
|
|
return -1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsMediaExpression::Matches(nsPresContext *aPresContext,
|
|
|
|
const nsCSSValue& aActualValue) const
|
|
|
|
{
|
|
|
|
const nsCSSValue& actual = aActualValue;
|
|
|
|
const nsCSSValue& required = mValue;
|
|
|
|
|
|
|
|
// If we don't have the feature, the match fails.
|
|
|
|
if (actual.GetUnit() == eCSSUnit_Null) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the expression had no value to match, the match succeeds,
|
|
|
|
// unless the value is an integer 0.
|
|
|
|
if (required.GetUnit() == eCSSUnit_Null) {
|
|
|
|
return actual.GetUnit() != eCSSUnit_Integer ||
|
|
|
|
actual.GetIntValue() != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mFeature->mRangeType == nsMediaFeature::eMinMaxAllowed ||
|
|
|
|
mRange == nsMediaExpression::eEqual, "yikes");
|
|
|
|
PRInt32 cmp; // -1 (actual < required)
|
|
|
|
// 0 (actual == required)
|
|
|
|
// 1 (actual > required)
|
|
|
|
switch (mFeature->mValueType) {
|
|
|
|
case nsMediaFeature::eLength:
|
|
|
|
{
|
|
|
|
NS_ASSERTION(actual.IsLengthUnit(), "bad actual value");
|
|
|
|
NS_ASSERTION(required.IsLengthUnit(), "bad required value");
|
|
|
|
nscoord actualCoord = nsRuleNode::CalcLengthWithInitialFont(
|
|
|
|
aPresContext, actual);
|
|
|
|
nscoord requiredCoord = nsRuleNode::CalcLengthWithInitialFont(
|
|
|
|
aPresContext, required);
|
|
|
|
cmp = DoCompare(actualCoord, requiredCoord);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsMediaFeature::eInteger:
|
|
|
|
{
|
|
|
|
NS_ASSERTION(actual.GetUnit() == eCSSUnit_Integer,
|
|
|
|
"bad actual value");
|
|
|
|
NS_ASSERTION(required.GetUnit() == eCSSUnit_Integer,
|
|
|
|
"bad required value");
|
|
|
|
cmp = DoCompare(actual.GetIntValue(), required.GetIntValue());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsMediaFeature::eIntRatio:
|
|
|
|
{
|
|
|
|
NS_ASSERTION(actual.GetUnit() == eCSSUnit_Array &&
|
|
|
|
actual.GetArrayValue()->Count() == 2 &&
|
|
|
|
actual.GetArrayValue()->Item(0).GetUnit() ==
|
|
|
|
eCSSUnit_Integer &&
|
|
|
|
actual.GetArrayValue()->Item(1).GetUnit() ==
|
|
|
|
eCSSUnit_Integer,
|
|
|
|
"bad actual value");
|
|
|
|
NS_ASSERTION(required.GetUnit() == eCSSUnit_Array &&
|
|
|
|
required.GetArrayValue()->Count() == 2 &&
|
|
|
|
required.GetArrayValue()->Item(0).GetUnit() ==
|
|
|
|
eCSSUnit_Integer &&
|
|
|
|
required.GetArrayValue()->Item(1).GetUnit() ==
|
|
|
|
eCSSUnit_Integer,
|
|
|
|
"bad required value");
|
|
|
|
// Convert to PRInt64 so we can multiply without worry. Note
|
|
|
|
// that while the spec requires that both halves of |required|
|
|
|
|
// be positive, the numerator or denominator of |actual| might
|
|
|
|
// be zero (e.g., when testing 'aspect-ratio' on a 0-width or
|
|
|
|
// 0-height iframe).
|
|
|
|
PRInt64 actualNum = actual.GetArrayValue()->Item(0).GetIntValue(),
|
|
|
|
actualDen = actual.GetArrayValue()->Item(1).GetIntValue(),
|
|
|
|
requiredNum = required.GetArrayValue()->Item(0).GetIntValue(),
|
|
|
|
requiredDen = required.GetArrayValue()->Item(1).GetIntValue();
|
|
|
|
cmp = DoCompare(actualNum * requiredDen, requiredNum * actualDen);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsMediaFeature::eResolution:
|
|
|
|
{
|
|
|
|
NS_ASSERTION(actual.GetUnit() == eCSSUnit_Inch ||
|
|
|
|
actual.GetUnit() == eCSSUnit_Centimeter,
|
|
|
|
"bad actual value");
|
|
|
|
NS_ASSERTION(required.GetUnit() == eCSSUnit_Inch ||
|
|
|
|
required.GetUnit() == eCSSUnit_Centimeter,
|
|
|
|
"bad required value");
|
|
|
|
float actualDPI = actual.GetFloatValue();
|
|
|
|
if (actual.GetUnit() == eCSSUnit_Centimeter)
|
|
|
|
actualDPI = actualDPI * 2.54f;
|
|
|
|
float requiredDPI = required.GetFloatValue();
|
|
|
|
if (required.GetUnit() == eCSSUnit_Centimeter)
|
|
|
|
requiredDPI = requiredDPI * 2.54f;
|
|
|
|
cmp = DoCompare(actualDPI, requiredDPI);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsMediaFeature::eEnumerated:
|
|
|
|
{
|
|
|
|
NS_ASSERTION(actual.GetUnit() == eCSSUnit_Enumerated,
|
|
|
|
"bad actual value");
|
|
|
|
NS_ASSERTION(required.GetUnit() == eCSSUnit_Enumerated,
|
|
|
|
"bad required value");
|
|
|
|
NS_ASSERTION(mFeature->mRangeType == nsMediaFeature::eMinMaxNotAllowed,
|
|
|
|
"bad range"); // we asserted above about mRange
|
|
|
|
// We don't really need DoCompare, but it doesn't hurt (and
|
|
|
|
// maybe the compiler will condense this case with eInteger).
|
|
|
|
cmp = DoCompare(actual.GetIntValue(), required.GetIntValue());
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
switch (mRange) {
|
|
|
|
case nsMediaExpression::eMin:
|
|
|
|
return cmp != -1;
|
|
|
|
case nsMediaExpression::eMax:
|
|
|
|
return cmp != 1;
|
|
|
|
case nsMediaExpression::eEqual:
|
|
|
|
return cmp == 0;
|
|
|
|
}
|
|
|
|
NS_NOTREACHED("unexpected mRange");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
void
|
|
|
|
nsMediaQueryResultCacheKey::AddExpression(const nsMediaExpression* aExpression,
|
|
|
|
PRBool aExpressionMatches)
|
|
|
|
{
|
|
|
|
const nsMediaFeature *feature = aExpression->mFeature;
|
|
|
|
FeatureEntry *entry = nsnull;
|
|
|
|
for (PRUint32 i = 0; i < mFeatureCache.Length(); ++i) {
|
|
|
|
if (mFeatureCache[i].mFeature == feature) {
|
|
|
|
entry = &mFeatureCache[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!entry) {
|
|
|
|
entry = mFeatureCache.AppendElement();
|
|
|
|
if (!entry) {
|
|
|
|
return; /* out of memory */
|
|
|
|
}
|
|
|
|
entry->mFeature = feature;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExpressionEntry eentry = { *aExpression, aExpressionMatches };
|
|
|
|
entry->mExpressions.AppendElement(eentry);
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
|
|
|
nsMediaQueryResultCacheKey::Matches(nsPresContext* aPresContext) const
|
|
|
|
{
|
|
|
|
if (aPresContext->Medium() != mMedium) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < mFeatureCache.Length(); ++i) {
|
|
|
|
const FeatureEntry *entry = &mFeatureCache[i];
|
|
|
|
nsCSSValue actual;
|
|
|
|
nsresult rv = (entry->mFeature->mGetter)(aPresContext, actual);
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE); // any better ideas?
|
|
|
|
|
|
|
|
for (PRUint32 j = 0; j < entry->mExpressions.Length(); ++j) {
|
|
|
|
const ExpressionEntry &eentry = entry->mExpressions[j];
|
|
|
|
if (eentry.mExpression.Matches(aPresContext, actual) !=
|
|
|
|
eentry.mExpressionMatches) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
void
|
|
|
|
nsMediaQuery::AppendToString(nsAString& aString) const
|
|
|
|
{
|
|
|
|
nsAutoString buffer;
|
|
|
|
|
|
|
|
if (mHadUnknownExpression) {
|
|
|
|
aString.AppendLiteral("not all");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(!mNegated || !mHasOnly, "can't have not and only");
|
|
|
|
NS_ASSERTION(!mTypeOmitted || (!mNegated && !mHasOnly),
|
|
|
|
"can't have not or only when type is omitted");
|
|
|
|
if (!mTypeOmitted) {
|
|
|
|
if (mNegated) {
|
|
|
|
aString.AppendLiteral("not ");
|
|
|
|
} else if (mHasOnly) {
|
|
|
|
aString.AppendLiteral("only ");
|
|
|
|
}
|
|
|
|
mMediaType->ToString(buffer);
|
|
|
|
aString.Append(buffer);
|
|
|
|
buffer.Truncate();
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRUint32 i = 0, i_end = mExpressions.Length(); i < i_end; ++i) {
|
|
|
|
if (i > 0 || !mTypeOmitted)
|
|
|
|
aString.AppendLiteral(" and ");
|
|
|
|
aString.AppendLiteral("(");
|
|
|
|
|
|
|
|
const nsMediaExpression &expr = mExpressions[i];
|
|
|
|
if (expr.mRange == nsMediaExpression::eMin) {
|
|
|
|
aString.AppendLiteral("min-");
|
|
|
|
} else if (expr.mRange == nsMediaExpression::eMax) {
|
|
|
|
aString.AppendLiteral("max-");
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsMediaFeature *feature = expr.mFeature;
|
|
|
|
(*feature->mName)->ToString(buffer);
|
|
|
|
aString.Append(buffer);
|
|
|
|
buffer.Truncate();
|
|
|
|
|
|
|
|
if (expr.mValue.GetUnit() != eCSSUnit_Null) {
|
|
|
|
aString.AppendLiteral(": ");
|
|
|
|
switch (feature->mValueType) {
|
|
|
|
case nsMediaFeature::eLength:
|
|
|
|
NS_ASSERTION(expr.mValue.IsLengthUnit(), "bad unit");
|
|
|
|
// Use 'width' as a property that takes length values
|
|
|
|
// written in the normal way.
|
|
|
|
nsCSSDeclaration::AppendCSSValueToString(eCSSProperty_width,
|
|
|
|
expr.mValue, aString);
|
|
|
|
break;
|
|
|
|
case nsMediaFeature::eInteger:
|
|
|
|
NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Integer,
|
|
|
|
"bad unit");
|
|
|
|
// Use 'z-index' as a property that takes integer values
|
|
|
|
// written without anything extra.
|
|
|
|
nsCSSDeclaration::AppendCSSValueToString(eCSSProperty_z_index,
|
|
|
|
expr.mValue, aString);
|
|
|
|
break;
|
|
|
|
case nsMediaFeature::eIntRatio:
|
|
|
|
{
|
|
|
|
NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Array,
|
|
|
|
"bad unit");
|
|
|
|
nsCSSValue::Array *array = expr.mValue.GetArrayValue();
|
|
|
|
NS_ASSERTION(array->Count() == 2, "unexpected length");
|
|
|
|
NS_ASSERTION(array->Item(0).GetUnit() == eCSSUnit_Integer,
|
|
|
|
"bad unit");
|
|
|
|
NS_ASSERTION(array->Item(1).GetUnit() == eCSSUnit_Integer,
|
|
|
|
"bad unit");
|
|
|
|
nsCSSDeclaration::AppendCSSValueToString(eCSSProperty_z_index,
|
|
|
|
array->Item(0), aString);
|
|
|
|
aString.AppendLiteral("/");
|
|
|
|
nsCSSDeclaration::AppendCSSValueToString(eCSSProperty_z_index,
|
|
|
|
array->Item(1), aString);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsMediaFeature::eResolution:
|
|
|
|
buffer.AppendFloat(expr.mValue.GetFloatValue());
|
|
|
|
aString.Append(buffer);
|
|
|
|
buffer.Truncate();
|
|
|
|
if (expr.mValue.GetUnit() == eCSSUnit_Inch) {
|
|
|
|
aString.AppendLiteral("dpi");
|
|
|
|
} else {
|
|
|
|
NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Centimeter,
|
|
|
|
"bad unit");
|
|
|
|
aString.AppendLiteral("dpcm");
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsMediaFeature::eEnumerated:
|
|
|
|
NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Enumerated,
|
|
|
|
"bad unit");
|
|
|
|
AppendASCIItoUTF16(
|
|
|
|
nsCSSProps::ValueToKeyword(expr.mValue.GetIntValue(),
|
|
|
|
feature->mKeywordTable),
|
|
|
|
aString);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aString.AppendLiteral(")");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMediaQuery*
|
|
|
|
nsMediaQuery::Clone() const
|
|
|
|
{
|
|
|
|
nsAutoPtr<nsMediaQuery> result(new nsMediaQuery(*this));
|
|
|
|
NS_ENSURE_TRUE(result &&
|
|
|
|
result->mExpressions.Length() == mExpressions.Length(),
|
|
|
|
nsnull);
|
|
|
|
return result.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2008-07-26 20:14:48 +04:00
|
|
|
nsMediaQuery::Matches(nsPresContext* aPresContext,
|
|
|
|
nsMediaQueryResultCacheKey& aKey) const
|
2008-07-26 20:14:48 +04:00
|
|
|
{
|
|
|
|
if (mHadUnknownExpression)
|
|
|
|
return PR_FALSE;
|
|
|
|
|
|
|
|
PRBool match =
|
|
|
|
mMediaType == aPresContext->Medium() || mMediaType == nsGkAtoms::all;
|
|
|
|
for (PRUint32 i = 0, i_end = mExpressions.Length(); match && i < i_end; ++i) {
|
|
|
|
const nsMediaExpression &expr = mExpressions[i];
|
|
|
|
nsCSSValue actual;
|
|
|
|
nsresult rv = (expr.mFeature->mGetter)(aPresContext, actual);
|
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE); // any better ideas?
|
2008-07-26 20:14:48 +04:00
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
match = expr.Matches(aPresContext, actual);
|
2008-07-26 20:14:48 +04:00
|
|
|
aKey.AddExpression(&expr, match);
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return match == !mNegated;
|
|
|
|
}
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsMediaList)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMediaList)
|
2005-03-30 04:36:57 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(MediaList)
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
NS_IMPL_ADDREF(nsMediaList)
|
|
|
|
NS_IMPL_RELEASE(nsMediaList)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList::nsMediaList()
|
2008-07-26 20:14:48 +04:00
|
|
|
: mIsEmpty(PR_TRUE)
|
|
|
|
, mStyleSheet(nsnull)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList::~nsMediaList()
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-08-05 01:19:53 +04:00
|
|
|
nsresult
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList::GetText(nsAString& aMediaText)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
|
|
|
aMediaText.Truncate();
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
if (mArray.Length() == 0 && !mIsEmpty) {
|
|
|
|
aMediaText.AppendLiteral("not all");
|
|
|
|
}
|
|
|
|
|
|
|
|
for (PRInt32 i = 0, i_end = mArray.Length(); i < i_end; ++i) {
|
|
|
|
nsMediaQuery* query = mArray[i];
|
|
|
|
NS_ENSURE_TRUE(query, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
query->AppendToString(aMediaText);
|
2000-04-26 17:58:56 +04:00
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
if (i + 1 < i_end) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aMediaText.AppendLiteral(", ");
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-10 05:27:41 +03:00
|
|
|
// XXXbz this is so ill-defined in the spec, it's not clear quite what
|
|
|
|
// it should be doing....
|
2005-03-30 04:36:57 +04:00
|
|
|
nsresult
|
|
|
|
nsMediaList::SetText(const nsAString& aMediaText)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
2005-03-30 04:36:57 +04:00
|
|
|
nsCOMPtr<nsICSSParser> parser;
|
|
|
|
nsresult rv = NS_NewCSSParser(getter_AddRefs(parser));
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
PRBool htmlMode = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIDOMStyleSheet> domSheet =
|
2007-07-08 11:08:04 +04:00
|
|
|
do_QueryInterface(static_cast<nsICSSStyleSheet*>(mStyleSheet));
|
2005-03-30 04:36:57 +04:00
|
|
|
if (domSheet) {
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
domSheet->GetOwnerNode(getter_AddRefs(node));
|
|
|
|
htmlMode = !!node;
|
|
|
|
}
|
2000-04-26 17:58:56 +04:00
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
return parser->ParseMediaList(nsString(aMediaText), nsnull, 0,
|
|
|
|
this, htmlMode);
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
PRBool
|
2008-07-26 20:14:48 +04:00
|
|
|
nsMediaList::Matches(nsPresContext* aPresContext,
|
|
|
|
nsMediaQueryResultCacheKey& aKey)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
2008-07-26 20:14:48 +04:00
|
|
|
for (PRInt32 i = 0, i_end = mArray.Length(); i < i_end; ++i) {
|
2008-07-26 20:14:48 +04:00
|
|
|
if (mArray[i]->Matches(aPresContext, aKey)) {
|
2008-07-26 20:14:48 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mIsEmpty;
|
2005-03-30 04:36:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMediaList::SetStyleSheet(nsICSSStyleSheet *aSheet)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aSheet == mStyleSheet || !aSheet || !mStyleSheet,
|
|
|
|
"multiple style sheets competing for one media list");
|
2007-07-08 11:08:04 +04:00
|
|
|
mStyleSheet = static_cast<nsCSSStyleSheet*>(aSheet);
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-03-30 04:36:57 +04:00
|
|
|
nsresult
|
|
|
|
nsMediaList::Clone(nsMediaList** aResult)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
2005-03-30 04:36:57 +04:00
|
|
|
nsRefPtr<nsMediaList> result = new nsMediaList();
|
2008-07-26 20:14:48 +04:00
|
|
|
if (!result || !result->mArray.AppendElements(mArray.Length()))
|
2005-03-30 04:36:57 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2008-07-26 20:14:48 +04:00
|
|
|
for (PRInt32 i = 0, i_end = mArray.Length(); i < i_end; ++i) {
|
|
|
|
if (!(result->mArray[i] = mArray[i]->Clone())) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
}
|
2005-03-30 04:36:57 +04:00
|
|
|
NS_ADDREF(*aResult = result);
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList::GetMediaText(nsAString& aMediaText)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
return GetText(aMediaText);
|
|
|
|
}
|
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
// "sheet" should be an nsCSSStyleSheet and "doc" should be an
|
2003-10-16 22:14:25 +04:00
|
|
|
// nsCOMPtr<nsIDocument>
|
|
|
|
#define BEGIN_MEDIA_CHANGE(sheet, doc) \
|
|
|
|
if (sheet) { \
|
|
|
|
rv = sheet->GetOwningDocument(*getter_AddRefs(doc)); \
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv); \
|
|
|
|
} \
|
|
|
|
mozAutoDocUpdate updateBatch(doc, UPDATE_STYLE, PR_TRUE); \
|
|
|
|
if (sheet) { \
|
|
|
|
rv = sheet->WillDirty(); \
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define END_MEDIA_CHANGE(sheet, doc) \
|
|
|
|
if (sheet) { \
|
|
|
|
sheet->DidDirty(); \
|
|
|
|
} \
|
|
|
|
/* XXXldb Pass something meaningful? */ \
|
|
|
|
if (doc) { \
|
2003-10-22 10:09:48 +04:00
|
|
|
doc->StyleRuleChanged(sheet, nsnull, nsnull); \
|
2003-10-16 22:14:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_IMETHODIMP
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList::SetMediaText(const nsAString& aMediaText)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
2003-10-16 22:14:25 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
|
|
|
|
BEGIN_MEDIA_CHANGE(mStyleSheet, doc)
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
rv = SetText(aMediaText);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2003-10-16 22:14:25 +04:00
|
|
|
END_MEDIA_CHANGE(mStyleSheet, doc)
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList::GetLength(PRUint32* aLength)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLength);
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
*aLength = mArray.Length();
|
2000-04-26 17:58:56 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList::Item(PRUint32 aIndex, nsAString& aReturn)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
2005-03-30 04:36:57 +04:00
|
|
|
PRInt32 index = aIndex;
|
|
|
|
if (0 <= index && index < Count()) {
|
2008-07-26 20:14:48 +04:00
|
|
|
nsMediaQuery* query = mArray[index];
|
|
|
|
NS_ENSURE_TRUE(query, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
aReturn.Truncate();
|
|
|
|
query->AppendToString(aReturn);
|
2000-04-26 17:58:56 +04:00
|
|
|
} else {
|
2005-03-30 04:36:57 +04:00
|
|
|
SetDOMStringToNull(aReturn);
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList::DeleteMedium(const nsAString& aOldMedium)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
2003-10-16 22:14:25 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
|
|
|
|
BEGIN_MEDIA_CHANGE(mStyleSheet, doc)
|
2001-09-05 04:00:18 +04:00
|
|
|
|
|
|
|
rv = Delete(aOldMedium);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2003-10-16 22:14:25 +04:00
|
|
|
END_MEDIA_CHANGE(mStyleSheet, doc)
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList::AppendMedium(const nsAString& aNewMedium)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
2003-10-16 22:14:25 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
|
|
|
|
BEGIN_MEDIA_CHANGE(mStyleSheet, doc)
|
2001-09-05 04:00:18 +04:00
|
|
|
|
|
|
|
rv = Append(aNewMedium);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2003-10-16 22:14:25 +04:00
|
|
|
END_MEDIA_CHANGE(mStyleSheet, doc)
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList::Delete(const nsAString& aOldMedium)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
2002-01-24 05:03:19 +03:00
|
|
|
if (aOldMedium.IsEmpty())
|
2000-04-26 17:58:56 +04:00
|
|
|
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
for (PRInt32 i = 0, i_end = mArray.Length(); i < i_end; ++i) {
|
|
|
|
nsMediaQuery* query = mArray[i];
|
|
|
|
NS_ENSURE_TRUE(query, NS_ERROR_FAILURE);
|
2000-04-26 17:58:56 +04:00
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
nsAutoString buf;
|
|
|
|
query->AppendToString(buf);
|
|
|
|
if (buf == aOldMedium) {
|
|
|
|
mArray.RemoveElementAt(i);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
nsresult
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList::Append(const nsAString& aNewMedium)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
2002-01-24 05:03:19 +03:00
|
|
|
if (aNewMedium.IsEmpty())
|
2000-04-26 17:58:56 +04:00
|
|
|
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
Delete(aNewMedium);
|
2000-04-26 17:58:56 +04:00
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsTArray<nsAutoPtr<nsMediaQuery> > buf;
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRBool ok =
|
|
|
|
#endif
|
|
|
|
mArray.SwapElements(buf);
|
|
|
|
NS_ASSERTION(ok, "SwapElements should never fail when neither array "
|
|
|
|
"is an auto array");
|
|
|
|
SetText(aNewMedium);
|
|
|
|
if (mArray.Length() == 1) {
|
|
|
|
nsMediaQuery *query = mArray[0].forget();
|
|
|
|
if (!buf.AppendElement(query)) {
|
|
|
|
delete query;
|
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
2008-07-26 20:14:48 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
ok =
|
|
|
|
#endif
|
|
|
|
mArray.SwapElements(buf);
|
|
|
|
NS_ASSERTION(ok, "SwapElements should never fail when neither array "
|
|
|
|
"is an auto array");
|
|
|
|
return rv;
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
|
|
|
|
1998-10-06 05:39:33 +04:00
|
|
|
// -------------------------------
|
|
|
|
// Imports Collection for the DOM
|
|
|
|
//
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
class CSSImportsCollectionImpl : public nsIDOMStyleSheetList
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
// nsIDOMCSSStyleSheetList interface
|
1998-10-06 05:39:33 +04:00
|
|
|
NS_IMETHOD GetLength(PRUint32* aLength);
|
|
|
|
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn);
|
|
|
|
|
|
|
|
void DropReference() { mStyleSheet = nsnull; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~CSSImportsCollectionImpl();
|
|
|
|
|
|
|
|
nsICSSStyleSheet* mStyleSheet;
|
|
|
|
};
|
|
|
|
|
|
|
|
CSSImportsCollectionImpl::CSSImportsCollectionImpl(nsICSSStyleSheet *aStyleSheet)
|
|
|
|
{
|
|
|
|
// Not reference counted to avoid circular references.
|
|
|
|
// The style sheet will tell us when its going away.
|
|
|
|
mStyleSheet = aStyleSheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSImportsCollectionImpl::~CSSImportsCollectionImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
|
|
|
// QueryInterface implementation for CSSImportsCollectionImpl
|
|
|
|
NS_INTERFACE_MAP_BEGIN(CSSImportsCollectionImpl)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheetList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(StyleSheetList)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
2003-09-08 01:50:21 +04:00
|
|
|
NS_IMPL_ADDREF(CSSImportsCollectionImpl)
|
|
|
|
NS_IMPL_RELEASE(CSSImportsCollectionImpl)
|
1998-10-06 05:39:33 +04:00
|
|
|
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_IMETHODIMP
|
1998-10-06 05:39:33 +04:00
|
|
|
CSSImportsCollectionImpl::GetLength(PRUint32* aLength)
|
|
|
|
{
|
|
|
|
if (nsnull != mStyleSheet) {
|
1999-06-10 09:29:22 +04:00
|
|
|
PRInt32 count;
|
|
|
|
mStyleSheet->StyleSheetCount(count);
|
|
|
|
*aLength = (PRUint32)count;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aLength = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSImportsCollectionImpl::Item(PRUint32 aIndex, nsIDOMStyleSheet** aReturn)
|
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
*aReturn = nsnull;
|
|
|
|
|
2002-12-11 17:24:49 +03:00
|
|
|
if (mStyleSheet) {
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> sheet;
|
|
|
|
|
|
|
|
result = mStyleSheet->GetStyleSheetAt(aIndex, *getter_AddRefs(sheet));
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
result = CallQueryInterface(sheet, aReturn);
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
1998-05-21 00:34:17 +04:00
|
|
|
// -------------------------------
|
1999-06-03 05:57:52 +04:00
|
|
|
// CSS Style Sheet Inner Data Container
|
1998-05-21 00:34:17 +04:00
|
|
|
//
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
static PRBool SetStyleSheetReference(nsICSSRule* aRule, void* aSheet)
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
if (aRule) {
|
|
|
|
aRule->SetStyleSheet((nsICSSStyleSheet*)aSheet);
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheetInner::nsCSSStyleSheetInner(nsICSSStyleSheet* aParentSheet)
|
1999-06-03 05:57:52 +04:00
|
|
|
: mSheets(),
|
2002-12-03 08:48:14 +03:00
|
|
|
mComplete(PR_FALSE)
|
2007-05-01 23:26:15 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
, mPrincipalSet(PR_FALSE)
|
|
|
|
#endif
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
2004-08-04 07:27:28 +04:00
|
|
|
MOZ_COUNT_CTOR(nsCSSStyleSheetInner);
|
1999-06-03 05:57:52 +04:00
|
|
|
mSheets.AppendElement(aParentSheet);
|
2007-05-01 23:26:15 +04:00
|
|
|
|
|
|
|
mPrincipal = do_CreateInstance("@mozilla.org/nullprincipal;1");
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1999-05-19 03:14:29 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
static PRBool
|
2005-10-16 00:21:20 +04:00
|
|
|
CloneRuleInto(nsICSSRule* aRule, void* aArray)
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
1999-06-10 09:29:22 +04:00
|
|
|
nsICSSRule* clone = nsnull;
|
2005-10-16 00:21:20 +04:00
|
|
|
aRule->Clone(clone);
|
1999-06-03 05:57:52 +04:00
|
|
|
if (clone) {
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsCOMArray<nsICSSRule>*>(aArray)->AppendObject(clone);
|
1999-06-03 05:57:52 +04:00
|
|
|
NS_RELEASE(clone);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheetInner::nsCSSStyleSheetInner(nsCSSStyleSheetInner& aCopy,
|
2007-05-01 23:26:15 +04:00
|
|
|
nsICSSStyleSheet* aParentSheet)
|
1999-06-03 05:57:52 +04:00
|
|
|
: mSheets(),
|
2004-09-10 10:45:59 +04:00
|
|
|
mSheetURI(aCopy.mSheetURI),
|
2008-01-22 07:26:01 +03:00
|
|
|
mOriginalSheetURI(aCopy.mOriginalSheetURI),
|
2004-09-10 10:45:59 +04:00
|
|
|
mBaseURI(aCopy.mBaseURI),
|
2007-05-01 23:26:15 +04:00
|
|
|
mPrincipal(aCopy.mPrincipal),
|
2002-12-03 08:48:14 +03:00
|
|
|
mComplete(aCopy.mComplete)
|
2007-05-01 23:26:15 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
, mPrincipalSet(aCopy.mPrincipalSet)
|
|
|
|
#endif
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
2004-08-04 07:27:28 +04:00
|
|
|
MOZ_COUNT_CTOR(nsCSSStyleSheetInner);
|
1999-06-03 05:57:52 +04:00
|
|
|
mSheets.AppendElement(aParentSheet);
|
2005-10-16 00:21:20 +04:00
|
|
|
aCopy.mOrderedRules.EnumerateForwards(CloneRuleInto, &mOrderedRules);
|
|
|
|
mOrderedRules.EnumerateForwards(SetStyleSheetReference, aParentSheet);
|
1999-06-15 10:20:46 +04:00
|
|
|
RebuildNameSpaces();
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheetInner::~nsCSSStyleSheetInner()
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
2004-08-04 07:27:28 +04:00
|
|
|
MOZ_COUNT_DTOR(nsCSSStyleSheetInner);
|
2005-10-16 00:21:20 +04:00
|
|
|
mOrderedRules.EnumerateForwards(SetStyleSheetReference, nsnull);
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheetInner*
|
|
|
|
nsCSSStyleSheetInner::CloneFor(nsICSSStyleSheet* aParentSheet)
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
2004-08-04 07:27:28 +04:00
|
|
|
return new nsCSSStyleSheetInner(*this, aParentSheet);
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
void
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheetInner::AddSheet(nsICSSStyleSheet* aParentSheet)
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
|
|
|
mSheets.AppendElement(aParentSheet);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
void
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheetInner::RemoveSheet(nsICSSStyleSheet* aParentSheet)
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
|
|
|
if (1 == mSheets.Count()) {
|
|
|
|
NS_ASSERTION(aParentSheet == (nsICSSStyleSheet*)mSheets.ElementAt(0), "bad parent");
|
|
|
|
delete this;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (aParentSheet == (nsICSSStyleSheet*)mSheets.ElementAt(0)) {
|
|
|
|
mSheets.RemoveElementAt(0);
|
|
|
|
NS_ASSERTION(mSheets.Count(), "no parents");
|
2005-10-16 00:21:20 +04:00
|
|
|
mOrderedRules.EnumerateForwards(SetStyleSheetReference,
|
|
|
|
(nsICSSStyleSheet*)mSheets.ElementAt(0));
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
mSheets.RemoveElement(aParentSheet);
|
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-06-15 10:20:46 +04:00
|
|
|
static PRBool
|
2005-10-16 00:21:20 +04:00
|
|
|
CreateNameSpace(nsICSSRule* aRule, void* aNameSpacePtr)
|
1999-06-15 10:20:46 +04:00
|
|
|
{
|
2001-09-05 04:00:18 +04:00
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
2005-10-16 00:21:20 +04:00
|
|
|
aRule->GetType(type);
|
1999-06-15 10:20:46 +04:00
|
|
|
if (nsICSSRule::NAMESPACE_RULE == type) {
|
2005-10-16 00:21:20 +04:00
|
|
|
nsICSSNameSpaceRule* nameSpaceRule = (nsICSSNameSpaceRule*)aRule;
|
2005-02-19 03:10:38 +03:00
|
|
|
nsXMLNameSpaceMap *nameSpaceMap =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsXMLNameSpaceMap*>(aNameSpacePtr);
|
1999-06-15 10:20:46 +04:00
|
|
|
|
|
|
|
nsIAtom* prefix = nsnull;
|
|
|
|
nsAutoString urlSpec;
|
|
|
|
nameSpaceRule->GetPrefix(prefix);
|
|
|
|
nameSpaceRule->GetURLSpec(urlSpec);
|
|
|
|
|
2005-02-18 22:18:37 +03:00
|
|
|
nameSpaceMap->AddPrefix(prefix, urlSpec);
|
1999-06-15 10:20:46 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
// stop if not namespace, import or charset because namespace can't follow anything else
|
|
|
|
return (((nsICSSRule::CHARSET_RULE == type) ||
|
|
|
|
(nsICSSRule::IMPORT_RULE)) ? PR_TRUE : PR_FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheetInner::RebuildNameSpaces()
|
1999-06-15 10:20:46 +04:00
|
|
|
{
|
2005-02-18 22:18:37 +03:00
|
|
|
if (mNameSpaceMap) {
|
|
|
|
mNameSpaceMap->Clear();
|
|
|
|
} else {
|
2005-02-19 03:10:38 +03:00
|
|
|
mNameSpaceMap = nsXMLNameSpaceMap::Create();
|
2005-02-18 22:18:37 +03:00
|
|
|
if (!mNameSpaceMap) {
|
|
|
|
return; // out of memory
|
|
|
|
}
|
|
|
|
}
|
2003-07-18 05:26:47 +04:00
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
mOrderedRules.EnumerateForwards(CreateNameSpace, mNameSpaceMap);
|
1999-06-15 10:20:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
// -------------------------------
|
|
|
|
// CSS Style Sheet
|
|
|
|
//
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::nsCSSStyleSheet()
|
1998-04-14 00:24:54 +04:00
|
|
|
: nsICSSStyleSheet(),
|
2002-09-17 08:49:28 +04:00
|
|
|
mRefCnt(0),
|
1999-06-03 05:57:52 +04:00
|
|
|
mTitle(),
|
|
|
|
mMedia(nsnull),
|
1998-11-26 04:34:53 +03:00
|
|
|
mFirstChild(nsnull),
|
1998-06-05 10:06:50 +04:00
|
|
|
mNext(nsnull),
|
1999-06-03 05:57:52 +04:00
|
|
|
mParent(nsnull),
|
2002-08-06 09:08:47 +04:00
|
|
|
mOwnerRule(nsnull),
|
1999-06-03 05:57:52 +04:00
|
|
|
mImportsCollection(nsnull),
|
|
|
|
mRuleCollection(nsnull),
|
|
|
|
mDocument(nsnull),
|
|
|
|
mOwningNode(nsnull),
|
|
|
|
mDisabled(PR_FALSE),
|
1999-07-16 21:40:39 +04:00
|
|
|
mDirty(PR_FALSE),
|
1999-10-14 04:59:21 +04:00
|
|
|
mRuleProcessors(nsnull)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1998-12-11 05:50:43 +03:00
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
mInner = new nsCSSStyleSheetInner(this);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::nsCSSStyleSheet(const nsCSSStyleSheet& aCopy,
|
2007-05-01 23:26:15 +04:00
|
|
|
nsICSSStyleSheet* aParentToUse,
|
|
|
|
nsICSSImportRule* aOwnerRuleToUse,
|
|
|
|
nsIDocument* aDocumentToUse,
|
|
|
|
nsIDOMNode* aOwningNodeToUse)
|
1999-06-03 05:57:52 +04:00
|
|
|
: nsICSSStyleSheet(),
|
2002-09-17 08:49:28 +04:00
|
|
|
mRefCnt(0),
|
1999-06-03 05:57:52 +04:00
|
|
|
mTitle(aCopy.mTitle),
|
|
|
|
mMedia(nsnull),
|
|
|
|
mFirstChild(nsnull),
|
|
|
|
mNext(nsnull),
|
2003-02-23 07:44:41 +03:00
|
|
|
mParent(aParentToUse),
|
|
|
|
mOwnerRule(aOwnerRuleToUse),
|
1999-06-03 05:57:52 +04:00
|
|
|
mImportsCollection(nsnull), // re-created lazily
|
|
|
|
mRuleCollection(nsnull), // re-created lazily
|
2003-02-23 07:44:41 +03:00
|
|
|
mDocument(aDocumentToUse),
|
|
|
|
mOwningNode(aOwningNodeToUse),
|
1999-06-03 05:57:52 +04:00
|
|
|
mDisabled(aCopy.mDisabled),
|
1999-07-16 21:40:39 +04:00
|
|
|
mDirty(PR_FALSE),
|
1999-10-14 04:59:21 +04:00
|
|
|
mInner(aCopy.mInner),
|
|
|
|
mRuleProcessors(nsnull)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
mInner->AddSheet(this);
|
|
|
|
|
|
|
|
if (aCopy.mRuleCollection &&
|
|
|
|
aCopy.mRuleCollection->mRulesAccessed) { // CSSOM's been there, force full copy now
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_ASSERTION(mInner->mComplete, "Why have rules been accessed on an incomplete sheet?");
|
1999-06-03 05:57:52 +04:00
|
|
|
EnsureUniqueInner();
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
if (aCopy.mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
aCopy.mMedia->Clone(getter_AddRefs(mMedia));
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aCopy.mFirstChild) {
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet* otherChild = aCopy.mFirstChild;
|
|
|
|
nsCSSStyleSheet** ourSlot = &mFirstChild;
|
1999-06-03 05:57:52 +04:00
|
|
|
do {
|
2003-02-23 07:44:41 +03:00
|
|
|
// XXX This is wrong; we should be keeping @import rules and
|
|
|
|
// sheets in sync!
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet* child = new nsCSSStyleSheet(*otherChild,
|
2003-03-17 06:44:02 +03:00
|
|
|
this,
|
|
|
|
nsnull,
|
|
|
|
aDocumentToUse,
|
|
|
|
nsnull);
|
1999-06-03 05:57:52 +04:00
|
|
|
if (child) {
|
|
|
|
NS_ADDREF(child);
|
|
|
|
(*ourSlot) = child;
|
|
|
|
ourSlot = &(child->mNext);
|
|
|
|
}
|
|
|
|
otherChild = otherChild->mNext;
|
|
|
|
}
|
|
|
|
while (otherChild && ourSlot);
|
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::~nsCSSStyleSheet()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
1999-05-19 03:14:29 +04:00
|
|
|
if (mFirstChild) {
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet* child = mFirstChild;
|
1999-05-19 03:14:29 +04:00
|
|
|
do {
|
|
|
|
child->mParent = nsnull;
|
2003-03-17 06:44:02 +03:00
|
|
|
child->mDocument = nsnull;
|
1999-05-19 03:14:29 +04:00
|
|
|
child = child->mNext;
|
|
|
|
} while (child);
|
|
|
|
NS_RELEASE(mFirstChild);
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
1999-05-19 03:14:29 +04:00
|
|
|
NS_IF_RELEASE(mNext);
|
1998-10-06 05:39:33 +04:00
|
|
|
if (nsnull != mRuleCollection) {
|
|
|
|
mRuleCollection->DropReference();
|
|
|
|
NS_RELEASE(mRuleCollection);
|
|
|
|
}
|
|
|
|
if (nsnull != mImportsCollection) {
|
|
|
|
mImportsCollection->DropReference();
|
|
|
|
NS_RELEASE(mImportsCollection);
|
|
|
|
}
|
2000-04-26 17:58:56 +04:00
|
|
|
if (mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
mMedia->SetStyleSheet(nsnull);
|
|
|
|
mMedia = nsnull;
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
1999-06-03 05:57:52 +04:00
|
|
|
mInner->RemoveSheet(this);
|
1998-11-17 05:14:38 +03:00
|
|
|
// XXX The document reference is not reference counted and should
|
|
|
|
// not be released. The document will let us know when it is going
|
|
|
|
// away.
|
1999-10-14 04:59:21 +04:00
|
|
|
if (mRuleProcessors) {
|
2006-02-23 12:36:43 +03:00
|
|
|
NS_ASSERTION(mRuleProcessors->Count() == 0, "destructing sheet with rule processor reference");
|
1999-10-14 04:59:21 +04:00
|
|
|
delete mRuleProcessors; // weak refs, should be empty here anyway
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
// QueryInterface implementation for nsCSSStyleSheet
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsCSSStyleSheet)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet)
|
2002-08-06 09:08:47 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver)
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONTENT_CLASSINFO(CSSStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
NS_IMPL_ADDREF(nsCSSStyleSheet)
|
|
|
|
NS_IMPL_RELEASE(nsCSSStyleSheet)
|
1998-04-14 00:24:54 +04:00
|
|
|
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::AddRuleProcessor(nsCSSRuleProcessor* aProcessor)
|
2004-07-28 11:08:41 +04:00
|
|
|
{
|
|
|
|
if (! mRuleProcessors) {
|
|
|
|
mRuleProcessors = new nsAutoVoidArray();
|
|
|
|
if (!mRuleProcessors)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
2004-07-28 11:08:41 +04:00
|
|
|
NS_ASSERTION(-1 == mRuleProcessors->IndexOf(aProcessor),
|
|
|
|
"processor already registered");
|
|
|
|
mRuleProcessors->AppendElement(aProcessor); // weak ref
|
1999-10-08 07:09:31 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::DropRuleProcessor(nsCSSRuleProcessor* aProcessor)
|
1999-10-08 07:09:31 +04:00
|
|
|
{
|
2004-07-28 11:08:41 +04:00
|
|
|
if (!mRuleProcessors)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return mRuleProcessors->RemoveElement(aProcessor)
|
|
|
|
? NS_OK
|
|
|
|
: NS_ERROR_FAILURE;
|
1999-10-08 07:09:31 +04:00
|
|
|
}
|
|
|
|
|
1998-12-20 04:17:05 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2007-10-24 01:56:41 +04:00
|
|
|
nsCSSStyleSheet::SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI,
|
|
|
|
nsIURI* aBaseURI)
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2004-09-10 10:45:59 +04:00
|
|
|
NS_PRECONDITION(aSheetURI && aBaseURI, "null ptr");
|
1998-12-20 04:17:05 +03:00
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
NS_ASSERTION(mInner->mOrderedRules.Count() == 0 && !mInner->mComplete,
|
2003-10-06 17:24:55 +04:00
|
|
|
"Can't call SetURL on sheets that are complete or have rules");
|
1998-12-20 04:17:05 +03:00
|
|
|
|
2004-09-10 10:45:59 +04:00
|
|
|
mInner->mSheetURI = aSheetURI;
|
2007-10-24 01:56:41 +04:00
|
|
|
mInner->mOriginalSheetURI = aOriginalSheetURI;
|
2004-09-10 10:45:59 +04:00
|
|
|
mInner->mBaseURI = aBaseURI;
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
1998-12-20 04:17:05 +03:00
|
|
|
}
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
void
|
|
|
|
nsCSSStyleSheet::SetPrincipal(nsIPrincipal* aPrincipal)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mInner->mPrincipalSet,
|
|
|
|
"Should have an inner whose principal has not yet been set");
|
|
|
|
if (aPrincipal) {
|
|
|
|
mInner->mPrincipal = aPrincipal;
|
|
|
|
#ifdef DEBUG
|
|
|
|
mInner->mPrincipalSet = PR_TRUE;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIPrincipal*
|
|
|
|
nsCSSStyleSheet::Principal() const
|
|
|
|
{
|
|
|
|
return mInner->mPrincipal;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-09-10 10:45:59 +04:00
|
|
|
nsCSSStyleSheet::GetSheetURI(nsIURI** aSheetURI) const
|
1998-12-20 04:17:05 +03:00
|
|
|
{
|
2007-05-01 23:26:15 +04:00
|
|
|
NS_IF_ADDREF(*aSheetURI = mInner->mSheetURI.get());
|
2004-09-10 10:45:59 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetBaseURI(nsIURI** aBaseURI) const
|
|
|
|
{
|
2007-05-01 23:26:15 +04:00
|
|
|
NS_IF_ADDREF(*aBaseURI = mInner->mBaseURI.get());
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
1998-12-20 04:17:05 +03:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::SetTitle(const nsAString& aTitle)
|
1999-02-27 10:17:52 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
mTitle = aTitle;
|
|
|
|
return NS_OK;
|
1999-02-27 10:17:52 +03:00
|
|
|
}
|
1998-12-20 04:17:05 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetType(nsString& aType) const
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aType.AssignLiteral("text/css");
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
PRBool
|
|
|
|
nsCSSStyleSheet::UseForPresentation(nsPresContext* aPresContext,
|
|
|
|
nsMediaQueryResultCacheKey& aKey) const
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
|
|
|
if (mMedia) {
|
2008-07-26 20:14:48 +04:00
|
|
|
return mMedia->Matches(aPresContext, aKey);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
return PR_TRUE;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-21 00:34:17 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2005-03-30 04:36:57 +04:00
|
|
|
nsCSSStyleSheet::SetMedia(nsMediaList* aMedia)
|
1999-02-27 10:17:52 +03:00
|
|
|
{
|
2005-03-30 04:36:57 +04:00
|
|
|
mMedia = aMedia;
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
2003-07-04 05:44:24 +04:00
|
|
|
NS_IMETHODIMP_(PRBool)
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::HasRules() const
|
2003-07-04 05:44:24 +04:00
|
|
|
{
|
|
|
|
PRInt32 count;
|
|
|
|
StyleRuleCount(count);
|
|
|
|
return count != 0;
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetApplicable(PRBool& aApplicable) const
|
1998-05-21 00:34:17 +04:00
|
|
|
{
|
2007-05-01 23:26:15 +04:00
|
|
|
aApplicable = !mDisabled && mInner->mComplete;
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::SetEnabled(PRBool aEnabled)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2007-01-11 22:32:31 +03:00
|
|
|
// Internal method, so callers must handle BeginUpdate/EndUpdate
|
|
|
|
PRBool oldDisabled = mDisabled;
|
|
|
|
mDisabled = !aEnabled;
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
if (mDocument && mInner->mComplete && oldDisabled != mDisabled) {
|
2007-01-11 22:32:31 +03:00
|
|
|
ClearRuleCascades();
|
|
|
|
|
|
|
|
mDocument->SetStyleSheetApplicableState(this, !mDisabled);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
1998-11-03 23:33:43 +03:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetComplete(PRBool& aComplete) const
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
2007-05-01 23:26:15 +04:00
|
|
|
aComplete = mInner->mComplete;
|
2002-12-03 08:48:14 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::SetComplete()
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!mDirty, "Can't set a dirty sheet complete!");
|
|
|
|
mInner->mComplete = PR_TRUE;
|
|
|
|
if (mDocument && !mDisabled) {
|
|
|
|
// Let the document know
|
2003-10-03 01:29:40 +04:00
|
|
|
mDocument->BeginUpdate(UPDATE_STYLE);
|
2002-12-03 08:48:14 +03:00
|
|
|
mDocument->SetStyleSheetApplicableState(this, PR_TRUE);
|
2003-10-03 01:29:40 +04:00
|
|
|
mDocument->EndUpdate(UPDATE_STYLE);
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetParentSheet(nsIStyleSheet*& aParent) const
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
|
|
|
aParent = mParent;
|
2000-02-18 02:19:18 +03:00
|
|
|
NS_IF_ADDREF(aParent);
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-05-19 01:10:19 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetOwningDocument(nsIDocument*& aDocument) const
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2003-03-17 06:44:02 +03:00
|
|
|
aDocument = mDocument;
|
|
|
|
NS_IF_ADDREF(aDocument);
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-11-03 23:33:43 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::SetOwningDocument(nsIDocument* aDocument)
|
1999-10-14 04:59:21 +04:00
|
|
|
{ // not ref counted
|
|
|
|
mDocument = aDocument;
|
2003-03-17 06:44:02 +03:00
|
|
|
// Now set the same document on all our child sheets....
|
2004-08-04 07:27:28 +04:00
|
|
|
for (nsCSSStyleSheet* child = mFirstChild; child; child = child->mNext) {
|
2006-08-17 12:16:41 +04:00
|
|
|
child->SetOwningDocument(aDocument);
|
2003-03-17 06:44:02 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1998-05-19 01:10:19 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::SetOwningNode(nsIDOMNode* aOwningNode)
|
1999-10-14 04:59:21 +04:00
|
|
|
{ // not ref counted
|
|
|
|
mOwningNode = aOwningNode;
|
1999-10-08 07:09:31 +04:00
|
|
|
return NS_OK;
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
2002-08-06 09:08:47 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::SetOwnerRule(nsICSSImportRule* aOwnerRule)
|
2002-08-06 09:08:47 +04:00
|
|
|
{ // not ref counted
|
|
|
|
mOwnerRule = aOwnerRule;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetOwnerRule(nsICSSImportRule** aOwnerRule)
|
2003-06-24 09:40:37 +04:00
|
|
|
{
|
|
|
|
*aOwnerRule = mOwnerRule;
|
|
|
|
NS_IF_ADDREF(*aOwnerRule);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::ContainsStyleSheet(nsIURI* aURL, PRBool& aContains, nsIStyleSheet** aTheChild /*=nsnull*/)
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aURL, "null arg");
|
1998-05-21 00:34:17 +04:00
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
if (!mInner->mSheetURI) {
|
2003-07-18 04:35:49 +04:00
|
|
|
// We're not yet far enough along in our load to know what our URL is (we
|
|
|
|
// may still get redirected and such). Assert (caller should really not be
|
|
|
|
// calling this on us at this stage) and return.
|
|
|
|
NS_ERROR("ContainsStyleSheet called on a sheet that's still loading");
|
|
|
|
aContains = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-06-03 01:45:06 +04:00
|
|
|
// first check ourself out
|
2004-09-10 10:45:59 +04:00
|
|
|
nsresult rv = mInner->mSheetURI->Equals(aURL, &aContains);
|
2000-06-03 01:45:06 +04:00
|
|
|
if (NS_FAILED(rv)) aContains = PR_FALSE;
|
1998-05-21 00:34:17 +04:00
|
|
|
|
2000-06-03 01:45:06 +04:00
|
|
|
if (aContains) {
|
|
|
|
// if we found it and the out-param is there, set it and addref
|
|
|
|
if (aTheChild) {
|
2001-01-04 23:44:42 +03:00
|
|
|
rv = QueryInterface( NS_GET_IID(nsIStyleSheet), (void **)aTheChild);
|
2000-06-03 01:45:06 +04:00
|
|
|
}
|
|
|
|
} else {
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet* child = mFirstChild;
|
2000-06-03 01:45:06 +04:00
|
|
|
// now check the chil'ins out (recursively)
|
|
|
|
while ((PR_FALSE == aContains) && (nsnull != child)) {
|
|
|
|
child->ContainsStyleSheet(aURL, aContains, aTheChild);
|
|
|
|
if (aContains) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
2000-06-03 01:45:06 +04:00
|
|
|
|
|
|
|
// NOTE: if there are errors in the above we are handling them locally
|
|
|
|
// and not promoting them to the caller
|
|
|
|
return NS_OK;
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
1998-05-21 00:34:17 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::AppendStyleSheet(nsICSSStyleSheet* aSheet)
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
1999-02-27 10:17:52 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (NS_SUCCEEDED(WillDirty())) {
|
|
|
|
NS_ADDREF(aSheet);
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet* sheet = (nsCSSStyleSheet*)aSheet;
|
1999-02-27 10:17:52 +03:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (! mFirstChild) {
|
|
|
|
mFirstChild = sheet;
|
1999-02-27 10:17:52 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
else {
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet* child = mFirstChild;
|
1999-10-14 04:59:21 +04:00
|
|
|
while (child->mNext) {
|
|
|
|
child = child->mNext;
|
1998-05-19 01:10:19 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
child->mNext = sheet;
|
1998-05-19 01:10:19 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
// This is not reference counted. Our parent tells us when
|
|
|
|
// it's going away.
|
|
|
|
sheet->mParent = this;
|
2003-03-17 06:44:02 +03:00
|
|
|
sheet->mDocument = mDocument;
|
1999-10-14 04:59:21 +04:00
|
|
|
DidDirty();
|
1998-05-19 01:10:19 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
1998-05-19 01:10:19 +04:00
|
|
|
}
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::InsertStyleSheetAt(nsICSSStyleSheet* aSheet, PRInt32 aIndex)
|
1998-05-19 01:10:19 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
1998-05-19 01:10:19 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
nsresult result = WillDirty();
|
1999-05-27 03:55:12 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
NS_ADDREF(aSheet);
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet* sheet = (nsCSSStyleSheet*)aSheet;
|
|
|
|
nsCSSStyleSheet* child = mFirstChild;
|
1998-05-21 00:34:17 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (aIndex && child) {
|
|
|
|
while ((0 < --aIndex) && child->mNext) {
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
sheet->mNext = child->mNext;
|
|
|
|
child->mNext = sheet;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sheet->mNext = mFirstChild;
|
|
|
|
mFirstChild = sheet;
|
|
|
|
}
|
|
|
|
|
|
|
|
// This is not reference counted. Our parent tells us when
|
|
|
|
// it's going away.
|
|
|
|
sheet->mParent = this;
|
2003-03-17 06:44:02 +03:00
|
|
|
sheet->mDocument = mDocument;
|
1999-10-14 04:59:21 +04:00
|
|
|
DidDirty();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return result;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::PrependStyleRule(nsICSSRule* aRule)
|
1999-04-20 04:05:54 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_PRECONDITION(nsnull != aRule, "null arg");
|
1999-04-20 04:05:54 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (NS_SUCCEEDED(WillDirty())) {
|
2005-10-16 00:21:20 +04:00
|
|
|
mInner->mOrderedRules.InsertObjectAt(aRule, 0);
|
|
|
|
aRule->SetStyleSheet(this);
|
|
|
|
DidDirty();
|
|
|
|
|
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
aRule->GetType(type);
|
|
|
|
if (nsICSSRule::NAMESPACE_RULE == type) {
|
|
|
|
// no api to prepend a namespace (ugh), release old ones and re-create them all
|
|
|
|
mInner->RebuildNameSpaces();
|
1999-04-20 04:05:54 +04:00
|
|
|
}
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
1999-04-20 04:05:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::AppendStyleRule(nsICSSRule* aRule)
|
1999-04-20 04:05:54 +04:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_PRECONDITION(nsnull != aRule, "null arg");
|
1999-05-27 03:55:12 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
if (NS_SUCCEEDED(WillDirty())) {
|
2005-10-16 00:21:20 +04:00
|
|
|
mInner->mOrderedRules.AppendObject(aRule);
|
|
|
|
aRule->SetStyleSheet(this);
|
|
|
|
DidDirty();
|
|
|
|
|
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
aRule->GetType(type);
|
|
|
|
if (nsICSSRule::NAMESPACE_RULE == type) {
|
|
|
|
if (!mInner->mNameSpaceMap) {
|
|
|
|
mInner->mNameSpaceMap = nsXMLNameSpaceMap::Create();
|
|
|
|
NS_ENSURE_TRUE(mInner->mNameSpaceMap, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
}
|
1999-04-20 04:05:54 +04:00
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
nsCOMPtr<nsICSSNameSpaceRule> nameSpaceRule(do_QueryInterface(aRule));
|
2005-02-18 22:18:37 +03:00
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
nsCOMPtr<nsIAtom> prefix;
|
|
|
|
nsAutoString urlSpec;
|
|
|
|
nameSpaceRule->GetPrefix(*getter_AddRefs(prefix));
|
|
|
|
nameSpaceRule->GetURLSpec(urlSpec);
|
2005-02-18 22:18:37 +03:00
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
mInner->mNameSpaceMap->AddPrefix(prefix, urlSpec);
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-04-20 04:05:54 +04:00
|
|
|
|
2003-06-18 05:59:57 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew)
|
2003-06-18 05:59:57 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
NS_PRECONDITION(mInner->mOrderedRules.Count() != 0, "can't have old rule");
|
2007-05-01 23:26:15 +04:00
|
|
|
NS_PRECONDITION(mInner->mComplete, "No replacing in an incomplete sheet!");
|
2003-06-18 05:59:57 +04:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(WillDirty())) {
|
2005-10-16 00:21:20 +04:00
|
|
|
PRInt32 index = mInner->mOrderedRules.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
|
|
|
mInner->mOrderedRules.ReplaceObjectAt(aNew, index);
|
2003-06-18 05:59:57 +04:00
|
|
|
|
|
|
|
aNew->SetStyleSheet(this);
|
|
|
|
aOld->SetStyleSheet(nsnull);
|
|
|
|
DidDirty();
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
aNew->GetType(type);
|
|
|
|
NS_ASSERTION(nsICSSRule::NAMESPACE_RULE != type, "not yet implemented");
|
|
|
|
aOld->GetType(type);
|
|
|
|
NS_ASSERTION(nsICSSRule::NAMESPACE_RULE != type, "not yet implemented");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-12-03 23:20:35 +03:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::StyleRuleCount(PRInt32& aCount) const
|
1998-12-03 23:20:35 +03:00
|
|
|
{
|
2007-05-01 23:26:15 +04:00
|
|
|
aCount = mInner->mOrderedRules.Count();
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-03 05:57:52 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2002-06-15 03:54:18 +04:00
|
|
|
// Important: If this function is ever made scriptable, we must add
|
2007-07-03 22:45:39 +04:00
|
|
|
// a security check here. See GetCssRules below for an example.
|
2007-05-01 23:26:15 +04:00
|
|
|
aRule = mInner->mOrderedRules.SafeObjectAt(aIndex);
|
|
|
|
if (aRule) {
|
|
|
|
NS_ADDREF(aRule);
|
|
|
|
return NS_OK;
|
2007-03-23 02:01:14 +03:00
|
|
|
}
|
2007-05-01 23:26:15 +04:00
|
|
|
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
1998-12-03 23:20:35 +03:00
|
|
|
}
|
|
|
|
|
2005-02-19 03:10:38 +03:00
|
|
|
nsXMLNameSpaceMap*
|
2005-02-18 22:18:37 +03:00
|
|
|
nsCSSStyleSheet::GetNameSpaceMap() const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2007-05-01 23:26:15 +04:00
|
|
|
return mInner->mNameSpaceMap;
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::StyleSheetCount(PRInt32& aCount) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
// XXX Far from an ideal way to do this, but the hope is that
|
|
|
|
// it won't be done too often. If it is, we might want to
|
|
|
|
// consider storing the children in an array.
|
|
|
|
aCount = 0;
|
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
const nsCSSStyleSheet* child = mFirstChild;
|
1999-10-14 04:59:21 +04:00
|
|
|
while (child) {
|
|
|
|
aCount++;
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
// XXX Ughh...an O(n^2) method for doing iteration. Again, we hope
|
|
|
|
// that this isn't done too often. If it is, we need to change the
|
|
|
|
// underlying storage mechanism
|
|
|
|
aSheet = nsnull;
|
|
|
|
|
|
|
|
if (mFirstChild) {
|
2004-08-04 07:27:28 +04:00
|
|
|
const nsCSSStyleSheet* child = mFirstChild;
|
1999-10-14 04:59:21 +04:00
|
|
|
while ((child) && (0 != aIndex)) {
|
|
|
|
--aIndex;
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
aSheet = (nsICSSStyleSheet*)child;
|
|
|
|
NS_IF_ADDREF(aSheet);
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
nsresult
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::EnsureUniqueInner()
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
if (1 < mInner->mSheets.Count()) {
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheetInner* clone = mInner->CloneFor(this);
|
1999-10-14 04:59:21 +04:00
|
|
|
if (clone) {
|
|
|
|
mInner->RemoveSheet(this);
|
|
|
|
mInner = clone;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1999-05-13 08:56:04 +04:00
|
|
|
}
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::Clone(nsICSSStyleSheet* aCloneParent,
|
2003-02-23 07:44:41 +03:00
|
|
|
nsICSSImportRule* aCloneOwnerRule,
|
|
|
|
nsIDocument* aCloneDocument,
|
|
|
|
nsIDOMNode* aCloneOwningNode,
|
|
|
|
nsICSSStyleSheet** aClone) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aClone, "Null out param!");
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet* clone = new nsCSSStyleSheet(*this,
|
2003-02-23 07:44:41 +03:00
|
|
|
aCloneParent,
|
|
|
|
aCloneOwnerRule,
|
|
|
|
aCloneDocument,
|
|
|
|
aCloneOwningNode);
|
1999-10-14 04:59:21 +04:00
|
|
|
if (clone) {
|
2007-07-08 11:08:04 +04:00
|
|
|
*aClone = static_cast<nsICSSStyleSheet*>(clone);
|
2003-02-23 07:44:41 +03:00
|
|
|
NS_ADDREF(*aClone);
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1999-10-14 04:59:21 +04:00
|
|
|
static void
|
2005-10-16 00:21:20 +04:00
|
|
|
ListRules(const nsCOMArray<nsICSSRule>& aRules, FILE* aOut, PRInt32 aIndent)
|
1999-06-15 10:20:46 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
for (PRInt32 index = aRules.Count() - 1; index >= 0; --index) {
|
|
|
|
aRules.ObjectAt(index)->List(aOut, aIndent);
|
1999-06-15 10:20:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
struct ListEnumData {
|
|
|
|
ListEnumData(FILE* aOut, PRInt32 aIndent)
|
|
|
|
: mOut(aOut),
|
|
|
|
mIndent(aIndent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
FILE* mOut;
|
|
|
|
PRInt32 mIndent;
|
|
|
|
};
|
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
void nsCSSStyleSheet::List(FILE* out, PRInt32 aIndent) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
|
|
|
|
// Indent
|
|
|
|
for (index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("CSS Style Sheet: ", out);
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString urlSpec;
|
2004-09-10 10:45:59 +04:00
|
|
|
nsresult rv = mInner->mSheetURI->GetSpec(urlSpec);
|
2002-03-06 10:48:55 +03:00
|
|
|
if (NS_SUCCEEDED(rv) && !urlSpec.IsEmpty()) {
|
|
|
|
fputs(urlSpec.get(), out);
|
1998-12-02 03:37:32 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
if (mMedia) {
|
|
|
|
fputs(" media: ", out);
|
|
|
|
nsAutoString buffer;
|
2005-03-30 04:36:57 +04:00
|
|
|
mMedia->GetText(buffer);
|
|
|
|
fputs(NS_ConvertUTF16toUTF8(buffer).get(), out);
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
fputs("\n", out);
|
|
|
|
|
2004-08-04 07:27:28 +04:00
|
|
|
const nsCSSStyleSheet* child = mFirstChild;
|
1999-10-14 04:59:21 +04:00
|
|
|
while (nsnull != child) {
|
|
|
|
child->List(out, aIndent + 1);
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs("Rules in source order:\n", out);
|
|
|
|
ListRules(mInner->mOrderedRules, out, aIndent);
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2000-05-03 03:07:11 +04:00
|
|
|
static PRBool PR_CALLBACK
|
1999-10-14 04:59:21 +04:00
|
|
|
EnumClearRuleCascades(void* aProcessor, void* aData)
|
1999-05-27 03:55:12 +04:00
|
|
|
{
|
2004-07-28 11:08:41 +04:00
|
|
|
nsCSSRuleProcessor* processor =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsCSSRuleProcessor*>(aProcessor);
|
1999-10-14 04:59:21 +04:00
|
|
|
processor->ClearRuleCascades();
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::ClearRuleCascades()
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
|
|
|
if (mRuleProcessors) {
|
|
|
|
mRuleProcessors->EnumerateForwards(EnumClearRuleCascades, nsnull);
|
|
|
|
}
|
|
|
|
if (mParent) {
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet* parent = (nsCSSStyleSheet*)mParent;
|
1999-10-14 04:59:21 +04:00
|
|
|
parent->ClearRuleCascades();
|
1999-05-27 03:55:12 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::WillDirty()
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2007-05-01 23:26:15 +04:00
|
|
|
if (!mInner->mComplete) {
|
2002-12-03 08:48:14 +03:00
|
|
|
// Do nothing
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
return EnsureUniqueInner();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::DidDirty()
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
|
|
|
ClearRuleCascades();
|
|
|
|
mDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-07-03 22:45:39 +04:00
|
|
|
nsresult
|
|
|
|
nsCSSStyleSheet::SubjectSubsumesInnerPrincipal() const
|
|
|
|
{
|
|
|
|
// Get the security manager and do the subsumes check
|
|
|
|
nsIScriptSecurityManager *securityManager =
|
|
|
|
nsContentUtils::GetSecurityManager();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrincipal> subjectPrincipal;
|
|
|
|
securityManager->GetSubjectPrincipal(getter_AddRefs(subjectPrincipal));
|
|
|
|
|
|
|
|
if (!subjectPrincipal) {
|
2008-01-18 08:23:44 +03:00
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
2007-07-03 22:45:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool subsumes;
|
|
|
|
nsresult rv = subjectPrincipal->Subsumes(mInner->mPrincipal, &subsumes);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (subsumes) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!nsContentUtils::IsCallerTrustedForWrite()) {
|
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::IsModified(PRBool* aSheetModified) const
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2000-04-16 04:23:57 +04:00
|
|
|
*aSheetModified = mDirty;
|
|
|
|
return NS_OK;
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::SetModified(PRBool aModified)
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
|
|
|
mDirty = aModified;
|
1999-05-27 03:55:12 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
// nsIDOMStyleSheet interface
|
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetType(nsAString& aType)
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aType.AssignLiteral("text/css");
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-05-27 03:55:12 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetDisabled(PRBool* aDisabled)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
*aDisabled = mDisabled;
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::SetDisabled(PRBool aDisabled)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2007-01-11 22:32:31 +03:00
|
|
|
// DOM method, so handle BeginUpdate/EndUpdate
|
|
|
|
MOZ_AUTO_DOC_UPDATE(mDocument, UPDATE_STYLE, PR_TRUE);
|
|
|
|
nsresult rv = nsCSSStyleSheet::SetEnabled(!aDisabled);
|
|
|
|
return rv;
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetOwnerNode(nsIDOMNode** aOwnerNode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-04-26 17:58:56 +04:00
|
|
|
*aOwnerNode = mOwningNode;
|
|
|
|
NS_IF_ADDREF(*aOwnerNode);
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aParentStyleSheet);
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (mParent) {
|
|
|
|
rv = mParent->QueryInterface(NS_GET_IID(nsIDOMStyleSheet),
|
|
|
|
(void **)aParentStyleSheet);
|
|
|
|
} else {
|
1999-10-14 04:59:21 +04:00
|
|
|
*aParentStyleSheet = nsnull;
|
|
|
|
}
|
2000-04-26 17:58:56 +04:00
|
|
|
|
|
|
|
return rv;
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetHref(nsAString& aHref)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2007-10-24 01:56:41 +04:00
|
|
|
if (mInner->mOriginalSheetURI) {
|
|
|
|
nsCAutoString str;
|
|
|
|
mInner->mOriginalSheetURI->GetSpec(str);
|
|
|
|
CopyUTF8toUTF16(str, aHref);
|
|
|
|
} else {
|
|
|
|
SetDOMStringToNull(aHref);
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
1999-06-10 09:29:22 +04:00
|
|
|
return NS_OK;
|
1999-05-19 03:14:29 +04:00
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetTitle(nsString& aTitle) const
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
|
|
|
aTitle = mTitle;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-05-19 03:14:29 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetTitle(nsAString& aTitle)
|
1999-05-19 03:14:29 +04:00
|
|
|
{
|
2000-08-23 21:27:06 +04:00
|
|
|
aTitle.Assign(mTitle);
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-06-10 09:29:22 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetMedia(nsIDOMMediaList** aMedia)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aMedia);
|
|
|
|
*aMedia = nsnull;
|
|
|
|
|
|
|
|
if (!mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
mMedia = new nsMediaList();
|
|
|
|
NS_ENSURE_TRUE(mMedia, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
mMedia->SetStyleSheet(this);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2000-04-26 17:58:56 +04:00
|
|
|
|
|
|
|
*aMedia = mMedia;
|
2005-03-30 04:36:57 +04:00
|
|
|
NS_ADDREF(*aMedia);
|
2000-04-26 17:58:56 +04:00
|
|
|
|
1999-06-10 09:29:22 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetOwnerRule(nsIDOMCSSRule** aOwnerRule)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
2002-08-06 09:08:47 +04:00
|
|
|
if (mOwnerRule) {
|
2003-06-24 09:40:37 +04:00
|
|
|
return mOwnerRule->GetDOMRule(aOwnerRule);
|
2002-08-06 09:08:47 +04:00
|
|
|
}
|
2000-05-13 22:10:24 +04:00
|
|
|
|
2002-08-06 09:08:47 +04:00
|
|
|
*aOwnerRule = nsnull;
|
|
|
|
return NS_OK;
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::GetCssRules(nsIDOMCSSRuleList** aCssRules)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
// No doing this on incomplete sheets!
|
|
|
|
PRBool complete;
|
|
|
|
GetComplete(complete);
|
|
|
|
if (!complete) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
//-- Security check: Only scripts whose principal subsumes that of the
|
|
|
|
// style sheet can access rule collections.
|
2007-07-03 22:45:39 +04:00
|
|
|
nsresult rv = SubjectSubsumesInnerPrincipal();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-06-15 03:54:18 +04:00
|
|
|
|
|
|
|
// OK, security check passed, so get the rule collection
|
1999-10-14 04:59:21 +04:00
|
|
|
if (nsnull == mRuleCollection) {
|
2000-04-26 17:58:56 +04:00
|
|
|
mRuleCollection = new CSSRuleListImpl(this);
|
1999-10-14 04:59:21 +04:00
|
|
|
if (nsnull == mRuleCollection) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_ADDREF(mRuleCollection);
|
|
|
|
}
|
1999-06-10 09:29:22 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
*aCssRules = mRuleCollection;
|
|
|
|
NS_ADDREF(mRuleCollection);
|
1999-06-10 09:29:22 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-10 09:29:22 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::InsertRule(const nsAString& aRule,
|
2004-10-06 04:34:06 +04:00
|
|
|
PRUint32 aIndex,
|
|
|
|
PRUint32* aReturn)
|
2008-01-18 08:23:44 +03:00
|
|
|
{
|
|
|
|
//-- Security check: Only scripts whose principal subsumes that of the
|
|
|
|
// style sheet can modify rule collections.
|
|
|
|
nsresult rv = SubjectSubsumesInnerPrincipal();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return InsertRuleInternal(aRule, aIndex, aReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::InsertRuleInternal(const nsAString& aRule,
|
|
|
|
PRUint32 aIndex,
|
|
|
|
PRUint32* aReturn)
|
2008-01-18 08:23:44 +03:00
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
// No doing this if the sheet is not complete!
|
|
|
|
PRBool complete;
|
|
|
|
GetComplete(complete);
|
|
|
|
if (!complete) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
2004-10-06 04:34:06 +04:00
|
|
|
|
|
|
|
if (aRule.IsEmpty()) {
|
|
|
|
// Nothing to do here
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
nsresult result;
|
2001-09-06 17:14:35 +04:00
|
|
|
result = WillDirty();
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
if (aIndex > PRUint32(mInner->mOrderedRules.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(mInner->mOrderedRules.Count()) <= PR_INT32_MAX,
|
|
|
|
"Too many style rules!");
|
|
|
|
|
2004-01-14 02:14:49 +03:00
|
|
|
// Hold strong ref to the CSSLoader in case the document update
|
|
|
|
// kills the document
|
2001-09-05 04:00:18 +04:00
|
|
|
nsCOMPtr<nsICSSLoader> loader;
|
2004-01-14 02:14:49 +03:00
|
|
|
if (mDocument) {
|
2005-04-19 05:27:11 +04:00
|
|
|
loader = mDocument->CSSLoader();
|
2004-01-14 02:14:49 +03:00
|
|
|
NS_ASSERTION(loader, "Document with no CSS loader!");
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
2004-01-14 02:14:49 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsICSSParser> css;
|
2001-09-05 04:00:18 +04:00
|
|
|
if (loader) {
|
|
|
|
result = loader->GetParserFor(this, getter_AddRefs(css));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = NS_NewCSSParser(getter_AddRefs(css));
|
2001-10-19 17:50:30 +04:00
|
|
|
if (css) {
|
|
|
|
css->SetStyleSheet(this);
|
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2001-10-19 17:50:30 +04:00
|
|
|
|
2003-10-16 22:14:25 +04:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
nsCOMArray<nsICSSRule> rules;
|
2007-05-03 05:15:53 +04:00
|
|
|
result = css->ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI,
|
|
|
|
mInner->mPrincipal, rules);
|
2001-09-05 04:00:18 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2001-09-06 17:14:35 +04:00
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
PRInt32 rulecount = rules.Count();
|
2004-10-06 04:34:06 +04:00
|
|
|
if (rulecount == 0) {
|
|
|
|
// Since we know aRule was not an empty string, just throw
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
2001-09-06 17:14:35 +04:00
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
// Hierarchy checking. Just check the first and last rule in the list.
|
|
|
|
|
|
|
|
// check that we're not inserting before a charset rule
|
|
|
|
PRInt32 nextType = nsICSSRule::UNKNOWN_RULE;
|
2005-10-16 00:21:20 +04:00
|
|
|
nsICSSRule* nextRule = mInner->mOrderedRules.SafeObjectAt(aIndex);
|
2001-09-06 17:14:35 +04:00
|
|
|
if (nextRule) {
|
|
|
|
nextRule->GetType(nextType);
|
|
|
|
if (nextType == nsICSSRule::CHARSET_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
// check last rule in list
|
2005-10-16 00:21:20 +04:00
|
|
|
nsICSSRule* lastRule = rules.ObjectAt(rulecount - 1);
|
2001-09-06 17:14:35 +04:00
|
|
|
PRInt32 lastType = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
lastRule->GetType(lastType);
|
|
|
|
|
|
|
|
if (nextType == nsICSSRule::IMPORT_RULE &&
|
|
|
|
lastType != nsICSSRule::CHARSET_RULE &&
|
|
|
|
lastType != nsICSSRule::IMPORT_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nextType == nsICSSRule::NAMESPACE_RULE &&
|
|
|
|
lastType != nsICSSRule::CHARSET_RULE &&
|
|
|
|
lastType != nsICSSRule::IMPORT_RULE &&
|
|
|
|
lastType != nsICSSRule::NAMESPACE_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check first rule in list
|
2005-10-16 00:21:20 +04:00
|
|
|
nsICSSRule* firstRule = rules.ObjectAt(0);
|
2001-09-06 17:14:35 +04:00
|
|
|
PRInt32 firstType = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
firstRule->GetType(firstType);
|
2001-09-05 04:00:18 +04:00
|
|
|
if (aIndex != 0) {
|
2001-09-06 17:14:35 +04:00
|
|
|
if (firstType == nsICSSRule::CHARSET_RULE) { // no inserting charset at nonzero position
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
nsICSSRule* prevRule = mInner->mOrderedRules.SafeObjectAt(aIndex - 1);
|
2001-09-05 04:00:18 +04:00
|
|
|
PRInt32 prevType = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
prevRule->GetType(prevType);
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
if (firstType == nsICSSRule::IMPORT_RULE &&
|
2001-09-05 04:00:18 +04:00
|
|
|
prevType != nsICSSRule::CHARSET_RULE &&
|
|
|
|
prevType != nsICSSRule::IMPORT_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1998-06-05 10:06:50 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
if (firstType == nsICSSRule::NAMESPACE_RULE &&
|
2001-09-05 04:00:18 +04:00
|
|
|
prevType != nsICSSRule::CHARSET_RULE &&
|
|
|
|
prevType != nsICSSRule::IMPORT_RULE &&
|
|
|
|
prevType != nsICSSRule::NAMESPACE_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
1998-06-05 10:06:50 +04:00
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
PRBool insertResult = mInner->mOrderedRules.InsertObjectsAt(rules, aIndex);
|
2004-10-06 04:34:06 +04:00
|
|
|
NS_ENSURE_TRUE(insertResult, NS_ERROR_OUT_OF_MEMORY);
|
2001-10-19 17:50:30 +04:00
|
|
|
DidDirty();
|
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
for (PRInt32 counter = 0; counter < rulecount; counter++) {
|
|
|
|
nsICSSRule* cssRule = rules.ObjectAt(counter);
|
2001-09-06 17:14:35 +04:00
|
|
|
cssRule->SetStyleSheet(this);
|
|
|
|
|
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
cssRule->GetType(type);
|
|
|
|
if (type == nsICSSRule::NAMESPACE_RULE) {
|
2005-02-18 22:18:37 +03:00
|
|
|
if (!mInner->mNameSpaceMap) {
|
2005-02-19 03:10:38 +03:00
|
|
|
mInner->mNameSpaceMap = nsXMLNameSpaceMap::Create();
|
2005-02-18 22:18:37 +03:00
|
|
|
NS_ENSURE_TRUE(mInner->mNameSpaceMap, NS_ERROR_OUT_OF_MEMORY);
|
2001-09-06 17:14:35 +04:00
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
nsCOMPtr<nsICSSNameSpaceRule> nameSpaceRule(do_QueryInterface(cssRule));
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
nsCOMPtr<nsIAtom> prefix;
|
|
|
|
nsAutoString urlSpec;
|
|
|
|
nameSpaceRule->GetPrefix(*getter_AddRefs(prefix));
|
|
|
|
nameSpaceRule->GetURLSpec(urlSpec);
|
2005-02-18 22:18:37 +03:00
|
|
|
|
|
|
|
mInner->mNameSpaceMap->AddPrefix(prefix, urlSpec);
|
2001-09-06 17:14:35 +04:00
|
|
|
}
|
2002-08-06 09:08:47 +04:00
|
|
|
|
|
|
|
// We don't notify immediately for @import rules, but rather when
|
|
|
|
// the sheet the rule is importing is loaded
|
|
|
|
PRBool notify = PR_TRUE;
|
|
|
|
if (type == nsICSSRule::IMPORT_RULE) {
|
|
|
|
nsCOMPtr<nsIDOMCSSImportRule> importRule(do_QueryInterface(cssRule));
|
|
|
|
NS_ASSERTION(importRule, "Rule which has type IMPORT_RULE and does not implement nsIDOMCSSImportRule!");
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleSheet> childSheet;
|
|
|
|
importRule->GetStyleSheet(getter_AddRefs(childSheet));
|
|
|
|
if (!childSheet) {
|
|
|
|
notify = PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (mDocument && notify) {
|
2003-10-22 10:09:48 +04:00
|
|
|
mDocument->StyleRuleAdded(this, cssRule);
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
}
|
2001-09-06 17:14:35 +04:00
|
|
|
|
2001-09-28 05:38:36 +04:00
|
|
|
if (loader) {
|
|
|
|
loader->RecycleParser(css);
|
|
|
|
}
|
2001-09-06 17:14:35 +04:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
*aReturn = aIndex;
|
|
|
|
return NS_OK;
|
1998-06-05 10:06:50 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::DeleteRule(PRUint32 aIndex)
|
1998-06-05 10:06:50 +04:00
|
|
|
{
|
2001-09-05 04:00:18 +04:00
|
|
|
nsresult result = NS_ERROR_DOM_INDEX_SIZE_ERR;
|
2002-12-03 08:48:14 +03:00
|
|
|
// No doing this if the sheet is not complete!
|
|
|
|
PRBool complete;
|
|
|
|
GetComplete(complete);
|
|
|
|
if (!complete) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
1998-06-05 10:06:50 +04:00
|
|
|
|
2007-07-03 22:45:39 +04:00
|
|
|
//-- Security check: Only scripts whose principal subsumes that of the
|
|
|
|
// style sheet can modify rule collections.
|
|
|
|
nsresult rv = SubjectSubsumesInnerPrincipal();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
// XXX TBI: handle @rule types
|
2007-05-01 23:26:15 +04:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
|
2003-10-16 22:14:25 +04:00
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
result = WillDirty();
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
if (aIndex >= PRUint32(mInner->mOrderedRules.Count()))
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
1999-10-14 04:59:21 +04:00
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
NS_ASSERTION(PRUint32(mInner->mOrderedRules.Count()) <= PR_INT32_MAX,
|
|
|
|
"Too many style rules!");
|
2005-10-16 00:21:20 +04:00
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
// Hold a strong ref to the rule so it doesn't die when we RemoveObjectAt
|
|
|
|
nsCOMPtr<nsICSSRule> rule = mInner->mOrderedRules.ObjectAt(aIndex);
|
|
|
|
if (rule) {
|
|
|
|
mInner->mOrderedRules.RemoveObjectAt(aIndex);
|
|
|
|
rule->SetStyleSheet(nsnull);
|
|
|
|
DidDirty();
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
if (mDocument) {
|
|
|
|
mDocument->StyleRuleRemoved(this, rule);
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
1998-06-05 10:06:50 +04:00
|
|
|
}
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
1998-06-05 10:06:50 +04:00
|
|
|
return result;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::DeleteRuleFromGroup(nsICSSGroupRule* aGroup, PRUint32 aIndex)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aGroup);
|
2007-05-01 23:26:15 +04:00
|
|
|
NS_ASSERTION(mInner->mComplete, "No deleting from an incomplete sheet!");
|
2001-09-05 04:00:18 +04:00
|
|
|
nsresult result;
|
|
|
|
nsCOMPtr<nsICSSRule> rule;
|
|
|
|
result = aGroup->GetStyleRuleAt(aIndex, *getter_AddRefs(rule));
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
// check that the rule actually belongs to this sheet!
|
2003-06-24 09:40:37 +04:00
|
|
|
nsCOMPtr<nsIStyleSheet> ruleSheet;
|
|
|
|
rule->GetStyleSheet(*getter_AddRefs(ruleSheet));
|
|
|
|
if (this != ruleSheet) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2003-10-16 22:14:25 +04:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
result = WillDirty();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
result = aGroup->DeleteStyleRuleAt(aIndex);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
rule->SetStyleSheet(nsnull);
|
|
|
|
|
|
|
|
DidDirty();
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
if (mDocument) {
|
2003-10-22 10:09:48 +04:00
|
|
|
mDocument->StyleRuleRemoved(this, rule);
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-10-06 04:34:06 +04:00
|
|
|
nsCSSStyleSheet::InsertRuleIntoGroup(const nsAString & aRule,
|
|
|
|
nsICSSGroupRule* aGroup,
|
|
|
|
PRUint32 aIndex,
|
|
|
|
PRUint32* _retval)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
nsresult result;
|
2007-05-01 23:26:15 +04:00
|
|
|
NS_ASSERTION(mInner->mComplete, "No inserting into an incomplete sheet!");
|
2001-09-05 04:00:18 +04:00
|
|
|
// check that the group actually belongs to this sheet!
|
2003-06-24 09:40:37 +04:00
|
|
|
nsCOMPtr<nsIStyleSheet> groupSheet;
|
|
|
|
aGroup->GetStyleSheet(*getter_AddRefs(groupSheet));
|
|
|
|
if (this != groupSheet) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2004-10-06 04:34:06 +04:00
|
|
|
if (aRule.IsEmpty()) {
|
|
|
|
// Nothing to do here
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-01-14 02:14:49 +03:00
|
|
|
// Hold strong ref to the CSSLoader in case the document update
|
|
|
|
// kills the document
|
2001-09-05 04:00:18 +04:00
|
|
|
nsCOMPtr<nsICSSLoader> loader;
|
2004-01-14 02:14:49 +03:00
|
|
|
if (mDocument) {
|
2005-04-19 05:27:11 +04:00
|
|
|
loader = mDocument->CSSLoader();
|
2004-01-14 02:14:49 +03:00
|
|
|
NS_ASSERTION(loader, "Document with no CSS loader!");
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
2001-10-19 17:50:30 +04:00
|
|
|
|
2004-01-14 02:14:49 +03:00
|
|
|
nsCOMPtr<nsICSSParser> css;
|
2001-09-05 04:00:18 +04:00
|
|
|
if (loader) {
|
|
|
|
result = loader->GetParserFor(this, getter_AddRefs(css));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
result = NS_NewCSSParser(getter_AddRefs(css));
|
2001-10-19 17:50:30 +04:00
|
|
|
if (css) {
|
|
|
|
css->SetStyleSheet(this);
|
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
2003-10-16 22:14:25 +04:00
|
|
|
// parse and grab the rule
|
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
|
|
|
result = WillDirty();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
nsCOMArray<nsICSSRule> rules;
|
2007-05-03 05:15:53 +04:00
|
|
|
result = css->ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI,
|
|
|
|
mInner->mPrincipal, rules);
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
PRInt32 rulecount = rules.Count();
|
2004-10-06 04:34:06 +04:00
|
|
|
if (rulecount == 0) {
|
|
|
|
// Since we know aRule was not an empty string, just throw
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
PRInt32 counter;
|
|
|
|
nsICSSRule* rule;
|
2001-09-06 17:14:35 +04:00
|
|
|
for (counter = 0; counter < rulecount; counter++) {
|
|
|
|
// Only rulesets are allowed in a group as of CSS2
|
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
2005-10-16 00:21:20 +04:00
|
|
|
rule = rules.ObjectAt(counter);
|
2001-09-06 17:14:35 +04:00
|
|
|
rule->GetType(type);
|
|
|
|
if (type != nsICSSRule::STYLE_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
result = aGroup->InsertStyleRulesAt(aIndex, rules);
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
DidDirty();
|
2001-09-06 17:14:35 +04:00
|
|
|
for (counter = 0; counter < rulecount; counter++) {
|
2005-10-16 00:21:20 +04:00
|
|
|
rule = rules.ObjectAt(counter);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
if (mDocument) {
|
2003-10-22 10:09:48 +04:00
|
|
|
mDocument->StyleRuleAdded(this, rule);
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
2001-09-06 17:14:35 +04:00
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2001-09-28 05:38:36 +04:00
|
|
|
if (loader) {
|
|
|
|
loader->RecycleParser(css);
|
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
*_retval = aIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-06-18 05:59:57 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet::ReplaceRuleInGroup(nsICSSGroupRule* aGroup,
|
2003-06-18 05:59:57 +04:00
|
|
|
nsICSSRule* aOld, nsICSSRule* aNew)
|
|
|
|
{
|
|
|
|
nsresult result;
|
2007-05-01 23:26:15 +04:00
|
|
|
NS_PRECONDITION(mInner->mComplete, "No replacing in an incomplete sheet!");
|
2003-06-18 05:59:57 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
2003-06-24 09:40:37 +04:00
|
|
|
nsCOMPtr<nsIStyleSheet> groupSheet;
|
|
|
|
aGroup->GetStyleSheet(*getter_AddRefs(groupSheet));
|
2003-06-18 05:59:57 +04:00
|
|
|
NS_ASSERTION(this == groupSheet, "group doesn't belong to this sheet");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
result = WillDirty();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
result = aGroup->ReplaceStyleRule(aOld, aNew);
|
|
|
|
DidDirty();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-08-06 09:08:47 +04:00
|
|
|
// nsICSSLoaderObserver implementation
|
|
|
|
NS_IMETHODIMP
|
2005-09-12 22:41:15 +04:00
|
|
|
nsCSSStyleSheet::StyleSheetLoaded(nsICSSStyleSheet* aSheet,
|
|
|
|
PRBool aWasAlternate,
|
|
|
|
nsresult aStatus)
|
2002-08-06 09:08:47 +04:00
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
nsCOMPtr<nsIStyleSheet> styleSheet(do_QueryInterface(aSheet));
|
|
|
|
NS_ASSERTION(styleSheet, "Sheet not implementing nsIStyleSheet!\n");
|
|
|
|
nsCOMPtr<nsIStyleSheet> parentSheet;
|
|
|
|
aSheet->GetParentSheet(*getter_AddRefs(parentSheet));
|
|
|
|
nsCOMPtr<nsIStyleSheet> thisSheet;
|
|
|
|
QueryInterface(NS_GET_IID(nsIStyleSheet), getter_AddRefs(thisSheet));
|
|
|
|
NS_ASSERTION(thisSheet == parentSheet, "We are being notified of a sheet load for a sheet that is not our child!\n");
|
|
|
|
#endif
|
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
if (mDocument && NS_SUCCEEDED(aStatus)) {
|
2003-06-24 09:40:37 +04:00
|
|
|
nsCOMPtr<nsICSSImportRule> ownerRule;
|
|
|
|
aSheet->GetOwnerRule(getter_AddRefs(ownerRule));
|
2002-08-06 09:08:47 +04:00
|
|
|
|
2003-10-16 22:14:25 +04:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
|
2002-08-06 09:08:47 +04:00
|
|
|
|
2003-06-24 09:40:37 +04:00
|
|
|
// XXXldb @import rules shouldn't even implement nsIStyleRule (but
|
|
|
|
// they do)!
|
2002-08-06 09:08:47 +04:00
|
|
|
nsCOMPtr<nsIStyleRule> styleRule(do_QueryInterface(ownerRule));
|
|
|
|
|
2003-10-22 10:09:48 +04:00
|
|
|
mDocument->StyleRuleAdded(this, styleRule);
|
2002-08-06 09:08:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-05 18:08:41 +03:00
|
|
|
nsresult
|
|
|
|
NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
2007-05-01 23:26:15 +04:00
|
|
|
*aInstancePtrResult = nsnull;
|
2004-08-04 07:27:28 +04:00
|
|
|
nsCSSStyleSheet *it = new nsCSSStyleSheet();
|
1999-10-14 04:59:21 +04:00
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
if (!it) {
|
1999-10-14 04:59:21 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_ADDREF(it);
|
2007-05-01 23:26:15 +04:00
|
|
|
|
|
|
|
if (!it->mInner || !it->mInner->mPrincipal) {
|
|
|
|
NS_RELEASE(it);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
*aInstancePtrResult = it;
|
1998-10-06 05:39:33 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|