mirror of
https://github.com/servo/servo.git
synced 2025-06-21 15:49:04 +01:00
Issue #1071 - Ensure that Documents always have a non-null Window.
This commit is contained in:
parent
c9c9eec3d8
commit
60b6d1bb57
7 changed files with 29 additions and 53 deletions
|
@ -112,7 +112,7 @@ pub enum DocumentType {
|
||||||
pub struct Document {
|
pub struct Document {
|
||||||
priv root: Option<AbstractNode<ScriptView>>,
|
priv root: Option<AbstractNode<ScriptView>>,
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
window: Option<@mut Window>,
|
window: @mut Window,
|
||||||
doctype: DocumentType,
|
doctype: DocumentType,
|
||||||
title: ~str,
|
title: ~str,
|
||||||
idmap: HashMap<~str, AbstractNode<ScriptView>>
|
idmap: HashMap<~str, AbstractNode<ScriptView>>
|
||||||
|
@ -120,7 +120,7 @@ pub struct Document {
|
||||||
|
|
||||||
impl Document {
|
impl Document {
|
||||||
#[fixed_stack_segment]
|
#[fixed_stack_segment]
|
||||||
pub fn new(window: Option<@mut Window>, doctype: DocumentType) -> Document {
|
pub fn new(window: @mut Window, doctype: DocumentType) -> Document {
|
||||||
Document {
|
Document {
|
||||||
root: None,
|
root: None,
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
|
@ -134,7 +134,7 @@ impl Document {
|
||||||
pub fn Constructor(owner: @mut Window) -> Fallible<AbstractDocument> {
|
pub fn Constructor(owner: @mut Window) -> Fallible<AbstractDocument> {
|
||||||
let cx = owner.get_cx();
|
let cx = owner.get_cx();
|
||||||
|
|
||||||
let document = AbstractDocument::as_abstract(cx, @mut Document::new(None, XML));
|
let document = AbstractDocument::as_abstract(cx, @mut Document::new(owner, XML));
|
||||||
|
|
||||||
let root = @HTMLHtmlElement {
|
let root = @HTMLHtmlElement {
|
||||||
htmlelement: HTMLElement::new(HTMLHtmlElementTypeId, ~"html", document)
|
htmlelement: HTMLElement::new(HTMLHtmlElementTypeId, ~"html", document)
|
||||||
|
@ -216,10 +216,7 @@ impl Reflectable for Document {
|
||||||
|
|
||||||
impl BindingObject for Document {
|
impl BindingObject for Document {
|
||||||
fn GetParentObject(&self, _cx: *JSContext) -> Option<@mut Reflectable> {
|
fn GetParentObject(&self, _cx: *JSContext) -> Option<@mut Reflectable> {
|
||||||
match self.window {
|
Some(self.window as @mut Reflectable)
|
||||||
Some(win) => Some(win as @mut Reflectable),
|
|
||||||
None => None
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,11 +246,11 @@ impl Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_cx(&self) -> *JSContext {
|
fn get_cx(&self) -> *JSContext {
|
||||||
self.window.get_ref().get_cx()
|
self.window.get_cx()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_scope_and_cx(&self) -> (*JSObject, *JSContext) {
|
fn get_scope_and_cx(&self) -> (*JSObject, *JSContext) {
|
||||||
let win = self.window.get_ref();
|
let win = self.window;
|
||||||
(win.reflector().get_jsobject(), win.get_cx())
|
(win.reflector().get_jsobject(), win.get_cx())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,15 +515,11 @@ impl Document {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn content_changed(&self) {
|
pub fn content_changed(&self) {
|
||||||
for window in self.window.iter() {
|
self.window.content_changed();
|
||||||
window.content_changed()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wait_until_safe_to_modify_dom(&self) {
|
pub fn wait_until_safe_to_modify_dom(&self) {
|
||||||
for window in self.window.iter() {
|
self.window.wait_until_safe_to_modify_dom();
|
||||||
window.wait_until_safe_to_modify_dom();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn register_nodes_with_id(&mut self, root: &AbstractNode<ScriptView>) {
|
pub fn register_nodes_with_id(&mut self, root: &AbstractNode<ScriptView>) {
|
||||||
|
|
|
@ -43,10 +43,10 @@ impl DOMParser {
|
||||||
let cx = self.owner.get_cx();
|
let cx = self.owner.get_cx();
|
||||||
let document = match ty {
|
let document = match ty {
|
||||||
Text_html => {
|
Text_html => {
|
||||||
HTMLDocument::new(None)
|
HTMLDocument::new(self.owner)
|
||||||
}
|
}
|
||||||
Text_xml => {
|
Text_xml => {
|
||||||
AbstractDocument::as_abstract(cx, @mut Document::new(None, XML))
|
AbstractDocument::as_abstract(cx, @mut Document::new(self.owner, XML))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
fail!("unsupported document type")
|
fail!("unsupported document type")
|
||||||
|
|
|
@ -274,7 +274,7 @@ impl Element {
|
||||||
|
|
||||||
pub fn GetClientRects(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRectList {
|
pub fn GetClientRects(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRectList {
|
||||||
let document = self.node.owner_doc;
|
let document = self.node.owner_doc;
|
||||||
let win = document.with_base(|doc| doc.window).expect("no window");
|
let win = document.with_base(|doc| doc.window);
|
||||||
let node = abstract_self;
|
let node = abstract_self;
|
||||||
assert!(node.is_element());
|
assert!(node.is_element());
|
||||||
let (port, chan) = comm::stream();
|
let (port, chan) = comm::stream();
|
||||||
|
@ -301,7 +301,7 @@ impl Element {
|
||||||
|
|
||||||
pub fn GetBoundingClientRect(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRect {
|
pub fn GetBoundingClientRect(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRect {
|
||||||
let document = self.node.owner_doc;
|
let document = self.node.owner_doc;
|
||||||
let win = document.with_base(|doc| doc.window).expect("no window");
|
let win = document.with_base(|doc| doc.window);
|
||||||
let node = abstract_self;
|
let node = abstract_self;
|
||||||
assert!(node.is_element());
|
assert!(node.is_element());
|
||||||
let (port, chan) = comm::stream();
|
let (port, chan) = comm::stream();
|
||||||
|
|
|
@ -24,12 +24,12 @@ pub struct HTMLDocument {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HTMLDocument {
|
impl HTMLDocument {
|
||||||
pub fn new(window: Option<@mut Window>) -> AbstractDocument {
|
pub fn new(window: @mut Window) -> AbstractDocument {
|
||||||
let doc = @mut HTMLDocument {
|
let doc = @mut HTMLDocument {
|
||||||
parent: Document::new(window, HTML)
|
parent: Document::new(window, HTML)
|
||||||
};
|
};
|
||||||
|
|
||||||
AbstractDocument::as_abstract(window.get_ref().get_cx(), doc)
|
AbstractDocument::as_abstract(window.get_cx(), doc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,13 +44,12 @@ impl HTMLImageElement {
|
||||||
if "src" == name {
|
if "src" == name {
|
||||||
let doc = self.htmlelement.element.node.owner_doc;
|
let doc = self.htmlelement.element.node.owner_doc;
|
||||||
do doc.with_base |doc| {
|
do doc.with_base |doc| {
|
||||||
for window in doc.window.iter() {
|
let window = doc.window;
|
||||||
let url = window.page.url.map(|&(ref url, _)| url.clone());
|
let url = window.page.url.map(|&(ref url, _)| url.clone());
|
||||||
self.update_image(window.image_cache_task.clone(), url);
|
self.update_image(window.image_cache_task.clone(), url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub fn Alt(&self) -> DOMString {
|
pub fn Alt(&self) -> DOMString {
|
||||||
None
|
None
|
||||||
|
@ -100,9 +99,7 @@ impl HTMLImageElement {
|
||||||
|
|
||||||
pub fn Width(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
|
pub fn Width(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
|
||||||
let node = &self.htmlelement.element.node;
|
let node = &self.htmlelement.element.node;
|
||||||
match node.owner_doc.with_base(|doc| doc.window) {
|
let page = node.owner_doc.with_base(|doc| doc.window).page;
|
||||||
Some(win) => {
|
|
||||||
let page = win.page;
|
|
||||||
let (port, chan) = stream();
|
let (port, chan) = stream();
|
||||||
match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
|
match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
|
||||||
ContentBoxResponse(rect) => {
|
ContentBoxResponse(rect) => {
|
||||||
|
@ -110,12 +107,6 @@ impl HTMLImageElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
|
||||||
debug!("no window");
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn SetWidth(&mut self,
|
pub fn SetWidth(&mut self,
|
||||||
abstract_self: AbstractNode<ScriptView>,
|
abstract_self: AbstractNode<ScriptView>,
|
||||||
|
@ -129,9 +120,7 @@ impl HTMLImageElement {
|
||||||
|
|
||||||
pub fn Height(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
|
pub fn Height(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
|
||||||
let node = &self.htmlelement.element.node;
|
let node = &self.htmlelement.element.node;
|
||||||
match node.owner_doc.with_base(|doc| doc.window) {
|
let page = node.owner_doc.with_base(|doc| doc.window).page;
|
||||||
Some(win) => {
|
|
||||||
let page = win.page;
|
|
||||||
let (port, chan) = stream();
|
let (port, chan) = stream();
|
||||||
match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
|
match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
|
||||||
ContentBoxResponse(rect) => {
|
ContentBoxResponse(rect) => {
|
||||||
|
@ -139,12 +128,6 @@ impl HTMLImageElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {
|
|
||||||
debug!("no window");
|
|
||||||
0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn SetHeight(&mut self,
|
pub fn SetHeight(&mut self,
|
||||||
abstract_self: AbstractNode<ScriptView>,
|
abstract_self: AbstractNode<ScriptView>,
|
||||||
|
|
|
@ -664,7 +664,7 @@ impl Node<ScriptView> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_scope_and_cx(&self) -> (*JSObject, *JSContext) {
|
pub fn get_scope_and_cx(&self) -> (*JSObject, *JSContext) {
|
||||||
let win = self.owner_doc.with_base(|doc| doc.window.unwrap());
|
let win = self.owner_doc.with_base(|doc| doc.window);
|
||||||
(win.reflector().get_jsobject(), win.get_cx())
|
(win.reflector().get_jsobject(), win.get_cx())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -717,7 +717,7 @@ impl ScriptTask {
|
||||||
// Parse HTML.
|
// Parse HTML.
|
||||||
//
|
//
|
||||||
// Note: We can parse the next document in parallel with any previous documents.
|
// Note: We can parse the next document in parallel with any previous documents.
|
||||||
let document = HTMLDocument::new(Some(window));
|
let document = HTMLDocument::new(window);
|
||||||
|
|
||||||
let html_parsing_result = hubbub_html_parser::parse_html(cx.ptr,
|
let html_parsing_result = hubbub_html_parser::parse_html(cx.ptr,
|
||||||
document,
|
document,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue