From 817eed22d13f8ebe3059fee6692ccfd96a71abbc Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Fri, 14 Aug 2015 07:25:43 -0700 Subject: [PATCH] Add a "-Z convert-mouse-to-touch" debug argument. This is enabled by default on Android, because Glutin currently sends mouse events instead of touch events on Android. It's also useful for testing on non-touch platforms. --- components/compositing/compositor.rs | 18 ++++++++++++++++-- components/util/opts.rs | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/components/compositing/compositor.rs b/components/compositing/compositor.rs index 0b44a715e88..3482d730be4 100644 --- a/components/compositing/compositor.rs +++ b/components/compositing/compositor.rs @@ -1123,7 +1123,16 @@ impl IOCompositor { chan.send(msg).unwrap() } - fn on_mouse_window_event_class(&self, mouse_window_event: MouseWindowEvent) { + fn on_mouse_window_event_class(&mut self, mouse_window_event: MouseWindowEvent) { + if opts::get().convert_mouse_to_touch { + match mouse_window_event { + MouseWindowEvent::Click(_, _) => {} + MouseWindowEvent::MouseDown(_, p) => self.on_touch_down(0, p), + MouseWindowEvent::MouseUp(_, p) => self.on_touch_up(0, p), + } + return + } + let point = match mouse_window_event { MouseWindowEvent::Click(_, p) => p, MouseWindowEvent::MouseDown(_, p) => p, @@ -1135,7 +1144,12 @@ impl IOCompositor { } } - fn on_mouse_window_move_event_class(&self, cursor: TypedPoint2D) { + fn on_mouse_window_move_event_class(&mut self, cursor: TypedPoint2D) { + if opts::get().convert_mouse_to_touch { + self.on_touch_move(0, cursor); + return + } + match self.find_topmost_layer_at_point(cursor / self.scene.scale) { Some(result) => result.layer.send_mouse_move_event(self, result.point), None => {}, diff --git a/components/util/opts.rs b/components/util/opts.rs index ea1d9609264..785f5909240 100644 --- a/components/util/opts.rs +++ b/components/util/opts.rs @@ -168,6 +168,9 @@ pub struct Opts { /// Whether to run absolute position calculation and display list construction in parallel. pub parallel_display_list_building: bool, + /// Translate mouse input into touch events. + pub convert_mouse_to_touch: bool, + /// True to exit after the page load (`-x`). pub exit_after_load: bool, @@ -247,6 +250,9 @@ pub struct DebugOptions { /// Build display lists in parallel. pub parallel_display_list_building: bool, + /// Translate mouse input into touch events. + pub convert_mouse_to_touch: bool, + /// Replace unpaires surrogates in DOM strings with U+FFFD. /// See https://github.com/servo/servo/issues/6564 pub replace_surrogates: bool, @@ -260,6 +266,12 @@ impl DebugOptions { pub fn new(debug_string: &str) -> Result { let mut debug_options = DebugOptions::default(); + // FIXME: Glutin currently converts touch input to mouse events on Android. + // Convert it back to touch events. + if cfg!(target_os = "android") { + debug_options.convert_mouse_to_touch = true; + } + for option in debug_string.split(',') { match option { "help" => debug_options.help = true, @@ -283,6 +295,7 @@ impl DebugOptions { "validate-display-list-geometry" => debug_options.validate_display_list_geometry = true, "disable-share-style-cache" => debug_options.disable_share_style_cache = true, "parallel-display-list-building" => debug_options.parallel_display_list_building = true, + "convert-mouse-to-touch" => debug_options.convert_mouse_to_touch = true, "replace-surrogates" => debug_options.replace_surrogates = true, "gc-profile" => debug_options.gc_profile = true, "" => {}, @@ -326,6 +339,7 @@ pub fn print_debug_usage(app: &str) -> ! { print_option("replace-surrogates", "Replace unpaires surrogates in DOM strings with U+FFFD. \ See https://github.com/servo/servo/issues/6564"); print_option("gc-profile", "Log GC passes and their durations."); + print_option("convert-mouse-to-touch", "Send touch events instead of mouse events"); println!(""); @@ -422,6 +436,7 @@ pub fn default_opts() -> Opts { sniff_mime_types: false, disable_share_style_cache: false, parallel_display_list_building: false, + convert_mouse_to_touch: false, exit_after_load: false, no_native_titlebar: false, } @@ -628,6 +643,7 @@ pub fn from_cmdline_args(args: &[String]) { sniff_mime_types: opt_match.opt_present("sniff-mime-types"), disable_share_style_cache: debug_options.disable_share_style_cache, parallel_display_list_building: debug_options.parallel_display_list_building, + convert_mouse_to_touch: debug_options.convert_mouse_to_touch, exit_after_load: opt_match.opt_present("x"), no_native_titlebar: opt_match.opt_present("b"), };