mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
Introduce a MouseButton enum.
This commit is contained in:
parent
85808c1cdd
commit
6b127a8df8
16 changed files with 57 additions and 20 deletions
2
ports/cef/Cargo.lock
generated
2
ports/cef/Cargo.lock
generated
|
@ -21,6 +21,7 @@ dependencies = [
|
|||
"plugins 0.0.1",
|
||||
"png 0.1.0 (git+https://github.com/servo/rust-png)",
|
||||
"script 0.0.1",
|
||||
"script_traits 0.0.1",
|
||||
"servo 0.0.1",
|
||||
"stb_image 0.1.0 (git+https://github.com/servo/rust-stb-image)",
|
||||
"style 0.0.1",
|
||||
|
@ -403,6 +404,7 @@ dependencies = [
|
|||
"layers 0.1.0 (git+https://github.com/servo/rust-layers)",
|
||||
"libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"msg 0.0.1",
|
||||
"script_traits 0.0.1",
|
||||
"time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"util 0.0.1",
|
||||
|
|
|
@ -26,6 +26,9 @@ path = "../../components/gfx"
|
|||
[dependencies.script]
|
||||
path = "../../components/script"
|
||||
|
||||
[dependencies.script_traits]
|
||||
path = "../../components/script_traits"
|
||||
|
||||
[dependencies.net]
|
||||
path = "../../components/net"
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ use geom::point::TypedPoint2D;
|
|||
use geom::size::TypedSize2D;
|
||||
use libc::{c_double, c_int};
|
||||
use msg::constellation_msg::{self, KeyModifiers, KeyState};
|
||||
use script_traits::MouseButton;
|
||||
use std::cell::RefCell;
|
||||
|
||||
pub struct ServoCefBrowserHost {
|
||||
|
@ -110,7 +111,11 @@ full_cef_class_impl! {
|
|||
let event: &cef_mouse_event = event;
|
||||
let mouse_button_type: cef_mouse_button_type_t = mouse_button_type;
|
||||
let mouse_up: c_int = mouse_up;
|
||||
let button_type = mouse_button_type as uint;
|
||||
let button_type = match mouse_button_type {
|
||||
cef_mouse_button_type_t::MBT_LEFT => MouseButton::Left,
|
||||
cef_mouse_button_type_t::MBT_MIDDLE => MouseButton::Middle,
|
||||
cef_mouse_button_type_t::MBT_RIGHT => MouseButton::Right,
|
||||
};
|
||||
let point = TypedPoint2D((*event).x as f32, (*event).y as f32);
|
||||
if mouse_up != 0 {
|
||||
this.downcast().send_window_event(WindowEvent::MouseWindowEventClass(
|
||||
|
|
|
@ -32,6 +32,7 @@ extern crate js;
|
|||
extern crate layers;
|
||||
extern crate png;
|
||||
extern crate script;
|
||||
extern crate script_traits;
|
||||
extern crate unicode;
|
||||
|
||||
extern crate net;
|
||||
|
|
|
@ -14,6 +14,9 @@ headless = ["glutin/headless"]
|
|||
[dependencies.compositing]
|
||||
path = "../../components/compositing"
|
||||
|
||||
[dependencies.script_traits]
|
||||
path = "../../components/script_traits"
|
||||
|
||||
[dependencies.geom]
|
||||
git = "https://github.com/servo/rust-geom"
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ extern crate glutin;
|
|||
extern crate layers;
|
||||
extern crate libc;
|
||||
extern crate msg;
|
||||
#[cfg(feature = "window")] extern crate script_traits;
|
||||
extern crate time;
|
||||
extern crate util;
|
||||
extern crate egl;
|
||||
|
|
|
@ -224,13 +224,15 @@ impl Window {
|
|||
|
||||
/// Helper function to handle a click
|
||||
fn handle_mouse(&self, button: glutin::MouseButton, action: glutin::ElementState, x: i32, y: i32) {
|
||||
use script_traits::MouseButton;
|
||||
|
||||
// FIXME(tkuehn): max pixel dist should be based on pixel density
|
||||
let max_pixel_dist = 10f64;
|
||||
let event = match action {
|
||||
ElementState::Pressed => {
|
||||
self.mouse_down_point.set(Point2D(x, y));
|
||||
self.mouse_down_button.set(Some(button));
|
||||
MouseWindowEvent::MouseDown(0, TypedPoint2D(x as f32, y as f32))
|
||||
MouseWindowEvent::MouseDown(MouseButton::Left, TypedPoint2D(x as f32, y as f32))
|
||||
}
|
||||
ElementState::Released => {
|
||||
match self.mouse_down_button.get() {
|
||||
|
@ -241,13 +243,13 @@ impl Window {
|
|||
pixel_dist.y * pixel_dist.y) as f64).sqrt();
|
||||
if pixel_dist < max_pixel_dist {
|
||||
let click_event = MouseWindowEvent::Click(
|
||||
0, TypedPoint2D(x as f32, y as f32));
|
||||
MouseButton::Left, TypedPoint2D(x as f32, y as f32));
|
||||
self.event_queue.borrow_mut().push(WindowEvent::MouseWindowEventClass(click_event));
|
||||
}
|
||||
}
|
||||
Some(_) => (),
|
||||
}
|
||||
MouseWindowEvent::MouseUp(0, TypedPoint2D(x as f32, y as f32))
|
||||
MouseWindowEvent::MouseUp(MouseButton::Left, TypedPoint2D(x as f32, y as f32))
|
||||
}
|
||||
};
|
||||
self.event_queue.borrow_mut().push(WindowEvent::MouseWindowEventClass(event));
|
||||
|
|
1
ports/gonk/Cargo.lock
generated
1
ports/gonk/Cargo.lock
generated
|
@ -15,6 +15,7 @@ dependencies = [
|
|||
"net 0.0.1",
|
||||
"profile 0.0.1",
|
||||
"script 0.0.1",
|
||||
"script_traits 0.0.1",
|
||||
"servo 0.0.1",
|
||||
"time 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
|
@ -20,6 +20,9 @@ path = "../../components/msg"
|
|||
[dependencies.script]
|
||||
path = "../../components/script"
|
||||
|
||||
[dependencies.script_traits]
|
||||
path = "../../components/script_traits"
|
||||
|
||||
[dependencies.net]
|
||||
path = "../../components/net"
|
||||
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use script_traits::MouseButton;
|
||||
|
||||
use std::path::Path;
|
||||
use std::mem::size_of;
|
||||
use std::mem::transmute;
|
||||
|
@ -167,9 +169,12 @@ fn read_input_device(device_path: &Path,
|
|||
if dist < 16 {
|
||||
let click_pt = TypedPoint2D(slotA.x as f32, slotA.y as f32);
|
||||
println!("Dispatching click!");
|
||||
sender.send(WindowEvent::MouseWindowEventClass(MouseWindowEvent::MouseDown(0, click_pt))).ok().unwrap();
|
||||
sender.send(WindowEvent::MouseWindowEventClass(MouseWindowEvent::MouseUp(0, click_pt))).ok().unwrap();
|
||||
sender.send(WindowEvent::MouseWindowEventClass(MouseWindowEvent::Click(0, click_pt))).ok().unwrap();
|
||||
sender.send(WindowEvent::MouseWindowEventClass(MouseWindowEvent::MouseDown(MouseButton::Left, click_pt)))
|
||||
.ok().unwrap();
|
||||
sender.send(WindowEvent::MouseWindowEventClass(MouseWindowEvent::MouseUp(MouseButton::Left, click_pt)))
|
||||
.ok().unwrap();
|
||||
sender.send(WindowEvent::MouseWindowEventClass(MouseWindowEvent::Click(MouseButton::Left, click_pt)))
|
||||
.ok().unwrap();
|
||||
}
|
||||
} else {
|
||||
println!("Touch down");
|
||||
|
|
|
@ -16,6 +16,7 @@ extern crate time;
|
|||
extern crate util;
|
||||
|
||||
extern crate compositing;
|
||||
extern crate script_traits;
|
||||
|
||||
extern crate geom;
|
||||
extern crate libc;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue