Bug 1461708 - part 6: Make EditorEventListener::MouseClick() use WidgetMouseEvent instead of dom::MouseEvent r=m_kato
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 10 Oct 2018 12:05:21 +0000
changeset 498897 a22e64bb83ed9873094e753df4f91e0f29853c13
parent 498896 95d15775e123f881124b1b0b239b2dd8f837bd0e
child 498898 0f2549de4e47ed8570b1e0a3f368bc82c17895b9
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersm_kato
bugs1461708
milestone64.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1461708 - part 6: Make EditorEventListener::MouseClick() use WidgetMouseEvent instead of dom::MouseEvent r=m_kato The event argument of only EditorEventListener::MouseClick() can be replaced with WidgetMouseEvent simply. So, for avoiding unnecessary RefPtr in EditorEventListener::HandleEvent(), we should fix this now. Differential Revision: https://phabricator.services.mozilla.com/D7853
editor/libeditor/EditorEventListener.cpp
editor/libeditor/EditorEventListener.h
editor/libeditor/HTMLEditorEventListener.cpp
editor/libeditor/HTMLEditorEventListener.h
--- a/editor/libeditor/EditorEventListener.cpp
+++ b/editor/libeditor/EditorEventListener.cpp
@@ -449,28 +449,28 @@ EditorEventListener::HandleEvent(Event* 
       if (mMouseDownOrUpConsumedByIME) {
         return NS_OK;
       }
       RefPtr<MouseEvent> mouseEvent = aEvent->AsMouseEvent();
       return NS_WARN_IF(!mouseEvent) ? NS_OK : MouseUp(mouseEvent);
     }
     // click
     case eMouseClick: {
-      RefPtr<MouseEvent> mouseEvent = aEvent->AsMouseEvent();
-      if (NS_WARN_IF(!mouseEvent)) {
+      WidgetMouseEvent* widgetMouseEvent = internalEvent->AsMouseEvent();
+      if (NS_WARN_IF(!widgetMouseEvent)) {
         return NS_OK;
       }
       // If the preceding mousedown event or mouseup event was consumed,
       // editor shouldn't handle this click event.
       if (mMouseDownOrUpConsumedByIME) {
         mMouseDownOrUpConsumedByIME = false;
-        mouseEvent->PreventDefault();
+        widgetMouseEvent->PreventDefault();
         return NS_OK;
       }
-      return MouseClick(mouseEvent);
+      return MouseClick(widgetMouseEvent);
     }
     // focus
     case eFocus:
       return Focus(internalEvent->AsFocusEvent());
     // blur
     case eBlur:
       return Blur(internalEvent->AsFocusEvent());
     // text
@@ -637,79 +637,78 @@ EditorEventListener::KeyPress(WidgetKeyb
                         nsIWidget::NativeKeyBindingsForRichTextEditor,
                         DoCommandCallback, doc)) {
     aKeyboardEvent->PreventDefault();
   }
   return NS_OK;
 }
 
 nsresult
