diff --git a/layout/style/nsCSSAnonBoxList.h b/layout/style/nsCSSAnonBoxList.h index f912522d59fb..e3afad194590 100644 --- a/layout/style/nsCSSAnonBoxList.h +++ b/layout/style/nsCSSAnonBoxList.h @@ -8,16 +8,29 @@ /* * This file contains the list of nsIAtoms and their values for CSS * pseudo-element-ish things used internally for anonymous boxes. It is - * designed to be used as inline input to nsCSSAnonBoxes.cpp *only* - * through the magic of C preprocessing. All entries must be enclosed - * in the macro CSS_ANON_BOX which will have cruel and unusual things - * done to it. The entries should be kept in some sort of logical - * order. The first argument to CSS_ANON_BOX is the C++ identifier of - * the atom. The second argument is the string value of the atom. + * designed to be used as inline input to nsCSSAnonBoxes.cpp *only* through the + * magic of C preprocessing. All entries must be enclosed in the macros + * CSS_ANON_BOX and CSS_NON_INHERITING_ANON_BOX which will have cruel and + * unusual things done to it. The entries should be kept in some sort of + * logical order. The first argument to + * CSS_ANON_BOX/CSS_NON_INHERITING_ANON_BOX is the C++ identifier of the atom. + * The second argument is the string value of the atom. + * + * CSS_NON_INHERITING_ANON_BOX is used for anon boxes that never inherit style + * from anything. This means all their property values are the initial values + * of those properties. */ // OUTPUT_CLASS=nsCSSAnonBoxes -// MACRO_NAME=CSS_ANON_BOX +// MACRO_NAME=CSS_ANON_BOX/CSS_NON_INHERITING_ANON_BOX + +#ifndef CSS_NON_INHERITING_ANON_BOX +# ifdef DEFINED_CSS_NON_INHERITING_ANON_BOX +# error "Recursive includes of nsCSSAnonBoxList.h?" +# endif /* DEFINED_CSS_NON_INHERITING_ANON_BOX */ +# define CSS_NON_INHERITING_ANON_BOX CSS_ANON_BOX +# define DEFINED_CSS_NON_INHERITING_ANON_BOX +#endif /* CSS_NON_INHERITING_ANON_BOX */ // ::-moz-text, ::-moz-oof-placeholder, and ::-moz-first-letter-continuation are // non-elements which no rule will match. @@ -102,3 +115,8 @@ CSS_ANON_BOX(mozSVGMarkerAnonChild, ":-moz-svg-marker-anon-child") CSS_ANON_BOX(mozSVGOuterSVGAnonChild, ":-moz-svg-outer-svg-anon-child") CSS_ANON_BOX(mozSVGForeignContent, ":-moz-svg-foreign-content") CSS_ANON_BOX(mozSVGText, ":-moz-svg-text") + +#ifdef DEFINED_CSS_NON_INHERITING_ANON_BOX +# undef DEFINED_CSS_NON_INHERITING_ANON_BOX +# undef CSS_NON_INHERITING_ANON_BOX +#endif /* DEFINED_CSS_NON_INHERITING_ANON_BOX */ diff --git a/layout/style/nsCSSAnonBoxes.cpp b/layout/style/nsCSSAnonBoxes.cpp index 3585c9e38d00..e6d09a6bd358 100644 --- a/layout/style/nsCSSAnonBoxes.cpp +++ b/layout/style/nsCSSAnonBoxes.cpp @@ -25,9 +25,19 @@ using namespace mozilla; #undef CSS_ANON_BOX static const nsStaticAtom CSSAnonBoxes_info[] = { -#define CSS_ANON_BOX(name_, value_) \ + // Put the non-inheriting anon boxes first, so we can index into them easily. +#define CSS_ANON_BOX(name_, value_) /* nothing */ +#define CSS_NON_INHERITING_ANON_BOX(name_, value_) \ NS_STATIC_ATOM(name_##_buffer, (nsIAtom**)&nsCSSAnonBoxes::name_), #include "nsCSSAnonBoxList.h" +#undef CSS_NON_INHERITING_ANON_BOX +#undef CSS_ANON_BOX + +#define CSS_ANON_BOX(name_, value_) \ + NS_STATIC_ATOM(name_##_buffer, (nsIAtom**)&nsCSSAnonBoxes::name_), +#define CSS_NON_INHERITING_ANON_BOX(name_, value_) /* nothing */ +#include "nsCSSAnonBoxList.h" +#undef CSS_NON_INHERITING_ANON_BOX #undef CSS_ANON_BOX }; @@ -50,3 +60,10 @@ nsCSSAnonBoxes::IsTreePseudoElement(nsIAtom* aPseudo) NS_LITERAL_STRING(":-moz-tree-")); } #endif + +/* static */ nsIAtom* +nsCSSAnonBoxes::GetNonInheritingPseudoAtom(NonInheriting aBoxType) +{ + MOZ_ASSERT(aBoxType < NonInheriting::_Count); + return *CSSAnonBoxes_info[static_cast(aBoxType)].mAtom; +} diff --git a/layout/style/nsCSSAnonBoxes.h b/layout/style/nsCSSAnonBoxes.h index dddc68b736b8..667d15e0b573 100644 --- a/layout/style/nsCSSAnonBoxes.h +++ b/layout/style/nsCSSAnonBoxes.h @@ -32,6 +32,36 @@ public: #define CSS_ANON_BOX(_name, _value) static nsICSSAnonBoxPseudo* _name; #include "nsCSSAnonBoxList.h" #undef CSS_ANON_BOX + + typedef uint8_t NonInheritingBase; + enum class NonInheriting : NonInheritingBase { +#define CSS_ANON_BOX(_name, _value) /* nothing */ +#define CSS_NON_INHERITING_ANON_BOX(_name, _value) _name, +#include "nsCSSAnonBoxList.h" +#undef CSS_NON_INHERITING_ANON_BOX +#undef CSS_ANON_BOX + _Count + }; + + // Be careful using this: if we have a lot of non-inheriting anon box types it + // might not be very fast. We may want to think of ways to handle that + // (e.g. by moving to an enum instead of an atom, like we did for + // pseudo-elements, or by adding a new value of the pseudo-element enum for + // non-inheriting anon boxes or something). + static bool IsNonInheritingAnonBox(nsIAtom* aPseudo) + { + return +#define CSS_ANON_BOX(_name, _value) /* nothing */ +#define CSS_NON_INHERITING_ANON_BOX(_name, _value) _name == aPseudo || +#include "nsCSSAnonBoxList.h" +#undef CSS_NON_INHERITING_ANON_BOX +#undef CSS_ANON_BOX + 0; + } + + // Get the atom for a given non-inheriting anon box type. aBoxType must be < + // NonInheriting::_Count. + static nsIAtom* GetNonInheritingPseudoAtom(NonInheriting aBoxType); }; #endif /* nsCSSAnonBoxes_h___ */