servo: Merge #5492 - Introduce a MouseButton enum (from Ms2ger:MouseButton)
authorMs2ger <ms2ger@gmail.com>
Fri, 03 Apr 2015 13:29:12 +0200
changeset 382715 fa7a19695b303b4a6375e7549e9244adb6217129
parent 382714 17d488a5e794d54b6e6b125bfcfdbd6f00620170
child 382716 af6e034da8fa19c4aae402d02552e52bcb61f93c
push id7198
push userjlorenzo@mozilla.com
push dateTue, 18 Apr 2017 12:07:49 +0000
treeherdermozilla-beta@d57aa49c3948 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
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
servo/components/compositing/lib.rs
servo/components/compositing/windowing.rs
servo/components/script/dom/document.rs
servo/components/script/script_task.rs
servo/components/script_traits/lib.rs
servo/components/servo/Cargo.lock
servo/ports/cef/Cargo.lock
servo/ports/cef/Cargo.toml
servo/ports/cef/browser_host.rs
servo/ports/cef/lib.rs
servo/ports/glutin/Cargo.toml
servo/ports/glutin/lib.rs
servo/ports/glutin/window.rs
servo/ports/gonk/Cargo.lock
servo/ports/gonk/Cargo.toml
servo/ports/gonk/src/input.rs
servo/ports/gonk/src/main.rs
--- a/servo/components/compositing/compositor_layer.rs
+++ b/servo/components/compositing/compositor_layer.rs
@@ -44,17 +44,17 @@ pub struct CompositorData {
     /// The scroll offset originating from this scrolling root. This allows scrolling roots
     /// to track their current scroll position even while their content_offset does not change.
     pub scroll_offset: TypedPoint2D<LayerPixel, f32>,
 }
 
 impl CompositorData {
     pub fn new_layer(layer_properties: LayerProperties,
                      wants_scroll_events: WantsScrollEventsFlag,
-                     tile_size: uint)
+                     tile_size: usize)
                      -> Rc<Layer<CompositorData>> {
         let new_compositor_data = CompositorData {
             pipeline_id: layer_properties.pipeline_id,
             id: layer_properties.id,
             wants_scroll_events: wants_scroll_events,
             scroll_policy: layer_properties.scroll_policy,
             epoch: layer_properties.epoch,
             scroll_offset: TypedPoint2D(0., 0.),
--- a/servo/components/compositing/lib.rs
+++ b/servo/components/compositing/lib.rs
@@ -1,15 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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(box_syntax)]
 #![feature(core)]
-#![feature(int_uint)]
 #![feature(io)]
 #![feature(old_io)]
 #![feature(rustc_private)]
 #![feature(std_misc)]
 
 #[macro_use]
 extern crate log;
 
--- a/servo/components/compositing/windowing.rs
+++ b/servo/components/compositing/windowing.rs
@@ -8,27 +8,28 @@ use compositor_task::{CompositorProxy, C
 
 use geom::point::TypedPoint2D;
 use geom::scale_factor::ScaleFactor;
 use geom::size::TypedSize2D;
 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;
 use std::fmt::{Error, Formatter, Debug};
 use std::rc::Rc;
 
 #[derive(Clone)]
 pub enum MouseWindowEvent {
-    Click(uint, TypedPoint2D<DevicePixel, f32>),
-    MouseDown(uint, TypedPoint2D<DevicePixel, f32>),
-    MouseUp(uint, TypedPoint2D<DevicePixel, f32>),
+    Click(MouseButton, TypedPoint2D<DevicePixel, f32>),
+    MouseDown(MouseButton, TypedPoint2D<DevicePixel, f32>),
+    MouseUp(MouseButton, TypedPoint2D<DevicePixel, f32>),
 }
 
 #[derive(Clone)]
 pub enum WindowNavigateMsg {
     Forward,
     Back,
 }
 
--- a/servo/components/script/dom/document.rs
+++ b/servo/components/script/dom/document.rs
@@ -61,17 +61,17 @@ use dom::window::{Window, WindowHelpers,
 use layout_interface::{HitTestResponse, MouseOverResponse};
 use msg::compositor_msg::ScriptListener;
 use msg::constellation_msg::Msg as ConstellationMsg;
 use msg::constellation_msg::{ConstellationChan, Key, KeyState, KeyModifiers, MozBrowserEvent};
 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};
 
 use geom::point::Point2D;
 use html5ever::tree_builder::{QuirksMode, NoQuirks, LimitedQuirks, Quirks};
 use layout_interface::{LayoutChan, Msg};
 use string_cache::{Atom, QualName};
@@ -211,17 +211,18 @@ pub trait DocumentHelpers<'a> {
     fn get_focused_element(self) -> Option<Temporary<Element>>;
     fn is_scripting_enabled(self) -> bool;
     fn begin_focus_transaction(self);
     fn request_focus(self, elem: JSRef<Element>);
     fn commit_focus_transaction(self);
     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<f32>);
+    fn handle_click_event(self, js_runtime: *mut JSRuntime,
+                          button: MouseButton, point: Point2D<f32>);
     fn dispatch_key_event(self, key: Key, state: KeyState,
         modifiers: KeyModifiers, compositor: &mut Box<ScriptListener+'static>);
 
     /// Handles a mouse-move event coming from the compositor.
     fn handle_mouse_move_event(self,
                                js_runtime: *mut JSRuntime,
                                point: Point2D<f32>,
                                prev_mouse_over_targets: &mut Vec<JS<Node>>);
@@ -475,17 +476,18 @@ impl<'a> DocumentHelpers<'a> for JSRef<'
 
     fn dirty_all_nodes(self) {
         let root: JSRef<Node> = NodeCast::from_ref(self);
         for node in root.traverse_preorder() {
             node.dirty(NodeDamage::OtherNodeDamage)
         }
     }
 
-    fn handle_click_event(self, js_runtime: *mut JSRuntime, _button: uint, point: Point2D<f32>) {
+    fn handle_click_event(self, js_runtime: *mut JSRuntime,
+                          _button: MouseButton, point: Point2D<f32>) {
         debug!("ClickEvent: clicked at {:?}", point);
         let node = match self.hit_test(&point) {
             Some(node_address) => {
                 debug!("node address is {:?}", node_address.0);
                 node::from_untrusted_node_address(js_runtime, node_address)
             },
             None => return,
         }.root();
--- a/servo/components/script/script_task.rs
+++ b/servo/components/script/script_task.rs
@@ -1200,20 +1200,20 @@ impl ScriptTask {
                     let document = page.document().root();
                     document.r().content_changed(node_to_dirty.r(),
                                                  NodeDamage::OtherNodeDamage);
                 }
 
                 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(..) => {}
             MouseUpEvent(..) => {}
             MouseMoveEvent(point) => {
                 let page = get_page(&self.root_page(), pipeline_id);
                 let document = page.document().root();
                 let mouse_over_targets = &mut *self.mouse_over_targets.borrow_mut();
--- a/servo/components/script_traits/lib.rs
+++ b/servo/components/script_traits/lib.rs
@@ -1,14 +1,12 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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;
 extern crate msg;
 extern crate net;
 extern crate util;
 extern crate url;
 
@@ -76,23 +74,31 @@ pub enum ConstellationControlMsg {
     MozBrowserEventMsg(PipelineId, SubpageId, MozBrowserEvent),
     /// Updates the current subpage id of a given iframe
     UpdateSubpageId(PipelineId, SubpageId, SubpageId),
 }
 
 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<UntrustedNodeAddress>),
-    ClickEvent(uint, Point2D<f32>),
-    MouseDownEvent(uint, Point2D<f32>),
-    MouseUpEvent(uint, Point2D<f32>),
+    ClickEvent(MouseButton, Point2D<f32>),
+    MouseDownEvent(MouseButton, Point2D<f32>),
+    MouseUpEvent(MouseButton, Point2D<f32>),
     MouseMoveEvent(Point2D<f32>),
     KeyEvent(Key, KeyState, KeyModifiers),
 }
 
 /// An opaque wrapper around script<->layout channels to avoid leaking message types into
 /// crates that don't need to know about them.
 pub struct OpaqueScriptLayoutChannel(pub (Box<Any+Send>, Box<Any+Send>));
 
--- a/servo/components/servo/Cargo.lock
+++ b/servo/components/servo/Cargo.lock
@@ -393,16 +393,17 @@ dependencies = [
  "compositing 0.0.1",
  "egl 0.1.0 (git+https://github.com/servo/rust-egl)",
  "geom 0.1.0 (git+https://github.com/servo/rust-geom)",
  "gleam 0.0.1 (git+https://github.com/servo/gleam)",
  "glutin 0.0.7 (git+https://github.com/servo/glutin?branch=servo)",
  "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",
 ]
 
 [[package]]
 name = "glx"
 version = "0.0.1"
--- a/servo/ports/cef/Cargo.lock
+++ b/servo/ports/cef/Cargo.lock
@@ -16,16 +16,17 @@ dependencies = [
  "js 0.1.0 (git+https://github.com/servo/rust-mozjs)",
  "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",
  "net 0.0.1",
  "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",
  "url 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
  "util 0.0.1",
 ]
 
 [[package]]
@@ -398,16 +399,17 @@ dependencies = [
  "compositing 0.0.1",
  "egl 0.1.0 (git+https://github.com/servo/rust-egl)",
  "geom 0.1.0 (git+https://github.com/servo/rust-geom)",
  "gleam 0.0.1 (git+https://github.com/servo/gleam)",
  "glutin 0.0.7 (git+https://github.com/servo/glutin?branch=servo)",
  "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",
 ]
 
 [[package]]
 name = "glx"
 version = "0.0.1"
--- a/servo/ports/cef/Cargo.toml
+++ b/servo/ports/cef/Cargo.toml
@@ -21,16 +21,19 @@ path = "../../components/plugins"
 path = "../../components/compositing"
 
 [dependencies.gfx]
 path = "../../components/gfx"
 
 [dependencies.script]
 path = "../../components/script"
 
+[dependencies.script_traits]
+path = "../../components/script_traits"
+
 [dependencies.net]
 path = "../../components/net"
 
 [dependencies.msg]
 path = "../../components/msg"
 
 [dependencies.util]
 path = "../../components/util"
--- a/servo/ports/cef/browser_host.rs
+++ b/servo/ports/cef/browser_host.rs
@@ -8,16 +8,17 @@ use types::{cef_mouse_button_type_t, cef
 use types::cef_key_event_type_t::{KEYEVENT_CHAR, KEYEVENT_KEYDOWN, KEYEVENT_KEYUP, KEYEVENT_RAWKEYDOWN};
 use browser::{self, ServoCefBrowserExtensions};
 
 use compositing::windowing::{WindowEvent, MouseWindowEvent};
 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 {
     /// A reference to the browser.
     pub browser: RefCell<Option<CefBrowser>>,
     /// A reference to the client.
     pub client: CefClient,
 }
@@ -105,17 +106,21 @@ full_cef_class_impl! {
                                   event: *const cef_mouse_event [&cef_mouse_event],
                                   mouse_button_type: cef_mouse_button_type_t [cef_mouse_button_type_t],
                                   mouse_up: c_int [c_int],
                                   _click_count: c_int [c_int],)
                                   -> () {{
             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(
                     MouseWindowEvent::Click(button_type, point)))
             } else {
                 this.downcast().send_window_event(WindowEvent::MouseWindowEventClass(
                     MouseWindowEvent::MouseUp(button_type, point)))
             }
--- a/servo/ports/cef/lib.rs
+++ b/servo/ports/cef/lib.rs
@@ -27,16 +27,17 @@ extern crate azure;
 extern crate geom;
 extern crate gfx;
 extern crate gleam;
 extern crate glutin_app;
 extern crate js;
 extern crate layers;
 extern crate png;
 extern crate script;
+extern crate script_traits;
 extern crate unicode;
 
 extern crate net;
 extern crate msg;
 extern crate util;
 extern crate style;
 extern crate stb_image;
 
--- a/servo/ports/glutin/Cargo.toml
+++ b/servo/ports/glutin/Cargo.toml
@@ -9,16 +9,19 @@ path = "lib.rs"
 
 [features]
 window = ["glutin/window"]
 headless = ["glutin/headless"]
 
 [dependencies.compositing]
 path = "../../components/compositing"
 
+[dependencies.script_traits]
+path = "../../components/script_traits"
+
 [dependencies.geom]
 git = "https://github.com/servo/rust-geom"
 
 [dependencies.layers]
 git = "https://github.com/servo/rust-layers"
 
 [dependencies.msg]
 path = "../../components/msg"
--- a/servo/ports/glutin/lib.rs
+++ b/servo/ports/glutin/lib.rs
@@ -12,16 +12,17 @@
 extern crate cgl;
 extern crate compositing;
 extern crate geom;
 extern crate gleam;
 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;
 extern crate url;
 
 use compositing::windowing::WindowEvent;
 use geom::scale_factor::ScaleFactor;
 use std::rc::Rc;
--- a/servo/ports/glutin/window.rs
+++ b/servo/ports/glutin/window.rs
@@ -219,40 +219,42 @@ impl Window {
         let mouse_pos = self.mouse_pos.get();
         let event = WindowEvent::Scroll(TypedPoint2D(dx as f32, dy as f32),
                                  TypedPoint2D(mouse_pos.x as i32, mouse_pos.y as i32));
         self.event_queue.borrow_mut().push(event);
     }
 
     /// 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() {
                     None => (),
                     Some(but) if button == but => {
                         let pixel_dist = self.mouse_down_point.get() - Point2D(x, y);
                         let pixel_dist = ((pixel_dist.x * pixel_dist.x +
                                            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));
     }
 
     pub fn wait_events(&self) -> WindowEvent {
         {
             let mut event_queue = self.event_queue.borrow_mut();
--- a/servo/ports/gonk/Cargo.lock
+++ b/servo/ports/gonk/Cargo.lock
@@ -10,16 +10,17 @@ dependencies = [
  "gleam 0.0.1 (git+https://github.com/servo/gleam)",
  "layers 0.1.0 (git+https://github.com/servo/rust-layers)",
  "layout 0.0.1",
  "libc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "msg 0.0.1",
  "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)",
  "util 0.0.1",
 ]
 
 [[package]]
 name = "azure"
--- a/servo/ports/gonk/Cargo.toml
+++ b/servo/ports/gonk/Cargo.toml
@@ -15,16 +15,19 @@ git = "https://github.com/servo/rust-geo
 git = "https://github.com/servo/rust-layers"
 
 [dependencies.msg]
 path = "../../components/msg"
 
 [dependencies.script]
 path = "../../components/script"
 
+[dependencies.script_traits]
+path = "../../components/script_traits"
+
 [dependencies.net]
 path = "../../components/net"
 
 [dependencies.gfx]
 path = "../../components/gfx"
 
 [dependencies.layout]
 path = "../../components/layout"
--- a/servo/ports/gonk/src/input.rs
+++ b/servo/ports/gonk/src/input.rs
@@ -1,12 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * 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;
 use std::mem::zeroed;
 use std::os::errno;
 use std::os::unix::AsRawFd;
 use std::num::Float;
 use std::fs::File;
@@ -162,19 +164,22 @@ fn read_input_device(device_path: &Path,
                         if slotA.tracking_id == -1 {
                             println!("Touch up");
                             let delta_x = slotA.x - first_x;
                             let delta_y = slotA.y - first_y;
                             let dist = delta_x * delta_x + delta_y * delta_y;
                             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");
                             last_x = slotA.x;
                             last_y = slotA.y;
                             first_x = slotA.x;
                             first_y = slotA.y;
                             if touch_count >= 2 {
--- a/servo/ports/gonk/src/main.rs
+++ b/servo/ports/gonk/src/main.rs
@@ -11,16 +11,17 @@
 // For FFI
 #![allow(non_snake_case, dead_code)]
 
 extern crate servo;
 extern crate time;
 extern crate util;
 
 extern crate compositing;
+extern crate script_traits;
 
 extern crate geom;
 extern crate libc;
 extern crate msg;
 extern crate gleam;
 extern crate layers;
 extern crate egl;
 extern crate url;