LCOV - code coverage report
Current view: top level - layout/style - nsHTMLStyleSheet.h (source / functions) Hit Total Coverage
Test: output.info Lines: 3 19 15.8 %
Date: 2017-07-14 16:53:18 Functions: 3 17 17.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             :  *
       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             : /*
       8             :  * style sheet and style rule processor representing data from presentational
       9             :  * HTML attributes
      10             :  */
      11             : 
      12             : #ifndef nsHTMLStyleSheet_h_
      13             : #define nsHTMLStyleSheet_h_
      14             : 
      15             : #include "nsColor.h"
      16             : #include "nsCOMPtr.h"
      17             : #include "nsIAtom.h"
      18             : #include "nsIStyleRule.h"
      19             : #include "nsIStyleRuleProcessor.h"
      20             : #include "PLDHashTable.h"
      21             : #include "mozilla/Attributes.h"
      22             : #include "mozilla/MemoryReporting.h"
      23             : #include "nsString.h"
      24             : 
      25             : class nsIDocument;
      26             : class nsMappedAttributes;
      27             : struct RawServoDeclarationBlock;
      28             : 
      29             : class nsHTMLStyleSheet final : public nsIStyleRuleProcessor
      30             : {
      31             : public:
      32             :   explicit nsHTMLStyleSheet(nsIDocument* aDocument);
      33             : 
      34             :   void SetOwningDocument(nsIDocument* aDocument);
      35             : 
      36             :   NS_DECL_ISUPPORTS
      37             : 
      38             :   // nsIStyleRuleProcessor API
      39             :   virtual void RulesMatching(ElementRuleProcessorData* aData) override;
      40             :   virtual void RulesMatching(PseudoElementRuleProcessorData* aData) override;
      41             :   virtual void RulesMatching(AnonBoxRuleProcessorData* aData) override;
      42             : #ifdef MOZ_XUL
      43             :   virtual void RulesMatching(XULTreeRuleProcessorData* aData) override;
      44             : #endif
      45             :   virtual nsRestyleHint HasStateDependentStyle(StateRuleProcessorData* aData) override;
      46             :   virtual nsRestyleHint HasStateDependentStyle(PseudoElementStateRuleProcessorData* aData) override;
      47             :   virtual bool HasDocumentStateDependentStyle(StateRuleProcessorData* aData) override;
      48             :   virtual nsRestyleHint
      49             :     HasAttributeDependentStyle(AttributeRuleProcessorData* aData,
      50             :                                mozilla::RestyleHintData& aRestyleHintDataResult) override;
      51             :   virtual bool MediumFeaturesChanged(nsPresContext* aPresContext) override;
      52             :   virtual size_t SizeOfExcludingThis(mozilla::MallocSizeOf aMallocSizeOf)
      53             :     const MOZ_MUST_OVERRIDE override;
      54             :   virtual size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf)
      55             :     const MOZ_MUST_OVERRIDE override;
      56             :   size_t DOMSizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
      57             : 
      58             :   void Reset();
      59             :   nsresult SetLinkColor(nscolor aColor);
      60             :   nsresult SetActiveLinkColor(nscolor aColor);
      61             :   nsresult SetVisitedLinkColor(nscolor aColor);
      62             : 
      63           0 :   const RefPtr<RawServoDeclarationBlock>& GetServoUnvisitedLinkDecl() const {
      64           0 :     return mServoUnvisitedLinkDecl;
      65             :   }
      66           0 :   const RefPtr<RawServoDeclarationBlock>& GetServoVisitedLinkDecl() const {
      67           0 :     return mServoVisitedLinkDecl;
      68             :   }
      69           0 :   const RefPtr<RawServoDeclarationBlock>& GetServoActiveLinkDecl() const {
      70           0 :     return mServoActiveLinkDecl;
      71             :   }
      72             : 
      73             :   // Mapped Attribute management methods
      74             :   already_AddRefed<nsMappedAttributes>
      75             :     UniqueMappedAttributes(nsMappedAttributes* aMapped);
      76             :   void DropMappedAttributes(nsMappedAttributes* aMapped);
      77             :   // For each mapped presentation attribute in the cache, resolve
      78             :   // the attached ServoDeclarationBlock by running the mapping
      79             :   // and converting the ruledata to Servo specified values.
      80             :   void CalculateMappedServoDeclarations(nsPresContext* aPresContext);
      81             : 
      82             :   nsIStyleRule* LangRuleFor(const nsIAtom* aLanguage);
      83             : 
      84             : private:
      85             :   nsHTMLStyleSheet(const nsHTMLStyleSheet& aCopy) = delete;
      86             :   nsHTMLStyleSheet& operator=(const nsHTMLStyleSheet& aCopy) = delete;
      87             : 
      88           0 :   ~nsHTMLStyleSheet() {}
      89             : 
      90             :   class HTMLColorRule;
      91             :   friend class HTMLColorRule;
      92             :   class HTMLColorRule final : public nsIStyleRule {
      93             :   private:
      94           0 :     ~HTMLColorRule() {}
      95             :   public:
      96           0 :     explicit HTMLColorRule(nscolor aColor)
      97           0 :       : mColor(aColor)
      98           0 :     {}
      99             : 
     100             :     NS_DECL_ISUPPORTS
     101             : 
     102             :     // nsIStyleRule interface
     103             :     virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
     104             :     virtual bool MightMapInheritedStyleData() override;
     105             :     virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
     106             :                                                nsCSSValue* aValue) override;
     107             :   #ifdef DEBUG
     108             :     virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
     109             :   #endif
     110             : 
     111             :     nscolor mColor;
     112             :   };
     113             : 
     114             :   // Implementation of SetLink/VisitedLink/ActiveLinkColor
     115             :   nsresult ImplLinkColorSetter(RefPtr<HTMLColorRule>& aRule,
     116             :                                RefPtr<RawServoDeclarationBlock>& aDecl,
     117             :                                nscolor aColor);
     118             : 
     119             :   class GenericTableRule;
     120             :   friend class GenericTableRule;
     121             :   class GenericTableRule : public nsIStyleRule {
     122             :   protected:
     123           0 :     virtual ~GenericTableRule() {}
     124             :   public:
     125          60 :     GenericTableRule() {}
     126             : 
     127             :     NS_DECL_ISUPPORTS
     128             : 
     129             :     // nsIStyleRule interface
     130             :     virtual void MapRuleInfoInto(nsRuleData* aRuleData) override = 0;
     131             :     virtual bool MightMapInheritedStyleData() override = 0;
     132             :     virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
     133             :                                                nsCSSValue* aValue) override = 0;
     134             :   #ifdef DEBUG
     135             :     virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
     136             :   #endif
     137             :   };
     138             : 
     139             :   // this rule handles <th> inheritance
     140             :   class TableTHRule;
     141             :   friend class TableTHRule;
     142           0 :   class TableTHRule final : public GenericTableRule {
     143             :   public:
     144          30 :     TableTHRule() {}
     145             : 
     146             :     virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
     147             :     virtual bool MightMapInheritedStyleData() override;
     148             :     virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
     149             :                                                nsCSSValue* aValue) override;
     150             :   };
     151             : 
     152             :   // Rule to handle quirk table colors
     153           0 :   class TableQuirkColorRule final : public GenericTableRule {
     154             :   public:
     155          30 :     TableQuirkColorRule() {}
     156             : 
     157             :     virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
     158             :     virtual bool MightMapInheritedStyleData() override;
     159             :     virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
     160             :                                                nsCSSValue* aValue) override;
     161             :   };
     162             : 
     163             : public: // for mLangRuleTable structures only
     164             : 
     165             :   // Rule to handle xml:lang attributes, of which we have exactly one
     166             :   // per language string, maintained in mLangRuleTable.
     167             :   // We also create one extra rule for the "x-math" language string, used on
     168             :   // <math> elements.
     169             :   class LangRule final : public nsIStyleRule {
     170             :   private:
     171           0 :     ~LangRule() {}
     172             :   public:
     173           0 :     explicit LangRule(nsIAtom* aLang) : mLang(aLang) {}
     174             : 
     175             :     NS_DECL_ISUPPORTS
     176             : 
     177             :     // nsIStyleRule interface
     178             :     virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
     179             :     virtual bool MightMapInheritedStyleData() override;
     180             :     virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
     181             :                                                nsCSSValue* aValue) override;
     182             :   #ifdef DEBUG
     183             :     virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
     184             :   #endif
     185             : 
     186             :     nsCOMPtr<nsIAtom> mLang;
     187             :   };
     188             : 
     189             : private:
     190             :   nsIDocument*            mDocument;
     191             :   RefPtr<HTMLColorRule> mLinkRule;
     192             :   RefPtr<HTMLColorRule> mVisitedRule;
     193             :   RefPtr<HTMLColorRule> mActiveRule;
     194             :   RefPtr<RawServoDeclarationBlock> mServoUnvisitedLinkDecl;
     195             :   RefPtr<RawServoDeclarationBlock> mServoVisitedLinkDecl;
     196             :   RefPtr<RawServoDeclarationBlock> mServoActiveLinkDecl;
     197             :   RefPtr<TableQuirkColorRule> mTableQuirkColorRule;
     198             :   RefPtr<TableTHRule>   mTableTHRule;
     199             : 
     200             :   PLDHashTable            mMappedAttrTable;
     201             :   // Whether or not the mapped attributes table
     202             :   // has been changed since the last call to
     203             :   // CalculateMappedServoDeclarations()
     204             :   bool                    mMappedAttrsDirty;
     205             :   PLDHashTable            mLangRuleTable;
     206             : };
     207             : 
     208             : #endif /* !defined(nsHTMLStyleSheet_h_) */

Generated by: LCOV version 1.13