From af4b371107362fd1a2d7d69848a389aeb82017df Mon Sep 17 00:00:00 2001 From: Keith Yeung Date: Thu, 5 Feb 2015 19:02:04 +0800 Subject: Moved Location object from Window to Document --- components/script/dom/document.rs | 6 ++++-- components/script/dom/window.rs | 9 ++++++--- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'components/script/dom') diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 3734527bc09..7a5b9be5a7d 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -9,7 +9,6 @@ use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, Documen use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::Bindings::NodeFilterBinding::NodeFilter; -use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::codegen::InheritTypes::{DocumentDerived, EventCast, HTMLElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLHeadElementCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast, NodeCast}; @@ -86,6 +85,7 @@ pub struct Document { window: JS, idmap: DOMRefCell>>>, implementation: MutNullableJS, + location: MutNullableJS, content_type: DOMString, last_modified: DOMRefCell>, encoding_name: DOMRefCell, @@ -425,6 +425,7 @@ impl Document { window: JS::from_rooted(window), idmap: DOMRefCell::new(HashMap::new()), implementation: Default::default(), + location: Default::default(), content_type: match content_type { Some(string) => string.clone(), None => match is_html_document { @@ -976,7 +977,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { fn Location(self) -> Temporary { let window = self.window.root(); - window.r().Location() + let window = window.r(); + self.location.or_init(|| Location::new(window, window.page_clone())) } // http://dom.spec.whatwg.org/#dom-parentnode-children diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index d1d76cfaa4e..7ac5ebbc5b9 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -7,6 +7,7 @@ use dom::bindings::codegen::Bindings::EventHandlerBinding::{OnErrorEventHandlerN use dom::bindings::codegen::Bindings::FunctionBinding::Function; use dom::bindings::codegen::Bindings::WindowBinding; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; +use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::InheritTypes::EventTargetCast; use dom::bindings::global::global_object_for_js_object; use dom::bindings::error::Fallible; @@ -57,7 +58,6 @@ pub struct Window { script_chan: Box, control_chan: ScriptControlChan, console: MutNullableJS, - location: MutNullableJS, navigator: MutNullableJS, image_cache_task: ImageCacheTask, compositor: DOMRefCell>, @@ -101,6 +101,10 @@ impl Window { &*self.page } + pub fn page_clone(&self) -> Rc { + self.page.clone() + } + pub fn get_url(&self) -> Url { self.page().get_url() } @@ -200,7 +204,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> { } fn Location(self) -> Temporary { - self.location.or_init(|| Location::new(self, self.page.clone())) + self.Document().root().r().Location() } fn SessionStorage(self) -> Temporary { @@ -401,7 +405,6 @@ impl Window { console: Default::default(), compositor: DOMRefCell::new(compositor), page: page, - location: Default::default(), navigator: Default::default(), image_cache_task: image_cache_task, browser_context: DOMRefCell::new(None), -- cgit v1.2.3