Minor layout thread cleanups:

- lifetime naming
- unrequired reference removal
- containing_shadow_host getter simplification
- use stylist.device getter where possible
This commit is contained in:
Fernando Jiménez Moreno 2019-02-20 16:30:38 +01:00
parent 00178aff4d
commit a841c713d6
2 changed files with 13 additions and 14 deletions

View file

@ -175,20 +175,20 @@ pub struct ServoShadowRoot<'a> {
chain: PhantomData<&'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 { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.as_node().fmt(f) self.as_node().fmt(f)
} }
} }
impl<'sr> TShadowRoot for ServoShadowRoot<'sr> { impl<'lr> TShadowRoot for ServoShadowRoot<'lr> {
type ConcreteNode = ServoLayoutNode<'sr>; type ConcreteNode = ServoLayoutNode<'lr>;
fn as_node(&self) -> Self::ConcreteNode { fn as_node(&self) -> Self::ConcreteNode {
ServoLayoutNode::from_layout_js(self.shadow_root.upcast()) 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() }) 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> { impl<'lr> ServoShadowRoot<'lr> {
fn from_layout_js(shadow_root: LayoutDom<ShadowRoot>) -> ServoShadowRoot<'sr> { fn from_layout_js(shadow_root: LayoutDom<ShadowRoot>) -> ServoShadowRoot<'lr> {
ServoShadowRoot { ServoShadowRoot {
shadow_root, shadow_root,
chain: PhantomData, chain: PhantomData,
@ -220,8 +220,7 @@ impl<'sr> ServoShadowRoot<'sr> {
guard: &SharedRwLockReadGuard, guard: &SharedRwLockReadGuard,
) { ) {
unsafe { unsafe {
&self self.shadow_root
.shadow_root
.flush_stylesheets::<ServoLayoutElement>(device, quirks_mode, guard) .flush_stylesheets::<ServoLayoutElement>(device, quirks_mode, guard)
}; };
} }
@ -791,10 +790,7 @@ impl<'le> ::selectors::Element for ServoLayoutElement<'le> {
} }
fn containing_shadow_host(&self) -> Option<Self> { fn containing_shadow_host(&self) -> Option<Self> {
match self.containing_shadow() { self.containing_shadow().map(|s| s.host())
Some(shadow) => Some(shadow.host()),
None => None,
}
} }
fn prev_sibling_element(&self) -> Option<ServoLayoutElement<'le>> { fn prev_sibling_element(&self) -> Option<ServoLayoutElement<'le>> {

View file

@ -1351,10 +1351,13 @@ impl LayoutThread {
document.shadow_roots().len() document.shadow_roots().len()
); );
let device = Device::new(MediaType::screen(), initial_viewport, device_pixel_ratio);
// Flush shadow roots stylesheets if dirty. // Flush shadow roots stylesheets if dirty.
for shadow_root in document.shadow_roots() { 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(); let restyles = document.drain_pending_restyles();