auto merge of #678 : metajack/servo/style-attributes, r=jdm

If a style attribute is given for a node, it is parsed and attached to the
Element. When selector matching runs on the Element, the style attribute's
stylesheet is passed in.

Fixes #86.
This commit is contained in:
bors-servo 2013-08-06 19:21:32 -07:00
commit b017785aad
5 changed files with 30 additions and 15 deletions

View file

@ -18,6 +18,7 @@ use dom::htmlimageelement::HTMLImageElement;
use dom::node::{ElementNodeTypeId, Node, ScriptView, AbstractNode};
use layout_interface::{ContentBoxQuery, ContentBoxResponse, ContentBoxesQuery};
use layout_interface::{ContentBoxesResponse};
use newcss::stylesheet::Stylesheet;
use js::jsapi::{JSContext, JSObject};
@ -34,6 +35,7 @@ pub struct Element {
parent: Node<ScriptView>,
tag_name: ~str, // TODO: This should be an atom, not a ~str.
attrs: ~[Attr],
style_attribute: Option<Stylesheet>,
}
impl CacheableWrapper for Element {
@ -206,7 +208,8 @@ impl<'self> Element {
Element {
parent: Node::new(ElementNodeTypeId(type_id)),
tag_name: tag_name,
attrs: ~[]
attrs: ~[],
style_attribute: None,
}
}

View file

@ -317,6 +317,13 @@ pub fn parse_html(cx: *JSContext,
do node.as_mut_element |element| {
for tag.attributes.iter().advance |attr| {
element.attrs.push(Attr::new(attr.name.clone(), attr.value.clone()));
if "style" == attr.name {
element.style_attribute = Some(
Stylesheet::from_attribute(
url::from_str("http://www.example.com/").unwrap(),
attr.value));
}
}
}
@ -379,7 +386,6 @@ pub fn parse_html(cx: *JSContext,
}
}
//TODO (Issue #86): handle inline styles ('style' attr)
_ => {}
}