Further changes required by Servo

This commit is contained in:
Oriol Brufau 2023-08-16 23:29:27 +02:00 committed by Martin Robinson
parent 1ce75ff7dd
commit 6c3f92cb85
27 changed files with 266 additions and 91 deletions

View file

@ -33,7 +33,6 @@ app_units = { workspace = true }
content-security-policy = { workspace = true, optional = true }
crossbeam-channel = { workspace = true, optional = true }
cssparser = { workspace = true }
dom = { path = "../../../dom/base/rust" }
euclid = { workspace = true }
http = { workspace = true, optional = true }
hyper_serde = { workspace = true, optional = true }

View file

@ -792,8 +792,6 @@ malloc_size_of_is_0!(app_units::Au);
malloc_size_of_is_0!(cssparser::RGBA, cssparser::TokenSerializationType);
malloc_size_of_is_0!(dom::ElementState, dom::DocumentState);
#[cfg(feature = "servo")]
malloc_size_of_is_0!(csp::Destination);

View file

@ -38,7 +38,6 @@ use servo_atoms::Atom;
use style::applicable_declarations::ApplicableDeclarationBlock;
use style::attr::{AttrValue, LengthOrPercentageOrAuto};
use style::context::QuirksMode;
use style::element_state::ElementState;
use style::invalidation::element::restyle_hints::RestyleHint;
use style::properties::longhands::{
self, background_image, border_spacing, font_family, font_size,
@ -58,6 +57,7 @@ use style::stylesheets::CssRuleType;
use style::values::generics::NonNegative;
use style::values::{computed, specified, AtomIdent, AtomString, CSSFloat};
use style::{dom_apis, thread_state, CaseSensitivityExt};
use style_traits::dom::ElementState;
use xml5ever::serialize as xmlSerialize;
use xml5ever::serialize::TraversalScope::{
ChildrenOnly as XmlChildrenOnly, IncludeNode as XmlIncludeNode,
@ -351,7 +351,7 @@ impl Element {
CustomElementState::Uncustomized | CustomElementState::Custom => true,
_ => false,
};
self.set_state(ElementState::IN_DEFINED_STATE, in_defined_state)
self.set_state(ElementState::DEFINED, in_defined_state)
}
pub fn get_custom_element_state(&self) -> CustomElementState {
@ -637,12 +637,7 @@ pub trait LayoutElementHelpers<'dom> {
impl<'dom> LayoutDom<'dom, Element> {
#[allow(unsafe_code)]
pub(super) fn focus_state(self) -> bool {
unsafe {
self.unsafe_get()
.state
.get()
.contains(ElementState::IN_FOCUS_STATE)
}
unsafe { self.unsafe_get().state.get().contains(ElementState::FOCUS) }
}
}
@ -3523,7 +3518,7 @@ impl Element {
/// <https://html.spec.whatwg.org/multipage/#concept-selector-active>
pub fn set_active_state(&self, value: bool) {
self.set_state(ElementState::IN_ACTIVE_STATE, value);
self.set_state(ElementState::ACTIVE, value);
if let Some(parent) = self.upcast::<Node>().GetParentElement() {
parent.set_active_state(value);
@ -3531,65 +3526,63 @@ impl Element {
}
pub fn focus_state(&self) -> bool {
self.state.get().contains(ElementState::IN_FOCUS_STATE)
self.state.get().contains(ElementState::FOCUS)
}
pub fn set_focus_state(&self, value: bool) {
self.set_state(ElementState::IN_FOCUS_STATE, value);
self.set_state(ElementState::FOCUS, value);
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
}
pub fn hover_state(&self) -> bool {
self.state.get().contains(ElementState::IN_HOVER_STATE)
self.state.get().contains(ElementState::HOVER)
}
pub fn set_hover_state(&self, value: bool) {
self.set_state(ElementState::IN_HOVER_STATE, value)
self.set_state(ElementState::HOVER, value)
}
pub fn enabled_state(&self) -> bool {
self.state.get().contains(ElementState::IN_ENABLED_STATE)
self.state.get().contains(ElementState::ENABLED)
}
pub fn set_enabled_state(&self, value: bool) {
self.set_state(ElementState::IN_ENABLED_STATE, value)
self.set_state(ElementState::ENABLED, value)
}
pub fn disabled_state(&self) -> bool {
self.state.get().contains(ElementState::IN_DISABLED_STATE)
self.state.get().contains(ElementState::DISABLED)
}
pub fn set_disabled_state(&self, value: bool) {
self.set_state(ElementState::IN_DISABLED_STATE, value)
self.set_state(ElementState::DISABLED, value)
}
pub fn read_write_state(&self) -> bool {
self.state.get().contains(ElementState::IN_READWRITE_STATE)
self.state.get().contains(ElementState::READWRITE)
}
pub fn set_read_write_state(&self, value: bool) {
self.set_state(ElementState::IN_READWRITE_STATE, value)
self.set_state(ElementState::READWRITE, value)
}
pub fn placeholder_shown_state(&self) -> bool {
self.state
.get()
.contains(ElementState::IN_PLACEHOLDER_SHOWN_STATE)
self.state.get().contains(ElementState::PLACEHOLDER_SHOWN)
}
pub fn set_placeholder_shown_state(&self, value: bool) {
if self.placeholder_shown_state() != value {
self.set_state(ElementState::IN_PLACEHOLDER_SHOWN_STATE, value);
self.set_state(ElementState::PLACEHOLDER_SHOWN, value);
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
}
}
pub fn set_target_state(&self, value: bool) {
self.set_state(ElementState::IN_TARGET_STATE, value)
self.set_state(ElementState::URLTARGET, value)
}
pub fn set_fullscreen_state(&self, value: bool) {
self.set_state(ElementState::IN_FULLSCREEN_STATE, value)
self.set_state(ElementState::FULLSCREEN, value)
}
/// <https://dom.spec.whatwg.org/#connected>

View file

@ -8,7 +8,7 @@ use std::default::Default;
use dom_struct::dom_struct;
use html5ever::{local_name, namespace_url, LocalName, Prefix};
use js::rust::HandleObject;
use style::element_state::ElementState;
use style_traits::dom::ElementState;
use crate::dom::activation::Activatable;
use crate::dom::attr::Attr;
@ -56,7 +56,7 @@ impl HTMLButtonElement {
) -> HTMLButtonElement {
HTMLButtonElement {
htmlelement: HTMLElement::new_inherited_with_state(
ElementState::IN_ENABLED_STATE,
ElementState::ENABLED,
local_name,
prefix,
document,

View file

@ -11,7 +11,7 @@ use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use script_layout_interface::message::QueryMsg;
use style::attr::AttrValue;
use style::element_state::*;
use style_traits::dom::ElementState;
use crate::dom::activation::Activatable;
use crate::dom::attr::Attr;

View file

@ -7,7 +7,7 @@ use std::default::Default;
use dom_struct::dom_struct;
use html5ever::{local_name, LocalName, Prefix};
use js::rust::HandleObject;
use style::element_state::ElementState;
use style_traits::dom::ElementState;
use crate::dom::attr::Attr;
use crate::dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding::HTMLFieldSetElementMethods;
@ -40,7 +40,7 @@ impl HTMLFieldSetElement {
) -> HTMLFieldSetElement {
HTMLFieldSetElement {
htmlelement: HTMLElement::new_inherited_with_state(
ElementState::IN_ENABLED_STATE | ElementState::IN_VALID_STATE,
ElementState::ENABLED | ElementState::VALID,
local_name,
prefix,
document,
@ -81,9 +81,9 @@ impl HTMLFieldSetElement {
});
self.upcast::<Element>()
.set_state(ElementState::IN_VALID_STATE, !has_invalid_child);
.set_state(ElementState::VALID, !has_invalid_child);
self.upcast::<Element>()
.set_state(ElementState::IN_INVALID_STATE, has_invalid_child);
.set_state(ElementState::INVALID, has_invalid_child);
}
}

View file

@ -18,8 +18,8 @@ use script_traits::{HistoryEntryReplacement, LoadData, LoadOrigin};
use servo_atoms::Atom;
use servo_rand::random;
use style::attr::AttrValue;
use style::element_state::ElementState;
use style::str::split_html_space_chars;
use style_traits::dom::ElementState;
use time::{now, Duration, Tm};
use super::bindings::trace::{HashMapTracedValues, NoTrace};
@ -107,7 +107,7 @@ impl HTMLFormElement {
) -> HTMLFormElement {
HTMLFormElement {
htmlelement: HTMLElement::new_inherited_with_state(
ElementState::IN_VALID_STATE,
ElementState::VALID,
local_name,
prefix,
document,
@ -693,9 +693,9 @@ impl HTMLFormElement {
});
self.upcast::<Element>()
.set_state(ElementState::IN_VALID_STATE, !is_any_invalid);
.set_state(ElementState::VALID, !is_any_invalid);
self.upcast::<Element>()
.set_state(ElementState::IN_INVALID_STATE, is_any_invalid);
.set_state(ElementState::INVALID, is_any_invalid);
}
/// [Form submission](https://html.spec.whatwg.org/multipage/#concept-form-submit)

View file

@ -30,8 +30,8 @@ use script_layout_interface::rpc::TextIndexResponse;
use script_traits::ScriptToConstellationChan;
use servo_atoms::Atom;
use style::attr::AttrValue;
use style::element_state::ElementState;
use style::str::{split_commas, str_join};
use style_traits::dom::ElementState;
use unicode_bidi::{bidi_class, BidiClass};
use url::Url;
@ -299,7 +299,7 @@ impl HTMLInputElement {
.clone();
HTMLInputElement {
htmlelement: HTMLElement::new_inherited_with_state(
ElementState::IN_ENABLED_STATE | ElementState::IN_READWRITE_STATE,
ElementState::ENABLED | ElementState::READWRITE,
local_name,
prefix,
document,
@ -1089,13 +1089,13 @@ impl<'dom> LayoutHTMLInputElementHelpers<'dom> for LayoutDom<'dom, HTMLInputElem
fn checked_state_for_layout(self) -> bool {
self.upcast::<Element>()
.get_state_for_layout()
.contains(ElementState::IN_CHECKED_STATE)
.contains(ElementState::CHECKED)
}
fn indeterminate_state_for_layout(self) -> bool {
self.upcast::<Element>()
.get_state_for_layout()
.contains(ElementState::IN_INDETERMINATE_STATE)
.contains(ElementState::INDETERMINATE)
}
}
@ -1201,7 +1201,7 @@ impl HTMLInputElementMethods for HTMLInputElement {
fn Checked(&self) -> bool {
self.upcast::<Element>()
.state()
.contains(ElementState::IN_CHECKED_STATE)
.contains(ElementState::CHECKED)
}
// https://html.spec.whatwg.org/multipage/#dom-input-checked
@ -1499,13 +1499,13 @@ impl HTMLInputElementMethods for HTMLInputElement {
fn Indeterminate(&self) -> bool {
self.upcast::<Element>()
.state()
.contains(ElementState::IN_INDETERMINATE_STATE)
.contains(ElementState::INDETERMINATE)
}
// https://html.spec.whatwg.org/multipage/#dom-input-indeterminate
fn SetIndeterminate(&self, val: bool) {
self.upcast::<Element>()
.set_state(ElementState::IN_INDETERMINATE_STATE, val)
.set_state(ElementState::INDETERMINATE, val)
}
// https://html.spec.whatwg.org/multipage/#dom-lfe-labels
@ -1803,7 +1803,7 @@ impl HTMLInputElement {
fn update_checked_state(&self, checked: bool, dirty: bool) {
self.upcast::<Element>()
.set_state(ElementState::IN_CHECKED_STATE, checked);
.set_state(ElementState::CHECKED, checked);
if dirty {
self.checked_changed.set(true);
@ -2651,7 +2651,7 @@ impl VirtualMethods for HTMLInputElement {
elem.value_dirty.set(self.value_dirty.get());
elem.checked_changed.set(self.checked_changed.get());
elem.upcast::<Element>()
.set_state(ElementState::IN_CHECKED_STATE, self.Checked());
.set_state(ElementState::CHECKED, self.Checked());
elem.textinput
.borrow_mut()
.set_content(self.textinput.borrow().get_content());

View file

@ -5,7 +5,7 @@
use dom_struct::dom_struct;
use html5ever::{local_name, LocalName, Prefix};
use js::rust::HandleObject;
use style::element_state::ElementState;
use style_traits::dom::ElementState;
use crate::dom::attr::Attr;
use crate::dom::bindings::codegen::Bindings::HTMLOptGroupElementBinding::HTMLOptGroupElementMethods;
@ -34,7 +34,7 @@ impl HTMLOptGroupElement {
) -> HTMLOptGroupElement {
HTMLOptGroupElement {
htmlelement: HTMLElement::new_inherited_with_state(
ElementState::IN_ENABLED_STATE,
ElementState::ENABLED,
local_name,
prefix,
document,

View file

@ -8,8 +8,8 @@ use std::convert::TryInto;
use dom_struct::dom_struct;
use html5ever::{local_name, namespace_url, ns, LocalName, Prefix, QualName};
use js::rust::HandleObject;
use style::element_state::ElementState;
use style::str::{split_html_space_chars, str_join};
use style_traits::dom::ElementState;
use crate::dom::attr::Attr;
use crate::dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods;
@ -55,7 +55,7 @@ impl HTMLOptionElement {
) -> HTMLOptionElement {
HTMLOptionElement {
htmlelement: HTMLElement::new_inherited_with_state(
ElementState::IN_ENABLED_STATE,
ElementState::ENABLED,
local_name,
prefix,
document,

View file

@ -9,7 +9,7 @@ use dom_struct::dom_struct;
use html5ever::{local_name, LocalName, Prefix};
use js::rust::HandleObject;
use style::attr::AttrValue;
use style::element_state::ElementState;
use style_traits::dom::ElementState;
use crate::dom::attr::Attr;
use crate::dom::bindings::codegen::Bindings::ElementBinding::ElementMethods;
@ -79,7 +79,7 @@ impl HTMLSelectElement {
) -> HTMLSelectElement {
HTMLSelectElement {
htmlelement: HTMLElement::new_inherited_with_state(
ElementState::IN_ENABLED_STATE | ElementState::IN_VALID_STATE,
ElementState::ENABLED | ElementState::VALID,
local_name,
prefix,
document,

View file

@ -11,7 +11,7 @@ use html5ever::{local_name, namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use script_traits::ScriptToConstellationChan;
use style::attr::AttrValue;
use style::element_state::ElementState;
use style_traits::dom::ElementState;
use crate::dom::attr::Attr;
use crate::dom::bindings::cell::DomRefCell;
@ -151,7 +151,7 @@ impl HTMLTextAreaElement {
.clone();
HTMLTextAreaElement {
htmlelement: HTMLElement::new_inherited_with_state(
ElementState::IN_ENABLED_STATE | ElementState::IN_READWRITE_STATE,
ElementState::ENABLED | ElementState::READWRITE,
local_name,
prefix,
document,

View file

@ -5,7 +5,7 @@
use dom_struct::dom_struct;
use html5ever::{namespace_url, ns, LocalName, Prefix};
use js::rust::HandleObject;
use style::element_state::ElementState;
use style_traits::dom::ElementState;
use crate::dom::bindings::codegen::Bindings::SVGElementBinding::SVGElementMethods;
use crate::dom::bindings::inheritance::Castable;

View file

@ -4,7 +4,7 @@
use dom_struct::dom_struct;
use html5ever::{LocalName, Prefix};
use style::element_state::ElementState;
use style_traits::dom::ElementState;
use crate::dom::bindings::inheritance::Castable;
use crate::dom::document::Document;

View file

@ -8,7 +8,7 @@ use std::fmt;
use bitflags::bitflags;
use dom_struct::dom_struct;
use itertools::Itertools;
use style::element_state::ElementState;
use style_traits::dom::ElementState;
use crate::dom::bindings::cell::{DomRefCell, Ref};
use crate::dom::bindings::codegen::Bindings::ValidityStateBinding::ValidityStateMethods;
@ -137,14 +137,11 @@ impl ValidityState {
if let Some(validatable) = self.element.as_maybe_validatable() {
if validatable.is_instance_validatable() {
let is_valid = self.invalid_flags.get().is_empty();
self.element
.set_state(ElementState::IN_VALID_STATE, is_valid);
self.element
.set_state(ElementState::IN_INVALID_STATE, !is_valid);
self.element.set_state(ElementState::VALID, is_valid);
self.element.set_state(ElementState::INVALID, !is_valid);
} else {
self.element.set_state(ElementState::IN_VALID_STATE, false);
self.element
.set_state(ElementState::IN_INVALID_STATE, false);
self.element.set_state(ElementState::VALID, false);
self.element.set_state(ElementState::INVALID, false);
}
}

View file

@ -25,7 +25,6 @@ use style::attr::AttrValue;
use style::context::SharedStyleContext;
use style::data::ElementData;
use style::dom::{DomChildren, LayoutIterator, TDocument, TElement, TNode, TShadowRoot};
use style::element_state::*;
use style::properties::PropertyDeclarationBlock;
use style::selector_parser::{
extended_filtering, AttrValue as SelectorAttrValue, Lang, NonTSPseudoClass, PseudoElement,
@ -34,6 +33,7 @@ use style::selector_parser::{
use style::shared_lock::Locked as StyleLocked;
use style::values::{AtomIdent, AtomString};
use style::CaseSensitivityExt;
use style_traits::dom::ElementState;
use crate::dom::attr::AttrHelpersForLayout;
use crate::dom::bindings::inheritance::{

View file

@ -43,7 +43,6 @@ bitflags = "1.0"
byteorder = "1.0"
cssparser = "0.29"
derive_more = "0.99"
dom = { path = "../../../dom/base/rust" }
encoding_rs = { version = "0.8", optional = true }
euclid = "0.22"
fxhash = "0.2"

View file

@ -21,7 +21,6 @@ use crate::traversal_flags::TraversalFlags;
use crate::values::AtomIdent;
use crate::{LocalName, Namespace, WeakAtom};
use atomic_refcell::{AtomicRef, AtomicRefMut};
use dom::ElementState;
use selectors::matching::{QuirksMode, VisitedHandlingMode};
use selectors::sink::Push;
use selectors::Element as SelectorsElement;
@ -30,6 +29,7 @@ use std::fmt;
use std::fmt::Debug;
use std::hash::Hash;
use std::ops::Deref;
use style_traits::dom::ElementState;
pub use style_traits::dom::OpaqueNode;

View file

@ -10,8 +10,8 @@ use crate::invalidation::element::invalidator::{DescendantInvalidationLists, Inv
use crate::invalidation::element::invalidator::{Invalidation, InvalidationProcessor};
use crate::invalidation::element::state_and_attributes;
use crate::stylist::CascadeData;
use dom::DocumentState;
use selectors::matching::{MatchingContext, MatchingMode, QuirksMode, VisitedHandlingMode, NeedsSelectorFlags};
use style_traits::dom::DocumentState;
/// A struct holding the members necessary to invalidate document state
/// selectors.

View file

@ -10,12 +10,12 @@ use crate::selector_parser::{AttrValue, NonTSPseudoClass, PseudoElement, Selecto
use crate::selector_parser::{Snapshot, SnapshotMap};
use crate::values::AtomIdent;
use crate::{CaseSensitivityExt, LocalName, Namespace, WeakAtom};
use dom::ElementState;
use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint};
use selectors::matching::{ElementSelectorFlags, MatchingContext};
use selectors::{Element, OpaqueElement};
use std::cell::Cell;
use std::fmt;
use style_traits::dom::ElementState;
/// In order to compute restyle hints, we perform a selector match against a
/// list of partial selectors whose rightmost simple selector may be sensitive

View file

@ -11,12 +11,12 @@ use crate::selector_map::{
use crate::selector_parser::SelectorImpl;
use crate::AllocErr;
use crate::{Atom, LocalName, Namespace, ShrinkIfNeeded};
use dom::{DocumentState, ElementState};
use selectors::attr::NamespaceConstraint;
use selectors::parser::{Combinator, Component};
use selectors::parser::{Selector, SelectorIter};
use selectors::visitor::SelectorVisitor;
use smallvec::SmallVec;
use style_traits::dom::{DocumentState, ElementState};
/// Mapping between (partial) CompoundSelectors (and the combinator to their
/// right) and the states and attributes they depend on.

View file

@ -17,11 +17,11 @@ use crate::selector_map::SelectorMap;
use crate::selector_parser::Snapshot;
use crate::stylesheets::origin::OriginSet;
use crate::{Atom, WeakAtom};
use dom::ElementState;
use selectors::attr::CaseSensitivity;
use selectors::matching::{matches_selector, MatchingContext, MatchingMode, VisitedHandlingMode, NeedsSelectorFlags};
use selectors::NthIndexCache;
use smallvec::SmallVec;
use style_traits::dom::ElementState;
/// The collector implementation.
struct Collector<'a, 'b: 'a, 'selectors: 'a, E>

View file

@ -10,10 +10,10 @@ use crate::stylesheets::{Namespaces, Origin, UrlExtraData};
use crate::values::serialize_atom_identifier;
use crate::Atom;
use cssparser::{Parser as CssParser, ParserInput};
use dom::ElementState;
use selectors::parser::SelectorList;
use std::fmt::{self, Debug, Write};
use style_traits::{CssWriter, ParseError, ToCss};
use style_traits::dom::ElementState;
/// A convenient alias for the type that represents an attribute value used for
/// selector parser implementation.

View file

@ -17,7 +17,7 @@ use crate::selector_parser::{PseudoElementCascadeType, SelectorParser};
use crate::values::{AtomIdent, AtomString};
use crate::{Atom, CaseSensitivityExt, LocalName, Namespace, Prefix};
use cssparser::{serialize_identifier, CowRcStr, Parser as CssParser, SourceLocation, ToCss};
use dom::{DocumentState, ElementState};
use style_traits::dom::{DocumentState, ElementState};
use fxhash::FxHashMap;
use selectors::attr::{AttrSelectorOperation, CaseSensitivity, NamespaceConstraint};
use selectors::parser::SelectorParseErrorKind;
@ -367,20 +367,20 @@ impl NonTSPseudoClass {
pub fn state_flag(&self) -> ElementState {
use self::NonTSPseudoClass::*;
match *self {
Active => ElementState::IN_ACTIVE_STATE,
Focus => ElementState::IN_FOCUS_STATE,
Fullscreen => ElementState::IN_FULLSCREEN_STATE,
Hover => ElementState::IN_HOVER_STATE,
Defined => ElementState::IN_DEFINED_STATE,
Enabled => ElementState::IN_ENABLED_STATE,
Disabled => ElementState::IN_DISABLED_STATE,
Checked => ElementState::IN_CHECKED_STATE,
Valid => ElementState::IN_VALID_STATE,
Invalid => ElementState::IN_INVALID_STATE,
Indeterminate => ElementState::IN_INDETERMINATE_STATE,
ReadOnly | ReadWrite => ElementState::IN_READWRITE_STATE,
PlaceholderShown => ElementState::IN_PLACEHOLDER_SHOWN_STATE,
Target => ElementState::IN_TARGET_STATE,
Active => ElementState::ACTIVE,
Focus => ElementState::FOCUS,
Fullscreen => ElementState::FULLSCREEN,
Hover => ElementState::HOVER,
Defined => ElementState::DEFINED,
Enabled => ElementState::ENABLED,
Disabled => ElementState::DISABLED,
Checked => ElementState::CHECKED,
Valid => ElementState::VALID,
Invalid => ElementState::INVALID,
Indeterminate => ElementState::INDETERMINATE,
ReadOnly | ReadWrite => ElementState::READWRITE,
PlaceholderShown => ElementState::PLACEHOLDER_SHOWN,
Target => ElementState::URLTARGET,
AnyLink | Lang(_) | Link | Visited | ServoNonZeroBorder => ElementState::empty(),
}

View file

@ -41,7 +41,6 @@ use crate::stylesheets::{
use crate::stylesheets::{StyleRule, StylesheetContents, StylesheetInDocument};
use crate::AllocErr;
use crate::{Atom, LocalName, Namespace, ShrinkIfNeeded, WeakAtom};
use dom::{DocumentState, ElementState};
use fxhash::FxHashMap;
use malloc_size_of::{MallocSizeOf, MallocShallowSizeOf, MallocSizeOfOps};
#[cfg(feature = "gecko")]
@ -60,6 +59,7 @@ use std::cmp::Ordering;
use std::hash::{Hash, Hasher};
use std::sync::Mutex;
use std::{mem, ops};
use style_traits::dom::{DocumentState, ElementState};
use style_traits::viewport::ViewportConstraints;
/// The type of the stylesheets that the stylist contains.

View file

@ -4,6 +4,8 @@
//! Types used to access the DOM from style calculation.
use bitflags::bitflags;
use malloc_size_of::malloc_size_of_is_0;
use malloc_size_of_derive::MallocSizeOf;
use serde::{Deserialize, Serialize};
@ -27,3 +29,191 @@ impl OpaqueNode {
self.0
}
}
// DOM types to be shared between Rust and C++.
bitflags! {
/// Event-based element states.
#[repr(C)]
pub struct ElementState: u64 {
/// The mouse is down on this element.
/// <https://html.spec.whatwg.org/multipage/#selector-active>
/// FIXME(#7333): set/unset this when appropriate
const ACTIVE = 1 << 0;
/// This element has focus.
/// <https://html.spec.whatwg.org/multipage/#selector-focus>
const FOCUS = 1 << 1;
/// The mouse is hovering over this element.
/// <https://html.spec.whatwg.org/multipage/#selector-hover>
const HOVER = 1 << 2;
/// Content is enabled (and can be disabled).
/// <http://www.whatwg.org/html/#selector-enabled>
const ENABLED = 1 << 3;
/// Content is disabled.
/// <http://www.whatwg.org/html/#selector-disabled>
const DISABLED = 1 << 4;
/// Content is checked.
/// <https://html.spec.whatwg.org/multipage/#selector-checked>
const CHECKED = 1 << 5;
/// <https://html.spec.whatwg.org/multipage/#selector-indeterminate>
const INDETERMINATE = 1 << 6;
/// <https://html.spec.whatwg.org/multipage/#selector-placeholder-shown>
const PLACEHOLDER_SHOWN = 1 << 7;
/// <https://html.spec.whatwg.org/multipage/#selector-target>
const URLTARGET = 1 << 8;
/// <https://fullscreen.spec.whatwg.org/#%3Afullscreen-pseudo-class>
const FULLSCREEN = 1 << 9;
/// <https://html.spec.whatwg.org/multipage/#selector-valid>
const VALID = 1 << 10;
/// <https://html.spec.whatwg.org/multipage/#selector-invalid>
const INVALID = 1 << 11;
/// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-ui-valid
const MOZ_UI_VALID = 1 << 12;
/// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-ui-invalid
const MOZ_UI_INVALID = 1 << 13;
/// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-broken
const BROKEN = 1 << 14;
/// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-loading
const LOADING = 1 << 15;
/// <https://html.spec.whatwg.org/multipage/#selector-required>
const REQUIRED = 1 << 16;
/// <https://html.spec.whatwg.org/multipage/#selector-optional>
/// We use an underscore to workaround a silly windows.h define.
const OPTIONAL_ = 1 << 17;
/// <https://html.spec.whatwg.org/multipage/#selector-defined>
const DEFINED = 1 << 18;
/// <https://html.spec.whatwg.org/multipage/#selector-visited>
const VISITED = 1 << 19;
/// <https://html.spec.whatwg.org/multipage/#selector-link>
const UNVISITED = 1 << 20;
/// <https://drafts.csswg.org/selectors-4/#the-any-link-pseudo>
const VISITED_OR_UNVISITED = Self::VISITED.bits | Self::UNVISITED.bits;
/// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/:-moz-drag-over
const DRAGOVER = 1 << 21;
/// <https://html.spec.whatwg.org/multipage/#selector-in-range>
const INRANGE = 1 << 22;
/// <https://html.spec.whatwg.org/multipage/#selector-out-of-range>
const OUTOFRANGE = 1 << 23;
/// <https://html.spec.whatwg.org/multipage/#selector-read-only>
const READONLY = 1 << 24;
/// <https://html.spec.whatwg.org/multipage/#selector-read-write>
const READWRITE = 1 << 25;
/// <https://html.spec.whatwg.org/multipage/#selector-default>
const DEFAULT = 1 << 26;
/// Non-standard & undocumented.
const OPTIMUM = 1 << 28;
/// Non-standard & undocumented.
const SUB_OPTIMUM = 1 << 29;
/// Non-standard & undocumented.
const SUB_SUB_OPTIMUM = 1 << 30;
/// Non-standard & undocumented.
const INCREMENT_SCRIPT_LEVEL = 1u64 << 31;
/// <https://drafts.csswg.org/selectors-4/#the-focus-visible-pseudo>
const FOCUSRING = 1u64 << 32;
/// <https://drafts.csswg.org/selectors-4/#the-focus-within-pseudo>
const FOCUS_WITHIN = 1u64 << 33;
/// :dir matching; the states are used for dynamic change detection.
/// State that elements that match :dir(ltr) are in.
const LTR = 1u64 << 34;
/// State that elements that match :dir(rtl) are in.
const RTL = 1u64 << 35;
/// State that HTML elements that have a "dir" attr are in.
const HAS_DIR_ATTR = 1u64 << 36;
/// State that HTML elements with dir="ltr" (or something
/// case-insensitively equal to "ltr") are in.
const HAS_DIR_ATTR_LTR = 1u64 << 37;
/// State that HTML elements with dir="rtl" (or something
/// case-insensitively equal to "rtl") are in.
const HAS_DIR_ATTR_RTL = 1u64 << 38;
/// State that HTML <bdi> elements without a valid-valued "dir" attr or
/// any HTML elements (including <bdi>) with dir="auto" (or something
/// case-insensitively equal to "auto") are in.
const HAS_DIR_ATTR_LIKE_AUTO = 1u64 << 39;
/// Non-standard & undocumented.
const AUTOFILL = 1u64 << 40;
/// Non-standard & undocumented.
const AUTOFILL_PREVIEW = 1u64 << 41;
/// State that dialog element is modal, for centered alignment
/// <https://html.spec.whatwg.org/multipage/#centered-alignment>
const MODAL_DIALOG = 1u64 << 42;
/// <https://html.spec.whatwg.org/multipage/#inert-subtrees>
const INERT = 1u64 << 43;
/// State for the topmost modal element in top layer
const TOPMOST_MODAL = 1u64 << 44;
/// Initially used for the devtools highlighter, but now somehow only
/// used for the devtools accessibility inspector.
const DEVTOOLS_HIGHLIGHTED = 1u64 << 45;
/// Used for the devtools style editor. Probably should go away.
const STYLEEDITOR_TRANSITIONING = 1u64 << 46;
/// For :-moz-value-empty (to show widgets like the reveal password
/// button or the clear button).
const VALUE_EMPTY = 1u64 << 47;
/// For :-moz-revealed.
const REVEALED = 1u64 << 48;
/// Some convenience unions.
const DIR_STATES = Self::LTR.bits | Self::RTL.bits;
const DIR_ATTR_STATES = Self::HAS_DIR_ATTR.bits |
Self::HAS_DIR_ATTR_LTR.bits |
Self::HAS_DIR_ATTR_RTL.bits |
Self::HAS_DIR_ATTR_LIKE_AUTO.bits;
const DISABLED_STATES = Self::DISABLED.bits | Self::ENABLED.bits;
const REQUIRED_STATES = Self::REQUIRED.bits | Self::OPTIONAL_.bits;
/// Event states that can be added and removed through
/// Element::{Add,Remove}ManuallyManagedStates.
///
/// Take care when manually managing state bits. You are responsible
/// for setting or clearing the bit when an Element is added or removed
/// from a document (e.g. in BindToTree and UnbindFromTree), if that is
/// an appropriate thing to do for your state bit.
const MANUALLY_MANAGED_STATES = Self::AUTOFILL.bits | Self::AUTOFILL_PREVIEW.bits;
/// Event states that are managed externally to an element (by the
/// EventStateManager, or by other code). As opposed to those in
/// INTRINSIC_STATES, which are are computed by the element itself
/// and returned from Element::IntrinsicState.
const EXTERNALLY_MANAGED_STATES =
Self::MANUALLY_MANAGED_STATES.bits |
Self::DIR_ATTR_STATES.bits |
Self::DISABLED_STATES.bits |
Self::REQUIRED_STATES.bits |
Self::ACTIVE.bits |
Self::DEFINED.bits |
Self::DRAGOVER.bits |
Self::FOCUS.bits |
Self::FOCUSRING.bits |
Self::FOCUS_WITHIN.bits |
Self::FULLSCREEN.bits |
Self::HOVER.bits |
Self::URLTARGET.bits |
Self::MODAL_DIALOG.bits |
Self::INERT.bits |
Self::TOPMOST_MODAL.bits |
Self::REVEALED.bits;
const INTRINSIC_STATES = !Self::EXTERNALLY_MANAGED_STATES.bits;
}
}
bitflags! {
/// Event-based document states.
#[repr(C)]
pub struct DocumentState: u64 {
/// Window activation status
const WINDOW_INACTIVE = 1 << 0;
/// RTL locale: specific to the XUL localedir attribute
const RTL_LOCALE = 1 << 1;
/// LTR locale: specific to the XUL localedir attribute
const LTR_LOCALE = 1 << 2;
/// LWTheme status
const LWTHEME = 1 << 3;
const ALL_LOCALEDIR_BITS = Self::LTR_LOCALE.bits | Self::RTL_LOCALE.bits;
}
}
malloc_size_of_is_0!(ElementState, DocumentState);

View file

@ -8,7 +8,6 @@
#![crate_name = "style_traits"]
#![crate_type = "rlib"]
#![deny(unsafe_code, missing_docs)]
use bitflags::bitflags;
use cssparser::{CowRcStr, Token};