From a841c713d653f57256e5b795197920c7ee6834e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Wed, 20 Feb 2019 16:30:38 +0100 Subject: [PATCH] Minor layout thread cleanups: - lifetime naming - unrequired reference removal - containing_shadow_host getter simplification - use stylist.device getter where possible --- components/layout_thread/dom_wrapper.rs | 20 ++++++++------------ components/layout_thread/lib.rs | 7 +++++-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/components/layout_thread/dom_wrapper.rs b/components/layout_thread/dom_wrapper.rs index 390dba09f06..7ea68e6e3a2 100644 --- a/components/layout_thread/dom_wrapper.rs +++ b/components/layout_thread/dom_wrapper.rs @@ -175,20 +175,20 @@ pub struct ServoShadowRoot<'a> { chain: PhantomData<&'a ()>, } -impl<'sr> Debug for ServoShadowRoot<'sr> { +impl<'lr> Debug for ServoShadowRoot<'lr> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.as_node().fmt(f) } } -impl<'sr> TShadowRoot for ServoShadowRoot<'sr> { - type ConcreteNode = ServoLayoutNode<'sr>; +impl<'lr> TShadowRoot for ServoShadowRoot<'lr> { + type ConcreteNode = ServoLayoutNode<'lr>; fn as_node(&self) -> Self::ConcreteNode { ServoLayoutNode::from_layout_js(self.shadow_root.upcast()) } - fn host(&self) -> ServoLayoutElement<'sr> { + fn host(&self) -> ServoLayoutElement<'lr> { ServoLayoutElement::from_layout_js(unsafe { self.shadow_root.get_host_for_layout() }) } @@ -205,8 +205,8 @@ impl<'sr> TShadowRoot for ServoShadowRoot<'sr> { } } -impl<'sr> ServoShadowRoot<'sr> { - fn from_layout_js(shadow_root: LayoutDom) -> ServoShadowRoot<'sr> { +impl<'lr> ServoShadowRoot<'lr> { + fn from_layout_js(shadow_root: LayoutDom) -> ServoShadowRoot<'lr> { ServoShadowRoot { shadow_root, chain: PhantomData, @@ -220,8 +220,7 @@ impl<'sr> ServoShadowRoot<'sr> { guard: &SharedRwLockReadGuard, ) { unsafe { - &self - .shadow_root + self.shadow_root .flush_stylesheets::(device, quirks_mode, guard) }; } @@ -791,10 +790,7 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> { } fn containing_shadow_host(&self) -> Option { - match self.containing_shadow() { - Some(shadow) => Some(shadow.host()), - None => None, - } + self.containing_shadow().map(|s| s.host()) } fn prev_sibling_element(&self) -> Option> { diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 8c46fb90720..3ed2624d2d3 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -1351,10 +1351,13 @@ impl LayoutThread { document.shadow_roots().len() ); - let device = Device::new(MediaType::screen(), initial_viewport, device_pixel_ratio); // Flush shadow roots stylesheets if dirty. for shadow_root in document.shadow_roots() { - shadow_root.flush_stylesheets(&device, document.quirks_mode(), guards.author.clone()); + shadow_root.flush_stylesheets( + &self.stylist.device(), + document.quirks_mode(), + guards.author.clone(), + ); } let restyles = document.drain_pending_restyles();