diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2015-12-04 02:54:22 +0530 |
---|---|---|
committer | bors-servo <lbergstrom+bors@mozilla.com> | 2015-12-04 02:54:22 +0530 |
commit | bc62b5aadb62267582fbd65daa28438ce6c6ac9c (patch) | |
tree | 535a0f8a529fe0f76ee5b6e852a317b0f0d36203 /components | |
parent | 5ee6fe120d43506e263cb4482b3a468d967a8386 (diff) | |
parent | 9551363bfba695b17c55cc551b87a6c0d16eb6a0 (diff) | |
download | servo-bc62b5aadb62267582fbd65daa28438ce6c6ac9c.tar.gz servo-bc62b5aadb62267582fbd65daa28438ce6c6ac9c.zip |
Auto merge of #8785 - mbrubeck:fixed-hit-test, r=pcwalton
Add slow path for hit testing of iframe behind positioned content layer
Fixes browser.html blocker #8759. r? @pcwalton
This adds a slow path for cases where the compositor's layer-based hit testing is incorrect. If the script task discovers that a mouse event should have been dispatched to an iframe, it bounces the event back to the constellation to be forwarded to the correct pipeline.
This isn't terribly slow (on the slow path, it adds one extra round-trip message between script and constellation), but if we want to optimize this better we could instead replace the compositor's layer hit testing with display list hit testing in the paint task. This would be a more complicated change that I think we should save for a follow-up.
This only fixes mouse input for now. A basically-identical change will be needed for touch-screen input, whether we stick with this approach or switch to the paint task.
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8785)
<!-- Reviewable:end -->
Diffstat (limited to 'components')
-rw-r--r-- | components/compositing/compositor.rs | 4 | ||||
-rw-r--r-- | components/compositing/compositor_layer.rs | 10 | ||||
-rw-r--r-- | components/compositing/constellation.rs | 13 | ||||
-rw-r--r-- | components/compositing/windowing.rs | 5 | ||||
-rw-r--r-- | components/msg/constellation_msg.rs | 23 | ||||
-rw-r--r-- | components/script/dom/document.rs | 51 | ||||
-rw-r--r-- | components/script/dom/htmliframeelement.rs | 5 | ||||
-rw-r--r-- | components/script/script_task.rs | 25 | ||||
-rw-r--r-- | components/script_traits/lib.rs | 20 |
9 files changed, 97 insertions, 59 deletions
diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index e61dff31d47..3e259a7b35a 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -30,13 +30,13 @@ use msg::compositor_msg::{Epoch, EventResult, FrameTreeId, LayerId, LayerKind}; use msg::compositor_msg::{LayerProperties, ScrollPolicy}; use msg::constellation_msg::CompositorMsg as ConstellationMsg; use msg::constellation_msg::{AnimationState, Image, PixelFormat}; -use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData}; +use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData, MouseButton}; use msg::constellation_msg::{NavigationDirection, PipelineId, WindowSizeData}; use pipeline::CompositionPipeline; use profile_traits::mem::{self, ReportKind, Reporter, ReporterRequest}; use profile_traits::time::{self, ProfilerCategory, profile}; use script_traits::CompositorEvent::{MouseMoveEvent, TouchEvent}; -use script_traits::{ConstellationControlMsg, LayoutControlMsg, MouseButton}; +use script_traits::{ConstellationControlMsg, LayoutControlMsg}; use script_traits::{TouchEventType, TouchId}; use scrolling::ScrollingTimerProxy; use std::collections::hash_map::Entry::{Occupied, Vacant}; diff --git a/components/compositing/compositor_layer.rs b/components/compositing/compositor_layer.rs index ceb034c83bd..27308adddbc 100644 --- a/components/compositing/compositor_layer.rs +++ b/components/compositing/compositor_layer.rs @@ -12,9 +12,9 @@ use layers::color::Color; use layers::geometry::LayerPixel; use layers::layers::{Layer, LayerBufferSet}; use msg::compositor_msg::{Epoch, LayerId, LayerProperties, ScrollPolicy}; -use msg::constellation_msg::PipelineId; +use msg::constellation_msg::{MouseEventType, PipelineId}; use script_traits::CompositorEvent; -use script_traits::CompositorEvent::{ClickEvent, MouseDownEvent, MouseMoveEvent, MouseUpEvent}; +use script_traits::CompositorEvent::{MouseButtonEvent, MouseMoveEvent}; use script_traits::ConstellationControlMsg; use std::rc::Rc; use windowing::{MouseWindowEvent, WindowMethods}; @@ -372,11 +372,11 @@ impl CompositorLayer for Layer<CompositorData> { let event_point = cursor.to_untyped(); let message = match event { MouseWindowEvent::Click(button, _) => - ClickEvent(button, event_point), + MouseButtonEvent(MouseEventType::Click, button, event_point), MouseWindowEvent::MouseDown(button, _) => - MouseDownEvent(button, event_point), + MouseButtonEvent(MouseEventType::MouseDown, button, event_point), MouseWindowEvent::MouseUp(button, _) => - MouseUpEvent(button, event_point), + MouseButtonEvent(MouseEventType::MouseUp, button, event_point), }; self.send_event(compositor, message); } diff --git a/components/compositing/constellation.rs b/components/compositing/constellation.rs index 22a22d459e7..34d20d42c0d 100644 --- a/components/compositing/constellation.rs +++ b/components/compositing/constellation.rs @@ -613,6 +613,19 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> { debug!("constellation got focus message"); self.handle_focus_msg(pipeline_id); } + Request::Script(FromScriptMsg::ForwardMouseButtonEvent( + pipeline_id, event_type, button, point)) => { + if let Some(pipeline) = self.pipelines.get(&pipeline_id) { + pipeline.script_chan.send(ConstellationControlMsg::SendEvent(pipeline_id, + CompositorEvent::MouseButtonEvent(event_type, button, point))); + } + } + Request::Script(FromScriptMsg::ForwardMouseMoveEvent(pipeline_id, point)) => { + if let Some(pipeline) = self.pipelines.get(&pipeline_id) { + pipeline.script_chan.send(ConstellationControlMsg::SendEvent(pipeline_id, + CompositorEvent::MouseMoveEvent(Some(point)))); + } + } Request::Script(FromScriptMsg::GetClipboardContents(sender)) => { let result = self.clipboard_ctx.as_ref().map_or( "".to_owned(), diff --git a/components/compositing/windowing.rs b/components/compositing/windowing.rs index d129a6deb5b..2a9dcb9bcb0 100644 --- a/components/compositing/windowing.rs +++ b/components/compositing/windowing.rs @@ -11,9 +11,9 @@ use euclid::size::TypedSize2D; use euclid::{Point2D, Size2D}; use layers::geometry::DevicePixel; use layers::platform::surface::NativeDisplay; -use msg::constellation_msg::{Key, KeyModifiers, KeyState}; +use msg::constellation_msg::{Key, KeyModifiers, KeyState, MouseButton}; use net_traits::net_error_list::NetError; -use script_traits::{MouseButton, TouchEventType, TouchId}; +use script_traits::{TouchEventType, TouchId}; use std::fmt::{Debug, Error, Formatter}; use std::rc::Rc; use url::Url; @@ -27,7 +27,6 @@ pub enum MouseWindowEvent { MouseUp(MouseButton, TypedPoint2D<DevicePixel, f32>), } - #[derive(Clone)] pub enum WindowNavigateMsg { Forward, diff --git a/components/msg/constellation_msg.rs b/components/msg/constellation_msg.rs index 027d8efddd8..d7ff06de6a4 100644 --- a/components/msg/constellation_msg.rs +++ b/components/msg/constellation_msg.rs @@ -7,6 +7,7 @@ use canvas_traits::CanvasMsg; use compositor_msg::Epoch; +use euclid::point::Point2D; use euclid::scale_factor::ScaleFactor; use euclid::size::{Size2D, TypedSize2D}; use hyper::header::Headers; @@ -283,6 +284,10 @@ pub enum ScriptMsg { Failure(Failure), /// Notifies the constellation that this frame has received focus. Focus(PipelineId), + /// Re-send a mouse button event that was sent to the parent window. + ForwardMouseButtonEvent(PipelineId, MouseEventType, MouseButton, Point2D<f32>), + /// Re-send a mouse move event that was sent to the parent window. + ForwardMouseMoveEvent(PipelineId, Point2D<f32>), /// Requests that the constellation retrieve the current contents of the clipboard GetClipboardContents(IpcSender<String>), /// <head> tag finished parsing @@ -307,6 +312,24 @@ pub enum ScriptMsg { ViewportConstrained(PipelineId, ViewportConstraints), } +#[derive(Deserialize, HeapSizeOf, Serialize)] +pub enum MouseEventType { + Click, + MouseDown, + MouseUp, +} + +/// The mouse button involved in the event. +#[derive(Clone, Copy, Debug, Deserialize, Serialize)] +pub enum MouseButton { + /// The left mouse button. + Left, + /// The middle mouse button. + Middle, + /// The right mouse button. + Right, +} + /// Messages from the paint task to the constellation. #[derive(Deserialize, Serialize)] pub enum PaintMsg { diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index a30e923cee8..0e790188320 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -5,12 +5,15 @@ use document_loader::{DocumentLoader, LoadType}; use dom::attr::{Attr, AttrValue}; use dom::bindings::cell::DOMRefCell; +use dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods; use dom::bindings::codegen::Bindings::DocumentBinding; use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState}; +use dom::bindings::codegen::Bindings::ElementBinding::ElementMethods; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::EventHandlerBinding::OnErrorEventHandlerNonNull; use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods; +use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::Bindings::NodeFilterBinding::NodeFilter; use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods; @@ -82,13 +85,14 @@ use msg::compositor_msg::ScriptToCompositorMsg; use msg::constellation_msg::ScriptMsg as ConstellationMsg; use msg::constellation_msg::{ALT, CONTROL, SHIFT, SUPER}; use msg::constellation_msg::{AnimationState, PipelineId}; -use msg::constellation_msg::{ConstellationChan, FocusType, Key, KeyModifiers, KeyState, MozBrowserEvent, SubpageId}; +use msg::constellation_msg::{ConstellationChan, FocusType, Key, KeyModifiers, KeyState}; +use msg::constellation_msg::{MouseButton, MouseEventType, MozBrowserEvent, SubpageId}; use net_traits::ControlMsg::{GetCookiesForUrl, SetCookiesForUrl}; use net_traits::CookieSource::NonHTTP; use net_traits::{AsyncResponseTarget, PendingAsyncLoad}; use num::ToPrimitive; use script_task::{MainThreadScriptMsg, Runnable}; -use script_traits::{MouseButton, TouchEventType, TouchId, UntrustedNodeAddress}; +use script_traits::{TouchEventType, TouchId, UntrustedNodeAddress}; use std::ascii::AsciiExt; use std::borrow::ToOwned; use std::boxed::FnBox; @@ -603,7 +607,7 @@ impl Document { pub fn handle_mouse_event(&self, js_runtime: *mut JSRuntime, - _button: MouseButton, + button: MouseButton, client_point: Point2D<f32>, mouse_event_type: MouseEventType) { let mouse_event_type_string = match mouse_event_type { @@ -634,6 +638,21 @@ impl Document { }, }; + // If the target is an iframe, forward the event to the child document. + if let Some(iframe) = el.downcast::<HTMLIFrameElement>() { + if let Some(pipeline_id) = iframe.pipeline_id() { + let rect = iframe.upcast::<Element>().GetBoundingClientRect(); + let child_origin = Point2D::new(rect.X() as f32, rect.Y() as f32); + let child_point = client_point - child_origin; + + let event = ConstellationMsg::ForwardMouseButtonEvent(pipeline_id, + mouse_event_type, + button, child_point); + self.window.constellation_chan().0.send(event).unwrap(); + } + return; + } + let node = el.upcast::<Node>(); debug!("{} on {:?}", mouse_event_type_string, node.debug_str()); // Prevent click event if form control element is disabled. @@ -766,11 +785,23 @@ impl Document { if mouse_over_addresses.len() > 0 { let top_most_node = node::from_untrusted_node_address(js_runtime, mouse_over_addresses[0]); + let client_point = client_point.unwrap(); // Must succeed because hit test succeeded. - let target = top_most_node.upcast(); - if let Some(client_point) = client_point { - self.fire_mouse_event(client_point, target, "mousemove".to_owned()); + // If the target is an iframe, forward the event to the child document. + if let Some(iframe) = top_most_node.downcast::<HTMLIFrameElement>() { + if let Some(pipeline_id) = iframe.pipeline_id() { + let rect = iframe.upcast::<Element>().GetBoundingClientRect(); + let child_origin = Point2D::new(rect.X() as f32, rect.Y() as f32); + let child_point = client_point - child_origin; + + let event = ConstellationMsg::ForwardMouseMoveEvent(pipeline_id, child_point); + self.window.constellation_chan().0.send(event).unwrap(); + } + return; } + + let target = top_most_node.upcast(); + self.fire_mouse_event(client_point, target, "mousemove".to_owned()); } // Store the current mouse over targets for next frame @@ -1362,14 +1393,6 @@ impl Document { } } -#[derive(HeapSizeOf)] -pub enum MouseEventType { - Click, - MouseDown, - MouseUp, -} - - #[derive(PartialEq, HeapSizeOf)] pub enum DocumentSource { FromParser, diff --git a/components/script/dom/htmliframeelement.rs b/components/script/dom/htmliframeelement.rs index 4c7f7276ca7..3798ab4f539 100644 --- a/components/script/dom/htmliframeelement.rs +++ b/components/script/dom/htmliframeelement.rs @@ -186,6 +186,11 @@ impl HTMLIFrameElement { } #[inline] + pub fn pipeline_id(&self) -> Option<PipelineId> { + self.pipeline_id.get() + } + + #[inline] pub fn subpage_id(&self) -> Option<SubpageId> { self.subpage_id.get() } diff --git a/components/script/script_task.rs b/components/script/script_task.rs index 8b9800063e2..736c95b0d2d 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -31,8 +31,7 @@ use dom::bindings::js::{Root, RootCollectionPtr, RootedReference}; use dom::bindings::refcounted::{LiveDOMReferences, Trusted, TrustedReference, trace_refcounted_objects}; use dom::bindings::trace::{JSTraceable, RootedVec, trace_traceables}; use dom::bindings::utils::{DOM_CALLBACKS, WRAP_CALLBACKS}; -use dom::document::{Document, DocumentProgressHandler, IsHTMLDocument}; -use dom::document::{DocumentSource, MouseEventType}; +use dom::document::{Document, DocumentProgressHandler, DocumentSource, IsHTMLDocument}; use dom::element::Element; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::htmlanchorelement::HTMLAnchorElement; @@ -65,7 +64,7 @@ use mem::heap_size_of_self_and_children; use msg::compositor_msg::{EventResult, LayerId, ScriptToCompositorMsg}; use msg::constellation_msg::ScriptMsg as ConstellationMsg; use msg::constellation_msg::{ConstellationChan, FocusType, LoadData}; -use msg::constellation_msg::{MozBrowserEvent, PipelineId}; +use msg::constellation_msg::{MouseButton, MouseEventType, MozBrowserEvent, PipelineId}; use msg::constellation_msg::{PipelineNamespace}; use msg::constellation_msg::{SubpageId, WindowSizeData, WorkerId}; use msg::webdriver_msg::WebDriverScriptCommand; @@ -78,11 +77,9 @@ use page::{Frame, IterablePage, Page}; use parse::html::{ParseContext, parse_html}; use profile_traits::mem::{self, OpaqueSender, Report, ReportKind, ReportsChan}; use profile_traits::time::{self, ProfilerCategory, profile}; -use script_traits::CompositorEvent::{ClickEvent, ResizeEvent}; -use script_traits::CompositorEvent::{KeyEvent, MouseMoveEvent}; -use script_traits::CompositorEvent::{MouseDownEvent, MouseUpEvent, TouchEvent}; -use script_traits::{CompositorEvent, ConstellationControlMsg}; -use script_traits::{InitialScriptState, MouseButton, NewLayoutInfo}; +use script_traits::CompositorEvent::{KeyEvent, MouseButtonEvent, MouseMoveEvent, ResizeEvent}; +use script_traits::CompositorEvent::{TouchEvent}; +use script_traits::{CompositorEvent, ConstellationControlMsg, InitialScriptState, NewLayoutInfo}; use script_traits::{OpaqueScriptLayoutChannel, ScriptState, ScriptTaskFactory}; use script_traits::{TimerEvent, TimerEventRequest, TimerSource}; use script_traits::{TouchEventType, TouchId}; @@ -1786,16 +1783,8 @@ impl ScriptTask { self.handle_resize_event(pipeline_id, new_size); } - ClickEvent(button, point) => { - self.handle_mouse_event(pipeline_id, MouseEventType::Click, button, point); - } - - MouseDownEvent(button, point) => { - self.handle_mouse_event(pipeline_id, MouseEventType::MouseDown, button, point); - } - - MouseUpEvent(button, point) => { - self.handle_mouse_event(pipeline_id, MouseEventType::MouseUp, button, point); + MouseButtonEvent(event_type, button, point) => { + self.handle_mouse_event(pipeline_id, event_type, button, point); } MouseMoveEvent(point) => { diff --git a/components/script_traits/lib.rs b/components/script_traits/lib.rs index 8a5ffcb459f..ef86ee26085 100644 --- a/components/script_traits/lib.rs +++ b/components/script_traits/lib.rs @@ -34,6 +34,7 @@ use msg::compositor_msg::{Epoch, LayerId, ScriptToCompositorMsg}; use msg::constellation_msg::ScriptMsg as ConstellationMsg; use msg::constellation_msg::{ConstellationChan, Failure, PipelineId, WindowSizeData}; use msg::constellation_msg::{Key, KeyModifiers, KeyState, LoadData, SubpageId}; +use msg::constellation_msg::{MouseButton, MouseEventType}; use msg::constellation_msg::{MozBrowserEvent, PipelineNamespaceId}; use msg::webdriver_msg::WebDriverScriptCommand; use net_traits::ResourceTask; @@ -146,17 +147,6 @@ pub enum ConstellationControlMsg { }, } -/// The mouse button involved in the event. -#[derive(Clone, Copy, Debug, Deserialize, Serialize)] -pub enum MouseButton { - /// The left mouse button. - Left, - /// The middle mouse button. - Middle, - /// The right mouse button. - Right, -} - /// The type of input represented by a multi-touch event. #[derive(Clone, Copy, Debug, Deserialize, Serialize)] pub enum TouchEventType { @@ -181,12 +171,8 @@ pub struct TouchId(pub i32); pub enum CompositorEvent { /// The window was resized. ResizeEvent(WindowSizeData), - /// A point was clicked. - ClickEvent(MouseButton, Point2D<f32>), - /// A mouse button was pressed on a point. - MouseDownEvent(MouseButton, Point2D<f32>), - /// A mouse button was released on a point. - MouseUpEvent(MouseButton, Point2D<f32>), + /// A mouse button state changed. + MouseButtonEvent(MouseEventType, MouseButton, Point2D<f32>), /// The mouse was moved over a point (or was moved out of the recognizable region). MouseMoveEvent(Option<Point2D<f32>>), /// A touch event was generated with a touch ID and location. |