Auto merge of #8326 - jdm:iframehover, r=glennw

Send mouse move events to the the previous layer when directing event…

…s to a new one for the first time. Resolves #7865.

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/8326)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-11-06 06:24:59 +05:30
commit 4067960ba5
4 changed files with 41 additions and 12 deletions

View file

@ -35,7 +35,7 @@ use msg::constellation_msg::{NavigationDirection, PipelineId, WindowSizeData};
use pipeline::CompositionPipeline; use pipeline::CompositionPipeline;
use profile_traits::mem::{self, ReportKind, Reporter, ReporterRequest}; use profile_traits::mem::{self, ReportKind, Reporter, ReporterRequest};
use profile_traits::time::{self, ProfilerCategory, profile}; use profile_traits::time::{self, ProfilerCategory, profile};
use script_traits::CompositorEvent::TouchEvent; use script_traits::CompositorEvent::{MouseMoveEvent, TouchEvent};
use script_traits::{ConstellationControlMsg, LayoutControlMsg, MouseButton}; use script_traits::{ConstellationControlMsg, LayoutControlMsg, MouseButton};
use script_traits::{TouchEventType, TouchId}; use script_traits::{TouchEventType, TouchId};
use scrolling::ScrollingTimerProxy; use scrolling::ScrollingTimerProxy;
@ -201,6 +201,9 @@ pub struct IOCompositor<Window: WindowMethods> {
/// Pipeline IDs of subpages that the compositor has seen in a layer tree but which have not /// Pipeline IDs of subpages that the compositor has seen in a layer tree but which have not
/// yet been painted. /// yet been painted.
pending_subpages: HashSet<PipelineId>, pending_subpages: HashSet<PipelineId>,
/// The id of the pipeline that was last sent a mouse move event, if any.
last_mouse_move_recipient: Option<PipelineId>,
} }
/// The states of the touch input state machine. /// The states of the touch input state machine.
@ -370,6 +373,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
ready_to_save_state: ReadyState::Unknown, ready_to_save_state: ReadyState::Unknown,
surface_map: SurfaceMap::new(BUFFER_MAP_SIZE), surface_map: SurfaceMap::new(BUFFER_MAP_SIZE),
pending_subpages: HashSet::new(), pending_subpages: HashSet::new(),
last_mouse_move_recipient: None,
} }
} }
@ -1205,8 +1209,24 @@ impl<Window: WindowMethods> IOCompositor<Window> {
} }
match self.find_topmost_layer_at_point(cursor / self.scene.scale) { match self.find_topmost_layer_at_point(cursor / self.scene.scale) {
Some(result) => result.layer.send_mouse_move_event(self, result.point), Some(result) => {
None => {}, // In the case that the mouse was previously over a different layer,
// that layer must update its state.
if let Some(last_pipeline_id) = self.last_mouse_move_recipient {
if last_pipeline_id != result.layer.pipeline_id() {
if let Some(pipeline) = self.pipeline(last_pipeline_id) {
let _ = pipeline.script_chan
.send(ConstellationControlMsg::SendEvent(
last_pipeline_id.clone(),
MouseMoveEvent(None)));
}
}
}
self.last_mouse_move_recipient = Some(result.layer.pipeline_id());
result.layer.send_mouse_move_event(self, result.point);
}
None => {}
} }
} }

View file

@ -385,7 +385,7 @@ impl CompositorLayer for Layer<CompositorData> {
compositor: &IOCompositor<Window>, compositor: &IOCompositor<Window>,
cursor: TypedPoint2D<LayerPixel, f32>) cursor: TypedPoint2D<LayerPixel, f32>)
where Window: WindowMethods { where Window: WindowMethods {
self.send_event(compositor, MouseMoveEvent(cursor.to_untyped())); self.send_event(compositor, MouseMoveEvent(Some(cursor.to_untyped())));
} }
fn send_event<Window>(&self, fn send_event<Window>(&self,

View file

@ -669,10 +669,12 @@ impl Document {
pub fn handle_mouse_move_event(&self, pub fn handle_mouse_move_event(&self,
js_runtime: *mut JSRuntime, js_runtime: *mut JSRuntime,
point: Point2D<f32>, point: Option<Point2D<f32>>,
prev_mouse_over_targets: &mut RootedVec<JS<Element>>) { prev_mouse_over_targets: &mut RootedVec<JS<Element>>) {
// Build a list of elements that are currently under the mouse. // Build a list of elements that are currently under the mouse.
let mouse_over_addresses = self.get_nodes_under_mouse(&point); let mouse_over_addresses = point.as_ref()
.map(|point| self.get_nodes_under_mouse(point))
.unwrap_or(vec![]);
let mut mouse_over_targets = mouse_over_addresses.iter().map(|node_address| { let mut mouse_over_targets = mouse_over_addresses.iter().map(|node_address| {
node::from_untrusted_node_address(js_runtime, *node_address) node::from_untrusted_node_address(js_runtime, *node_address)
.inclusive_ancestors() .inclusive_ancestors()
@ -691,7 +693,11 @@ impl Document {
let target = target_ref.upcast(); let target = target_ref.upcast();
self.fire_mouse_event(point, &target, "mouseout".to_owned()); // FIXME: we should be dispatching this event but we lack an actual
// point to pass to it.
if let Some(point) = point {
self.fire_mouse_event(point, &target, "mouseout".to_owned());
}
} }
} }
} }
@ -705,8 +711,9 @@ impl Document {
let target = target.upcast(); let target = target.upcast();
self.fire_mouse_event(point, target, "mouseover".to_owned()); if let Some(point) = point {
self.fire_mouse_event(point, target, "mouseover".to_owned());
}
} }
} }
@ -716,7 +723,9 @@ impl Document {
node::from_untrusted_node_address(js_runtime, mouse_over_addresses[0]); node::from_untrusted_node_address(js_runtime, mouse_over_addresses[0]);
let target = top_most_node.upcast(); let target = top_most_node.upcast();
self.fire_mouse_event(point, target, "mousemove".to_owned()); if let Some(point) = point {
self.fire_mouse_event(point, target, "mousemove".to_owned());
}
} }
// Store the current mouse over targets for next frame // Store the current mouse over targets for next frame

View file

@ -187,8 +187,8 @@ pub enum CompositorEvent {
MouseDownEvent(MouseButton, Point2D<f32>), MouseDownEvent(MouseButton, Point2D<f32>),
/// A mouse button was released on a point. /// A mouse button was released on a point.
MouseUpEvent(MouseButton, Point2D<f32>), MouseUpEvent(MouseButton, Point2D<f32>),
/// The mouse was moved over a point. /// The mouse was moved over a point (or was moved out of the recognizable region).
MouseMoveEvent(Point2D<f32>), MouseMoveEvent(Option<Point2D<f32>>),
/// A touch event was generated with a touch ID and location. /// A touch event was generated with a touch ID and location.
TouchEvent(TouchEventType, TouchId, Point2D<f32>), TouchEvent(TouchEventType, TouchId, Point2D<f32>),
/// A key was pressed. /// A key was pressed.