Auto merge of #6698 - Ms2ger:layoutelement, r=jdm

Implement some methods on LayoutJS<Element>.

Part of my long-term plan to stop exposing `unsafe_get()` outside the script crate.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6698)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-07-22 21:10:04 -06:00
commit 37a1e22515
2 changed files with 31 additions and 22 deletions

View file

@ -383,11 +383,9 @@ pub struct LayoutElement<'le> {
impl<'le> LayoutElement<'le> { impl<'le> LayoutElement<'le> {
pub fn style_attribute(&self) -> &'le Option<PropertyDeclarationBlock> { pub fn style_attribute(&self) -> &'le Option<PropertyDeclarationBlock> {
use script::dom::element::ElementHelpers; unsafe {
let style: &Option<PropertyDeclarationBlock> = unsafe { &*self.element.style_attribute()
&*(*self.element.unsafe_get()).style_attribute().borrow_for_layout() }
};
style
} }
} }
@ -404,23 +402,18 @@ impl<'le> ::selectors::Element for LayoutElement<'le> {
#[inline] #[inline]
fn get_local_name<'a>(&'a self) -> &'a Atom { fn get_local_name<'a>(&'a self) -> &'a Atom {
unsafe { self.element.local_name()
(*self.element.unsafe_get()).local_name()
}
} }
#[inline] #[inline]
fn get_namespace<'a>(&'a self) -> &'a Namespace { fn get_namespace<'a>(&'a self) -> &'a Namespace {
use script::dom::element::ElementHelpers; self.element.namespace()
unsafe {
(*self.element.unsafe_get()).namespace()
}
} }
fn is_link(&self) -> bool { fn is_link(&self) -> bool {
// FIXME: This is HTML only. // FIXME: This is HTML only.
let node = NodeCast::from_layout_js(&self.element); let node = self.as_node();
match unsafe { (*node.unsafe_get()).type_id_for_layout() } { match node.type_id() {
// https://html.spec.whatwg.org/multipage/#selector-link // https://html.spec.whatwg.org/multipage/#selector-link
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) |
NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAreaElement)) |

View file

@ -181,8 +181,6 @@ pub trait RawLayoutElementHelpers {
unsafe fn get_indeterminate_state_for_layout(&self) -> bool; unsafe fn get_indeterminate_state_for_layout(&self) -> bool;
unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute) unsafe fn get_unsigned_integer_attribute_for_layout(&self, attribute: UnsignedIntegerAttribute)
-> Option<u32>; -> Option<u32>;
fn local_name<'a>(&'a self) -> &'a Atom;
} }
#[inline] #[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 { pub trait LayoutElementHelpers {
@ -511,6 +503,9 @@ pub trait LayoutElementHelpers {
unsafe fn html_element_in_html_document_for_layout(&self) -> bool; unsafe fn html_element_in_html_document_for_layout(&self) -> bool;
#[allow(unsafe_code)] #[allow(unsafe_code)]
unsafe fn has_attr_for_layout(&self, namespace: &Namespace, name: &Atom) -> bool; unsafe fn has_attr_for_layout(&self, namespace: &Namespace, name: &Atom) -> bool;
fn style_attribute(&self) -> *const Option<PropertyDeclarationBlock>;
fn local_name<'a>(&'a self) -> &'a Atom;
fn namespace<'a>(&'a self) -> &'a Namespace;
} }
impl LayoutElementHelpers for LayoutJS<Element> { impl LayoutElementHelpers for LayoutJS<Element> {
@ -528,6 +523,27 @@ impl LayoutElementHelpers for LayoutJS<Element> {
unsafe fn has_attr_for_layout(&self, namespace: &Namespace, name: &Atom) -> bool { unsafe fn has_attr_for_layout(&self, namespace: &Namespace, name: &Atom) -> bool {
get_attr_for_layout(&*self.unsafe_get(), namespace, name).is_some() get_attr_for_layout(&*self.unsafe_get(), namespace, name).is_some()
} }
#[allow(unsafe_code)]
fn style_attribute(&self) -> *const Option<PropertyDeclarationBlock> {
unsafe {
(*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)] #[derive(PartialEq)]