Bug 1730256 [wpt PR 30555] - Move getWindowSegments to visualViewport.segments, a...
[gecko.git] / layout / style / nsCSSPseudoElements.h
blob244810943a1f93a9c1c1c23bac93b9a2344066d7
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/. */
7 /* atom list for CSS pseudo-elements */
9 #ifndef nsCSSPseudoElements_h___
10 #define nsCSSPseudoElements_h___
12 #include "nsGkAtoms.h"
13 #include "mozilla/CSSEnabledState.h"
14 #include "mozilla/Compiler.h"
15 #include "mozilla/PseudoStyleType.h"
16 #include "mozilla/StaticPrefs_layout.h"
18 // Is this pseudo-element a CSS2 pseudo-element that can be specified
19 // with the single colon syntax (in addition to the double-colon syntax,
20 // which can be used for all pseudo-elements)?
22 // Note: We also rely on this for IsEagerlyCascadedInServo.
23 #define CSS_PSEUDO_ELEMENT_IS_CSS2 (1 << 0)
24 // Is this pseudo-element a pseudo-element that can contain other
25 // elements?
26 // (Currently pseudo-elements are either leaves of the tree (relative to
27 // real elements) or they contain other elements in a non-tree-like
28 // manner (i.e., like incorrectly-nested start and end tags). It's
29 // possible that in the future there might be container pseudo-elements
30 // that form a properly nested tree structure. If that happens, we
31 // should probably split this flag into two.)
32 #define CSS_PSEUDO_ELEMENT_CONTAINS_ELEMENTS (1 << 1)
33 // Flag to add the ability to take into account style attribute set for the
34 // pseudo element (by default it's ignored).
35 #define CSS_PSEUDO_ELEMENT_SUPPORTS_STYLE_ATTRIBUTE (1 << 2)
36 // Flag that indicate the pseudo-element supports a user action pseudo-class
37 // following it, such as :active or :hover. This would normally correspond
38 // to whether the pseudo-element is tree-like, but we don't support these
39 // pseudo-classes on ::before and ::after generated content yet. See
40 // http://dev.w3.org/csswg/selectors4/#pseudo-elements.
41 #define CSS_PSEUDO_ELEMENT_SUPPORTS_USER_ACTION_STATE (1 << 3)
42 // Should this pseudo-element be enabled only for UA sheets?
43 #define CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS (1 << 4)
44 // Should this pseudo-element be enabled only for UA sheets and chrome
45 // stylesheets?
46 #define CSS_PSEUDO_ELEMENT_ENABLED_IN_CHROME (1 << 5)
48 #define CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS_AND_CHROME \
49 (CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS | \
50 CSS_PSEUDO_ELEMENT_ENABLED_IN_CHROME)
52 // Can we use the ChromeOnly document.createElement(..., { pseudo: "::foo" })
53 // API for creating pseudo-implementing native anonymous content in JS with this
54 // pseudo-element?
55 #define CSS_PSEUDO_ELEMENT_IS_JS_CREATED_NAC (1 << 6)
56 // Does this pseudo-element act like an item for containers (such as flex and
57 // grid containers) and thus needs parent display-based style fixup?
58 #define CSS_PSEUDO_ELEMENT_IS_FLEX_OR_GRID_ITEM (1 << 7)
60 class nsCSSPseudoElements {
61 typedef mozilla::PseudoStyleType Type;
62 typedef mozilla::CSSEnabledState EnabledState;
64 public:
65 static bool IsEagerlyCascadedInServo(const Type aType) {
66 return PseudoElementHasFlags(aType, CSS_PSEUDO_ELEMENT_IS_CSS2);
69 public:
70 #ifdef DEBUG
71 static void AssertAtoms();
72 #endif
74 // Alias nsCSSPseudoElements::foo() to nsGkAtoms::foo.
75 #define CSS_PSEUDO_ELEMENT(name_, value_, flags_) \
76 static nsCSSPseudoElementStaticAtom* name_() { \
77 return const_cast<nsCSSPseudoElementStaticAtom*>( \
78 static_cast<const nsCSSPseudoElementStaticAtom*>( \
79 nsGkAtoms::PseudoElement_##name_)); \
81 #include "nsCSSPseudoElementList.h"
82 #undef CSS_PSEUDO_ELEMENT
84 // Returns Nothing() for a syntactically invalid pseudo-element, and NotPseudo
85 // for the empty / null string.
86 static mozilla::Maybe<Type> GetPseudoType(
87 const nsAString& aPseudoElement,
88 EnabledState = EnabledState::ForAllContent);
90 // Get the atom for a given Type. aType must be <
91 // PseudoType::CSSPseudoElementsEnd.
92 // This only ever returns static atoms, so it's fine to return a raw pointer.
93 static nsAtom* GetPseudoAtom(Type aType);
95 // Get the atom for a given pseudo-element string (e.g. "::before"). This can
96 // return dynamic atoms, for unrecognized pseudo-elements.
97 static already_AddRefed<nsAtom> GetPseudoAtom(
98 const nsAString& aPseudoElement);
100 static bool PseudoElementContainsElements(const Type aType) {
101 return PseudoElementHasFlags(aType, CSS_PSEUDO_ELEMENT_CONTAINS_ELEMENTS);
104 static bool PseudoElementSupportsStyleAttribute(const Type aType) {
105 MOZ_ASSERT(aType < Type::CSSPseudoElementsEnd);
106 return PseudoElementHasFlags(aType,
107 CSS_PSEUDO_ELEMENT_SUPPORTS_STYLE_ATTRIBUTE);
110 static bool PseudoElementSupportsUserActionState(const Type aType);
112 static bool PseudoElementIsJSCreatedNAC(Type aType) {
113 return PseudoElementHasFlags(aType, CSS_PSEUDO_ELEMENT_IS_JS_CREATED_NAC);
116 static bool PseudoElementIsFlexOrGridItem(const Type aType) {
117 return PseudoElementHasFlags(aType,
118 CSS_PSEUDO_ELEMENT_IS_FLEX_OR_GRID_ITEM);
121 static bool EnabledInContent(Type aType) {
122 return !PseudoElementHasAnyFlag(
123 aType, CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS_AND_CHROME);
126 static bool IsEnabled(Type aType, EnabledState aEnabledState) {
127 if (EnabledInContent(aType)) {
128 return true;
131 if ((aEnabledState & EnabledState::InUASheets) &&
132 PseudoElementHasFlags(aType, CSS_PSEUDO_ELEMENT_ENABLED_IN_UA_SHEETS)) {
133 return true;
136 if ((aEnabledState & EnabledState::InChrome) &&
137 PseudoElementHasFlags(aType, CSS_PSEUDO_ELEMENT_ENABLED_IN_CHROME)) {
138 return true;
141 return false;
144 static nsString PseudoTypeAsString(Type aPseudoType);
146 private:
147 // Does the given pseudo-element have all of the flags given?
148 static bool PseudoElementHasFlags(const Type aType, uint32_t aFlags) {
149 MOZ_ASSERT(aType < Type::CSSPseudoElementsEnd);
150 return (kPseudoElementFlags[size_t(aType)] & aFlags) == aFlags;
153 static bool PseudoElementHasAnyFlag(const Type aType, uint32_t aFlags) {
154 MOZ_ASSERT(aType < Type::CSSPseudoElementsEnd);
155 return (kPseudoElementFlags[size_t(aType)] & aFlags) != 0;
158 static nsStaticAtom* GetAtomBase();
160 static const uint32_t kPseudoElementFlags[size_t(Type::CSSPseudoElementsEnd)];
163 #endif /* nsCSSPseudoElements_h___ */