mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Implement document.compatMode
Spec: http://dom.spec.whatwg.org/#dom-document-compatmode This is a sub-task for #1428.
This commit is contained in:
parent
0dd37d9cd3
commit
56572a2814
6 changed files with 68 additions and 3 deletions
|
@ -22,6 +22,7 @@ use dom::uievent::UIEvent;
|
|||
use dom::window::Window;
|
||||
use dom::htmltitleelement::HTMLTitleElement;
|
||||
use html::hubbub_html_parser::build_element_from_tag;
|
||||
use hubbub::hubbub::{QuirksMode, NoQuirks, LimitedQuirks, FullQuirks};
|
||||
use layout_interface::{DocumentDamageLevel, ContentChangedDocumentDamage};
|
||||
use servo_util::namespace::Null;
|
||||
|
||||
|
@ -91,7 +92,8 @@ pub struct Document {
|
|||
idmap: HashMap<DOMString, AbstractNode>,
|
||||
implementation: Option<@mut DOMImplementation>,
|
||||
content_type: DOMString,
|
||||
url: Url
|
||||
url: Url,
|
||||
quirks_mode: QuirksMode
|
||||
}
|
||||
|
||||
impl Document {
|
||||
|
@ -136,7 +138,9 @@ impl Document {
|
|||
url: match url {
|
||||
None => from_str("about:blank").unwrap(),
|
||||
Some(_url) => _url
|
||||
}
|
||||
},
|
||||
// http://dom.spec.whatwg.org/#concept-document-quirks
|
||||
quirks_mode: NoQuirks
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -191,6 +195,18 @@ impl Document {
|
|||
self.URL()
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-document-compatmode
|
||||
pub fn CompatMode(&self) -> DOMString {
|
||||
match self.quirks_mode {
|
||||
NoQuirks => ~"CSS1Compat",
|
||||
LimitedQuirks | FullQuirks => ~"BackCompat"
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_quirks_mode(&mut self, mode: QuirksMode) {
|
||||
self.quirks_mode = mode;
|
||||
}
|
||||
|
||||
// http://dom.spec.whatwg.org/#dom-document-content_type
|
||||
pub fn ContentType(&self) -> DOMString {
|
||||
self.content_type.clone()
|
||||
|
|
|
@ -28,7 +28,8 @@ interface Document : Node {
|
|||
readonly attribute DOMImplementation implementation;
|
||||
readonly attribute DOMString URL;
|
||||
readonly attribute DOMString documentURI;
|
||||
// readonly attribute DOMString compatMode;
|
||||
// readonly attribute DOMString origin;
|
||||
readonly attribute DOMString compatMode;
|
||||
// readonly attribute DOMString characterSet;
|
||||
readonly attribute DOMString contentType;
|
||||
|
||||
|
|
|
@ -445,6 +445,7 @@ pub fn parse_html(cx: *JSContext,
|
|||
},
|
||||
set_quirks_mode: |_mode| {
|
||||
debug!("set quirks mode");
|
||||
document.mut_document().set_quirks_mode(_mode);
|
||||
},
|
||||
encoding_change: |_encname| {
|
||||
debug!("encoding change");
|
||||
|
|
21
src/test/html/content/test_document_compatMode.html
Normal file
21
src/test/html/content/test_document_compatMode.html
Normal file
|
@ -0,0 +1,21 @@
|
|||
<html>
|
||||
<head>
|
||||
<script src="harness.js"></script>
|
||||
<script>
|
||||
// test1: BackCompat
|
||||
{
|
||||
is(document.compatMode, "BackCompat", "test1-0, BackCompat");
|
||||
}
|
||||
|
||||
// test2: Non-parsed documents
|
||||
{
|
||||
var xmldoc = new Document;
|
||||
is(xmldoc.compatMode, "CSS1Compat", "test2-0, Non-parsed documents");
|
||||
|
||||
var htmldoc = document.implementation.createHTMLDocument("title");
|
||||
is(htmldoc.compatMode, "CSS1Compat", "test2-1, Non-parsed documents");
|
||||
}
|
||||
finish();
|
||||
</script>
|
||||
</head>
|
||||
</html>
|
13
src/test/html/content/test_document_compatMode_loose.html
Normal file
13
src/test/html/content/test_document_compatMode_loose.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<script src="harness.js"></script>
|
||||
<script>
|
||||
// test1: Loose HTML
|
||||
{
|
||||
is(document.compatMode, "BackCompat", "test1-0, Loose HTML");
|
||||
}
|
||||
finish();
|
||||
</script>
|
||||
</head>
|
||||
</html>
|
13
src/test/html/content/test_document_compatMode_strict.html
Normal file
13
src/test/html/content/test_document_compatMode_strict.html
Normal file
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<script src="harness.js"></script>
|
||||
<script>
|
||||
// test1: Strict HTML
|
||||
{
|
||||
is(document.compatMode, "CSS1Compat", "test1-0, Strict HTML");
|
||||
}
|
||||
finish();
|
||||
</script>
|
||||
</head>
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue