From c28d616253de4be4828056135b374d51a7e3650b Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 2 Jun 2016 20:50:55 -0500 Subject: [PATCH] servo: Merge #11537 - compositing: Don't translate points to layer space when using WebRender (from pcwalton:webrender-remove-layer-space-translation); r=glennw This makes mouse events take the same code path, regardless of whether WebRender is in use or not. This approach enables accurate display-list-based hit testing when WebRender is in use. Closes #11108. r? @glennw Source-Repo: https://github.com/servo/servo Source-Revision: 77e6ea95873c1fc06ea6e19fa20c727b9ca808a9 --- servo/components/compositing/compositor.rs | 48 ++++++++++------------ 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/servo/components/compositing/compositor.rs b/servo/components/compositing/compositor.rs index f00cb496eb1e..fb471ab90f9f 100644 --- a/servo/components/compositing/compositor.rs +++ b/servo/components/compositing/compositor.rs @@ -1387,31 +1387,27 @@ impl IOCompositor { MouseWindowEvent::MouseUp(_, p) => p, }; - if let Some(ref webrender_api) = self.webrender_api { + if self.webrender_api.is_some() { let root_pipeline_id = match self.get_root_pipeline_id() { Some(root_pipeline_id) => root_pipeline_id, None => return, }; - if self.pipeline(root_pipeline_id).is_none() { - return; - } - let (translated_point, translated_pipeline_id) = - webrender_api.translate_point_to_layer_space(&point.to_untyped()); - let event_to_send = match mouse_window_event { - MouseWindowEvent::Click(button, _) => { - MouseButtonEvent(MouseEventType::Click, button, translated_point) - } - MouseWindowEvent::MouseDown(button, _) => { - MouseButtonEvent(MouseEventType::MouseDown, button, translated_point) - } - MouseWindowEvent::MouseUp(button, _) => { - MouseButtonEvent(MouseEventType::MouseUp, button, translated_point) - } - }; - let translated_pipeline_id = translated_pipeline_id.from_webrender(); - let msg = ConstellationControlMsg::SendEvent(translated_pipeline_id, event_to_send); - if let Some(pipeline) = self.pipeline(translated_pipeline_id) { + if let Some(pipeline) = self.pipeline(root_pipeline_id) { + let dppx = self.page_zoom * self.device_pixels_per_screen_px(); + let translated_point = (point / dppx).to_untyped(); + let event_to_send = match mouse_window_event { + MouseWindowEvent::Click(button, _) => { + MouseButtonEvent(MouseEventType::Click, button, translated_point) + } + MouseWindowEvent::MouseDown(button, _) => { + MouseButtonEvent(MouseEventType::MouseDown, button, translated_point) + } + MouseWindowEvent::MouseUp(button, _) => { + MouseButtonEvent(MouseEventType::MouseUp, button, translated_point) + } + }; + let msg = ConstellationControlMsg::SendEvent(root_pipeline_id, event_to_send); if let Err(e) = pipeline.script_chan.send(msg) { warn!("Sending control event to script failed ({}).", e); } @@ -1431,7 +1427,7 @@ impl IOCompositor { return } - if let Some(ref webrender_api) = self.webrender_api { + if self.webrender_api.is_some() { let root_pipeline_id = match self.get_root_pipeline_id() { Some(root_pipeline_id) => root_pipeline_id, None => return, @@ -1440,12 +1436,10 @@ impl IOCompositor { return; } - let (translated_point, translated_pipeline_id) = - webrender_api.translate_point_to_layer_space(&cursor.to_untyped()); - let translated_pipeline_id = translated_pipeline_id.from_webrender(); - let event_to_send = MouseMoveEvent(Some(translated_point)); - let msg = ConstellationControlMsg::SendEvent(translated_pipeline_id, event_to_send); - if let Some(pipeline) = self.pipeline(translated_pipeline_id) { + let dppx = self.page_zoom * self.device_pixels_per_screen_px(); + let event_to_send = MouseMoveEvent(Some((cursor / dppx).to_untyped())); + let msg = ConstellationControlMsg::SendEvent(root_pipeline_id, event_to_send); + if let Some(pipeline) = self.pipeline(root_pipeline_id) { if let Err(e) = pipeline.script_chan.send(msg) { warn!("Sending mouse control event to script failed ({}).", e); }