From 4304ee28dceffa8ad66f5b088754705bc2bb3b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Mon, 21 Jan 2019 20:58:52 +0100 Subject: Partial ShadowRoot implementation of DocumentOrShadowRoot --- components/script/dom/macros.rs | 47 ++++++++++++++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 10 deletions(-) (limited to 'components/script/dom/macros.rs') diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index 94a0779732c..c64902d8f94 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -633,16 +633,44 @@ macro_rules! handle_potential_webgl_error { }; } -macro_rules! impl_document_or_shadow_root { +macro_rules! impl_document_or_shadow_root_helpers( () => ( + /// + #[inline] + pub fn browsing_context(&self) -> Option> { + if self.has_browsing_context { + self.window.undiscarded_window_proxy() + } else { + None + } + } + + pub fn nodes_from_point( + &self, + client_point: &Point2D, + reflow_goal: NodesFromPointQueryType, + ) -> Vec { + if !self + .window + .layout_reflow(QueryMsg::NodesFromPointQuery(*client_point, reflow_goal)) + { + return vec![]; + }; + + self.window.layout().nodes_from_point_response() + } + ); +); + +macro_rules! impl_document_or_shadow_root_methods( + ($struct:ident) => ( #[allow(unsafe_code)] // https://drafts.csswg.org/cssom-view/#dom-document-elementfrompoint fn ElementFromPoint(&self, x: Finite, y: Finite) -> Option> { let x = *x as f32; let y = *y as f32; let point = &Point2D::new(x, y); - let window = window_from_node(self); - let viewport = window.window_size().initial_viewport; + let viewport = self.window.window_size().initial_viewport; if self.browsing_context().is_none() { return None; @@ -657,7 +685,7 @@ macro_rules! impl_document_or_shadow_root { .first() { Some(address) => { - let js_runtime = unsafe { JS_GetRuntime(window.get_cx()) }; + let js_runtime = unsafe { JS_GetRuntime(self.window.get_cx()) }; let node = unsafe { node::from_untrusted_node_address(js_runtime, *address) }; let parent_node = node.GetParentNode().unwrap(); let element_ref = node @@ -676,8 +704,7 @@ macro_rules! impl_document_or_shadow_root { let x = *x as f32; let y = *y as f32; let point = &Point2D::new(x, y); - let window = window_from_node(self); - let viewport = window.window_size().initial_viewport; + let viewport = self.window.window_size().initial_viewport; if self.browsing_context().is_none() { return vec![]; @@ -688,7 +715,7 @@ macro_rules! impl_document_or_shadow_root { return vec![]; } - let js_runtime = unsafe { JS_GetRuntime(window.get_cx()) }; + let js_runtime = unsafe { JS_GetRuntime(self.window.get_cx()) }; // Step 1 and Step 3 let nodes = self.nodes_from_point(point, NodesFromPointQueryType::All); @@ -730,7 +757,7 @@ macro_rules! impl_document_or_shadow_root { // https://drafts.csswg.org/cssom/#dom-document-stylesheets fn StyleSheets(&self) -> DomRoot { self.stylesheet_list - .or_init(|| StyleSheetList::new(&self.window, Dom::from_ref(&self))) + .or_init(|| StyleSheetList::new(&self.window, DocumentOrShadowRoot::$struct(Dom::from_ref(self)))) } - ) -} + ); +); -- cgit v1.2.3