Bug 1449564 - part 3: Make absolute position editor listen to mouse events at the system event group r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Thu, 05 Apr 2018 00:32:32 +0900
changeset 777694 cf9b6929b8106c453b00236e692956fd4d6ca186
parent 777693 094d1ed044e170d9dd8d24582c76018c63f67e5c
push id105264
push usermasayuki@d-toybox.com
push dateThu, 05 Apr 2018 05:23:22 +0000
reviewersm_kato
bugs1449564
milestone61.0a1
Bug 1449564 - part 3: Make absolute position editor listen to mouse events at the system event group r?m_kato Currently, absolute position editor listens to mouse events at the default event group to handle dragging of positioner. However, this is blocked by a call of Event.stopPropagation() in web apps unexpectedly. Therefore, we should make it listen to the events at the system event group instead. MozReview-Commit-ID: Hoa8c9QvMuG
editor/libeditor/HTMLAbsPositionEditor.cpp
editor/libeditor/tests/test_abs_positioner_positioning_elements.html
--- a/editor/libeditor/HTMLAbsPositionEditor.cpp
+++ b/editor/libeditor/HTMLAbsPositionEditor.cpp
@@ -206,29 +206,31 @@ HTMLEditor::GetZIndex(Element& aElement)
   nsresult errorCode;
   return zIndexStr.ToInteger(&errorCode);
 }
 
 ManualNACPtr
 HTMLEditor::CreateGrabber(nsIContent& aParentContent)
 {
   // let's create a grabber through the element factory
-  ManualNACPtr ret =
+  ManualNACPtr grabber =
     CreateAnonymousElement(nsGkAtoms::span, aParentContent,
                            NS_LITERAL_STRING("mozGrabber"), false);
-  if (NS_WARN_IF(!ret)) {
+  if (NS_WARN_IF(!grabber)) {
     return nullptr;
   }
 
   // add the mouse listener so we can detect a click on a resizer
-  nsCOMPtr<nsIDOMEventTarget> evtTarget = do_QueryInterface(ret);
-  evtTarget->AddEventListener(NS_LITERAL_STRING("mousedown"),
-                              mEventListener, false);
-
-  return ret;
+  EventListenerManager* eventListenerManager =
+    grabber->GetOrCreateListenerManager();
+  eventListenerManager->AddEventListenerByType(
+                          mEventListener,
+                          NS_LITERAL_STRING("mousedown"),
+                          TrustedEventsAtSystemGroupBubble());
+  return grabber;
 }
 
 NS_IMETHODIMP
 HTMLEditor::RefreshGrabber()
 {
   NS_ENSURE_TRUE(mAbsolutelyPositionedObject, NS_ERROR_NULL_POINTER);
 
   nsresult rv =
@@ -351,51 +353,52 @@ HTMLEditor::SnapToGrid(int32_t& newX, in
 }
 
 nsresult
 HTMLEditor::GrabberClicked()
 {
   // add a mouse move listener to the editor
   nsresult rv = NS_OK;
   if (!mMouseMotionListenerP) {
+    EventTarget* eventTarget = GetDOMEventTarget();
+    if (NS_WARN_IF(!eventTarget)) {
+      return NS_ERROR_FAILURE;
+    }
     mMouseMotionListenerP = new ResizerMouseMotionListener(*this);
-    if (!mMouseMotionListenerP) {return NS_ERROR_NULL_POINTER;}
-
-    nsIDOMEventTarget* piTarget = GetDOMEventTarget();
-    NS_ENSURE_TRUE(piTarget, NS_ERROR_FAILURE);
-
-    rv = piTarget->AddEventListener(NS_LITERAL_STRING("mousemove"),
-                                     mMouseMotionListenerP,
-                                     false, false);
-    NS_ASSERTION(NS_SUCCEEDED(rv),
-                 "failed to register mouse motion listener");
+    EventListenerManager* eventListenerManager =
+      eventTarget->GetOrCreateListenerManager();
+    eventListenerManager->AddEventListenerByType(
+                            mMouseMotionListenerP,
+                            NS_LITERAL_STRING("mousemove"),
+                            TrustedEventsAtSystemGroupBubble());
   }
   mGrabberClicked = true;
   return rv;
 }
 
 nsresult
 HTMLEditor::EndMoving()
 {
   if (mPositioningShadow) {
     nsCOMPtr<nsIPresShell> ps = GetPresShell();
     NS_ENSURE_TRUE(ps, NS_ERROR_NOT_INITIALIZED);
 
     DeleteRefToAnonymousNode(Move(mPositioningShadow), ps);
 
     mPositioningShadow = nullptr;
   }
-  nsCOMPtr<nsIDOMEventTarget> piTarget = GetDOMEventTarget();
 
-  if (piTarget && mMouseMotionListenerP) {
-    DebugOnly<nsresult> rv =
-      piTarget->RemoveEventListener(NS_LITERAL_STRING("mousemove"),
-                                    mMouseMotionListenerP,
-                                    false);
-    NS_ASSERTION(NS_SUCCEEDED(rv), "failed to remove mouse motion listener");
+  EventTarget* eventTarget = GetDOMEventTarget();
+  if (eventTarget && mMouseMotionListenerP) {
+    EventListenerManager* eventListenerManager =
+      eventTarget->GetOrCreateListenerManager();
+    eventListenerManager->RemoveEventListenerByType(
+                            mMouseMotionListenerP,
+                            NS_LITERAL_STRING("mousemove"),
+                            TrustedEventsAtSystemGroupBubble());
   }
   mMouseMotionListenerP = nullptr;
 
   mGrabberClicked = false;
   mIsMoving = false;
   RefPtr<Selection> selection = GetSelection();
   if (!selection) {
     return NS_ERROR_NOT_INITIALIZED;
--- a/editor/libeditor/tests/test_abs_positioner_positioning_elements.html
+++ b/editor/libeditor/tests/test_abs_positioner_positioning_elements.html
@@ -23,17 +23,17 @@
 SimpleTest.waitForExplicitFinish();
 SimpleTest.waitForFocus(async function() {
   document.execCommand("enableAbsolutePositionEditing", false, true);
   ok(document.queryCommandState("enableAbsolutePositionEditing"),
      "Absolute positioned element editor should be enabled by the call of execCommand");
 
   let outOfEditor = document.getElementById("clickaway");
 
-  function cancel(e) { /* TODO: e.stopPropagation(); */ }
+  function cancel(e) { e.stopPropagation(); }
   let content = document.getElementById("content");
   content.addEventListener("mousedown", cancel);
   content.addEventListener("mousemove", cancel);
   content.addEventListener("mouseup", cancel);
 
   async function waitForSelectionChange() {
     return new Promise(resolve => {
       document.addEventListener("selectionchange", () => {