content/base/src/nsMappedAttributes.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /*
     7  * A unique per-element set of attributes that is used as an
     8  * nsIStyleRule; used to implement presentational attributes.
     9  */
    11 #ifndef nsMappedAttributes_h___
    12 #define nsMappedAttributes_h___
    14 #include "nsAttrAndChildArray.h"
    15 #include "nsMappedAttributeElement.h"
    16 #include "nsIStyleRule.h"
    17 #include "mozilla/Attributes.h"
    18 #include "mozilla/MemoryReporting.h"
    20 class nsIAtom;
    21 class nsHTMLStyleSheet;
    22 class nsRuleWalker;
    24 class nsMappedAttributes MOZ_FINAL : public nsIStyleRule
    25 {
    26 public:
    27   nsMappedAttributes(nsHTMLStyleSheet* aSheet,
    28                      nsMapRuleToAttributesFunc aMapRuleFunc);
    30   // Do not return null.
    31   void* operator new(size_t size, uint32_t aAttrCount = 1) CPP_THROW_NEW;
    32   nsMappedAttributes* Clone(bool aWillAddAttr);
    34   NS_DECL_ISUPPORTS
    36   void SetAndTakeAttr(nsIAtom* aAttrName, nsAttrValue& aValue);
    37   const nsAttrValue* GetAttr(nsIAtom* aAttrName) const;
    38   const nsAttrValue* GetAttr(const nsAString& aAttrName) const;
    40   uint32_t Count() const
    41   {
    42     return mAttrCount;
    43   }
    45   bool Equals(const nsMappedAttributes* aAttributes) const;
    46   uint32_t HashValue() const;
    48   void DropStyleSheetReference()
    49   {
    50     mSheet = nullptr;
    51   }
    52   void SetStyleSheet(nsHTMLStyleSheet* aSheet);
    53   nsHTMLStyleSheet* GetStyleSheet()
    54   {
    55     return mSheet;
    56   }
    58   const nsAttrName* NameAt(uint32_t aPos) const
    59   {
    60     NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
    61     return &Attrs()[aPos].mName;
    62   }
    63   const nsAttrValue* AttrAt(uint32_t aPos) const
    64   {
    65     NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
    66     return &Attrs()[aPos].mValue;
    67   }
    68   // Remove the attr at position aPos.  The value of the attr is placed in
    69   // aValue; any value that was already in aValue is destroyed.
    70   void RemoveAttrAt(uint32_t aPos, nsAttrValue& aValue);
    71   const nsAttrName* GetExistingAttrNameFromQName(const nsAString& aName) const;
    72   int32_t IndexOfAttr(nsIAtom* aLocalName) const;
    75   // nsIStyleRule 
    76   virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE;
    77 #ifdef DEBUG
    78   virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE;
    79 #endif
    81   size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
    83 private:
    84   nsMappedAttributes(const nsMappedAttributes& aCopy);
    85   ~nsMappedAttributes();
    87   struct InternalAttr
    88   {
    89     nsAttrName mName;
    90     nsAttrValue mValue;
    91   };
    93   /**
    94    * Due to a compiler bug in VisualAge C++ for AIX, we need to return the 
    95    * address of the first index into mAttrs here, instead of simply
    96    * returning mAttrs itself.
    97    *
    98    * See Bug 231104 for more information.
    99    */
   100   const InternalAttr* Attrs() const
   101   {
   102     return reinterpret_cast<const InternalAttr*>(&(mAttrs[0]));
   103   }
   104   InternalAttr* Attrs()
   105   {
   106     return reinterpret_cast<InternalAttr*>(&(mAttrs[0]));
   107   }
   109   uint16_t mAttrCount;
   110 #ifdef DEBUG
   111   uint16_t mBufferSize;
   112 #endif
   113   nsHTMLStyleSheet* mSheet; //weak
   114   nsMapRuleToAttributesFunc mRuleMapper;
   115   void* mAttrs[1];
   116 };
   118 #endif /* nsMappedAttributes_h___ */

mercurial