Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | * temporary (expanded) representation of property-value pairs used to |
michael@0 | 8 | * hold data from matched rules during style data computation. |
michael@0 | 9 | */ |
michael@0 | 10 | |
michael@0 | 11 | #ifndef nsRuleData_h_ |
michael@0 | 12 | #define nsRuleData_h_ |
michael@0 | 13 | |
michael@0 | 14 | #include "mozilla/CSSVariableDeclarations.h" |
michael@0 | 15 | #include "nsCSSProps.h" |
michael@0 | 16 | #include "nsCSSValue.h" |
michael@0 | 17 | #include "nsStyleStructFwd.h" |
michael@0 | 18 | |
michael@0 | 19 | class nsPresContext; |
michael@0 | 20 | class nsStyleContext; |
michael@0 | 21 | struct nsRuleData; |
michael@0 | 22 | |
michael@0 | 23 | typedef void (*nsPostResolveFunc)(void* aStyleStruct, nsRuleData* aData); |
michael@0 | 24 | |
michael@0 | 25 | struct nsRuleData |
michael@0 | 26 | { |
michael@0 | 27 | const uint32_t mSIDs; |
michael@0 | 28 | bool mCanStoreInRuleTree; |
michael@0 | 29 | bool mIsImportantRule; |
michael@0 | 30 | uint16_t mLevel; // an nsStyleSet::sheetType |
michael@0 | 31 | nsPresContext* const mPresContext; |
michael@0 | 32 | nsStyleContext* const mStyleContext; |
michael@0 | 33 | |
michael@0 | 34 | // We store nsCSSValues needed to compute the data for one or more |
michael@0 | 35 | // style structs (specified by the bitfield mSIDs). These are stored |
michael@0 | 36 | // in a single array allocation (which our caller allocates; see |
michael@0 | 37 | // AutoCSSValueArray) The offset of each property |prop| in |
michael@0 | 38 | // mValueStorage is the sum of |
michael@0 | 39 | // mValueOffsets[nsCSSProps::kSIDTable[prop]] and |
michael@0 | 40 | // nsCSSProps::PropertyIndexInStruct(prop). The only place we gather |
michael@0 | 41 | // more than one style struct's data at a time is |
michael@0 | 42 | // nsRuleNode::HasAuthorSpecifiedRules; therefore some code that we |
michael@0 | 43 | // know is not called from HasAuthorSpecifiedRules assumes that the |
michael@0 | 44 | // mValueOffsets for the one struct in mSIDs is zero. |
michael@0 | 45 | nsCSSValue* const mValueStorage; // our user owns this array |
michael@0 | 46 | size_t mValueOffsets[nsStyleStructID_Length]; |
michael@0 | 47 | |
michael@0 | 48 | nsAutoPtr<mozilla::CSSVariableDeclarations> mVariables; |
michael@0 | 49 | |
michael@0 | 50 | nsRuleData(uint32_t aSIDs, nsCSSValue* aValueStorage, |
michael@0 | 51 | nsPresContext* aContext, nsStyleContext* aStyleContext); |
michael@0 | 52 | |
michael@0 | 53 | #ifdef DEBUG |
michael@0 | 54 | ~nsRuleData(); |
michael@0 | 55 | #else |
michael@0 | 56 | ~nsRuleData() {} |
michael@0 | 57 | #endif |
michael@0 | 58 | |
michael@0 | 59 | /** |
michael@0 | 60 | * Return a pointer to the value object within |this| corresponding |
michael@0 | 61 | * to property |aProperty|. |
michael@0 | 62 | * |
michael@0 | 63 | * This function must only be called if the given property is in |
michael@0 | 64 | * mSIDs. |
michael@0 | 65 | */ |
michael@0 | 66 | nsCSSValue* ValueFor(nsCSSProperty aProperty) |
michael@0 | 67 | { |
michael@0 | 68 | NS_ABORT_IF_FALSE(aProperty < eCSSProperty_COUNT_no_shorthands, |
michael@0 | 69 | "invalid or shorthand property"); |
michael@0 | 70 | |
michael@0 | 71 | nsStyleStructID sid = nsCSSProps::kSIDTable[aProperty]; |
michael@0 | 72 | size_t indexInStruct = nsCSSProps::PropertyIndexInStruct(aProperty); |
michael@0 | 73 | |
michael@0 | 74 | // This should really be nsCachedStyleData::GetBitForSID, but we can't |
michael@0 | 75 | // include that here since it includes us. |
michael@0 | 76 | NS_ABORT_IF_FALSE(mSIDs & (1 << sid), |
michael@0 | 77 | "calling nsRuleData::ValueFor on property not in mSIDs"); |
michael@0 | 78 | NS_ABORT_IF_FALSE(sid != eStyleStruct_BackendOnly && |
michael@0 | 79 | indexInStruct != size_t(-1), |
michael@0 | 80 | "backend-only property"); |
michael@0 | 81 | |
michael@0 | 82 | return mValueStorage + mValueOffsets[sid] + indexInStruct; |
michael@0 | 83 | } |
michael@0 | 84 | |
michael@0 | 85 | const nsCSSValue* ValueFor(nsCSSProperty aProperty) const { |
michael@0 | 86 | return const_cast<nsRuleData*>(this)->ValueFor(aProperty); |
michael@0 | 87 | } |
michael@0 | 88 | |
michael@0 | 89 | /** |
michael@0 | 90 | * Getters like ValueFor(aProperty), but for each property by name |
michael@0 | 91 | * (ValueForBackgroundColor, etc.), and more efficient than ValueFor. |
michael@0 | 92 | * These use the names used for the property on DOM interfaces (the |
michael@0 | 93 | * 'method' field in nsCSSPropList.h). |
michael@0 | 94 | * |
michael@0 | 95 | * Like ValueFor(), the caller must check that the property is within |
michael@0 | 96 | * mSIDs. |
michael@0 | 97 | */ |
michael@0 | 98 | #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) privatename_ |
michael@0 | 99 | #define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_, \ |
michael@0 | 100 | kwtable_, stylestruct_, stylestructoffset_, animtype_) \ |
michael@0 | 101 | nsCSSValue* ValueFor##method_() { \ |
michael@0 | 102 | NS_ABORT_IF_FALSE(mSIDs & NS_STYLE_INHERIT_BIT(stylestruct_), \ |
michael@0 | 103 | "Calling nsRuleData::ValueFor" #method_ " without " \ |
michael@0 | 104 | "NS_STYLE_INHERIT_BIT(" #stylestruct_ " in mSIDs."); \ |
michael@0 | 105 | nsStyleStructID sid = eStyleStruct_##stylestruct_; \ |
michael@0 | 106 | size_t indexInStruct = \ |
michael@0 | 107 | nsCSSProps::PropertyIndexInStruct(eCSSProperty_##id_); \ |
michael@0 | 108 | NS_ABORT_IF_FALSE(sid != eStyleStruct_BackendOnly && \ |
michael@0 | 109 | indexInStruct != size_t(-1), \ |
michael@0 | 110 | "backend-only property"); \ |
michael@0 | 111 | return mValueStorage + mValueOffsets[sid] + indexInStruct; \ |
michael@0 | 112 | } \ |
michael@0 | 113 | const nsCSSValue* ValueFor##method_() const { \ |
michael@0 | 114 | return const_cast<nsRuleData*>(this)->ValueFor##method_(); \ |
michael@0 | 115 | } |
michael@0 | 116 | #define CSS_PROP_BACKENDONLY(name_, id_, method_, flags_, pref_, \ |
michael@0 | 117 | parsevariant_, kwtable_) \ |
michael@0 | 118 | /* empty; backend-only structs are not in nsRuleData */ |
michael@0 | 119 | #include "nsCSSPropList.h" |
michael@0 | 120 | #undef CSS_PROP |
michael@0 | 121 | #undef CSS_PROP_PUBLIC_OR_PRIVATE |
michael@0 | 122 | #undef CSS_PROP_BACKENDONLY |
michael@0 | 123 | |
michael@0 | 124 | private: |
michael@0 | 125 | inline size_t GetPoisonOffset(); |
michael@0 | 126 | |
michael@0 | 127 | }; |
michael@0 | 128 | |
michael@0 | 129 | #endif |