layout/style/nsRuleData.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/style/nsRuleData.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,129 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.8 +
     1.9 +/*
    1.10 + * temporary (expanded) representation of property-value pairs used to
    1.11 + * hold data from matched rules during style data computation.
    1.12 + */
    1.13 +
    1.14 +#ifndef nsRuleData_h_
    1.15 +#define nsRuleData_h_
    1.16 +
    1.17 +#include "mozilla/CSSVariableDeclarations.h"
    1.18 +#include "nsCSSProps.h"
    1.19 +#include "nsCSSValue.h"
    1.20 +#include "nsStyleStructFwd.h"
    1.21 +
    1.22 +class nsPresContext;
    1.23 +class nsStyleContext;
    1.24 +struct nsRuleData;
    1.25 +
    1.26 +typedef void (*nsPostResolveFunc)(void* aStyleStruct, nsRuleData* aData);
    1.27 +
    1.28 +struct nsRuleData
    1.29 +{
    1.30 +  const uint32_t mSIDs;
    1.31 +  bool mCanStoreInRuleTree;
    1.32 +  bool mIsImportantRule;
    1.33 +  uint16_t mLevel; // an nsStyleSet::sheetType
    1.34 +  nsPresContext* const mPresContext;
    1.35 +  nsStyleContext* const mStyleContext;
    1.36 +
    1.37 +  // We store nsCSSValues needed to compute the data for one or more
    1.38 +  // style structs (specified by the bitfield mSIDs).  These are stored
    1.39 +  // in a single array allocation (which our caller allocates; see
    1.40 +  // AutoCSSValueArray)   The offset of each property |prop| in
    1.41 +  // mValueStorage is the sum of
    1.42 +  // mValueOffsets[nsCSSProps::kSIDTable[prop]] and
    1.43 +  // nsCSSProps::PropertyIndexInStruct(prop).  The only place we gather
    1.44 +  // more than one style struct's data at a time is
    1.45 +  // nsRuleNode::HasAuthorSpecifiedRules; therefore some code that we
    1.46 +  // know is not called from HasAuthorSpecifiedRules assumes that the
    1.47 +  // mValueOffsets for the one struct in mSIDs is zero.
    1.48 +  nsCSSValue* const mValueStorage; // our user owns this array
    1.49 +  size_t mValueOffsets[nsStyleStructID_Length];
    1.50 +
    1.51 +  nsAutoPtr<mozilla::CSSVariableDeclarations> mVariables;
    1.52 +
    1.53 +  nsRuleData(uint32_t aSIDs, nsCSSValue* aValueStorage,
    1.54 +             nsPresContext* aContext, nsStyleContext* aStyleContext);
    1.55 +
    1.56 +#ifdef DEBUG
    1.57 +  ~nsRuleData();
    1.58 +#else
    1.59 +  ~nsRuleData() {}
    1.60 +#endif
    1.61 +
    1.62 +  /**
    1.63 +   * Return a pointer to the value object within |this| corresponding
    1.64 +   * to property |aProperty|.
    1.65 +   *
    1.66 +   * This function must only be called if the given property is in
    1.67 +   * mSIDs.
    1.68 +   */
    1.69 +  nsCSSValue* ValueFor(nsCSSProperty aProperty)
    1.70 +  {
    1.71 +    NS_ABORT_IF_FALSE(aProperty < eCSSProperty_COUNT_no_shorthands,
    1.72 +                      "invalid or shorthand property");
    1.73 +
    1.74 +    nsStyleStructID sid = nsCSSProps::kSIDTable[aProperty];
    1.75 +    size_t indexInStruct = nsCSSProps::PropertyIndexInStruct(aProperty);
    1.76 +
    1.77 +    // This should really be nsCachedStyleData::GetBitForSID, but we can't
    1.78 +    // include that here since it includes us.
    1.79 +    NS_ABORT_IF_FALSE(mSIDs & (1 << sid),
    1.80 +                      "calling nsRuleData::ValueFor on property not in mSIDs");
    1.81 +    NS_ABORT_IF_FALSE(sid != eStyleStruct_BackendOnly &&
    1.82 +                      indexInStruct != size_t(-1),
    1.83 +                      "backend-only property");
    1.84 +
    1.85 +    return mValueStorage + mValueOffsets[sid] + indexInStruct;
    1.86 +  }
    1.87 +
    1.88 +  const nsCSSValue* ValueFor(nsCSSProperty aProperty) const {
    1.89 +    return const_cast<nsRuleData*>(this)->ValueFor(aProperty);
    1.90 +  }
    1.91 +
    1.92 +  /**
    1.93 +   * Getters like ValueFor(aProperty), but for each property by name
    1.94 +   * (ValueForBackgroundColor, etc.), and more efficient than ValueFor.
    1.95 +   * These use the names used for the property on DOM interfaces (the
    1.96 +   * 'method' field in nsCSSPropList.h).
    1.97 +   *
    1.98 +   * Like ValueFor(), the caller must check that the property is within
    1.99 +   * mSIDs.
   1.100 +   */
   1.101 +  #define CSS_PROP_PUBLIC_OR_PRIVATE(publicname_, privatename_) privatename_
   1.102 +  #define CSS_PROP(name_, id_, method_, flags_, pref_, parsevariant_,        \
   1.103 +                   kwtable_, stylestruct_, stylestructoffset_, animtype_)    \
   1.104 +    nsCSSValue* ValueFor##method_() {                                        \
   1.105 +      NS_ABORT_IF_FALSE(mSIDs & NS_STYLE_INHERIT_BIT(stylestruct_),          \
   1.106 +                        "Calling nsRuleData::ValueFor" #method_ " without "  \
   1.107 +                        "NS_STYLE_INHERIT_BIT(" #stylestruct_ " in mSIDs."); \
   1.108 +      nsStyleStructID sid = eStyleStruct_##stylestruct_;                     \
   1.109 +      size_t indexInStruct =                                                 \
   1.110 +        nsCSSProps::PropertyIndexInStruct(eCSSProperty_##id_);               \
   1.111 +      NS_ABORT_IF_FALSE(sid != eStyleStruct_BackendOnly &&                   \
   1.112 +                        indexInStruct != size_t(-1),                         \
   1.113 +                        "backend-only property");                            \
   1.114 +      return mValueStorage + mValueOffsets[sid] + indexInStruct;             \
   1.115 +    }                                                                        \
   1.116 +    const nsCSSValue* ValueFor##method_() const {                            \
   1.117 +      return const_cast<nsRuleData*>(this)->ValueFor##method_();             \
   1.118 +    }
   1.119 +  #define CSS_PROP_BACKENDONLY(name_, id_, method_, flags_, pref_,           \
   1.120 +                             parsevariant_, kwtable_)                        \
   1.121 +    /* empty; backend-only structs are not in nsRuleData  */
   1.122 +  #include "nsCSSPropList.h"
   1.123 +  #undef CSS_PROP
   1.124 +  #undef CSS_PROP_PUBLIC_OR_PRIVATE
   1.125 +  #undef CSS_PROP_BACKENDONLY
   1.126 +
   1.127 +private:
   1.128 +  inline size_t GetPoisonOffset();
   1.129 +
   1.130 +};
   1.131 +
   1.132 +#endif

mercurial