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 {
|
||||
priv root: Option<AbstractNode<ScriptView>>,
|
||||
reflector_: Reflector,
|
||||
window: Option<@mut Window>,
|
||||
window: @mut Window,
|
||||
doctype: DocumentType,
|
||||
title: ~str,
|
||||
idmap: HashMap<~str, AbstractNode<ScriptView>>
|
||||
|
@ -120,7 +120,7 @@ pub struct Document {
|
|||
|
||||
impl Document {
|
||||
#[fixed_stack_segment]
|
||||
pub fn new(window: Option<@mut Window>, doctype: DocumentType) -> Document {
|
||||
pub fn new(window: @mut Window, doctype: DocumentType) -> Document {
|
||||
Document {
|
||||
root: None,
|
||||
reflector_: Reflector::new(),
|
||||
|
@ -134,7 +134,7 @@ impl Document {
|
|||
pub fn Constructor(owner: @mut Window) -> Fallible<AbstractDocument> {
|
||||
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 {
|
||||
htmlelement: HTMLElement::new(HTMLHtmlElementTypeId, ~"html", document)
|
||||
|
@ -216,10 +216,7 @@ impl Reflectable for Document {
|
|||
|
||||
impl BindingObject for Document {
|
||||
fn GetParentObject(&self, _cx: *JSContext) -> Option<@mut Reflectable> {
|
||||
match self.window {
|
||||
Some(win) => Some(win as @mut Reflectable),
|
||||
None => None
|
||||
}
|
||||
Some(self.window as @mut Reflectable)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -249,11 +246,11 @@ impl Document {
|
|||
}
|
||||
|
||||
fn get_cx(&self) -> *JSContext {
|
||||
self.window.get_ref().get_cx()
|
||||
self.window.get_cx()
|
||||
}
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
|
@ -518,15 +515,11 @@ impl Document {
|
|||
}
|
||||
|
||||
pub fn content_changed(&self) {
|
||||
for window in self.window.iter() {
|
||||
window.content_changed()
|
||||
}
|
||||
self.window.content_changed();
|
||||
}
|
||||
|
||||
pub fn wait_until_safe_to_modify_dom(&self) {
|
||||
for window in self.window.iter() {
|
||||
window.wait_until_safe_to_modify_dom();
|
||||
}
|
||||
self.window.wait_until_safe_to_modify_dom();
|
||||
}
|
||||
|
||||
pub fn register_nodes_with_id(&mut self, root: &AbstractNode<ScriptView>) {
|
||||
|
|
|
@ -43,10 +43,10 @@ impl DOMParser {
|
|||
let cx = self.owner.get_cx();
|
||||
let document = match ty {
|
||||
Text_html => {
|
||||
HTMLDocument::new(None)
|
||||
HTMLDocument::new(self.owner)
|
||||
}
|
||||
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")
|
||||
|
|
|
@ -274,7 +274,7 @@ impl Element {
|
|||
|
||||
pub fn GetClientRects(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRectList {
|
||||
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;
|
||||
assert!(node.is_element());
|
||||
let (port, chan) = comm::stream();
|
||||
|
@ -301,7 +301,7 @@ impl Element {
|
|||
|
||||
pub fn GetBoundingClientRect(&self, abstract_self: AbstractNode<ScriptView>) -> @mut ClientRect {
|
||||
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;
|
||||
assert!(node.is_element());
|
||||
let (port, chan) = comm::stream();
|
||||
|
|
|
@ -24,12 +24,12 @@ pub struct HTMLDocument {
|
|||
}
|
||||
|
||||
impl HTMLDocument {
|
||||
pub fn new(window: Option<@mut Window>) -> AbstractDocument {
|
||||
pub fn new(window: @mut Window) -> AbstractDocument {
|
||||
let doc = @mut HTMLDocument {
|
||||
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 {
|
||||
let doc = self.htmlelement.element.node.owner_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());
|
||||
self.update_image(window.image_cache_task.clone(), url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn Alt(&self) -> DOMString {
|
||||
None
|
||||
|
@ -100,9 +99,7 @@ impl HTMLImageElement {
|
|||
|
||||
pub fn Width(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
|
||||
let node = &self.htmlelement.element.node;
|
||||
match node.owner_doc.with_base(|doc| doc.window) {
|
||||
Some(win) => {
|
||||
let page = win.page;
|
||||
let page = node.owner_doc.with_base(|doc| doc.window).page;
|
||||
let (port, chan) = stream();
|
||||
match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
|
||||
ContentBoxResponse(rect) => {
|
||||
|
@ -110,12 +107,6 @@ impl HTMLImageElement {
|
|||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
debug!("no window");
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn SetWidth(&mut self,
|
||||
abstract_self: AbstractNode<ScriptView>,
|
||||
|
@ -129,9 +120,7 @@ impl HTMLImageElement {
|
|||
|
||||
pub fn Height(&self, abstract_self: AbstractNode<ScriptView>) -> u32 {
|
||||
let node = &self.htmlelement.element.node;
|
||||
match node.owner_doc.with_base(|doc| doc.window) {
|
||||
Some(win) => {
|
||||
let page = win.page;
|
||||
let page = node.owner_doc.with_base(|doc| doc.window).page;
|
||||
let (port, chan) = stream();
|
||||
match page.query_layout(ContentBoxQuery(abstract_self, chan), port) {
|
||||
ContentBoxResponse(rect) => {
|
||||
|
@ -139,12 +128,6 @@ impl HTMLImageElement {
|
|||
}
|
||||
}
|
||||
}
|
||||
None => {
|
||||
debug!("no window");
|
||||
0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn SetHeight(&mut self,
|
||||
abstract_self: AbstractNode<ScriptView>,
|
||||
|
|
|
@ -664,7 +664,7 @@ impl Node<ScriptView> {
|
|||
}
|
||||
|
||||
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())
|
||||
}
|
||||
|
||||
|
|
|
@ -717,7 +717,7 @@ impl ScriptTask {
|
|||
// Parse HTML.
|
||||
//
|
||||
// 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,
|
||||
document,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue