content/base/src/nsAttrValueInlines.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 #ifndef nsAttrValueInlines_h__
michael@0 6 #define nsAttrValueInlines_h__
michael@0 7
michael@0 8 #include <stdint.h>
michael@0 9
michael@0 10 #include "nsAttrValue.h"
michael@0 11
michael@0 12 struct MiscContainer
michael@0 13 {
michael@0 14 typedef nsAttrValue::ValueType ValueType;
michael@0 15
michael@0 16 ValueType mType;
michael@0 17 // mStringBits points to either nsIAtom* or nsStringBuffer* and is used when
michael@0 18 // mType isn't mCSSStyleRule.
michael@0 19 // Note eStringBase and eAtomBase is used also to handle the type of
michael@0 20 // mStringBits.
michael@0 21 uintptr_t mStringBits;
michael@0 22 union {
michael@0 23 struct {
michael@0 24 union {
michael@0 25 int32_t mInteger;
michael@0 26 nscolor mColor;
michael@0 27 uint32_t mEnumValue;
michael@0 28 int32_t mPercent;
michael@0 29 mozilla::css::StyleRule* mCSSStyleRule;
michael@0 30 mozilla::css::URLValue* mURL;
michael@0 31 mozilla::css::ImageValue* mImage;
michael@0 32 nsAttrValue::AtomArray* mAtomArray;
michael@0 33 nsIntMargin* mIntMargin;
michael@0 34 const nsSVGAngle* mSVGAngle;
michael@0 35 const nsSVGIntegerPair* mSVGIntegerPair;
michael@0 36 const nsSVGLength2* mSVGLength;
michael@0 37 const mozilla::SVGLengthList* mSVGLengthList;
michael@0 38 const mozilla::SVGNumberList* mSVGNumberList;
michael@0 39 const nsSVGNumberPair* mSVGNumberPair;
michael@0 40 const mozilla::SVGPathData* mSVGPathData;
michael@0 41 const mozilla::SVGPointList* mSVGPointList;
michael@0 42 const mozilla::SVGAnimatedPreserveAspectRatio* mSVGPreserveAspectRatio;
michael@0 43 const mozilla::SVGStringList* mSVGStringList;
michael@0 44 const mozilla::SVGTransformList* mSVGTransformList;
michael@0 45 const nsSVGViewBox* mSVGViewBox;
michael@0 46 };
michael@0 47 uint32_t mRefCount : 31;
michael@0 48 uint32_t mCached : 1;
michael@0 49 } mValue;
michael@0 50 double mDoubleValue;
michael@0 51 };
michael@0 52
michael@0 53 MiscContainer()
michael@0 54 : mType(nsAttrValue::eColor),
michael@0 55 mStringBits(0)
michael@0 56 {
michael@0 57 MOZ_COUNT_CTOR(MiscContainer);
michael@0 58 mValue.mColor = 0;
michael@0 59 mValue.mRefCount = 0;
michael@0 60 mValue.mCached = 0;
michael@0 61 }
michael@0 62
michael@0 63 ~MiscContainer()
michael@0 64 {
michael@0 65 if (IsRefCounted()) {
michael@0 66 MOZ_ASSERT(mValue.mRefCount == 0);
michael@0 67 MOZ_ASSERT(!mValue.mCached);
michael@0 68 }
michael@0 69 MOZ_COUNT_DTOR(MiscContainer);
michael@0 70 }
michael@0 71
michael@0 72 bool GetString(nsAString& aString) const;
michael@0 73
michael@0 74 inline bool IsRefCounted() const
michael@0 75 {
michael@0 76 // Nothing stops us from refcounting (and sharing) other types of
michael@0 77 // MiscContainer (except eDoubleValue types) but there's no compelling
michael@0 78 // reason to
michael@0 79 return mType == nsAttrValue::eCSSStyleRule;
michael@0 80 }
michael@0 81
michael@0 82 inline int32_t AddRef() {
michael@0 83 MOZ_ASSERT(IsRefCounted());
michael@0 84 return ++mValue.mRefCount;
michael@0 85 }
michael@0 86
michael@0 87 inline int32_t Release() {
michael@0 88 MOZ_ASSERT(IsRefCounted());
michael@0 89 return --mValue.mRefCount;
michael@0 90 }
michael@0 91
michael@0 92 void Cache();
michael@0 93 void Evict();
michael@0 94 };
michael@0 95
michael@0 96
michael@0 97 /**
michael@0 98 * Implementation of inline methods
michael@0 99 */
michael@0 100
michael@0 101 inline int32_t
michael@0 102 nsAttrValue::GetIntegerValue() const
michael@0 103 {
michael@0 104 NS_PRECONDITION(Type() == eInteger, "wrong type");
michael@0 105 return (BaseType() == eIntegerBase)
michael@0 106 ? GetIntInternal()
michael@0 107 : GetMiscContainer()->mValue.mInteger;
michael@0 108 }
michael@0 109
michael@0 110 inline int16_t
michael@0 111 nsAttrValue::GetEnumValue() const
michael@0 112 {
michael@0 113 NS_PRECONDITION(Type() == eEnum, "wrong type");
michael@0 114 // We don't need to worry about sign extension here since we're
michael@0 115 // returning an int16_t which will cut away the top bits.
michael@0 116 return static_cast<int16_t>((
michael@0 117 (BaseType() == eIntegerBase)
michael@0 118 ? static_cast<uint32_t>(GetIntInternal())
michael@0 119 : GetMiscContainer()->mValue.mEnumValue)
michael@0 120 >> NS_ATTRVALUE_ENUMTABLEINDEX_BITS);
michael@0 121 }
michael@0 122
michael@0 123 inline float
michael@0 124 nsAttrValue::GetPercentValue() const
michael@0 125 {
michael@0 126 NS_PRECONDITION(Type() == ePercent, "wrong type");
michael@0 127 return ((BaseType() == eIntegerBase)
michael@0 128 ? GetIntInternal()
michael@0 129 : GetMiscContainer()->mValue.mPercent)
michael@0 130 / 100.0f;
michael@0 131 }
michael@0 132
michael@0 133 inline nsAttrValue::AtomArray*
michael@0 134 nsAttrValue::GetAtomArrayValue() const
michael@0 135 {
michael@0 136 NS_PRECONDITION(Type() == eAtomArray, "wrong type");
michael@0 137 return GetMiscContainer()->mValue.mAtomArray;
michael@0 138 }
michael@0 139
michael@0 140 inline mozilla::css::StyleRule*
michael@0 141 nsAttrValue::GetCSSStyleRuleValue() const
michael@0 142 {
michael@0 143 NS_PRECONDITION(Type() == eCSSStyleRule, "wrong type");
michael@0 144 return GetMiscContainer()->mValue.mCSSStyleRule;
michael@0 145 }
michael@0 146
michael@0 147 inline mozilla::css::URLValue*
michael@0 148 nsAttrValue::GetURLValue() const
michael@0 149 {
michael@0 150 NS_PRECONDITION(Type() == eURL, "wrong type");
michael@0 151 return GetMiscContainer()->mValue.mURL;
michael@0 152 }
michael@0 153
michael@0 154 inline mozilla::css::ImageValue*
michael@0 155 nsAttrValue::GetImageValue() const
michael@0 156 {
michael@0 157 NS_PRECONDITION(Type() == eImage, "wrong type");
michael@0 158 return GetMiscContainer()->mValue.mImage;
michael@0 159 }
michael@0 160
michael@0 161 inline double
michael@0 162 nsAttrValue::GetDoubleValue() const
michael@0 163 {
michael@0 164 NS_PRECONDITION(Type() == eDoubleValue, "wrong type");
michael@0 165 return GetMiscContainer()->mDoubleValue;
michael@0 166 }
michael@0 167
michael@0 168 inline bool
michael@0 169 nsAttrValue::GetIntMarginValue(nsIntMargin& aMargin) const
michael@0 170 {
michael@0 171 NS_PRECONDITION(Type() == eIntMarginValue, "wrong type");
michael@0 172 nsIntMargin* m = GetMiscContainer()->mValue.mIntMargin;
michael@0 173 if (!m)
michael@0 174 return false;
michael@0 175 aMargin = *m;
michael@0 176 return true;
michael@0 177 }
michael@0 178
michael@0 179 inline bool
michael@0 180 nsAttrValue::IsSVGType(ValueType aType) const
michael@0 181 {
michael@0 182 return aType >= eSVGTypesBegin && aType <= eSVGTypesEnd;
michael@0 183 }
michael@0 184
michael@0 185 inline void
michael@0 186 nsAttrValue::SetPtrValueAndType(void* aValue, ValueBaseType aType)
michael@0 187 {
michael@0 188 NS_ASSERTION(!(NS_PTR_TO_INT32(aValue) & ~NS_ATTRVALUE_POINTERVALUE_MASK),
michael@0 189 "pointer not properly aligned, this will crash");
michael@0 190 mBits = reinterpret_cast<intptr_t>(aValue) | aType;
michael@0 191 }
michael@0 192
michael@0 193 inline void
michael@0 194 nsAttrValue::ResetIfSet()
michael@0 195 {
michael@0 196 if (mBits) {
michael@0 197 Reset();
michael@0 198 }
michael@0 199 }
michael@0 200
michael@0 201 inline MiscContainer*
michael@0 202 nsAttrValue::GetMiscContainer() const
michael@0 203 {
michael@0 204 NS_ASSERTION(BaseType() == eOtherBase, "wrong type");
michael@0 205 return static_cast<MiscContainer*>(GetPtr());
michael@0 206 }
michael@0 207
michael@0 208 inline int32_t
michael@0 209 nsAttrValue::GetIntInternal() const
michael@0 210 {
michael@0 211 NS_ASSERTION(BaseType() == eIntegerBase,
michael@0 212 "getting integer from non-integer");
michael@0 213 // Make sure we get a signed value.
michael@0 214 // Lets hope the optimizer optimizes this into a shift. Unfortunatly signed
michael@0 215 // bitshift right is implementaion dependant.
michael@0 216 return static_cast<int32_t>(mBits & ~NS_ATTRVALUE_INTEGERTYPE_MASK) /
michael@0 217 NS_ATTRVALUE_INTEGERTYPE_MULTIPLIER;
michael@0 218 }
michael@0 219
michael@0 220 #endif

mercurial