Bug 1304263 - On Windows, fire the eMouseLongTap event as soon as APZ detects the long-press. r?TYLin draft
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 03 Oct 2016 14:22:56 -0400
changeset 420219 0d0548965602f8cf6b4873bc3490661a8115b652
parent 420017 955840bfd3c20eb24dd5a01be27bdc55c489a285
child 532754 3f18e86e9747c4207db539aa8d5974d9b7665833
push id31132
push userkgupta@mozilla.com
push dateMon, 03 Oct 2016 18:23:51 +0000
reviewersTYLin
bugs1304263, 1147335
milestone52.0a1
Bug 1304263 - On Windows, fire the eMouseLongTap event as soon as APZ detects the long-press. r?TYLin On Windows, the contextmenu event is fired when the finger is lifted after a long-press. However, there are various bits of code, such as the AccessibleCaret or potential fixes for bug 1147335, which would benefit from knowing when the long-press gesture was detected. By moving eMouseLongTap event up we can satisfy that need. An alternative approach considered was to fire the eMouseLongTap before the contextmenu on all platforms unconditionally, but that makes it harder to implement platform-specific text selection behaviour the way we want. In particular we would have to add an extra message or notification for non-Windows platforms that initiated text selection if the contextmenu event was not consumed. MozReview-Commit-ID: 2X5zJc09ihj
gfx/layers/apz/util/APZEventState.cpp
mobile/android/app/mobile.js
modules/libpref/init/all.js
--- a/gfx/layers/apz/util/APZEventState.cpp
+++ b/gfx/layers/apz/util/APZEventState.cpp
@@ -225,27 +225,25 @@ APZEventState::FireContextmenuEvents(con
                          aPoint, 2, 1, WidgetModifiersToDOMModifiers(aModifiers), true,
                          nsIDOMMouseEvent::MOZ_SOURCE_TOUCH);
 
   APZES_LOG("Contextmenu event handled: %d\n", eventHandled);
   if (eventHandled) {
     // If the contextmenu event was handled then we're showing a contextmenu,
     // and so we should remove any activation
     mActiveElementManager->ClearActivation();
+#ifndef XP_WIN
   } else {
-    // If no one handle context menu, fire MOZLONGTAP event
-    LayoutDevicePoint ldPoint = aPoint * aScale;
-    int time = 0;
-    nsEventStatus status =
-        APZCCallbackHelper::DispatchSynthesizedMouseEvent(eMouseLongTap, time,
-                                                          ldPoint, aModifiers,
-                                                          /*clickCount*/ 1,
-                                                          aWidget);
+    // If the contextmenu wasn't consumed, fire the eMouseLongTap event.
+    nsEventStatus status = APZCCallbackHelper::DispatchSynthesizedMouseEvent(
+        eMouseLongTap, /*time*/ 0, aPoint * aScale, aModifiers,
+        /*clickCount*/ 1, aWidget);
     eventHandled = (status == nsEventStatus_eConsumeNoDefault);
-    APZES_LOG("MOZLONGTAP event handled: %d\n", eventHandled);
+    APZES_LOG("eMouseLongTap event handled: %d\n", eventHandled);
+#endif
   }
 
   return eventHandled;
 }
 
 void
 APZEventState::ProcessLongTap(const nsCOMPtr<nsIPresShell>& aPresShell,
                               const CSSPoint& aPoint,
@@ -261,18 +259,24 @@ APZEventState::ProcessLongTap(const nsCO
     return;
   }
 
   SendPendingTouchPreventedResponse(false);
 
 #ifdef XP_WIN
   // On Windows, we fire the contextmenu events when the user lifts their
   // finger, in keeping with the platform convention. This happens in the
-  // ProcessLongTapUp function.
-  bool eventHandled = false;
+  // ProcessLongTapUp function. However, we still fire the eMouseLongTap event
+  // at this time, because things like text selection or dragging may want
+  // to know about it.
+  nsEventStatus status = APZCCallbackHelper::DispatchSynthesizedMouseEvent(
+      eMouseLongTap, /*time*/ 0, aPoint * aScale, aModifiers, /*clickCount*/ 1,
+      widget);
+
+  bool eventHandled = (status == nsEventStatus_eConsumeNoDefault);
 #else
   bool eventHandled = FireContextmenuEvents(aPresShell, aPoint, aScale,
         aModifiers, widget);
 #endif
   mContentReceivedInputBlockCallback(aGuid, aInputBlockId, eventHandled);
 
   if (eventHandled) {
     // Also send a touchcancel to content, so that listeners that might be
--- a/mobile/android/app/mobile.js
+++ b/mobile/android/app/mobile.js
@@ -843,19 +843,16 @@ pref("layout.accessiblecaret.enabled", t
 // AccessibleCaret CSS for the Android L style assets.
 pref("layout.accessiblecaret.width", "22.0");
 pref("layout.accessiblecaret.height", "22.0");
 pref("layout.accessiblecaret.margin-left", "-11.5");
 
 // Android needs to show the caret when long tapping on an empty content.
 pref("layout.accessiblecaret.caret_shown_when_long_tapping_on_empty_content", true);
 
-// Android generates long tap (mouse) events.
-pref("layout.accessiblecaret.use_long_tap_injector", false);
-
 // Androids carets are always tilt to match the text selection guideline.
 pref("layout.accessiblecaret.always_tilt", true);
 
 // Selection change notifications generated by Javascript changes
 // update active AccessibleCarets / UI interactions.
 pref("layout.accessiblecaret.allow_script_change_updates", true);
 
 // Optionally provide haptic feedback on longPress selection events.
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -5233,17 +5233,17 @@ pref("layout.accessiblecaret.bar.enabled
 pref("layout.accessiblecaret.caret_shown_when_long_tapping_on_empty_content", false);
 
 // Timeout in milliseconds to hide the accessiblecaret under cursor mode while
 // no one touches it. Set the value to 0 to disable this feature.
 pref("layout.accessiblecaret.timeout_ms", 0);
 
 // Simulate long tap to select words on the platforms where APZ is not enabled
 // or long tap events does not fired by APZ.
-pref("layout.accessiblecaret.use_long_tap_injector", true);
+pref("layout.accessiblecaret.use_long_tap_injector", false);
 
 // By default, carets become tilt only when they are overlapping.
 pref("layout.accessiblecaret.always_tilt", false);
 
 // By default, carets always show when scrolling (either panning for zooming)
 // the page.
 pref("layout.accessiblecaret.always_show_when_scrolling", true);