2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 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
|
|
|
|
|
|
|
/*
|
|
|
|
* internal interface representing CSS style rules that contain other
|
|
|
|
* rules, such as @media rules
|
|
|
|
*/
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
#ifndef mozilla_css_GroupRule_h__
|
|
|
|
#define mozilla_css_GroupRule_h__
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2013-05-14 20:33:23 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2017-01-13 18:41:03 +03:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2015-06-15 22:34:23 +03:00
|
|
|
#include "mozilla/IncrementalClearCOMRuleArray.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2017-03-09 14:02:26 +03:00
|
|
|
#include "mozilla/Variant.h"
|
2011-04-08 05:23:46 +04:00
|
|
|
#include "mozilla/css/Rule.h"
|
2012-10-08 06:39:09 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
class nsPresContext;
|
2008-07-26 20:14:48 +04:00
|
|
|
class nsMediaQueryResultCacheKey;
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
namespace mozilla {
|
2014-06-20 14:32:49 +04:00
|
|
|
|
2016-11-23 02:26:20 +03:00
|
|
|
class StyleSheet;
|
2014-06-20 14:32:49 +04:00
|
|
|
|
2017-01-13 18:41:03 +03:00
|
|
|
namespace dom {
|
|
|
|
class CSSRuleList;
|
|
|
|
} // namespace dom
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
namespace css {
|
2010-05-20 06:28:00 +04:00
|
|
|
|
2017-03-09 14:02:26 +03:00
|
|
|
class GroupRule;
|
2010-08-08 09:28:33 +04:00
|
|
|
class GroupRuleRuleList;
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2017-03-09 14:02:26 +03:00
|
|
|
struct GeckoGroupRuleRules
|
|
|
|
{
|
|
|
|
GeckoGroupRuleRules();
|
|
|
|
GeckoGroupRuleRules(GeckoGroupRuleRules&& aOther);
|
|
|
|
GeckoGroupRuleRules(const GeckoGroupRuleRules& aCopy);
|
|
|
|
~GeckoGroupRuleRules();
|
|
|
|
|
|
|
|
void SetParentRule(GroupRule* aParentRule) {
|
|
|
|
for (Rule* rule : mRules) {
|
|
|
|
rule->SetParentRule(aParentRule);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void SetStyleSheet(StyleSheet* aSheet) {
|
|
|
|
for (Rule* rule : mRules) {
|
|
|
|
rule->SetStyleSheet(aSheet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Clear();
|
|
|
|
void Traverse(nsCycleCollectionTraversalCallback& cb);
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void List(FILE* out, int32_t aIndent) const;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int32_t StyleRuleCount() const { return mRules.Count(); }
|
|
|
|
Rule* GetStyleRuleAt(int32_t aIndex) const {
|
|
|
|
return mRules.SafeObjectAt(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult DeleteStyleRuleAt(uint32_t aIndex);
|
|
|
|
|
|
|
|
dom::CSSRuleList* CssRules(GroupRule* aParentRule);
|
|
|
|
|
|
|
|
size_t SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const;
|
|
|
|
|
|
|
|
IncrementalClearCOMRuleArray mRules;
|
|
|
|
RefPtr<GroupRuleRuleList> mRuleCollection; // lazily constructed
|
|
|
|
};
|
|
|
|
|
|
|
|
#define REDIRECT_TO_INNER(call_) \
|
|
|
|
return mInner.as<GeckoGroupRuleRules>().call_;
|
|
|
|
|
2011-03-07 06:59:03 +03:00
|
|
|
// inherits from Rule so it can be shared between
|
2011-03-18 08:18:08 +03:00
|
|
|
// MediaRule and DocumentRule
|
2011-03-07 06:59:03 +03:00
|
|
|
class GroupRule : public Rule
|
2010-08-08 09:28:33 +04:00
|
|
|
{
|
|
|
|
protected:
|
2014-07-15 02:57:54 +04:00
|
|
|
GroupRule(uint32_t aLineNumber, uint32_t aColumnNumber);
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule(const GroupRule& aCopy);
|
|
|
|
virtual ~GroupRule();
|
1999-06-10 09:32:38 +04:00
|
|
|
public:
|
|
|
|
|
2016-12-01 02:18:14 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(GroupRule, Rule)
|
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
virtual bool IsCCLeaf() const override;
|
2012-10-08 06:39:09 +04:00
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
#ifdef DEBUG
|
2017-03-09 14:02:26 +03:00
|
|
|
void List(FILE* out = stdout, int32_t aIndent = 0) const override {
|
|
|
|
REDIRECT_TO_INNER(List(out, aIndent))
|
|
|
|
}
|
2010-08-08 09:28:33 +04:00
|
|
|
#endif
|
2016-11-23 02:26:20 +03:00
|
|
|
virtual void SetStyleSheet(StyleSheet* aSheet) override;
|
2010-08-08 09:28:33 +04:00
|
|
|
|
|
|
|
public:
|
2011-04-08 05:23:46 +04:00
|
|
|
void AppendStyleRule(Rule* aRule);
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2017-03-09 14:02:26 +03:00
|
|
|
int32_t StyleRuleCount() const {
|
|
|
|
REDIRECT_TO_INNER(StyleRuleCount())
|
|
|
|
}
|
|
|
|
Rule* GetStyleRuleAt(uint32_t aIndex) const {
|
|
|
|
REDIRECT_TO_INNER(GetStyleRuleAt(aIndex))
|
|
|
|
}
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2017-02-24 13:37:07 +03:00
|
|
|
typedef bool (*RuleEnumFunc)(Rule* aElement, void* aData);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const;
|
2001-09-05 04:00:18 +04:00
|
|
|
|
|
|
|
/*
|
2017-03-09 14:02:26 +03:00
|
|
|
* The next two methods should never be called unless you have first
|
2003-06-18 05:59:57 +04:00
|
|
|
* called WillDirty() on the parent stylesheet. After they are
|
|
|
|
* called, DidDirty() needs to be called on the sheet.
|
2001-09-05 04:00:18 +04:00
|
|
|
*/
|
2017-03-09 14:02:26 +03:00
|
|
|
nsresult DeleteStyleRuleAt(uint32_t aIndex) {
|
|
|
|
REDIRECT_TO_INNER(DeleteStyleRuleAt(aIndex));
|
|
|
|
}
|
2013-02-10 10:56:49 +04:00
|
|
|
nsresult InsertStyleRuleAt(uint32_t aIndex, Rule* aRule);
|
2004-08-05 22:26:14 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
virtual bool UseForPresentation(nsPresContext* aPresContext,
|
2010-08-08 09:29:28 +04:00
|
|
|
nsMediaQueryResultCacheKey& aKey) = 0;
|
2010-08-08 09:28:33 +04:00
|
|
|
|
2013-03-24 06:14:43 +04:00
|
|
|
// non-virtual -- it is only called by subclasses
|
2017-03-09 14:02:26 +03:00
|
|
|
size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf) const {
|
|
|
|
REDIRECT_TO_INNER(SizeOfExcludingThis(aMallocSizeOf))
|
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const override = 0;
|
2012-01-03 06:19:14 +04:00
|
|
|
|
2017-01-13 18:41:03 +03:00
|
|
|
// WebIDL API
|
|
|
|
dom::CSSRuleList* CssRules();
|
|
|
|
uint32_t InsertRule(const nsAString& aRule, uint32_t aIndex,
|
|
|
|
ErrorResult& aRv);
|
|
|
|
void DeleteRule(uint32_t aIndex, ErrorResult& aRv);
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
protected:
|
|
|
|
// to help implement nsIDOMCSSRule
|
2017-01-13 18:41:02 +03:00
|
|
|
void AppendRulesToCssText(nsAString& aCssText) const;
|
2010-08-08 09:28:33 +04:00
|
|
|
|
|
|
|
// to implement common methods on nsIDOMCSSMediaRule and
|
|
|
|
// nsIDOMCSSMozDocumentRule
|
2011-04-12 06:46:35 +04:00
|
|
|
nsresult GetCssRules(nsIDOMCSSRuleList* *aRuleList);
|
2012-08-22 19:56:38 +04:00
|
|
|
nsresult InsertRule(const nsAString & aRule, uint32_t aIndex,
|
|
|
|
uint32_t* _retval);
|
|
|
|
nsresult DeleteRule(uint32_t aIndex);
|
2010-08-08 09:28:33 +04:00
|
|
|
|
2017-03-09 14:02:26 +03:00
|
|
|
// Must only be called if this is a Gecko GroupRule.
|
|
|
|
IncrementalClearCOMRuleArray& GeckoRules() {
|
|
|
|
return mInner.as<GeckoGroupRuleRules>().mRules;
|
|
|
|
}
|
|
|
|
const IncrementalClearCOMRuleArray& GeckoRules() const {
|
|
|
|
return mInner.as<GeckoGroupRuleRules>().mRules;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Variant<GeckoGroupRuleRules> mInner;
|
1999-06-10 09:32:38 +04:00
|
|
|
};
|
|
|
|
|
2017-03-09 14:02:26 +03:00
|
|
|
#undef REDIRECT_TO_INNER
|
|
|
|
|
2017-01-13 18:41:03 +03:00
|
|
|
// Implementation of WebIDL CSSConditionRule.
|
|
|
|
class ConditionRule : public GroupRule
|
|
|
|
{
|
|
|
|
protected:
|
2017-02-24 06:12:23 +03:00
|
|
|
using GroupRule::GroupRule;
|
2017-01-13 18:41:03 +03:00
|
|
|
|
|
|
|
public:
|
|
|
|
// GetConditionText signature matches nsIDOMCSSConditionRule, so subclasses
|
|
|
|
// can implement this easily. The implementations should never return
|
|
|
|
// anything other than NS_OK.
|
|
|
|
NS_IMETHOD GetConditionText(nsAString& aConditionText) = 0;
|
|
|
|
virtual void SetConditionText(const nsAString& aConditionText,
|
|
|
|
ErrorResult& aRv) = 0;
|
|
|
|
};
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
2005-11-11 17:36:26 +03:00
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
#endif /* mozilla_css_GroupRule_h__ */
|