michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * A unique per-element set of attributes that is used as an michael@0: * nsIStyleRule; used to implement presentational attributes. michael@0: */ michael@0: michael@0: #ifndef nsMappedAttributes_h___ michael@0: #define nsMappedAttributes_h___ michael@0: michael@0: #include "nsAttrAndChildArray.h" michael@0: #include "nsMappedAttributeElement.h" michael@0: #include "nsIStyleRule.h" michael@0: #include "mozilla/Attributes.h" michael@0: #include "mozilla/MemoryReporting.h" michael@0: michael@0: class nsIAtom; michael@0: class nsHTMLStyleSheet; michael@0: class nsRuleWalker; michael@0: michael@0: class nsMappedAttributes MOZ_FINAL : public nsIStyleRule michael@0: { michael@0: public: michael@0: nsMappedAttributes(nsHTMLStyleSheet* aSheet, michael@0: nsMapRuleToAttributesFunc aMapRuleFunc); michael@0: michael@0: // Do not return null. michael@0: void* operator new(size_t size, uint32_t aAttrCount = 1) CPP_THROW_NEW; michael@0: nsMappedAttributes* Clone(bool aWillAddAttr); michael@0: michael@0: NS_DECL_ISUPPORTS michael@0: michael@0: void SetAndTakeAttr(nsIAtom* aAttrName, nsAttrValue& aValue); michael@0: const nsAttrValue* GetAttr(nsIAtom* aAttrName) const; michael@0: const nsAttrValue* GetAttr(const nsAString& aAttrName) const; michael@0: michael@0: uint32_t Count() const michael@0: { michael@0: return mAttrCount; michael@0: } michael@0: michael@0: bool Equals(const nsMappedAttributes* aAttributes) const; michael@0: uint32_t HashValue() const; michael@0: michael@0: void DropStyleSheetReference() michael@0: { michael@0: mSheet = nullptr; michael@0: } michael@0: void SetStyleSheet(nsHTMLStyleSheet* aSheet); michael@0: nsHTMLStyleSheet* GetStyleSheet() michael@0: { michael@0: return mSheet; michael@0: } michael@0: michael@0: const nsAttrName* NameAt(uint32_t aPos) const michael@0: { michael@0: NS_ASSERTION(aPos < mAttrCount, "out-of-bounds"); michael@0: return &Attrs()[aPos].mName; michael@0: } michael@0: const nsAttrValue* AttrAt(uint32_t aPos) const michael@0: { michael@0: NS_ASSERTION(aPos < mAttrCount, "out-of-bounds"); michael@0: return &Attrs()[aPos].mValue; michael@0: } michael@0: // Remove the attr at position aPos. The value of the attr is placed in michael@0: // aValue; any value that was already in aValue is destroyed. michael@0: void RemoveAttrAt(uint32_t aPos, nsAttrValue& aValue); michael@0: const nsAttrName* GetExistingAttrNameFromQName(const nsAString& aName) const; michael@0: int32_t IndexOfAttr(nsIAtom* aLocalName) const; michael@0: michael@0: michael@0: // nsIStyleRule michael@0: virtual void MapRuleInfoInto(nsRuleData* aRuleData) MOZ_OVERRIDE; michael@0: #ifdef DEBUG michael@0: virtual void List(FILE* out = stdout, int32_t aIndent = 0) const MOZ_OVERRIDE; michael@0: #endif michael@0: michael@0: size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const; michael@0: michael@0: private: michael@0: nsMappedAttributes(const nsMappedAttributes& aCopy); michael@0: ~nsMappedAttributes(); michael@0: michael@0: struct InternalAttr michael@0: { michael@0: nsAttrName mName; michael@0: nsAttrValue mValue; michael@0: }; michael@0: michael@0: /** michael@0: * Due to a compiler bug in VisualAge C++ for AIX, we need to return the michael@0: * address of the first index into mAttrs here, instead of simply michael@0: * returning mAttrs itself. michael@0: * michael@0: * See Bug 231104 for more information. michael@0: */ michael@0: const InternalAttr* Attrs() const michael@0: { michael@0: return reinterpret_cast(&(mAttrs[0])); michael@0: } michael@0: InternalAttr* Attrs() michael@0: { michael@0: return reinterpret_cast(&(mAttrs[0])); michael@0: } michael@0: michael@0: uint16_t mAttrCount; michael@0: #ifdef DEBUG michael@0: uint16_t mBufferSize; michael@0: #endif michael@0: nsHTMLStyleSheet* mSheet; //weak michael@0: nsMapRuleToAttributesFunc mRuleMapper; michael@0: void* mAttrs[1]; michael@0: }; michael@0: michael@0: #endif /* nsMappedAttributes_h___ */