Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for mouseover and mouseout events #6434

Merged
merged 1 commit into from Jul 1, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

add support for mouseover and mouseout events

  • Loading branch information
yoava333 authored and Yoav Alon committed Jun 30, 2015
commit 3a44e143bc8d326c1e12571e7b523de49431efc4
@@ -259,6 +259,9 @@ pub trait DocumentHelpers<'a> {
fn get_body_attribute(self, local_name: &Atom) -> DOMString;
fn set_body_attribute(self, local_name: &Atom, value: DOMString);

fn fire_mouse_event(self, point: Point2D<f32>,
target: &EventTarget,
event_name: String);
fn handle_mouse_event(self, js_runtime: *mut JSRuntime,
button: MouseButton, point: Point2D<f32>,
mouse_event_type: MouseEventType);
@@ -670,6 +673,29 @@ impl<'a> DocumentHelpers<'a> for &'a Document {
window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::MouseEvent);
}

fn fire_mouse_event(self,
point: Point2D<f32>,
target: &EventTarget,
event_name: String) {
let x = point.x.to_i32().unwrap_or(0);
let y = point.y.to_i32().unwrap_or(0);

let window = self.window.root();

let mouse_event = MouseEvent::new(window.r(),
event_name,
EventBubbles::Bubbles,
EventCancelable::Cancelable,
Some(window.r()),
0i32,
x, y, x, y,
false, false, false, false,
0i16,
None);
let event = EventCast::from_ref(mouse_event.r());
event.fire(target);
}

fn handle_mouse_move_event(self,
js_runtime: *mut JSRuntime,
point: Point2D<f32>,
@@ -688,7 +714,15 @@ impl<'a> DocumentHelpers<'a> for &'a Document {
// under the mouse.
for target in prev_mouse_over_targets.iter() {
if !mouse_over_targets.contains(target) {
target.root().r().set_hover_state(false);
let target = target.root();
let target_ref = target.r();
if target_ref.get_hover_state() {
target_ref.set_hover_state(false);

let target = EventTargetCast::from_ref(target_ref);

self.fire_mouse_event(point, &target, "mouseout".to_owned());
}
}
}

@@ -700,6 +734,11 @@ impl<'a> DocumentHelpers<'a> for &'a Document {
let target_ref = target.r();
if !target_ref.get_hover_state() {
target_ref.set_hover_state(true);

let target = EventTargetCast::from_ref(target_ref);

self.fire_mouse_event(point, &target, "mouseover".to_owned());

}
}

@@ -708,24 +747,8 @@ impl<'a> DocumentHelpers<'a> for &'a Document {
let top_most_node =
node::from_untrusted_node_address(js_runtime, mouse_over_addresses[0]);

let x = point.x.to_i32().unwrap_or(0);
let y = point.y.to_i32().unwrap_or(0);

let window = self.window.root();
let mouse_event = MouseEvent::new(window.r(),
"mousemove".to_owned(),
EventBubbles::Bubbles,
EventCancelable::Cancelable,
Some(window.r()),
0i32,
x, y, x, y,
false, false, false, false,
0i16,
None);

let event = EventCast::from_ref(mouse_event.r());
let target = EventTargetCast::from_ref(top_most_node.r());
event.fire(target);
self.fire_mouse_event(point, target, "mousemove".to_owned());
}

// Store the current mouse over targets for next frame
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.