mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Auto merge of #26083 - servo:layout-2020-more-cleanups, r=jdm
More layout cleanups from the introduction of a lifetime in LayoutDom<T> What can I say, the follow-up fixes just kept coming to my door one by one, I couldn't just tell them to go away.
This commit is contained in:
commit
af1ebe79ef
23 changed files with 602 additions and 696 deletions
|
@ -48,7 +48,6 @@ use script::layout_exports::{Document, Element, Node, Text};
|
||||||
use script::layout_exports::{LayoutCharacterDataHelpers, LayoutDocumentHelpers};
|
use script::layout_exports::{LayoutCharacterDataHelpers, LayoutDocumentHelpers};
|
||||||
use script::layout_exports::{
|
use script::layout_exports::{
|
||||||
LayoutDom, LayoutElementHelpers, LayoutNodeHelpers, LayoutShadowRootHelpers,
|
LayoutDom, LayoutElementHelpers, LayoutNodeHelpers, LayoutShadowRootHelpers,
|
||||||
RawLayoutElementHelpers,
|
|
||||||
};
|
};
|
||||||
use script_layout_interface::wrapper_traits::{
|
use script_layout_interface::wrapper_traits::{
|
||||||
DangerousThreadSafeLayoutNode, GetLayoutData, LayoutNode,
|
DangerousThreadSafeLayoutNode, GetLayoutData, LayoutNode,
|
||||||
|
@ -136,13 +135,13 @@ impl<'ln> ServoLayoutNode<'ln> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn script_type_id(&self) -> NodeTypeId {
|
fn script_type_id(&self) -> NodeTypeId {
|
||||||
unsafe { self.node.type_id_for_layout() }
|
self.node.type_id_for_layout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ln> NodeInfo for ServoLayoutNode<'ln> {
|
impl<'ln> NodeInfo for ServoLayoutNode<'ln> {
|
||||||
fn is_element(&self) -> bool {
|
fn is_element(&self) -> bool {
|
||||||
unsafe { self.node.is_element_for_layout() }
|
self.node.is_element_for_layout()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_text_node(&self) -> bool {
|
fn is_text_node(&self) -> bool {
|
||||||
|
@ -171,14 +170,14 @@ impl<'lr> TShadowRoot for ServoShadowRoot<'lr> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn host(&self) -> ServoLayoutElement<'lr> {
|
fn host(&self) -> ServoLayoutElement<'lr> {
|
||||||
ServoLayoutElement::from_layout_js(unsafe { self.shadow_root.get_host_for_layout() })
|
ServoLayoutElement::from_layout_js(self.shadow_root.get_host_for_layout())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn style_data<'a>(&self) -> Option<&'a CascadeData>
|
fn style_data<'a>(&self) -> Option<&'a CascadeData>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
Some(unsafe { &self.shadow_root.get_style_data_for_layout().data })
|
Some(&self.shadow_root.get_style_data_for_layout())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,31 +203,29 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
|
||||||
type ConcreteShadowRoot = ServoShadowRoot<'ln>;
|
type ConcreteShadowRoot = ServoShadowRoot<'ln>;
|
||||||
|
|
||||||
fn parent_node(&self) -> Option<Self> {
|
fn parent_node(&self) -> Option<Self> {
|
||||||
unsafe {
|
|
||||||
self.node
|
self.node
|
||||||
.composed_parent_node_ref()
|
.composed_parent_node_ref()
|
||||||
.map(Self::from_layout_js)
|
.map(Self::from_layout_js)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn first_child(&self) -> Option<Self> {
|
fn first_child(&self) -> Option<Self> {
|
||||||
unsafe { self.node.first_child_ref().map(Self::from_layout_js) }
|
self.node.first_child_ref().map(Self::from_layout_js)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn last_child(&self) -> Option<Self> {
|
fn last_child(&self) -> Option<Self> {
|
||||||
unsafe { self.node.last_child_ref().map(Self::from_layout_js) }
|
self.node.last_child_ref().map(Self::from_layout_js)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prev_sibling(&self) -> Option<Self> {
|
fn prev_sibling(&self) -> Option<Self> {
|
||||||
unsafe { self.node.prev_sibling_ref().map(Self::from_layout_js) }
|
self.node.prev_sibling_ref().map(Self::from_layout_js)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_sibling(&self) -> Option<Self> {
|
fn next_sibling(&self) -> Option<Self> {
|
||||||
unsafe { self.node.next_sibling_ref().map(Self::from_layout_js) }
|
self.node.next_sibling_ref().map(Self::from_layout_js)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn owner_doc(&self) -> Self::ConcreteDocument {
|
fn owner_doc(&self) -> Self::ConcreteDocument {
|
||||||
ServoLayoutDocument::from_layout_js(unsafe { self.node.owner_doc_for_layout() })
|
ServoLayoutDocument::from_layout_js(self.node.owner_doc_for_layout())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn traversal_parent(&self) -> Option<ServoLayoutElement<'ln>> {
|
fn traversal_parent(&self) -> Option<ServoLayoutElement<'ln>> {
|
||||||
|
@ -346,11 +343,11 @@ impl<'ld> TDocument for ServoLayoutDocument<'ld> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn quirks_mode(&self) -> QuirksMode {
|
fn quirks_mode(&self) -> QuirksMode {
|
||||||
unsafe { self.document.quirks_mode() }
|
self.document.quirks_mode()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_html_document(&self) -> bool {
|
fn is_html_document(&self) -> bool {
|
||||||
unsafe { self.document.is_html_document_for_layout() }
|
self.document.is_html_document_for_layout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -371,7 +368,7 @@ impl<'ld> ServoLayoutDocument<'ld> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn style_shared_lock(&self) -> &StyleSharedRwLock {
|
pub fn style_shared_lock(&self) -> &StyleSharedRwLock {
|
||||||
unsafe { self.document.style_shared_lock() }
|
self.document.style_shared_lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn shadow_roots(&self) -> Vec<ServoShadowRoot> {
|
pub fn shadow_roots(&self) -> Vec<ServoShadowRoot> {
|
||||||
|
@ -444,7 +441,7 @@ impl<'le> TElement for ServoLayoutElement<'le> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_html_element(&self) -> bool {
|
fn is_html_element(&self) -> bool {
|
||||||
unsafe { self.element.is_html_element() }
|
self.element.is_html_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_mathml_element(&self) -> bool {
|
fn is_mathml_element(&self) -> bool {
|
||||||
|
@ -490,14 +487,12 @@ impl<'le> TElement for ServoLayoutElement<'le> {
|
||||||
where
|
where
|
||||||
F: FnMut(&Atom),
|
F: FnMut(&Atom),
|
||||||
{
|
{
|
||||||
unsafe {
|
|
||||||
if let Some(ref classes) = self.element.get_classes_for_layout() {
|
if let Some(ref classes) = self.element.get_classes_for_layout() {
|
||||||
for class in *classes {
|
for class in *classes {
|
||||||
callback(class)
|
callback(class)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn has_dirty_descendants(&self) -> bool {
|
fn has_dirty_descendants(&self) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -644,30 +639,24 @@ impl<'le> TElement for ServoLayoutElement<'le> {
|
||||||
) where
|
) where
|
||||||
V: Push<ApplicableDeclarationBlock>,
|
V: Push<ApplicableDeclarationBlock>,
|
||||||
{
|
{
|
||||||
unsafe {
|
|
||||||
self.element
|
self.element
|
||||||
.synthesize_presentational_hints_for_legacy_attributes(hints);
|
.synthesize_presentational_hints_for_legacy_attributes(hints);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// The shadow root this element is a host of.
|
/// The shadow root this element is a host of.
|
||||||
fn shadow_root(&self) -> Option<ServoShadowRoot<'le>> {
|
fn shadow_root(&self) -> Option<ServoShadowRoot<'le>> {
|
||||||
unsafe {
|
|
||||||
self.element
|
self.element
|
||||||
.get_shadow_root_for_layout()
|
.get_shadow_root_for_layout()
|
||||||
.map(ServoShadowRoot::from_layout_js)
|
.map(ServoShadowRoot::from_layout_js)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// The shadow root which roots the subtree this element is contained in.
|
/// The shadow root which roots the subtree this element is contained in.
|
||||||
fn containing_shadow(&self) -> Option<ServoShadowRoot<'le>> {
|
fn containing_shadow(&self) -> Option<ServoShadowRoot<'le>> {
|
||||||
unsafe {
|
|
||||||
self.element
|
self.element
|
||||||
.upcast()
|
.upcast()
|
||||||
.containing_shadow_root_for_layout()
|
.containing_shadow_root_for_layout()
|
||||||
.map(ServoShadowRoot::from_layout_js)
|
.map(ServoShadowRoot::from_layout_js)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn local_name(&self) -> &LocalName {
|
fn local_name(&self) -> &LocalName {
|
||||||
self.element.local_name()
|
self.element.local_name()
|
||||||
|
@ -699,12 +688,12 @@ impl<'le> ServoLayoutElement<'le> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_attr_enum(&self, namespace: &Namespace, name: &LocalName) -> Option<&AttrValue> {
|
fn get_attr_enum(&self, namespace: &Namespace, name: &LocalName) -> Option<&AttrValue> {
|
||||||
unsafe { (*self.element.unsafe_get()).get_attr_for_layout(namespace, name) }
|
self.element.get_attr_for_layout(namespace, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_attr(&self, namespace: &Namespace, name: &LocalName) -> Option<&str> {
|
fn get_attr(&self, namespace: &Namespace, name: &LocalName) -> Option<&str> {
|
||||||
unsafe { (*self.element.unsafe_get()).get_attr_val_for_layout(namespace, name) }
|
self.element.get_attr_val_for_layout(namespace, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_style_data(&self) -> Option<&StyleData> {
|
fn get_style_data(&self) -> Option<&StyleData> {
|
||||||
|
@ -752,13 +741,11 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parent_element(&self) -> Option<ServoLayoutElement<'le>> {
|
fn parent_element(&self) -> Option<ServoLayoutElement<'le>> {
|
||||||
unsafe {
|
|
||||||
self.element
|
self.element
|
||||||
.upcast()
|
.upcast()
|
||||||
.composed_parent_node_ref()
|
.composed_parent_node_ref()
|
||||||
.and_then(as_element)
|
.and_then(as_element)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn parent_node_is_shadow_root(&self) -> bool {
|
fn parent_node_is_shadow_root(&self) -> bool {
|
||||||
match self.as_node().parent_node() {
|
match self.as_node().parent_node() {
|
||||||
|
@ -806,11 +793,11 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
||||||
NamespaceConstraint::Specific(ref ns) => self
|
NamespaceConstraint::Specific(ref ns) => self
|
||||||
.get_attr_enum(ns, local_name)
|
.get_attr_enum(ns, local_name)
|
||||||
.map_or(false, |value| value.eval_selector(operation)),
|
.map_or(false, |value| value.eval_selector(operation)),
|
||||||
NamespaceConstraint::Any => {
|
NamespaceConstraint::Any => self
|
||||||
let values =
|
.element
|
||||||
unsafe { (*self.element.unsafe_get()).get_attr_vals_for_layout(local_name) };
|
.get_attr_vals_for_layout(local_name)
|
||||||
values.iter().any(|value| value.eval_selector(operation))
|
.iter()
|
||||||
},
|
.any(|value| value.eval_selector(operation)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -880,8 +867,9 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
||||||
|
|
||||||
NonTSPseudoClass::Lang(ref lang) => self.match_element_lang(None, &*lang),
|
NonTSPseudoClass::Lang(ref lang) => self.match_element_lang(None, &*lang),
|
||||||
|
|
||||||
NonTSPseudoClass::ServoNonZeroBorder => unsafe {
|
NonTSPseudoClass::ServoNonZeroBorder => {
|
||||||
match (*self.element.unsafe_get())
|
match self
|
||||||
|
.element
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("border"))
|
.get_attr_for_layout(&ns!(), &local_name!("border"))
|
||||||
{
|
{
|
||||||
None | Some(&AttrValue::UInt(_, 0)) => false,
|
None | Some(&AttrValue::UInt(_, 0)) => false,
|
||||||
|
@ -913,24 +901,20 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_link(&self) -> bool {
|
fn is_link(&self) -> bool {
|
||||||
unsafe {
|
|
||||||
match self.as_node().script_type_id() {
|
match self.as_node().script_type_id() {
|
||||||
// https://html.spec.whatwg.org/multipage/#selector-link
|
// https://html.spec.whatwg.org/multipage/#selector-link
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(
|
NodeTypeId::Element(ElementTypeId::HTMLElement(
|
||||||
HTMLElementTypeId::HTMLAnchorElement,
|
HTMLElementTypeId::HTMLAnchorElement,
|
||||||
)) |
|
)) |
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) |
|
||||||
HTMLElementTypeId::HTMLAreaElement,
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
|
||||||
)) |
|
self.element
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(
|
|
||||||
HTMLElementTypeId::HTMLLinkElement,
|
|
||||||
)) => (*self.element.unsafe_get())
|
|
||||||
.get_attr_val_for_layout(&ns!(), &local_name!("href"))
|
.get_attr_val_for_layout(&ns!(), &local_name!("href"))
|
||||||
.is_some(),
|
.is_some()
|
||||||
|
},
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn has_id(&self, id: &Atom, case_sensitivity: CaseSensitivity) -> bool {
|
fn has_id(&self, id: &Atom, case_sensitivity: CaseSensitivity) -> bool {
|
||||||
|
@ -956,19 +940,17 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn has_class(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {
|
fn has_class(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {
|
||||||
unsafe { self.element.has_class_for_layout(name, case_sensitivity) }
|
self.element.has_class_for_layout(name, case_sensitivity)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_html_slot_element(&self) -> bool {
|
fn is_html_slot_element(&self) -> bool {
|
||||||
unsafe { self.element.is_html_element() && self.local_name() == &local_name!("slot") }
|
self.element.is_html_element() && self.local_name() == &local_name!("slot")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_html_element_in_html_document(&self) -> bool {
|
fn is_html_element_in_html_document(&self) -> bool {
|
||||||
unsafe {
|
|
||||||
if !self.element.is_html_element() {
|
if !self.element.is_html_element() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.as_node().owner_doc().is_html_document()
|
self.as_node().owner_doc().is_html_document()
|
||||||
}
|
}
|
||||||
|
@ -1439,12 +1421,12 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> {
|
||||||
NamespaceConstraint::Specific(ref ns) => self
|
NamespaceConstraint::Specific(ref ns) => self
|
||||||
.get_attr_enum(ns, local_name)
|
.get_attr_enum(ns, local_name)
|
||||||
.map_or(false, |value| value.eval_selector(operation)),
|
.map_or(false, |value| value.eval_selector(operation)),
|
||||||
NamespaceConstraint::Any => {
|
NamespaceConstraint::Any => self
|
||||||
let values = unsafe {
|
.element
|
||||||
(*self.element.element.unsafe_get()).get_attr_vals_for_layout(local_name)
|
.element
|
||||||
};
|
.get_attr_vals_for_layout(local_name)
|
||||||
values.iter().any(|v| v.eval_selector(operation))
|
.iter()
|
||||||
},
|
.any(|v| v.eval_selector(operation)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,6 @@ use script::layout_exports::{Document, Element, Node, Text};
|
||||||
use script::layout_exports::{LayoutCharacterDataHelpers, LayoutDocumentHelpers};
|
use script::layout_exports::{LayoutCharacterDataHelpers, LayoutDocumentHelpers};
|
||||||
use script::layout_exports::{
|
use script::layout_exports::{
|
||||||
LayoutDom, LayoutElementHelpers, LayoutNodeHelpers, LayoutShadowRootHelpers,
|
LayoutDom, LayoutElementHelpers, LayoutNodeHelpers, LayoutShadowRootHelpers,
|
||||||
RawLayoutElementHelpers,
|
|
||||||
};
|
};
|
||||||
use script_layout_interface::wrapper_traits::{
|
use script_layout_interface::wrapper_traits::{
|
||||||
DangerousThreadSafeLayoutNode, GetLayoutData, LayoutNode,
|
DangerousThreadSafeLayoutNode, GetLayoutData, LayoutNode,
|
||||||
|
@ -143,13 +142,13 @@ impl<'ln> ServoLayoutNode<'ln> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn script_type_id(&self) -> NodeTypeId {
|
fn script_type_id(&self) -> NodeTypeId {
|
||||||
unsafe { self.node.type_id_for_layout() }
|
self.node.type_id_for_layout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'ln> NodeInfo for ServoLayoutNode<'ln> {
|
impl<'ln> NodeInfo for ServoLayoutNode<'ln> {
|
||||||
fn is_element(&self) -> bool {
|
fn is_element(&self) -> bool {
|
||||||
unsafe { self.node.is_element_for_layout() }
|
self.node.is_element_for_layout()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_text_node(&self) -> bool {
|
fn is_text_node(&self) -> bool {
|
||||||
|
@ -178,14 +177,14 @@ impl<'lr> TShadowRoot for ServoShadowRoot<'lr> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn host(&self) -> ServoLayoutElement<'lr> {
|
fn host(&self) -> ServoLayoutElement<'lr> {
|
||||||
ServoLayoutElement::from_layout_js(unsafe { self.shadow_root.get_host_for_layout() })
|
ServoLayoutElement::from_layout_js(self.shadow_root.get_host_for_layout())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn style_data<'a>(&self) -> Option<&'a CascadeData>
|
fn style_data<'a>(&self) -> Option<&'a CascadeData>
|
||||||
where
|
where
|
||||||
Self: 'a,
|
Self: 'a,
|
||||||
{
|
{
|
||||||
Some(unsafe { &self.shadow_root.get_style_data_for_layout().data })
|
Some(&self.shadow_root.get_style_data_for_layout())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,31 +210,29 @@ impl<'ln> TNode for ServoLayoutNode<'ln> {
|
||||||
type ConcreteShadowRoot = ServoShadowRoot<'ln>;
|
type ConcreteShadowRoot = ServoShadowRoot<'ln>;
|
||||||
|
|
||||||
fn parent_node(&self) -> Option<Self> {
|
fn parent_node(&self) -> Option<Self> {
|
||||||
unsafe {
|
|
||||||
self.node
|
self.node
|
||||||
.composed_parent_node_ref()
|
.composed_parent_node_ref()
|
||||||
.map(Self::from_layout_js)
|
.map(Self::from_layout_js)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn first_child(&self) -> Option<Self> {
|
fn first_child(&self) -> Option<Self> {
|
||||||
unsafe { self.node.first_child_ref().map(Self::from_layout_js) }
|
self.node.first_child_ref().map(Self::from_layout_js)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn last_child(&self) -> Option<Self> {
|
fn last_child(&self) -> Option<Self> {
|
||||||
unsafe { self.node.last_child_ref().map(Self::from_layout_js) }
|
self.node.last_child_ref().map(Self::from_layout_js)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prev_sibling(&self) -> Option<Self> {
|
fn prev_sibling(&self) -> Option<Self> {
|
||||||
unsafe { self.node.prev_sibling_ref().map(Self::from_layout_js) }
|
self.node.prev_sibling_ref().map(Self::from_layout_js)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_sibling(&self) -> Option<Self> {
|
fn next_sibling(&self) -> Option<Self> {
|
||||||
unsafe { self.node.next_sibling_ref().map(Self::from_layout_js) }
|
self.node.next_sibling_ref().map(Self::from_layout_js)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn owner_doc(&self) -> Self::ConcreteDocument {
|
fn owner_doc(&self) -> Self::ConcreteDocument {
|
||||||
ServoLayoutDocument::from_layout_js(unsafe { self.node.owner_doc_for_layout() })
|
ServoLayoutDocument::from_layout_js(self.node.owner_doc_for_layout())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn traversal_parent(&self) -> Option<ServoLayoutElement<'ln>> {
|
fn traversal_parent(&self) -> Option<ServoLayoutElement<'ln>> {
|
||||||
|
@ -353,11 +350,11 @@ impl<'ld> TDocument for ServoLayoutDocument<'ld> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn quirks_mode(&self) -> QuirksMode {
|
fn quirks_mode(&self) -> QuirksMode {
|
||||||
unsafe { self.document.quirks_mode() }
|
self.document.quirks_mode()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_html_document(&self) -> bool {
|
fn is_html_document(&self) -> bool {
|
||||||
unsafe { self.document.is_html_document_for_layout() }
|
self.document.is_html_document_for_layout()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -378,7 +375,7 @@ impl<'ld> ServoLayoutDocument<'ld> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn style_shared_lock(&self) -> &StyleSharedRwLock {
|
pub fn style_shared_lock(&self) -> &StyleSharedRwLock {
|
||||||
unsafe { self.document.style_shared_lock() }
|
self.document.style_shared_lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn shadow_roots(&self) -> Vec<ServoShadowRoot> {
|
pub fn shadow_roots(&self) -> Vec<ServoShadowRoot> {
|
||||||
|
@ -451,7 +448,7 @@ impl<'le> TElement for ServoLayoutElement<'le> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_html_element(&self) -> bool {
|
fn is_html_element(&self) -> bool {
|
||||||
unsafe { self.element.is_html_element() }
|
self.element.is_html_element()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_mathml_element(&self) -> bool {
|
fn is_mathml_element(&self) -> bool {
|
||||||
|
@ -497,14 +494,12 @@ impl<'le> TElement for ServoLayoutElement<'le> {
|
||||||
where
|
where
|
||||||
F: FnMut(&Atom),
|
F: FnMut(&Atom),
|
||||||
{
|
{
|
||||||
unsafe {
|
|
||||||
if let Some(ref classes) = self.element.get_classes_for_layout() {
|
if let Some(ref classes) = self.element.get_classes_for_layout() {
|
||||||
for class in *classes {
|
for class in *classes {
|
||||||
callback(class)
|
callback(class)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn has_dirty_descendants(&self) -> bool {
|
fn has_dirty_descendants(&self) -> bool {
|
||||||
unsafe {
|
unsafe {
|
||||||
|
@ -651,30 +646,24 @@ impl<'le> TElement for ServoLayoutElement<'le> {
|
||||||
) where
|
) where
|
||||||
V: Push<ApplicableDeclarationBlock>,
|
V: Push<ApplicableDeclarationBlock>,
|
||||||
{
|
{
|
||||||
unsafe {
|
|
||||||
self.element
|
self.element
|
||||||
.synthesize_presentational_hints_for_legacy_attributes(hints);
|
.synthesize_presentational_hints_for_legacy_attributes(hints);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// The shadow root this element is a host of.
|
/// The shadow root this element is a host of.
|
||||||
fn shadow_root(&self) -> Option<ServoShadowRoot<'le>> {
|
fn shadow_root(&self) -> Option<ServoShadowRoot<'le>> {
|
||||||
unsafe {
|
|
||||||
self.element
|
self.element
|
||||||
.get_shadow_root_for_layout()
|
.get_shadow_root_for_layout()
|
||||||
.map(ServoShadowRoot::from_layout_js)
|
.map(ServoShadowRoot::from_layout_js)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/// The shadow root which roots the subtree this element is contained in.
|
/// The shadow root which roots the subtree this element is contained in.
|
||||||
fn containing_shadow(&self) -> Option<ServoShadowRoot<'le>> {
|
fn containing_shadow(&self) -> Option<ServoShadowRoot<'le>> {
|
||||||
unsafe {
|
|
||||||
self.element
|
self.element
|
||||||
.upcast()
|
.upcast()
|
||||||
.containing_shadow_root_for_layout()
|
.containing_shadow_root_for_layout()
|
||||||
.map(ServoShadowRoot::from_layout_js)
|
.map(ServoShadowRoot::from_layout_js)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn local_name(&self) -> &LocalName {
|
fn local_name(&self) -> &LocalName {
|
||||||
self.element.local_name()
|
self.element.local_name()
|
||||||
|
@ -706,12 +695,12 @@ impl<'le> ServoLayoutElement<'le> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_attr_enum(&self, namespace: &Namespace, name: &LocalName) -> Option<&AttrValue> {
|
fn get_attr_enum(&self, namespace: &Namespace, name: &LocalName) -> Option<&AttrValue> {
|
||||||
unsafe { (*self.element.unsafe_get()).get_attr_for_layout(namespace, name) }
|
self.element.get_attr_for_layout(namespace, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_attr(&self, namespace: &Namespace, name: &LocalName) -> Option<&str> {
|
fn get_attr(&self, namespace: &Namespace, name: &LocalName) -> Option<&str> {
|
||||||
unsafe { (*self.element.unsafe_get()).get_attr_val_for_layout(namespace, name) }
|
self.element.get_attr_val_for_layout(namespace, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_style_data(&self) -> Option<&StyleData> {
|
fn get_style_data(&self) -> Option<&StyleData> {
|
||||||
|
@ -759,13 +748,11 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parent_element(&self) -> Option<ServoLayoutElement<'le>> {
|
fn parent_element(&self) -> Option<ServoLayoutElement<'le>> {
|
||||||
unsafe {
|
|
||||||
self.element
|
self.element
|
||||||
.upcast()
|
.upcast()
|
||||||
.composed_parent_node_ref()
|
.composed_parent_node_ref()
|
||||||
.and_then(as_element)
|
.and_then(as_element)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn parent_node_is_shadow_root(&self) -> bool {
|
fn parent_node_is_shadow_root(&self) -> bool {
|
||||||
match self.as_node().parent_node() {
|
match self.as_node().parent_node() {
|
||||||
|
@ -813,11 +800,11 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
||||||
NamespaceConstraint::Specific(ref ns) => self
|
NamespaceConstraint::Specific(ref ns) => self
|
||||||
.get_attr_enum(ns, local_name)
|
.get_attr_enum(ns, local_name)
|
||||||
.map_or(false, |value| value.eval_selector(operation)),
|
.map_or(false, |value| value.eval_selector(operation)),
|
||||||
NamespaceConstraint::Any => {
|
NamespaceConstraint::Any => self
|
||||||
let values =
|
.element
|
||||||
unsafe { (*self.element.unsafe_get()).get_attr_vals_for_layout(local_name) };
|
.get_attr_vals_for_layout(local_name)
|
||||||
values.iter().any(|value| value.eval_selector(operation))
|
.iter()
|
||||||
},
|
.any(|value| value.eval_selector(operation)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -887,8 +874,9 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
||||||
|
|
||||||
NonTSPseudoClass::Lang(ref lang) => self.match_element_lang(None, &*lang),
|
NonTSPseudoClass::Lang(ref lang) => self.match_element_lang(None, &*lang),
|
||||||
|
|
||||||
NonTSPseudoClass::ServoNonZeroBorder => unsafe {
|
NonTSPseudoClass::ServoNonZeroBorder => {
|
||||||
match (*self.element.unsafe_get())
|
match self
|
||||||
|
.element
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("border"))
|
.get_attr_for_layout(&ns!(), &local_name!("border"))
|
||||||
{
|
{
|
||||||
None | Some(&AttrValue::UInt(_, 0)) => false,
|
None | Some(&AttrValue::UInt(_, 0)) => false,
|
||||||
|
@ -920,24 +908,20 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn is_link(&self) -> bool {
|
fn is_link(&self) -> bool {
|
||||||
unsafe {
|
|
||||||
match self.as_node().script_type_id() {
|
match self.as_node().script_type_id() {
|
||||||
// https://html.spec.whatwg.org/multipage/#selector-link
|
// https://html.spec.whatwg.org/multipage/#selector-link
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(
|
NodeTypeId::Element(ElementTypeId::HTMLElement(
|
||||||
HTMLElementTypeId::HTMLAnchorElement,
|
HTMLElementTypeId::HTMLAnchorElement,
|
||||||
)) |
|
)) |
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) |
|
||||||
HTMLElementTypeId::HTMLAreaElement,
|
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLLinkElement)) => {
|
||||||
)) |
|
self.element
|
||||||
NodeTypeId::Element(ElementTypeId::HTMLElement(
|
|
||||||
HTMLElementTypeId::HTMLLinkElement,
|
|
||||||
)) => (*self.element.unsafe_get())
|
|
||||||
.get_attr_val_for_layout(&ns!(), &local_name!("href"))
|
.get_attr_val_for_layout(&ns!(), &local_name!("href"))
|
||||||
.is_some(),
|
.is_some()
|
||||||
|
},
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn has_id(&self, id: &Atom, case_sensitivity: CaseSensitivity) -> bool {
|
fn has_id(&self, id: &Atom, case_sensitivity: CaseSensitivity) -> bool {
|
||||||
|
@ -963,19 +947,17 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn has_class(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {
|
fn has_class(&self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {
|
||||||
unsafe { self.element.has_class_for_layout(name, case_sensitivity) }
|
self.element.has_class_for_layout(name, case_sensitivity)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_html_slot_element(&self) -> bool {
|
fn is_html_slot_element(&self) -> bool {
|
||||||
unsafe { self.element.is_html_element() && self.local_name() == &local_name!("slot") }
|
self.element.is_html_element() && self.local_name() == &local_name!("slot")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_html_element_in_html_document(&self) -> bool {
|
fn is_html_element_in_html_document(&self) -> bool {
|
||||||
unsafe {
|
|
||||||
if !self.element.is_html_element() {
|
if !self.element.is_html_element() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
self.as_node().owner_doc().is_html_document()
|
self.as_node().owner_doc().is_html_document()
|
||||||
}
|
}
|
||||||
|
@ -1447,9 +1429,7 @@ impl<'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> {
|
||||||
.get_attr_enum(ns, local_name)
|
.get_attr_enum(ns, local_name)
|
||||||
.map_or(false, |value| value.eval_selector(operation)),
|
.map_or(false, |value| value.eval_selector(operation)),
|
||||||
NamespaceConstraint::Any => {
|
NamespaceConstraint::Any => {
|
||||||
let values = unsafe {
|
let values = self.element.element.get_attr_vals_for_layout(local_name);
|
||||||
(*self.element.element.unsafe_get()).get_attr_vals_for_layout(local_name)
|
|
||||||
};
|
|
||||||
values.iter().any(|v| v.eval_selector(operation))
|
values.iter().any(|v| v.eval_selector(operation))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -441,6 +441,15 @@ where
|
||||||
debug_assert!(thread_state::get().is_layout());
|
debug_assert!(thread_state::get().is_layout());
|
||||||
self.value.downcast::<U>().map(|value| LayoutDom { value })
|
self.value.downcast::<U>().map(|value| LayoutDom { value })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns whether this inner object is a U.
|
||||||
|
pub fn is<U>(&self) -> bool
|
||||||
|
where
|
||||||
|
U: DerivedFrom<T>,
|
||||||
|
{
|
||||||
|
debug_assert!(thread_state::get().is_layout());
|
||||||
|
self.value.is::<U>()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> LayoutDom<'_, T>
|
impl<T> LayoutDom<'_, T>
|
||||||
|
@ -736,6 +745,15 @@ where
|
||||||
debug_assert!(thread_state::get().is_layout());
|
debug_assert!(thread_state::get().is_layout());
|
||||||
self.value
|
self.value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Transforms a slice of Dom<T> into a slice of LayoutDom<T>.
|
||||||
|
// FIXME(nox): This should probably be done through a ToLayout trait.
|
||||||
|
pub unsafe fn to_layout_slice(slice: &'dom [Dom<T>]) -> &'dom [LayoutDom<'dom, T>] {
|
||||||
|
// This doesn't compile if Dom and LayoutDom don't have the same
|
||||||
|
// representation.
|
||||||
|
let _ = mem::transmute::<Dom<T>, LayoutDom<T>>;
|
||||||
|
&*(slice as *const [Dom<T>] as *const [LayoutDom<T>])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Helper trait for safer manipulations of `Option<Heap<T>>` values.
|
/// Helper trait for safer manipulations of `Option<Heap<T>>` values.
|
||||||
|
|
|
@ -153,8 +153,7 @@ impl CanvasRenderingContext2D {
|
||||||
pub trait LayoutCanvasRenderingContext2DHelpers {
|
pub trait LayoutCanvasRenderingContext2DHelpers {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_ipc_renderer(self) -> IpcSender<CanvasMsg>;
|
unsafe fn get_ipc_renderer(self) -> IpcSender<CanvasMsg>;
|
||||||
#[allow(unsafe_code)]
|
fn get_canvas_id(self) -> CanvasId;
|
||||||
unsafe fn get_canvas_id(self) -> CanvasId;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutCanvasRenderingContext2DHelpers for LayoutDom<'_, CanvasRenderingContext2D> {
|
impl LayoutCanvasRenderingContext2DHelpers for LayoutDom<'_, CanvasRenderingContext2D> {
|
||||||
|
@ -168,12 +167,17 @@ impl LayoutCanvasRenderingContext2DHelpers for LayoutDom<'_, CanvasRenderingCont
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_canvas_id(self) -> CanvasId {
|
fn get_canvas_id(self) -> CanvasId {
|
||||||
(*self.unsafe_get())
|
// FIXME(nox): This relies on the fact that CanvasState::get_canvas_id
|
||||||
|
// does nothing fancy but it would be easier to trust a
|
||||||
|
// LayoutDom<_>-like type that would wrap the &CanvasState.
|
||||||
|
unsafe {
|
||||||
|
self.unsafe_get()
|
||||||
.canvas_state
|
.canvas_state
|
||||||
.borrow_for_layout()
|
.borrow_for_layout()
|
||||||
.get_canvas_id()
|
.get_canvas_id()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// We add a guard to each of methods by the spec:
|
// We add a guard to each of methods by the spec:
|
||||||
|
|
|
@ -2618,21 +2618,21 @@ pub enum DocumentSource {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub trait LayoutDocumentHelpers<'dom> {
|
pub trait LayoutDocumentHelpers<'dom> {
|
||||||
unsafe fn is_html_document_for_layout(self) -> bool;
|
fn is_html_document_for_layout(self) -> bool;
|
||||||
unsafe fn needs_paint_from_layout(self);
|
unsafe fn needs_paint_from_layout(self);
|
||||||
unsafe fn will_paint(self);
|
unsafe fn will_paint(self);
|
||||||
unsafe fn quirks_mode(self) -> QuirksMode;
|
fn quirks_mode(self) -> QuirksMode;
|
||||||
unsafe fn style_shared_lock(self) -> &'dom StyleSharedRwLock;
|
fn style_shared_lock(self) -> &'dom StyleSharedRwLock;
|
||||||
unsafe fn shadow_roots(self) -> Vec<LayoutDom<'dom, ShadowRoot>>;
|
fn shadow_roots(self) -> Vec<LayoutDom<'dom, ShadowRoot>>;
|
||||||
unsafe fn shadow_roots_styles_changed(self) -> bool;
|
fn shadow_roots_styles_changed(self) -> bool;
|
||||||
unsafe fn flush_shadow_roots_stylesheets(self);
|
unsafe fn flush_shadow_roots_stylesheets(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
impl<'dom> LayoutDocumentHelpers<'dom> for LayoutDom<'dom, Document> {
|
impl<'dom> LayoutDocumentHelpers<'dom> for LayoutDom<'dom, Document> {
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn is_html_document_for_layout(self) -> bool {
|
fn is_html_document_for_layout(self) -> bool {
|
||||||
(*self.unsafe_get()).is_html_document
|
unsafe { self.unsafe_get().is_html_document }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -2646,28 +2646,34 @@ impl<'dom> LayoutDocumentHelpers<'dom> for LayoutDom<'dom, Document> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn quirks_mode(self) -> QuirksMode {
|
fn quirks_mode(self) -> QuirksMode {
|
||||||
(*self.unsafe_get()).quirks_mode()
|
unsafe { self.unsafe_get().quirks_mode.get() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn style_shared_lock(self) -> &'dom StyleSharedRwLock {
|
fn style_shared_lock(self) -> &'dom StyleSharedRwLock {
|
||||||
(*self.unsafe_get()).style_shared_lock()
|
unsafe { self.unsafe_get().style_shared_lock() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn shadow_roots(self) -> Vec<LayoutDom<'dom, ShadowRoot>> {
|
fn shadow_roots(self) -> Vec<LayoutDom<'dom, ShadowRoot>> {
|
||||||
(*self.unsafe_get())
|
// FIXME(nox): We should just return a
|
||||||
|
// &'dom HashSet<LayoutDom<'dom, ShadowRoot>> here but not until
|
||||||
|
// I rework the ToLayout trait as mentioned in
|
||||||
|
// LayoutDom::to_layout_slice.
|
||||||
|
unsafe {
|
||||||
|
self.unsafe_get()
|
||||||
.shadow_roots
|
.shadow_roots
|
||||||
.borrow_for_layout()
|
.borrow_for_layout()
|
||||||
.iter()
|
.iter()
|
||||||
.map(|sr| sr.to_layout())
|
.map(|sr| sr.to_layout())
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn shadow_roots_styles_changed(self) -> bool {
|
fn shadow_roots_styles_changed(self) -> bool {
|
||||||
(*self.unsafe_get()).shadow_roots_styles_changed()
|
unsafe { self.unsafe_get().shadow_roots_styles_changed.get() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -551,92 +551,29 @@ impl Element {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
pub trait RawLayoutElementHelpers {
|
|
||||||
unsafe fn get_attr_for_layout<'a>(
|
|
||||||
&'a self,
|
|
||||||
namespace: &Namespace,
|
|
||||||
name: &LocalName,
|
|
||||||
) -> Option<&'a AttrValue>;
|
|
||||||
unsafe fn get_attr_val_for_layout<'a>(
|
|
||||||
&'a self,
|
|
||||||
namespace: &Namespace,
|
|
||||||
name: &LocalName,
|
|
||||||
) -> Option<&'a str>;
|
|
||||||
unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &LocalName) -> Vec<&'a AttrValue>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
pub fn get_attr_for_layout<'dom>(
|
||||||
pub unsafe fn get_attr_for_layout<'dom>(
|
elem: LayoutDom<'dom, Element>,
|
||||||
elem: &'dom Element,
|
|
||||||
namespace: &Namespace,
|
namespace: &Namespace,
|
||||||
name: &LocalName,
|
name: &LocalName,
|
||||||
) -> Option<LayoutDom<'dom, Attr>> {
|
) -> Option<LayoutDom<'dom, Attr>> {
|
||||||
// cast to point to T in RefCell<T> directly
|
elem.attrs()
|
||||||
let attrs = elem.attrs.borrow_for_layout();
|
|
||||||
attrs
|
|
||||||
.iter()
|
.iter()
|
||||||
.find(|attr| {
|
.find(|attr| name == attr.local_name() && namespace == attr.namespace())
|
||||||
let attr = attr.to_layout();
|
.cloned()
|
||||||
name == attr.local_name() && namespace == attr.namespace()
|
|
||||||
})
|
|
||||||
.map(|attr| attr.to_layout())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
impl RawLayoutElementHelpers for Element {
|
|
||||||
#[inline]
|
|
||||||
unsafe fn get_attr_for_layout<'a>(
|
|
||||||
&'a self,
|
|
||||||
namespace: &Namespace,
|
|
||||||
name: &LocalName,
|
|
||||||
) -> Option<&'a AttrValue> {
|
|
||||||
get_attr_for_layout(self, namespace, name).map(|attr| attr.value())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
unsafe fn get_attr_val_for_layout<'a>(
|
|
||||||
&'a self,
|
|
||||||
namespace: &Namespace,
|
|
||||||
name: &LocalName,
|
|
||||||
) -> Option<&'a str> {
|
|
||||||
get_attr_for_layout(self, namespace, name).map(|attr| attr.as_str())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
unsafe fn get_attr_vals_for_layout<'a>(&'a self, name: &LocalName) -> Vec<&'a AttrValue> {
|
|
||||||
let attrs = self.attrs.borrow_for_layout();
|
|
||||||
attrs
|
|
||||||
.iter()
|
|
||||||
.filter_map(|attr| {
|
|
||||||
let attr = attr.to_layout();
|
|
||||||
if name == attr.local_name() {
|
|
||||||
Some(attr.value())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LayoutElementHelpers<'dom> {
|
pub trait LayoutElementHelpers<'dom> {
|
||||||
#[allow(unsafe_code)]
|
fn attrs(self) -> &'dom [LayoutDom<'dom, Attr>];
|
||||||
unsafe fn has_class_for_layout(self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool;
|
fn has_class_for_layout(self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool;
|
||||||
#[allow(unsafe_code)]
|
fn get_classes_for_layout(self) -> Option<&'dom [Atom]>;
|
||||||
unsafe fn get_classes_for_layout(self) -> Option<&'dom [Atom]>;
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
fn synthesize_presentational_hints_for_legacy_attributes<V>(self, hints: &mut V)
|
||||||
unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(self, _: &mut V)
|
|
||||||
where
|
where
|
||||||
V: Push<ApplicableDeclarationBlock>;
|
V: Push<ApplicableDeclarationBlock>;
|
||||||
#[allow(unsafe_code)]
|
fn get_colspan(self) -> u32;
|
||||||
unsafe fn get_colspan(self) -> u32;
|
fn get_rowspan(self) -> u32;
|
||||||
#[allow(unsafe_code)]
|
fn is_html_element(self) -> bool;
|
||||||
unsafe fn get_rowspan(self) -> u32;
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
unsafe fn is_html_element(self) -> bool;
|
|
||||||
fn id_attribute(self) -> *const Option<Atom>;
|
fn id_attribute(self) -> *const Option<Atom>;
|
||||||
fn style_attribute(self) -> *const Option<Arc<Locked<PropertyDeclarationBlock>>>;
|
fn style_attribute(self) -> *const Option<Arc<Locked<PropertyDeclarationBlock>>>;
|
||||||
fn local_name(self) -> &'dom LocalName;
|
fn local_name(self) -> &'dom LocalName;
|
||||||
|
@ -646,34 +583,52 @@ pub trait LayoutElementHelpers<'dom> {
|
||||||
fn insert_selector_flags(self, flags: ElementSelectorFlags);
|
fn insert_selector_flags(self, flags: ElementSelectorFlags);
|
||||||
fn has_selector_flags(self, flags: ElementSelectorFlags) -> bool;
|
fn has_selector_flags(self, flags: ElementSelectorFlags) -> bool;
|
||||||
/// The shadow root this element is a host of.
|
/// The shadow root this element is a host of.
|
||||||
|
fn get_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
|
||||||
|
fn get_attr_for_layout(
|
||||||
|
self,
|
||||||
|
namespace: &Namespace,
|
||||||
|
name: &LocalName,
|
||||||
|
) -> Option<&'dom AttrValue>;
|
||||||
|
fn get_attr_val_for_layout(self, namespace: &Namespace, name: &LocalName) -> Option<&'dom str>;
|
||||||
|
fn get_attr_vals_for_layout(self, name: &LocalName) -> Vec<&'dom AttrValue>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'dom> LayoutDom<'dom, Element> {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
|
pub(super) fn focus_state(self) -> bool {
|
||||||
|
unsafe {
|
||||||
|
self.unsafe_get()
|
||||||
|
.state
|
||||||
|
.get()
|
||||||
|
.contains(ElementState::IN_FOCUS_STATE)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn has_class_for_layout(self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {
|
fn attrs(self) -> &'dom [LayoutDom<'dom, Attr>] {
|
||||||
get_attr_for_layout(&*self.unsafe_get(), &ns!(), &local_name!("class")).map_or(
|
unsafe { LayoutDom::to_layout_slice(self.unsafe_get().attrs.borrow_for_layout()) }
|
||||||
false,
|
}
|
||||||
|attr| {
|
|
||||||
|
#[inline]
|
||||||
|
fn has_class_for_layout(self, name: &Atom, case_sensitivity: CaseSensitivity) -> bool {
|
||||||
|
get_attr_for_layout(self, &ns!(), &local_name!("class")).map_or(false, |attr| {
|
||||||
attr.as_tokens()
|
attr.as_tokens()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.iter()
|
.iter()
|
||||||
.any(|atom| case_sensitivity.eq_atom(atom, name))
|
.any(|atom| case_sensitivity.eq_atom(atom, name))
|
||||||
},
|
})
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
#[inline]
|
#[inline]
|
||||||
unsafe fn get_classes_for_layout(self) -> Option<&'dom [Atom]> {
|
fn get_classes_for_layout(self) -> Option<&'dom [Atom]> {
|
||||||
get_attr_for_layout(&*self.unsafe_get(), &ns!(), &local_name!("class"))
|
get_attr_for_layout(self, &ns!(), &local_name!("class"))
|
||||||
.map(|attr| attr.as_tokens().unwrap())
|
.map(|attr| attr.as_tokens().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
fn synthesize_presentational_hints_for_legacy_attributes<V>(self, hints: &mut V)
|
||||||
unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(self, hints: &mut V)
|
|
||||||
where
|
where
|
||||||
V: Push<ApplicableDeclarationBlock>,
|
V: Push<ApplicableDeclarationBlock>,
|
||||||
{
|
{
|
||||||
|
@ -803,7 +758,7 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
||||||
|
|
||||||
let size = if let Some(this) = self.downcast::<HTMLInputElement>() {
|
let size = if let Some(this) = self.downcast::<HTMLInputElement>() {
|
||||||
// FIXME(pcwalton): More use of atoms, please!
|
// FIXME(pcwalton): More use of atoms, please!
|
||||||
match (*self.unsafe_get()).get_attr_val_for_layout(&ns!(), &local_name!("type")) {
|
match self.get_attr_val_for_layout(&ns!(), &local_name!("type")) {
|
||||||
// Not text entry widget
|
// Not text entry widget
|
||||||
Some("hidden") |
|
Some("hidden") |
|
||||||
Some("date") |
|
Some("date") |
|
||||||
|
@ -996,8 +951,7 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
fn get_colspan(self) -> u32 {
|
||||||
unsafe fn get_colspan(self) -> u32 {
|
|
||||||
if let Some(this) = self.downcast::<HTMLTableCellElement>() {
|
if let Some(this) = self.downcast::<HTMLTableCellElement>() {
|
||||||
this.get_colspan().unwrap_or(1)
|
this.get_colspan().unwrap_or(1)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1007,8 +961,7 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
fn get_rowspan(self) -> u32 {
|
||||||
unsafe fn get_rowspan(self) -> u32 {
|
|
||||||
if let Some(this) = self.downcast::<HTMLTableCellElement>() {
|
if let Some(this) = self.downcast::<HTMLTableCellElement>() {
|
||||||
this.get_rowspan().unwrap_or(1)
|
this.get_rowspan().unwrap_or(1)
|
||||||
} else {
|
} else {
|
||||||
|
@ -1019,9 +972,8 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
fn is_html_element(self) -> bool {
|
||||||
unsafe fn is_html_element(self) -> bool {
|
*self.namespace() == ns!(html)
|
||||||
(*self.unsafe_get()).namespace == ns!(html)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
|
@ -1044,22 +996,18 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
||||||
unsafe { &(*self.unsafe_get()).namespace }
|
unsafe { &(*self.unsafe_get()).namespace }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_lang_for_layout(self) -> String {
|
fn get_lang_for_layout(self) -> String {
|
||||||
unsafe {
|
|
||||||
let mut current_node = Some(self.upcast::<Node>());
|
let mut current_node = Some(self.upcast::<Node>());
|
||||||
while let Some(node) = current_node {
|
while let Some(node) = current_node {
|
||||||
current_node = node.composed_parent_node_ref();
|
current_node = node.composed_parent_node_ref();
|
||||||
match node.downcast::<Element>().map(|el| el.unsafe_get()) {
|
match node.downcast::<Element>() {
|
||||||
Some(elem) => {
|
Some(elem) => {
|
||||||
if let Some(attr) =
|
if let Some(attr) =
|
||||||
(*elem).get_attr_val_for_layout(&ns!(xml), &local_name!("lang"))
|
elem.get_attr_val_for_layout(&ns!(xml), &local_name!("lang"))
|
||||||
{
|
{
|
||||||
return attr.to_owned();
|
return attr.to_owned();
|
||||||
}
|
}
|
||||||
if let Some(attr) =
|
if let Some(attr) = elem.get_attr_val_for_layout(&ns!(), &local_name!("lang")) {
|
||||||
(*elem).get_attr_val_for_layout(&ns!(), &local_name!("lang"))
|
|
||||||
{
|
|
||||||
return attr.to_owned();
|
return attr.to_owned();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -1070,7 +1018,6 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
||||||
// TODO: Check HTTP Content-Language header
|
// TODO: Check HTTP Content-Language header
|
||||||
String::new()
|
String::new()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
|
@ -1096,14 +1043,45 @@ impl<'dom> LayoutElementHelpers<'dom> for LayoutDom<'dom, Element> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>> {
|
fn get_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>> {
|
||||||
(*self.unsafe_get())
|
unsafe {
|
||||||
.rare_data_for_layout()
|
self.unsafe_get()
|
||||||
|
.rare_data
|
||||||
|
.borrow_for_layout()
|
||||||
.as_ref()?
|
.as_ref()?
|
||||||
.shadow_root
|
.shadow_root
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|sr| sr.to_layout())
|
.map(|sr| sr.to_layout())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn get_attr_for_layout(
|
||||||
|
self,
|
||||||
|
namespace: &Namespace,
|
||||||
|
name: &LocalName,
|
||||||
|
) -> Option<&'dom AttrValue> {
|
||||||
|
get_attr_for_layout(self, namespace, name).map(|attr| attr.value())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn get_attr_val_for_layout(self, namespace: &Namespace, name: &LocalName) -> Option<&'dom str> {
|
||||||
|
get_attr_for_layout(self, namespace, name).map(|attr| attr.as_str())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
fn get_attr_vals_for_layout(self, name: &LocalName) -> Vec<&'dom AttrValue> {
|
||||||
|
self.attrs()
|
||||||
|
.iter()
|
||||||
|
.filter_map(|attr| {
|
||||||
|
if name == attr.local_name() {
|
||||||
|
Some(attr.value())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Element {
|
impl Element {
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::root::{DomRoot, LayoutDom};
|
use crate::dom::bindings::root::{DomRoot, LayoutDom};
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::document::Document;
|
use crate::dom::document::Document;
|
||||||
use crate::dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
|
use crate::dom::element::{AttributeMutation, Element, LayoutElementHelpers};
|
||||||
use crate::dom::eventtarget::EventTarget;
|
use crate::dom::eventtarget::EventTarget;
|
||||||
use crate::dom::htmlelement::HTMLElement;
|
use crate::dom::htmlelement::HTMLElement;
|
||||||
use crate::dom::node::{document_from_node, window_from_node, BindContext, Node};
|
use crate::dom::node::{document_from_node, window_from_node, BindContext, Node};
|
||||||
|
@ -100,35 +100,26 @@ pub trait HTMLBodyElementLayoutHelpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HTMLBodyElementLayoutHelpers for LayoutDom<'_, HTMLBodyElement> {
|
impl HTMLBodyElementLayoutHelpers for LayoutDom<'_, HTMLBodyElement> {
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_background_color(self) -> Option<RGBA> {
|
fn get_background_color(self) -> Option<RGBA> {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||||
.and_then(AttrValue::as_color)
|
.and_then(AttrValue::as_color)
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_color(self) -> Option<RGBA> {
|
fn get_color(self) -> Option<RGBA> {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("text"))
|
.get_attr_for_layout(&ns!(), &local_name!("text"))
|
||||||
.and_then(AttrValue::as_color)
|
.and_then(AttrValue::as_color)
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_background(self) -> Option<ServoUrl> {
|
fn get_background(self) -> Option<ServoUrl> {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("background"))
|
.get_attr_for_layout(&ns!(), &local_name!("background"))
|
||||||
.and_then(AttrValue::as_resolved_url)
|
.and_then(AttrValue::as_resolved_url)
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for HTMLBodyElement {
|
impl VirtualMethods for HTMLBodyElement {
|
||||||
|
|
|
@ -18,7 +18,7 @@ use crate::dom::canvasrenderingcontext2d::{
|
||||||
CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers,
|
CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers,
|
||||||
};
|
};
|
||||||
use crate::dom::document::Document;
|
use crate::dom::document::Document;
|
||||||
use crate::dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
|
use crate::dom::element::{AttributeMutation, Element, LayoutElementHelpers};
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::htmlelement::HTMLElement;
|
use crate::dom::htmlelement::HTMLElement;
|
||||||
use crate::dom::node::{window_from_node, Node};
|
use crate::dom::node::{window_from_node, Node};
|
||||||
|
@ -123,9 +123,8 @@ pub trait LayoutHTMLCanvasElementHelpers {
|
||||||
impl LayoutHTMLCanvasElementHelpers for LayoutDom<'_, HTMLCanvasElement> {
|
impl LayoutHTMLCanvasElementHelpers for LayoutDom<'_, HTMLCanvasElement> {
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn data(self) -> HTMLCanvasData {
|
fn data(self) -> HTMLCanvasData {
|
||||||
unsafe {
|
let source = unsafe {
|
||||||
let canvas = &*self.unsafe_get();
|
match self.unsafe_get().context.borrow_for_layout().as_ref() {
|
||||||
let source = match canvas.context.borrow_for_layout().as_ref() {
|
|
||||||
Some(&CanvasContext::Context2d(ref context)) => {
|
Some(&CanvasContext::Context2d(ref context)) => {
|
||||||
HTMLCanvasDataSource::Image(Some(context.to_layout().get_ipc_renderer()))
|
HTMLCanvasDataSource::Image(Some(context.to_layout().get_ipc_renderer()))
|
||||||
},
|
},
|
||||||
|
@ -136,12 +135,13 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<'_, HTMLCanvasElement> {
|
||||||
context.to_layout().canvas_data_source()
|
context.to_layout().canvas_data_source()
|
||||||
},
|
},
|
||||||
None => HTMLCanvasDataSource::Image(None),
|
None => HTMLCanvasDataSource::Image(None),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let width_attr = canvas
|
let width_attr = self
|
||||||
.upcast::<Element>()
|
.upcast::<Element>()
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("width"));
|
.get_attr_for_layout(&ns!(), &local_name!("width"));
|
||||||
let height_attr = canvas
|
let height_attr = self
|
||||||
.upcast::<Element>()
|
.upcast::<Element>()
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("height"));
|
.get_attr_for_layout(&ns!(), &local_name!("height"));
|
||||||
HTMLCanvasData {
|
HTMLCanvasData {
|
||||||
|
@ -151,27 +151,20 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<'_, HTMLCanvasElement> {
|
||||||
canvas_id: self.get_canvas_id_for_layout(),
|
canvas_id: self.get_canvas_id_for_layout(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_width(self) -> LengthOrPercentageOrAuto {
|
fn get_width(self) -> LengthOrPercentageOrAuto {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(&*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||||
.map(AttrValue::as_uint_px_dimension)
|
.map(AttrValue::as_uint_px_dimension)
|
||||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_height(self) -> LengthOrPercentageOrAuto {
|
fn get_height(self) -> LengthOrPercentageOrAuto {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(&*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("height"))
|
.get_attr_for_layout(&ns!(), &local_name!("height"))
|
||||||
.map(AttrValue::as_uint_px_dimension)
|
.map(AttrValue::as_uint_px_dimension)
|
||||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn get_canvas_id_for_layout(self) -> CanvasId {
|
fn get_canvas_id_for_layout(self) -> CanvasId {
|
||||||
|
|
|
@ -8,7 +8,7 @@ use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::root::{DomRoot, LayoutDom};
|
use crate::dom::bindings::root::{DomRoot, LayoutDom};
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::document::Document;
|
use crate::dom::document::Document;
|
||||||
use crate::dom::element::{Element, RawLayoutElementHelpers};
|
use crate::dom::element::{Element, LayoutElementHelpers};
|
||||||
use crate::dom::htmlelement::HTMLElement;
|
use crate::dom::htmlelement::HTMLElement;
|
||||||
use crate::dom::node::Node;
|
use crate::dom::node::Node;
|
||||||
use crate::dom::virtualmethods::VirtualMethods;
|
use crate::dom::virtualmethods::VirtualMethods;
|
||||||
|
@ -107,32 +107,24 @@ pub trait HTMLFontElementLayoutHelpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HTMLFontElementLayoutHelpers for LayoutDom<'_, HTMLFontElement> {
|
impl HTMLFontElementLayoutHelpers for LayoutDom<'_, HTMLFontElement> {
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_color(self) -> Option<RGBA> {
|
fn get_color(self) -> Option<RGBA> {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("color"))
|
.get_attr_for_layout(&ns!(), &local_name!("color"))
|
||||||
.and_then(AttrValue::as_color)
|
.and_then(AttrValue::as_color)
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_face(self) -> Option<Atom> {
|
fn get_face(self) -> Option<Atom> {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("face"))
|
.get_attr_for_layout(&ns!(), &local_name!("face"))
|
||||||
.map(AttrValue::as_atom)
|
.map(AttrValue::as_atom)
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_size(self) -> Option<u32> {
|
fn get_size(self) -> Option<u32> {
|
||||||
let size = unsafe {
|
let size = self
|
||||||
(*self.upcast::<Element>().unsafe_get())
|
.upcast::<Element>()
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("size"))
|
.get_attr_for_layout(&ns!(), &local_name!("size"));
|
||||||
};
|
|
||||||
match size {
|
match size {
|
||||||
Some(&AttrValue::UInt(_, s)) => Some(s),
|
Some(&AttrValue::UInt(_, s)) => Some(s),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::root::{DomRoot, LayoutDom};
|
use crate::dom::bindings::root::{DomRoot, LayoutDom};
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::document::Document;
|
use crate::dom::document::Document;
|
||||||
use crate::dom::element::{Element, RawLayoutElementHelpers};
|
use crate::dom::element::{Element, LayoutElementHelpers};
|
||||||
use crate::dom::htmlelement::HTMLElement;
|
use crate::dom::htmlelement::HTMLElement;
|
||||||
use crate::dom::node::Node;
|
use crate::dom::node::Node;
|
||||||
use crate::dom::virtualmethods::VirtualMethods;
|
use crate::dom::virtualmethods::VirtualMethods;
|
||||||
|
@ -71,26 +71,20 @@ pub trait HTMLHRLayoutHelpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HTMLHRLayoutHelpers for LayoutDom<'_, HTMLHRElement> {
|
impl HTMLHRLayoutHelpers for LayoutDom<'_, HTMLHRElement> {
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_color(self) -> Option<RGBA> {
|
fn get_color(self) -> Option<RGBA> {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(&*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("color"))
|
.get_attr_for_layout(&ns!(), &local_name!("color"))
|
||||||
.and_then(AttrValue::as_color)
|
.and_then(AttrValue::as_color)
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_width(self) -> LengthOrPercentageOrAuto {
|
fn get_width(self) -> LengthOrPercentageOrAuto {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(&*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||||
.map(AttrValue::as_dimension)
|
.map(AttrValue::as_dimension)
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for HTMLHRElement {
|
impl VirtualMethods for HTMLHRElement {
|
||||||
|
|
|
@ -14,7 +14,7 @@ use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
|
||||||
use crate::dom::bindings::str::{DOMString, USVString};
|
use crate::dom::bindings::str::{DOMString, USVString};
|
||||||
use crate::dom::document::Document;
|
use crate::dom::document::Document;
|
||||||
use crate::dom::domtokenlist::DOMTokenList;
|
use crate::dom::domtokenlist::DOMTokenList;
|
||||||
use crate::dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
|
use crate::dom::element::{AttributeMutation, Element, LayoutElementHelpers};
|
||||||
use crate::dom::eventtarget::EventTarget;
|
use crate::dom::eventtarget::EventTarget;
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
use crate::dom::htmlelement::HTMLElement;
|
use crate::dom::htmlelement::HTMLElement;
|
||||||
|
@ -499,27 +499,21 @@ impl HTMLIFrameElementLayoutMethods for LayoutDom<'_, HTMLIFrameElement> {
|
||||||
unsafe { (*self.unsafe_get()).browsing_context_id.get() }
|
unsafe { (*self.unsafe_get()).browsing_context_id.get() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_width(self) -> LengthOrPercentageOrAuto {
|
fn get_width(self) -> LengthOrPercentageOrAuto {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||||
.map(AttrValue::as_dimension)
|
.map(AttrValue::as_dimension)
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_height(self) -> LengthOrPercentageOrAuto {
|
fn get_height(self) -> LengthOrPercentageOrAuto {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("height"))
|
.get_attr_for_layout(&ns!(), &local_name!("height"))
|
||||||
.map(AttrValue::as_dimension)
|
.map(AttrValue::as_dimension)
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HTMLIFrameElementMethods for HTMLIFrameElement {
|
impl HTMLIFrameElementMethods for HTMLIFrameElement {
|
||||||
|
|
|
@ -22,7 +22,7 @@ use crate::dom::document::Document;
|
||||||
use crate::dom::element::{cors_setting_for_element, referrer_policy_for_element};
|
use crate::dom::element::{cors_setting_for_element, referrer_policy_for_element};
|
||||||
use crate::dom::element::{reflect_cross_origin_attribute, set_cross_origin_attribute};
|
use crate::dom::element::{reflect_cross_origin_attribute, set_cross_origin_attribute};
|
||||||
use crate::dom::element::{
|
use crate::dom::element::{
|
||||||
AttributeMutation, CustomElementCreationMode, Element, ElementCreator, RawLayoutElementHelpers,
|
AttributeMutation, CustomElementCreationMode, Element, ElementCreator, LayoutElementHelpers,
|
||||||
};
|
};
|
||||||
use crate::dom::event::Event;
|
use crate::dom::event::Event;
|
||||||
use crate::dom::eventtarget::EventTarget;
|
use crate::dom::eventtarget::EventTarget;
|
||||||
|
@ -1366,76 +1366,57 @@ impl MicrotaskRunnable for ImageElementMicrotask {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait LayoutHTMLImageElementHelpers {
|
pub trait LayoutHTMLImageElementHelpers {
|
||||||
#[allow(unsafe_code)]
|
fn image(self) -> Option<Arc<Image>>;
|
||||||
unsafe fn image(self) -> Option<Arc<Image>>;
|
fn image_url(self) -> Option<ServoUrl>;
|
||||||
#[allow(unsafe_code)]
|
fn image_density(self) -> Option<f64>;
|
||||||
unsafe fn image_url(self) -> Option<ServoUrl>;
|
fn image_data(self) -> (Option<Arc<Image>>, Option<ImageMetadata>);
|
||||||
#[allow(unsafe_code)]
|
|
||||||
unsafe fn image_density(self) -> Option<f64>;
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
unsafe fn image_data(self) -> (Option<Arc<Image>>, Option<ImageMetadata>);
|
|
||||||
fn get_width(self) -> LengthOrPercentageOrAuto;
|
fn get_width(self) -> LengthOrPercentageOrAuto;
|
||||||
fn get_height(self) -> LengthOrPercentageOrAuto;
|
fn get_height(self) -> LengthOrPercentageOrAuto;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'dom> LayoutDom<'dom, HTMLImageElement> {
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
fn current_request(self) -> &'dom ImageRequest {
|
||||||
|
unsafe { self.unsafe_get().current_request.borrow_for_layout() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl LayoutHTMLImageElementHelpers for LayoutDom<'_, HTMLImageElement> {
|
impl LayoutHTMLImageElementHelpers for LayoutDom<'_, HTMLImageElement> {
|
||||||
#[allow(unsafe_code)]
|
fn image(self) -> Option<Arc<Image>> {
|
||||||
unsafe fn image(self) -> Option<Arc<Image>> {
|
self.current_request().image.clone()
|
||||||
(*self.unsafe_get())
|
|
||||||
.current_request
|
|
||||||
.borrow_for_layout()
|
|
||||||
.image
|
|
||||||
.clone()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
fn image_url(self) -> Option<ServoUrl> {
|
||||||
unsafe fn image_url(self) -> Option<ServoUrl> {
|
self.current_request().parsed_url.clone()
|
||||||
(*self.unsafe_get())
|
|
||||||
.current_request
|
|
||||||
.borrow_for_layout()
|
|
||||||
.parsed_url
|
|
||||||
.clone()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
fn image_data(self) -> (Option<Arc<Image>>, Option<ImageMetadata>) {
|
||||||
unsafe fn image_data(self) -> (Option<Arc<Image>>, Option<ImageMetadata>) {
|
let current_request = self.current_request();
|
||||||
let current_request = (*self.unsafe_get()).current_request.borrow_for_layout();
|
|
||||||
(
|
(
|
||||||
current_request.image.clone(),
|
current_request.image.clone(),
|
||||||
current_request.metadata.clone(),
|
current_request.metadata.clone(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
fn image_density(self) -> Option<f64> {
|
||||||
unsafe fn image_density(self) -> Option<f64> {
|
self.current_request().current_pixel_density.clone()
|
||||||
(*self.unsafe_get())
|
|
||||||
.current_request
|
|
||||||
.borrow_for_layout()
|
|
||||||
.current_pixel_density
|
|
||||||
.clone()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_width(self) -> LengthOrPercentageOrAuto {
|
fn get_width(self) -> LengthOrPercentageOrAuto {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||||
.map(AttrValue::as_dimension)
|
.map(AttrValue::as_dimension)
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_height(self) -> LengthOrPercentageOrAuto {
|
fn get_height(self) -> LengthOrPercentageOrAuto {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("height"))
|
.get_attr_for_layout(&ns!(), &local_name!("height"))
|
||||||
.map(AttrValue::as_dimension)
|
.map(AttrValue::as_dimension)
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//https://html.spec.whatwg.org/multipage/#parse-a-sizes-attribute
|
//https://html.spec.whatwg.org/multipage/#parse-a-sizes-attribute
|
||||||
|
|
|
@ -18,9 +18,7 @@ use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
|
||||||
use crate::dom::bindings::str::{DOMString, USVString};
|
use crate::dom::bindings::str::{DOMString, USVString};
|
||||||
use crate::dom::compositionevent::CompositionEvent;
|
use crate::dom::compositionevent::CompositionEvent;
|
||||||
use crate::dom::document::Document;
|
use crate::dom::document::Document;
|
||||||
use crate::dom::element::{
|
use crate::dom::element::{AttributeMutation, Element, LayoutElementHelpers};
|
||||||
AttributeMutation, Element, LayoutElementHelpers, RawLayoutElementHelpers,
|
|
||||||
};
|
|
||||||
use crate::dom::event::{Event, EventBubbles, EventCancelable};
|
use crate::dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use crate::dom::eventtarget::EventTarget;
|
use crate::dom::eventtarget::EventTarget;
|
||||||
use crate::dom::file::File;
|
use crate::dom::file::File;
|
||||||
|
@ -707,89 +705,98 @@ impl HTMLInputElement {
|
||||||
|
|
||||||
pub trait LayoutHTMLInputElementHelpers<'dom> {
|
pub trait LayoutHTMLInputElementHelpers<'dom> {
|
||||||
fn value_for_layout(self) -> Cow<'dom, str>;
|
fn value_for_layout(self) -> Cow<'dom, str>;
|
||||||
#[allow(unsafe_code)]
|
fn size_for_layout(self) -> u32;
|
||||||
unsafe fn size_for_layout(self) -> u32;
|
fn selection_for_layout(self) -> Option<Range<usize>>;
|
||||||
#[allow(unsafe_code)]
|
fn checked_state_for_layout(self) -> bool;
|
||||||
unsafe fn selection_for_layout(self) -> Option<Range<usize>>;
|
fn indeterminate_state_for_layout(self) -> bool;
|
||||||
#[allow(unsafe_code)]
|
|
||||||
unsafe fn checked_state_for_layout(self) -> bool;
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
unsafe fn indeterminate_state_for_layout(self) -> bool;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_raw_textinput_value(input: LayoutDom<HTMLInputElement>) -> DOMString {
|
impl<'dom> LayoutDom<'dom, HTMLInputElement> {
|
||||||
(*input.unsafe_get())
|
fn get_raw_textinput_value(self) -> DOMString {
|
||||||
|
unsafe {
|
||||||
|
self.unsafe_get()
|
||||||
.textinput
|
.textinput
|
||||||
.borrow_for_layout()
|
.borrow_for_layout()
|
||||||
.get_content()
|
.get_content()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn placeholder(self) -> &'dom str {
|
||||||
|
unsafe { self.unsafe_get().placeholder.borrow_for_layout() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn input_type(self) -> InputType {
|
||||||
|
unsafe { self.unsafe_get().input_type.get() }
|
||||||
|
}
|
||||||
|
|
||||||
|
fn textinput_sorted_selection_offsets_range(self) -> Range<UTF8Bytes> {
|
||||||
|
unsafe {
|
||||||
|
self.unsafe_get()
|
||||||
|
.textinput
|
||||||
|
.borrow_for_layout()
|
||||||
|
.sorted_selection_offsets_range()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'dom> LayoutHTMLInputElementHelpers<'dom> for LayoutDom<'dom, HTMLInputElement> {
|
impl<'dom> LayoutHTMLInputElementHelpers<'dom> for LayoutDom<'dom, HTMLInputElement> {
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn value_for_layout(self) -> Cow<'dom, str> {
|
fn value_for_layout(self) -> Cow<'dom, str> {
|
||||||
fn get_raw_attr_value<'dom>(
|
fn get_raw_attr_value<'dom>(
|
||||||
input: LayoutDom<'dom, HTMLInputElement>,
|
input: LayoutDom<'dom, HTMLInputElement>,
|
||||||
default: &'static str,
|
default: &'static str,
|
||||||
) -> Cow<'dom, str> {
|
) -> Cow<'dom, str> {
|
||||||
unsafe {
|
|
||||||
input
|
input
|
||||||
.upcast::<Element>()
|
.upcast::<Element>()
|
||||||
.unsafe_get()
|
|
||||||
.get_attr_val_for_layout(&ns!(), &local_name!("value"))
|
.get_attr_val_for_layout(&ns!(), &local_name!("value"))
|
||||||
.unwrap_or(default)
|
.unwrap_or(default)
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let placeholder = unsafe { &**self.unsafe_get().placeholder.borrow_for_layout() };
|
match self.input_type() {
|
||||||
match unsafe { self.unsafe_get().input_type() } {
|
|
||||||
InputType::Checkbox | InputType::Radio => "".into(),
|
InputType::Checkbox | InputType::Radio => "".into(),
|
||||||
InputType::File | InputType::Image => "".into(),
|
InputType::File | InputType::Image => "".into(),
|
||||||
InputType::Button => get_raw_attr_value(self, ""),
|
InputType::Button => get_raw_attr_value(self, ""),
|
||||||
InputType::Submit => get_raw_attr_value(self, DEFAULT_SUBMIT_VALUE),
|
InputType::Submit => get_raw_attr_value(self, DEFAULT_SUBMIT_VALUE),
|
||||||
InputType::Reset => get_raw_attr_value(self, DEFAULT_RESET_VALUE),
|
InputType::Reset => get_raw_attr_value(self, DEFAULT_RESET_VALUE),
|
||||||
InputType::Password => {
|
InputType::Password => {
|
||||||
let text = unsafe { get_raw_textinput_value(self) };
|
let text = self.get_raw_textinput_value();
|
||||||
if !text.is_empty() {
|
if !text.is_empty() {
|
||||||
text.chars()
|
text.chars()
|
||||||
.map(|_| PASSWORD_REPLACEMENT_CHAR)
|
.map(|_| PASSWORD_REPLACEMENT_CHAR)
|
||||||
.collect::<String>()
|
.collect::<String>()
|
||||||
.into()
|
.into()
|
||||||
} else {
|
} else {
|
||||||
placeholder.into()
|
self.placeholder().into()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
let text = unsafe { get_raw_textinput_value(self) };
|
let text = self.get_raw_textinput_value();
|
||||||
if !text.is_empty() {
|
if !text.is_empty() {
|
||||||
text.into()
|
text.into()
|
||||||
} else {
|
} else {
|
||||||
placeholder.into()
|
self.placeholder().into()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn size_for_layout(self) -> u32 {
|
fn size_for_layout(self) -> u32 {
|
||||||
(*self.unsafe_get()).size.get()
|
unsafe { self.unsafe_get().size.get() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
fn selection_for_layout(self) -> Option<Range<usize>> {
|
||||||
#[allow(unsafe_code)]
|
if !self.upcast::<Element>().focus_state() {
|
||||||
unsafe fn selection_for_layout(self) -> Option<Range<usize>> {
|
|
||||||
if !(*self.unsafe_get()).upcast::<Element>().focus_state() {
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let textinput = (*self.unsafe_get()).textinput.borrow_for_layout();
|
let sorted_selection_offsets_range = self.textinput_sorted_selection_offsets_range();
|
||||||
|
|
||||||
match (*self.unsafe_get()).input_type() {
|
match self.input_type() {
|
||||||
InputType::Password => {
|
InputType::Password => {
|
||||||
let text = get_raw_textinput_value(self);
|
let text = self.get_raw_textinput_value();
|
||||||
let sel = UTF8Bytes::unwrap_range(textinput.sorted_selection_offsets_range());
|
let sel = UTF8Bytes::unwrap_range(sorted_selection_offsets_range);
|
||||||
|
|
||||||
// Translate indices from the raw value to indices in the replacement value.
|
// Translate indices from the raw value to indices in the replacement value.
|
||||||
let char_start = text[..sel.start].chars().count();
|
let char_start = text[..sel.start].chars().count();
|
||||||
|
@ -798,24 +805,20 @@ impl<'dom> LayoutHTMLInputElementHelpers<'dom> for LayoutDom<'dom, HTMLInputElem
|
||||||
let bytes_per_char = PASSWORD_REPLACEMENT_CHAR.len_utf8();
|
let bytes_per_char = PASSWORD_REPLACEMENT_CHAR.len_utf8();
|
||||||
Some(char_start * bytes_per_char..char_end * bytes_per_char)
|
Some(char_start * bytes_per_char..char_end * bytes_per_char)
|
||||||
},
|
},
|
||||||
input_type if input_type.is_textual() => Some(UTF8Bytes::unwrap_range(
|
input_type if input_type.is_textual() => {
|
||||||
textinput.sorted_selection_offsets_range(),
|
Some(UTF8Bytes::unwrap_range(sorted_selection_offsets_range))
|
||||||
)),
|
},
|
||||||
_ => None,
|
_ => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
fn checked_state_for_layout(self) -> bool {
|
||||||
#[allow(unsafe_code)]
|
|
||||||
unsafe fn checked_state_for_layout(self) -> bool {
|
|
||||||
self.upcast::<Element>()
|
self.upcast::<Element>()
|
||||||
.get_state_for_layout()
|
.get_state_for_layout()
|
||||||
.contains(ElementState::IN_CHECKED_STATE)
|
.contains(ElementState::IN_CHECKED_STATE)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
fn indeterminate_state_for_layout(self) -> bool {
|
||||||
#[allow(unsafe_code)]
|
|
||||||
unsafe fn indeterminate_state_for_layout(self) -> bool {
|
|
||||||
self.upcast::<Element>()
|
self.upcast::<Element>()
|
||||||
.get_state_for_layout()
|
.get_state_for_layout()
|
||||||
.contains(ElementState::IN_INDETERMINATE_STATE)
|
.contains(ElementState::IN_INDETERMINATE_STATE)
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::dom::bindings::root::DomRoot;
|
||||||
use crate::dom::bindings::root::LayoutDom;
|
use crate::dom::bindings::root::LayoutDom;
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::document::Document;
|
use crate::dom::document::Document;
|
||||||
use crate::dom::element::{Element, RawLayoutElementHelpers};
|
use crate::dom::element::{Element, LayoutElementHelpers};
|
||||||
use crate::dom::htmlelement::HTMLElement;
|
use crate::dom::htmlelement::HTMLElement;
|
||||||
use crate::dom::htmltablerowelement::HTMLTableRowElement;
|
use crate::dom::htmltablerowelement::HTMLTableRowElement;
|
||||||
use crate::dom::node::Node;
|
use crate::dom::node::Node;
|
||||||
|
@ -104,42 +104,33 @@ pub trait HTMLTableCellElementLayoutHelpers {
|
||||||
fn get_width(self) -> LengthOrPercentageOrAuto;
|
fn get_width(self) -> LengthOrPercentageOrAuto;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
impl HTMLTableCellElementLayoutHelpers for LayoutDom<'_, HTMLTableCellElement> {
|
impl HTMLTableCellElementLayoutHelpers for LayoutDom<'_, HTMLTableCellElement> {
|
||||||
fn get_background_color(self) -> Option<RGBA> {
|
fn get_background_color(self) -> Option<RGBA> {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(&*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||||
.and_then(AttrValue::as_color)
|
.and_then(AttrValue::as_color)
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn get_colspan(self) -> Option<u32> {
|
fn get_colspan(self) -> Option<u32> {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(&*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("colspan"))
|
.get_attr_for_layout(&ns!(), &local_name!("colspan"))
|
||||||
.map(AttrValue::as_uint)
|
.map(AttrValue::as_uint)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn get_rowspan(self) -> Option<u32> {
|
fn get_rowspan(self) -> Option<u32> {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(&*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("rowspan"))
|
.get_attr_for_layout(&ns!(), &local_name!("rowspan"))
|
||||||
.map(AttrValue::as_uint)
|
.map(AttrValue::as_uint)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn get_width(self) -> LengthOrPercentageOrAuto {
|
fn get_width(self) -> LengthOrPercentageOrAuto {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(&*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||||
.map(AttrValue::as_dimension)
|
.map(AttrValue::as_dimension)
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for HTMLTableCellElement {
|
impl VirtualMethods for HTMLTableCellElement {
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom};
|
use crate::dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom};
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::document::Document;
|
use crate::dom::document::Document;
|
||||||
use crate::dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
|
use crate::dom::element::{AttributeMutation, Element, LayoutElementHelpers};
|
||||||
use crate::dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
use crate::dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
||||||
use crate::dom::htmlelement::HTMLElement;
|
use crate::dom::htmlelement::HTMLElement;
|
||||||
use crate::dom::htmltablecaptionelement::HTMLTableCaptionElement;
|
use crate::dom::htmltablecaptionelement::HTMLTableCaptionElement;
|
||||||
|
@ -413,15 +413,12 @@ pub trait HTMLTableElementLayoutHelpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HTMLTableElementLayoutHelpers for LayoutDom<'_, HTMLTableElement> {
|
impl HTMLTableElementLayoutHelpers for LayoutDom<'_, HTMLTableElement> {
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_background_color(self) -> Option<RGBA> {
|
fn get_background_color(self) -> Option<RGBA> {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||||
.and_then(AttrValue::as_color)
|
.and_then(AttrValue::as_color)
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
fn get_border(self) -> Option<u32> {
|
fn get_border(self) -> Option<u32> {
|
||||||
|
@ -433,16 +430,13 @@ impl HTMLTableElementLayoutHelpers for LayoutDom<'_, HTMLTableElement> {
|
||||||
unsafe { (*self.unsafe_get()).cellspacing.get() }
|
unsafe { (*self.unsafe_get()).cellspacing.get() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_width(self) -> LengthOrPercentageOrAuto {
|
fn get_width(self) -> LengthOrPercentageOrAuto {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
.get_attr_for_layout(&ns!(), &local_name!("width"))
|
||||||
.map(AttrValue::as_dimension)
|
.map(AttrValue::as_dimension)
|
||||||
.cloned()
|
.cloned()
|
||||||
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
.unwrap_or(LengthOrPercentageOrAuto::Auto)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for HTMLTableElement {
|
impl VirtualMethods for HTMLTableElement {
|
||||||
|
|
|
@ -11,7 +11,7 @@ use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
|
use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::document::Document;
|
use crate::dom::document::Document;
|
||||||
use crate::dom::element::{Element, RawLayoutElementHelpers};
|
use crate::dom::element::{Element, LayoutElementHelpers};
|
||||||
use crate::dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
use crate::dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
||||||
use crate::dom::htmlelement::HTMLElement;
|
use crate::dom::htmlelement::HTMLElement;
|
||||||
use crate::dom::htmltablecellelement::HTMLTableCellElement;
|
use crate::dom::htmltablecellelement::HTMLTableCellElement;
|
||||||
|
@ -149,16 +149,13 @@ pub trait HTMLTableRowElementLayoutHelpers {
|
||||||
fn get_background_color(self) -> Option<RGBA>;
|
fn get_background_color(self) -> Option<RGBA>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
impl HTMLTableRowElementLayoutHelpers for LayoutDom<'_, HTMLTableRowElement> {
|
impl HTMLTableRowElementLayoutHelpers for LayoutDom<'_, HTMLTableRowElement> {
|
||||||
fn get_background_color(self) -> Option<RGBA> {
|
fn get_background_color(self) -> Option<RGBA> {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(&*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||||
.and_then(AttrValue::as_color)
|
.and_then(AttrValue::as_color)
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for HTMLTableRowElement {
|
impl VirtualMethods for HTMLTableRowElement {
|
||||||
|
|
|
@ -9,7 +9,7 @@ use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::root::{DomRoot, LayoutDom};
|
use crate::dom::bindings::root::{DomRoot, LayoutDom};
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::document::Document;
|
use crate::dom::document::Document;
|
||||||
use crate::dom::element::{Element, RawLayoutElementHelpers};
|
use crate::dom::element::{Element, LayoutElementHelpers};
|
||||||
use crate::dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
use crate::dom::htmlcollection::{CollectionFilter, HTMLCollection};
|
||||||
use crate::dom::htmlelement::HTMLElement;
|
use crate::dom::htmlelement::HTMLElement;
|
||||||
use crate::dom::htmltablerowelement::HTMLTableRowElement;
|
use crate::dom::htmltablerowelement::HTMLTableRowElement;
|
||||||
|
@ -87,16 +87,13 @@ pub trait HTMLTableSectionElementLayoutHelpers {
|
||||||
fn get_background_color(self) -> Option<RGBA>;
|
fn get_background_color(self) -> Option<RGBA>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
impl HTMLTableSectionElementLayoutHelpers for LayoutDom<'_, HTMLTableSectionElement> {
|
impl HTMLTableSectionElementLayoutHelpers for LayoutDom<'_, HTMLTableSectionElement> {
|
||||||
fn get_background_color(self) -> Option<RGBA> {
|
fn get_background_color(self) -> Option<RGBA> {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(&*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
.get_attr_for_layout(&ns!(), &local_name!("bgcolor"))
|
||||||
.and_then(AttrValue::as_color)
|
.and_then(AttrValue::as_color)
|
||||||
.cloned()
|
.cloned()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for HTMLTableSectionElement {
|
impl VirtualMethods for HTMLTableSectionElement {
|
||||||
|
|
|
@ -14,7 +14,7 @@ use crate::dom::bindings::root::{DomRoot, LayoutDom, MutNullableDom};
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::compositionevent::CompositionEvent;
|
use crate::dom::compositionevent::CompositionEvent;
|
||||||
use crate::dom::document::Document;
|
use crate::dom::document::Document;
|
||||||
use crate::dom::element::RawLayoutElementHelpers;
|
use crate::dom::element::LayoutElementHelpers;
|
||||||
use crate::dom::element::{AttributeMutation, Element};
|
use crate::dom::element::{AttributeMutation, Element};
|
||||||
use crate::dom::event::{Event, EventBubbles, EventCancelable};
|
use crate::dom::event::{Event, EventBubbles, EventCancelable};
|
||||||
use crate::dom::globalscope::GlobalScope;
|
use crate::dom::globalscope::GlobalScope;
|
||||||
|
@ -57,62 +57,71 @@ pub struct HTMLTextAreaElement {
|
||||||
|
|
||||||
pub trait LayoutHTMLTextAreaElementHelpers {
|
pub trait LayoutHTMLTextAreaElementHelpers {
|
||||||
fn value_for_layout(self) -> String;
|
fn value_for_layout(self) -> String;
|
||||||
#[allow(unsafe_code)]
|
fn selection_for_layout(self) -> Option<Range<usize>>;
|
||||||
unsafe fn selection_for_layout(self) -> Option<Range<usize>>;
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_cols(self) -> u32;
|
fn get_cols(self) -> u32;
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_rows(self) -> u32;
|
fn get_rows(self) -> u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutHTMLTextAreaElementHelpers for LayoutDom<'_, HTMLTextAreaElement> {
|
#[allow(unsafe_code)]
|
||||||
#[allow(unsafe_code)]
|
impl<'dom> LayoutDom<'dom, HTMLTextAreaElement> {
|
||||||
fn value_for_layout(self) -> String {
|
fn textinput_content(self) -> DOMString {
|
||||||
let text = unsafe {
|
unsafe {
|
||||||
self.unsafe_get()
|
self.unsafe_get()
|
||||||
.textinput
|
.textinput
|
||||||
.borrow_for_layout()
|
.borrow_for_layout()
|
||||||
.get_content()
|
.get_content()
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn textinput_sorted_selection_offsets_range(self) -> Range<UTF8Bytes> {
|
||||||
|
unsafe {
|
||||||
|
self.unsafe_get()
|
||||||
|
.textinput
|
||||||
|
.borrow_for_layout()
|
||||||
|
.sorted_selection_offsets_range()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn placeholder(self) -> &'dom str {
|
||||||
|
unsafe { self.unsafe_get().placeholder.borrow_for_layout() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl LayoutHTMLTextAreaElementHelpers for LayoutDom<'_, HTMLTextAreaElement> {
|
||||||
|
fn value_for_layout(self) -> String {
|
||||||
|
let text = self.textinput_content();
|
||||||
if text.is_empty() {
|
if text.is_empty() {
|
||||||
let placeholder = unsafe { self.unsafe_get().placeholder.borrow_for_layout() };
|
|
||||||
// FIXME(nox): Would be cool to not allocate a new string if the
|
// FIXME(nox): Would be cool to not allocate a new string if the
|
||||||
// placeholder is single line, but that's an unimportant detail.
|
// placeholder is single line, but that's an unimportant detail.
|
||||||
placeholder.replace("\r\n", "\n").replace("\r", "\n").into()
|
self.placeholder()
|
||||||
|
.replace("\r\n", "\n")
|
||||||
|
.replace("\r", "\n")
|
||||||
|
.into()
|
||||||
} else {
|
} else {
|
||||||
text.into()
|
text.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unrooted_must_root)]
|
fn selection_for_layout(self) -> Option<Range<usize>> {
|
||||||
#[allow(unsafe_code)]
|
if !self.upcast::<Element>().focus_state() {
|
||||||
unsafe fn selection_for_layout(self) -> Option<Range<usize>> {
|
|
||||||
if !(*self.unsafe_get()).upcast::<Element>().focus_state() {
|
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let textinput = (*self.unsafe_get()).textinput.borrow_for_layout();
|
|
||||||
Some(UTF8Bytes::unwrap_range(
|
Some(UTF8Bytes::unwrap_range(
|
||||||
textinput.sorted_selection_offsets_range(),
|
self.textinput_sorted_selection_offsets_range(),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_cols(self) -> u32 {
|
fn get_cols(self) -> u32 {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("cols"))
|
.get_attr_for_layout(&ns!(), &local_name!("cols"))
|
||||||
.map_or(DEFAULT_COLS, AttrValue::as_uint)
|
.map_or(DEFAULT_COLS, AttrValue::as_uint)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn get_rows(self) -> u32 {
|
fn get_rows(self) -> u32 {
|
||||||
unsafe {
|
self.upcast::<Element>()
|
||||||
(*self.upcast::<Element>().unsafe_get())
|
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("rows"))
|
.get_attr_for_layout(&ns!(), &local_name!("rows"))
|
||||||
.map_or(DEFAULT_ROWS, AttrValue::as_uint)
|
.map_or(DEFAULT_ROWS, AttrValue::as_uint)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#attr-textarea-cols-value
|
// https://html.spec.whatwg.org/multipage/#attr-textarea-cols-value
|
||||||
|
|
|
@ -671,11 +671,6 @@ macro_rules! impl_rare_data (
|
||||||
rare_data.as_mut().unwrap()
|
rare_data.as_mut().unwrap()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn rare_data_for_layout(&self) -> &Option<Box<$type>> {
|
|
||||||
unsafe { self.rare_data.borrow_for_layout() }
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -1305,22 +1305,22 @@ pub unsafe fn from_untrusted_node_address(
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub trait LayoutNodeHelpers<'dom> {
|
pub trait LayoutNodeHelpers<'dom> {
|
||||||
unsafe fn type_id_for_layout(self) -> NodeTypeId;
|
fn type_id_for_layout(self) -> NodeTypeId;
|
||||||
|
|
||||||
unsafe fn composed_parent_node_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
fn composed_parent_node_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
||||||
unsafe fn first_child_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
fn first_child_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
||||||
unsafe fn last_child_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
fn last_child_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
||||||
unsafe fn prev_sibling_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
fn prev_sibling_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
||||||
unsafe fn next_sibling_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
fn next_sibling_ref(self) -> Option<LayoutDom<'dom, Node>>;
|
||||||
|
|
||||||
unsafe fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document>;
|
fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document>;
|
||||||
unsafe fn containing_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
|
fn containing_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>>;
|
||||||
|
|
||||||
unsafe fn is_element_for_layout(self) -> bool;
|
fn is_element_for_layout(self) -> bool;
|
||||||
unsafe fn get_flag(self, flag: NodeFlags) -> bool;
|
unsafe fn get_flag(self, flag: NodeFlags) -> bool;
|
||||||
unsafe fn set_flag(self, flag: NodeFlags, value: bool);
|
unsafe fn set_flag(self, flag: NodeFlags, value: bool);
|
||||||
|
|
||||||
unsafe fn children_count(self) -> u32;
|
fn children_count(self) -> u32;
|
||||||
|
|
||||||
unsafe fn get_style_and_layout_data(self) -> Option<OpaqueStyleAndLayoutData>;
|
unsafe fn get_style_and_layout_data(self) -> Option<OpaqueStyleAndLayoutData>;
|
||||||
unsafe fn init_style_and_layout_data(self, _: OpaqueStyleAndLayoutData);
|
unsafe fn init_style_and_layout_data(self, _: OpaqueStyleAndLayoutData);
|
||||||
|
@ -1339,24 +1339,30 @@ pub trait LayoutNodeHelpers<'dom> {
|
||||||
fn opaque(self) -> OpaqueNode;
|
fn opaque(self) -> OpaqueNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'dom> LayoutDom<'dom, Node> {
|
||||||
|
#[inline]
|
||||||
|
#[allow(unsafe_code)]
|
||||||
|
fn parent_node_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
||||||
|
unsafe { self.unsafe_get().parent_node.get_inner_as_layout() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn type_id_for_layout(self) -> NodeTypeId {
|
fn type_id_for_layout(self) -> NodeTypeId {
|
||||||
(*self.unsafe_get()).type_id()
|
unsafe { self.unsafe_get().type_id() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
fn is_element_for_layout(self) -> bool {
|
||||||
unsafe fn is_element_for_layout(self) -> bool {
|
self.is::<Element>()
|
||||||
(*self.unsafe_get()).is::<Element>()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
fn composed_parent_node_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
||||||
unsafe fn composed_parent_node_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
let parent = self.parent_node_ref();
|
||||||
let parent = (*self.unsafe_get()).parent_node.get_inner_as_layout();
|
if let Some(parent) = parent {
|
||||||
if let Some(ref parent) = parent {
|
|
||||||
if let Some(shadow_root) = parent.downcast::<ShadowRoot>() {
|
if let Some(shadow_root) = parent.downcast::<ShadowRoot>() {
|
||||||
return Some(shadow_root.get_host_for_layout().upcast());
|
return Some(shadow_root.get_host_for_layout().upcast());
|
||||||
}
|
}
|
||||||
|
@ -1366,47 +1372,51 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn first_child_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
fn first_child_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
||||||
(*self.unsafe_get()).first_child.get_inner_as_layout()
|
unsafe { self.unsafe_get().first_child.get_inner_as_layout() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn last_child_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
fn last_child_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
||||||
(*self.unsafe_get()).last_child.get_inner_as_layout()
|
unsafe { self.unsafe_get().last_child.get_inner_as_layout() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn prev_sibling_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
fn prev_sibling_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
||||||
(*self.unsafe_get()).prev_sibling.get_inner_as_layout()
|
unsafe { self.unsafe_get().prev_sibling.get_inner_as_layout() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn next_sibling_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
fn next_sibling_ref(self) -> Option<LayoutDom<'dom, Node>> {
|
||||||
(*self.unsafe_get()).next_sibling.get_inner_as_layout()
|
unsafe { self.unsafe_get().next_sibling.get_inner_as_layout() }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document> {
|
fn owner_doc_for_layout(self) -> LayoutDom<'dom, Document> {
|
||||||
(*self.unsafe_get())
|
unsafe { self.unsafe_get().owner_doc.get_inner_as_layout().unwrap() }
|
||||||
.owner_doc
|
|
||||||
.get_inner_as_layout()
|
|
||||||
.unwrap()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn containing_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>> {
|
fn containing_shadow_root_for_layout(self) -> Option<LayoutDom<'dom, ShadowRoot>> {
|
||||||
(*self.unsafe_get())
|
unsafe {
|
||||||
.rare_data_for_layout()
|
self.unsafe_get()
|
||||||
|
.rare_data
|
||||||
|
.borrow_for_layout()
|
||||||
.as_ref()?
|
.as_ref()?
|
||||||
.containing_shadow_root
|
.containing_shadow_root
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|sr| sr.to_layout())
|
.map(|sr| sr.to_layout())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FIXME(nox): get_flag/set_flag (especially the latter) are not safe because
|
||||||
|
// they mutate stuff while values of this type can be used from multiple
|
||||||
|
// threads at once, this should be revisited.
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
|
@ -1431,10 +1441,13 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn children_count(self) -> u32 {
|
fn children_count(self) -> u32 {
|
||||||
(*self.unsafe_get()).children_count.get()
|
unsafe { self.unsafe_get().children_count.get() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(nox): How we handle style and layout data needs to be completely
|
||||||
|
// revisited so we can do that more cleanly and safely in layout 2020.
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_style_and_layout_data(self) -> Option<OpaqueStyleAndLayoutData> {
|
unsafe fn get_style_and_layout_data(self) -> Option<OpaqueStyleAndLayoutData> {
|
||||||
|
@ -1472,41 +1485,33 @@ impl<'dom> LayoutNodeHelpers<'dom> for LayoutDom<'dom, Node> {
|
||||||
panic!("not text!")
|
panic!("not text!")
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn selection(self) -> Option<Range<usize>> {
|
fn selection(self) -> Option<Range<usize>> {
|
||||||
if let Some(area) = self.downcast::<HTMLTextAreaElement>() {
|
if let Some(area) = self.downcast::<HTMLTextAreaElement>() {
|
||||||
return unsafe { area.selection_for_layout() };
|
return area.selection_for_layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(input) = self.downcast::<HTMLInputElement>() {
|
if let Some(input) = self.downcast::<HTMLInputElement>() {
|
||||||
return unsafe { input.selection_for_layout() };
|
return input.selection_for_layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn image_url(self) -> Option<ServoUrl> {
|
fn image_url(self) -> Option<ServoUrl> {
|
||||||
unsafe {
|
|
||||||
self.downcast::<HTMLImageElement>()
|
self.downcast::<HTMLImageElement>()
|
||||||
.expect("not an image!")
|
.expect("not an image!")
|
||||||
.image_url()
|
.image_url()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn image_data(self) -> Option<(Option<StdArc<Image>>, Option<ImageMetadata>)> {
|
fn image_data(self) -> Option<(Option<StdArc<Image>>, Option<ImageMetadata>)> {
|
||||||
unsafe { self.downcast::<HTMLImageElement>().map(|e| e.image_data()) }
|
self.downcast::<HTMLImageElement>().map(|e| e.image_data())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
|
||||||
fn image_density(self) -> Option<f64> {
|
fn image_density(self) -> Option<f64> {
|
||||||
unsafe {
|
|
||||||
self.downcast::<HTMLImageElement>()
|
self.downcast::<HTMLImageElement>()
|
||||||
.expect("not an image!")
|
.expect("not an image!")
|
||||||
.image_density()
|
.image_density()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn canvas_data(self) -> Option<HTMLCanvasData> {
|
fn canvas_data(self) -> Option<HTMLCanvasData> {
|
||||||
self.downcast::<HTMLCanvasElement>()
|
self.downcast::<HTMLCanvasElement>()
|
||||||
|
|
|
@ -27,6 +27,7 @@ use style::dom::TElement;
|
||||||
use style::media_queries::Device;
|
use style::media_queries::Device;
|
||||||
use style::shared_lock::SharedRwLockReadGuard;
|
use style::shared_lock::SharedRwLockReadGuard;
|
||||||
use style::stylesheets::Stylesheet;
|
use style::stylesheets::Stylesheet;
|
||||||
|
use style::stylist::CascadeData;
|
||||||
|
|
||||||
/// Whether a shadow root hosts an User Agent widget.
|
/// Whether a shadow root hosts an User Agent widget.
|
||||||
#[derive(JSTraceable, MallocSizeOf, PartialEq)]
|
#[derive(JSTraceable, MallocSizeOf, PartialEq)]
|
||||||
|
@ -240,8 +241,8 @@ impl ShadowRootMethods for ShadowRoot {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
pub trait LayoutShadowRootHelpers<'dom> {
|
pub trait LayoutShadowRootHelpers<'dom> {
|
||||||
unsafe fn get_host_for_layout(self) -> LayoutDom<'dom, Element>;
|
fn get_host_for_layout(self) -> LayoutDom<'dom, Element>;
|
||||||
unsafe fn get_style_data_for_layout(self) -> &'dom AuthorStyles<StyleSheetInDocument>;
|
fn get_style_data_for_layout(self) -> &'dom CascadeData;
|
||||||
unsafe fn flush_stylesheets<E: TElement>(
|
unsafe fn flush_stylesheets<E: TElement>(
|
||||||
self,
|
self,
|
||||||
device: &Device,
|
device: &Device,
|
||||||
|
@ -253,19 +254,25 @@ pub trait LayoutShadowRootHelpers<'dom> {
|
||||||
impl<'dom> LayoutShadowRootHelpers<'dom> for LayoutDom<'dom, ShadowRoot> {
|
impl<'dom> LayoutShadowRootHelpers<'dom> for LayoutDom<'dom, ShadowRoot> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_host_for_layout(self) -> LayoutDom<'dom, Element> {
|
fn get_host_for_layout(self) -> LayoutDom<'dom, Element> {
|
||||||
(*self.unsafe_get())
|
unsafe {
|
||||||
|
self.unsafe_get()
|
||||||
.host
|
.host
|
||||||
.get_inner_as_layout()
|
.get_inner_as_layout()
|
||||||
.expect("We should never do layout on a detached shadow root")
|
.expect("We should never do layout on a detached shadow root")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn get_style_data_for_layout(self) -> &'dom AuthorStyles<StyleSheetInDocument> {
|
fn get_style_data_for_layout(self) -> &'dom CascadeData {
|
||||||
(*self.unsafe_get()).author_styles.borrow_for_layout()
|
fn is_sync<T: Sync>() {}
|
||||||
|
let _ = is_sync::<CascadeData>;
|
||||||
|
unsafe { &self.unsafe_get().author_styles.borrow_for_layout().data }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FIXME(nox): This uses the dreaded borrow_mut_for_layout so this should
|
||||||
|
// probably be revisited.
|
||||||
#[inline]
|
#[inline]
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
unsafe fn flush_stylesheets<E: TElement>(
|
unsafe fn flush_stylesheets<E: TElement>(
|
||||||
|
|
|
@ -7,7 +7,7 @@ use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::root::{DomRoot, LayoutDom};
|
use crate::dom::bindings::root::{DomRoot, LayoutDom};
|
||||||
use crate::dom::bindings::str::DOMString;
|
use crate::dom::bindings::str::DOMString;
|
||||||
use crate::dom::document::Document;
|
use crate::dom::document::Document;
|
||||||
use crate::dom::element::{AttributeMutation, Element, RawLayoutElementHelpers};
|
use crate::dom::element::{AttributeMutation, Element, LayoutElementHelpers};
|
||||||
use crate::dom::node::Node;
|
use crate::dom::node::Node;
|
||||||
use crate::dom::svggraphicselement::SVGGraphicsElement;
|
use crate::dom::svggraphicselement::SVGGraphicsElement;
|
||||||
use crate::dom::virtualmethods::VirtualMethods;
|
use crate::dom::virtualmethods::VirtualMethods;
|
||||||
|
@ -53,15 +53,11 @@ pub trait LayoutSVGSVGElementHelpers {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LayoutSVGSVGElementHelpers for LayoutDom<'_, SVGSVGElement> {
|
impl LayoutSVGSVGElementHelpers for LayoutDom<'_, SVGSVGElement> {
|
||||||
#[allow(unsafe_code, non_snake_case)]
|
|
||||||
fn data(self) -> SVGSVGData {
|
fn data(self) -> SVGSVGData {
|
||||||
unsafe {
|
let width_attr = self
|
||||||
let SVG = &*self.unsafe_get();
|
|
||||||
|
|
||||||
let width_attr = SVG
|
|
||||||
.upcast::<Element>()
|
.upcast::<Element>()
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("width"));
|
.get_attr_for_layout(&ns!(), &local_name!("width"));
|
||||||
let height_attr = SVG
|
let height_attr = self
|
||||||
.upcast::<Element>()
|
.upcast::<Element>()
|
||||||
.get_attr_for_layout(&ns!(), &local_name!("height"));
|
.get_attr_for_layout(&ns!(), &local_name!("height"));
|
||||||
SVGSVGData {
|
SVGSVGData {
|
||||||
|
@ -69,7 +65,6 @@ impl LayoutSVGSVGElementHelpers for LayoutDom<'_, SVGSVGElement> {
|
||||||
height: height_attr.map_or(DEFAULT_HEIGHT, |val| val.as_uint()),
|
height: height_attr.map_or(DEFAULT_HEIGHT, |val| val.as_uint()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VirtualMethods for SVGSVGElement {
|
impl VirtualMethods for SVGSVGElement {
|
||||||
|
|
|
@ -131,7 +131,7 @@ pub mod layout_exports {
|
||||||
pub use crate::dom::bindings::root::LayoutDom;
|
pub use crate::dom::bindings::root::LayoutDom;
|
||||||
pub use crate::dom::characterdata::LayoutCharacterDataHelpers;
|
pub use crate::dom::characterdata::LayoutCharacterDataHelpers;
|
||||||
pub use crate::dom::document::{Document, LayoutDocumentHelpers};
|
pub use crate::dom::document::{Document, LayoutDocumentHelpers};
|
||||||
pub use crate::dom::element::{Element, LayoutElementHelpers, RawLayoutElementHelpers};
|
pub use crate::dom::element::{Element, LayoutElementHelpers};
|
||||||
pub use crate::dom::node::NodeFlags;
|
pub use crate::dom::node::NodeFlags;
|
||||||
pub use crate::dom::node::{LayoutNodeHelpers, Node};
|
pub use crate::dom::node::{LayoutNodeHelpers, Node};
|
||||||
pub use crate::dom::shadowroot::{LayoutShadowRootHelpers, ShadowRoot};
|
pub use crate::dom::shadowroot::{LayoutShadowRootHelpers, ShadowRoot};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue