mirror of
https://github.com/servo/servo.git
synced 2025-08-04 21:20:23 +01:00
Handle style attributes in element setter instead of html parser
This commit is contained in:
parent
eadda9411b
commit
2ad350531a
4 changed files with 16 additions and 13 deletions
|
@ -47,6 +47,7 @@ use js::jsapi::{JSContext, JSObject};
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::comm;
|
use std::comm;
|
||||||
use std::str::eq_slice;
|
use std::str::eq_slice;
|
||||||
|
use extra::net::url;
|
||||||
|
|
||||||
pub struct Element {
|
pub struct Element {
|
||||||
parent: Node<ScriptView>,
|
parent: Node<ScriptView>,
|
||||||
|
@ -262,8 +263,7 @@ impl<'self> Element {
|
||||||
|
|
||||||
pub fn set_attr(&mut self, name: &DOMString, value: &DOMString) {
|
pub fn set_attr(&mut self, name: &DOMString, value: &DOMString) {
|
||||||
let name = name.to_str();
|
let name = name.to_str();
|
||||||
let value = value.to_str();
|
let value_cell = Cell::new(value.to_str());
|
||||||
let value_cell = Cell::new(value);
|
|
||||||
let mut found = false;
|
let mut found = false;
|
||||||
for self.attrs.mut_iter().advance |attr| {
|
for self.attrs.mut_iter().advance |attr| {
|
||||||
if eq_slice(attr.name, name) {
|
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()));
|
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 {
|
match self.parent.owner_doc {
|
||||||
Some(owner) => do owner.with_base |owner| { owner.content_changed() },
|
Some(owner) => do owner.with_base |owner| { owner.content_changed() },
|
||||||
None => {}
|
None => {}
|
||||||
|
@ -312,7 +319,7 @@ impl Element {
|
||||||
null_string
|
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) {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn SetAttributeNS(&self, _namespace: &DOMString, _localname: &DOMString, _value: &DOMString, _rv: &mut ErrorResult) {
|
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::htmltextareaelement::HTMLTextAreaElement;
|
||||||
use dom::htmltitleelement::HTMLTitleElement;
|
use dom::htmltitleelement::HTMLTitleElement;
|
||||||
use dom::htmlulistelement::HTMLUListElement;
|
use dom::htmlulistelement::HTMLUListElement;
|
||||||
use dom::element::{Element, Attr};
|
use dom::element::Element;
|
||||||
use dom::htmlelement::HTMLElement;
|
use dom::htmlelement::HTMLElement;
|
||||||
use dom::node::{AbstractNode, Comment, Doctype, ElementNodeTypeId, Node, ScriptView};
|
use dom::node::{AbstractNode, Comment, Doctype, ElementNodeTypeId, Node, ScriptView};
|
||||||
use dom::node::{Text};
|
use dom::node::{Text};
|
||||||
|
use dom::bindings::utils::str;
|
||||||
use html::cssparse::{InlineProvenance, StylesheetProvenance, UrlProvenance, spawn_css_parser};
|
use html::cssparse::{InlineProvenance, StylesheetProvenance, UrlProvenance, spawn_css_parser};
|
||||||
use js::jsapi::JSContext;
|
use js::jsapi::JSContext;
|
||||||
use newcss::stylesheet::Stylesheet;
|
use newcss::stylesheet::Stylesheet;
|
||||||
|
@ -343,14 +344,7 @@ pub fn parse_html(cx: *JSContext,
|
||||||
debug!("-- attach attrs");
|
debug!("-- attach attrs");
|
||||||
do node.as_mut_element |element| {
|
do node.as_mut_element |element| {
|
||||||
for tag.attributes.iter().advance |attr| {
|
for tag.attributes.iter().advance |attr| {
|
||||||
element.attrs.push(Attr::new(attr.name.clone(), attr.value.clone()));
|
element.set_attr(&str(attr.name.clone()), &str(attr.value.clone()));
|
||||||
|
|
||||||
if "style" == attr.name {
|
|
||||||
element.style_attribute = Some(
|
|
||||||
Stylesheet::from_attribute(
|
|
||||||
url::from_str("http://www.example.com/").unwrap(),
|
|
||||||
attr.value));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
<script src="color-change-text.js"></script>
|
<script src="color-change-text.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="change" class="red">Hello, World!</div>
|
<div id="change" class="red">Hello, World!</div>
|
||||||
|
<div id="change" style="color:blue;">Hello, Servo!</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
window.setTimeout(function () {
|
window.setTimeout(function () {
|
||||||
window.document.getElementsByTagName('div')[0].setAttribute('class', 'blue');
|
window.document.getElementsByTagName('div')[0].setAttribute('class', 'blue');
|
||||||
|
window.document.getElementsByTagName('div')[1].setAttribute('style', 'color:red;');
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue