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