Bug 1337718 part.10 Make EditorEventListener::MouseClick() and EditorEventListener::HandleMiddleClickPaste() use WidgetMouseEvent as far as possible r?m_kato draft
authorMasayuki Nakano <masayuki@d-toybox.com>
Wed, 08 Feb 2017 22:55:54 +0900
changeset 481130 00f21b1928abe8ff8157d5b5b42c2accdb4bb891
parent 481129 66073c830fdb376ef52fd3bf5878edde04e268d6
child 545120 1aea3436883971138411d446e57987600d51c41e
push id44730
push usermasayuki@d-toybox.com
push dateThu, 09 Feb 2017 09:50:16 +0000
reviewersm_kato
bugs1337718
milestone54.0a1
Bug 1337718 part.10 Make EditorEventListener::MouseClick() and EditorEventListener::HandleMiddleClickPaste() use WidgetMouseEvent as far as possible r?m_kato MozReview-Commit-ID: EMFevpq9ftM
editor/libeditor/EditorEventListener.cpp
--- a/editor/libeditor/EditorEventListener.cpp
+++ b/editor/libeditor/EditorEventListener.cpp
@@ -666,30 +666,30 @@ EditorEventListener::MouseClick(nsIDOMMo
 
   // If we got a mouse down inside the editing area, we should force the
   // IME to commit before we change the cursor position
   editorBase->ForceCompositionEnd();
   if (DetachedFromEditor()) {
     return NS_OK;
   }
 
-  int16_t button = -1;
-  aMouseEvent->GetButton(&button);
-  if (button == 1) {
+  if (clickEvent->button == 1) {
     return HandleMiddleClickPaste(aMouseEvent);
   }
   return NS_OK;
 }
 
 nsresult
 EditorEventListener::HandleMiddleClickPaste(nsIDOMMouseEvent* aMouseEvent)
 {
   MOZ_ASSERT(aMouseEvent);
-  MOZ_ASSERT(!DetachedFromEditorOrDefaultPrevented(
-                aMouseEvent->AsEvent()->WidgetEventPtr()));
+
+  WidgetMouseEvent* clickEvent =
+    aMouseEvent->AsEvent()->WidgetEventPtr()->AsMouseEvent();
+  MOZ_ASSERT(!DetachedFromEditorOrDefaultPrevented(clickEvent));
 
   if (!Preferences::GetBool("middlemouse.paste", false)) {
     // Middle click paste isn't enabled.
     return NS_OK;
   }
 
   // Set the selection to the point under the mouse cursor:
   nsCOMPtr<nsIDOMNode> parent;
@@ -704,21 +704,18 @@ EditorEventListener::HandleMiddleClickPa
   RefPtr<EditorBase> editorBase(mEditorBase);
   RefPtr<Selection> selection = editorBase->GetSelection();
   if (selection) {
     selection->Collapse(parent, offset);
   }
 
   // If the ctrl key is pressed, we'll do paste as quotation.
   // Would've used the alt key, but the kde wmgr treats alt-middle specially.
-  bool ctrlKey = false;
-  aMouseEvent->GetCtrlKey(&ctrlKey);
-
   nsCOMPtr<nsIEditorMailSupport> mailEditor;
-  if (ctrlKey) {
+  if (clickEvent->IsControl()) {
     mailEditor = do_QueryObject(editorBase);
   }
 
   nsresult rv;
   int32_t clipboard = nsIClipboard::kGlobalClipboard;
   nsCOMPtr<nsIClipboard> clipboardService =
     do_GetService("@mozilla.org/widget/clipboard;1", &rv);
   if (NS_SUCCEEDED(rv)) {
@@ -732,18 +729,18 @@ EditorEventListener::HandleMiddleClickPa
   if (mailEditor) {
     mailEditor->PasteAsQuotation(clipboard);
   } else {
     editorBase->Paste(clipboard);
   }
 
   // Prevent the event from propagating up to be possibly handled
   // again by the containing window:
-  aMouseEvent->AsEvent()->StopPropagation();
-  aMouseEvent->AsEvent()->PreventDefault();
+  clickEvent->StopPropagation();
+  clickEvent->PreventDefault();
 
   // We processed the event, whether drop/paste succeeded or not
   return NS_OK;
 }
 
 bool
 EditorEventListener::NotifyIMEOfMouseButtonEvent(
                        WidgetMouseEvent* aMouseEvent)