Move Element::get_attr to a trait defined in util::tree

… and add a get_local_name() method to that trait.
This commit is contained in:
Simon Sapin 2013-10-16 16:47:04 +01:00
parent f38b4ab9bb
commit 62f1f03c16
10 changed files with 32 additions and 13 deletions

View file

@ -14,6 +14,7 @@ use dom::node::{ElementNodeTypeId, Node, ScriptView, AbstractNode};
use layout_interface::{ContentBoxQuery, ContentBoxResponse, ContentBoxesQuery};
use layout_interface::{ContentBoxesResponse};
use newcss::stylesheet::Stylesheet;
use servo_util::tree::ElementLike;
use js::jsapi::{JSContext, JSObject};
@ -119,17 +120,12 @@ pub enum ElementTypeId {
// Element methods
//
impl<'self> Element {
pub fn new(type_id: ElementTypeId, tag_name: ~str, document: AbstractDocument) -> Element {
Element {
node: Node::new(ElementNodeTypeId(type_id), document),
tag_name: tag_name,
attrs: ~[],
style_attribute: None,
}
impl<'self> ElementLike<'self> for Element {
fn get_local_name(&'self self) -> &'self str {
self.tag_name.as_slice()
}
pub fn get_attr(&'self self, name: &str) -> Option<&'self str> {
fn get_attr(&'self self, name: &str) -> Option<&'self str> {
// FIXME: Need an each() that links lifetimes in Rust.
for attr in self.attrs.iter() {
// FIXME: only case-insensitive in the HTML namespace (as opposed to SVG, etc.)
@ -140,6 +136,17 @@ impl<'self> Element {
}
return None;
}
}
impl<'self> Element {
pub fn new(type_id: ElementTypeId, tag_name: ~str, document: AbstractDocument) -> Element {
Element {
node: Node::new(ElementNodeTypeId(type_id), document),
tag_name: tag_name,
attrs: ~[],
style_attribute: None,
}
}
pub fn set_attr(&mut self,
abstract_self: AbstractNode<ScriptView>,