From 8c4fed42b0e50f51134dca8f92558c7f4e37c4ab Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Wed, 2 Dec 2015 11:49:37 -0800 Subject: Minor refactoring of mouse event types * Move some types into the `msg` crate so they can be shared more. * Use MouseEventType instead of duplicating it in other enums. --- components/script/dom/document.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'components/script/dom/document.rs') diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index a30e923cee8..0887cd8b1e3 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -82,13 +82,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; @@ -1362,14 +1363,6 @@ impl Document { } } -#[derive(HeapSizeOf)] -pub enum MouseEventType { - Click, - MouseDown, - MouseUp, -} - - #[derive(PartialEq, HeapSizeOf)] pub enum DocumentSource { FromParser, -- cgit v1.2.3 From 9551363bfba695b17c55cc551b87a6c0d16eb6a0 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Tue, 1 Dec 2015 14:22:15 -0800 Subject: If a mouse event is targeting an iframe, forward it to the iframe's inner window Fixes #8759. This adds a slow path for cases where the compositor's layer-based hit testing is incorrect. To optimize for this case, we could instead replace the layer hit testing with display-list hit testing done in the paint task. --- components/script/dom/document.rs | 38 ++++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) (limited to 'components/script/dom/document.rs') diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 0887cd8b1e3..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; @@ -604,7 +607,7 @@ impl Document { pub fn handle_mouse_event(&self, js_runtime: *mut JSRuntime, - _button: MouseButton, + button: MouseButton, client_point: Point2D, mouse_event_type: MouseEventType) { let mouse_event_type_string = match mouse_event_type { @@ -635,6 +638,21 @@ impl Document { }, }; + // If the target is an iframe, forward the event to the child document. + if let Some(iframe) = el.downcast::() { + if let Some(pipeline_id) = iframe.pipeline_id() { + let rect = iframe.upcast::().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::(); debug!("{} on {:?}", mouse_event_type_string, node.debug_str()); // Prevent click event if form control element is disabled. @@ -767,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::() { + if let Some(pipeline_id) = iframe.pipeline_id() { + let rect = iframe.upcast::().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 -- cgit v1.2.3