From e137b3f89d2c977c478836ab59c6ffcae2c08a38 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Fri, 3 Apr 2015 13:29:12 +0200 Subject: [PATCH] servo: Merge #5492 - Introduce a MouseButton enum (from Ms2ger:MouseButton) Source-Repo: https://github.com/servo/servo Source-Revision: 02be76bd4855a226669e8fcd1a638ff53e8f83d5 --- servo/components/compositing/compositor_layer.rs | 2 +- servo/components/compositing/lib.rs | 1 - servo/components/compositing/windowing.rs | 7 ++++--- servo/components/script/dom/document.rs | 8 +++++--- servo/components/script/script_task.rs | 4 ++-- servo/components/script_traits/lib.rs | 16 +++++++++++----- servo/components/servo/Cargo.lock | 1 + servo/ports/cef/Cargo.lock | 2 ++ servo/ports/cef/Cargo.toml | 3 +++ servo/ports/cef/browser_host.rs | 7 ++++++- servo/ports/cef/lib.rs | 1 + servo/ports/glutin/Cargo.toml | 3 +++ servo/ports/glutin/lib.rs | 1 + servo/ports/glutin/window.rs | 8 +++++--- servo/ports/gonk/Cargo.lock | 1 + servo/ports/gonk/Cargo.toml | 3 +++ servo/ports/gonk/src/input.rs | 11 ++++++++--- servo/ports/gonk/src/main.rs | 1 + 18 files changed, 58 insertions(+), 22 deletions(-) diff --git a/servo/components/compositing/compositor_layer.rs b/servo/components/compositing/compositor_layer.rs index 33cec1761c5e..20912b13f9b3 100644 --- a/servo/components/compositing/compositor_layer.rs +++ b/servo/components/compositing/compositor_layer.rs @@ -49,7 +49,7 @@ pub struct CompositorData { impl CompositorData { pub fn new_layer(layer_properties: LayerProperties, wants_scroll_events: WantsScrollEventsFlag, - tile_size: uint) + tile_size: usize) -> Rc> { let new_compositor_data = CompositorData { pipeline_id: layer_properties.pipeline_id, diff --git a/servo/components/compositing/lib.rs b/servo/components/compositing/lib.rs index d8e2a2a95b8e..52095f364227 100644 --- a/servo/components/compositing/lib.rs +++ b/servo/components/compositing/lib.rs @@ -4,7 +4,6 @@ #![feature(box_syntax)] #![feature(core)] -#![feature(int_uint)] #![feature(io)] #![feature(old_io)] #![feature(rustc_private)] diff --git a/servo/components/compositing/windowing.rs b/servo/components/compositing/windowing.rs index 1990523dd2f9..852b97cc2e14 100644 --- a/servo/components/compositing/windowing.rs +++ b/servo/components/compositing/windowing.rs @@ -13,6 +13,7 @@ use layers::geometry::DevicePixel; use layers::platform::surface::NativeGraphicsMetadata; use msg::compositor_msg::{PaintState, ReadyState}; use msg::constellation_msg::{Key, KeyState, KeyModifiers}; +use script_traits::MouseButton; use url::Url; use util::cursor::Cursor; use util::geometry::ScreenPx; @@ -21,9 +22,9 @@ use std::rc::Rc; #[derive(Clone)] pub enum MouseWindowEvent { - Click(uint, TypedPoint2D), - MouseDown(uint, TypedPoint2D), - MouseUp(uint, TypedPoint2D), + Click(MouseButton, TypedPoint2D), + MouseDown(MouseButton, TypedPoint2D), + MouseUp(MouseButton, TypedPoint2D), } #[derive(Clone)] diff --git a/servo/components/script/dom/document.rs b/servo/components/script/dom/document.rs index e94ba0c0e789..ca3f75395019 100644 --- a/servo/components/script/dom/document.rs +++ b/servo/components/script/dom/document.rs @@ -66,7 +66,7 @@ use msg::constellation_msg::{SUPER, ALT, SHIFT, CONTROL}; use net::resource_task::ControlMsg::{SetCookiesForUrl, GetCookiesForUrl}; use net::cookie_storage::CookieSource::NonHTTP; use script_task::Runnable; -use script_traits::UntrustedNodeAddress; +use script_traits::{MouseButton, UntrustedNodeAddress}; use util::{opts, namespace}; use util::str::{DOMString, split_html_space_chars}; use layout_interface::{ReflowGoal, ReflowQueryType}; @@ -216,7 +216,8 @@ pub trait DocumentHelpers<'a> { fn title_changed(self); fn send_title_to_compositor(self); fn dirty_all_nodes(self); - fn handle_click_event(self, js_runtime: *mut JSRuntime, _button: uint, point: Point2D); + fn handle_click_event(self, js_runtime: *mut JSRuntime, + button: MouseButton, point: Point2D); fn dispatch_key_event(self, key: Key, state: KeyState, modifiers: KeyModifiers, compositor: &mut Box); @@ -480,7 +481,8 @@ impl<'a> DocumentHelpers<'a> for JSRef<'a, Document> { } } - fn handle_click_event(self, js_runtime: *mut JSRuntime, _button: uint, point: Point2D) { + fn handle_click_event(self, js_runtime: *mut JSRuntime, + _button: MouseButton, point: Point2D) { debug!("ClickEvent: clicked at {:?}", point); let node = match self.hit_test(&point) { Some(node_address) => { diff --git a/servo/components/script/script_task.rs b/servo/components/script/script_task.rs index 593bd40bdf04..ff69fabe760c 100644 --- a/servo/components/script/script_task.rs +++ b/servo/components/script/script_task.rs @@ -1205,10 +1205,10 @@ impl ScriptTask { self.handle_reflow_event(pipeline_id); } - ClickEvent(_button, point) => { + ClickEvent(button, point) => { let page = get_page(&self.root_page(), pipeline_id); let document = page.document().root(); - document.r().handle_click_event(self.js_runtime.ptr, _button, point); + document.r().handle_click_event(self.js_runtime.ptr, button, point); } MouseDownEvent(..) => {} diff --git a/servo/components/script_traits/lib.rs b/servo/components/script_traits/lib.rs index da93a143dc2f..626819ebea69 100644 --- a/servo/components/script_traits/lib.rs +++ b/servo/components/script_traits/lib.rs @@ -2,8 +2,6 @@ * 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/. */ -#![feature(int_uint)] - extern crate devtools_traits; extern crate geom; extern crate libc; @@ -81,13 +79,21 @@ pub enum ConstellationControlMsg { unsafe impl Send for ConstellationControlMsg { } +/// The mouse button involved in the event. +#[derive(Clone, Debug)] +pub enum MouseButton { + Left, + Middle, + Right, +} + /// Events from the compositor that the script task needs to know about pub enum CompositorEvent { ResizeEvent(WindowSizeData), ReflowEvent(SmallVec1), - ClickEvent(uint, Point2D), - MouseDownEvent(uint, Point2D), - MouseUpEvent(uint, Point2D), + ClickEvent(MouseButton, Point2D), + MouseDownEvent(MouseButton, Point2D), + MouseUpEvent(MouseButton, Point2D), MouseMoveEvent(Point2D), KeyEvent(Key, KeyState, KeyModifiers), } diff --git a/servo/components/servo/Cargo.lock b/servo/components/servo/Cargo.lock index b8bd6086f936..862b17b01dfe 100644 --- a/servo/components/servo/Cargo.lock +++ b/servo/components/servo/Cargo.lock @@ -398,6 +398,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", diff --git a/servo/ports/cef/Cargo.lock b/servo/ports/cef/Cargo.lock index 0d5cb75c18d4..f182a770fe71 100644 --- a/servo/ports/cef/Cargo.lock +++ b/servo/ports/cef/Cargo.lock @@ -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", diff --git a/servo/ports/cef/Cargo.toml b/servo/ports/cef/Cargo.toml index 913173eb1697..a8ea2e62517b 100644 --- a/servo/ports/cef/Cargo.toml +++ b/servo/ports/cef/Cargo.toml @@ -26,6 +26,9 @@ path = "../../components/gfx" [dependencies.script] path = "../../components/script" +[dependencies.script_traits] +path = "../../components/script_traits" + [dependencies.net] path = "../../components/net" diff --git a/servo/ports/cef/browser_host.rs b/servo/ports/cef/browser_host.rs index a12c0402da40..96804c770b5c 100644 --- a/servo/ports/cef/browser_host.rs +++ b/servo/ports/cef/browser_host.rs @@ -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( diff --git a/servo/ports/cef/lib.rs b/servo/ports/cef/lib.rs index 23e2b5b84575..040c5991e9bf 100644 --- a/servo/ports/cef/lib.rs +++ b/servo/ports/cef/lib.rs @@ -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; diff --git a/servo/ports/glutin/Cargo.toml b/servo/ports/glutin/Cargo.toml index ad71622a9a80..cdf0e9890a58 100644 --- a/servo/ports/glutin/Cargo.toml +++ b/servo/ports/glutin/Cargo.toml @@ -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" diff --git a/servo/ports/glutin/lib.rs b/servo/ports/glutin/lib.rs index ccf9570569c0..654d47a0ecc8 100644 --- a/servo/ports/glutin/lib.rs +++ b/servo/ports/glutin/lib.rs @@ -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; diff --git a/servo/ports/glutin/window.rs b/servo/ports/glutin/window.rs index fbc725407888..ea4858de7b71 100644 --- a/servo/ports/glutin/window.rs +++ b/servo/ports/glutin/window.rs @@ -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)); diff --git a/servo/ports/gonk/Cargo.lock b/servo/ports/gonk/Cargo.lock index d836bf44eb4e..a249d5477325 100644 --- a/servo/ports/gonk/Cargo.lock +++ b/servo/ports/gonk/Cargo.lock @@ -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)", diff --git a/servo/ports/gonk/Cargo.toml b/servo/ports/gonk/Cargo.toml index 4ab7d59b3772..6ecee4c39285 100644 --- a/servo/ports/gonk/Cargo.toml +++ b/servo/ports/gonk/Cargo.toml @@ -20,6 +20,9 @@ path = "../../components/msg" [dependencies.script] path = "../../components/script" +[dependencies.script_traits] +path = "../../components/script_traits" + [dependencies.net] path = "../../components/net" diff --git a/servo/ports/gonk/src/input.rs b/servo/ports/gonk/src/input.rs index 44640316f3d2..c10a6038ef52 100644 --- a/servo/ports/gonk/src/input.rs +++ b/servo/ports/gonk/src/input.rs @@ -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"); diff --git a/servo/ports/gonk/src/main.rs b/servo/ports/gonk/src/main.rs index 4aef94c4582e..b74809940629 100644 --- a/servo/ports/gonk/src/main.rs +++ b/servo/ports/gonk/src/main.rs @@ -16,6 +16,7 @@ extern crate time; extern crate util; extern crate compositing; +extern crate script_traits; extern crate geom; extern crate libc;