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
Move body of ScriptTask::handle_mouse_move_event into a method on #5032
Closed
+98
−88
Closed
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.
Move body of ScriptTask::handle_mouse_move_event into a method on
Document #4984
- Loading branch information
commit 1eef07c11a702d0be246d6e6d795be2e1c48dd6b
| @@ -77,6 +77,7 @@ use std::ascii::AsciiExt; | ||
| use std::cell::{Cell, Ref}; | ||
| use std::default::Default; | ||
| use std::sync::mpsc::channel; | ||
| use std::num::ToPrimitive; | ||
| use time; | ||
|
|
||
| #[derive(PartialEq)] | ||
| @@ -199,6 +200,7 @@ pub trait DocumentHelpers<'a> { | ||
| fn send_title_to_compositor(self); | ||
| fn dirty_all_nodes(self); | ||
| fn handle_click_event(self, js_runtime: *mut JSRuntime, _button: uint, point: Point2D<f32>); | ||
| fn handle_mouse_move_event(self, js_runtime: *mut JSRuntime, point: Point2D<f32>, mouse_over_targets: &mut Option<Vec<JS<Node>>>) -> bool; | ||
| } | ||
|
|
||
| impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { | ||
| @@ -450,6 +452,91 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { | ||
| None => {} | ||
| } | ||
| } | ||
|
|
||
| fn handle_mouse_move_event (self, js_runtime: *mut JSRuntime, point: Point2D<f32>, mouse_over_targets: &mut Option<Vec<JS<Node>>>) -> bool{ | ||
kmcallister
Contributor
|
||
| let window = self.window.root(); | ||
| let window = window.r(); | ||
| let page = window.page(); | ||
| match page.get_nodes_under_mouse(&point) { | ||
| Some(node_address) => { | ||
| let mut target_list = vec!(); | ||
| let mut target_compare = false; | ||
|
|
||
| match *mouse_over_targets { | ||
| Some(ref mut mouse_over_targets) => { | ||
| for node in mouse_over_targets.iter_mut() { | ||
| let node = node.root(); | ||
| node.r().set_hover_state(false); | ||
| } | ||
| } | ||
| None => {} | ||
| } | ||
|
|
||
| if node_address.len() > 0 { | ||
| let top_most_node = | ||
| node::from_untrusted_node_address(js_runtime, node_address[0]).root(); | ||
|
|
||
| if let Some(ref frame) = *page.frame() { | ||
| let window = frame.window.root(); | ||
|
|
||
| let x = point.x.to_i32().unwrap_or(0); | ||
| let y = point.y.to_i32().unwrap_or(0); | ||
|
|
||
| let mouse_event = MouseEvent::new(window.r(), | ||
| "mousemove".to_owned(), | ||
| true, | ||
| true, | ||
| Some(window.r()), | ||
| 0i32, | ||
| x, y, x, y, | ||
| false, false, false, false, | ||
| 0i16, | ||
| None).root(); | ||
|
|
||
| let event: JSRef<Event> = EventCast::from_ref(mouse_event.r()); | ||
| let target: JSRef<EventTarget> = EventTargetCast::from_ref(top_most_node.r()); | ||
| event.fire(target); | ||
| } | ||
| } | ||
|
|
||
| for node_address in node_address.iter() { | ||
| let temp_node = | ||
| node::from_untrusted_node_address(js_runtime, *node_address).root(); | ||
|
|
||
| let maybe_node = temp_node.r().ancestors().find(|node| node.is_element()); | ||
| match maybe_node { | ||
| Some(node) => { | ||
| node.set_hover_state(true); | ||
| match *mouse_over_targets { | ||
| Some(ref mouse_over_targets) if !target_compare => { | ||
| target_compare = | ||
| !mouse_over_targets.contains(&JS::from_rooted(node)); | ||
| } | ||
| _ => {} | ||
| } | ||
| target_list.push(JS::from_rooted(node)); | ||
| } | ||
| None => {} | ||
| } | ||
| } | ||
| match *mouse_over_targets { | ||
| Some(ref mouse_over_targets) => { | ||
| if mouse_over_targets.len() != target_list.len() { | ||
| target_compare = true | ||
| } | ||
| } | ||
| None => target_compare = true, | ||
| } | ||
|
|
||
| if target_compare { | ||
| *mouse_over_targets = Some(target_list); | ||
| } | ||
| target_compare | ||
| } | ||
|
|
||
| None => false | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(PartialEq)] | ||
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Nit: space before
(