diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp index b26b93ae71bc..21a4a44d647e 100644 --- a/dom/events/EventStateManager.cpp +++ b/dom/events/EventStateManager.cpp @@ -35,6 +35,7 @@ #include "nsCOMPtr.h" #include "nsFocusManager.h" #include "nsGenericHTMLElement.h" +#include "nsIClipboard.h" #include "nsIContent.h" #include "nsIContentInlines.h" #include "nsIDocument.h" @@ -5120,6 +5121,95 @@ EventStateManager::DispatchClickEvents(nsIPresShell* aPresShell, return rv; } +nsresult +EventStateManager::HandleMiddleClickPaste(nsIPresShell* aPresShell, + WidgetMouseEvent* aMouseEvent, + nsEventStatus* aStatus, + TextEditor* aTextEditor) +{ + MOZ_ASSERT(aPresShell); + MOZ_ASSERT(aMouseEvent); + MOZ_ASSERT(aMouseEvent->mMessage == eMouseClick && + aMouseEvent->button == WidgetMouseEventBase::eMiddleButton); + MOZ_ASSERT(aStatus); + MOZ_ASSERT(aTextEditor); + + if (*aStatus == nsEventStatus_eConsumeNoDefault) { + // Already consumed. Do nothing. + return NS_OK; + } + + RefPtr selection = aTextEditor->GetSelection(); + if (NS_WARN_IF(!selection)) { + return NS_ERROR_FAILURE; + } + + // Move selection to the clicked point. + nsCOMPtr container; + int32_t offset; + nsLayoutUtils::GetContainerAndOffsetAtEvent(aPresShell, aMouseEvent, + getter_AddRefs(container), + &offset); + if (container) { + // XXX If readonly or disabled or