-EditorEventListener::MouseClick(MouseEvent* aMouseEvent)
+EditorEventListener::MouseClick(WidgetMouseEvent* aMouseClickEvent)
 {
-  if (NS_WARN_IF(!aMouseEvent) || DetachedFromEditor()) {
+  if (NS_WARN_IF(!aMouseClickEvent) || DetachedFromEditor()) {
     return NS_OK;
   }
   // nothing to do if editor isn't editable or clicked on out of the editor.
   RefPtr<TextEditor> textEditor = mEditorBase->AsTextEditor();
-  WidgetMouseEvent* clickEvent =
-    aMouseEvent->WidgetEventPtr()->AsMouseEvent();
   if (textEditor->IsReadonly() || textEditor->IsDisabled() ||
-      !textEditor->IsAcceptableInputEvent(clickEvent)) {
+      !textEditor->IsAcceptableInputEvent(aMouseClickEvent)) {
     return NS_OK;
   }
 
   // Notifies clicking on editor to IMEStateManager even when the event was
   // consumed.
   if (EditorHasFocus()) {
     RefPtr<nsPresContext> presContext = GetPresContext();
     if (presContext) {
       IMEStateManager::OnClickInEditor(presContext, GetFocusedRootContent(),
-                                       clickEvent);
+                                       aMouseClickEvent);
       if (DetachedFromEditor()) {
         return NS_OK;
       }
     }
   }
 
-  if (DetachedFromEditorOrDefaultPrevented(clickEvent)) {
+  if (DetachedFromEditorOrDefaultPrevented(aMouseClickEvent)) {
     // We're done if 'preventdefault' is true (see for example bug 70698).
     return NS_OK;
   }
 
   // If we got a mouse down inside the editing area, we should force the
   // IME to commit before we change the cursor position
   if (!EnsureCommitCompoisition()) {
     return NS_OK;
   }
 
-  if (clickEvent->button != WidgetMouseEventBase::eMiddleButton ||
+  if (aMouseClickEvent->button != WidgetMouseEventBase::eMiddleButton ||
       !WidgetMouseEvent::IsMiddleClickPasteEnabled()) {
     return NS_OK;
   }
 
   nsCOMPtr<nsIPresShell> presShell = GetPresShell();
   if (NS_WARN_IF(!presShell)) {
     return NS_OK;
   }
   nsPresContext* presContext = GetPresContext();
   if (NS_WARN_IF(!presContext)) {
     return NS_OK;
   }
-  MOZ_ASSERT(!clickEvent->DefaultPrevented());
+  MOZ_ASSERT(!aMouseClickEvent->DefaultPrevented());
   nsEventStatus status = nsEventStatus_eIgnore;
   RefPtr<EventStateManager> esm = presContext->EventStateManager();
   DebugOnly<nsresult> rv =
-    esm->HandleMiddleClickPaste(presShell, clickEvent, &status, textEditor);
+    esm->HandleMiddleClickPaste(presShell, aMouseClickEvent, &status,
+                                textEditor);
   NS_WARNING_ASSERTION(NS_SUCCEEDED(rv),
                        "Failed to paste for the middle button click");
   if (status == nsEventStatus_eConsumeNoDefault) {
     // Prevent the event from propagating up to be possibly handled
     // again by the containing window:
-    clickEvent->StopImmediatePropagation();
-    clickEvent->PreventDefault();
+    aMouseClickEvent->StopImmediatePropagation();
+    aMouseClickEvent->PreventDefault();
   }
   return NS_OK;
 }
 
 bool
 EditorEventListener::NotifyIMEOfMouseButtonEvent(
                        WidgetMouseEvent* aMouseEvent)
 {
--- a/editor/libeditor/EditorEventListener.h
+++ b/editor/libeditor/EditorEventListener.h
@@ -68,17 +68,17 @@ protected:
   nsresult KeyPress(WidgetKeyboardEvent* aKeyboardEvent);
   nsresult HandleChangeComposition(WidgetCompositionEvent* aCompositionEvent);
   nsresult HandleStartComposition(WidgetCompositionEvent* aCompositionEvent);
   void HandleEndComposition(WidgetCompositionEvent* aCompositionEvent);
   MOZ_CAN_RUN_SCRIPT
   virtual nsresult MouseDown(dom::MouseEvent* aMouseEvent);
   virtual nsresult MouseUp(dom::MouseEvent* aMouseEvent) { return NS_OK; }
   MOZ_CAN_RUN_SCRIPT
-  virtual nsresult MouseClick(dom::MouseEvent* aMouseEvent);
+  virtual nsresult MouseClick(WidgetMouseEvent* aMouseClickEvent);
   nsresult Focus(InternalFocusEvent* aFocusEvent);
   nsresult Blur(InternalFocusEvent* aBlurEvent);
   MOZ_CAN_RUN_SCRIPT nsresult DragEnter(dom::DragEvent* aDragEvent);
   MOZ_CAN_RUN_SCRIPT nsresult DragOver(dom::DragEvent* aDragEvent);
   nsresult DragExit(dom::DragEvent* aDragEvent);
   MOZ_CAN_RUN_SCRIPT nsresult Drop(dom::DragEvent* aDragEvent);
 
   MOZ_CAN_RUN_SCRIPT bool CanDrop(dom::DragEvent* aEvent);
--- a/editor/libeditor/HTMLEditorEventListener.cpp
+++ b/editor/libeditor/HTMLEditorEventListener.cpp
@@ -178,34 +178,36 @@ HTMLEditorEventListener::MouseDown(Mouse
     int32_t clientY = aMouseEvent->ClientY();
     htmlEditor->OnMouseDown(clientX, clientY, element, aMouseEvent);
   }
 
   return EditorEventListener::MouseDown(aMouseEvent);
 }
 
 nsresult
-HTMLEditorEventListener::MouseClick(MouseEvent* aMouseEvent)
+HTMLEditorEventListener::MouseClick(WidgetMouseEvent* aMouseClickEvent)
 {
   if (NS_WARN_IF(DetachedFromEditor())) {
     return NS_OK;
   }
 
-  RefPtr<EventTarget> target = aMouseEvent->GetTarget();
-  NS_ENSURE_TRUE(target, NS_ERROR_NULL_POINTER);
+  RefPtr<EventTarget> target = aMouseClickEvent->GetDOMEventTarget();
+  if (NS_WARN_IF(!target)) {
+    return NS_ERROR_FAILURE;
+  }
   nsCOMPtr<Element> element = do_QueryInterface(target);
   if (NS_WARN_IF(!element)) {
     return NS_ERROR_FAILURE;
   }
 
   RefPtr<HTMLEditor> htmlEditor = mEditorBase->AsHTMLEditor();
   MOZ_ASSERT(htmlEditor);
   htmlEditor->DoInlineTableEditingAction(*element);
   // DoInlineTableEditingAction might cause reframe
   // Editor is destroyed.
   if (htmlEditor->Destroyed()) {
     return NS_OK;
   }
 
-  return EditorEventListener::MouseClick(aMouseEvent);
+  return EditorEventListener::MouseClick(aMouseClickEvent);
 }
 
 } // namespace mozilla
--- a/editor/libeditor/HTMLEditorEventListener.h
+++ b/editor/libeditor/HTMLEditorEventListener.h
@@ -29,14 +29,14 @@ public:
    */
   virtual nsresult Connect(EditorBase* aEditorBase) override;
 
 protected:
   MOZ_CAN_RUN_SCRIPT
   virtual nsresult MouseDown(dom::MouseEvent* aMouseEvent) override;
   virtual nsresult MouseUp(dom::MouseEvent* aMouseEvent) override;
   MOZ_CAN_RUN_SCRIPT
-  virtual nsresult MouseClick(dom::MouseEvent* aMouseEvent) override;
+  virtual nsresult MouseClick(WidgetMouseEvent* aMouseClickEvent) override;
 };
 
 } // namespace mozilla
 
 #endif // #ifndef HTMLEditorEventListener_h