From 704505617399f040b0ca10eb1d06dde2811937c0 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 23 Nov 2015 10:42:04 -0500 Subject: [PATCH 1/2] Make it possible for XMLDocuments to have a browsing context. --- components/script/dom/domimplementation.rs | 1 + components/script/dom/xmldocument.rs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/components/script/dom/domimplementation.rs b/components/script/dom/domimplementation.rs index 01cd8acb7df..37b75688c2b 100644 --- a/components/script/dom/domimplementation.rs +++ b/components/script/dom/domimplementation.rs @@ -71,6 +71,7 @@ impl DOMImplementationMethods for DOMImplementation { // Step 1. let doc = XMLDocument::new(win, + None, None, IsHTMLDocument::NonHTMLDocument, None, diff --git a/components/script/dom/xmldocument.rs b/components/script/dom/xmldocument.rs index 200480d4fc0..fc04c418867 100644 --- a/components/script/dom/xmldocument.rs +++ b/components/script/dom/xmldocument.rs @@ -11,6 +11,7 @@ use dom::bindings::global::GlobalRef; use dom::bindings::inheritance::Castable; use dom::bindings::js::{Root, RootedReference}; use dom::bindings::reflector::{Reflectable, reflect_dom_object}; +use dom::browsingcontext::BrowsingContext; use dom::document::{Document, DocumentSource, IsHTMLDocument}; use dom::location::Location; use dom::node::Node; @@ -27,6 +28,7 @@ pub struct XMLDocument { impl XMLDocument { fn new_inherited(window: &Window, + browsing_context: Option<&BrowsingContext>, url: Option, is_html_document: IsHTMLDocument, content_type: Option, @@ -35,7 +37,7 @@ impl XMLDocument { doc_loader: DocumentLoader) -> XMLDocument { XMLDocument { document: Document::new_inherited(window, - None, + browsing_context, url, is_html_document, content_type, @@ -46,6 +48,7 @@ impl XMLDocument { } pub fn new(window: &Window, + browsing_context: Option<&BrowsingContext>, url: Option, doctype: IsHTMLDocument, content_type: Option, @@ -55,6 +58,7 @@ impl XMLDocument { -> Root { let doc = reflect_dom_object( box XMLDocument::new_inherited(window, + browsing_context, url, doctype, content_type, @@ -77,6 +81,7 @@ impl XMLDocument { let docloader = DocumentLoader::new(&*doc.loader()); Ok(XMLDocument::new(win, + None, None, IsHTMLDocument::NonHTMLDocument, None, From f5b5079e2a01113492e76da61d0bf27488d8a6f4 Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Mon, 23 Nov 2015 10:42:04 -0500 Subject: [PATCH 2/2] Use the browsing context from the document where appropriate. This should not change behaviour. --- components/script/dom/document.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 9fdff62aabb..7a1ce36e5e4 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -314,8 +314,10 @@ impl Document { // https://html.spec.whatwg.org/multipage/#fully-active pub fn is_fully_active(&self) -> bool { - let browsing_context = self.window.browsing_context(); - let browsing_context = browsing_context.as_ref().unwrap(); + let browsing_context = match self.browsing_context() { + Some(browsing_context) => browsing_context, + None => return false, + }; let active_document = browsing_context.active_document(); if self != &*active_document { @@ -1766,17 +1768,12 @@ impl DocumentMethods for Document { // https://html.spec.whatwg.org/multipage/#dom-document-hasfocus fn HasFocus(&self) -> bool { - // Step 1. - let target = self; - let browsing_context = self.window.browsing_context(); - let browsing_context = browsing_context.as_ref(); - - match browsing_context { + match self.browsing_context() { Some(browsing_context) => { // Step 2. let candidate = browsing_context.active_document(); // Step 3. - if &*candidate == target { + if &*candidate == self { true } else { false //TODO Step 4.