mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
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:
parent
f38b4ab9bb
commit
62f1f03c16
10 changed files with 32 additions and 13 deletions
|
@ -24,7 +24,7 @@ use html::hubbub_html_parser::build_element_from_tag;
|
|||
use js::jsapi::{JSObject, JSContext, JSVal};
|
||||
use js::jsapi::{JSTRACE_OBJECT, JSTracer, JS_CallTracer};
|
||||
use js::glue::RUST_OBJECT_TO_JSVAL;
|
||||
use servo_util::tree::TreeNodeRef;
|
||||
use servo_util::tree::{TreeNodeRef, ElementLike};
|
||||
|
||||
use std::hashmap::HashMap;
|
||||
|
||||
|
|
|
@ -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>,
|
||||
|
|
|
@ -13,7 +13,7 @@ use dom::window::Window;
|
|||
|
||||
use js::jsapi::{JSObject, JSContext, JSTracer};
|
||||
|
||||
use servo_util::tree::TreeNodeRef;
|
||||
use servo_util::tree::{TreeNodeRef, ElementLike};
|
||||
|
||||
use std::libc;
|
||||
use std::ptr;
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
@ -11,6 +12,7 @@ use layout_interface::{ContentBoxQuery, ContentBoxResponse};
|
|||
use servo_net::image_cache_task;
|
||||
use servo_net::image_cache_task::ImageCacheTask;
|
||||
use servo_util::url::make_url;
|
||||
use servo_util::tree::ElementLike;
|
||||
|
||||
pub struct HTMLImageElement {
|
||||
htmlelement: HTMLElement,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue