compositor can get mouse point from window event

This commit is contained in:
HyunJune Kim 2014-02-05 17:39:18 +09:00
parent 8486ba4325
commit d2f8b593a9
6 changed files with 28 additions and 5 deletions

View file

@ -13,7 +13,7 @@ use windowing::{WindowEvent, WindowMethods,
IdleWindowEvent, RefreshWindowEvent, ResizeWindowEvent, LoadUrlWindowEvent, IdleWindowEvent, RefreshWindowEvent, ResizeWindowEvent, LoadUrlWindowEvent,
MouseWindowEventClass,ScrollWindowEvent, ZoomWindowEvent, NavigationWindowEvent, MouseWindowEventClass,ScrollWindowEvent, ZoomWindowEvent, NavigationWindowEvent,
FinishedWindowEvent, QuitWindowEvent, FinishedWindowEvent, QuitWindowEvent,
MouseWindowEvent, MouseWindowClickEvent, MouseWindowMouseDownEvent, MouseWindowMouseUpEvent}; MouseWindowEvent, MouseWindowClickEvent, MouseWindowMouseDownEvent, MouseWindowMouseUpEvent, MouseMoveEventClass};
use azure::azure_hl::{SourceSurfaceMethods, Color}; use azure::azure_hl::{SourceSurfaceMethods, Color};
@ -515,6 +515,10 @@ impl IOCompositor {
self.on_mouse_window_event_class(mouse_window_event); self.on_mouse_window_event_class(mouse_window_event);
} }
MouseMoveEventClass(cursor) => {
self.on_mouse_window_move_event_class(cursor);
}
ScrollWindowEvent(delta, cursor) => { ScrollWindowEvent(delta, cursor) => {
self.on_scroll_window_event(delta, cursor); self.on_scroll_window_event(delta, cursor);
} }
@ -579,6 +583,12 @@ impl IOCompositor {
} }
} }
fn on_mouse_window_move_event_class(&self, cursor: Point2D<f32>) {
for layer in self.compositor_layer.iter() {
layer.send_mouse_move_event(cursor);
}
}
fn on_scroll_window_event(&mut self, delta: Point2D<f32>, cursor: Point2D<i32>) { fn on_scroll_window_event(&mut self, delta: Point2D<f32>, cursor: Point2D<i32>) {
let world_zoom = self.world_zoom; let world_zoom = self.world_zoom;
// TODO: modify delta to snap scroll to pixels. // TODO: modify delta to snap scroll to pixels.

View file

@ -18,7 +18,7 @@ use layers::platform::surface::{NativeCompositingGraphicsContext, NativeSurfaceM
use layers::texturegl::{Texture, TextureTarget}; use layers::texturegl::{Texture, TextureTarget};
#[cfg(target_os="macos")] use layers::texturegl::TextureTargetRectangle; #[cfg(target_os="macos")] use layers::texturegl::TextureTargetRectangle;
use pipeline::CompositionPipeline; use pipeline::CompositionPipeline;
use script::dom::event::{ClickEvent, MouseDownEvent, MouseUpEvent}; use script::dom::event::{ClickEvent, MouseDownEvent, MouseUpEvent, MouseMoveEvent};
use script::script_task::SendEventMsg; use script::script_task::SendEventMsg;
use servo_msg::compositor_msg::{LayerBuffer, LayerBufferSet, Epoch, Tile}; use servo_msg::compositor_msg::{LayerBuffer, LayerBufferSet, Epoch, Tile};
use servo_msg::constellation_msg::PipelineId; use servo_msg::constellation_msg::PipelineId;
@ -251,7 +251,12 @@ impl CompositorLayer {
self.pipeline.script_chan.send(SendEventMsg(self.pipeline.id.clone(), message)); self.pipeline.script_chan.send(SendEventMsg(self.pipeline.id.clone(), message));
} }
pub fn send_mouse_move_event(&self, cursor: Point2D<f32>) {
let message = MouseMoveEvent(cursor);
self.pipeline.script_chan.send(SendEventMsg(self.pipeline.id.clone(), message));
}
// Given the current window size, determine which tiles need to be (re)rendered // Given the current window size, determine which tiles need to be (re)rendered
// and sends them off the the appropriate renderer. // and sends them off the the appropriate renderer.
// Returns a bool that is true if the scene should be repainted. // Returns a bool that is true if the scene should be repainted.

View file

@ -7,7 +7,7 @@
use windowing::{ApplicationMethods, WindowEvent, WindowMethods}; use windowing::{ApplicationMethods, WindowEvent, WindowMethods};
use windowing::{IdleWindowEvent, ResizeWindowEvent, LoadUrlWindowEvent, MouseWindowEventClass}; use windowing::{IdleWindowEvent, ResizeWindowEvent, LoadUrlWindowEvent, MouseWindowEventClass};
use windowing::{ScrollWindowEvent, ZoomWindowEvent, NavigationWindowEvent, FinishedWindowEvent}; use windowing::{ScrollWindowEvent, ZoomWindowEvent, NavigationWindowEvent, FinishedWindowEvent};
use windowing::{QuitWindowEvent, MouseWindowClickEvent, MouseWindowMouseDownEvent, MouseWindowMouseUpEvent}; use windowing::{QuitWindowEvent, MouseWindowClickEvent, MouseWindowMouseDownEvent, MouseWindowMouseUpEvent, MouseMoveEventClass};
use windowing::RefreshWindowEvent; use windowing::RefreshWindowEvent;
use windowing::{Forward, Back}; use windowing::{Forward, Back};
@ -156,6 +156,10 @@ impl WindowMethods<Application> for Window {
local_window().handle_mouse(button, action, x as i32, y as i32); local_window().handle_mouse(button, action, x as i32, y as i32);
} }
})); }));
window.glfw_window.set_cursor_pos_callback(
glfw_callback!(glfw::CursorPosCallback(win: &glfw::Window, xpos: f64, ypos: f64) {
local_window().event_queue.push(MouseMoveEventClass(Point2D(xpos as f32, ypos as f32)));
}));
window.glfw_window.set_scroll_callback( window.glfw_window.set_scroll_callback(
glfw_callback!(glfw::ScrollCallback(win: &glfw::Window, xpos: f64, ypos: f64) { glfw_callback!(glfw::ScrollCallback(win: &glfw::Window, xpos: f64, ypos: f64) {
let dx = (xpos as f32) * 30.0; let dx = (xpos as f32) * 30.0;

View file

@ -34,6 +34,8 @@ pub enum WindowEvent {
LoadUrlWindowEvent(~str), LoadUrlWindowEvent(~str),
/// Sent when a mouse hit test is to be performed. /// Sent when a mouse hit test is to be performed.
MouseWindowEventClass(MouseWindowEvent), MouseWindowEventClass(MouseWindowEvent),
/// Sent when a mouse move.
MouseMoveEventClass(Point2D<f32>),
/// Sent when the user scrolls. Includes the current cursor position. /// Sent when the user scrolls. Includes the current cursor position.
ScrollWindowEvent(Point2D<f32>, Point2D<i32>), ScrollWindowEvent(Point2D<f32>, Point2D<i32>),
/// Sent when the user zooms. /// Sent when the user zooms.

View file

@ -21,6 +21,7 @@ pub enum Event_ {
ClickEvent(uint, Point2D<f32>), ClickEvent(uint, Point2D<f32>),
MouseDownEvent(uint, Point2D<f32>), MouseDownEvent(uint, Point2D<f32>),
MouseUpEvent(uint, Point2D<f32>), MouseUpEvent(uint, Point2D<f32>),
MouseMoveEvent(Point2D<f32>)
} }
pub struct AbstractEvent { pub struct AbstractEvent {

View file

@ -9,7 +9,7 @@ use dom::bindings::codegen::RegisterBindings;
use dom::bindings::utils::{Reflectable, GlobalStaticData}; use dom::bindings::utils::{Reflectable, GlobalStaticData};
use dom::document::AbstractDocument; use dom::document::AbstractDocument;
use dom::element::Element; use dom::element::Element;
use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseUpEvent}; use dom::event::{Event_, ResizeEvent, ReflowEvent, ClickEvent, MouseDownEvent, MouseUpEvent, MouseMoveEvent};
use dom::event::Event; use dom::event::Event;
use dom::eventtarget::AbstractEventTarget; use dom::eventtarget::AbstractEventTarget;
use dom::htmldocument::HTMLDocument; use dom::htmldocument::HTMLDocument;
@ -882,6 +882,7 @@ impl ScriptTask {
} }
MouseDownEvent(..) => {} MouseDownEvent(..) => {}
MouseUpEvent(..) => {} MouseUpEvent(..) => {}
MouseMoveEvent(point) => {}
} }
} }