Skip to content

Commit

Permalink
Fixes #4123
Browse files Browse the repository at this point in the history
  • Loading branch information
aakashjain committed Nov 29, 2014
1 parent 1ac79c6 commit fab09a5
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 42 deletions.
81 changes: 44 additions & 37 deletions components/script/dom/element.rs
Expand Up @@ -182,36 +182,6 @@ impl Element {
Node::reflect_node(box Element::new_inherited(ElementTypeId_, local_name, namespace, prefix, document),
document, ElementBinding::Wrap)
}

#[inline]
pub fn local_name<'a>(&'a self) -> &'a Atom {
&self.local_name
}

#[inline]
pub fn namespace<'a>(&'a self) -> &'a Namespace {
&self.namespace
}

#[inline]
pub fn prefix<'a>(&'a self) -> &'a Option<DOMString> {
&self.prefix
}

#[inline]
pub fn attrs(&self) -> Ref<Vec<JS<Attr>>> {
self.attrs.borrow()
}

#[inline]
pub fn attrs_mut(&self) -> RefMut<Vec<JS<Attr>>> {
self.attrs.borrow_mut()
}

#[inline]
pub fn style_attribute<'a>(&'a self) -> &'a DOMRefCell<Option<style::PropertyDeclarationBlock>> {
&self.style_attribute
}
}

pub trait RawLayoutElementHelpers {
Expand All @@ -225,6 +195,9 @@ pub trait RawLayoutElementHelpers {
-> LengthOrPercentageOrAuto;
unsafe fn get_integer_attribute_for_layout(&self, integer_attribute: IntegerAttribute)
-> Option<i32>;
fn local_name<'a>(&'a self) -> &'a Atom;
fn namespace<'a>(&'a self) -> &'a Namespace;
fn style_attribute<'a>(&'a self) -> &'a DOMRefCell<Option<style::PropertyDeclarationBlock>>;
}

#[inline]
Expand Down Expand Up @@ -336,6 +309,20 @@ impl RawLayoutElementHelpers for Element {
}
}
}

// Getters used in components/layout/wrapper.rs

fn local_name<'a>(&'a self) -> &'a Atom {
&self.local_name
}

fn namespace<'a>(&'a self) -> &'a Namespace {
&self.namespace
}

fn style_attribute<'a>(&'a self) -> &'a DOMRefCell<Option<style::PropertyDeclarationBlock>> {
&self.style_attribute
}
}

pub trait LayoutElementHelpers {
Expand All @@ -361,8 +348,12 @@ impl LayoutElementHelpers for JS<Element> {

pub trait ElementHelpers<'a> {
fn html_element_in_html_document(self) -> bool;
fn get_local_name(self) -> &'a Atom;
fn get_namespace(self) -> &'a Namespace;
fn local_name(self) -> &'a Atom;
fn namespace(self) -> &'a Namespace;
fn prefix(self) -> &'a Option<DOMString>;
fn attrs(&self) -> Ref<Vec<JS<Attr>>>;
fn attrs_mut(&self) -> RefMut<Vec<JS<Attr>>>;
fn style_attribute(self) -> &'a DOMRefCell<Option<style::PropertyDeclarationBlock>>;
fn summarize(self) -> Vec<AttrInfo>;
fn is_void(self) -> bool;
}
Expand All @@ -373,14 +364,30 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
self.namespace == ns!(HTML) && node.is_in_html_doc()
}

fn get_local_name(self) -> &'a Atom {
fn local_name(self) -> &'a Atom {
&self.extended_deref().local_name
}

fn get_namespace(self) -> &'a Namespace {
fn namespace(self) -> &'a Namespace {
&self.extended_deref().namespace
}

fn prefix(self) -> &'a Option<DOMString> {
&self.extended_deref().prefix
}

fn attrs(&self) -> Ref<Vec<JS<Attr>>> {
self.extended_deref().attrs.borrow()
}

