LCOV - code coverage report
Current view: top level - layout/style - CSSStyleSheet.h (source / functions) Hit Total Coverage
Test: output.info Lines: 7 11 63.6 %
Date: 2017-07-14 16:53:18 Functions: 5 9 55.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : // vim:cindent:tabstop=2:expandtab:shiftwidth=2:
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : /* representation of a CSS style sheet */
       8             : 
       9             : #ifndef mozilla_CSSStyleSheet_h
      10             : #define mozilla_CSSStyleSheet_h
      11             : 
      12             : #include "mozilla/Attributes.h"
      13             : #include "mozilla/IncrementalClearCOMRuleArray.h"
      14             : #include "mozilla/MemoryReporting.h"
      15             : #include "mozilla/StyleSheet.h"
      16             : #include "mozilla/StyleSheetInfo.h"
      17             : #include "mozilla/css/SheetParsingMode.h"
      18             : 
      19             : #include "nscore.h"
      20             : #include "nsCOMPtr.h"
      21             : #include "nsAutoPtr.h"
      22             : #include "nsTArrayForwardDeclare.h"
      23             : #include "nsString.h"
      24             : #include "mozilla/CORSMode.h"
      25             : #include "nsCycleCollectionParticipant.h"
      26             : #include "mozilla/net/ReferrerPolicy.h"
      27             : #include "mozilla/dom/SRIMetadata.h"
      28             : 
      29             : class CSSRuleListImpl;
      30             : class nsCSSRuleProcessor;
      31             : class nsIURI;
      32             : class nsMediaQueryResultCacheKey;
      33             : class nsPresContext;
      34             : class nsXMLNameSpaceMap;
      35             : 
      36             : namespace mozilla {
      37             : class CSSStyleSheet;
      38             : struct ChildSheetListBuilder;
      39             : 
      40             : namespace css {
      41             : class GroupRule;
      42             : } // namespace css
      43             : namespace dom {
      44             : class CSSRuleList;
      45             : class Element;
      46             : } // namespace dom
      47             : 
      48             :   // -------------------------------
      49             : // CSS Style Sheet Inner Data Container
      50             : //
      51             : 
      52             : struct CSSStyleSheetInner : public StyleSheetInfo
      53             : {
      54             :   CSSStyleSheetInner(CORSMode aCORSMode,
      55             :                      ReferrerPolicy aReferrerPolicy,
      56             :                      const dom::SRIMetadata& aIntegrity);
      57             :   CSSStyleSheetInner(CSSStyleSheetInner& aCopy,
      58             :                      CSSStyleSheet* aPrimarySheet);
      59             :   ~CSSStyleSheetInner();
      60             : 
      61             :   StyleSheetInfo* CloneFor(StyleSheet* aPrimarySheet) override;
      62             :   void RemoveSheet(StyleSheet* aSheet) override;
      63             : 
      64             :   void RebuildNameSpaces();
      65             : 
      66             :   // Create a new namespace map
      67             :   nsresult CreateNamespaceMap();
      68             : 
      69             :   size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const;
      70             : 
      71             :   IncrementalClearCOMRuleArray mOrderedRules;
      72             :   nsAutoPtr<nsXMLNameSpaceMap> mNameSpaceMap;
      73             : };
      74             : 
      75             : 
      76             : // -------------------------------
      77             : // CSS Style Sheet
      78             : //
      79             : 
      80             : // CID for the CSSStyleSheet class
      81             : // 7985c7ac-9ddc-444d-9899-0c86ec122f54
      82             : #define NS_CSS_STYLE_SHEET_IMPL_CID     \
      83             : { 0x7985c7ac, 0x9ddc, 0x444d, \
      84             :   { 0x98, 0x99, 0x0c, 0x86, 0xec, 0x12, 0x2f, 0x54 } }
      85             : 
      86             : 
      87             : class CSSStyleSheet final : public StyleSheet
      88             : {
      89             : public:
      90             :   typedef net::ReferrerPolicy ReferrerPolicy;
      91             :   CSSStyleSheet(css::SheetParsingMode aParsingMode,
      92             :                 CORSMode aCORSMode, ReferrerPolicy aReferrerPolicy);
      93             :   CSSStyleSheet(css::SheetParsingMode aParsingMode,
      94             :                 CORSMode aCORSMode, ReferrerPolicy aReferrerPolicy,
      95             :                 const dom::SRIMetadata& aIntegrity);
      96             : 
      97             :   NS_DECL_ISUPPORTS_INHERITED
      98          75 :   NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(CSSStyleSheet, StyleSheet)
      99             : 
     100             :   NS_DECLARE_STATIC_IID_ACCESSOR(NS_CSS_STYLE_SHEET_IMPL_CID)
     101             : 
     102             :   bool HasRules() const;
     103             : 
     104             : #ifdef DEBUG
     105             :   void List(FILE* out = stdout, int32_t aIndent = 0) const override;
     106             : #endif
     107             : 
     108             :   // XXX do these belong here or are they generic?
     109             :   void AppendStyleRule(css::Rule* aRule);
     110             : 
     111             :   int32_t StyleRuleCount() const;
     112             :   css::Rule* GetStyleRuleAt(int32_t aIndex) const;
     113             : 
     114          99 :   nsXMLNameSpaceMap* GetNameSpaceMap() const {
     115          99 :     return Inner()->mNameSpaceMap;
     116             :   }
     117             : 
     118             :   already_AddRefed<StyleSheet> Clone(StyleSheet* aCloneParent,
     119             :     dom::CSSImportRule* aCloneOwnerRule,
     120             :     nsIDocument* aCloneDocument,
     121             :     nsINode* aCloneOwningNode) const final;
     122             : 
     123           0 :   void SetModifiedByChildRule() {
     124           0 :     NS_ASSERTION(mDirty,
     125             :                  "sheet must be marked dirty before handing out child rules");
     126           0 :     DidDirty();
     127           0 :   }
     128             : 
     129             :   nsresult AddRuleProcessor(nsCSSRuleProcessor* aProcessor);
     130             :   nsresult DropRuleProcessor(nsCSSRuleProcessor* aProcessor);
     131             : 
     132             :   // nsICSSLoaderObserver interface
     133             :   NS_IMETHOD StyleSheetLoaded(StyleSheet* aSheet, bool aWasAlternate,
     134             :                               nsresult aStatus) override;
     135             : 
     136             :   bool UseForPresentation(nsPresContext* aPresContext,
     137             :                             nsMediaQueryResultCacheKey& aKey) const;
     138             : 
     139             :   nsresult ReparseSheet(const nsAString& aInput);
     140             : 
     141          69 :   void SetInRuleProcessorCache() { mInRuleProcessorCache = true; }
     142             : 
     143             :   // Function used as a callback to rebuild our inner's child sheet
     144             :   // list after we clone a unique inner for ourselves.
     145             :   static bool RebuildChildList(css::Rule* aRule,
     146             :                                ChildSheetListBuilder* aBuilder);
     147             : 
     148             :   size_t SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const override;
     149             : 
     150          50 :   dom::Element* GetScopeElement() const { return mScopeElement; }
     151             :   void SetScopeElement(dom::Element* aScopeElement);
     152             : 
     153             :   void DidDirty() override;
     154             : 
     155             : private:
     156             :   CSSStyleSheet(const CSSStyleSheet& aCopy,
     157             :                 CSSStyleSheet* aParentToUse,
     158             :                 dom::CSSImportRule* aOwnerRuleToUse,
     159             :                 nsIDocument* aDocumentToUse,
     160             :                 nsINode* aOwningNodeToUse);
     161             : 
     162             :   CSSStyleSheet(const CSSStyleSheet& aCopy) = delete;
     163             :   CSSStyleSheet& operator=(const CSSStyleSheet& aCopy) = delete;
     164             : 
     165             : protected:
     166             :   virtual ~CSSStyleSheet();
     167             : 
     168             :   void LastRelease();
     169             : 
     170             :   void ClearRuleCascades();
     171             : 
     172             :   // Add the namespace mapping from this @namespace rule to our namespace map
     173             :   nsresult RegisterNamespaceRule(css::Rule* aRule);
     174             : 
     175             :   // Drop our reference to mRuleCollection
     176             :   void DropRuleCollection();
     177             : 
     178        3719 :   CSSStyleSheetInner* Inner() const
     179             :   {
     180        3719 :     return static_cast<CSSStyleSheetInner*>(mInner);
     181             :   }
     182             : 
     183             :   // Unlink our inner, if needed, for cycle collection
     184             :   virtual void UnlinkInner() override;
     185             :   // Traverse our inner, if needed, for cycle collection
     186             :   virtual void TraverseInner(nsCycleCollectionTraversalCallback &) override;
     187             : 
     188             : protected:
     189             :   // Internal methods which do not have security check and completeness check.
     190             :   dom::CSSRuleList* GetCssRulesInternal();
     191             :   uint32_t InsertRuleInternal(const nsAString& aRule,
     192             :                               uint32_t aIndex, ErrorResult& aRv);
     193             :   void DeleteRuleInternal(uint32_t aIndex, ErrorResult& aRv);
     194             :   nsresult InsertRuleIntoGroupInternal(const nsAString& aRule,
     195             :                                        css::GroupRule* aGroup,
     196             :                                        uint32_t aIndex);
     197             : 
     198             :   void EnabledStateChangedInternal();
     199             : 
     200             :   RefPtr<CSSRuleListImpl> mRuleCollection;
     201             :   bool                  mInRuleProcessorCache;
     202             :   RefPtr<dom::Element> mScopeElement;
     203             : 
     204             :   AutoTArray<nsCSSRuleProcessor*, 8>* mRuleProcessors;
     205             : 
     206             :   friend class mozilla::StyleSheet;
     207             :   friend class ::nsCSSRuleProcessor;
     208             : };
     209             : 
     210             : NS_DEFINE_STATIC_IID_ACCESSOR(CSSStyleSheet, NS_CSS_STYLE_SHEET_IMPL_CID)
     211             : 
     212             : } // namespace mozilla
     213             : 
     214             : #endif /* !defined(mozilla_CSSStyleSheet_h) */

Generated by: LCOV version 1.13