stylo_dom/lib.rs
1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use bitflags::bitflags;
6use malloc_size_of::malloc_size_of_is_0;
7
8pub const HEADING_LEVEL_OFFSET: usize = 52;
9
10// DOM types to be shared between Rust and C++.
11bitflags! {
12 /// Event-based element states.
13 #[repr(C)]
14 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
15 pub struct ElementState: u64 {
16 /// The mouse is down on this element.
17 /// <https://html.spec.whatwg.org/multipage/#selector-active>
18 /// FIXME(#7333): set/unset this when appropriate
19 const ACTIVE = 1 << 0;
20 /// This element has focus.
21 /// <https://html.spec.whatwg.org/multipage/#selector-focus>
22 const FOCUS = 1 << 1;
23 /// The mouse is hovering over this element.
24 /// <https://html.spec.whatwg.org/multipage/#selector-hover>
25 const HOVER = 1 << 2;
26 /// Content is enabled (and can be disabled).
27 /// <http://www.whatwg.org/html/#selector-enabled>
28 const ENABLED = 1 << 3;
29 /// Content is disabled.
30 /// <http://www.whatwg.org/html/#selector-disabled>
31 const DISABLED = 1 << 4;
32 /// Content is checked.
33 /// <https://html.spec.whatwg.org/multipage/#selector-checked>
34 const CHECKED = 1 << 5;
35 /// <https://html.spec.whatwg.org/multipage/#selector-indeterminate>
36 const INDETERMINATE = 1 << 6;
37 /// <https://html.spec.whatwg.org/multipage/#selector-placeholder-shown>
38 const PLACEHOLDER_SHOWN = 1 << 7;
39 /// <https://html.spec.whatwg.org/multipage/#selector-target>
40 const URLTARGET = 1 << 8;
41 /// <https://fullscreen.spec.whatwg.org/#%3Afullscreen-pseudo-class>
42 const FULLSCREEN = 1 << 9;
43 /// <https://html.spec.whatwg.org/multipage/#selector-valid>
44 const VALID = 1 << 10;
45 /// <https://html.spec.whatwg.org/multipage/#selector-invalid>
46 const INVALID = 1 << 11;
47 /// <https://drafts.csswg.org/selectors-4/#user-valid-pseudo>
48 const USER_VALID = 1 << 12;
49 /// <https://drafts.csswg.org/selectors-4/#user-invalid-pseudo>
50 const USER_INVALID = 1 << 13;
51 /// All the validity bits at once.
52 const VALIDITY_STATES = Self::VALID.bits() | Self::INVALID.bits() | Self::USER_VALID.bits() | Self::USER_INVALID.bits();
53 /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-broken
54 const BROKEN = 1 << 14;
55 /// <https://html.spec.whatwg.org/multipage/#selector-required>
56 const REQUIRED = 1 << 15;
57 /// <https://html.spec.whatwg.org/multipage/#selector-optional>
58 /// We use an underscore to workaround a silly windows.h define.
59 const OPTIONAL_ = 1 << 16;
60 /// <https://html.spec.whatwg.org/multipage/#selector-defined>
61 const DEFINED = 1 << 17;
62 /// <https://html.spec.whatwg.org/multipage/#selector-visited>
63 const VISITED = 1 << 18;
64 /// <https://html.spec.whatwg.org/multipage/#selector-link>
65 const UNVISITED = 1 << 19;
66 /// <https://drafts.csswg.org/selectors-4/#the-any-link-pseudo>
67 const VISITED_OR_UNVISITED = Self::VISITED.bits() | Self::UNVISITED.bits();
68 /// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-drag-over
69 const DRAGOVER = 1 << 20;
70 /// <https://html.spec.whatwg.org/multipage/#selector-in-range>
71 const INRANGE = 1 << 21;
72 /// <https://html.spec.whatwg.org/multipage/#selector-out-of-range>
73 const OUTOFRANGE = 1 << 22;
74 /// <https://html.spec.whatwg.org/multipage/#selector-read-only>
75 const READONLY = 1 << 23;
76 /// <https://html.spec.whatwg.org/multipage/#selector-read-write>
77 const READWRITE = 1 << 24;
78 /// <https://html.spec.whatwg.org/multipage/#selector-default>
79 const DEFAULT = 1 << 25;
80 /// Non-standard & undocumented.
81 const OPTIMUM = 1 << 26;
82 /// Non-standard & undocumented.
83 const SUB_OPTIMUM = 1 << 27;
84 /// Non-standard & undocumented.
85 const SUB_SUB_OPTIMUM = 1 << 28;
86 /// All the above <meter> bits in one place.
87 const METER_OPTIMUM_STATES = Self::OPTIMUM.bits() | Self::SUB_OPTIMUM.bits() | Self::SUB_SUB_OPTIMUM.bits();
88 /// Non-standard & undocumented.
89 const INCREMENT_SCRIPT_LEVEL = 1 << 29;
90 /// <https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo>
91 const FOCUSRING = 1 << 30;
92 /// <https://drafts.csswg.org/selectors-4/#the-focus-within-pseudo>
93 const FOCUS_WITHIN = 1u64 << 31;
94 /// :dir matching; the states are used for dynamic change detection.
95 /// State that elements that match :dir(ltr) are in.
96 const LTR = 1u64 << 32;
97 /// State that elements that match :dir(rtl) are in.
98 const RTL = 1u64 << 33;
99 /// State that HTML elements that have a "dir" attr are in.
100 const HAS_DIR_ATTR = 1u64 << 34;
101 /// State that HTML elements with dir="ltr" (or something
102 /// case-insensitively equal to "ltr") are in.
103 const HAS_DIR_ATTR_LTR = 1u64 << 35;
104 /// State that HTML elements with dir="rtl" (or something
105 /// case-insensitively equal to "rtl") are in.
106 const HAS_DIR_ATTR_RTL = 1u64 << 36;
107 /// State that HTML <bdi> elements without a valid-valued "dir" attr or
108 /// any HTML elements (including <bdi>) with dir="auto" (or something
109 /// case-insensitively equal to "auto") are in.
110 const HAS_DIR_ATTR_LIKE_AUTO = 1u64 << 37;
111 /// Non-standard & undocumented.
112 const AUTOFILL = 1u64 << 38;
113 /// Non-standard & undocumented.
114 const AUTOFILL_PREVIEW = 1u64 << 39;
115 /// State for modal elements:
116 /// <https://drafts.csswg.org/selectors-4/#modal-state>
117 const MODAL = 1u64 << 40;
118 /// <https://html.spec.whatwg.org/multipage/#inert-subtrees>
119 const INERT = 1u64 << 41;
120 /// State for the topmost modal element in top layer
121 const TOPMOST_MODAL = 1u64 << 42;
122 /// Initially used for the devtools highlighter, but now somehow only
123 /// used for the devtools accessibility inspector.
124 const DEVTOOLS_HIGHLIGHTED = 1u64 << 43;
125 /// Used for the devtools style editor. Probably should go away.
126 const STYLEEDITOR_TRANSITIONING = 1u64 << 44;
127 /// For :-moz-value-empty (to show widgets like the reveal password
128 /// button or the clear button).
129 const VALUE_EMPTY = 1u64 << 45;
130 /// For :-moz-revealed.
131 const REVEALED = 1u64 << 46;
132 /// https://html.spec.whatwg.org/#selector-popover-open
133 /// Match element's popover visibility state of showing
134 const POPOVER_OPEN = 1u64 << 47;
135 /// https://drafts.csswg.org/css-scoping-1/#the-has-slotted-pseudo
136 /// Match whether a slot element has assigned nodes
137 const HAS_SLOTTED = 1u64 << 48;
138 /// https://drafts.csswg.org/selectors-4/#open-state
139 /// Match whether an openable element is currently open
140 const OPEN = 1u64 << 49;
141 /// For :active-view-transition.
142 /// <https://www.w3.org/TR/css-view-transitions-2/#the-active-view-transition-pseudo>
143 const ACTIVE_VIEW_TRANSITION = 1u64 << 50;
144 /// For :-moz-suppress-for-print-selection.
145 const SUPPRESS_FOR_PRINT_SELECTION = 1u64 << 51;
146 /// https://drafts.csswg.org/selectors-5/#headings
147 /// These 4 bits are used to pack the elements heading level into the element state
148 /// Heading levels can be from 1-9 so 4 bits allows us to express the full range.
149 const HEADING_LEVEL_BITS = 0b1111u64 << HEADING_LEVEL_OFFSET;
150
151 /// Some convenience unions.
152 const DIR_STATES = Self::LTR.bits() | Self::RTL.bits();
153
154 const DIR_ATTR_STATES = Self::HAS_DIR_ATTR.bits() |
155 Self::HAS_DIR_ATTR_LTR.bits() |
156 Self::HAS_DIR_ATTR_RTL.bits() |
157 Self::HAS_DIR_ATTR_LIKE_AUTO.bits();
158
159 const DISABLED_STATES = Self::DISABLED.bits() | Self::ENABLED.bits();
160
161 const REQUIRED_STATES = Self::REQUIRED.bits() | Self::OPTIONAL_.bits();
162 }
163}
164
165bitflags! {
166 /// Event-based document states.
167 #[repr(C)]
168 #[derive(Clone, Copy, Debug, Eq, PartialEq)]
169 pub struct DocumentState: u64 {
170 /// Window activation status
171 const WINDOW_INACTIVE = 1 << 0;
172 /// RTL locale: specific to the XUL localedir attribute
173 const RTL_LOCALE = 1 << 1;
174 /// LTR locale: specific to the XUL localedir attribute
175 const LTR_LOCALE = 1 << 2;
176
177 const ALL_LOCALEDIR_BITS = Self::LTR_LOCALE.bits() | Self::RTL_LOCALE.bits();
178 }
179}
180
181malloc_size_of_is_0!(ElementState, DocumentState);