fn attrs_mut(&self) -> RefMut<Vec<JS<Attr>>> {
self.extended_deref().attrs.borrow_mut()
}

fn style_attribute(self) -> &'a DOMRefCell<Option<style::PropertyDeclarationBlock>> {
&self.extended_deref().style_attribute
}

fn summarize(self) -> Vec<AttrInfo> {
let attrs = self.Attributes().root();
let mut i = 0;
Expand All @@ -393,7 +400,7 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> {
summarized
}

fn is_void(self) -> bool {
fn is_void(self) -> bool {
if self.namespace != ns!(HTML) {
return false
}
Expand Down Expand Up @@ -1116,7 +1123,7 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> {
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn get_local_name<'a, T: ElementHelpers<'a>>(this: T) -> &'a Atom {
this.get_local_name()
this.local_name()
}

get_local_name(self)
Expand All @@ -1125,7 +1132,7 @@ impl<'a> style::TElement<'a> for JSRef<'a, Element> {
// FIXME(zwarich): Remove this when UFCS lands and there is a better way
// of disambiguating methods.
fn get_namespace<'a, T: ElementHelpers<'a>>(this: T) -> &'a Namespace {
this.get_namespace()
this.namespace()
}

get_namespace(self)
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/htmlfieldsetelement.rs
Expand Up @@ -11,7 +11,7 @@ use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLLegendElementDer
use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::document::Document;
use dom::element::{AttributeHandlers, Element, HTMLFieldSetElementTypeId, HTMLButtonElementTypeId};
use dom::element::{AttributeHandlers, Element, ElementHelpers, HTMLFieldSetElementTypeId, HTMLButtonElementTypeId};
use dom::element::{HTMLInputElementTypeId, HTMLSelectElementTypeId, HTMLTextAreaElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlcollection::{HTMLCollection, CollectionFilter};
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/htmloptionelement.rs
Expand Up @@ -15,7 +15,7 @@ use dom::bindings::js::{JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector};
use dom::characterdata::CharacterData;
use dom::document::Document;
use dom::element::{AttributeHandlers, Element, HTMLOptionElementTypeId};
use dom::element::{AttributeHandlers, Element, ElementHelpers, HTMLOptionElementTypeId};
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
use dom::htmlelement::HTMLElement;
use dom::node::{DisabledStateHelpers, Node, NodeHelpers, ElementNodeTypeId};
Expand Down
2 changes: 1 addition & 1 deletion components/script/dom/namednodemap.rs
Expand Up @@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::NamedNodeMapBinding::NamedNodeMapMethods;
use dom::bindings::global;
use dom::bindings::js::{JS, JSRef, Temporary};
use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object};
use dom::element::Element;
use dom::element::{Element, ElementHelpers};
use dom::window::Window;

#[dom_struct]
Expand Down
4 changes: 2 additions & 2 deletions components/script/parse/html.rs
Expand Up @@ -98,8 +98,8 @@ impl<'a> TreeSink<TrustedNodeAddress> for servohtmlparser::Sink {
let elem: JSRef<Element> = ElementCast::to_ref(*node)
.expect("tried to get name of non-Element in HTML parsing");
QualName {
ns: elem.get_namespace().clone(),
local: elem.get_local_name().clone(),
ns: elem.namespace().clone(),
local: elem.local_name().clone(),
}
}

Expand Down

9 comments on commit fab09a5

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from Manishearth
at aakashjain@fab09a5

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging aakashjain/servo/MovingElementGetters = fab09a5 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aakashjain/servo/MovingElementGetters = fab09a5 merged ok, testing candidate = 5efa563

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from Manishearth
at aakashjain@fab09a5

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging aakashjain/servo/MovingElementGetters = fab09a5 into auto

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aakashjain/servo/MovingElementGetters = fab09a5 merged ok, testing candidate = 9541dcd

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors-servo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 9541dcd

Please sign in to comment.