mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
auto merge of #730 : metajack/servo/style_setter, r=metajack,me
Rebasing to land #719.
This commit is contained in:
commit
d1bee3fe3d
5 changed files with 29 additions and 15 deletions
|
@ -105,6 +105,13 @@ impl DOMString {
|
|||
null_string => ~""
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_ref<'a>(&'a self) -> &'a str {
|
||||
match *self {
|
||||
str(ref s) => s.as_slice(),
|
||||
null_string => &'a "",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct rust_box<T> {
|
||||
|
|
|
@ -47,6 +47,7 @@ use js::jsapi::{JSContext, JSObject};
|
|||
use std::cell::Cell;
|
||||
use std::comm;
|
||||
use std::str::eq_slice;
|
||||
use extra::net::url;
|
||||
|
||||
pub struct Element {
|
||||
parent: Node<ScriptView>,
|
||||
|
@ -262,8 +263,7 @@ impl<'self> Element {
|
|||
|
||||
pub fn set_attr(&mut self, name: &DOMString, value: &DOMString) {
|
||||
let name = name.to_str();
|
||||
let value = value.to_str();
|
||||
let value_cell = Cell::new(value);
|
||||
let value_cell = Cell::new(value.to_str());
|
||||
let mut found = false;
|
||||
for self.attrs.mut_iter().advance |attr| {
|
||||
if eq_slice(attr.name, name) {
|
||||
|
@ -276,6 +276,13 @@ impl<'self> Element {
|
|||
self.attrs.push(Attr::new(name.to_str(), value_cell.take().clone()));
|
||||
}
|
||||
|
||||
if "style" == name {
|
||||
self.style_attribute = Some(
|
||||
Stylesheet::from_attribute(
|
||||
url::from_str("http://www.example.com/").unwrap(),
|
||||
value.get_ref()));
|
||||
}
|
||||
|
||||
match self.parent.owner_doc {
|
||||
Some(owner) => do owner.with_base |owner| { owner.content_changed() },
|
||||
None => {}
|
||||
|
@ -304,15 +311,19 @@ impl Element {
|
|||
pub fn SetId(&self, _id: &DOMString) {
|
||||
}
|
||||
|
||||
pub fn GetAttribute(&self, _name: &DOMString) -> DOMString {
|
||||
null_string
|
||||
pub fn GetAttribute(&self, name: &DOMString) -> DOMString {
|
||||
match self.get_attr(name.get_ref()) {
|
||||
Some(val) => str(val.to_owned()),
|
||||
None => null_string
|
||||
}
|
||||
}
|
||||
|
||||
pub fn GetAttributeNS(&self, _namespace: &DOMString, _localname: &DOMString) -> DOMString {
|
||||
null_string
|
||||
}
|
||||
|
||||
pub fn SetAttribute(&self, _name: &DOMString, _value: &DOMString, _rv: &mut ErrorResult) {
|
||||
pub fn SetAttribute(&mut self, name: &DOMString, value: &DOMString, _rv: &mut ErrorResult) {
|
||||
self.set_attr(name, value);
|
||||
}
|
||||
|
||||
pub fn SetAttributeNS(&self, _namespace: &DOMString, _localname: &DOMString, _value: &DOMString, _rv: &mut ErrorResult) {
|
||||
|
|
|
@ -42,10 +42,11 @@ use dom::htmltablesectionelement::HTMLTableSectionElement;
|
|||
use dom::htmltextareaelement::HTMLTextAreaElement;
|
||||
use dom::htmltitleelement::HTMLTitleElement;
|
||||
use dom::htmlulistelement::HTMLUListElement;
|
||||
use dom::element::{Element, Attr};
|
||||
use dom::element::Element;
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::node::{AbstractNode, Comment, Doctype, ElementNodeTypeId, Node, ScriptView};
|
||||
use dom::node::{Text};
|
||||
use dom::bindings::utils::str;
|
||||
use html::cssparse::{InlineProvenance, StylesheetProvenance, UrlProvenance, spawn_css_parser};
|
||||
use js::jsapi::JSContext;
|
||||
use newcss::stylesheet::Stylesheet;
|
||||
|
@ -343,14 +344,7 @@ pub fn parse_html(cx: *JSContext,
|
|||
debug!("-- attach attrs");
|
||||
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));
|
||||
}
|
||||
element.set_attr(&str(attr.name.clone()), &str(attr.value.clone()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -10,5 +10,6 @@
|
|||
</head>
|
||||
<body>
|
||||
<div id="change" class="red">Hello, World!</div>
|
||||
<div id="change" style="color:blue;">Hello, Servo!</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
window.setTimeout(function () {
|
||||
window.document.getElementsByTagName('div')[0].setAttribute('class', 'blue');
|
||||
window.document.getElementsByTagName('div')[1].setAttribute('style', 'color:red;');
|
||||
}, 1000);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue