1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is mozilla.org code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * IBM Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 2004
20 : * IBM Corporation. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * IBM Corporation
24 : *
25 : * Alternatively, the contents of this file may be used under the terms of
26 : * either the GNU General Public License Version 2 or later (the "GPL"), or
27 : * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 : * in which case the provisions of the GPL or the LGPL are applicable instead
29 : * of those above. If you wish to allow use of your version of this file only
30 : * under the terms of either the GPL or the LGPL, and not to allow others to
31 : * use your version of this file under the terms of the MPL, indicate your
32 : * decision by deleting the provisions above and replace them with the notice
33 : * and other provisions required by the GPL or the LGPL. If you do not delete
34 : * the provisions above, a recipient may use your version of this file under
35 : * the terms of any one of the MPL, the GPL or the LGPL.
36 : *
37 : * ***** END LICENSE BLOCK ***** */
38 :
39 : /*
40 : * A unique per-element set of attributes that is used as an
41 : * nsIStyleRule; used to implement presentational attributes.
42 : */
43 :
44 : #ifndef nsMappedAttributes_h___
45 : #define nsMappedAttributes_h___
46 :
47 : #include "nsAttrAndChildArray.h"
48 : #include "nsMappedAttributeElement.h"
49 : #include "nsIStyleRule.h"
50 :
51 : class nsIAtom;
52 : class nsHTMLStyleSheet;
53 : class nsRuleWalker;
54 :
55 : class nsMappedAttributes : public nsIStyleRule
56 : {
57 : public:
58 : nsMappedAttributes(nsHTMLStyleSheet* aSheet,
59 : nsMapRuleToAttributesFunc aMapRuleFunc);
60 :
61 : void* operator new(size_t size, PRUint32 aAttrCount = 1) CPP_THROW_NEW;
62 :
63 : nsMappedAttributes* Clone(bool aWillAddAttr);
64 :
65 : NS_DECL_ISUPPORTS
66 :
67 : nsresult SetAndTakeAttr(nsIAtom* aAttrName, nsAttrValue& aValue);
68 : const nsAttrValue* GetAttr(nsIAtom* aAttrName) const;
69 :
70 0 : PRUint32 Count() const
71 : {
72 0 : return mAttrCount;
73 : }
74 :
75 : bool Equals(const nsMappedAttributes* aAttributes) const;
76 : PRUint32 HashValue() const;
77 :
78 0 : void DropStyleSheetReference()
79 : {
80 0 : mSheet = nsnull;
81 0 : }
82 : void SetStyleSheet(nsHTMLStyleSheet* aSheet);
83 0 : nsHTMLStyleSheet* GetStyleSheet()
84 : {
85 0 : return mSheet;
86 : }
87 :
88 0 : const nsAttrName* NameAt(PRUint32 aPos) const
89 : {
90 0 : NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
91 0 : return &Attrs()[aPos].mName;
92 : }
93 0 : const nsAttrValue* AttrAt(PRUint32 aPos) const
94 : {
95 0 : NS_ASSERTION(aPos < mAttrCount, "out-of-bounds");
96 0 : return &Attrs()[aPos].mValue;
97 : }
98 : // Remove the attr at position aPos. The value of the attr is placed in
99 : // aValue; any value that was already in aValue is destroyed.
100 : void RemoveAttrAt(PRUint32 aPos, nsAttrValue& aValue);
101 : const nsAttrName* GetExistingAttrNameFromQName(const nsAString& aName) const;
102 : PRInt32 IndexOfAttr(nsIAtom* aLocalName, PRInt32 aNamespaceID) const;
103 :
104 :
105 : // nsIStyleRule
106 : virtual void MapRuleInfoInto(nsRuleData* aRuleData);
107 : #ifdef DEBUG
108 : virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
109 : #endif
110 :
111 : size_t SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const;
112 :
113 : private:
114 : nsMappedAttributes(const nsMappedAttributes& aCopy);
115 : ~nsMappedAttributes();
116 :
117 : struct InternalAttr
118 0 : {
119 : nsAttrName mName;
120 : nsAttrValue mValue;
121 : };
122 :
123 : /**
124 : * Due to a compiler bug in VisualAge C++ for AIX, we need to return the
125 : * address of the first index into mAttrs here, instead of simply
126 : * returning mAttrs itself.
127 : *
128 : * See Bug 231104 for more information.
129 : */
130 0 : const InternalAttr* Attrs() const
131 : {
132 0 : return reinterpret_cast<const InternalAttr*>(&(mAttrs[0]));
133 : }
134 0 : InternalAttr* Attrs()
135 : {
136 0 : return reinterpret_cast<InternalAttr*>(&(mAttrs[0]));
137 : }
138 :
139 : PRUint16 mAttrCount;
140 : #ifdef DEBUG
141 : PRUint16 mBufferSize;
142 : #endif
143 : nsHTMLStyleSheet* mSheet; //weak
144 : nsMapRuleToAttributesFunc mRuleMapper;
145 : void* mAttrs[1];
146 : };
147 :
148 : #endif /* nsMappedAttributes_h___ */
|