2004-08-04 03:27:28 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
// vim:cindent:tabstop=2:expandtab:shiftwidth=2:
|
2012-05-21 11:12:37 +00: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/. */
|
2004-08-04 03:27:28 +00:00
|
|
|
|
2006-03-25 05:47:31 +00:00
|
|
|
/* representation of a CSS style sheet */
|
|
|
|
|
2014-06-20 10:32:49 +00:00
|
|
|
#ifndef mozilla_CSSStyleSheet_h
|
|
|
|
#define mozilla_CSSStyleSheet_h
|
2004-08-04 03:27:28 +00:00
|
|
|
|
2011-11-21 06:21:16 +00:00
|
|
|
#include "mozilla/Attributes.h"
|
2015-06-15 19:34:23 +00:00
|
|
|
#include "mozilla/IncrementalClearCOMRuleArray.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2016-02-26 01:51:01 +00:00
|
|
|
#include "mozilla/StyleSheet.h"
|
2016-02-26 01:51:01 +00:00
|
|
|
#include "mozilla/StyleSheetInfo.h"
|
2016-02-24 07:01:11 +00:00
|
|
|
#include "mozilla/css/SheetParsingMode.h"
|
2011-11-21 06:21:16 +00:00
|
|
|
|
2004-08-04 03:27:28 +00:00
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
2005-02-18 19:18:37 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2014-05-09 15:23:14 +00:00
|
|
|
#include "nsTArrayForwardDeclare.h"
|
2011-10-28 07:35:45 +00:00
|
|
|
#include "nsString.h"
|
2012-08-28 17:10:08 +00:00
|
|
|
#include "mozilla/CORSMode.h"
|
2012-10-08 02:39:08 +00:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2014-11-18 13:46:47 +00:00
|
|
|
#include "mozilla/net/ReferrerPolicy.h"
|
2015-08-13 03:19:11 +00:00
|
|
|
#include "mozilla/dom/SRIMetadata.h"
|
2004-08-04 03:27:28 +00:00
|
|
|
|
2014-06-20 10:32:49 +00:00
|
|
|
class CSSRuleListImpl;
|
2010-05-11 20:41:47 +00:00
|
|
|
class nsCSSRuleProcessor;
|
2004-08-04 03:27:28 +00:00
|
|
|
class nsIURI;
|
2008-07-26 16:14:48 +00:00
|
|
|
class nsMediaQueryResultCacheKey;
|
2010-04-10 20:10:12 +00:00
|
|
|
class nsPresContext;
|
2014-06-20 10:32:49 +00:00
|
|
|
class nsXMLNameSpaceMap;
|
2004-08-04 03:27:28 +00:00
|
|
|
|
2011-03-17 17:41:52 +00:00
|
|
|
namespace mozilla {
|
2014-06-20 10:32:49 +00:00
|
|
|
class CSSStyleSheet;
|
2017-03-03 04:19:06 +00:00
|
|
|
struct ChildSheetListBuilder;
|
2014-06-20 10:32:49 +00:00
|
|
|
|
2011-03-17 17:41:52 +00:00
|
|
|
namespace css {
|
2010-08-08 05:28:33 +00:00
|
|
|
class GroupRule;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace css
|
2014-06-10 02:11:00 +00:00
|
|
|
namespace dom {
|
|
|
|
class CSSRuleList;
|
2017-03-28 09:05:12 +00:00
|
|
|
class Element;
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace dom
|
2011-03-17 17:41:52 +00:00
|
|
|
|
2015-12-21 15:52:45 +00:00
|
|
|
// -------------------------------
|
2004-08-04 03:27:28 +00:00
|
|
|
// CSS Style Sheet Inner Data Container
|
|
|
|
//
|
|
|
|
|
2016-09-29 06:17:58 +00:00
|
|
|
struct CSSStyleSheetInner : public StyleSheetInfo
|
2014-06-20 10:32:49 +00:00
|
|
|
{
|
2017-02-17 23:48:35 +00:00
|
|
|
CSSStyleSheetInner(CORSMode aCORSMode,
|
2015-08-13 03:19:11 +00:00
|
|
|
ReferrerPolicy aReferrerPolicy,
|
|
|
|
const dom::SRIMetadata& aIntegrity);
|
2014-06-20 10:32:49 +00:00
|
|
|
CSSStyleSheetInner(CSSStyleSheetInner& aCopy,
|
|
|
|
CSSStyleSheet* aPrimarySheet);
|
|
|
|
~CSSStyleSheetInner();
|
2004-08-04 03:27:28 +00:00
|
|
|
|
2017-05-15 23:19:17 +00:00
|
|
|
StyleSheetInfo* CloneFor(StyleSheet* aPrimarySheet) override;
|
2017-02-17 23:48:35 +00:00
|
|
|
void RemoveSheet(StyleSheet* aSheet) override;
|
2004-08-04 03:27:28 +00:00
|
|
|
|
2008-10-15 20:24:45 +00:00
|
|
|
void RebuildNameSpaces();
|
2004-08-04 03:27:28 +00:00
|
|
|
|
2008-10-15 20:23:21 +00:00
|
|
|
// Create a new namespace map
|
|
|
|
nsresult CreateNamespaceMap();
|
|
|
|
|
2014-06-20 10:32:49 +00:00
|
|
|
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
|
2012-01-03 02:19:14 +00:00
|
|
|
|
2015-06-15 19:34:23 +00:00
|
|
|
IncrementalClearCOMRuleArray mOrderedRules;
|
2005-02-19 00:10:38 +00:00
|
|
|
nsAutoPtr<nsXMLNameSpaceMap> mNameSpaceMap;
|
2004-08-04 03:27:28 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------
|
|
|
|
// CSS Style Sheet
|
|
|
|
//
|
|
|
|
|
2014-06-20 10:32:49 +00:00
|
|
|
// CID for the CSSStyleSheet class
|
2015-11-17 06:04:09 +00:00
|
|
|
// 7985c7ac-9ddc-444d-9899-0c86ec122f54
|
2010-05-11 20:41:47 +00:00
|
|
|
#define NS_CSS_STYLE_SHEET_IMPL_CID \
|
2015-11-17 06:04:09 +00:00
|
|
|
{ 0x7985c7ac, 0x9ddc, 0x444d, \
|
|
|
|
{ 0x98, 0x99, 0x0c, 0x86, 0xec, 0x12, 0x2f, 0x54 } }
|
2010-05-11 20:41:47 +00:00
|
|
|
|
|
|
|
|
2016-10-14 11:25:38 +00:00
|
|
|
class CSSStyleSheet final : public StyleSheet
|
2004-08-04 03:27:28 +00:00
|
|
|
{
|
|
|
|
public:
|
2014-11-18 13:46:47 +00:00
|
|
|
typedef net::ReferrerPolicy ReferrerPolicy;
|
2016-08-02 20:12:27 +00:00
|
|
|
CSSStyleSheet(css::SheetParsingMode aParsingMode,
|
|
|
|
CORSMode aCORSMode, ReferrerPolicy aReferrerPolicy);
|
|
|
|
CSSStyleSheet(css::SheetParsingMode aParsingMode,
|
|
|
|
CORSMode aCORSMode, ReferrerPolicy aReferrerPolicy,
|
2015-08-13 03:19:11 +00:00
|
|
|
const dom::SRIMetadata& aIntegrity);
|
2004-08-04 03:27:28 +00:00
|
|
|
|
2016-10-14 11:25:38 +00:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CSSStyleSheet, StyleSheet)
|
2004-08-04 03:27:28 +00:00
|
|
|
|
2010-05-11 20:41:47 +00:00
|
|
|
NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_SHEET_IMPL_CID)
|
|
|
|
|
2015-11-17 06:04:09 +00:00
|
|
|
bool HasRules() const;
|
|
|
|
|
2011-08-24 20:44:35 +00:00
|
|
|
// Find the ID of the owner inner window.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint64_t FindOwningWindowInnerID() const;
|
2004-08-04 03:27:28 +00:00
|
|
|
#ifdef DEBUG
|
2017-01-24 00:40:28 +00:00
|
|
|
void List(FILE* out = stdout, int32_t aIndent = 0) const override;
|
2004-08-04 03:27:28 +00:00
|
|
|
#endif
|
2010-05-11 20:59:25 +00:00
|
|
|
|
|
|
|
// XXX do these belong here or are they generic?
|
2014-06-20 10:32:49 +00:00
|
|
|
void AppendStyleRule(css::Rule* aRule);
|
2010-05-11 20:59:25 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t StyleRuleCount() const;
|
2014-06-20 10:32:49 +00:00
|
|
|
css::Rule* GetStyleRuleAt(int32_t aIndex) const;
|
2010-05-11 20:59:25 +00:00
|
|
|
|
2017-02-14 17:41:33 +00:00
|
|
|
nsXMLNameSpaceMap* GetNameSpaceMap() const {
|
|
|
|
return Inner()->mNameSpaceMap;
|
|
|
|
}
|
2010-05-11 20:59:25 +00:00
|
|
|
|
2017-05-30 01:10:25 +00:00
|
|
|
already_AddRefed<StyleSheet> Clone(StyleSheet* aCloneParent,
|
|
|
|
dom::CSSImportRule* aCloneOwnerRule,
|
2017-02-15 21:33:17 +00:00
|
|
|
nsIDocument* aCloneDocument,
|
|
|
|
nsINode* aCloneOwningNode) const final;
|
2010-05-11 20:59:25 +00:00
|
|
|
|
2011-04-12 06:18:43 +00:00
|
|
|
void SetModifiedByChildRule() {
|
|
|
|
NS_ASSERTION(mDirty,
|
|
|
|
"sheet must be marked dirty before handing out child rules");
|
|
|
|
DidDirty();
|
|
|
|
}
|
2010-05-11 20:59:25 +00:00
|
|
|
|
2010-05-11 20:41:48 +00:00
|
|
|
nsresult AddRuleProcessor(nsCSSRuleProcessor* aProcessor);
|
|
|
|
nsresult DropRuleProcessor(nsCSSRuleProcessor* aProcessor);
|
2010-05-11 20:59:25 +00:00
|
|
|
|
2004-08-04 03:27:28 +00:00
|
|
|
// nsICSSLoaderObserver interface
|
2016-09-26 12:03:25 +00:00
|
|
|
NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet, bool aWasAlternate,
|
2015-03-21 16:28:04 +00:00
|
|
|
nsresult aStatus) override;
|
2009-12-31 15:56:33 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool UseForPresentation(nsPresContext* aPresContext,
|
2008-07-26 16:14:48 +00:00
|
|
|
nsMediaQueryResultCacheKey& aKey) const;
|
|
|
|
|
2015-09-18 05:27:00 +00:00
|
|
|
nsresult ReparseSheet(const nsAString& aInput);
|
2012-06-03 16:54:38 +00:00
|
|
|
|
2015-06-26 03:52:47 +00:00
|
|
|
void SetInRuleProcessorCache() { mInRuleProcessorCache = true; }
|
|
|
|
|
2009-05-26 19:40:49 +00:00
|
|
|
// Function used as a callback to rebuild our inner's child sheet
|
|
|
|
// list after we clone a unique inner for ourselves.
|
2017-03-03 04:19:06 +00:00
|
|
|
static bool RebuildChildList(css::Rule* aRule,
|
|
|
|
ChildSheetListBuilder* aBuilder);
|
2009-05-26 19:40:49 +00:00
|
|
|
|
2017-01-24 00:42:31 +00:00
|
|
|
size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
|
2012-01-03 02:19:14 +00:00
|
|
|
|
2014-06-20 10:32:49 +00:00
|
|
|
dom::Element* GetScopeElement() const { return mScopeElement; }
|
2017-03-28 09:05:12 +00:00
|
|
|
void SetScopeElement(dom::Element* aScopeElement);
|
2013-01-08 23:25:47 +00:00
|
|
|
|
2017-05-15 23:19:17 +00:00
|
|
|
void DidDirty() override;
|
2015-11-09 07:57:17 +00:00
|
|
|
|
2004-08-04 03:27:28 +00:00
|
|
|
private:
|
2014-06-20 10:32:49 +00:00
|
|
|
CSSStyleSheet(const CSSStyleSheet& aCopy,
|
|
|
|
CSSStyleSheet* aParentToUse,
|
2017-05-30 01:10:25 +00:00
|
|
|
dom::CSSImportRule* aOwnerRuleToUse,
|
2014-06-20 10:32:49 +00:00
|
|
|
nsIDocument* aDocumentToUse,
|
|
|
|
nsINode* aOwningNodeToUse);
|
2010-05-11 20:41:47 +00:00
|
|
|
|
2015-01-06 23:35:02 +00:00
|
|
|
CSSStyleSheet(const CSSStyleSheet& aCopy) = delete;
|
|
|
|
CSSStyleSheet& operator=(const CSSStyleSheet& aCopy) = delete;
|
2004-08-04 03:27:28 +00:00
|
|
|
|
|
|
|
protected:
|
2014-06-20 10:32:49 +00:00
|
|
|
virtual ~CSSStyleSheet();
|
2004-08-04 03:27:28 +00:00
|
|
|
|
2017-05-25 20:33:47 +00:00
|
|
|
void ClearRuleCascades();
|
2004-08-04 03:27:28 +00:00
|
|
|
|
2008-10-15 20:23:21 +00:00
|
|
|
// Add the namespace mapping from this @namespace rule to our namespace map
|
2014-06-20 10:32:49 +00:00
|
|
|
nsresult RegisterNamespaceRule(css::Rule* aRule);
|
2008-10-15 20:23:21 +00:00
|
|
|
|
2012-10-08 02:39:08 +00:00
|
|
|
// Drop our reference to mRuleCollection
|
|
|
|
void DropRuleCollection();
|
|
|
|
|
2017-02-14 17:41:33 +00:00
|
|
|
CSSStyleSheetInner* Inner() const
|
|
|
|
{
|
|
|
|
return static_cast<CSSStyleSheetInner*>(mInner);
|
|
|
|
}
|
|
|
|
|
2012-10-08 02:39:08 +00:00
|
|
|
// Unlink our inner, if needed, for cycle collection
|
2017-02-16 00:19:33 +00:00
|
|
|
virtual void UnlinkInner() override;
|
2012-10-08 02:39:08 +00:00
|
|
|
// Traverse our inner, if needed, for cycle collection
|
2017-02-16 00:19:33 +00:00
|
|
|
virtual void TraverseInner(nsCycleCollectionTraversalCallback &) override;
|
2012-10-08 02:39:08 +00:00
|
|
|
|
2004-08-04 03:27:28 +00:00
|
|
|
protected:
|
2016-10-14 11:25:38 +00:00
|
|
|
// Internal methods which do not have security check and completeness check.
|
|
|
|
dom::CSSRuleList* GetCssRulesInternal(ErrorResult& aRv);
|
|
|
|
uint32_t InsertRuleInternal(const nsAString& aRule,
|
|
|
|
uint32_t aIndex, ErrorResult& aRv);
|
|
|
|
void DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv);
|
2017-03-08 07:04:15 +00:00
|
|
|
nsresult InsertRuleIntoGroupInternal(const nsAString& aRule,
|
|
|
|
css::GroupRule* aGroup,
|
|
|
|
uint32_t aIndex);
|
2016-10-14 11:25:38 +00:00
|
|
|
|
2017-01-06 07:05:24 +00:00
|
|
|
void EnabledStateChangedInternal();
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<CSSRuleListImpl> mRuleCollection;
|
2015-06-26 03:52:47 +00:00
|
|
|
bool mInRuleProcessorCache;
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<dom::Element> mScopeElement;
|
2004-08-04 03:27:28 +00:00
|
|
|
|
2016-02-02 15:36:30 +00:00
|
|
|
AutoTArray<nsCSSRuleProcessor*, 8>* mRuleProcessors;
|
2004-08-04 03:27:28 +00:00
|
|
|
|
2016-03-01 22:38:13 +00:00
|
|
|
friend class mozilla::StyleSheet;
|
2017-01-23 23:52:56 +00:00
|
|
|
friend class ::nsCSSRuleProcessor;
|
2004-08-04 03:27:28 +00:00
|
|
|
};
|
|
|
|
|
2014-06-20 10:32:49 +00:00
|
|
|
NS_DEFINE_STATIC_IID_ACCESSOR(CSSStyleSheet, NS_CSS_STYLE_SHEET_IMPL_CID)
|
|
|
|
|
|
|
|
} // namespace mozilla
|
2010-05-11 20:41:47 +00:00
|
|
|
|
2014-06-20 10:32:49 +00:00
|
|
|
#endif /* !defined(mozilla_CSSStyleSheet_h) */
|