2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
// vim:cindent:tabstop=2:expandtab:shiftwidth=2:
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
* L. David Baron <dbaron@dbaron.org>
|
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
|
|
|
* Daniel Glazman <glazman@netscape.com>
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* 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"),
|
|
|
|
* 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
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* 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
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
/* representation of a CSS style sheet */
|
|
|
|
|
|
|
|
#include "nsCSSStyleSheet.h"
|
|
|
|
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsCSSRuleProcessor.h"
|
|
|
|
#include "nsICSSStyleRule.h"
|
|
|
|
#include "nsICSSNameSpaceRule.h"
|
|
|
|
#include "nsICSSGroupRule.h"
|
|
|
|
#include "nsICSSImportRule.h"
|
|
|
|
#include "nsIMediaList.h"
|
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsString.h"
|
2009-02-03 06:42:18 -08:00
|
|
|
#include "nsTArray.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMStyleSheetList.h"
|
|
|
|
#include "nsIDOMCSSStyleSheet.h"
|
|
|
|
#include "nsIDOMCSSRule.h"
|
|
|
|
#include "nsIDOMCSSImportRule.h"
|
2008-10-22 07:31:14 -07:00
|
|
|
#include "nsICSSRuleList.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDOMMediaList.h"
|
|
|
|
#include "nsIDOMNode.h"
|
|
|
|
#include "nsDOMError.h"
|
2010-03-02 12:59:32 -08:00
|
|
|
#include "nsCSSParser.h"
|
2010-03-02 13:00:53 -08:00
|
|
|
#include "nsCSSLoader.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsICSSLoaderObserver.h"
|
|
|
|
#include "nsINameSpaceManager.h"
|
|
|
|
#include "nsXMLNameSpaceMap.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsContentUtils.h"
|
|
|
|
#include "nsIJSContextStack.h"
|
|
|
|
#include "nsIScriptSecurityManager.h"
|
2008-04-11 10:29:06 -07:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2008-07-26 09:14:48 -07:00
|
|
|
#include "nsCSSDeclaration.h"
|
|
|
|
#include "nsRuleNode.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-03-02 13:00:53 -08:00
|
|
|
namespace css = mozilla::css;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// -------------------------------
|
|
|
|
// Style Rule List for the DOM
|
|
|
|
//
|
2008-10-22 07:31:14 -07:00
|
|
|
class CSSRuleListImpl : public nsICSSRuleList
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
CSSRuleListImpl(nsCSSStyleSheet *aStyleSheet);
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIDOMCSSRuleList interface
|
|
|
|
NS_IMETHOD GetLength(PRUint32* aLength);
|
|
|
|
NS_IMETHOD Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn);
|
|
|
|
|
2008-10-22 07:31:14 -07:00
|
|
|
virtual nsIDOMCSSRule* GetItemAt(PRUint32 aIndex, nsresult* aResult);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
void DropReference() { mStyleSheet = nsnull; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~CSSRuleListImpl();
|
|
|
|
|
|
|
|
nsCSSStyleSheet* mStyleSheet;
|
|
|
|
public:
|
|
|
|
PRBool mRulesAccessed;
|
|
|
|
};
|
|
|
|
|
|
|
|
CSSRuleListImpl::CSSRuleListImpl(nsCSSStyleSheet *aStyleSheet)
|
|
|
|
{
|
|
|
|
// Not reference counted to avoid circular references.
|
|
|
|
// The style sheet will tell us when its going away.
|
|
|
|
mStyleSheet = aStyleSheet;
|
|
|
|
mRulesAccessed = PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSRuleListImpl::~CSSRuleListImpl()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
DOMCI_DATA(CSSRuleList, CSSRuleListImpl)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// QueryInterface implementation for CSSRuleList
|
|
|
|
NS_INTERFACE_MAP_BEGIN(CSSRuleListImpl)
|
2008-10-22 07:31:14 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSRuleList)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRuleList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSRuleList)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(CSSRuleListImpl)
|
|
|
|
NS_IMPL_RELEASE(CSSRuleListImpl)
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSRuleListImpl::GetLength(PRUint32* aLength)
|
|
|
|
{
|
|
|
|
if (nsnull != mStyleSheet) {
|
|
|
|
PRInt32 count;
|
|
|
|
mStyleSheet->StyleRuleCount(count);
|
|
|
|
*aLength = (PRUint32)count;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*aLength = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-22 07:31:14 -07:00
|
|
|
nsIDOMCSSRule*
|
|
|
|
CSSRuleListImpl::GetItemAt(PRUint32 aIndex, nsresult* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsresult result = NS_OK;
|
|
|
|
|
|
|
|
if (mStyleSheet) {
|
2009-12-31 07:56:33 -08:00
|
|
|
// ensure rules have correct parent
|
|
|
|
if (mStyleSheet->EnsureUniqueInner() !=
|
|
|
|
nsCSSStyleSheet::eUniqueInner_CloneFailed) {
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCOMPtr<nsICSSRule> rule;
|
|
|
|
|
|
|
|
result = mStyleSheet->GetStyleRuleAt(aIndex, *getter_AddRefs(rule));
|
|
|
|
if (rule) {
|
|
|
|
mRulesAccessed = PR_TRUE; // signal to never share rules again
|
2008-10-22 07:31:14 -07:00
|
|
|
return rule->GetDOMRuleWeak(aResult);
|
|
|
|
}
|
|
|
|
if (result == NS_ERROR_ILLEGAL_VALUE) {
|
2007-03-22 10:30:00 -07:00
|
|
|
result = NS_OK; // per spec: "Return Value ... null if ... not a valid index."
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2008-10-22 07:31:14 -07:00
|
|
|
|
|
|
|
*aResult = result;
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSRuleListImpl::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIDOMCSSRule* rule = GetItemAt(aIndex, &rv);
|
|
|
|
if (!rule) {
|
|
|
|
*aReturn = nsnull;
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(rule, aReturn);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-07-26 09:14:48 -07: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,
|
2008-09-06 07:04:28 -07:00
|
|
|
// unless the value is an integer 0 or a zero length.
|
2008-07-26 09:14:48 -07:00
|
|
|
if (required.GetUnit() == eCSSUnit_Null) {
|
2008-09-06 07:04:28 -07:00
|
|
|
if (actual.GetUnit() == eCSSUnit_Integer)
|
|
|
|
return actual.GetIntValue() != 0;
|
|
|
|
if (actual.IsLengthUnit())
|
|
|
|
return actual.GetFloatValue() != 0;
|
|
|
|
return PR_TRUE;
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
2008-09-06 07:04:28 -07:00
|
|
|
case nsMediaFeature::eBoolInteger:
|
2008-07-26 09:14:48 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION(actual.GetUnit() == eCSSUnit_Integer,
|
|
|
|
"bad actual value");
|
|
|
|
NS_ASSERTION(required.GetUnit() == eCSSUnit_Integer,
|
|
|
|
"bad required value");
|
2008-09-06 07:04:28 -07:00
|
|
|
NS_ASSERTION(mFeature->mValueType != nsMediaFeature::eBoolInteger ||
|
|
|
|
actual.GetIntValue() == 0 || actual.GetIntValue() == 1,
|
|
|
|
"bad actual bool integer value");
|
|
|
|
NS_ASSERTION(mFeature->mValueType != nsMediaFeature::eBoolInteger ||
|
|
|
|
required.GetIntValue() == 0 || required.GetIntValue() == 1,
|
|
|
|
"bad required bool integer value");
|
2008-07-26 09:14:48 -07:00
|
|
|
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 09:14:48 -07: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;
|
2009-10-15 17:23:18 -07:00
|
|
|
nsresult rv =
|
|
|
|
(entry->mFeature->mGetter)(aPresContext, entry->mFeature, actual);
|
2008-07-26 09:14:48 -07:00
|
|
|
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 09:14:48 -07:00
|
|
|
void
|
|
|
|
nsMediaQuery::AppendToString(nsAString& aString) const
|
|
|
|
{
|
|
|
|
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 ");
|
|
|
|
}
|
2010-03-08 07:45:00 -08:00
|
|
|
aString.Append(nsDependentAtomString(mMediaType));
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2010-03-08 07:45:00 -08:00
|
|
|
aString.Append(nsDependentAtomString(*feature->mName));
|
2008-07-26 09:14:48 -07:00
|
|
|
|
|
|
|
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:
|
2008-09-06 07:04:28 -07:00
|
|
|
case nsMediaFeature::eBoolInteger:
|
2008-07-26 09:14:48 -07:00
|
|
|
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:
|
2010-03-08 07:45:00 -08:00
|
|
|
{
|
|
|
|
nsAutoString buffer;
|
|
|
|
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");
|
|
|
|
}
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsMediaFeature::eEnumerated:
|
|
|
|
NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Enumerated,
|
|
|
|
"bad unit");
|
|
|
|
AppendASCIItoUTF16(
|
|
|
|
nsCSSProps::ValueToKeyword(expr.mValue.GetIntValue(),
|
2009-10-15 17:23:18 -07:00
|
|
|
feature->mData.mKeywordTable),
|
2008-07-26 09:14:48 -07:00
|
|
|
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 09:14:48 -07:00
|
|
|
nsMediaQuery::Matches(nsPresContext* aPresContext,
|
|
|
|
nsMediaQueryResultCacheKey& aKey) const
|
2008-07-26 09:14:48 -07: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;
|
2009-10-15 17:23:18 -07:00
|
|
|
nsresult rv =
|
|
|
|
(expr.mFeature->mGetter)(aPresContext, expr.mFeature, actual);
|
2008-07-26 09:14:48 -07:00
|
|
|
NS_ENSURE_SUCCESS(rv, PR_FALSE); // any better ideas?
|
2008-07-26 09:14:48 -07:00
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
match = expr.Matches(aPresContext, actual);
|
2008-07-26 09:14:48 -07:00
|
|
|
aKey.AddExpression(&expr, match);
|
2008-07-26 09:14:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return match == !mNegated;
|
|
|
|
}
|
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
DOMCI_DATA(MediaList, nsMediaList)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsMediaList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMediaList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MediaList)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsMediaList)
|
|
|
|
NS_IMPL_RELEASE(nsMediaList)
|
|
|
|
|
|
|
|
|
|
|
|
nsMediaList::nsMediaList()
|
2008-07-26 09:14:48 -07:00
|
|
|
: mIsEmpty(PR_TRUE)
|
|
|
|
, mStyleSheet(nsnull)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMediaList::~nsMediaList()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMediaList::GetText(nsAString& aMediaText)
|
|
|
|
{
|
|
|
|
aMediaText.Truncate();
|
|
|
|
|
2008-07-26 09:14:48 -07: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);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (i + 1 < i_end) {
|
|
|
|
aMediaText.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXXbz this is so ill-defined in the spec, it's not clear quite what
|
|
|
|
// it should be doing....
|
|
|
|
nsresult
|
|
|
|
nsMediaList::SetText(const nsAString& aMediaText)
|
|
|
|
{
|
2010-03-02 12:59:32 -08:00
|
|
|
nsCSSParser parser;
|
|
|
|
NS_ENSURE_TRUE(parser, NS_ERROR_OUT_OF_MEMORY);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
PRBool htmlMode = PR_FALSE;
|
|
|
|
nsCOMPtr<nsIDOMStyleSheet> domSheet =
|
2007-07-08 00:08:04 -07:00
|
|
|
do_QueryInterface(static_cast<nsICSSStyleSheet*>(mStyleSheet));
|
2007-03-22 10:30:00 -07:00
|
|
|
if (domSheet) {
|
|
|
|
nsCOMPtr<nsIDOMNode> node;
|
|
|
|
domSheet->GetOwnerNode(getter_AddRefs(node));
|
|
|
|
htmlMode = !!node;
|
|
|
|
}
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
return parser.ParseMediaList(nsString(aMediaText), nsnull, 0,
|
|
|
|
this, htmlMode);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
PRBool
|
2008-07-26 09:14:48 -07:00
|
|
|
nsMediaList::Matches(nsPresContext* aPresContext,
|
|
|
|
nsMediaQueryResultCacheKey& aKey)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-07-26 09:14:48 -07:00
|
|
|
for (PRInt32 i = 0, i_end = mArray.Length(); i < i_end; ++i) {
|
2008-07-26 09:14:48 -07:00
|
|
|
if (mArray[i]->Matches(aPresContext, aKey)) {
|
2008-07-26 09:14:48 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return mIsEmpty;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMediaList::SetStyleSheet(nsICSSStyleSheet *aSheet)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(aSheet == mStyleSheet || !aSheet || !mStyleSheet,
|
|
|
|
"multiple style sheets competing for one media list");
|
2007-07-08 00:08:04 -07:00
|
|
|
mStyleSheet = static_cast<nsCSSStyleSheet*>(aSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMediaList::Clone(nsMediaList** aResult)
|
|
|
|
{
|
|
|
|
nsRefPtr<nsMediaList> result = new nsMediaList();
|
2008-07-26 09:14:48 -07:00
|
|
|
if (!result || !result->mArray.AppendElements(mArray.Length()))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2008-07-26 09:14:48 -07: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;
|
|
|
|
}
|
|
|
|
}
|
2009-07-17 20:47:38 -07:00
|
|
|
result->mIsEmpty = mIsEmpty;
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ADDREF(*aResult = result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMediaList::GetMediaText(nsAString& aMediaText)
|
|
|
|
{
|
|
|
|
return GetText(aMediaText);
|
|
|
|
}
|
|
|
|
|
|
|
|
// "sheet" should be an nsCSSStyleSheet and "doc" should be an
|
|
|
|
// 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) { \
|
|
|
|
doc->StyleRuleChanged(sheet, nsnull, nsnull); \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMediaList::SetMediaText(const nsAString& aMediaText)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
|
|
|
|
BEGIN_MEDIA_CHANGE(mStyleSheet, doc)
|
|
|
|
|
|
|
|
rv = SetText(aMediaText);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
END_MEDIA_CHANGE(mStyleSheet, doc)
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMediaList::GetLength(PRUint32* aLength)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLength);
|
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
*aLength = mArray.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMediaList::Item(PRUint32 aIndex, nsAString& aReturn)
|
|
|
|
{
|
|
|
|
PRInt32 index = aIndex;
|
|
|
|
if (0 <= index && index < Count()) {
|
2008-07-26 09:14:48 -07:00
|
|
|
nsMediaQuery* query = mArray[index];
|
|
|
|
NS_ENSURE_TRUE(query, NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
aReturn.Truncate();
|
|
|
|
query->AppendToString(aReturn);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
SetDOMStringToNull(aReturn);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMediaList::DeleteMedium(const nsAString& aOldMedium)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
|
|
|
|
BEGIN_MEDIA_CHANGE(mStyleSheet, doc)
|
|
|
|
|
|
|
|
rv = Delete(aOldMedium);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
END_MEDIA_CHANGE(mStyleSheet, doc)
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsMediaList::AppendMedium(const nsAString& aNewMedium)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
|
|
|
|
BEGIN_MEDIA_CHANGE(mStyleSheet, doc)
|
|
|
|
|
|
|
|
rv = Append(aNewMedium);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
END_MEDIA_CHANGE(mStyleSheet, doc)
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMediaList::Delete(const nsAString& aOldMedium)
|
|
|
|
{
|
|
|
|
if (aOldMedium.IsEmpty())
|
|
|
|
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
for (PRInt32 i = 0, i_end = mArray.Length(); i < i_end; ++i) {
|
|
|
|
nsMediaQuery* query = mArray[i];
|
|
|
|
NS_ENSURE_TRUE(query, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
nsAutoString buf;
|
|
|
|
query->AppendToString(buf);
|
|
|
|
if (buf == aOldMedium) {
|
|
|
|
mArray.RemoveElementAt(i);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsMediaList::Append(const nsAString& aNewMedium)
|
|
|
|
{
|
|
|
|
if (aNewMedium.IsEmpty())
|
|
|
|
return NS_ERROR_DOM_NOT_FOUND_ERR;
|
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
Delete(aNewMedium);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2008-07-26 09:14:48 -07: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;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-07-26 09:14:48 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
ok =
|
|
|
|
#endif
|
|
|
|
mArray.SwapElements(buf);
|
|
|
|
NS_ASSERTION(ok, "SwapElements should never fail when neither array "
|
|
|
|
"is an auto array");
|
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------
|
|
|
|
// CSS Style Sheet Inner Data Container
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2008-09-09 11:08:11 -07:00
|
|
|
nsCSSStyleSheetInner::nsCSSStyleSheetInner(nsICSSStyleSheet* aPrimarySheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mSheets(),
|
|
|
|
mComplete(PR_FALSE)
|
2007-05-01 12:26:15 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
, mPrincipalSet(PR_FALSE)
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsCSSStyleSheetInner);
|
2008-09-09 11:08:11 -07:00
|
|
|
mSheets.AppendElement(aPrimarySheet);
|
2007-05-01 12:26:15 -07:00
|
|
|
|
|
|
|
mPrincipal = do_CreateInstance("@mozilla.org/nullprincipal;1");
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2008-09-09 11:08:11 -07:00
|
|
|
static PRBool SetStyleSheetReference(nsICSSRule* aRule, void* aSheet)
|
|
|
|
{
|
|
|
|
if (aRule) {
|
|
|
|
aRule->SetStyleSheet((nsICSSStyleSheet*)aSheet);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static PRBool
|
|
|
|
CloneRuleInto(nsICSSRule* aRule, void* aArray)
|
|
|
|
{
|
|
|
|
nsICSSRule* clone = nsnull;
|
|
|
|
aRule->Clone(clone);
|
|
|
|
if (clone) {
|
2007-07-08 00:08:04 -07:00
|
|
|
static_cast<nsCOMArray<nsICSSRule>*>(aArray)->AppendObject(clone);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_RELEASE(clone);
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2008-09-09 11:08:11 -07:00
|
|
|
struct ChildSheetListBuilder {
|
|
|
|
nsRefPtr<nsCSSStyleSheet>* sheetSlot;
|
|
|
|
nsCSSStyleSheet* parent;
|
|
|
|
|
|
|
|
void SetParentLinks(nsCSSStyleSheet* aSheet) {
|
|
|
|
aSheet->mParent = parent;
|
|
|
|
aSheet->SetOwningDocument(parent->mDocument);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-05-26 12:40:49 -07:00
|
|
|
PRBool
|
|
|
|
nsCSSStyleSheet::RebuildChildList(nsICSSRule* aRule, void* aBuilder)
|
2008-09-09 11:08:11 -07:00
|
|
|
{
|
|
|
|
PRInt32 type;
|
|
|
|
aRule->GetType(type);
|
2009-05-28 15:16:31 -07:00
|
|
|
if (type < nsICSSRule::IMPORT_RULE) {
|
|
|
|
// Keep going till we get to the import rules.
|
2008-09-09 11:08:11 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2009-05-28 15:16:31 -07:00
|
|
|
if (type != nsICSSRule::IMPORT_RULE) {
|
|
|
|
// We're past all the import rules; stop the enumeration.
|
2008-09-09 11:08:11 -07:00
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ChildSheetListBuilder* builder =
|
|
|
|
static_cast<ChildSheetListBuilder*>(aBuilder);
|
|
|
|
|
|
|
|
// XXXbz We really need to decomtaminate all this stuff. Is there a reason
|
|
|
|
// that I can't just QI to nsICSSImportRule and get an nsCSSStyleSheet
|
|
|
|
// directly from it?
|
|
|
|
nsCOMPtr<nsIDOMCSSImportRule> importRule(do_QueryInterface(aRule));
|
|
|
|
NS_ASSERTION(importRule, "GetType lied");
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMCSSStyleSheet> childSheet;
|
|
|
|
importRule->GetStyleSheet(getter_AddRefs(childSheet));
|
|
|
|
|
|
|
|
// Have to do this QI to be safe, since XPConnect can fake
|
|
|
|
// nsIDOMCSSStyleSheets
|
|
|
|
nsCOMPtr<nsICSSStyleSheet> cssSheet = do_QueryInterface(childSheet);
|
|
|
|
if (!cssSheet) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*builder->sheetSlot) = static_cast<nsCSSStyleSheet*>(cssSheet.get());
|
|
|
|
builder->SetParentLinks(*builder->sheetSlot);
|
2009-05-26 12:40:49 -07:00
|
|
|
builder->sheetSlot = &(*builder->sheetSlot)->mNext;
|
2008-09-09 11:08:11 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSStyleSheetInner::nsCSSStyleSheetInner(nsCSSStyleSheetInner& aCopy,
|
2008-09-09 11:08:11 -07:00
|
|
|
nsCSSStyleSheet* aPrimarySheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
: mSheets(),
|
|
|
|
mSheetURI(aCopy.mSheetURI),
|
2008-01-21 20:26:01 -08:00
|
|
|
mOriginalSheetURI(aCopy.mOriginalSheetURI),
|
2007-03-22 10:30:00 -07:00
|
|
|
mBaseURI(aCopy.mBaseURI),
|
2007-05-01 12:26:15 -07:00
|
|
|
mPrincipal(aCopy.mPrincipal),
|
2007-03-22 10:30:00 -07:00
|
|
|
mComplete(aCopy.mComplete)
|
2007-05-01 12:26:15 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
, mPrincipalSet(aCopy.mPrincipalSet)
|
|
|
|
#endif
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
MOZ_COUNT_CTOR(nsCSSStyleSheetInner);
|
2009-02-05 01:38:51 -08:00
|
|
|
AddSheet(aPrimarySheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
aCopy.mOrderedRules.EnumerateForwards(CloneRuleInto, &mOrderedRules);
|
2008-09-09 11:08:11 -07:00
|
|
|
mOrderedRules.EnumerateForwards(SetStyleSheetReference, aPrimarySheet);
|
|
|
|
|
|
|
|
ChildSheetListBuilder builder = { &mFirstChild, aPrimarySheet };
|
2009-05-26 12:40:49 -07:00
|
|
|
mOrderedRules.EnumerateForwards(nsCSSStyleSheet::RebuildChildList, &builder);
|
2008-09-09 11:08:11 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
RebuildNameSpaces();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSStyleSheetInner::~nsCSSStyleSheetInner()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsCSSStyleSheetInner);
|
|
|
|
mOrderedRules.EnumerateForwards(SetStyleSheetReference, nsnull);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSStyleSheetInner*
|
2008-09-09 11:08:11 -07:00
|
|
|
nsCSSStyleSheetInner::CloneFor(nsCSSStyleSheet* aPrimarySheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 11:08:11 -07:00
|
|
|
return new nsCSSStyleSheetInner(*this, aPrimarySheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-09-09 11:08:11 -07:00
|
|
|
nsCSSStyleSheetInner::AddSheet(nsICSSStyleSheet* aSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2008-09-09 11:08:11 -07:00
|
|
|
mSheets.AppendElement(aSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-09-09 11:08:11 -07:00
|
|
|
nsCSSStyleSheetInner::RemoveSheet(nsICSSStyleSheet* aSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2009-02-03 06:42:18 -08:00
|
|
|
if (1 == mSheets.Length()) {
|
|
|
|
NS_ASSERTION(aSheet == mSheets.ElementAt(0), "bad parent");
|
2007-03-22 10:30:00 -07:00
|
|
|
delete this;
|
|
|
|
return;
|
|
|
|
}
|
2009-02-03 06:42:18 -08:00
|
|
|
if (aSheet == mSheets.ElementAt(0)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mSheets.RemoveElementAt(0);
|
2009-02-03 06:42:18 -08:00
|
|
|
NS_ASSERTION(mSheets.Length(), "no parents");
|
2007-03-22 10:30:00 -07:00
|
|
|
mOrderedRules.EnumerateForwards(SetStyleSheetReference,
|
2009-02-03 06:42:18 -08:00
|
|
|
mSheets.ElementAt(0));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
2008-09-09 11:08:11 -07:00
|
|
|
mSheets.RemoveElement(aSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-15 13:23:21 -07:00
|
|
|
static void
|
|
|
|
AddNamespaceRuleToMap(nsICSSRule* aRule, nsXMLNameSpaceMap* aMap)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
PRInt32 type;
|
|
|
|
aRule->GetType(type);
|
|
|
|
NS_ASSERTION(type == nsICSSRule::NAMESPACE_RULE, "Bogus rule type");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
nsCOMPtr<nsICSSNameSpaceRule> nameSpaceRule = do_QueryInterface(aRule);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIAtom> prefix;
|
|
|
|
nsAutoString urlSpec;
|
|
|
|
nameSpaceRule->GetPrefix(*getter_AddRefs(prefix));
|
|
|
|
nameSpaceRule->GetURLSpec(urlSpec);
|
|
|
|
|
|
|
|
aMap->AddPrefix(prefix, urlSpec);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static PRBool
|
|
|
|
CreateNameSpace(nsICSSRule* aRule, void* aNameSpacePtr)
|
|
|
|
{
|
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
aRule->GetType(type);
|
|
|
|
if (nsICSSRule::NAMESPACE_RULE == type) {
|
2008-10-15 13:23:21 -07:00
|
|
|
AddNamespaceRuleToMap(aRule,
|
|
|
|
static_cast<nsXMLNameSpaceMap*>(aNameSpacePtr));
|
2007-03-22 10:30:00 -07:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
2008-10-15 13:23:21 -07:00
|
|
|
// stop if not namespace, import or charset because namespace can't follow
|
|
|
|
// anything else
|
|
|
|
return (nsICSSRule::CHARSET_RULE == type || nsICSSRule::IMPORT_RULE == type);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSStyleSheetInner::RebuildNameSpaces()
|
|
|
|
{
|
2008-10-15 13:23:21 -07:00
|
|
|
// Just nuke our existing namespace map, if any
|
|
|
|
if (NS_SUCCEEDED(CreateNamespaceMap())) {
|
|
|
|
mOrderedRules.EnumerateForwards(CreateNameSpace, mNameSpaceMap);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-15 13:23:21 -07:00
|
|
|
nsresult
|
|
|
|
nsCSSStyleSheetInner::CreateNamespaceMap()
|
|
|
|
{
|
2009-10-29 18:47:48 -07:00
|
|
|
mNameSpaceMap = nsXMLNameSpaceMap::Create(PR_FALSE);
|
2008-10-15 13:23:21 -07:00
|
|
|
NS_ENSURE_TRUE(mNameSpaceMap, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
// Override the default namespace map behavior for the null prefix to
|
|
|
|
// return the wildcard namespace instead of the null namespace.
|
|
|
|
mNameSpaceMap->AddPrefix(nsnull, kNameSpaceID_Unknown);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// -------------------------------
|
|
|
|
// CSS Style Sheet
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCSSStyleSheet::nsCSSStyleSheet()
|
|
|
|
: nsICSSStyleSheet(),
|
|
|
|
mRefCnt(0),
|
|
|
|
mTitle(),
|
|
|
|
mMedia(nsnull),
|
|
|
|
mParent(nsnull),
|
|
|
|
mOwnerRule(nsnull),
|
|
|
|
mRuleCollection(nsnull),
|
|
|
|
mDocument(nsnull),
|
|
|
|
mOwningNode(nsnull),
|
|
|
|
mDisabled(PR_FALSE),
|
|
|
|
mDirty(PR_FALSE),
|
|
|
|
mRuleProcessors(nsnull)
|
|
|
|
{
|
|
|
|
|
|
|
|
mInner = new nsCSSStyleSheetInner(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSStyleSheet::nsCSSStyleSheet(const nsCSSStyleSheet& aCopy,
|
2007-05-01 12:26:15 -07:00
|
|
|
nsICSSStyleSheet* aParentToUse,
|
|
|
|
nsICSSImportRule* aOwnerRuleToUse,
|
|
|
|
nsIDocument* aDocumentToUse,
|
|
|
|
nsIDOMNode* aOwningNodeToUse)
|
2007-03-22 10:30:00 -07:00
|
|
|
: nsICSSStyleSheet(),
|
|
|
|
mRefCnt(0),
|
|
|
|
mTitle(aCopy.mTitle),
|
|
|
|
mMedia(nsnull),
|
|
|
|
mParent(aParentToUse),
|
|
|
|
mOwnerRule(aOwnerRuleToUse),
|
|
|
|
mRuleCollection(nsnull), // re-created lazily
|
|
|
|
mDocument(aDocumentToUse),
|
|
|
|
mOwningNode(aOwningNodeToUse),
|
|
|
|
mDisabled(aCopy.mDisabled),
|
|
|
|
mDirty(PR_FALSE),
|
|
|
|
mInner(aCopy.mInner),
|
|
|
|
mRuleProcessors(nsnull)
|
|
|
|
{
|
|
|
|
|
|
|
|
mInner->AddSheet(this);
|
|
|
|
|
|
|
|
if (aCopy.mRuleCollection &&
|
|
|
|
aCopy.mRuleCollection->mRulesAccessed) { // CSSOM's been there, force full copy now
|
|
|
|
NS_ASSERTION(mInner->mComplete, "Why have rules been accessed on an incomplete sheet?");
|
2009-12-31 07:56:33 -08:00
|
|
|
// FIXME: handle failure?
|
2007-03-22 10:30:00 -07:00
|
|
|
EnsureUniqueInner();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aCopy.mMedia) {
|
2008-09-09 11:08:11 -07:00
|
|
|
// XXX This is wrong; we should be keeping @import rules and
|
|
|
|
// sheets in sync!
|
2007-03-22 10:30:00 -07:00
|
|
|
aCopy.mMedia->Clone(getter_AddRefs(mMedia));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSStyleSheet::~nsCSSStyleSheet()
|
|
|
|
{
|
2008-09-09 11:08:11 -07:00
|
|
|
for (nsCSSStyleSheet* child = mInner->mFirstChild;
|
|
|
|
child;
|
|
|
|
child = child->mNext) {
|
|
|
|
// XXXbz this is a little bogus; see the XXX comment where we
|
|
|
|
// declare mFirstChild.
|
|
|
|
if (child->mParent == this) {
|
2007-03-22 10:30:00 -07:00
|
|
|
child->mParent = nsnull;
|
|
|
|
child->mDocument = nsnull;
|
2008-09-09 11:08:11 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (nsnull != mRuleCollection) {
|
|
|
|
mRuleCollection->DropReference();
|
|
|
|
NS_RELEASE(mRuleCollection);
|
|
|
|
}
|
|
|
|
if (mMedia) {
|
|
|
|
mMedia->SetStyleSheet(nsnull);
|
|
|
|
mMedia = nsnull;
|
|
|
|
}
|
|
|
|
mInner->RemoveSheet(this);
|
|
|
|
// XXX The document reference is not reference counted and should
|
|
|
|
// not be released. The document will let us know when it is going
|
|
|
|
// away.
|
|
|
|
if (mRuleProcessors) {
|
2009-02-03 06:42:18 -08:00
|
|
|
NS_ASSERTION(mRuleProcessors->Length() == 0, "destructing sheet with rule processor reference");
|
2007-03-22 10:30:00 -07:00
|
|
|
delete mRuleProcessors; // weak refs, should be empty here anyway
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
DOMCI_DATA(CSSStyleSheet, nsCSSStyleSheet)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// QueryInterface implementation for nsCSSStyleSheet
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsCSSStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsICSSStyleSheet)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSStyleSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsCSSStyleSheet)
|
|
|
|
NS_IMPL_RELEASE(nsCSSStyleSheet)
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::AddRuleProcessor(nsCSSRuleProcessor* aProcessor)
|
|
|
|
{
|
|
|
|
if (! mRuleProcessors) {
|
2009-02-03 06:42:18 -08:00
|
|
|
mRuleProcessors = new nsAutoTArray<nsCSSRuleProcessor*, 8>();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (!mRuleProcessors)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
2009-05-18 15:13:12 -07:00
|
|
|
NS_ASSERTION(mRuleProcessors->NoIndex == mRuleProcessors->IndexOf(aProcessor),
|
2007-03-22 10:30:00 -07:00
|
|
|
"processor already registered");
|
|
|
|
mRuleProcessors->AppendElement(aProcessor); // weak ref
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::DropRuleProcessor(nsCSSRuleProcessor* aProcessor)
|
|
|
|
{
|
|
|
|
if (!mRuleProcessors)
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
return mRuleProcessors->RemoveElement(aProcessor)
|
|
|
|
? NS_OK
|
|
|
|
: NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2007-10-23 14:56:41 -07:00
|
|
|
nsCSSStyleSheet::SetURIs(nsIURI* aSheetURI, nsIURI* aOriginalSheetURI,
|
|
|
|
nsIURI* aBaseURI)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aSheetURI && aBaseURI, "null ptr");
|
|
|
|
|
|
|
|
NS_ASSERTION(mInner->mOrderedRules.Count() == 0 && !mInner->mComplete,
|
|
|
|
"Can't call SetURL on sheets that are complete or have rules");
|
|
|
|
|
|
|
|
mInner->mSheetURI = aSheetURI;
|
2007-10-23 14:56:41 -07:00
|
|
|
mInner->mOriginalSheetURI = aOriginalSheetURI;
|
2007-03-22 10:30:00 -07:00
|
|
|
mInner->mBaseURI = aBaseURI;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-05-01 12:26:15 -07: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;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetSheetURI(nsIURI** aSheetURI) const
|
|
|
|
{
|
2007-05-01 12:26:15 -07:00
|
|
|
NS_IF_ADDREF(*aSheetURI = mInner->mSheetURI.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetBaseURI(nsIURI** aBaseURI) const
|
|
|
|
{
|
2007-05-01 12:26:15 -07:00
|
|
|
NS_IF_ADDREF(*aBaseURI = mInner->mBaseURI.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::SetTitle(const nsAString& aTitle)
|
|
|
|
{
|
|
|
|
mTitle = aTitle;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetType(nsString& aType) const
|
|
|
|
{
|
|
|
|
aType.AssignLiteral("text/css");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-07-26 09:14:48 -07:00
|
|
|
PRBool
|
|
|
|
nsCSSStyleSheet::UseForPresentation(nsPresContext* aPresContext,
|
|
|
|
nsMediaQueryResultCacheKey& aKey) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mMedia) {
|
2008-07-26 09:14:48 -07:00
|
|
|
return mMedia->Matches(aPresContext, aKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::SetMedia(nsMediaList* aMedia)
|
|
|
|
{
|
|
|
|
mMedia = aMedia;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
|
|
nsCSSStyleSheet::HasRules() const
|
|
|
|
{
|
|
|
|
PRInt32 count;
|
|
|
|
StyleRuleCount(count);
|
|
|
|
return count != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetApplicable(PRBool& aApplicable) const
|
|
|
|
{
|
2007-05-01 12:26:15 -07:00
|
|
|
aApplicable = !mDisabled && mInner->mComplete;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::SetEnabled(PRBool aEnabled)
|
|
|
|
{
|
|
|
|
// Internal method, so callers must handle BeginUpdate/EndUpdate
|
|
|
|
PRBool oldDisabled = mDisabled;
|
|
|
|
mDisabled = !aEnabled;
|
|
|
|
|
2008-11-25 13:27:54 -08:00
|
|
|
if (mInner->mComplete && oldDisabled != mDisabled) {
|
2007-03-22 10:30:00 -07:00
|
|
|
ClearRuleCascades();
|
|
|
|
|
2008-11-25 13:27:54 -08:00
|
|
|
if (mDocument) {
|
|
|
|
mDocument->SetStyleSheetApplicableState(this, !mDisabled);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetComplete(PRBool& aComplete) const
|
|
|
|
{
|
2007-05-01 12:26:15 -07:00
|
|
|
aComplete = mInner->mComplete;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::SetComplete()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mDirty, "Can't set a dirty sheet complete!");
|
|
|
|
mInner->mComplete = PR_TRUE;
|
|
|
|
if (mDocument && !mDisabled) {
|
|
|
|
// Let the document know
|
|
|
|
mDocument->BeginUpdate(UPDATE_STYLE);
|
|
|
|
mDocument->SetStyleSheetApplicableState(this, PR_TRUE);
|
|
|
|
mDocument->EndUpdate(UPDATE_STYLE);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetParentSheet(nsIStyleSheet*& aParent) const
|
|
|
|
{
|
|
|
|
aParent = mParent;
|
|
|
|
NS_IF_ADDREF(aParent);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetOwningDocument(nsIDocument*& aDocument) const
|
|
|
|
{
|
|
|
|
aDocument = mDocument;
|
|
|
|
NS_IF_ADDREF(aDocument);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::SetOwningDocument(nsIDocument* aDocument)
|
|
|
|
{ // not ref counted
|
|
|
|
mDocument = aDocument;
|
|
|
|
// Now set the same document on all our child sheets....
|
2008-09-09 11:08:11 -07:00
|
|
|
// XXXbz this is a little bogus; see the XXX comment where we
|
|
|
|
// declare mFirstChild.
|
|
|
|
for (nsCSSStyleSheet* child = mInner->mFirstChild;
|
|
|
|
child; child = child->mNext) {
|
|
|
|
if (child->mParent == this) {
|
|
|
|
child->SetOwningDocument(aDocument);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::SetOwningNode(nsIDOMNode* aOwningNode)
|
|
|
|
{ // not ref counted
|
|
|
|
mOwningNode = aOwningNode;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::SetOwnerRule(nsICSSImportRule* aOwnerRule)
|
|
|
|
{ // not ref counted
|
|
|
|
mOwnerRule = aOwnerRule;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetOwnerRule(nsICSSImportRule** aOwnerRule)
|
|
|
|
{
|
|
|
|
*aOwnerRule = mOwnerRule;
|
|
|
|
NS_IF_ADDREF(*aOwnerRule);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::AppendStyleSheet(nsICSSStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(WillDirty())) {
|
|
|
|
nsCSSStyleSheet* sheet = (nsCSSStyleSheet*)aSheet;
|
|
|
|
|
2008-09-09 11:08:11 -07:00
|
|
|
nsRefPtr<nsCSSStyleSheet>* tail = &mInner->mFirstChild;
|
|
|
|
while (*tail) {
|
|
|
|
tail = &(*tail)->mNext;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-09-09 13:16:21 -07:00
|
|
|
*tail = sheet;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// This is not reference counted. Our parent tells us when
|
|
|
|
// it's going away.
|
|
|
|
sheet->mParent = this;
|
|
|
|
sheet->mDocument = mDocument;
|
|
|
|
DidDirty();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::InsertStyleSheetAt(nsICSSStyleSheet* aSheet, PRInt32 aIndex)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aSheet, "null arg");
|
|
|
|
|
|
|
|
nsresult result = WillDirty();
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
nsCSSStyleSheet* sheet = (nsCSSStyleSheet*)aSheet;
|
|
|
|
|
2008-09-09 11:08:11 -07:00
|
|
|
nsRefPtr<nsCSSStyleSheet>* tail = &mInner->mFirstChild;
|
|
|
|
while (*tail && aIndex) {
|
|
|
|
--aIndex;
|
|
|
|
tail = &(*tail)->mNext;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-09-09 11:08:11 -07:00
|
|
|
sheet->mNext = *tail;
|
|
|
|
*tail = sheet;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// This is not reference counted. Our parent tells us when
|
|
|
|
// it's going away.
|
|
|
|
sheet->mParent = this;
|
|
|
|
sheet->mDocument = mDocument;
|
|
|
|
DidDirty();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::PrependStyleRule(nsICSSRule* aRule)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aRule, "null arg");
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(WillDirty())) {
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::AppendStyleRule(nsICSSRule* aRule)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(nsnull != aRule, "null arg");
|
|
|
|
|
|
|
|
if (NS_SUCCEEDED(WillDirty())) {
|
|
|
|
mInner->mOrderedRules.AppendObject(aRule);
|
|
|
|
aRule->SetStyleSheet(this);
|
|
|
|
DidDirty();
|
|
|
|
|
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
aRule->GetType(type);
|
|
|
|
if (nsICSSRule::NAMESPACE_RULE == type) {
|
2008-10-15 13:23:21 -07:00
|
|
|
nsresult rv = RegisterNamespaceRule(aRule);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::ReplaceStyleRule(nsICSSRule* aOld, nsICSSRule* aNew)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mInner->mOrderedRules.Count() != 0, "can't have old rule");
|
2007-05-01 12:26:15 -07:00
|
|
|
NS_PRECONDITION(mInner->mComplete, "No replacing in an incomplete sheet!");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (NS_SUCCEEDED(WillDirty())) {
|
|
|
|
PRInt32 index = mInner->mOrderedRules.IndexOf(aOld);
|
|
|
|
NS_ENSURE_TRUE(index != -1, NS_ERROR_UNEXPECTED);
|
|
|
|
mInner->mOrderedRules.ReplaceObjectAt(aNew, index);
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::StyleRuleCount(PRInt32& aCount) const
|
|
|
|
{
|
2007-05-01 12:26:15 -07:00
|
|
|
aCount = mInner->mOrderedRules.Count();
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetStyleRuleAt(PRInt32 aIndex, nsICSSRule*& aRule) const
|
|
|
|
{
|
|
|
|
// Important: If this function is ever made scriptable, we must add
|
2007-07-03 11:45:39 -07:00
|
|
|
// a security check here. See GetCssRules below for an example.
|
2007-05-01 12:26:15 -07:00
|
|
|
aRule = mInner->mOrderedRules.SafeObjectAt(aIndex);
|
|
|
|
if (aRule) {
|
|
|
|
NS_ADDREF(aRule);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-05-01 12:26:15 -07:00
|
|
|
|
|
|
|
return NS_ERROR_ILLEGAL_VALUE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsXMLNameSpaceMap*
|
|
|
|
nsCSSStyleSheet::GetNameSpaceMap() const
|
|
|
|
{
|
2007-05-01 12:26:15 -07:00
|
|
|
return mInner->mNameSpaceMap;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::StyleSheetCount(PRInt32& aCount) const
|
|
|
|
{
|
|
|
|
// XXX Far from an ideal way to do this, but the hope is that
|
|
|
|
// it won't be done too often. If it is, we might want to
|
|
|
|
// consider storing the children in an array.
|
|
|
|
aCount = 0;
|
|
|
|
|
2008-09-09 11:08:11 -07:00
|
|
|
const nsCSSStyleSheet* child = mInner->mFirstChild;
|
2007-03-22 10:30:00 -07:00
|
|
|
while (child) {
|
|
|
|
aCount++;
|
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetStyleSheetAt(PRInt32 aIndex, nsICSSStyleSheet*& aSheet) const
|
|
|
|
{
|
|
|
|
// XXX Ughh...an O(n^2) method for doing iteration. Again, we hope
|
|
|
|
// that this isn't done too often. If it is, we need to change the
|
|
|
|
// underlying storage mechanism
|
|
|
|
aSheet = nsnull;
|
|
|
|
|
2008-09-09 11:08:11 -07:00
|
|
|
nsCSSStyleSheet* child = mInner->mFirstChild;
|
|
|
|
while (child && (0 != aIndex)) {
|
|
|
|
--aIndex;
|
|
|
|
child = child->mNext;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-09-09 11:08:11 -07:00
|
|
|
|
|
|
|
NS_IF_ADDREF(aSheet = child);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-12-31 07:56:33 -08:00
|
|
|
nsCSSStyleSheet::EnsureUniqueInnerResult
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSStyleSheet::EnsureUniqueInner()
|
|
|
|
{
|
2009-12-31 07:56:33 -08:00
|
|
|
NS_ABORT_IF_FALSE(mInner->mSheets.Length() != 0,
|
|
|
|
"unexpected number of outers");
|
|
|
|
if (mInner->mSheets.Length() == 1) {
|
|
|
|
return eUniqueInner_AlreadyUnique;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2009-12-31 07:56:33 -08:00
|
|
|
nsCSSStyleSheetInner* clone = mInner->CloneFor(this);
|
|
|
|
if (!clone) {
|
|
|
|
return eUniqueInner_CloneFailed;
|
|
|
|
}
|
|
|
|
mInner->RemoveSheet(this);
|
|
|
|
mInner = clone;
|
2009-12-31 07:56:33 -08:00
|
|
|
|
|
|
|
// otherwise the rule processor has pointers to the old rules
|
|
|
|
ClearRuleCascades();
|
|
|
|
|
2009-12-31 07:56:33 -08:00
|
|
|
return eUniqueInner_ClonedInner;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2009-12-31 07:56:33 -08:00
|
|
|
PRBool
|
|
|
|
nsCSSStyleSheet::AppendAllChildSheets(nsTArray<nsCSSStyleSheet*>& aArray)
|
|
|
|
{
|
|
|
|
for (nsCSSStyleSheet* child = mInner->mFirstChild; child;
|
|
|
|
child = child->mNext) {
|
|
|
|
if (!aArray.AppendElement(child)) {
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::Clone(nsICSSStyleSheet* aCloneParent,
|
2008-09-05 18:10:35 -07:00
|
|
|
nsICSSImportRule* aCloneOwnerRule,
|
|
|
|
nsIDocument* aCloneDocument,
|
|
|
|
nsIDOMNode* aCloneOwningNode,
|
|
|
|
nsICSSStyleSheet** aClone) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aClone, "Null out param!");
|
|
|
|
nsCSSStyleSheet* clone = new nsCSSStyleSheet(*this,
|
2008-09-05 18:10:35 -07:00
|
|
|
aCloneParent,
|
|
|
|
aCloneOwnerRule,
|
|
|
|
aCloneDocument,
|
|
|
|
aCloneOwningNode);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (clone) {
|
2007-07-08 00:08:04 -07:00
|
|
|
*aClone = static_cast<nsICSSStyleSheet*>(clone);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ADDREF(*aClone);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
static void
|
|
|
|
ListRules(const nsCOMArray<nsICSSRule>& aRules, FILE* aOut, PRInt32 aIndent)
|
|
|
|
{
|
|
|
|
for (PRInt32 index = aRules.Count() - 1; index >= 0; --index) {
|
|
|
|
aRules.ObjectAt(index)->List(aOut, aIndent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ListEnumData {
|
|
|
|
ListEnumData(FILE* aOut, PRInt32 aIndent)
|
|
|
|
: mOut(aOut),
|
|
|
|
mIndent(aIndent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
FILE* mOut;
|
|
|
|
PRInt32 mIndent;
|
|
|
|
};
|
|
|
|
|
|
|
|
void nsCSSStyleSheet::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
|
|
|
|
PRInt32 index;
|
|
|
|
|
|
|
|
// Indent
|
|
|
|
for (index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("CSS Style Sheet: ", out);
|
|
|
|
nsCAutoString urlSpec;
|
|
|
|
nsresult rv = mInner->mSheetURI->GetSpec(urlSpec);
|
|
|
|
if (NS_SUCCEEDED(rv) && !urlSpec.IsEmpty()) {
|
|
|
|
fputs(urlSpec.get(), out);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mMedia) {
|
|
|
|
fputs(" media: ", out);
|
|
|
|
nsAutoString buffer;
|
|
|
|
mMedia->GetText(buffer);
|
|
|
|
fputs(NS_ConvertUTF16toUTF8(buffer).get(), out);
|
|
|
|
}
|
|
|
|
fputs("\n", out);
|
|
|
|
|
2008-09-09 11:08:11 -07:00
|
|
|
for (const nsCSSStyleSheet* child = mInner->mFirstChild;
|
|
|
|
child;
|
|
|
|
child = child->mNext) {
|
2007-03-22 10:30:00 -07:00
|
|
|
child->List(out, aIndent + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs("Rules in source order:\n", out);
|
|
|
|
ListRules(mInner->mOrderedRules, out, aIndent);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSStyleSheet::ClearRuleCascades()
|
|
|
|
{
|
|
|
|
if (mRuleProcessors) {
|
2009-02-03 06:42:18 -08:00
|
|
|
nsCSSRuleProcessor **iter = mRuleProcessors->Elements(),
|
|
|
|
**end = iter + mRuleProcessors->Length();
|
|
|
|
for(; iter != end; ++iter) {
|
|
|
|
(*iter)->ClearRuleCascades();
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
if (mParent) {
|
|
|
|
nsCSSStyleSheet* parent = (nsCSSStyleSheet*)mParent;
|
|
|
|
parent->ClearRuleCascades();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCSSStyleSheet::WillDirty()
|
|
|
|
{
|
2007-05-01 12:26:15 -07:00
|
|
|
if (!mInner->mComplete) {
|
2007-03-22 10:30:00 -07:00
|
|
|
// Do nothing
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2009-12-31 07:56:33 -08:00
|
|
|
|
|
|
|
if (EnsureUniqueInner() == eUniqueInner_CloneFailed) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSStyleSheet::DidDirty()
|
|
|
|
{
|
|
|
|
ClearRuleCascades();
|
|
|
|
mDirty = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2007-07-03 11:45:39 -07: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-17 21:23:44 -08:00
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
2007-07-03 11:45:39 -07: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;
|
|
|
|
}
|
|
|
|
|
2008-10-15 13:23:21 -07:00
|
|
|
nsresult
|
|
|
|
nsCSSStyleSheet::RegisterNamespaceRule(nsICSSRule* aRule)
|
|
|
|
{
|
|
|
|
if (!mInner->mNameSpaceMap) {
|
|
|
|
nsresult rv = mInner->CreateNamespaceMap();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
AddNamespaceRuleToMap(aRule, mInner->mNameSpaceMap);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::IsModified(PRBool* aSheetModified) const
|
|
|
|
{
|
|
|
|
*aSheetModified = mDirty;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::SetModified(PRBool aModified)
|
|
|
|
{
|
|
|
|
mDirty = aModified;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMStyleSheet interface
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetType(nsAString& aType)
|
|
|
|
{
|
|
|
|
aType.AssignLiteral("text/css");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetDisabled(PRBool* aDisabled)
|
|
|
|
{
|
|
|
|
*aDisabled = mDisabled;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::SetDisabled(PRBool aDisabled)
|
|
|
|
{
|
|
|
|
// DOM method, so handle BeginUpdate/EndUpdate
|
|
|
|
MOZ_AUTO_DOC_UPDATE(mDocument, UPDATE_STYLE, PR_TRUE);
|
|
|
|
nsresult rv = nsCSSStyleSheet::SetEnabled(!aDisabled);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetOwnerNode(nsIDOMNode** aOwnerNode)
|
|
|
|
{
|
|
|
|
*aOwnerNode = mOwningNode;
|
|
|
|
NS_IF_ADDREF(*aOwnerNode);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParentStyleSheet);
|
|
|
|
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (mParent) {
|
|
|
|
rv = mParent->QueryInterface(NS_GET_IID(nsIDOMStyleSheet),
|
|
|
|
(void **)aParentStyleSheet);
|
|
|
|
} else {
|
|
|
|
*aParentStyleSheet = nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetHref(nsAString& aHref)
|
|
|
|
{
|
2007-10-23 14:56:41 -07:00
|
|
|
if (mInner->mOriginalSheetURI) {
|
|
|
|
nsCAutoString str;
|
|
|
|
mInner->mOriginalSheetURI->GetSpec(str);
|
|
|
|
CopyUTF8toUTF16(str, aHref);
|
|
|
|
} else {
|
|
|
|
SetDOMStringToNull(aHref);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetTitle(nsString& aTitle) const
|
|
|
|
{
|
|
|
|
aTitle = mTitle;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetTitle(nsAString& aTitle)
|
|
|
|
{
|
|
|
|
aTitle.Assign(mTitle);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetMedia(nsIDOMMediaList** aMedia)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aMedia);
|
|
|
|
*aMedia = nsnull;
|
|
|
|
|
|
|
|
if (!mMedia) {
|
|
|
|
mMedia = new nsMediaList();
|
|
|
|
NS_ENSURE_TRUE(mMedia, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
mMedia->SetStyleSheet(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aMedia = mMedia;
|
|
|
|
NS_ADDREF(*aMedia);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetOwnerRule(nsIDOMCSSRule** aOwnerRule)
|
|
|
|
{
|
|
|
|
if (mOwnerRule) {
|
|
|
|
return mOwnerRule->GetDOMRule(aOwnerRule);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aOwnerRule = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::GetCssRules(nsIDOMCSSRuleList** aCssRules)
|
|
|
|
{
|
|
|
|
// No doing this on incomplete sheets!
|
|
|
|
PRBool complete;
|
|
|
|
GetComplete(complete);
|
|
|
|
if (!complete) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
|
|
|
|
2007-05-01 12:26:15 -07:00
|
|
|
//-- Security check: Only scripts whose principal subsumes that of the
|
|
|
|
// style sheet can access rule collections.
|
2007-07-03 11:45:39 -07:00
|
|
|
nsresult rv = SubjectSubsumesInnerPrincipal();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// OK, security check passed, so get the rule collection
|
|
|
|
if (nsnull == mRuleCollection) {
|
|
|
|
mRuleCollection = new CSSRuleListImpl(this);
|
|
|
|
if (nsnull == mRuleCollection) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
NS_ADDREF(mRuleCollection);
|
|
|
|
}
|
|
|
|
|
|
|
|
*aCssRules = mRuleCollection;
|
|
|
|
NS_ADDREF(mRuleCollection);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::InsertRule(const nsAString& aRule,
|
|
|
|
PRUint32 aIndex,
|
|
|
|
PRUint32* aReturn)
|
2008-01-17 21:23:44 -08: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)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// No doing this if the sheet is not complete!
|
|
|
|
PRBool complete;
|
|
|
|
GetComplete(complete);
|
|
|
|
if (!complete) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRule.IsEmpty()) {
|
|
|
|
// Nothing to do here
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult result;
|
|
|
|
result = WillDirty();
|
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
|
|
|
|
|
|
|
if (aIndex > PRUint32(mInner->mOrderedRules.Count()))
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
|
|
|
|
NS_ASSERTION(PRUint32(mInner->mOrderedRules.Count()) <= PR_INT32_MAX,
|
|
|
|
"Too many style rules!");
|
|
|
|
|
|
|
|
// Hold strong ref to the CSSLoader in case the document update
|
|
|
|
// kills the document
|
2010-03-02 13:00:53 -08:00
|
|
|
nsRefPtr<css::Loader> loader;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mDocument) {
|
|
|
|
loader = mDocument->CSSLoader();
|
|
|
|
NS_ASSERTION(loader, "Document with no CSS loader!");
|
|
|
|
}
|
2010-03-02 12:59:32 -08:00
|
|
|
|
|
|
|
nsCSSParser css(loader, this);
|
|
|
|
if (!css)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
|
|
|
|
|
|
|
|
nsCOMArray<nsICSSRule> rules;
|
2010-03-02 12:59:32 -08:00
|
|
|
result = css.ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI,
|
|
|
|
mInner->mPrincipal, rules);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2010-03-02 12:59:32 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
PRInt32 rulecount = rules.Count();
|
|
|
|
if (rulecount == 0) {
|
|
|
|
// Since we know aRule was not an empty string, just throw
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
nsICSSRule* nextRule = mInner->mOrderedRules.SafeObjectAt(aIndex);
|
|
|
|
if (nextRule) {
|
|
|
|
nextRule->GetType(nextType);
|
|
|
|
if (nextType == nsICSSRule::CHARSET_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// check last rule in list
|
|
|
|
nsICSSRule* lastRule = rules.ObjectAt(rulecount - 1);
|
|
|
|
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
|
|
|
|
nsICSSRule* firstRule = rules.ObjectAt(0);
|
|
|
|
PRInt32 firstType = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
firstRule->GetType(firstType);
|
|
|
|
if (aIndex != 0) {
|
|
|
|
if (firstType == nsICSSRule::CHARSET_RULE) { // no inserting charset at nonzero position
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsICSSRule* prevRule = mInner->mOrderedRules.SafeObjectAt(aIndex - 1);
|
|
|
|
PRInt32 prevType = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
prevRule->GetType(prevType);
|
|
|
|
|
|
|
|
if (firstType == nsICSSRule::IMPORT_RULE &&
|
|
|
|
prevType != nsICSSRule::CHARSET_RULE &&
|
|
|
|
prevType != nsICSSRule::IMPORT_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (firstType == nsICSSRule::NAMESPACE_RULE &&
|
|
|
|
prevType != nsICSSRule::CHARSET_RULE &&
|
|
|
|
prevType != nsICSSRule::IMPORT_RULE &&
|
|
|
|
prevType != nsICSSRule::NAMESPACE_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
PRBool insertResult = mInner->mOrderedRules.InsertObjectsAt(rules, aIndex);
|
|
|
|
NS_ENSURE_TRUE(insertResult, NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
DidDirty();
|
|
|
|
|
|
|
|
for (PRInt32 counter = 0; counter < rulecount; counter++) {
|
|
|
|
nsICSSRule* cssRule = rules.ObjectAt(counter);
|
|
|
|
cssRule->SetStyleSheet(this);
|
|
|
|
|
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
cssRule->GetType(type);
|
|
|
|
if (type == nsICSSRule::NAMESPACE_RULE) {
|
2008-10-15 13:23:21 -07:00
|
|
|
// XXXbz does this screw up when inserting a namespace rule before
|
|
|
|
// another namespace rule that binds the same prefix to a different
|
|
|
|
// namespace?
|
|
|
|
result = RegisterNamespaceRule(cssRule);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
2007-03-22 10:30:00 -07: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) {
|
|
|
|
mDocument->StyleRuleAdded(this, cssRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*aReturn = aIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::DeleteRule(PRUint32 aIndex)
|
|
|
|
{
|
|
|
|
nsresult result = NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
// No doing this if the sheet is not complete!
|
|
|
|
PRBool complete;
|
|
|
|
GetComplete(complete);
|
|
|
|
if (!complete) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
|
|
|
|
2007-07-03 11:45:39 -07: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);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// XXX TBI: handle @rule types
|
2007-05-01 12:26:15 -07:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-01 12:26:15 -07:00
|
|
|
result = WillDirty();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-01 12:26:15 -07:00
|
|
|
if (NS_SUCCEEDED(result)) {
|
|
|
|
if (aIndex >= PRUint32(mInner->mOrderedRules.Count()))
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-01 12:26:15 -07:00
|
|
|
NS_ASSERTION(PRUint32(mInner->mOrderedRules.Count()) <= PR_INT32_MAX,
|
|
|
|
"Too many style rules!");
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-01 12:26:15 -07: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();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-05-01 12:26:15 -07:00
|
|
|
if (mDocument) {
|
|
|
|
mDocument->StyleRuleRemoved(this, rule);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::DeleteRuleFromGroup(nsICSSGroupRule* aGroup, PRUint32 aIndex)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aGroup);
|
2007-05-01 12:26:15 -07:00
|
|
|
NS_ASSERTION(mInner->mComplete, "No deleting from an incomplete sheet!");
|
2007-03-22 10:30:00 -07: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!
|
|
|
|
nsCOMPtr<nsIStyleSheet> ruleSheet;
|
|
|
|
rule->GetStyleSheet(*getter_AddRefs(ruleSheet));
|
|
|
|
if (this != ruleSheet) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
|
|
|
|
|
|
|
|
result = WillDirty();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
result = aGroup->DeleteStyleRuleAt(aIndex);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
rule->SetStyleSheet(nsnull);
|
|
|
|
|
|
|
|
DidDirty();
|
|
|
|
|
|
|
|
if (mDocument) {
|
|
|
|
mDocument->StyleRuleRemoved(this, rule);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::InsertRuleIntoGroup(const nsAString & aRule,
|
|
|
|
nsICSSGroupRule* aGroup,
|
|
|
|
PRUint32 aIndex,
|
|
|
|
PRUint32* _retval)
|
|
|
|
{
|
|
|
|
nsresult result;
|
2007-05-01 12:26:15 -07:00
|
|
|
NS_ASSERTION(mInner->mComplete, "No inserting into an incomplete sheet!");
|
2007-03-22 10:30:00 -07:00
|
|
|
// check that the group actually belongs to this sheet!
|
|
|
|
nsCOMPtr<nsIStyleSheet> groupSheet;
|
|
|
|
aGroup->GetStyleSheet(*getter_AddRefs(groupSheet));
|
|
|
|
if (this != groupSheet) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRule.IsEmpty()) {
|
|
|
|
// Nothing to do here
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-03-02 13:00:53 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// Hold strong ref to the CSSLoader in case the document update
|
|
|
|
// kills the document
|
2010-03-02 13:00:53 -08:00
|
|
|
nsRefPtr<css::Loader> loader;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mDocument) {
|
|
|
|
loader = mDocument->CSSLoader();
|
|
|
|
NS_ASSERTION(loader, "Document with no CSS loader!");
|
|
|
|
}
|
|
|
|
|
2010-03-02 12:59:32 -08:00
|
|
|
nsCSSParser css(loader, this);
|
|
|
|
if (!css) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// parse and grab the rule
|
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
|
|
|
|
|
|
|
|
result = WillDirty();
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
nsCOMArray<nsICSSRule> rules;
|
2010-03-02 12:59:32 -08:00
|
|
|
result = css.ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI,
|
|
|
|
mInner->mPrincipal, rules);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
|
|
|
PRInt32 rulecount = rules.Count();
|
|
|
|
if (rulecount == 0) {
|
|
|
|
// Since we know aRule was not an empty string, just throw
|
|
|
|
return NS_ERROR_DOM_SYNTAX_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32 counter;
|
|
|
|
nsICSSRule* rule;
|
|
|
|
for (counter = 0; counter < rulecount; counter++) {
|
|
|
|
// Only rulesets are allowed in a group as of CSS2
|
|
|
|
PRInt32 type = nsICSSRule::UNKNOWN_RULE;
|
|
|
|
rule = rules.ObjectAt(counter);
|
|
|
|
rule->GetType(type);
|
|
|
|
if (type != nsICSSRule::STYLE_RULE) {
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
result = aGroup->InsertStyleRulesAt(aIndex, rules);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
DidDirty();
|
|
|
|
for (counter = 0; counter < rulecount; counter++) {
|
|
|
|
rule = rules.ObjectAt(counter);
|
|
|
|
|
|
|
|
if (mDocument) {
|
|
|
|
mDocument->StyleRuleAdded(this, rule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
*_retval = aIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::ReplaceRuleInGroup(nsICSSGroupRule* aGroup,
|
|
|
|
nsICSSRule* aOld, nsICSSRule* aNew)
|
|
|
|
{
|
|
|
|
nsresult result;
|
2007-05-01 12:26:15 -07:00
|
|
|
NS_PRECONDITION(mInner->mComplete, "No replacing in an incomplete sheet!");
|
2007-03-22 10:30:00 -07:00
|
|
|
#ifdef DEBUG
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIStyleSheet> groupSheet;
|
|
|
|
aGroup->GetStyleSheet(*getter_AddRefs(groupSheet));
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsICSSLoaderObserver implementation
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSStyleSheet::StyleSheetLoaded(nsICSSStyleSheet* aSheet,
|
|
|
|
PRBool aWasAlternate,
|
|
|
|
nsresult aStatus)
|
|
|
|
{
|
|
|
|
#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
|
|
|
|
|
|
|
|
if (mDocument && NS_SUCCEEDED(aStatus)) {
|
|
|
|
nsCOMPtr<nsICSSImportRule> ownerRule;
|
|
|
|
aSheet->GetOwnerRule(getter_AddRefs(ownerRule));
|
|
|
|
|
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, PR_TRUE);
|
|
|
|
|
|
|
|
// XXXldb @import rules shouldn't even implement nsIStyleRule (but
|
|
|
|
// they do)!
|
|
|
|
nsCOMPtr<nsIStyleRule> styleRule(do_QueryInterface(ownerRule));
|
|
|
|
|
|
|
|
mDocument->StyleRuleAdded(this, styleRule);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2009-03-10 06:52:23 -07:00
|
|
|
NS_IMETHODIMP_(nsIURI*)
|
|
|
|
nsCSSStyleSheet::GetOriginalURI() const
|
|
|
|
{
|
|
|
|
return mInner->mOriginalSheetURI;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsresult
|
|
|
|
NS_NewCSSStyleSheet(nsICSSStyleSheet** aInstancePtrResult)
|
|
|
|
{
|
2007-05-01 12:26:15 -07:00
|
|
|
*aInstancePtrResult = nsnull;
|
2007-03-22 10:30:00 -07:00
|
|
|
nsCSSStyleSheet *it = new nsCSSStyleSheet();
|
|
|
|
|
2007-05-01 12:26:15 -07:00
|
|
|
if (!it) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ADDREF(it);
|
2007-05-01 12:26:15 -07:00
|
|
|
|
|
|
|
if (!it->mInner || !it->mInner->mPrincipal) {
|
|
|
|
NS_RELEASE(it);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
*aInstancePtrResult = it;
|
|
|
|
return NS_OK;
|
|
|
|
}
|