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:
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
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
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
#include "mozilla/CSSStyleSheet.h"
|
2002-03-22 09:28:16 +03:00
|
|
|
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsIAtom.h"
|
2004-07-28 11:08:41 +04:00
|
|
|
#include "nsCSSRuleProcessor.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2013-01-09 03:25:47 +04:00
|
|
|
#include "mozilla/dom/Element.h"
|
2014-06-07 12:42:54 +04:00
|
|
|
#include "mozilla/dom/ShadowRoot.h"
|
2013-11-11 12:03:17 +04:00
|
|
|
#include "mozilla/dom/MediaListBinding.h"
|
2011-03-17 20:41:52 +03:00
|
|
|
#include "mozilla/css/NameSpaceRule.h"
|
2010-08-08 09:28:33 +04:00
|
|
|
#include "mozilla/css/GroupRule.h"
|
2011-03-17 20:41:52 +03:00
|
|
|
#include "mozilla/css/ImportRule.h"
|
2015-06-26 06:52:47 +03:00
|
|
|
#include "nsCSSRules.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"
|
2015-04-15 19:47:03 +03:00
|
|
|
#include "nsQueryObject.h"
|
1998-04-14 00:24:54 +04:00
|
|
|
#include "nsString.h"
|
2009-02-03 17:42:18 +03:00
|
|
|
#include "nsTArray.h"
|
1998-10-06 05:39:33 +04:00
|
|
|
#include "nsIDOMCSSStyleSheet.h"
|
2014-06-10 06:11:00 +04:00
|
|
|
#include "mozilla/dom/CSSRuleList.h"
|
2000-04-26 17:58:56 +04:00
|
|
|
#include "nsIDOMMediaList.h"
|
1998-11-26 04:34:53 +03:00
|
|
|
#include "nsIDOMNode.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2010-03-02 23:59:32 +03:00
|
|
|
#include "nsCSSParser.h"
|
2010-06-29 02:49:35 +04:00
|
|
|
#include "mozilla/css/Loader.h"
|
2002-08-06 09:08:47 +04:00
|
|
|
#include "nsICSSLoaderObserver.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.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 "nsIScriptSecurityManager.h"
|
2008-04-11 21:29:06 +04:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2008-07-26 20:14:48 +04:00
|
|
|
#include "nsRuleNode.h"
|
2010-05-12 00:41:47 +04:00
|
|
|
#include "nsMediaFeatures.h"
|
2012-07-20 20:42:08 +04:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2013-03-17 18:45:01 +04:00
|
|
|
#include "mozilla/dom/CSSStyleSheetBinding.h"
|
2013-09-06 21:50:24 +04:00
|
|
|
#include "nsComponentManagerUtils.h"
|
2015-04-13 21:47:41 +03:00
|
|
|
#include "nsNullPrincipal.h"
|
2015-06-26 06:52:47 +03:00
|
|
|
#include "mozilla/RuleProcessorCache.h"
|
1999-06-03 05:57:52 +04:00
|
|
|
|
2012-08-28 21:10:08 +04:00
|
|
|
using namespace mozilla;
|
2013-01-09 03:25:47 +04:00
|
|
|
using namespace mozilla::dom;
|
2012-08-28 21:10:08 +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
|
|
|
//
|
2015-03-21 19:28:04 +03:00
|
|
|
class CSSRuleListImpl final : public CSSRuleList
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-09-01 07:36:37 +04:00
|
|
|
explicit CSSRuleListImpl(CSSStyleSheet *aStyleSheet);
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual CSSStyleSheet* GetParentObject() override;
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2013-07-24 11:27:17 +04:00
|
|
|
virtual nsIDOMCSSRule*
|
2015-03-21 19:28:04 +03:00
|
|
|
IndexedGetter(uint32_t aIndex, bool& aFound) override;
|
2013-07-24 11:27:17 +04:00
|
|
|
virtual uint32_t
|
2015-03-21 19:28:04 +03:00
|
|
|
Length() override;
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
void DropReference() { mStyleSheet = nullptr; }
|
1998-10-06 05:39:33 +04:00
|
|
|
|
|
|
|
protected:
|
2000-04-26 17:58:56 +04:00
|
|
|
virtual ~CSSRuleListImpl();
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet* mStyleSheet;
|
1998-10-06 05:39:33 +04:00
|
|
|
};
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSRuleListImpl::CSSRuleListImpl(CSSStyleSheet *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;
|
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
CSSRuleListImpl::~CSSRuleListImpl()
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet*
|
2014-05-03 11:32:54 +04:00
|
|
|
CSSRuleListImpl::GetParentObject()
|
|
|
|
{
|
|
|
|
return mStyleSheet;
|
|
|
|
}
|
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
|
|
|
|
2013-07-24 11:27:17 +04:00
|
|
|
uint32_t
|
|
|
|
CSSRuleListImpl::Length()
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
2013-07-24 11:27:17 +04:00
|
|
|
if (!mStyleSheet) {
|
|
|
|
return 0;
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
2014-08-25 23:17:32 +04:00
|
|
|
return AssertedCast<uint32_t>(mStyleSheet->StyleRuleCount());
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
2008-10-22 18:31:14 +04:00
|
|
|
nsIDOMCSSRule*
|
2013-07-24 11:27:17 +04:00
|
|
|
CSSRuleListImpl::IndexedGetter(uint32_t aIndex, bool& aFound)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
2013-07-24 11:27:17 +04:00
|
|
|
aFound = false;
|
|
|
|
|
2001-03-20 01:12:12 +03:00
|
|
|
if (mStyleSheet) {
|
2009-12-31 18:56:33 +03:00
|
|
|
// ensure rules have correct parent
|
2013-11-11 12:00:18 +04:00
|
|
|
mStyleSheet->EnsureUniqueInner();
|
|
|
|
css::Rule* rule = mStyleSheet->GetStyleRuleAt(aIndex);
|
|
|
|
if (rule) {
|
|
|
|
aFound = true;
|
|
|
|
return rule->GetDOMRule();
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
}
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2013-07-08 00:23:13 +04:00
|
|
|
// Per spec: "Return Value ... null if ... not a valid index."
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
template <class Numeric>
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t DoCompare(Numeric a, Numeric b)
|
2008-07-26 20:14:48 +04:00
|
|
|
{
|
|
|
|
if (a == b)
|
|
|
|
return 0;
|
|
|
|
if (a < b)
|
|
|
|
return -1;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-07-26 20:14:48 +04:00
|
|
|
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) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// If the expression had no value to match, the match succeeds,
|
2008-09-06 18:04:28 +04:00
|
|
|
// unless the value is an integer 0 or a zero length.
|
2008-07-26 20:14:48 +04:00
|
|
|
if (required.GetUnit() == eCSSUnit_Null) {
|
2008-09-06 18:04:28 +04:00
|
|
|
if (actual.GetUnit() == eCSSUnit_Integer)
|
|
|
|
return actual.GetIntValue() != 0;
|
|
|
|
if (actual.IsLengthUnit())
|
|
|
|
return actual.GetFloatValue() != 0;
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(mFeature->mRangeType == nsMediaFeature::eMinMaxAllowed ||
|
|
|
|
mRange == nsMediaExpression::eEqual, "yikes");
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t cmp; // -1 (actual < required)
|
2008-07-26 20:14:48 +04:00
|
|
|
// 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 18:04:28 +04:00
|
|
|
case nsMediaFeature::eBoolInteger:
|
2008-07-26 20:14:48 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(actual.GetUnit() == eCSSUnit_Integer,
|
|
|
|
"bad actual value");
|
|
|
|
NS_ASSERTION(required.GetUnit() == eCSSUnit_Integer,
|
|
|
|
"bad required value");
|
2008-09-06 18:04:28 +04: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 20:14:48 +04:00
|
|
|
cmp = DoCompare(actual.GetIntValue(), required.GetIntValue());
|
|
|
|
}
|
|
|
|
break;
|
2010-09-11 00:27:52 +04:00
|
|
|
case nsMediaFeature::eFloat:
|
|
|
|
{
|
|
|
|
NS_ASSERTION(actual.GetUnit() == eCSSUnit_Number,
|
|
|
|
"bad actual value");
|
|
|
|
NS_ASSERTION(required.GetUnit() == eCSSUnit_Number,
|
|
|
|
"bad required value");
|
|
|
|
cmp = DoCompare(actual.GetFloatValue(), required.GetFloatValue());
|
|
|
|
}
|
|
|
|
break;
|
2008-07-26 20:14:48 +04:00
|
|
|
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");
|
2012-08-22 19:56:38 +04:00
|
|
|
// Convert to int64_t so we can multiply without worry. Note
|
2008-07-26 20:14:48 +04:00
|
|
|
// 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).
|
2012-08-22 19:56:38 +04:00
|
|
|
int64_t actualNum = actual.GetArrayValue()->Item(0).GetIntValue(),
|
2008-07-26 20:14:48 +04:00
|
|
|
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 ||
|
2012-07-08 08:41:27 +04:00
|
|
|
actual.GetUnit() == eCSSUnit_Pixel ||
|
2008-07-26 20:14:48 +04:00
|
|
|
actual.GetUnit() == eCSSUnit_Centimeter,
|
|
|
|
"bad actual value");
|
|
|
|
NS_ASSERTION(required.GetUnit() == eCSSUnit_Inch ||
|
2012-07-08 08:41:27 +04:00
|
|
|
required.GetUnit() == eCSSUnit_Pixel ||
|
2008-07-26 20:14:48 +04:00
|
|
|
required.GetUnit() == eCSSUnit_Centimeter,
|
|
|
|
"bad required value");
|
|
|
|
float actualDPI = actual.GetFloatValue();
|
2012-07-08 08:41:27 +04:00
|
|
|
if (actual.GetUnit() == eCSSUnit_Centimeter) {
|
2008-07-26 20:14:48 +04:00
|
|
|
actualDPI = actualDPI * 2.54f;
|
2012-07-08 08:41:27 +04:00
|
|
|
} else if (actual.GetUnit() == eCSSUnit_Pixel) {
|
|
|
|
actualDPI = actualDPI * 96.0f;
|
|
|
|
}
|
2008-07-26 20:14:48 +04:00
|
|
|
float requiredDPI = required.GetFloatValue();
|
2012-07-08 08:41:27 +04:00
|
|
|
if (required.GetUnit() == eCSSUnit_Centimeter) {
|
2008-07-26 20:14:48 +04:00
|
|
|
requiredDPI = requiredDPI * 2.54f;
|
2012-07-08 08:41:27 +04:00
|
|
|
} else if (required.GetUnit() == eCSSUnit_Pixel) {
|
|
|
|
requiredDPI = requiredDPI * 96.0f;
|
|
|
|
}
|
2008-07-26 20:14:48 +04:00
|
|
|
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;
|
2010-10-10 00:53:45 +04:00
|
|
|
case nsMediaFeature::eIdent:
|
|
|
|
{
|
|
|
|
NS_ASSERTION(actual.GetUnit() == eCSSUnit_Ident,
|
|
|
|
"bad actual value");
|
|
|
|
NS_ASSERTION(required.GetUnit() == eCSSUnit_Ident,
|
|
|
|
"bad required value");
|
|
|
|
NS_ASSERTION(mFeature->mRangeType == nsMediaFeature::eMinMaxNotAllowed,
|
|
|
|
"bad range");
|
|
|
|
cmp = !(actual == required); // string comparison
|
|
|
|
}
|
|
|
|
break;
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
switch (mRange) {
|
|
|
|
case nsMediaExpression::eMin:
|
|
|
|
return cmp != -1;
|
|
|
|
case nsMediaExpression::eMax:
|
|
|
|
return cmp != 1;
|
|
|
|
case nsMediaExpression::eEqual:
|
|
|
|
return cmp == 0;
|
|
|
|
}
|
|
|
|
NS_NOTREACHED("unexpected mRange");
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:48 +04:00
|
|
|
void
|
|
|
|
nsMediaQueryResultCacheKey::AddExpression(const nsMediaExpression* aExpression,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aExpressionMatches)
|
2008-07-26 20:14:48 +04:00
|
|
|
{
|
|
|
|
const nsMediaFeature *feature = aExpression->mFeature;
|
2012-07-30 18:20:58 +04:00
|
|
|
FeatureEntry *entry = nullptr;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mFeatureCache.Length(); ++i) {
|
2008-07-26 20:14:48 +04:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-07-26 20:14:48 +04:00
|
|
|
nsMediaQueryResultCacheKey::Matches(nsPresContext* aPresContext) const
|
|
|
|
{
|
|
|
|
if (aPresContext->Medium() != mMedium) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0; i < mFeatureCache.Length(); ++i) {
|
2008-07-26 20:14:48 +04:00
|
|
|
const FeatureEntry *entry = &mFeatureCache[i];
|
|
|
|
nsCSSValue actual;
|
2009-10-16 04:23:18 +04:00
|
|
|
nsresult rv =
|
|
|
|
(entry->mFeature->mGetter)(aPresContext, entry->mFeature, actual);
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, false); // any better ideas?
|
2008-07-26 20:14:48 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t j = 0; j < entry->mExpressions.Length(); ++j) {
|
2008-07-26 20:14:48 +04:00
|
|
|
const ExpressionEntry &eentry = entry->mExpressions[j];
|
|
|
|
if (eentry.mExpression.Matches(aPresContext, actual) !=
|
|
|
|
eentry.mExpressionMatches) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
2015-06-26 06:52:47 +03:00
|
|
|
bool
|
|
|
|
nsDocumentRuleResultCacheKey::AddMatchingRule(css::DocumentRule* aRule)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(!mFinalized);
|
|
|
|
return mMatchingRules.AppendElement(aRule);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsDocumentRuleResultCacheKey::Finalize()
|
|
|
|
{
|
|
|
|
mMatchingRules.Sort();
|
|
|
|
#ifdef DEBUG
|
|
|
|
mFinalized = true;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsDocumentRuleResultCacheKey::Matches(
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
const nsTArray<css::DocumentRule*>& aRules) const
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mFinalized);
|
|
|
|
|
|
|
|
// First check that aPresContext matches all the rules listed in
|
|
|
|
// mMatchingRules.
|
|
|
|
for (css::DocumentRule* rule : mMatchingRules) {
|
|
|
|
if (!rule->UseForPresentation(aPresContext)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then check that all the rules in aRules that aren't also in
|
|
|
|
// mMatchingRules do not match.
|
|
|
|
|
|
|
|
// pointer to matching rules
|
|
|
|
auto pm = mMatchingRules.begin();
|
|
|
|
auto pm_end = mMatchingRules.end();
|
|
|
|
|
|
|
|
// pointer to all rules
|
|
|
|
auto pr = aRules.begin();
|
|
|
|
auto pr_end = aRules.end();
|
|
|
|
|
|
|
|
// mMatchingRules and aRules are both sorted by their pointer values,
|
|
|
|
// so we can iterate over the two lists simultaneously.
|
|
|
|
while (pr < pr_end) {
|
|
|
|
while (pm < pm_end && *pm < *pr) {
|
|
|
|
++pm;
|
|
|
|
MOZ_ASSERT(pm >= pm_end || *pm == *pr,
|
|
|
|
"shouldn't find rule in mMatchingRules that is not in aRules");
|
|
|
|
}
|
|
|
|
if (pm >= pm_end || *pm != *pr) {
|
|
|
|
if ((*pr)->UseForPresentation(aPresContext)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++pr;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsDocumentRuleResultCacheKey::List(FILE* aOut, int32_t aIndent) const
|
|
|
|
{
|
|
|
|
for (css::DocumentRule* rule : mMatchingRules) {
|
|
|
|
nsCString str;
|
|
|
|
|
|
|
|
for (int32_t i = 0; i < aIndent; i++) {
|
|
|
|
str.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
str.AppendLiteral("{ ");
|
|
|
|
|
|
|
|
nsString condition;
|
|
|
|
rule->GetConditionText(condition);
|
|
|
|
AppendUTF16toUTF8(condition, str);
|
|
|
|
|
|
|
|
str.AppendLiteral(" }\n");
|
|
|
|
fprintf_stderr(aOut, "%s", str.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
size_t
|
|
|
|
nsDocumentRuleResultCacheKey::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = 0;
|
2015-07-29 09:24:24 +03:00
|
|
|
n += mMatchingRules.ShallowSizeOfExcludingThis(aMallocSizeOf);
|
2015-06-26 06:52:47 +03:00
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2008-07-26 20:14:48 +04: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 18:45:00 +03:00
|
|
|
aString.Append(nsDependentAtomString(mMediaType));
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, i_end = mExpressions.Length(); i < i_end; ++i) {
|
2008-07-26 20:14:48 +04:00
|
|
|
if (i > 0 || !mTypeOmitted)
|
|
|
|
aString.AppendLiteral(" and ");
|
2014-05-22 07:48:51 +04:00
|
|
|
aString.Append('(');
|
2008-07-26 20:14:48 +04:00
|
|
|
|
|
|
|
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 18:45:00 +03:00
|
|
|
aString.Append(nsDependentAtomString(*feature->mName));
|
2008-07-26 20:14:48 +04: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.
|
2013-09-16 03:35:49 +04:00
|
|
|
expr.mValue.AppendToString(eCSSProperty_width, aString,
|
|
|
|
nsCSSValue::eNormalized);
|
2008-07-26 20:14:48 +04:00
|
|
|
break;
|
|
|
|
case nsMediaFeature::eInteger:
|
2008-09-06 18:04:28 +04:00
|
|
|
case nsMediaFeature::eBoolInteger:
|
2008-07-26 20:14:48 +04:00
|
|
|
NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Integer,
|
|
|
|
"bad unit");
|
|
|
|
// Use 'z-index' as a property that takes integer values
|
|
|
|
// written without anything extra.
|
2013-09-16 03:35:49 +04:00
|
|
|
expr.mValue.AppendToString(eCSSProperty_z_index, aString,
|
|
|
|
nsCSSValue::eNormalized);
|
2008-07-26 20:14:48 +04:00
|
|
|
break;
|
2010-09-11 00:27:52 +04:00
|
|
|
case nsMediaFeature::eFloat:
|
|
|
|
{
|
|
|
|
NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Number,
|
|
|
|
"bad unit");
|
|
|
|
// Use 'line-height' as a property that takes float values
|
|
|
|
// written in the normal way.
|
2013-09-16 03:35:49 +04:00
|
|
|
expr.mValue.AppendToString(eCSSProperty_line_height, aString,
|
|
|
|
nsCSSValue::eNormalized);
|
2010-09-11 00:27:52 +04:00
|
|
|
}
|
|
|
|
break;
|
2008-07-26 20:14:48 +04:00
|
|
|
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");
|
2013-09-16 03:35:49 +04:00
|
|
|
array->Item(0).AppendToString(eCSSProperty_z_index, aString,
|
|
|
|
nsCSSValue::eNormalized);
|
2014-05-22 07:48:51 +04:00
|
|
|
aString.Append('/');
|
2013-09-16 03:35:49 +04:00
|
|
|
array->Item(1).AppendToString(eCSSProperty_z_index, aString,
|
|
|
|
nsCSSValue::eNormalized);
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsMediaFeature::eResolution:
|
2010-03-08 18:45:00 +03:00
|
|
|
{
|
2010-11-30 21:18:15 +03:00
|
|
|
aString.AppendFloat(expr.mValue.GetFloatValue());
|
2010-03-08 18:45:00 +03:00
|
|
|
if (expr.mValue.GetUnit() == eCSSUnit_Inch) {
|
|
|
|
aString.AppendLiteral("dpi");
|
2012-07-08 08:41:27 +04:00
|
|
|
} else if (expr.mValue.GetUnit() == eCSSUnit_Pixel) {
|
|
|
|
aString.AppendLiteral("dppx");
|
2010-03-08 18:45:00 +03:00
|
|
|
} else {
|
|
|
|
NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Centimeter,
|
|
|
|
"bad unit");
|
|
|
|
aString.AppendLiteral("dpcm");
|
|
|
|
}
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case nsMediaFeature::eEnumerated:
|
|
|
|
NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Enumerated,
|
|
|
|
"bad unit");
|
|
|
|
AppendASCIItoUTF16(
|
|
|
|
nsCSSProps::ValueToKeyword(expr.mValue.GetIntValue(),
|
2009-10-16 04:23:18 +04:00
|
|
|
feature->mData.mKeywordTable),
|
2008-07-26 20:14:48 +04:00
|
|
|
aString);
|
|
|
|
break;
|
2010-10-10 00:53:45 +04:00
|
|
|
case nsMediaFeature::eIdent:
|
|
|
|
NS_ASSERTION(expr.mValue.GetUnit() == eCSSUnit_Ident,
|
|
|
|
"bad unit");
|
|
|
|
aString.Append(expr.mValue.GetStringBufferValue());
|
|
|
|
break;
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-22 07:48:51 +04:00
|
|
|
aString.Append(')');
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMediaQuery*
|
|
|
|
nsMediaQuery::Clone() const
|
|
|
|
{
|
2013-11-11 12:00:50 +04:00
|
|
|
return new nsMediaQuery(*this);
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-07-26 20:14:48 +04:00
|
|
|
nsMediaQuery::Matches(nsPresContext* aPresContext,
|
2011-04-22 07:17:31 +04:00
|
|
|
nsMediaQueryResultCacheKey* aKey) const
|
2008-07-26 20:14:48 +04:00
|
|
|
{
|
|
|
|
if (mHadUnknownExpression)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-07-26 20:14:48 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool match =
|
2008-07-26 20:14:48 +04:00
|
|
|
mMediaType == aPresContext->Medium() || mMediaType == nsGkAtoms::all;
|
2012-08-22 19:56:38 +04:00
|
|
|
for (uint32_t i = 0, i_end = mExpressions.Length(); match && i < i_end; ++i) {
|
2008-07-26 20:14:48 +04:00
|
|
|
const nsMediaExpression &expr = mExpressions[i];
|
|
|
|
nsCSSValue actual;
|
2009-10-16 04:23:18 +04:00
|
|
|
nsresult rv =
|
|
|
|
(expr.mFeature->mGetter)(aPresContext, expr.mFeature, actual);
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, 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);
|
2011-04-22 07:17:31 +04:00
|
|
|
if (aKey) {
|
|
|
|
aKey->AddExpression(&expr, match);
|
|
|
|
}
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return match == !mNegated;
|
|
|
|
}
|
|
|
|
|
2013-11-11 12:03:17 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsMediaList)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
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)
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2013-11-11 12:03:17 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsMediaList)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_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
|
|
|
|
2013-11-11 12:03:17 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(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()
|
2012-07-30 18:20:58 +04:00
|
|
|
: mStyleSheet(nullptr)
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-11-11 12:03:17 +04:00
|
|
|
/* virtual */ JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
nsMediaList::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-11-11 12:03:17 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return MediaListBinding::Wrap(aCx, this, aGivenProto);
|
2013-11-11 12:03:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList::GetText(nsAString& aMediaText)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
|
|
|
aMediaText.Truncate();
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0, i_end = mArray.Length(); i < i_end; ++i) {
|
2008-07-26 20:14:48 +04:00
|
|
|
nsMediaQuery* query = mArray[i];
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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....
|
2013-11-11 12:03:17 +04:00
|
|
|
void
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList::SetText(const nsAString& aMediaText)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
2010-03-02 23:59:32 +03:00
|
|
|
nsCSSParser parser;
|
2000-04-26 17:58:56 +04:00
|
|
|
|
2013-03-17 18:42:59 +04:00
|
|
|
bool htmlMode = mStyleSheet && mStyleSheet->GetOwnerNode();
|
2000-04-26 17:58:56 +04:00
|
|
|
|
2013-11-11 11:57:34 +04:00
|
|
|
parser.ParseMediaList(aMediaText, nullptr, 0, this, htmlMode);
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2008-07-26 20:14:48 +04:00
|
|
|
nsMediaList::Matches(nsPresContext* aPresContext,
|
2011-04-22 07:17:31 +04:00
|
|
|
nsMediaQueryResultCacheKey* aKey)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0, i_end = mArray.Length(); i < i_end; ++i) {
|
2008-07-26 20:14:48 +04:00
|
|
|
if (mArray[i]->Matches(aPresContext, aKey)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
|
|
|
}
|
2011-10-18 00:49:22 +04:00
|
|
|
return mArray.IsEmpty();
|
2005-03-30 04:36:57 +04:00
|
|
|
}
|
|
|
|
|
2014-07-02 14:53:41 +04:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
nsMediaList::SetStyleSheet(CSSStyleSheet* aSheet)
|
2005-03-30 04:36:57 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION(aSheet == mStyleSheet || !aSheet || !mStyleSheet,
|
|
|
|
"multiple style sheets competing for one media list");
|
2010-05-12 00:41:47 +04:00
|
|
|
mStyleSheet = aSheet;
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
|
2013-11-11 12:00:55 +04:00
|
|
|
already_AddRefed<nsMediaList>
|
|
|
|
nsMediaList::Clone()
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
2005-03-30 04:36:57 +04:00
|
|
|
nsRefPtr<nsMediaList> result = new nsMediaList();
|
2013-11-11 12:00:55 +04:00
|
|
|
result->mArray.AppendElements(mArray.Length());
|
2013-11-11 12:00:50 +04:00
|
|
|
for (uint32_t i = 0, i_end = mArray.Length(); i < i_end; ++i) {
|
|
|
|
result->mArray[i] = mArray[i]->Clone();
|
|
|
|
MOZ_ASSERT(result->mArray[i]);
|
2008-07-26 20:14:48 +04:00
|
|
|
}
|
2013-11-11 12:00:55 +04:00
|
|
|
return result.forget();
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2005-03-30 04:36:57 +04:00
|
|
|
nsMediaList::GetMediaText(nsAString& aMediaText)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
2013-11-11 12:03:17 +04:00
|
|
|
GetText(aMediaText);
|
|
|
|
return NS_OK;
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
// "sheet" should be a CSSStyleSheet and "doc" should be an
|
2003-10-16 22:14:25 +04:00
|
|
|
// nsCOMPtr<nsIDocument>
|
|
|
|
#define BEGIN_MEDIA_CHANGE(sheet, doc) \
|
|
|
|
if (sheet) { \
|
2010-05-13 00:18:47 +04:00
|
|
|
doc = sheet->GetOwningDocument(); \
|
2003-10-16 22:14:25 +04:00
|
|
|
} \
|
2013-11-11 12:00:46 +04:00
|
|
|
mozAutoDocUpdate updateBatch(doc, UPDATE_STYLE, true); \
|
2003-10-16 22:14:25 +04:00
|
|
|
if (sheet) { \
|
2013-11-11 12:00:46 +04:00
|
|
|
sheet->WillDirty(); \
|
2003-10-16 22:14:25 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define END_MEDIA_CHANGE(sheet, doc) \
|
|
|
|
if (sheet) { \
|
|
|
|
sheet->DidDirty(); \
|
|
|
|
} \
|
|
|
|
/* XXXldb Pass something meaningful? */ \
|
|
|
|
if (doc) { \
|
2012-07-30 18:20:58 +04:00
|
|
|
doc->StyleRuleChanged(sheet, nullptr, nullptr); \
|
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
|
|
|
nsCOMPtr<nsIDocument> doc;
|
|
|
|
|
|
|
|
BEGIN_MEDIA_CHANGE(mStyleSheet, doc)
|
|
|
|
|
2013-11-11 12:03:17 +04:00
|
|
|
SetText(aMediaText);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2003-10-16 22:14:25 +04:00
|
|
|
END_MEDIA_CHANGE(mStyleSheet, doc)
|
|
|
|
|
2013-11-11 12:03:17 +04:00
|
|
|
return NS_OK;
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsMediaList::GetLength(uint32_t* aLength)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aLength);
|
|
|
|
|
2013-11-11 12:01:01 +04:00
|
|
|
*aLength = Length();
|
2000-04-26 17:58:56 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsMediaList::Item(uint32_t aIndex, nsAString& aReturn)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
2013-11-11 12:03:17 +04:00
|
|
|
bool dummy;
|
|
|
|
IndexedGetter(aIndex, dummy, aReturn);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2008-07-26 20:14:48 +04:00
|
|
|
|
2013-11-11 12:03:17 +04:00
|
|
|
void
|
|
|
|
nsMediaList::IndexedGetter(uint32_t aIndex, bool& aFound, nsAString& aReturn)
|
|
|
|
{
|
|
|
|
if (aIndex < Length()) {
|
|
|
|
aFound = true;
|
2008-07-26 20:14:48 +04:00
|
|
|
aReturn.Truncate();
|
2013-11-11 12:03:17 +04:00
|
|
|
mArray[aIndex]->AppendToString(aReturn);
|
2000-04-26 17:58:56 +04:00
|
|
|
} else {
|
2013-11-11 12:03:17 +04:00
|
|
|
aFound = false;
|
2005-03-30 04:36:57 +04:00
|
|
|
SetDOMStringToNull(aReturn);
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t i = 0, i_end = mArray.Length(); i < i_end; ++i) {
|
2008-07-26 20:14:48 +04:00
|
|
|
nsMediaQuery* query = mArray[i];
|
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;
|
2013-04-01 21:46:26 +04:00
|
|
|
mArray.SwapElements(buf);
|
2008-07-26 20:14:48 +04:00
|
|
|
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
|
|
|
}
|
2013-04-01 21:46:26 +04:00
|
|
|
|
|
|
|
mArray.SwapElements(buf);
|
2008-07-26 20:14:48 +04:00
|
|
|
return rv;
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
namespace mozilla {
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheetInner::CSSStyleSheetInner(CSSStyleSheet* aPrimarySheet,
|
2014-11-18 16:46:47 +03:00
|
|
|
CORSMode aCORSMode,
|
2015-08-13 06:19:11 +03:00
|
|
|
ReferrerPolicy aReferrerPolicy,
|
|
|
|
const SRIMetadata& aIntegrity)
|
2014-11-18 16:46:47 +03:00
|
|
|
: mSheets()
|
|
|
|
, mCORSMode(aCORSMode)
|
|
|
|
, mReferrerPolicy (aReferrerPolicy)
|
2015-08-13 06:19:11 +03:00
|
|
|
, mIntegrity(aIntegrity)
|
2014-11-18 16:46:47 +03:00
|
|
|
, mComplete(false)
|
2007-05-01 23:26:15 +04:00
|
|
|
#ifdef DEBUG
|
2014-11-18 16:46:47 +03:00
|
|
|
, mPrincipalSet(false)
|
2007-05-01 23:26:15 +04:00
|
|
|
#endif
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
2014-06-20 14:32:49 +04:00
|
|
|
MOZ_COUNT_CTOR(CSSStyleSheetInner);
|
2008-09-09 22:08:11 +04:00
|
|
|
mSheets.AppendElement(aPrimarySheet);
|
2007-05-01 23:26:15 +04:00
|
|
|
|
2015-04-13 21:47:41 +03:00
|
|
|
mPrincipal = nsNullPrincipal::Create();
|
2012-08-04 11:44:01 +04:00
|
|
|
if (!mPrincipal) {
|
2015-05-27 00:04:24 +03:00
|
|
|
NS_RUNTIMEABORT("nsNullPrincipal::Init failed");
|
2012-08-04 11:44:01 +04:00
|
|
|
}
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1999-05-19 03:14:29 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool SetStyleSheetReference(css::Rule* aRule, void* aSheet)
|
2008-09-09 22:08:11 +04:00
|
|
|
{
|
|
|
|
if (aRule) {
|
2014-06-20 14:32:49 +04:00
|
|
|
aRule->SetStyleSheet(static_cast<CSSStyleSheet*>(aSheet));
|
2008-09-09 22:08:11 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-09-09 22:08:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ChildSheetListBuilder {
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet>* sheetSlot;
|
|
|
|
CSSStyleSheet* parent;
|
2008-09-09 22:08:11 +04:00
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
void SetParentLinks(CSSStyleSheet* aSheet) {
|
2008-09-09 22:08:11 +04:00
|
|
|
aSheet->mParent = parent;
|
|
|
|
aSheet->SetOwningDocument(parent->mDocument);
|
|
|
|
}
|
2011-01-15 06:57:53 +03:00
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
static void ReparentChildList(CSSStyleSheet* aPrimarySheet,
|
|
|
|
CSSStyleSheet* aFirstChild)
|
2011-01-15 06:57:53 +03:00
|
|
|
{
|
2014-06-20 14:32:49 +04:00
|
|
|
for (CSSStyleSheet *child = aFirstChild; child; child = child->mNext) {
|
2011-01-15 06:57:53 +03:00
|
|
|
child->mParent = aPrimarySheet;
|
|
|
|
child->SetOwningDocument(aPrimarySheet->mDocument);
|
|
|
|
}
|
|
|
|
}
|
2008-09-09 22:08:11 +04:00
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::RebuildChildList(css::Rule* aRule, void* aBuilder)
|
2008-09-09 22:08:11 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t type = aRule->GetType();
|
2011-04-08 05:23:46 +04:00
|
|
|
if (type < css::Rule::IMPORT_RULE) {
|
2009-05-29 02:16:31 +04:00
|
|
|
// Keep going till we get to the import rules.
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-09-09 22:08:11 +04:00
|
|
|
}
|
|
|
|
|
2011-04-08 05:23:46 +04:00
|
|
|
if (type != css::Rule::IMPORT_RULE) {
|
2009-05-29 02:16:31 +04:00
|
|
|
// We're past all the import rules; stop the enumeration.
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-09-09 22:08:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
ChildSheetListBuilder* builder =
|
|
|
|
static_cast<ChildSheetListBuilder*>(aBuilder);
|
|
|
|
|
|
|
|
// XXXbz We really need to decomtaminate all this stuff. Is there a reason
|
2014-06-20 14:32:49 +04:00
|
|
|
// that I can't just QI to ImportRule and get a CSSStyleSheet
|
2008-09-09 22:08:11 +04:00
|
|
|
// 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
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet> cssSheet = do_QueryObject(childSheet);
|
2008-09-09 22:08:11 +04:00
|
|
|
if (!cssSheet) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-09-09 22:08:11 +04:00
|
|
|
}
|
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
(*builder->sheetSlot) = cssSheet;
|
2008-09-09 22:08:11 +04:00
|
|
|
builder->SetParentLinks(*builder->sheetSlot);
|
2009-05-26 23:40:49 +04:00
|
|
|
builder->sheetSlot = &(*builder->sheetSlot)->mNext;
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-09-09 22:08:11 +04:00
|
|
|
}
|
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
|
|
|
size_t n = 0;
|
2014-06-20 14:32:49 +04:00
|
|
|
const CSSStyleSheet* s = this;
|
2012-01-03 06:19:14 +04:00
|
|
|
while (s) {
|
|
|
|
n += aMallocSizeOf(s);
|
|
|
|
|
2012-10-10 07:03:18 +04:00
|
|
|
// Each inner can be shared by multiple sheets. So we only count the inner
|
|
|
|
// if this sheet is the first one in the list of those sharing it. As a
|
|
|
|
// result, the first such sheet takes all the blame for the memory
|
|
|
|
// consumption of the inner, which isn't ideal but it's better than
|
|
|
|
// double-counting the inner.
|
|
|
|
if (s->mInner->mSheets[0] == s) {
|
|
|
|
n += s->mInner->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it
|
|
|
|
// is worthwhile:
|
2012-01-03 06:19:14 +04:00
|
|
|
// - s->mTitle
|
|
|
|
// - s->mMedia
|
|
|
|
// - s->mRuleCollection
|
|
|
|
// - s->mRuleProcessors
|
|
|
|
//
|
|
|
|
// The following members are not measured:
|
|
|
|
// - s->mOwnerRule, because it's non-owning
|
|
|
|
|
|
|
|
s = s->mNext;
|
|
|
|
}
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheetInner::CSSStyleSheetInner(CSSStyleSheetInner& aCopy,
|
|
|
|
CSSStyleSheet* aPrimarySheet)
|
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),
|
2012-08-28 21:10:08 +04:00
|
|
|
mCORSMode(aCopy.mCORSMode),
|
2014-11-18 16:46:47 +03:00
|
|
|
mReferrerPolicy(aCopy.mReferrerPolicy),
|
2015-08-13 06:19:11 +03:00
|
|
|
mIntegrity(aCopy.mIntegrity),
|
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
|
|
|
{
|
2014-06-20 14:32:49 +04:00
|
|
|
MOZ_COUNT_CTOR(CSSStyleSheetInner);
|
2009-02-05 12:38:51 +03:00
|
|
|
AddSheet(aPrimarySheet);
|
2013-11-15 06:42:57 +04:00
|
|
|
aCopy.mOrderedRules.EnumerateForwards(css::GroupRule::CloneRuleInto, &mOrderedRules);
|
2008-09-09 22:08:11 +04:00
|
|
|
mOrderedRules.EnumerateForwards(SetStyleSheetReference, aPrimarySheet);
|
|
|
|
|
|
|
|
ChildSheetListBuilder builder = { &mFirstChild, aPrimarySheet };
|
2014-06-20 14:32:49 +04:00
|
|
|
mOrderedRules.EnumerateForwards(CSSStyleSheet::RebuildChildList, &builder);
|
2008-09-09 22:08:11 +04:00
|
|
|
|
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
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheetInner::~CSSStyleSheetInner()
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
2014-06-20 14:32:49 +04:00
|
|
|
MOZ_COUNT_DTOR(CSSStyleSheetInner);
|
2012-07-30 18:20:58 +04:00
|
|
|
mOrderedRules.EnumerateForwards(SetStyleSheetReference, nullptr);
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheetInner*
|
|
|
|
CSSStyleSheetInner::CloneFor(CSSStyleSheet* aPrimarySheet)
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
2014-06-20 14:32:49 +04:00
|
|
|
return new CSSStyleSheetInner(*this, aPrimarySheet);
|
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
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheetInner::AddSheet(CSSStyleSheet* aSheet)
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
2008-09-09 22:08:11 +04:00
|
|
|
mSheets.AppendElement(aSheet);
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheetInner::RemoveSheet(CSSStyleSheet* aSheet)
|
1999-06-03 05:57:52 +04:00
|
|
|
{
|
2009-02-03 17:42:18 +03:00
|
|
|
if (1 == mSheets.Length()) {
|
|
|
|
NS_ASSERTION(aSheet == mSheets.ElementAt(0), "bad parent");
|
1999-06-03 05:57:52 +04:00
|
|
|
delete this;
|
|
|
|
return;
|
|
|
|
}
|
2009-02-03 17:42:18 +03:00
|
|
|
if (aSheet == mSheets.ElementAt(0)) {
|
1999-06-03 05:57:52 +04:00
|
|
|
mSheets.RemoveElementAt(0);
|
2009-02-03 17:42:18 +03:00
|
|
|
NS_ASSERTION(mSheets.Length(), "no parents");
|
2005-10-16 00:21:20 +04:00
|
|
|
mOrderedRules.EnumerateForwards(SetStyleSheetReference,
|
2009-02-03 17:42:18 +03:00
|
|
|
mSheets.ElementAt(0));
|
2011-01-15 06:57:53 +03:00
|
|
|
|
|
|
|
ChildSheetListBuilder::ReparentChildList(mSheets[0], mFirstChild);
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
|
|
|
else {
|
2008-09-09 22:08:11 +04:00
|
|
|
mSheets.RemoveElement(aSheet);
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2008-10-16 00:23:21 +04:00
|
|
|
static void
|
2011-04-08 05:23:46 +04:00
|
|
|
AddNamespaceRuleToMap(css::Rule* aRule, nsXMLNameSpaceMap* aMap)
|
2008-10-16 00:23:21 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
NS_ASSERTION(aRule->GetType() == css::Rule::NAMESPACE_RULE, "Bogus rule type");
|
2008-10-16 00:23:21 +04:00
|
|
|
|
2011-03-17 20:41:52 +03:00
|
|
|
nsRefPtr<css::NameSpaceRule> nameSpaceRule = do_QueryObject(aRule);
|
|
|
|
|
2008-10-16 00:23:21 +04:00
|
|
|
nsAutoString urlSpec;
|
|
|
|
nameSpaceRule->GetURLSpec(urlSpec);
|
|
|
|
|
2011-03-17 20:41:52 +03:00
|
|
|
aMap->AddPrefix(nameSpaceRule->GetPrefix(), urlSpec);
|
2008-10-16 00:23:21 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2011-04-08 05:23:46 +04:00
|
|
|
CreateNameSpace(css::Rule* aRule, void* aNameSpacePtr)
|
1999-06-15 10:20:46 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t type = aRule->GetType();
|
2011-04-08 05:23:46 +04:00
|
|
|
if (css::Rule::NAMESPACE_RULE == type) {
|
2008-10-16 00:23:21 +04:00
|
|
|
AddNamespaceRuleToMap(aRule,
|
|
|
|
static_cast<nsXMLNameSpaceMap*>(aNameSpacePtr));
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
1999-06-15 10:20:46 +04:00
|
|
|
}
|
2008-10-16 00:23:21 +04:00
|
|
|
// stop if not namespace, import or charset because namespace can't follow
|
|
|
|
// anything else
|
2011-04-08 05:23:46 +04:00
|
|
|
return (css::Rule::CHARSET_RULE == type || css::Rule::IMPORT_RULE == type);
|
1999-06-15 10:20:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheetInner::RebuildNameSpaces()
|
1999-06-15 10:20:46 +04:00
|
|
|
{
|
2008-10-16 00:23:21 +04:00
|
|
|
// Just nuke our existing namespace map, if any
|
|
|
|
if (NS_SUCCEEDED(CreateNamespaceMap())) {
|
|
|
|
mOrderedRules.EnumerateForwards(CreateNameSpace, mNameSpaceMap);
|
2005-02-18 22:18:37 +03:00
|
|
|
}
|
1999-06-15 10:20:46 +04:00
|
|
|
}
|
|
|
|
|
2008-10-16 00:23:21 +04:00
|
|
|
nsresult
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheetInner::CreateNamespaceMap()
|
2008-10-16 00:23:21 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mNameSpaceMap = nsXMLNameSpaceMap::Create(false);
|
2008-10-16 00:23:21 +04: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.
|
2012-07-30 18:20:58 +04:00
|
|
|
mNameSpaceMap->AddPrefix(nullptr, kNameSpaceID_Unknown);
|
2008-10-16 00:23:21 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-15 10:20:46 +04:00
|
|
|
|
2012-01-03 06:19:14 +04:00
|
|
|
size_t
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheetInner::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const
|
2012-01-03 06:19:14 +04:00
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += mOrderedRules.SizeOfExcludingThis(css::Rule::SizeOfCOMArrayElementIncludingThis,
|
|
|
|
aMallocSizeOf);
|
|
|
|
n += mFirstChild ? mFirstChild->SizeOfIncludingThis(aMallocSizeOf) : 0;
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mSheetURI
|
|
|
|
// - mOriginalSheetURI
|
|
|
|
// - mBaseURI
|
|
|
|
// - mPrincipal
|
|
|
|
// - mNameSpaceMap
|
|
|
|
//
|
|
|
|
// The following members are not measured:
|
|
|
|
// - mSheets, because it's non-owning
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
// -------------------------------
|
|
|
|
// CSS Style Sheet
|
|
|
|
//
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2014-11-18 16:46:47 +03:00
|
|
|
CSSStyleSheet::CSSStyleSheet(CORSMode aCORSMode, ReferrerPolicy aReferrerPolicy)
|
2010-05-18 08:00:39 +04:00
|
|
|
: mTitle(),
|
2012-07-30 18:20:58 +04:00
|
|
|
mParent(nullptr),
|
|
|
|
mOwnerRule(nullptr),
|
|
|
|
mDocument(nullptr),
|
|
|
|
mOwningNode(nullptr),
|
2011-10-17 18:59:28 +04:00
|
|
|
mDisabled(false),
|
|
|
|
mDirty(false),
|
2015-06-26 06:52:47 +03:00
|
|
|
mInRuleProcessorCache(false),
|
2013-01-09 03:25:47 +04:00
|
|
|
mScopeElement(nullptr),
|
2012-07-30 18:20:58 +04:00
|
|
|
mRuleProcessors(nullptr)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2015-08-13 06:19:11 +03:00
|
|
|
mInner = new CSSStyleSheetInner(this, aCORSMode, aReferrerPolicy,
|
|
|
|
SRIMetadata());
|
|
|
|
}
|
|
|
|
|
|
|
|
CSSStyleSheet::CSSStyleSheet(CORSMode aCORSMode,
|
|
|
|
ReferrerPolicy aReferrerPolicy,
|
|
|
|
const SRIMetadata& aIntegrity)
|
|
|
|
: mTitle(),
|
|
|
|
mParent(nullptr),
|
|
|
|
mOwnerRule(nullptr),
|
|
|
|
mDocument(nullptr),
|
|
|
|
mOwningNode(nullptr),
|
|
|
|
mDisabled(false),
|
|
|
|
mDirty(false),
|
|
|
|
mInRuleProcessorCache(false),
|
|
|
|
mScopeElement(nullptr),
|
|
|
|
mRuleProcessors(nullptr)
|
|
|
|
{
|
|
|
|
mInner = new CSSStyleSheetInner(this, aCORSMode, aReferrerPolicy,
|
|
|
|
aIntegrity);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::CSSStyleSheet(const CSSStyleSheet& aCopy,
|
|
|
|
CSSStyleSheet* aParentToUse,
|
|
|
|
css::ImportRule* aOwnerRuleToUse,
|
|
|
|
nsIDocument* aDocumentToUse,
|
|
|
|
nsINode* aOwningNodeToUse)
|
2010-05-18 08:00:39 +04:00
|
|
|
: mTitle(aCopy.mTitle),
|
2003-02-23 07:44:41 +03:00
|
|
|
mParent(aParentToUse),
|
|
|
|
mOwnerRule(aOwnerRuleToUse),
|
|
|
|
mDocument(aDocumentToUse),
|
|
|
|
mOwningNode(aOwningNodeToUse),
|
1999-06-03 05:57:52 +04:00
|
|
|
mDisabled(aCopy.mDisabled),
|
2011-04-12 10:18:43 +04:00
|
|
|
mDirty(aCopy.mDirty),
|
2015-06-26 06:52:47 +03:00
|
|
|
mInRuleProcessorCache(false),
|
2013-01-09 03:25:47 +04:00
|
|
|
mScopeElement(nullptr),
|
1999-10-14 04:59:21 +04:00
|
|
|
mInner(aCopy.mInner),
|
2012-07-30 18:20:58 +04:00
|
|
|
mRuleProcessors(nullptr)
|
1998-10-06 05:39:33 +04:00
|
|
|
{
|
|
|
|
|
1999-06-03 05:57:52 +04:00
|
|
|
mInner->AddSheet(this);
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
if (mDirty) { // 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?");
|
2009-12-31 18:56:33 +03:00
|
|
|
// FIXME: handle failure?
|
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) {
|
2008-09-09 22:08:11 +04:00
|
|
|
// XXX This is wrong; we should be keeping @import rules and
|
|
|
|
// sheets in sync!
|
2013-11-11 12:00:55 +04:00
|
|
|
mMedia = aCopy.mMedia->Clone();
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::~CSSStyleSheet()
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2014-06-20 14:32:49 +04:00
|
|
|
for (CSSStyleSheet* child = mInner->mFirstChild;
|
2008-09-09 22:08:11 +04:00
|
|
|
child;
|
|
|
|
child = child->mNext) {
|
|
|
|
// XXXbz this is a little bogus; see the XXX comment where we
|
|
|
|
// declare mFirstChild.
|
|
|
|
if (child->mParent == this) {
|
2012-07-30 18:20:58 +04:00
|
|
|
child->mParent = nullptr;
|
|
|
|
child->mDocument = nullptr;
|
2008-09-09 22:08:11 +04:00
|
|
|
}
|
1998-10-06 05:39:33 +04:00
|
|
|
}
|
2012-10-08 06:39:08 +04:00
|
|
|
DropRuleCollection();
|
|
|
|
DropMedia();
|
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) {
|
2009-02-03 17:42:18 +03:00
|
|
|
NS_ASSERTION(mRuleProcessors->Length() == 0, "destructing sheet with rule processor reference");
|
1999-10-14 04:59:21 +04:00
|
|
|
delete mRuleProcessors; // weak refs, should be empty here anyway
|
|
|
|
}
|
2015-06-26 06:52:47 +03:00
|
|
|
if (mInRuleProcessorCache) {
|
|
|
|
RuleProcessorCache::RemoveSheet(this);
|
|
|
|
}
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2012-10-08 06:39:08 +04:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::DropRuleCollection()
|
2012-10-08 06:39:08 +04:00
|
|
|
{
|
|
|
|
if (mRuleCollection) {
|
|
|
|
mRuleCollection->DropReference();
|
2012-11-12 23:19:01 +04:00
|
|
|
mRuleCollection = nullptr;
|
2012-10-08 06:39:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::DropMedia()
|
2012-10-08 06:39:08 +04:00
|
|
|
{
|
|
|
|
if (mMedia) {
|
|
|
|
mMedia->SetStyleSheet(nullptr);
|
|
|
|
mMedia = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::UnlinkInner()
|
2012-10-08 06:39:08 +04:00
|
|
|
{
|
|
|
|
// We can only have a cycle through our inner if we have a unique inner,
|
|
|
|
// because otherwise there are no JS wrappers for anything in the inner.
|
|
|
|
if (mInner->mSheets.Length() != 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mInner->mOrderedRules.EnumerateForwards(SetStyleSheetReference, nullptr);
|
|
|
|
mInner->mOrderedRules.Clear();
|
|
|
|
|
|
|
|
// Have to be a bit careful with child sheets, because we want to
|
|
|
|
// drop their mNext pointers and null out their mParent and
|
|
|
|
// mDocument, but don't want to work with deleted objects. And we
|
|
|
|
// don't want to do any addrefing in the process, just to make sure
|
|
|
|
// we don't confuse the cycle collector (though on the face of it,
|
|
|
|
// addref/release pairs during unlink should probably be ok).
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet> child;
|
2012-10-08 06:39:08 +04:00
|
|
|
child.swap(mInner->mFirstChild);
|
|
|
|
while (child) {
|
|
|
|
MOZ_ASSERT(child->mParent == this, "We have a unique inner!");
|
|
|
|
child->mParent = nullptr;
|
|
|
|
child->mDocument = nullptr;
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet> next;
|
2012-10-08 06:39:08 +04:00
|
|
|
// Null out child->mNext, but don't let it die yet
|
|
|
|
next.swap(child->mNext);
|
|
|
|
// Switch to looking at the old value of child->mNext next iteration
|
|
|
|
child.swap(next);
|
|
|
|
// "next" is now our previous value of child; it'll get released
|
|
|
|
// as we loop around.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::TraverseInner(nsCycleCollectionTraversalCallback &cb)
|
2012-10-08 06:39:08 +04:00
|
|
|
{
|
|
|
|
// We can only have a cycle through our inner if we have a unique inner,
|
|
|
|
// because otherwise there are no JS wrappers for anything in the inner.
|
|
|
|
if (mInner->mSheets.Length() != 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet>* childSheetSlot = &mInner->mFirstChild;
|
2012-10-08 06:39:08 +04:00
|
|
|
while (*childSheetSlot) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "child sheet");
|
|
|
|
cb.NoteXPCOMChild(NS_ISUPPORTS_CAST(nsIStyleSheet*, childSheetSlot->get()));
|
|
|
|
childSheetSlot = &(*childSheetSlot)->mNext;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsCOMArray<css::Rule>& rules = mInner->mOrderedRules;
|
|
|
|
for (int32_t i = 0, count = rules.Count(); i < count; ++i) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mOrderedRules[i]");
|
|
|
|
cb.NoteXPCOMChild(rules[i]->GetExistingDOMRule());
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
// QueryInterface implementation for CSSStyleSheet
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSStyleSheet)
|
2013-03-17 18:42:09 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
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(nsIStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMStyleSheet)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleSheet)
|
2002-08-06 09:08:47 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSLoaderObserver)
|
2010-05-12 00:41:47 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleSheet)
|
2014-06-20 14:32:49 +04:00
|
|
|
if (aIID.Equals(NS_GET_IID(CSSStyleSheet)))
|
2010-05-12 00:41:47 +04:00
|
|
|
foundInterface = reinterpret_cast<nsISupports*>(this);
|
|
|
|
else
|
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_END
|
|
|
|
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(CSSStyleSheet)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(CSSStyleSheet)
|
2012-10-08 06:39:08 +04:00
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(CSSStyleSheet)
|
2013-08-02 05:29:05 +04:00
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(CSSStyleSheet)
|
2012-10-08 06:39:08 +04:00
|
|
|
tmp->DropMedia();
|
|
|
|
// We do not unlink mNext; our parent will handle that. If we
|
|
|
|
// unlinked it here, our parent would not be able to walk its list
|
|
|
|
// of child sheets and null out the back-references to it, if we got
|
|
|
|
// unlinked before it does.
|
|
|
|
tmp->DropRuleCollection();
|
|
|
|
tmp->UnlinkInner();
|
2013-01-09 03:25:47 +04:00
|
|
|
tmp->mScopeElement = nullptr;
|
2013-03-17 18:42:09 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER
|
2012-10-08 06:39:08 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2014-06-20 14:32:49 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(CSSStyleSheet)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mMedia)
|
2012-10-08 06:39:08 +04:00
|
|
|
// We do not traverse mNext; our parent will handle that. See
|
|
|
|
// comments in Unlink for why.
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRuleCollection)
|
2013-01-09 03:25:47 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mScopeElement)
|
2012-10-08 06:39:08 +04:00
|
|
|
tmp->TraverseInner(cb);
|
2013-03-17 18:42:09 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
2012-10-08 06:39:08 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2014-06-20 14:32:49 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_WRAPPERCACHE(CSSStyleSheet)
|
1998-04-14 00:24:54 +04:00
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
nsresult
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::AddRuleProcessor(nsCSSRuleProcessor* aProcessor)
|
2004-07-28 11:08:41 +04:00
|
|
|
{
|
|
|
|
if (! mRuleProcessors) {
|
2009-02-03 17:42:18 +03:00
|
|
|
mRuleProcessors = new nsAutoTArray<nsCSSRuleProcessor*, 8>();
|
2004-07-28 11:08:41 +04:00
|
|
|
if (!mRuleProcessors)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
2009-05-19 02:13:12 +04:00
|
|
|
NS_ASSERTION(mRuleProcessors->NoIndex == mRuleProcessors->IndexOf(aProcessor),
|
2004-07-28 11:08:41 +04:00
|
|
|
"processor already registered");
|
|
|
|
mRuleProcessors->AppendElement(aProcessor); // weak ref
|
1999-10-08 07:09:31 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
nsresult
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::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
|
|
|
}
|
|
|
|
|
2015-06-26 06:49:58 +03:00
|
|
|
void
|
|
|
|
CSSStyleSheet::AddStyleSet(nsStyleSet* aStyleSet)
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mStyleSets.Contains(aStyleSet),
|
|
|
|
"style set already registered");
|
|
|
|
mStyleSets.AppendElement(aStyleSet);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CSSStyleSheet::DropStyleSet(nsStyleSet* aStyleSet)
|
|
|
|
{
|
|
|
|
DebugOnly<bool> found = mStyleSets.RemoveElement(aStyleSet);
|
|
|
|
NS_ASSERTION(found, "didn't find style set");
|
|
|
|
}
|
1998-12-20 04:17:05 +03:00
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::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;
|
1998-12-20 04:17:05 +03:00
|
|
|
}
|
|
|
|
|
2007-05-01 23:26:15 +04:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::SetPrincipal(nsIPrincipal* aPrincipal)
|
2007-05-01 23:26:15 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mInner->mPrincipalSet,
|
|
|
|
"Should have an inner whose principal has not yet been set");
|
|
|
|
if (aPrincipal) {
|
|
|
|
mInner->mPrincipal = aPrincipal;
|
|
|
|
#ifdef DEBUG
|
2011-10-17 18:59:28 +04:00
|
|
|
mInner->mPrincipalSet = true;
|
2007-05-01 23:26:15 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-18 08:00:39 +04:00
|
|
|
/* virtual */ nsIURI*
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetSheetURI() const
|
1998-12-20 04:17:05 +03:00
|
|
|
{
|
2010-05-18 08:00:39 +04:00
|
|
|
return mInner->mSheetURI;
|
2004-09-10 10:45:59 +04:00
|
|
|
}
|
|
|
|
|
2010-05-18 08:00:39 +04:00
|
|
|
/* virtual */ nsIURI*
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetBaseURI() const
|
2004-09-10 10:45:59 +04:00
|
|
|
{
|
2010-05-18 08:00:39 +04:00
|
|
|
return mInner->mBaseURI;
|
1998-12-20 04:17:05 +03:00
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::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
|
|
|
}
|
1998-12-11 05:50:43 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::UseForPresentation(nsPresContext* aPresContext,
|
|
|
|
nsMediaQueryResultCacheKey& aKey) const
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
|
|
|
if (mMedia) {
|
2011-04-22 07:17:31 +04:00
|
|
|
return mMedia->Matches(aPresContext, &aKey);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1998-05-21 00:34:17 +04:00
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::SetMedia(nsMediaList* aMedia)
|
1999-02-27 10:17:52 +03:00
|
|
|
{
|
2005-03-30 04:36:57 +04:00
|
|
|
mMedia = aMedia;
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* virtual */ bool
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::HasRules() const
|
2003-07-04 05:44:24 +04:00
|
|
|
{
|
2010-05-12 00:41:47 +04:00
|
|
|
return StyleRuleCount() != 0;
|
2003-07-04 05:44:24 +04:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* virtual */ bool
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::IsApplicable() const
|
1998-05-21 00:34:17 +04:00
|
|
|
{
|
2010-05-13 00:18:47 +04:00
|
|
|
return !mDisabled && mInner->mComplete;
|
1998-05-21 00:34:17 +04:00
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::SetEnabled(bool 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
|
2011-09-29 10:19:26 +04:00
|
|
|
bool oldDisabled = mDisabled;
|
2007-01-11 22:32:31 +03:00
|
|
|
mDisabled = !aEnabled;
|
|
|
|
|
2008-11-26 00:27:54 +03:00
|
|
|
if (mInner->mComplete && oldDisabled != mDisabled) {
|
2007-01-11 22:32:31 +03:00
|
|
|
ClearRuleCascades();
|
|
|
|
|
2008-11-26 00:27:54 +03:00
|
|
|
if (mDocument) {
|
|
|
|
mDocument->SetStyleSheetApplicableState(this, !mDisabled);
|
|
|
|
}
|
2007-01-11 22:32:31 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
1998-11-03 23:33:43 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
/* virtual */ bool
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::IsComplete() const
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
2010-05-13 00:18:47 +04:00
|
|
|
return mInner->mComplete;
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::SetComplete()
|
2002-12-03 08:48:14 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(!mDirty, "Can't set a dirty sheet complete!");
|
2011-10-17 18:59:28 +04:00
|
|
|
mInner->mComplete = true;
|
2002-12-03 08:48:14 +03:00
|
|
|
if (mDocument && !mDisabled) {
|
|
|
|
// Let the document know
|
2003-10-03 01:29:40 +04:00
|
|
|
mDocument->BeginUpdate(UPDATE_STYLE);
|
2011-10-17 18:59:28 +04:00
|
|
|
mDocument->SetStyleSheetApplicableState(this, true);
|
2003-10-03 01:29:40 +04:00
|
|
|
mDocument->EndUpdate(UPDATE_STYLE);
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
2014-06-07 12:42:54 +04:00
|
|
|
|
|
|
|
if (mOwningNode && !mDisabled &&
|
|
|
|
mOwningNode->HasFlag(NODE_IS_IN_SHADOW_TREE) &&
|
|
|
|
mOwningNode->IsContent()) {
|
|
|
|
ShadowRoot* shadowRoot = mOwningNode->AsContent()->GetContainingShadow();
|
|
|
|
shadowRoot->StyleSheetChanged();
|
|
|
|
}
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
2010-05-18 08:00:39 +04:00
|
|
|
/* virtual */ nsIStyleSheet*
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetParentSheet() const
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2010-05-13 00:18:47 +04:00
|
|
|
return mParent;
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
1998-05-19 01:10:19 +04:00
|
|
|
|
2010-05-18 08:00:39 +04:00
|
|
|
/* virtual */ nsIDocument*
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetOwningDocument() const
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2010-05-13 00:18:47 +04:00
|
|
|
return mDocument;
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
1998-11-03 23:33:43 +03:00
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::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....
|
2008-09-09 22:08:11 +04:00
|
|
|
// XXXbz this is a little bogus; see the XXX comment where we
|
|
|
|
// declare mFirstChild.
|
2014-06-20 14:32:49 +04:00
|
|
|
for (CSSStyleSheet* child = mInner->mFirstChild;
|
2008-09-09 22:08:11 +04:00
|
|
|
child; child = child->mNext) {
|
|
|
|
if (child->mParent == this) {
|
|
|
|
child->SetOwningDocument(aDocument);
|
|
|
|
}
|
2003-03-17 06:44:02 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
1998-05-19 01:10:19 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::FindOwningWindowInnerID() const
|
2010-12-20 19:21:59 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint64_t windowID = 0;
|
2010-12-20 19:21:59 +03:00
|
|
|
if (mDocument) {
|
2011-08-25 00:44:35 +04:00
|
|
|
windowID = mDocument->InnerWindowID();
|
2010-12-20 19:21:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (windowID == 0 && mOwningNode) {
|
2013-03-17 18:42:59 +04:00
|
|
|
windowID = mOwningNode->OwnerDoc()->InnerWindowID();
|
2010-12-20 19:21:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (windowID == 0 && mOwnerRule) {
|
2011-04-06 11:11:42 +04:00
|
|
|
nsCOMPtr<nsIStyleSheet> sheet = static_cast<css::Rule*>(mOwnerRule)->GetStyleSheet();
|
2010-12-20 19:21:59 +03:00
|
|
|
if (sheet) {
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet> cssSheet = do_QueryObject(sheet);
|
2010-12-20 19:21:59 +03:00
|
|
|
if (cssSheet) {
|
2011-08-25 00:44:35 +04:00
|
|
|
windowID = cssSheet->FindOwningWindowInnerID();
|
2010-12-20 19:21:59 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (windowID == 0 && mParent) {
|
2011-08-25 00:44:35 +04:00
|
|
|
windowID = mParent->FindOwningWindowInnerID();
|
2010-12-20 19:21:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return windowID;
|
|
|
|
}
|
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::AppendStyleSheet(CSSStyleSheet* aSheet)
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(nullptr != aSheet, "null arg");
|
1999-02-27 10:17:52 +03:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
WillDirty();
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet>* tail = &mInner->mFirstChild;
|
2013-11-11 12:00:46 +04:00
|
|
|
while (*tail) {
|
|
|
|
tail = &(*tail)->mNext;
|
1998-05-19 01:10:19 +04:00
|
|
|
}
|
2013-11-11 12:00:46 +04:00
|
|
|
*tail = aSheet;
|
|
|
|
|
|
|
|
// This is not reference counted. Our parent tells us when
|
|
|
|
// it's going away.
|
|
|
|
aSheet->mParent = this;
|
|
|
|
aSheet->mDocument = mDocument;
|
|
|
|
DidDirty();
|
1998-05-19 01:10:19 +04:00
|
|
|
}
|
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::InsertStyleSheetAt(CSSStyleSheet* aSheet, int32_t aIndex)
|
1998-05-19 01:10:19 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(nullptr != aSheet, "null arg");
|
1998-05-19 01:10:19 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
WillDirty();
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet>* tail = &mInner->mFirstChild;
|
2013-11-11 12:00:46 +04:00
|
|
|
while (*tail && aIndex) {
|
|
|
|
--aIndex;
|
|
|
|
tail = &(*tail)->mNext;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2013-11-11 12:00:46 +04:00
|
|
|
aSheet->mNext = *tail;
|
|
|
|
*tail = aSheet;
|
|
|
|
|
|
|
|
// This is not reference counted. Our parent tells us when
|
|
|
|
// it's going away.
|
|
|
|
aSheet->mParent = this;
|
|
|
|
aSheet->mDocument = mDocument;
|
|
|
|
DidDirty();
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::PrependStyleRule(css::Rule* aRule)
|
1999-04-20 04:05:54 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(nullptr != aRule, "null arg");
|
1999-04-20 04:05:54 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
WillDirty();
|
|
|
|
mInner->mOrderedRules.InsertObjectAt(aRule, 0);
|
|
|
|
aRule->SetStyleSheet(this);
|
|
|
|
DidDirty();
|
2005-10-16 00:21:20 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
if (css::Rule::NAMESPACE_RULE == aRule->GetType()) {
|
|
|
|
// 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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::AppendStyleRule(css::Rule* aRule)
|
1999-04-20 04:05:54 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(nullptr != aRule, "null arg");
|
1999-05-27 03:55:12 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
WillDirty();
|
|
|
|
mInner->mOrderedRules.AppendObject(aRule);
|
|
|
|
aRule->SetStyleSheet(this);
|
|
|
|
DidDirty();
|
2005-10-16 00:21:20 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
if (css::Rule::NAMESPACE_RULE == aRule->GetType()) {
|
2010-07-11 16:47:45 +04:00
|
|
|
#ifdef DEBUG
|
2013-11-11 12:00:46 +04:00
|
|
|
nsresult rv =
|
2010-07-11 16:47:45 +04:00
|
|
|
#endif
|
2013-11-11 12:00:46 +04:00
|
|
|
RegisterNamespaceRule(aRule);
|
|
|
|
NS_WARN_IF_FALSE(NS_SUCCEEDED(rv),
|
|
|
|
"RegisterNamespaceRule returned error");
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
}
|
1999-04-20 04:05:54 +04:00
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::ReplaceStyleRule(css::Rule* aOld, css::Rule* 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
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
WillDirty();
|
|
|
|
int32_t index = mInner->mOrderedRules.IndexOf(aOld);
|
|
|
|
if (MOZ_UNLIKELY(index == -1)) {
|
|
|
|
NS_NOTREACHED("Couldn't find old rule");
|
|
|
|
return;
|
2003-06-18 05:59:57 +04:00
|
|
|
}
|
2013-11-11 12:00:46 +04:00
|
|
|
mInner->mOrderedRules.ReplaceObjectAt(aNew, index);
|
|
|
|
|
|
|
|
aNew->SetStyleSheet(this);
|
|
|
|
aOld->SetStyleSheet(nullptr);
|
|
|
|
DidDirty();
|
|
|
|
NS_ASSERTION(css::Rule::NAMESPACE_RULE != aNew->GetType(), "not yet implemented");
|
|
|
|
NS_ASSERTION(css::Rule::NAMESPACE_RULE != aOld->GetType(), "not yet implemented");
|
2003-06-18 05:59:57 +04:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::StyleRuleCount() const
|
1998-12-03 23:20:35 +03:00
|
|
|
{
|
2010-05-12 00:41:47 +04:00
|
|
|
return mInner->mOrderedRules.Count();
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
1999-06-03 05:57:52 +04:00
|
|
|
|
2013-07-08 00:23:13 +04:00
|
|
|
css::Rule*
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetStyleRuleAt(int32_t aIndex) 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.
|
2013-07-08 00:23:13 +04:00
|
|
|
return mInner->mOrderedRules.SafeObjectAt(aIndex);
|
1998-12-03 23:20:35 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::StyleSheetCount() 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.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t count = 0;
|
1999-10-14 04:59:21 +04:00
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
const CSSStyleSheet* child = mInner->mFirstChild;
|
1999-10-14 04:59:21 +04:00
|
|
|
while (child) {
|
2010-05-12 00:41:47 +04:00
|
|
|
count++;
|
1999-10-14 04:59:21 +04:00
|
|
|
child = child->mNext;
|
|
|
|
}
|
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
return count;
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2015-06-26 06:49:58 +03:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::EnsureUniqueInner()
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
mDirty = true;
|
2011-04-12 10:18:43 +04:00
|
|
|
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mInner->mSheets.Length() != 0,
|
|
|
|
"unexpected number of outers");
|
2009-12-31 18:56:33 +03:00
|
|
|
if (mInner->mSheets.Length() == 1) {
|
2015-06-26 06:49:58 +03:00
|
|
|
// already unique
|
|
|
|
return;
|
1999-05-13 08:56:04 +04:00
|
|
|
}
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheetInner* clone = mInner->CloneFor(this);
|
2013-11-11 12:00:18 +04:00
|
|
|
MOZ_ASSERT(clone);
|
2009-12-31 18:56:33 +03:00
|
|
|
mInner->RemoveSheet(this);
|
|
|
|
mInner = clone;
|
2009-12-31 18:56:33 +03:00
|
|
|
|
|
|
|
// otherwise the rule processor has pointers to the old rules
|
|
|
|
ClearRuleCascades();
|
|
|
|
|
2015-06-26 06:49:58 +03:00
|
|
|
// let our containing style sets know that if we call
|
|
|
|
// nsPresContext::EnsureSafeToHandOutCSSRules we will need to restyle the
|
|
|
|
// document
|
|
|
|
for (nsStyleSet* styleSet : mStyleSets) {
|
|
|
|
styleSet->SetNeedsRestyleAfterEnsureUniqueInner();
|
|
|
|
}
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2013-11-11 11:59:58 +04:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::AppendAllChildSheets(nsTArray<CSSStyleSheet*>& aArray)
|
2009-12-31 18:56:33 +03:00
|
|
|
{
|
2014-06-20 14:32:49 +04:00
|
|
|
for (CSSStyleSheet* child = mInner->mFirstChild; child;
|
2009-12-31 18:56:33 +03:00
|
|
|
child = child->mNext) {
|
2013-11-11 11:59:58 +04:00
|
|
|
aArray.AppendElement(child);
|
2009-12-31 18:56:33 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
already_AddRefed<CSSStyleSheet>
|
|
|
|
CSSStyleSheet::Clone(CSSStyleSheet* aCloneParent,
|
|
|
|
css::ImportRule* aCloneOwnerRule,
|
|
|
|
nsIDocument* aCloneDocument,
|
|
|
|
nsINode* aCloneOwningNode) const
|
2003-02-23 07:44:41 +03:00
|
|
|
{
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet> clone = new CSSStyleSheet(*this,
|
|
|
|
aCloneParent,
|
|
|
|
aCloneOwnerRule,
|
|
|
|
aCloneDocument,
|
|
|
|
aCloneOwningNode);
|
2013-04-22 15:15:59 +04:00
|
|
|
return clone.forget();
|
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
|
2012-08-22 19:56:38 +04:00
|
|
|
ListRules(const nsCOMArray<css::Rule>& aRules, FILE* aOut, int32_t aIndent)
|
1999-06-15 10:20:46 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t index = aRules.Count() - 1; index >= 0; --index) {
|
2005-10-16 00:21:20 +04:00
|
|
|
aRules.ObjectAt(index)->List(aOut, aIndent);
|
1999-06-15 10:20:46 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
struct ListEnumData {
|
2012-08-22 19:56:38 +04:00
|
|
|
ListEnumData(FILE* aOut, int32_t aIndent)
|
1999-10-14 04:59:21 +04:00
|
|
|
: mOut(aOut),
|
|
|
|
mIndent(aIndent)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
FILE* mOut;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mIndent;
|
1999-10-14 04:59:21 +04:00
|
|
|
};
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
/* virtual */ void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::List(FILE* out, int32_t aIndent) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1999-10-14 04:59:21 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t index;
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
// Indent
|
2014-11-27 09:29:44 +03:00
|
|
|
nsAutoCString str;
|
2014-11-27 09:29:44 +03:00
|
|
|
for (index = aIndent; --index >= 0; ) {
|
2014-11-27 09:29:44 +03:00
|
|
|
str.AppendLiteral(" ");
|
2014-11-27 09:29:44 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
2014-11-27 09:29:44 +03:00
|
|
|
str.AppendLiteral("CSS Style Sheet: ");
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString 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()) {
|
2014-11-27 09:29:44 +03:00
|
|
|
str.Append(urlSpec);
|
1998-12-02 03:37:32 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
|
|
|
if (mMedia) {
|
2014-11-27 09:29:44 +03:00
|
|
|
str.AppendLiteral(" media: ");
|
1999-10-14 04:59:21 +04:00
|
|
|
nsAutoString buffer;
|
2005-03-30 04:36:57 +04:00
|
|
|
mMedia->GetText(buffer);
|
2014-11-27 09:29:44 +03:00
|
|
|
AppendUTF16toUTF8(buffer, str);
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
2014-11-27 09:29:44 +03:00
|
|
|
str.Append('\n');
|
|
|
|
fprintf_stderr(out, "%s", str.get());
|
1999-10-14 04:59:21 +04:00
|
|
|
|
2014-06-20 14:32:49 +04:00
|
|
|
for (const CSSStyleSheet* child = mInner->mFirstChild;
|
2008-09-09 22:08:11 +04:00
|
|
|
child;
|
|
|
|
child = child->mNext) {
|
1999-10-14 04:59:21 +04:00
|
|
|
child->List(out, aIndent + 1);
|
|
|
|
}
|
|
|
|
|
2014-11-27 09:29:44 +03:00
|
|
|
fprintf_stderr(out, "%s", "Rules in source order:\n");
|
1999-10-14 04:59:21 +04:00
|
|
|
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
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::ClearRuleCascades()
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2015-08-05 15:42:21 +03:00
|
|
|
// We might be in ClearRuleCascades because we had a modification
|
|
|
|
// to the sheet that resulted in an nsCSSSelector being destroyed.
|
|
|
|
// Tell the RestyleManager for each document we're used in
|
|
|
|
// so that they can drop any nsCSSSelector pointers (used for
|
|
|
|
// eRestyle_SomeDescendants) in their mPendingRestyles.
|
|
|
|
for (nsStyleSet* styleSet : mStyleSets) {
|
|
|
|
styleSet->ClearSelectors();
|
|
|
|
}
|
|
|
|
|
2015-06-26 06:52:47 +03:00
|
|
|
bool removedSheetFromRuleProcessorCache = false;
|
1999-10-14 04:59:21 +04:00
|
|
|
if (mRuleProcessors) {
|
2009-02-03 17:42:18 +03:00
|
|
|
nsCSSRuleProcessor **iter = mRuleProcessors->Elements(),
|
|
|
|
**end = iter + mRuleProcessors->Length();
|
|
|
|
for(; iter != end; ++iter) {
|
2015-06-26 06:52:47 +03:00
|
|
|
if (!removedSheetFromRuleProcessorCache && (*iter)->IsShared()) {
|
|
|
|
// Since the sheet has been modified, we need to remove all
|
|
|
|
// RuleProcessorCache entries that contain this sheet, as the
|
|
|
|
// list of @-moz-document rules might have changed.
|
|
|
|
RuleProcessorCache::RemoveSheet(this);
|
|
|
|
removedSheetFromRuleProcessorCache = true;
|
|
|
|
}
|
2009-02-03 17:42:18 +03:00
|
|
|
(*iter)->ClearRuleCascades();
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
if (mParent) {
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet* parent = (CSSStyleSheet*)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
|
|
|
}
|
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::WillDirty()
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2013-11-11 12:00:46 +04:00
|
|
|
if (mInner->mComplete) {
|
|
|
|
EnsureUniqueInner();
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::DidDirty()
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(!mInner->mComplete || mDirty,
|
|
|
|
"caller must have called WillDirty()");
|
1999-10-14 04:59:21 +04:00
|
|
|
ClearRuleCascades();
|
|
|
|
}
|
|
|
|
|
2007-07-03 22:45:39 +04:00
|
|
|
nsresult
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::SubjectSubsumesInnerPrincipal()
|
2007-07-03 22:45:39 +04:00
|
|
|
{
|
2014-05-13 13:58:00 +04:00
|
|
|
nsCOMPtr<nsIPrincipal> subjectPrincipal = nsContentUtils::SubjectPrincipal();
|
2014-05-07 02:43:03 +04:00
|
|
|
if (subjectPrincipal->Subsumes(mInner->mPrincipal)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2007-07-03 22:45:39 +04:00
|
|
|
|
2014-05-07 02:43:03 +04:00
|
|
|
// Allow access only if CORS mode is not NONE
|
|
|
|
if (GetCORSMode() == CORS_NONE) {
|
2008-01-18 08:23:44 +03:00
|
|
|
return NS_ERROR_DOM_SECURITY_ERR;
|
2007-07-03 22:45:39 +04:00
|
|
|
}
|
|
|
|
|
2014-05-07 02:43:03 +04:00
|
|
|
// Now make sure we set the principal of our inner to the
|
|
|
|
// subjectPrincipal. That means we need a unique inner, of
|
|
|
|
// course. But we don't want to do that if we're not complete
|
|
|
|
// yet. Luckily, all the callers of this method throw anyway if
|
|
|
|
// not complete, so we can just do that here too.
|
|
|
|
if (!mInner->mComplete) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
2007-07-03 22:45:39 +04:00
|
|
|
}
|
2012-08-28 21:10:09 +04:00
|
|
|
|
2014-05-07 02:43:03 +04:00
|
|
|
WillDirty();
|
2012-08-28 21:10:09 +04:00
|
|
|
|
2014-05-07 02:43:03 +04:00
|
|
|
mInner->mPrincipal = subjectPrincipal;
|
2012-08-28 21:10:09 +04:00
|
|
|
|
2014-05-07 02:43:03 +04:00
|
|
|
DidDirty();
|
2007-07-03 22:45:39 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-10-16 00:23:21 +04:00
|
|
|
nsresult
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::RegisterNamespaceRule(css::Rule* aRule)
|
2008-10-16 00:23:21 +04:00
|
|
|
{
|
|
|
|
if (!mInner->mNameSpaceMap) {
|
|
|
|
nsresult rv = mInner->CreateNamespaceMap();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
|
|
|
AddNamespaceRuleToMap(aRule, mInner->mNameSpaceMap);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
// nsIDOMStyleSheet interface
|
|
|
|
NS_IMETHODIMP
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::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
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetDisabled(bool* aDisabled)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2013-03-17 18:42:59 +04:00
|
|
|
*aDisabled = Disabled();
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::SetDisabled(bool aDisabled)
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2007-01-11 22:32:31 +03:00
|
|
|
// DOM method, so handle BeginUpdate/EndUpdate
|
2011-10-17 18:59:28 +04:00
|
|
|
MOZ_AUTO_DOC_UPDATE(mDocument, UPDATE_STYLE, true);
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::SetEnabled(!aDisabled);
|
2010-05-13 00:18:47 +04:00
|
|
|
return NS_OK;
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetOwnerNode(nsIDOMNode** aOwnerNode)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2013-03-17 18:42:59 +04:00
|
|
|
nsCOMPtr<nsIDOMNode> ownerNode = do_QueryInterface(GetOwnerNode());
|
|
|
|
ownerNode.forget(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
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetParentStyleSheet(nsIDOMStyleSheet** aParentStyleSheet)
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aParentStyleSheet);
|
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
NS_IF_ADDREF(*aParentStyleSheet = mParent);
|
2000-04-26 17:58:56 +04:00
|
|
|
|
2010-05-14 23:05:14 +04:00
|
|
|
return NS_OK;
|
1998-11-26 04:34:53 +03:00
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetHref(nsAString& aHref)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2007-10-24 01:56:41 +04:00
|
|
|
if (mInner->mOriginalSheetURI) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString str;
|
2007-10-24 01:56:41 +04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2010-05-18 08:00:39 +04:00
|
|
|
/* virtual */ void
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetTitle(nsString& aTitle) const
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
|
|
|
aTitle = mTitle;
|
|
|
|
}
|
|
|
|
|
1999-05-19 03:14:29 +04:00
|
|
|
NS_IMETHODIMP
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::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
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetMedia(nsIDOMMediaList** aMedia)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2013-03-17 18:42:59 +04:00
|
|
|
NS_ADDREF(*aMedia = Media());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-04-26 17:58:56 +04:00
|
|
|
|
2013-11-11 12:03:17 +04:00
|
|
|
nsMediaList*
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::Media()
|
2013-03-17 18:42:59 +04:00
|
|
|
{
|
2000-04-26 17:58:56 +04:00
|
|
|
if (!mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
mMedia = new nsMediaList();
|
|
|
|
mMedia->SetStyleSheet(this);
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
2000-04-26 17:58:56 +04:00
|
|
|
|
2013-03-17 18:42:59 +04:00
|
|
|
return mMedia;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetOwnerRule(nsIDOMCSSRule** aOwnerRule)
|
2000-04-26 17:58:56 +04:00
|
|
|
{
|
2013-03-17 18:42:59 +04:00
|
|
|
NS_IF_ADDREF(*aOwnerRule = GetOwnerRule());
|
2011-04-08 10:36:09 +04:00
|
|
|
return NS_OK;
|
2000-04-26 17:58:56 +04:00
|
|
|
}
|
|
|
|
|
2013-03-17 18:42:59 +04:00
|
|
|
nsIDOMCSSRule*
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetDOMOwnerRule() const
|
2013-03-17 18:42:59 +04:00
|
|
|
{
|
|
|
|
return mOwnerRule ? mOwnerRule->GetDOMRule() : nullptr;
|
|
|
|
}
|
|
|
|
|
2000-04-26 17:58:56 +04:00
|
|
|
NS_IMETHODIMP
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetCssRules(nsIDOMCSSRuleList** aCssRules)
|
2013-03-17 18:42:59 +04:00
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
nsCOMPtr<nsIDOMCSSRuleList> rules = GetCssRules(rv);
|
|
|
|
rules.forget(aCssRules);
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2013-03-17 18:42:59 +04:00
|
|
|
}
|
|
|
|
|
2014-06-10 06:11:00 +04:00
|
|
|
CSSRuleList*
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetCssRules(ErrorResult& aRv)
|
1998-04-14 00:24:54 +04:00
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
// No doing this on incomplete sheets!
|
2010-05-14 23:05:14 +04:00
|
|
|
if (!mInner->mComplete) {
|
2013-03-17 18:42:59 +04:00
|
|
|
aRv.Throw(NS_ERROR_DOM_INVALID_ACCESS_ERR);
|
|
|
|
return nullptr;
|
2002-12-03 08:48:14 +03:00
|
|
|
}
|
|
|
|
|
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();
|
2013-03-17 18:42:59 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
aRv.Throw(rv);
|
|
|
|
return nullptr;
|
|
|
|
}
|
2002-06-15 03:54:18 +04:00
|
|
|
|
|
|
|
// OK, security check passed, so get the rule collection
|
2013-03-17 18:42:59 +04:00
|
|
|
if (!mRuleCollection) {
|
2000-04-26 17:58:56 +04:00
|
|
|
mRuleCollection = new CSSRuleListImpl(this);
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
1999-06-10 09:29:22 +04:00
|
|
|
|
2013-03-17 18:42:59 +04:00
|
|
|
return mRuleCollection;
|
1999-10-14 04:59:21 +04:00
|
|
|
}
|
1999-06-10 09:29:22 +04:00
|
|
|
|
1999-10-14 04:59:21 +04:00
|
|
|
NS_IMETHODIMP
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::InsertRule(const nsAString& aRule,
|
|
|
|
uint32_t aIndex,
|
|
|
|
uint32_t* 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);
|
|
|
|
}
|
|
|
|
|
2012-06-03 20:54:38 +04:00
|
|
|
static bool
|
|
|
|
RuleHasPendingChildSheet(css::Rule *cssRule)
|
|
|
|
{
|
|
|
|
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));
|
2014-06-20 14:32:49 +04:00
|
|
|
nsRefPtr<CSSStyleSheet> cssSheet = do_QueryObject(childSheet);
|
2012-07-30 18:20:58 +04:00
|
|
|
return cssSheet != nullptr && !cssSheet->IsComplete();
|
2012-06-03 20:54:38 +04:00
|
|
|
}
|
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
nsresult
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::InsertRuleInternal(const nsAString& aRule,
|
|
|
|
uint32_t aIndex,
|
|
|
|
uint32_t* aReturn)
|
1999-10-14 04:59:21 +04:00
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
// No doing this if the sheet is not complete!
|
2010-05-14 23:05:14 +04:00
|
|
|
if (!mInner->mComplete) {
|
2002-12-03 08:48:14 +03:00
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
2004-10-06 04:34:06 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
WillDirty();
|
2001-09-06 17:14:35 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
if (aIndex > uint32_t(mInner->mOrderedRules.Count()))
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
|
2012-09-28 10:57:33 +04:00
|
|
|
NS_ASSERTION(uint32_t(mInner->mOrderedRules.Count()) <= INT32_MAX,
|
2005-10-16 00:21:20 +04:00
|
|
|
"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
|
2010-03-03 00:00:53 +03:00
|
|
|
nsRefPtr<css::Loader> 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
|
|
|
}
|
2010-03-02 23:59:32 +03:00
|
|
|
|
|
|
|
nsCSSParser css(loader, this);
|
2001-10-19 17:50:30 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2013-02-10 10:56:49 +04:00
|
|
|
nsRefPtr<css::Rule> rule;
|
2013-11-11 12:00:46 +04:00
|
|
|
nsresult result = css.ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI,
|
|
|
|
mInner->mPrincipal, getter_AddRefs(rule));
|
2001-09-05 04:00:18 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2010-03-02 23:59:32 +03:00
|
|
|
|
2013-02-10 10:56:49 +04:00
|
|
|
// Hierarchy checking.
|
|
|
|
int32_t newType = rule->GetType();
|
|
|
|
|
2001-09-06 17:14:35 +04:00
|
|
|
// check that we're not inserting before a charset rule
|
2011-04-08 05:23:46 +04:00
|
|
|
css::Rule* nextRule = mInner->mOrderedRules.SafeObjectAt(aIndex);
|
2001-09-06 17:14:35 +04:00
|
|
|
if (nextRule) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nextType = nextRule->GetType();
|
2011-04-08 05:23:46 +04:00
|
|
|
if (nextType == css::Rule::CHARSET_RULE) {
|
2001-09-06 17:14:35 +04:00
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2011-04-08 05:23:46 +04:00
|
|
|
if (nextType == css::Rule::IMPORT_RULE &&
|
2013-02-10 10:56:49 +04:00
|
|
|
newType != css::Rule::CHARSET_RULE &&
|
|
|
|
newType != css::Rule::IMPORT_RULE) {
|
2001-09-06 17:14:35 +04:00
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
2013-02-10 10:56:49 +04:00
|
|
|
|
2011-04-08 05:23:46 +04:00
|
|
|
if (nextType == css::Rule::NAMESPACE_RULE &&
|
2013-02-10 10:56:49 +04:00
|
|
|
newType != css::Rule::CHARSET_RULE &&
|
|
|
|
newType != css::Rule::IMPORT_RULE &&
|
|
|
|
newType != css::Rule::NAMESPACE_RULE) {
|
2001-09-06 17:14:35 +04:00
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
2013-02-10 10:56:49 +04:00
|
|
|
}
|
2001-09-06 17:14:35 +04:00
|
|
|
}
|
2013-02-10 10:56:49 +04:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
if (aIndex != 0) {
|
2013-02-10 10:56:49 +04:00
|
|
|
// no inserting charset at nonzero position
|
|
|
|
if (newType == css::Rule::CHARSET_RULE) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
2013-02-10 10:56:49 +04:00
|
|
|
|
2011-04-08 05:23:46 +04:00
|
|
|
css::Rule* prevRule = mInner->mOrderedRules.SafeObjectAt(aIndex - 1);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t prevType = prevRule->GetType();
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2013-02-10 10:56:49 +04:00
|
|
|
if (newType == css::Rule::IMPORT_RULE &&
|
2011-04-08 05:23:46 +04:00
|
|
|
prevType != css::Rule::CHARSET_RULE &&
|
|
|
|
prevType != css::Rule::IMPORT_RULE) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
1999-06-03 05:57:52 +04:00
|
|
|
}
|
1998-06-05 10:06:50 +04:00
|
|
|
|
2013-02-10 10:56:49 +04:00
|
|
|
if (newType == css::Rule::NAMESPACE_RULE &&
|
2011-04-08 05:23:46 +04:00
|
|
|
prevType != css::Rule::CHARSET_RULE &&
|
|
|
|
prevType != css::Rule::IMPORT_RULE &&
|
|
|
|
prevType != css::Rule::NAMESPACE_RULE) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
}
|
1998-06-05 10:06:50 +04:00
|
|
|
}
|
2013-02-10 10:56:49 +04:00
|
|
|
|
|
|
|
bool insertResult = mInner->mOrderedRules.InsertObjectAt(rule, 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();
|
|
|
|
|
2013-02-10 10:56:49 +04:00
|
|
|
rule->SetStyleSheet(this);
|
2002-08-06 09:08:47 +04:00
|
|
|
|
2013-02-10 10:56:49 +04:00
|
|
|
int32_t type = rule->GetType();
|
|
|
|
if (type == css::Rule::NAMESPACE_RULE) {
|
|
|
|
// 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(rule);
|
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We don't notify immediately for @import rules, but rather when
|
|
|
|
// the sheet the rule is importing is loaded (see StyleSheetLoaded)
|
|
|
|
if ((type != css::Rule::IMPORT_RULE || !RuleHasPendingChildSheet(rule)) &&
|
|
|
|
mDocument) {
|
|
|
|
mDocument->StyleRuleAdded(this, rule);
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
2012-06-03 20:54:38 +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
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::DeleteRule(uint32_t aIndex)
|
1998-06-05 10:06:50 +04:00
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
// No doing this if the sheet is not complete!
|
2010-05-14 23:05:14 +04:00
|
|
|
if (!mInner->mComplete) {
|
2002-12-03 08:48:14 +03:00
|
|
|
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
|
2011-10-17 18:59:28 +04:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
|
2003-10-16 22:14:25 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
WillDirty();
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
if (aIndex >= uint32_t(mInner->mOrderedRules.Count()))
|
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
1999-10-14 04:59:21 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
NS_ASSERTION(uint32_t(mInner->mOrderedRules.Count()) <= INT32_MAX,
|
|
|
|
"Too many style rules!");
|
2005-10-16 00:21:20 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
// Hold a strong ref to the rule so it doesn't die when we RemoveObjectAt
|
|
|
|
nsRefPtr<css::Rule> rule = mInner->mOrderedRules.ObjectAt(aIndex);
|
|
|
|
if (rule) {
|
|
|
|
mInner->mOrderedRules.RemoveObjectAt(aIndex);
|
|
|
|
if (mDocument && mDocument->StyleSheetChangeEventsEnabled()) {
|
|
|
|
// Force creation of the DOM rule, so that it can be put on the
|
|
|
|
// StyleRuleRemoved event object.
|
|
|
|
rule->GetDOMRule();
|
|
|
|
}
|
|
|
|
rule->SetStyleSheet(nullptr);
|
|
|
|
DidDirty();
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
if (mDocument) {
|
|
|
|
mDocument->StyleRuleRemoved(this, rule);
|
1998-06-05 10:06:50 +04:00
|
|
|
}
|
|
|
|
}
|
1999-10-14 04:59:21 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
return NS_OK;
|
1998-04-14 00:24:54 +04:00
|
|
|
}
|
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
nsresult
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::DeleteRuleFromGroup(css::GroupRule* aGroup, uint32_t 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!");
|
2011-04-08 05:23:46 +04:00
|
|
|
nsRefPtr<css::Rule> rule = aGroup->GetStyleRuleAt(aIndex);
|
2010-08-08 09:29:28 +04:00
|
|
|
NS_ENSURE_TRUE(rule, NS_ERROR_ILLEGAL_VALUE);
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
// check that the rule actually belongs to this sheet!
|
2010-08-08 09:33:15 +04:00
|
|
|
if (this != rule->GetStyleSheet()) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
|
2003-10-16 22:14:25 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
WillDirty();
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
nsresult result = aGroup->DeleteStyleRuleAt(aIndex);
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
rule->SetStyleSheet(nullptr);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
nsresult
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::InsertRuleIntoGroup(const nsAString & aRule,
|
|
|
|
css::GroupRule* aGroup,
|
|
|
|
uint32_t aIndex,
|
|
|
|
uint32_t* _retval)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
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!
|
2010-08-08 09:33:15 +04:00
|
|
|
if (this != aGroup->GetStyleSheet()) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2004-01-14 02:14:49 +03:00
|
|
|
// Hold strong ref to the CSSLoader in case the document update
|
|
|
|
// kills the document
|
2010-03-03 00:00:53 +03:00
|
|
|
nsRefPtr<css::Loader> 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
|
|
|
|
2010-03-02 23:59:32 +03:00
|
|
|
nsCSSParser css(loader, this);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2003-10-16 22:14:25 +04:00
|
|
|
// parse and grab the rule
|
2011-10-17 18:59:28 +04:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
WillDirty();
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2013-02-10 10:56:49 +04:00
|
|
|
nsRefPtr<css::Rule> rule;
|
2013-11-11 12:00:46 +04:00
|
|
|
nsresult result = css.ParseRule(aRule, mInner->mSheetURI, mInner->mBaseURI,
|
|
|
|
mInner->mPrincipal, getter_AddRefs(rule));
|
2013-02-10 10:56:49 +04:00
|
|
|
if (NS_FAILED(result))
|
|
|
|
return result;
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2013-02-10 10:56:49 +04:00
|
|
|
switch (rule->GetType()) {
|
|
|
|
case css::Rule::STYLE_RULE:
|
|
|
|
case css::Rule::MEDIA_RULE:
|
|
|
|
case css::Rule::FONT_FACE_RULE:
|
|
|
|
case css::Rule::PAGE_RULE:
|
|
|
|
case css::Rule::KEYFRAMES_RULE:
|
2014-06-12 05:10:00 +04:00
|
|
|
case css::Rule::COUNTER_STYLE_RULE:
|
2013-02-10 10:56:49 +04:00
|
|
|
case css::Rule::DOCUMENT_RULE:
|
|
|
|
case css::Rule::SUPPORTS_RULE:
|
|
|
|
// these types are OK to insert into a group
|
|
|
|
break;
|
|
|
|
case css::Rule::CHARSET_RULE:
|
|
|
|
case css::Rule::IMPORT_RULE:
|
|
|
|
case css::Rule::NAMESPACE_RULE:
|
|
|
|
// these aren't
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("unexpected rule type");
|
|
|
|
return NS_ERROR_DOM_HIERARCHY_REQUEST_ERR;
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
2013-02-10 10:56:49 +04:00
|
|
|
|
|
|
|
result = aGroup->InsertStyleRuleAt(aIndex, rule);
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_ENSURE_SUCCESS(result, result);
|
|
|
|
DidDirty();
|
2013-02-10 10:56:49 +04:00
|
|
|
|
|
|
|
if (mDocument) {
|
|
|
|
mDocument->StyleRuleAdded(this, rule);
|
2001-09-06 17:14:35 +04:00
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
|
|
|
|
*_retval = aIndex;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-12 00:41:47 +04:00
|
|
|
nsresult
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::ReplaceRuleInGroup(css::GroupRule* aGroup,
|
|
|
|
css::Rule* aOld, css::Rule* aNew)
|
2003-06-18 05:59:57 +04:00
|
|
|
{
|
2007-05-01 23:26:15 +04:00
|
|
|
NS_PRECONDITION(mInner->mComplete, "No replacing in an incomplete sheet!");
|
2010-08-08 09:33:15 +04:00
|
|
|
NS_ASSERTION(this == aGroup->GetStyleSheet(), "group doesn't belong to this sheet");
|
2003-06-18 05:59:57 +04:00
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
WillDirty();
|
|
|
|
|
|
|
|
nsresult result = aGroup->ReplaceStyleRule(aOld, aNew);
|
2003-06-18 05:59:57 +04:00
|
|
|
DidDirty();
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2002-08-06 09:08:47 +04:00
|
|
|
// nsICSSLoaderObserver implementation
|
|
|
|
NS_IMETHODIMP
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::StyleSheetLoaded(CSSStyleSheet* aSheet,
|
|
|
|
bool aWasAlternate,
|
|
|
|
nsresult aStatus)
|
2002-08-06 09:08:47 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
if (aSheet->GetParentSheet() == nullptr) {
|
2012-06-03 20:54:38 +04:00
|
|
|
return NS_OK; // ignore if sheet has been detached already (see parseSheet)
|
|
|
|
}
|
2010-05-18 08:00:40 +04:00
|
|
|
NS_ASSERTION(this == aSheet->GetParentSheet(),
|
|
|
|
"We are being notified of a sheet load for a sheet that is not our child!");
|
|
|
|
|
2005-09-12 22:41:15 +04:00
|
|
|
if (mDocument && NS_SUCCEEDED(aStatus)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, 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)!
|
2011-03-17 20:41:52 +03:00
|
|
|
mDocument->StyleRuleAdded(this, aSheet->GetOwnerRule());
|
2002-08-06 09:08:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-06-03 20:54:38 +04:00
|
|
|
nsresult
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::ParseSheet(const nsAString& aInput)
|
2012-06-03 20:54:38 +04:00
|
|
|
{
|
|
|
|
// Not doing this if the sheet is not complete!
|
|
|
|
if (!mInner->mComplete) {
|
|
|
|
return NS_ERROR_DOM_INVALID_ACCESS_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hold strong ref to the CSSLoader in case the document update
|
|
|
|
// kills the document
|
|
|
|
nsRefPtr<css::Loader> loader;
|
|
|
|
if (mDocument) {
|
|
|
|
loader = mDocument->CSSLoader();
|
|
|
|
NS_ASSERTION(loader, "Document with no CSS loader!");
|
|
|
|
} else {
|
|
|
|
loader = new css::Loader();
|
|
|
|
}
|
|
|
|
|
|
|
|
mozAutoDocUpdate updateBatch(mDocument, UPDATE_STYLE, true);
|
|
|
|
|
2013-11-11 12:00:46 +04:00
|
|
|
WillDirty();
|
2012-06-03 20:54:38 +04:00
|
|
|
|
|
|
|
// detach existing rules (including child sheets via import rules)
|
|
|
|
int ruleCount;
|
|
|
|
while ((ruleCount = mInner->mOrderedRules.Count()) != 0) {
|
|
|
|
nsRefPtr<css::Rule> rule = mInner->mOrderedRules.ObjectAt(ruleCount - 1);
|
|
|
|
mInner->mOrderedRules.RemoveObjectAt(ruleCount - 1);
|
2012-07-30 18:20:58 +04:00
|
|
|
rule->SetStyleSheet(nullptr);
|
2012-06-03 20:54:38 +04:00
|
|
|
if (mDocument) {
|
|
|
|
mDocument->StyleRuleRemoved(this, rule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// nuke child sheets list and current namespace map
|
2014-06-20 14:32:49 +04:00
|
|
|
for (CSSStyleSheet* child = mInner->mFirstChild; child; child = child->mNext) {
|
2012-06-03 20:54:38 +04:00
|
|
|
NS_ASSERTION(child->mParent == this, "Child sheet is not parented to this!");
|
2012-07-30 18:20:58 +04:00
|
|
|
child->mParent = nullptr;
|
|
|
|
child->mDocument = nullptr;
|
2012-06-03 20:54:38 +04:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
mInner->mFirstChild = nullptr;
|
|
|
|
mInner->mNameSpaceMap = nullptr;
|
2012-06-03 20:54:38 +04:00
|
|
|
|
|
|
|
// allow unsafe rules if the style sheet's principal is the system principal
|
|
|
|
bool allowUnsafeRules = nsContentUtils::IsSystemPrincipal(mInner->mPrincipal);
|
2012-09-06 03:10:55 +04:00
|
|
|
|
|
|
|
nsCSSParser parser(loader, this);
|
2013-11-11 12:00:46 +04:00
|
|
|
nsresult rv = parser.ParseSheet(aInput, mInner->mSheetURI, mInner->mBaseURI,
|
|
|
|
mInner->mPrincipal, 1, allowUnsafeRules);
|
2012-06-03 20:54:38 +04:00
|
|
|
DidDirty(); // we are always 'dirty' here since we always remove rules first
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// notify document of all new rules
|
|
|
|
if (mDocument) {
|
2012-08-22 19:56:38 +04:00
|
|
|
for (int32_t index = 0; index < mInner->mOrderedRules.Count(); ++index) {
|
2012-06-03 20:54:38 +04:00
|
|
|
nsRefPtr<css::Rule> rule = mInner->mOrderedRules.ObjectAt(index);
|
|
|
|
if (rule->GetType() == css::Rule::IMPORT_RULE &&
|
|
|
|
RuleHasPendingChildSheet(rule)) {
|
|
|
|
continue; // notify when loaded (see StyleSheetLoaded)
|
|
|
|
}
|
|
|
|
mDocument->StyleRuleAdded(this, rule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-05-12 00:41:48 +04:00
|
|
|
/* virtual */ nsIURI*
|
2014-06-20 14:32:49 +04:00
|
|
|
CSSStyleSheet::GetOriginalURI() const
|
2009-03-10 16:52:23 +03:00
|
|
|
{
|
|
|
|
return mInner->mOriginalSheetURI;
|
|
|
|
}
|
2013-03-17 18:45:01 +04:00
|
|
|
|
|
|
|
/* virtual */
|
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
CSSStyleSheet::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-03-17 18:45:01 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return CSSStyleSheetBinding::Wrap(aCx, this, aGivenProto);
|
2013-03-17 18:45:01 +04:00
|
|
|
}
|
2014-06-20 14:32:49 +04:00
|
|
|
|
|
|
|
} // namespace mozilla
|