mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Merge pull request #2692 from Martiusweb/style_is_in_doc
HTMLStyleElement only applies CSS in the document; r=Ms2ger
This commit is contained in:
commit
1a349369f1
3 changed files with 60 additions and 1 deletions
|
@ -9,7 +9,7 @@ use dom::document::Document;
|
|||
use dom::element::HTMLStyleElementTypeId;
|
||||
use dom::eventtarget::{EventTarget, NodeTargetTypeId};
|
||||
use dom::htmlelement::HTMLElement;
|
||||
use dom::node::{Node, NodeMethods, ElementNodeTypeId, window_from_node};
|
||||
use dom::node::{Node, NodeMethods, NodeHelpers, ElementNodeTypeId, window_from_node};
|
||||
use dom::virtualmethods::VirtualMethods;
|
||||
use html::cssparse::parse_inline_css;
|
||||
use layout_interface::{AddStylesheetMsg, LayoutChan};
|
||||
|
@ -49,6 +49,11 @@ pub trait StyleElementHelpers {
|
|||
impl<'a> StyleElementHelpers for JSRef<'a, HTMLStyleElement> {
|
||||
fn parse_own_css(&self) {
|
||||
let node: &JSRef<Node> = NodeCast::from_ref(self);
|
||||
|
||||
if !node.is_in_doc() {
|
||||
return;
|
||||
}
|
||||
|
||||
let win = window_from_node(node).root();
|
||||
let url = win.deref().page().get_url();
|
||||
|
||||
|
@ -72,4 +77,12 @@ impl<'a> VirtualMethods for JSRef<'a, HTMLStyleElement> {
|
|||
}
|
||||
self.parse_own_css();
|
||||
}
|
||||
|
||||
fn bind_to_tree(&self) {
|
||||
match self.super_type() {
|
||||
Some(ref s) => s.bind_to_tree(),
|
||||
_ => ()
|
||||
}
|
||||
self.parse_own_css();
|
||||
}
|
||||
}
|
||||
|
|
28
src/test/ref/style_is_in_doc.html
Normal file
28
src/test/ref/style_is_in_doc.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<style>
|
||||
.from_html { color: blue; }
|
||||
.is_not_in_doc { color: grey; }
|
||||
</style>
|
||||
<script type="text/javascript">
|
||||
var append_later = document.createElement('style');
|
||||
append_later.textContent = ".append_later { color: green; }";
|
||||
document.head.appendChild(append_later);
|
||||
|
||||
var text_set_later = document.createElement('style');
|
||||
document.head.appendChild(text_set_later);
|
||||
text_set_later.textContent = ".text_set_later { color: yellow; }";
|
||||
|
||||
var is_not_in_doc = document.createElement('style');
|
||||
is_not_in_doc = ".is_not_in_doc { color: red; }";
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<p class="from_html">Style from html element</p>
|
||||
<p class="append_later">Style from an element added in javascript</p>
|
||||
<p class="text_set_later">Style from an element with content set in javascript</p>
|
||||
<p class="is_not_in_doc">Style that is never in the document</p>
|
||||
</body>
|
||||
</html>
|
18
src/test/ref/style_is_in_doc_ref.html
Normal file
18
src/test/ref/style_is_in_doc_ref.html
Normal file
|
@ -0,0 +1,18 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<style>
|
||||
.from_html { color: blue; }
|
||||
.append_later { color: green; }
|
||||
.text_set_later { color: yellow; }
|
||||
.is_not_in_doc { color: grey; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<p class="from_html">Style from html element</p>
|
||||
<p class="append_later">Style from an element added in javascript</p>
|
||||
<p class="text_set_later">Style from an element with content set in javascript</p>
|
||||
<p class="is_not_in_doc">Style that is never in the document</p>
|
||||
</body>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue