File: PseudoStyleType.h

package info (click to toggle)
firefox 149.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,767,760 kB
  • sloc: cpp: 7,416,064; javascript: 6,752,859; ansic: 3,774,850; python: 1,250,473; xml: 641,578; asm: 439,191; java: 186,617; sh: 56,634; makefile: 18,856; objc: 13,092; perl: 12,763; pascal: 5,960; yacc: 4,583; cs: 3,846; lex: 1,720; ruby: 1,002; php: 436; lisp: 258; awk: 105; sql: 66; sed: 53; csh: 10; exp: 6
file content (164 lines) | stat: -rw-r--r-- 5,120 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_PseudoStyleType_h
#define mozilla_PseudoStyleType_h

#include <cstddef>
#include <cstdint>
#include <iosfwd>

#include "mozilla/CSSEnabledState.h"
#include "mozilla/StaticPrefs_dom.h"
#include "mozilla/StaticPrefs_layout.h"
#include "mozilla/TypedEnumBits.h"

class nsStaticAtom;

namespace mozilla {
namespace dom {
class Element;
}  // namespace dom

enum class PseudoStyleTypeFlags : uint16_t {
  NONE = 0,
  ENABLED_IN_UA = 1 << 0,
  ENABLED_IN_CHROME = 1 << 1,
  ENABLED_BY_PREF = 1 << 2,
  IS_PSEUDO_ELEMENT = 1 << 3,
  IS_CSS2 = 1 << 4,
  IS_EAGER = 1 << 5,
  IS_JS_CREATED_NAC = 1 << 6,
  IS_FLEX_OR_GRID_ITEM = 1 << 7,
  IS_ELEMENT_BACKED = 1 << 8,
  SUPPORTS_USER_ACTION_STATE = 1 << 9,
  IS_INHERITING_ANON_BOX = 1 << 10,
  IS_NON_INHERITING_ANON_BOX = 1 << 11,
  IS_ANON_BOX = IS_INHERITING_ANON_BOX | IS_NON_INHERITING_ANON_BOX,
  IS_WRAPPER_ANON_BOX = 1 << 12,
};

MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(PseudoStyleTypeFlags)

// The kind of pseudo-style that we have. This can be:
//
//  * CSS pseudo-elements (see PseudoStyleType.h).
//  * Anonymous boxes (see nsCSSAnonBoxes.h).
//  * XUL tree pseudo-element stuff.
//
// This roughly corresponds to the `PseudoElement` enum in Rust code.
enum class PseudoStyleType : uint8_t {
// If CSS pseudo-elements stop being first here, change GetPseudoType.
#define CSS_PSEUDO_STYLE_TYPE(_name, _flags) _name,
#include "mozilla/PseudoStyleTypeList.h"
#undef CSS_PSEUDO_STYLE_TYPE
  NotPseudo,
  MAX,
};

enum NonInheritingAnonBox : uint8_t {
#define CSS_NON_INHERITING_ANON_BOX(_name, _flags) _name,
#include "mozilla/PseudoStyleTypeList.h"
#undef CSS_NON_INHERITING_ANON_BOX
  _Count,
};

std::ostream& operator<<(std::ostream&, PseudoStyleType);

class PseudoStyle final {
  static const PseudoStyleTypeFlags kFlags[size_t(PseudoStyleType::MAX)];
  static const nsStaticAtom* kAtoms[size_t(PseudoStyleType::MAX)];

 public:
  static constexpr size_t kEagerPseudoCount = 4;
  using Type = PseudoStyleType;

  static PseudoStyleTypeFlags GetFlags(Type aType) {
    MOZ_ASSERT(aType < Type::MAX);
    return kFlags[size_t(aType)];
  }

  static const nsStaticAtom* GetAtom(Type aType) {
    MOZ_ASSERT(aType < Type::MAX);
    MOZ_ASSERT(aType != Type::NotPseudo);
    return kAtoms[size_t(aType)];
  }

  static bool HasAnyFlag(Type aType, PseudoStyleTypeFlags aFlags) {
    return bool(GetFlags(aType) & aFlags);
  }

  static bool IsPseudoElement(Type aType) {
    return HasAnyFlag(aType, PseudoStyleTypeFlags::IS_PSEUDO_ELEMENT);
  }

  static bool IsAnonBox(Type aType) {
    return HasAnyFlag(aType, PseudoStyleTypeFlags::IS_ANON_BOX);
  }

  static bool IsNonElement(PseudoStyleType aPseudo) {
    return aPseudo == PseudoStyleType::MozText ||
           aPseudo == PseudoStyleType::MozOofPlaceholder ||
           aPseudo == PseudoStyleType::MozFirstLetterContinuation;
  }

  static bool IsInheritingAnonBox(Type aType) {
    return HasAnyFlag(aType, PseudoStyleTypeFlags::IS_INHERITING_ANON_BOX);
  }

  static bool IsNonInheritingAnonBox(Type aType) {
    return HasAnyFlag(aType, PseudoStyleTypeFlags::IS_NON_INHERITING_ANON_BOX);
  }

  static bool IsWrapperAnonBox(Type aType) {
    return HasAnyFlag(aType, PseudoStyleTypeFlags::IS_WRAPPER_ANON_BOX);
  }

  static bool IsElementBackedPseudo(Type aType) {
    return HasAnyFlag(aType, PseudoStyleTypeFlags::IS_ELEMENT_BACKED);
  }

  static bool IsNamedViewTransitionPseudoElement(Type aType) {
    return aType == Type::ViewTransitionGroup ||
           aType == Type::ViewTransitionImagePair ||
           aType == Type::ViewTransitionOld || aType == Type::ViewTransitionNew;
  }

  static bool IsViewTransitionPseudoElement(Type aType) {
    return aType == Type::ViewTransition ||
           IsNamedViewTransitionPseudoElement(aType);
  }

  static bool IsEagerlyCascadedInServo(const Type aType) {
    return HasAnyFlag(aType, PseudoStyleTypeFlags::IS_EAGER);
  }

  // Get the NonInheriting type for a given pseudo tag. The pseudo tag must test
  // true for IsNonInheritingAnonBox.
  static NonInheritingAnonBox NonInheritingTypeForPseudoType(
      PseudoStyleType aType) {
    MOZ_ASSERT(IsNonInheritingAnonBox(aType));
    static_assert(sizeof(PseudoStyleType) == sizeof(uint8_t));
    // We rely on non-inheriting anon boxes going first.
    return NonInheritingAnonBox(static_cast<uint8_t>(aType));
  }

  static bool SupportsUserActionState(const Type aType) {
    return HasAnyFlag(aType, PseudoStyleTypeFlags::SUPPORTS_USER_ACTION_STATE);
  }

  static bool IsJSCreatedNAC(Type aType) {
    return HasAnyFlag(aType, PseudoStyleTypeFlags::IS_JS_CREATED_NAC);
  }

  static bool PseudoElementIsFlexOrGridItem(const Type aType) {
    return HasAnyFlag(aType, PseudoStyleTypeFlags::IS_FLEX_OR_GRID_ITEM);
  }
};

}  // namespace mozilla

#endif