LCOV - code coverage report
Current view: top level - dom/base - nsMappedAttributes.h (source / functions) Hit Total Coverage
Test: output.info Lines: 15 24 62.5 %
Date: 2017-07-14 16:53:18 Functions: 7 11 63.6 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       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             :  * A unique per-element set of attributes that is used as an
       9             :  * nsIStyleRule; used to implement presentational attributes.
      10             :  */
      11             : 
      12             : #ifndef nsMappedAttributes_h___
      13             : #define nsMappedAttributes_h___
      14             : 
      15             : #include "nsAttrAndChildArray.h"
      16             : #include "nsMappedAttributeElement.h"
      17             : #include "nsIStyleRule.h"
      18             : #include "mozilla/Attributes.h"
      19             : #include "mozilla/ServoBindingTypes.h"
      20             : #include "mozilla/MemoryReporting.h"
      21             : 
      22             : class nsIAtom;
      23             : class nsHTMLStyleSheet;
      24             : 
      25             : class nsMappedAttributes final : public nsIStyleRule
      26             : {
      27             : public:
      28             :   nsMappedAttributes(nsHTMLStyleSheet* aSheet,
      29             :                      nsMapRuleToAttributesFunc aMapRuleFunc);
      30             : 
      31             :   // Do not return null.
      32             :   void* operator new(size_t size, uint32_t aAttrCount = 1) CPP_THROW_NEW;
      33             :   nsMappedAttributes* Clone(bool aWillAddAttr);
      34             : 
      35             :   NS_DECL_ISUPPORTS
      36             : 
      37             :   void SetAndSwapAttr(nsIAtom* aAttrName, nsAttrValue& aValue,
      38             :                       bool* aValueWasSet);
      39             :   const nsAttrValue* GetAttr(nsIAtom* aAttrName) const;
      40             :   const nsAttrValue* GetAttr(const nsAString& aAttrName) const;
      41             : 
      42         336 :   uint32_t Count() const
      43             :   {
      44         336 :     return mAttrCount;
      45             :   }
      46             : 
      47             :   bool Equals(const nsMappedAttributes* aAttributes) const;
      48             :   PLDHashNumber HashValue() const;
      49             : 
      50           1 :   void DropStyleSheetReference()
      51             :   {
      52           1 :     mSheet = nullptr;
      53           1 :   }
      54             :   void SetStyleSheet(nsHTMLStyleSheet* aSheet);
      55          66 :   nsHTMLStyleSheet* GetStyleSheet()
      56             :   {
      57          66 :     return mSheet;
      58             :   }
      59             : 
      60           1 :   const nsAttrName* NameAt(uint32_t aPos) const
      61             :   {
      62           1 :     NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
      63           1 :     return &Attrs()[aPos].mName;
      64             :   }
      65           0 :   const nsAttrValue* AttrAt(uint32_t aPos) const
      66             :   {
      67           0 :     NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
      68           0 :     return &Attrs()[aPos].mValue;
      69             :   }
      70             :   // Remove the attr at position aPos.  The value of the attr is placed in
      71             :   // aValue; any value that was already in aValue is destroyed.
      72             :   void RemoveAttrAt(uint32_t aPos, nsAttrValue& aValue);
      73             :   const nsAttrName* GetExistingAttrNameFromQName(const nsAString& aName) const;
      74             :   int32_t IndexOfAttr(nsIAtom* aLocalName) const;
      75             : 
      76             :   // Apply the contained mapper to the contained set of servo rules,
      77             :   // unless the servo rules have already been initialized.
      78             :   void LazilyResolveServoDeclaration(nsPresContext* aPresContext);
      79             : 
      80             :   // Obtain the contained servo declaration block
      81             :   // May return null if called before the inner block
      82             :   // has been (lazily) resolved
      83           0 :   const RefPtr<RawServoDeclarationBlock>& GetServoStyle() const
      84             :   {
      85           0 :     return mServoStyle;
      86             :   }
      87             : 
      88           0 :   void ClearServoStyle() {
      89           0 :     MOZ_ASSERT(NS_IsMainThread());
      90           0 :     mServoStyle = nullptr;
      91           0 :   }
      92             : 
      93             :   // nsIStyleRule
      94             :   virtual void MapRuleInfoInto(nsRuleData* aRuleData) override;
      95             :   virtual bool MightMapInheritedStyleData() override;
      96             :   virtual bool GetDiscretelyAnimatedCSSValue(nsCSSPropertyID aProperty,
      97             :                                              nsCSSValue* aValue) override;
      98             : #ifdef DEBUG
      99             :   virtual void List(FILE* out = stdout, int32_t aIndent = 0) const override;
     100             : #endif
     101             : 
     102             :   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
     103             : 
     104             :   static void Shutdown();
     105             : private:
     106             : 
     107             :   void LastRelease();
     108             : 
     109             :   nsMappedAttributes(const nsMappedAttributes& aCopy);
     110             :   ~nsMappedAttributes();
     111             : 
     112           1 :   struct InternalAttr
     113             :   {
     114             :     nsAttrName mName;
     115             :     nsAttrValue mValue;
     116             :   };
     117             : 
     118             :   /**
     119             :    * Due to a compiler bug in VisualAge C++ for AIX, we need to return the
     120             :    * address of the first index into mAttrs here, instead of simply
     121             :    * returning mAttrs itself.
     122             :    *
     123             :    * See Bug 231104 for more information.
     124             :    */
     125         692 :   const InternalAttr* Attrs() const
     126             :   {
     127         692 :     return reinterpret_cast<const InternalAttr*>(&(mAttrs[0]));
     128             :   }
     129          79 :   InternalAttr* Attrs()
     130             :   {
     131          79 :     return reinterpret_cast<InternalAttr*>(&(mAttrs[0]));
     132             :   }
     133             : 
     134             :   uint16_t mAttrCount;
     135             : #ifdef DEBUG
     136             :   uint16_t mBufferSize;
     137             : #endif
     138             :   nsHTMLStyleSheet* mSheet; //weak
     139             :   nsMapRuleToAttributesFunc mRuleMapper;
     140             :   RefPtr<RawServoDeclarationBlock> mServoStyle;
     141             :   void* mAttrs[1];
     142             : 
     143             :   static bool sShuttingDown;
     144             : 
     145             :   // We're caching some memory to avoid trashing the allocator.
     146             :   // The memory stored at index N can hold N attribute values.
     147             :   static nsTArray<void*>* sCachedMappedAttributeAllocations;
     148             : };
     149             : 
     150             : #endif /* nsMappedAttributes_h___ */

Generated by: LCOV version 1.13