aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOriol Brufau <obrufau@igalia.com>2023-08-16 23:29:27 +0200
committerMartin Robinson <mrobinson@igalia.com>2023-10-02 14:37:19 +0000
commit6c3f92cb85e7afd2a003647800c8284420523053 (patch)
treeaf8c617835208c7a89cb84c8711086fe37eca2f1
parent1ce75ff7dd4d31eaba0f333e25dcbda68aef89d6 (diff)
downloadservo-6c3f92cb85e7afd2a003647800c8284420523053.tar.gz
servo-6c3f92cb85e7afd2a003647800c8284420523053.zip
Further changes required by Servo
-rw-r--r--components/malloc_size_of/Cargo.toml1
-rw-r--r--components/malloc_size_of/lib.rs2
-rw-r--r--components/script/dom/element.rs43
-rwxr-xr-xcomponents/script/dom/htmlbuttonelement.rs4
-rw-r--r--components/script/dom/htmlelement.rs2
-rw-r--r--components/script/dom/htmlfieldsetelement.rs8
-rw-r--r--components/script/dom/htmlformelement.rs8
-rwxr-xr-xcomponents/script/dom/htmlinputelement.rs18
-rw-r--r--components/script/dom/htmloptgroupelement.rs4
-rw-r--r--components/script/dom/htmloptionelement.rs4
-rwxr-xr-xcomponents/script/dom/htmlselectelement.rs4
-rwxr-xr-xcomponents/script/dom/htmltextareaelement.rs4
-rw-r--r--components/script/dom/svgelement.rs2
-rw-r--r--components/script/dom/svggraphicselement.rs2
-rwxr-xr-xcomponents/script/dom/validitystate.rs13
-rw-r--r--components/script/layout_dom/element.rs2
-rw-r--r--components/style/Cargo.toml1
-rw-r--r--components/style/dom.rs2
-rw-r--r--components/style/invalidation/element/document_state.rs2
-rw-r--r--components/style/invalidation/element/element_wrapper.rs2
-rw-r--r--components/style/invalidation/element/invalidation_map.rs2
-rw-r--r--components/style/invalidation/element/state_and_attributes.rs2
-rw-r--r--components/style/selector_parser.rs2
-rw-r--r--components/style/servo/selector_parser.rs30
-rw-r--r--components/style/stylist.rs2
-rw-r--r--components/style_traits/dom.rs190
-rw-r--r--components/style_traits/lib.rs1
27 files changed, 266 insertions, 91 deletions
diff --git a/components/malloc_size_of/Cargo.toml b/components/malloc_size_of/Cargo.toml
index 4908dbf16bb..feb219f3c83 100644
--- a/components/malloc_size_of/Cargo.toml
+++ b/components/malloc_size_of/Cargo.toml
@@ -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 }
diff --git a/components/malloc_size_of/lib.rs b/components/malloc_size_of/lib.rs
index ed82e596a4c..9a7be7423e6 100644
--- a/components/malloc_size_of/lib.rs
+++ b/components/malloc_size_of/lib.rs
@@ -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);
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs
index 35b869df59b..7498318d436 100644
--- a/components/script/dom/element.rs
+++ b/components/script/dom/element.rs
@@ -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>
diff --git a/components/script/dom/htmlbuttonelement.rs b/components/script/dom/htmlbuttonelement.rs
index d324c10a953..333f3538745 100755
--- a/components/script/dom/htmlbuttonelement.rs
+++ b/components/script/dom/htmlbuttonelement.rs
@@ -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,
diff --git a/components/script/dom/htmlelement.rs b/components/script/dom/htmlelement.rs
index 8874d5e5ffc..ffc9dd887a3 100644
--- a/components/script/dom/htmlelement.rs
+++ b/components/script/dom/htmlelement.rs
@@ -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;
diff --git a/components/script/dom/htmlfieldsetelement.rs b/components/script/dom/htmlfieldsetelement.rs
index a0e95ed9ca0..ff5ac4e26bc 100644
--- a/components/script/dom/htmlfieldsetelement.rs
+++ b/components/script/dom/htmlfieldsetelement.rs
@@ -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);
}
}
diff --git a/components/script/dom/htmlformelement.rs b/components/script/dom/htmlformelement.rs
index 50d99361b55..9896ec75cf8 100644
--- a/components/script/dom/htmlformelement.rs
+++ b/components/script/dom/htmlformelement.rs
@@ -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)
diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs
index 931882082ad..8c082a70e49 100755
--- a/components/script/dom/htmlinputelement.rs
+++ b/components/script/dom/htmlinputelement.rs
@@ -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());
diff --git a/components/script/dom/htmloptgroupelement.rs b/components/script/dom/htmloptgroupelement.rs
index 58c943a5fb3..881ec922cd4 100644
--- a/components/script/dom/htmloptgroupelement.rs
+++ b/components/script/dom/htmloptgroupelement.rs
@@ -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,
diff --git a/components/script/dom/htmloptionelement.rs b/components/script/dom/htmloptionelement.rs
index c04ecc639fe..6a919c84df3 100644
--- a/components/script/dom/htmloptionelement.rs
+++ b/components/script/dom/htmloptionelement.rs
@@ -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,
diff --git a/components/script/dom/htmlselectelement.rs b/components/script/dom/htmlselectelement.rs
index a7eb1ea6060..c4d133e922c 100755
--- a/components/script/dom/htmlselectelement.rs
+++ b/components/script/dom/htmlselectelement.rs
@@ -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,
diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs
index 93cc3c6d292..ca77d6cefad 100755
--- a/components/script/dom/htmltextareaelement.rs
+++ b/components/script/dom/htmltextareaelement.rs
@@ -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,
diff --git a/components/script/dom/svgelement.rs b/components/script/dom/svgelement.rs
index c4975d1178c..b92f902f369 100644
--- a/components/script/dom/svgelement.rs
+++ b/components/script/dom/svgelement.rs
@@ -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;
diff --git a/components/script/dom/svggraphicselement.rs b/components/script/dom/svggraphicselement.rs
index 4ba18af76aa..2a3f7f139c3 100644
--- a/components/script/dom/svggraphicselement.rs
+++ b/components/script/dom/svggraphicselement.rs
@@ -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;
diff --git a/components/script/dom/validitystate.rs b/components/script/dom/validitystate.rs
index 6d71181a426..a3dff8b585f 100755
--- a/components/script/dom/validitystate.rs
+++ b/components/script/dom/validitystate.rs
@@ -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);
}
}
diff --git a/components/script/layout_dom/element.rs b/components/script/layout_dom/element.rs
index b923cdb12f8..94e2676fff5 100644
--- a/components/script/layout_dom/element.rs
+++ b/components/script/layout_dom/element.rs
@@ -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::{
diff --git a/components/style/Cargo.toml b/components/style/Cargo.toml
index 103271d4b46..e5b9640b430 100644
--- a/components/style/Cargo.toml
+++ b/components/style/Cargo.toml
@@ -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"
diff --git a/components/style/dom.rs b/components/style/dom.rs
index 74afca8c977..425b61575d2 100644
--- a/components/style/dom.rs
+++ b/components/style/dom.rs
@@ -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;
diff --git a/components/style/invalidation/element/document_state.rs b/components/style/invalidation/element/document_state.rs
index 5b308cbdfa4..c43a519a7ed 100644
--- a/components/style/invalidation/element/document_state.rs
+++ b/components/style/invalidation/element/document_state.rs
@@ -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.
diff --git a/components/style/invalidation/element/element_wrapper.rs b/components/style/invalidation/element/element_wrapper.rs
index b244f45d1c4..388097f53e8 100644
--- a/components/style/invalidation/element/element_wrapper.rs
+++ b/components/style/invalidation/element/element_wrapper.rs
@@ -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
diff --git a/components/style/invalidation/element/invalidation_map.rs b/components/style/invalidation/element/invalidation_map.rs
index e319116b43a..12d1ada4eba 100644
--- a/components/style/invalidation/element/invalidation_map.rs
+++ b/components/style/invalidation/element/invalidation_map.rs
@@ -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.
diff --git a/components/style/invalidation/element/state_and_attributes.rs b/components/style/invalidation/element/state_and_attributes.rs
index 62642dec761..fc3f0bb064a 100644
--- a/components/style/invalidation/element/state_and_attributes.rs
+++ b/components/style/invalidation/element/state_and_attributes.rs
@@ -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>
diff --git a/components/style/selector_parser.rs b/components/style/selector_parser.rs
index 4586c33f470..1af4d6ff07a 100644
--- a/components/style/selector_parser.rs
+++ b/components/style/selector_parser.rs
@@ -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.
diff --git a/components/style/servo/selector_parser.rs b/components/style/servo/selector_parser.rs
index 33b8a2d4463..d2488790025 100644
--- a/components/style/servo/selector_parser.rs
+++ b/components/style/servo/selector_parser.rs
@@ -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(),
}
diff --git a/components/style/stylist.rs b/components/style/stylist.rs
index b2d102523b5..b895a4f4154 100644
--- a/components/style/stylist.rs
+++ b/components/style/stylist.rs
@@ -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.
diff --git a/components/style_traits/dom.rs b/components/style_traits/dom.rs
index 78bc9e0d3fb..a5a5b8d5e43 100644
--- a/components/style_traits/dom.rs
+++ b/components/style_traits/dom.rs
@@ -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);
diff --git a/components/style_traits/lib.rs b/components/style_traits/lib.rs
index 1fe46743293..cff19722513 100644
--- a/components/style_traits/lib.rs
+++ b/components/style_traits/lib.rs
@@ -8,7 +8,6 @@
#![crate_name = "style_traits"]
#![crate_type = "rlib"]
-#![deny(unsafe_code, missing_docs)]
use bitflags::bitflags;
use cssparser::{CowRcStr, Token};