From 23c679d55aa34a168d0b526589106c478a9e642c Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 4 Jul 2015 21:41:34 +0200 Subject: [PATCH 1/3] Implement style_attribute() on LayoutJS. --- components/layout/wrapper.rs | 8 +++----- components/script/dom/element.rs | 8 ++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index 6b93514ad6e..b4e78319135 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -383,11 +383,9 @@ pub struct LayoutElement<'le> { impl<'le> LayoutElement<'le> { pub fn style_attribute(&self) -> &'le Option { - use script::dom::element::ElementHelpers; - let style: &Option = unsafe { - &*(*self.element.unsafe_get()).style_attribute().borrow_for_layout() - }; - style + unsafe { + &*self.element.style_attribute() + } } } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index ff9864c88b8..85fe33aa5b5 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -511,6 +511,7 @@ pub trait LayoutElementHelpers { unsafe fn html_element_in_html_document_for_layout(&self) -> bool; #[allow(unsafe_code)] unsafe fn has_attr_for_layout(&self, namespace: &Namespace, name: &Atom) -> bool; + fn style_attribute(&self) -> *const Option; } impl LayoutElementHelpers for LayoutJS { @@ -528,6 +529,13 @@ impl LayoutElementHelpers for LayoutJS { unsafe fn has_attr_for_layout(&self, namespace: &Namespace, name: &Atom) -> bool { get_attr_for_layout(&*self.unsafe_get(), namespace, name).is_some() } + + #[allow(unsafe_code)] + fn style_attribute(&self) -> *const Option { + unsafe { + (*self.unsafe_get()).style_attribute.borrow_for_layout() + } + } } #[derive(PartialEq)] From 9cc1e017ee3991692a2d0f657c59c21f93d46dc6 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 22 Jul 2015 18:28:17 +0200 Subject: [PATCH 2/3] Move local_name and namespace to LayoutJS. --- components/layout/wrapper.rs | 9 ++------- components/script/dom/element.rs | 24 ++++++++++++++++-------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index b4e78319135..fe374aa4b25 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -402,17 +402,12 @@ impl<'le> ::selectors::Element for LayoutElement<'le> { #[inline] fn get_local_name<'a>(&'a self) -> &'a Atom { - unsafe { - (*self.element.unsafe_get()).local_name() - } + self.element.local_name() } #[inline] fn get_namespace<'a>(&'a self) -> &'a Namespace { - use script::dom::element::ElementHelpers; - unsafe { - (*self.element.unsafe_get()).namespace() - } + self.element.namespace() } fn is_link(&self) -> bool { diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 85fe33aa5b5..a5fc6f955da 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -181,8 +181,6 @@ pub trait RawLayoutElementHelpers { unsafe fn get_indeterminate_state_for_layout(&self) -> bool; unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute) -> Option; - - fn local_name<'a>(&'a self) -> &'a Atom; } #[inline] @@ -498,12 +496,6 @@ impl RawLayoutElementHelpers for Element { } } } - - // Getters used in components/layout/wrapper.rs - - fn local_name<'a>(&'a self) -> &'a Atom { - &self.local_name - } } pub trait LayoutElementHelpers { @@ -512,6 +504,8 @@ pub trait LayoutElementHelpers { #[allow(unsafe_code)] unsafe fn has_attr_for_layout(&self, namespace: &Namespace, name: &Atom) -> bool; fn style_attribute(&self) -> *const Option; + fn local_name<'a>(&'a self) -> &'a Atom; + fn namespace<'a>(&'a self) -> &'a Namespace; } impl LayoutElementHelpers for LayoutJS { @@ -536,6 +530,20 @@ impl LayoutElementHelpers for LayoutJS { (*self.unsafe_get()).style_attribute.borrow_for_layout() } } + + #[allow(unsafe_code)] + fn local_name<'a>(&'a self) -> &'a Atom { + unsafe { + &(*self.unsafe_get()).local_name + } + } + + #[allow(unsafe_code)] + fn namespace<'a>(&'a self) -> &'a Namespace { + unsafe { + &(*self.unsafe_get()).namespace + } + } } #[derive(PartialEq)] From 751a367eb94f3872fee5c34e3f69fb564fc17a86 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Wed, 22 Jul 2015 18:29:38 +0200 Subject: [PATCH 3/3] Don't call type_id_for_layout directly in LayoutElement::is_link. --- components/layout/wrapper.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/layout/wrapper.rs b/components/layout/wrapper.rs index fe374aa4b25..762f7dba2a0 100644 --- a/components/layout/wrapper.rs +++ b/components/layout/wrapper.rs @@ -412,8 +412,8 @@ impl<'le> ::selectors::Element for LayoutElement<'le> { fn is_link(&self) -> bool { // FIXME: This is HTML only. - let node = NodeCast::from_layout_js(&self.element); - match unsafe { (*node.unsafe_get()).type_id_for_layout() } { + let node = self.as_node(); + match node.type_id() { // https://html.spec.whatwg.org/multipage/#selector-link NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) |