Bug 1550519 - Show a translucent parent highlight when a subgrid is highlighted....
[gecko.git] / dom / base / nsMappedAttributes.h
blob55710169528e0c0b4147d04a6e47f7dc21963019
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/. */
7 /*
8 * A unique per-element set of attributes that is used as an
9 * nsIStyleRule; used to implement presentational attributes.
12 #ifndef nsMappedAttributes_h___
13 #define nsMappedAttributes_h___
15 #include "AttrArray.h"
16 #include "nsMappedAttributeElement.h"
17 #include "mozilla/Attributes.h"
18 #include "mozilla/ServoBindingTypes.h"
19 #include "mozilla/MemoryReporting.h"
21 class nsAtom;
22 class nsHTMLStyleSheet;
24 class nsMappedAttributes final {
25 public:
26 nsMappedAttributes(nsHTMLStyleSheet* aSheet,
27 nsMapRuleToAttributesFunc aMapRuleFunc);
29 // Do not return null.
30 void* operator new(size_t size, uint32_t aAttrCount = 1) CPP_THROW_NEW;
31 nsMappedAttributes* Clone(bool aWillAddAttr);
33 NS_INLINE_DECL_REFCOUNTING_WITH_DESTROY(nsMappedAttributes, LastRelease())
35 void SetAndSwapAttr(nsAtom* aAttrName, nsAttrValue& aValue,
36 bool* aValueWasSet);
37 const nsAttrValue* GetAttr(const nsAtom* aAttrName) const;
38 const nsAttrValue* GetAttr(const nsAString& aAttrName) const;
40 uint32_t Count() const { return mAttrCount; }
42 bool Equals(const nsMappedAttributes* aAttributes) const;
43 PLDHashNumber HashValue() const;
45 void DropStyleSheetReference() { mSheet = nullptr; }
46 void SetStyleSheet(nsHTMLStyleSheet* aSheet);
47 nsHTMLStyleSheet* GetStyleSheet() { return mSheet; }
49 void SetRuleMapper(nsMapRuleToAttributesFunc aRuleMapper) {
50 mRuleMapper = aRuleMapper;
53 const nsAttrName* NameAt(uint32_t aPos) const {
54 NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
55 return &Attrs()[aPos].mName;
57 const nsAttrValue* AttrAt(uint32_t aPos) const {
58 NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
59 return &Attrs()[aPos].mValue;
61 // Remove the attr at position aPos. The value of the attr is placed in
62 // aValue; any value that was already in aValue is destroyed.
63 void RemoveAttrAt(uint32_t aPos, nsAttrValue& aValue);
64 const nsAttrName* GetExistingAttrNameFromQName(const nsAString& aName) const;
65 int32_t IndexOfAttr(const nsAtom* aLocalName) const;
67 // Apply the contained mapper to the contained set of servo rules,
68 // unless the servo rules have already been initialized.
69 void LazilyResolveServoDeclaration(mozilla::dom::Document* aDocument);
71 // Obtain the contained servo declaration block
72 // May return null if called before the inner block
73 // has been (lazily) resolved
74 const RefPtr<RawServoDeclarationBlock>& GetServoStyle() const {
75 return mServoStyle;
78 void ClearServoStyle() {
79 MOZ_ASSERT(NS_IsMainThread());
80 mServoStyle = nullptr;
83 size_t SizeOfIncludingThis(mozilla::MallocSizeOf aMallocSizeOf) const;
85 static void Shutdown();
87 private:
88 void LastRelease();
90 nsMappedAttributes(const nsMappedAttributes& aCopy);
91 ~nsMappedAttributes();
93 struct InternalAttr {
94 nsAttrName mName;
95 nsAttrValue mValue;
98 /**
99 * Due to a compiler bug in VisualAge C++ for AIX, we need to return the
100 * address of the first index into mAttrs here, instead of simply
101 * returning mAttrs itself.
103 * See Bug 231104 for more information.
105 const InternalAttr* Attrs() const {
106 return reinterpret_cast<const InternalAttr*>(&(mAttrs[0]));
108 InternalAttr* Attrs() {
109 return reinterpret_cast<InternalAttr*>(&(mAttrs[0]));
112 uint16_t mAttrCount;
113 #ifdef DEBUG
114 uint16_t mBufferSize;
115 #endif
116 nsHTMLStyleSheet* mSheet; // weak
117 nsMapRuleToAttributesFunc mRuleMapper;
118 RefPtr<RawServoDeclarationBlock> mServoStyle;
119 void* mAttrs[1];
121 static bool sShuttingDown;
123 // We're caching some memory to avoid trashing the allocator.
124 // The memory stored at index N can hold N attribute values.
125 static nsTArray<void*>* sCachedMappedAttributeAllocations;
128 #endif /* nsMappedAttributes_h___ */