/src/mozilla-central/layout/style/nsCSSPseudoElements.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | /* atom list for CSS pseudo-elements */ |
8 | | |
9 | | #ifndef nsCSSPseudoElements_h___ |
10 | | #define nsCSSPseudoElements_h___ |
11 | | |
12 | | #include "nsGkAtoms.h" |
13 | | #include "mozilla/CSSEnabledState.h" |
14 | | #include "mozilla/Compiler.h" |
15 | | |
16 | | // Is this pseudo-element a CSS2 pseudo-element that can be specified |
17 | | // with the single colon syntax (in addition to the double-colon syntax, |
18 | | // which can be used for all pseudo-elements)? |
19 | | // |
20 | | // Note: We also rely on this for IsEagerlyCascadedInServo. |
21 | 0 | #define CSS_PSEUDO_ELEMENT_IS_CSS2 (1<<0) |
22 | | // Is this pseudo-element a pseudo-element that can contain other |
23 | | // elements? |
24 | | // (Currently pseudo-elements are either leaves of the tree (relative to |
25 | | // real elements) or they contain other elements in a non-tree-like |
26 | | // manner (i.e., like incorrectly-nested start and end tags). It's |
27 | | // possible that in the future there might be container pseudo-elements |
28 | | // that form a properly nested tree structure. If that happens, we |
29 | | // should probably split this flag into two.) |
30 | | #define CSS_PSEUDO_ELEMENT_CONTAINS_ELEMENTS (1<<1) |
31 | | // Flag to add the ability to take into account style attribute set for the |
32 | | // pseudo element (by default it's ignored). |
33 | | #define CSS_PSEUDO_ELEMENT_SUPPORTS_STYLE_ATTRIBUTE (1<<2) |
34 | | // Flag that indicate the pseudo-element supports a user action pseudo-class |
35 | | // following it, such as :active or :hover. This would normally correspond |
36 | | // to whether the pseudo-element is tree-like, but we don't support these |
37 | | // pseudo-classes on ::before and ::after generated content yet. See |
38 | | // http://dev.w3.org/csswg/selectors4/#pseudo-elements. |
39 | 0 | #define CSS_PSEUDO_ELEMENT_SUPPORTS_USER_ACTION_STATE (1<<3) |
40 | | // Should this pseudo-element be enabled only for UA sheets? |
41 | 0 | #define CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS (1<<4) |
42 | | // Should this pseudo-element be enabled only for UA sheets and chrome |
43 | | // stylesheets? |
44 | 0 | #define CSS_PSEUDO_ELEMENT_ENABLED_IN_CHROME (1<<5) |
45 | | |
46 | | #define CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS_AND_CHROME \ |
47 | 0 | (CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS | \ |
48 | 0 | CSS_PSEUDO_ELEMENT_ENABLED_IN_CHROME) |
49 | | |
50 | | // Can we use the ChromeOnly document.createElement(..., { pseudo: "::foo" }) |
51 | | // API for creating pseudo-implementing native anonymous content in JS with this |
52 | | // pseudo-element? |
53 | 0 | #define CSS_PSEUDO_ELEMENT_IS_JS_CREATED_NAC (1<<6) |
54 | | // Does this pseudo-element act like an item for containers (such as flex and |
55 | | // grid containers) and thus needs parent display-based style fixup? |
56 | | #define CSS_PSEUDO_ELEMENT_IS_FLEX_OR_GRID_ITEM (1<<7) |
57 | | |
58 | | namespace mozilla { |
59 | | |
60 | | // The total count of CSSPseudoElement is less than 256, |
61 | | // so use uint8_t as its underlying type. |
62 | | typedef uint8_t CSSPseudoElementTypeBase; |
63 | | enum class CSSPseudoElementType : CSSPseudoElementTypeBase { |
64 | | // If the actual pseudo-elements stop being first here, change |
65 | | // GetPseudoType. |
66 | | #define CSS_PSEUDO_ELEMENT(_name, _value, _flags) \ |
67 | | _name, |
68 | | #include "nsCSSPseudoElementList.h" |
69 | | #undef CSS_PSEUDO_ELEMENT |
70 | | Count, |
71 | | InheritingAnonBox = Count, // pseudo from nsCSSAnonBoxes, |
72 | | // IsNonInheritingAnonBox false. |
73 | | NonInheritingAnonBox, // from nsCSSAnonBoxes, IsNonInheritingAnonBox true. |
74 | | #ifdef MOZ_XUL |
75 | | XULTree, |
76 | | #endif |
77 | | NotPseudo, |
78 | | MAX |
79 | | }; |
80 | | |
81 | | } // namespace mozilla |
82 | | |
83 | | class nsCSSPseudoElements |
84 | | { |
85 | | typedef mozilla::CSSPseudoElementType Type; |
86 | | typedef mozilla::CSSEnabledState EnabledState; |
87 | | |
88 | | public: |
89 | | static bool IsPseudoElement(nsAtom *aAtom); |
90 | | |
91 | | static bool IsCSS2PseudoElement(nsAtom *aAtom); |
92 | | |
93 | | // This must match EAGER_PSEUDO_COUNT in Rust code. |
94 | | static const size_t kEagerPseudoCount = 4; |
95 | | |
96 | | static bool IsEagerlyCascadedInServo(const Type aType) |
97 | 0 | { |
98 | 0 | return PseudoElementHasFlags(aType, CSS_PSEUDO_ELEMENT_IS_CSS2); |
99 | 0 | } |
100 | | |
101 | | public: |
102 | | #ifdef DEBUG |
103 | | static void AssertAtoms(); |
104 | | #endif |
105 | | |
106 | | // Alias nsCSSPseudoElements::foo() to alias nsGkAtoms::foo. |
107 | | // XXX Once nsGkAtoms::foo become constexpr variables, these can too. |
108 | | // See bug 1449787. |
109 | | #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \ |
110 | | static constexpr nsICSSPseudoElement* const& name_() \ |
111 | 0 | { \ |
112 | 0 | return nsGkAtoms::PseudoElement_##name_; \ |
113 | 0 | } Unexecuted instantiation: nsCSSPseudoElements::after() Unexecuted instantiation: nsCSSPseudoElements::before() Unexecuted instantiation: nsCSSPseudoElements::firstLetter() Unexecuted instantiation: nsCSSPseudoElements::firstLine() |
114 | | #include "nsCSSPseudoElementList.h" |
115 | | #undef CSS_PSEUDO_ELEMENT |
116 | | |
117 | | static Type GetPseudoType(nsAtom* aAtom, EnabledState aEnabledState); |
118 | | |
119 | | // Get the atom for a given Type. aType must be < CSSPseudoElementType::Count. |
120 | | // This only ever returns static atoms, so it's fine to return a raw pointer. |
121 | | static nsAtom* GetPseudoAtom(Type aType); |
122 | | |
123 | | // Get the atom for a given pseudo-element string (e.g. "::before"). This can |
124 | | // return dynamic atoms, for unrecognized pseudo-elements. |
125 | | static already_AddRefed<nsAtom> GetPseudoAtom(const nsAString& aPseudoElement); |
126 | | |
127 | | static bool PseudoElementContainsElements(const Type aType) { |
128 | | return PseudoElementHasFlags(aType, CSS_PSEUDO_ELEMENT_CONTAINS_ELEMENTS); |
129 | | } |
130 | | |
131 | | static bool PseudoElementSupportsStyleAttribute(const Type aType) { |
132 | | MOZ_ASSERT(aType < Type::Count); |
133 | | return PseudoElementHasFlags(aType, |
134 | | CSS_PSEUDO_ELEMENT_SUPPORTS_STYLE_ATTRIBUTE); |
135 | | } |
136 | | |
137 | | static bool PseudoElementSupportsUserActionState(const Type aType); |
138 | | |
139 | | static bool PseudoElementIsJSCreatedNAC(Type aType) |
140 | 0 | { |
141 | 0 | return PseudoElementHasFlags(aType, CSS_PSEUDO_ELEMENT_IS_JS_CREATED_NAC); |
142 | 0 | } |
143 | | |
144 | | static bool PseudoElementIsFlexOrGridItem(const Type aType) |
145 | | { |
146 | | return PseudoElementHasFlags(aType, |
147 | | CSS_PSEUDO_ELEMENT_IS_FLEX_OR_GRID_ITEM); |
148 | | } |
149 | | |
150 | | static bool IsEnabled(Type aType, EnabledState aEnabledState) |
151 | 0 | { |
152 | 0 | if (!PseudoElementHasAnyFlag( |
153 | 0 | aType, CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS_AND_CHROME)) { |
154 | 0 | return true; |
155 | 0 | } |
156 | 0 | |
157 | 0 | if ((aEnabledState & EnabledState::eInUASheets) && |
158 | 0 | PseudoElementHasFlags(aType, CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS)) { |
159 | 0 | return true; |
160 | 0 | } |
161 | 0 | |
162 | 0 | if ((aEnabledState & EnabledState::eInChrome) && |
163 | 0 | PseudoElementHasFlags(aType, CSS_PSEUDO_ELEMENT_ENABLED_IN_CHROME)) { |
164 | 0 | return true; |
165 | 0 | } |
166 | 0 | |
167 | 0 | return false; |
168 | 0 | } |
169 | | |
170 | | static nsString PseudoTypeAsString(Type aPseudoType); |
171 | | |
172 | | private: |
173 | | // Does the given pseudo-element have all of the flags given? |
174 | | static bool PseudoElementHasFlags(const Type aType, uint32_t aFlags) |
175 | 0 | { |
176 | 0 | MOZ_ASSERT(aType < Type::Count); |
177 | 0 | return (kPseudoElementFlags[size_t(aType)] & aFlags) == aFlags; |
178 | 0 | } |
179 | | |
180 | | static bool PseudoElementHasAnyFlag(const Type aType, uint32_t aFlags) |
181 | 0 | { |
182 | 0 | MOZ_ASSERT(aType < Type::Count); |
183 | 0 | return (kPseudoElementFlags[size_t(aType)] & aFlags) != 0; |
184 | 0 | } |
185 | | |
186 | | static const uint32_t kPseudoElementFlags[size_t(Type::Count)]; |
187 | | }; |
188 | | |
189 | | #endif /* nsCSSPseudoElements_h___ */ |