Bug 1337718 part.8 Make EditorEventListener::NotifyIMEOfMouseButtonEvent() take WidgetMouseEvent* instead of nsIDOMMouseEvent* r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 08 Feb 2017 22:19:14 +0900
changeset 481128 748d9dddd895477ac20cf537855f2c2ebae6f67b
parent 481127 ee77012f199725d5d969b35dee3f63eb2886ae31
child 481129 66073c830fdb376ef52fd3bf5878edde04e268d6
push id44730
push usermasayuki@d-toybox.com
push dateThu, 09 Feb 2017 09:50:16 +0000
reviewersm_kato
bugs1337718
milestone54.0a1
Bug 1337718 part.8 Make EditorEventListener::NotifyIMEOfMouseButtonEvent() take WidgetMouseEvent* instead of nsIDOMMouseEvent* r?m_kato MozReview-Commit-ID: A53lxmDXLMb
editor/libeditor/EditorEventListener.cpp
editor/libeditor/EditorEventListener.h
--- a/editor/libeditor/EditorEventListener.cpp
+++ b/editor/libeditor/EditorEventListener.cpp
@@ -401,46 +401,51 @@ EditorEventListener::HandleEvent(nsIDOME
     case eKeyUp:
       return KeyUp(internalEvent->AsKeyboardEvent());
 #endif // #ifdef HANDLE_NATIVE_TEXT_DIRECTION_SWITCH
     // keypress
     case eKeyPress:
       return KeyPress(internalEvent->AsKeyboardEvent());
     // mousedown
     case eMouseDown: {
-      nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent);
-      NS_ENSURE_TRUE(mouseEvent, NS_OK);
       // EditorEventListener may receive (1) all mousedown, mouseup and click
       // events, (2) only mousedown event or (3) only mouseup event.
       // mMouseDownOrUpConsumedByIME is used only for ignoring click event if
       // preceding mousedown and/or mouseup event is consumed by IME.
       // Therefore, even if case #2 or case #3 occurs,
       // mMouseDownOrUpConsumedByIME is true here.  Therefore, we should always
       // overwrite it here.
-      mMouseDownOrUpConsumedByIME = NotifyIMEOfMouseButtonEvent(mouseEvent);
-      return mMouseDownOrUpConsumedByIME ? NS_OK : MouseDown(mouseEvent);
+      mMouseDownOrUpConsumedByIME =
+        NotifyIMEOfMouseButtonEvent(internalEvent->AsMouseEvent());
+      if (mMouseDownOrUpConsumedByIME) {
+        return NS_OK;
+      }
+      nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent);
+      return NS_WARN_IF(!mouseEvent) ? NS_OK : MouseDown(mouseEvent);
     }
     // mouseup
     case eMouseUp: {
-      nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent);
-      NS_ENSURE_TRUE(mouseEvent, NS_OK);
       // See above comment in the eMouseDown case, first.
       // This code assumes that case #1 is occuring.  However, if case #3 may
       // occurs after case #2 and the mousedown is consumed,
       // mMouseDownOrUpConsumedByIME is true even though EditorEventListener
       // has not received the preceding mousedown event of this mouseup event.
       // So, mMouseDownOrUpConsumedByIME may be invalid here.  However,
       // this is not a matter because mMouseDownOrUpConsumedByIME is referred
       // only by eMouseClick case but click event is fired only in case #1.
       // So, before a click event is fired, mMouseDownOrUpConsumedByIME is
       // always initialized in the eMouseDown case if it's referred.
-      if (NotifyIMEOfMouseButtonEvent(mouseEvent)) {
+      if (NotifyIMEOfMouseButtonEvent(internalEvent->AsMouseEvent())) {
         mMouseDownOrUpConsumedByIME = true;
       }
-      return mMouseDownOrUpConsumedByIME ? NS_OK : MouseUp(mouseEvent);
+      if (mMouseDownOrUpConsumedByIME) {
+        return NS_OK;
+      }
+      nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent);
+      return NS_WARN_IF(!mouseEvent) ? NS_OK : MouseUp(mouseEvent);
     }
     // click
     case eMouseClick: {
       nsCOMPtr<nsIDOMMouseEvent> mouseEvent = do_QueryInterface(aEvent);
       NS_ENSURE_TRUE(mouseEvent, NS_OK);
       // If the preceding mousedown event or mouseup event was consumed,
       // editor shouldn't handle this click event.
       if (mMouseDownOrUpConsumedByIME) {
@@ -736,31 +741,29 @@ EditorEventListener::HandleMiddleClickPa
   aMouseEvent->AsEvent()->PreventDefault();
 
   // We processed the event, whether drop/paste succeeded or not
   return NS_OK;
 }
 
 bool
 EditorEventListener::NotifyIMEOfMouseButtonEvent(
-                       nsIDOMMouseEvent* aMouseEvent)
+                       WidgetMouseEvent* aMouseEvent)
 {
   MOZ_ASSERT(aMouseEvent);
 
   if (!EditorHasFocus()) {
     return false;
   }
 
   nsPresContext* presContext = GetPresContext();
   NS_ENSURE_TRUE(presContext, false);
-  WidgetMouseEvent* mouseEvent =
-    aMouseEvent->AsEvent()->WidgetEventPtr()->AsMouseEvent();
   return IMEStateManager::OnMouseButtonEventInEditor(presContext,
                                                      GetFocusedRootContent(),
-                                                     mouseEvent);
+                                                     aMouseEvent);
 }
 
 nsresult
 EditorEventListener::MouseDown(nsIDOMMouseEvent* aMouseEvent)
 {
   // FYI: We don't need to check if it's already consumed here because
   //      we need to commit composition at mouse button operation.
   // FYI: This may be called by HTMLEditorEventListener::MouseDown() even
--- a/editor/libeditor/EditorEventListener.h
+++ b/editor/libeditor/EditorEventListener.h
@@ -75,17 +75,17 @@ protected:
   nsresult Drop(nsIDOMDragEvent* aDragEvent);
 
   bool CanDrop(nsIDOMDragEvent* aEvent);
   void CleanupDragDropCaret();
   already_AddRefed<nsIPresShell> GetPresShell();
   nsPresContext* GetPresContext();
   nsIContent* GetFocusedRootContent();
   // Returns true if IME consumes the mouse event.
-  bool NotifyIMEOfMouseButtonEvent(nsIDOMMouseEvent* aMouseEvent);
+  bool NotifyIMEOfMouseButtonEvent(WidgetMouseEvent* aMouseEvent);
   bool EditorHasFocus();
   bool IsFileControlTextBox();
   bool ShouldHandleNativeKeyBindings(WidgetKeyboardEvent* aKeyboardEvent);
   nsresult HandleMiddleClickPaste(nsIDOMMouseEvent* aMouseEvent);
 
   /**
    * DetachedFromEditor() returns true if editor was detached.
    * Otherwise, false.