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.)

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

mercurial