Bug 1083629 - Use nsHTMLEditor::IsAcceptableInputEvent() instead of nsEditor::IsDescendantOfEditorRoot() for checking if a mouse down event target is in focused HTML editor. r=ehsan, a=lsblakk
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 17 Oct 2014 10:09:32 +0900
changeset 233428 bf823df545e3d3e0eca8be59c3107c4109aee286
parent 233427 7ec4746b298c0fdc2049c4a0f8fa6080e233b9f1
child 233429 c4b405e8f11278ce853c4f0c7b65742c96fb1533
push id1
push usersledru@mozilla.com
push dateThu, 04 Dec 2014 17:57:20 +0000
reviewersehsan, lsblakk
bugs1083629
milestone35.0a2
Bug 1083629 - Use nsHTMLEditor::IsAcceptableInputEvent() instead of nsEditor::IsDescendantOfEditorRoot() for checking if a mouse down event target is in focused HTML editor. r=ehsan, a=lsblakk
editor/libeditor/nsHTMLEditorEventListener.cpp
--- a/editor/libeditor/nsHTMLEditorEventListener.cpp
+++ b/editor/libeditor/nsHTMLEditorEventListener.cpp
@@ -67,16 +67,21 @@ nsHTMLEditorEventListener::MouseUp(nsIDO
 
   return nsEditorEventListener::MouseUp(aMouseEvent);
 }
 
 nsresult
 nsHTMLEditorEventListener::MouseDown(nsIDOMMouseEvent* aMouseEvent)
 {
   nsHTMLEditor* htmlEditor = GetHTMLEditor();
+  // Contenteditable should disregard mousedowns outside it.
+  // IsAcceptableInputEvent() checks it for a mouse event.
+  if (!htmlEditor->IsAcceptableInputEvent(aMouseEvent)) {
+    return NS_OK;
+  }
 
   // Detect only "context menu" click
   // XXX This should be easier to do!
   // But eDOMEvents_contextmenu and NS_CONTEXTMENU is not exposed in any event
   // interface :-(
   int16_t buttonNumber;
   nsresult rv = aMouseEvent->GetButton(&buttonNumber);
   NS_ENSURE_SUCCESS(rv, rv);
@@ -88,21 +93,16 @@ nsHTMLEditorEventListener::MouseDown(nsI
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIDOMEventTarget> target;
   rv = aMouseEvent->GetExplicitOriginalTarget(getter_AddRefs(target));
   NS_ENSURE_SUCCESS(rv, rv);
   NS_ENSURE_TRUE(target, NS_ERROR_NULL_POINTER);
   nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
 
-  // Contenteditable should disregard mousedowns outside it
-  if (element && !htmlEditor->IsDescendantOfEditorRoot(element)) {
-    return NS_OK;
-  }
-
   if (isContextClick || (buttonNumber == 0 && clickCount == 2)) {
     nsCOMPtr<nsISelection> selection;
     mEditor->GetSelection(getter_AddRefs(selection));
     NS_ENSURE_TRUE(selection, NS_OK);
 
     // Get location of mouse within target node
     nsCOMPtr<nsIDOMNode> parent;
     rv = aMouseEvent->GetRangeParent(getter_AddRefs(parent));