aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbors-servo <release+servo@mozilla.com>2013-08-06 19:21:32 -0700
committerbors-servo <release+servo@mozilla.com>2013-08-06 19:21:32 -0700
commitb017785aad93171cf199c286dd30dceff46372eb (patch)
treeded6f21ced8dccfb30ac68bbed15a6fdd585aeeb
parentff9e72a01351cd6407db8ead03df0b997e303053 (diff)
parent4d71918366f2971ec1b042f79767767eff2e0a37 (diff)
downloadservo-b017785aad93171cf199c286dd30dceff46372eb.tar.gz
servo-b017785aad93171cf199c286dd30dceff46372eb.zip
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.
-rw-r--r--src/components/main/css/matching.rs28
-rw-r--r--src/components/script/dom/element.rs5
-rw-r--r--src/components/script/html/hubbub_html_parser.rs8
m---------src/support/css/rust-css0
m---------src/support/netsurfcss/rust-netsurfcss0
5 files changed, 28 insertions, 13 deletions
diff --git a/src/components/main/css/matching.rs b/src/components/main/css/matching.rs
index 4801979bcc8..b1712d286eb 100644
--- a/src/components/main/css/matching.rs
+++ b/src/components/main/css/matching.rs
@@ -28,18 +28,24 @@ impl MatchMethods for AbstractNode<LayoutView> {
fn restyle_subtree(&self, select_ctx: &SelectCtx) {
// Only elements have styles
if self.is_element() {
- let select_handler = NodeSelectHandler { node: *self };
- let incomplete_results = select_ctx.select_style(self, &select_handler);
- // Combine this node's results with its parent's to resolve all inherited values
- let complete_results = compose_results(*self, incomplete_results);
+ do self.with_imm_element |elem| {
+ let inline_style = match elem.style_attribute {
+ None => None,
+ Some(ref sheet) => Some(sheet),
+ };
+ let select_handler = NodeSelectHandler { node: *self };
+ let incomplete_results = select_ctx.select_style(self, inline_style, &select_handler);
+ // Combine this node's results with its parent's to resolve all inherited values
+ let complete_results = compose_results(*self, incomplete_results);
- // If there was an existing style, compute the damage that
- // incremental layout will need to fix.
- if self.have_css_select_results() {
- let damage = incremental::compute_damage(self, self.get_css_select_results(), &complete_results);
- self.set_restyle_damage(damage);
- }
- self.set_css_select_results(complete_results);
+ // If there was an existing style, compute the damage that
+ // incremental layout will need to fix.
+ if self.have_css_select_results() {
+ let damage = incremental::compute_damage(self, self.get_css_select_results(), &complete_results);
+ self.set_restyle_damage(damage);
+ }
+ self.set_css_select_results(complete_results);
+ };
}
for self.each_child |kid| {
diff --git a/src/components/script/dom/element.rs b/src/components/script/dom/element.rs
index 7c2a9d13f13..04977ae7931 100644
--- a/src/components/script/dom/element.rs
+++ b/src/components/script/dom/element.rs
@@ -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,
}
}
diff --git a/src/components/script/html/hubbub_html_parser.rs b/src/components/script/html/hubbub_html_parser.rs
index c24c87c5038..cd2b5ee028c 100644
--- a/src/components/script/html/hubbub_html_parser.rs
+++ b/src/components/script/html/hubbub_html_parser.rs
@@ -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)
_ => {}
}
diff --git a/src/support/css/rust-css b/src/support/css/rust-css
-Subproject 55884aac7f9780a7915936169565101cbf4f172
+Subproject 789c7a43e28629ea0b568ce7d9a7ca8a0a975d3
diff --git a/src/support/netsurfcss/rust-netsurfcss b/src/support/netsurfcss/rust-netsurfcss
-Subproject e6866a5684b403350768da0fcba11b21e3d6097
+Subproject d72f06f51220083111487940f19ad36d6ae17bd